python3-protobuf: fix build with Python 3.11

This commit is contained in:
Đoàn Trần Công Danh 2022-09-22 23:07:52 +07:00
parent 14957afa52
commit 0619b27e82

View file

@ -0,0 +1,46 @@
--- a/google/protobuf/pyext/descriptor.cc
+++ b/google/protobuf/pyext/descriptor.cc
@@ -91,6 +91,12 @@ PyObject* PyString_FromCppString(const s
//
// TODO(amauryfa): Change the proto2 compiler to remove the assignments, and
// remove this hack.
+#if PY_VERSION_HEX < 0x03090000
+#define PyFrame_GetCode(x) (x)->f_code
+#define PyFrame_GetGlobals(x) (x)->f_globals
+#define PyFrame_GetLocals(x) (x)->f_locals
+#define PyFrame_GetBack(x) (x)->f_back
+#endif
bool _CalledFromGeneratedFile(int stacklevel) {
#ifndef PYPY_VERSION
// This check is not critical and is somewhat difficult to implement correctly
@@ -100,18 +106,18 @@ bool _CalledFromGeneratedFile(int stackl
return false;
}
while (stacklevel-- > 0) {
- frame = frame->f_back;
+ frame = PyFrame_GetBack(frame);
if (frame == nullptr) {
return false;
}
}
- if (frame->f_code->co_filename == nullptr) {
+ if (PyFrame_GetCode(frame)->co_filename == nullptr) {
return false;
}
char* filename;
Py_ssize_t filename_size;
- if (PyString_AsStringAndSize(frame->f_code->co_filename,
+ if (PyString_AsStringAndSize(PyFrame_GetCode(frame)->co_filename,
&filename, &filename_size) < 0) {
// filename is not a string.
PyErr_Clear();
@@ -132,7 +138,7 @@ bool _CalledFromGeneratedFile(int stackl
return false;
}
- if (frame->f_globals != frame->f_locals) {
+ if (PyFrame_GetGlobals(frame) != PyFrame_GetLocals(frame)) {
// Not at global module scope
return false;
}