restore pypy support broken when adding 3.11 support (from GH)

This is a copy of https://github.com/protocolbuffers/protobuf/pull/12431
but with the ifdef logic reversed. The original PR could not kick off our
CI tests because it wasn't branched directly from repo main.

Thanks to Tom Gillespie for the original PR.

PiperOrigin-RevId: 524041105
pull/12464/head
Eric Salo 2 years ago committed by Copybara-Service
parent 0f3f1e826d
commit 69a4876d69
  1. 6
      python/google/protobuf/pyext/descriptor.cc

@ -126,7 +126,9 @@ PyObject* PyString_FromCppString(const std::string& str) {
// TODO(amauryfa): Change the proto2 compiler to remove the assignments, and
// remove this hack.
bool _CalledFromGeneratedFile(int stacklevel) {
#ifndef PYPY_VERSION
#ifdef PYPY_VERSION
return true;
#else
// This check is not critical and is somewhat difficult to implement correctly
// in PyPy.
PyFrameObject* frame = PyEval_GetFrame();
@ -182,7 +184,6 @@ bool _CalledFromGeneratedFile(int stacklevel) {
// Not at global module scope
goto exit;
}
#endif
result = true;
exit:
Py_XDECREF(frame_globals);
@ -190,6 +191,7 @@ exit:
Py_XDECREF(frame_code);
Py_XDECREF(frame);
return result;
#endif
}
// If the calling code is not a _pb2.py file, raise AttributeError.

Loading…
Cancel
Save