From 69a4876d69eeee37aab121f6f4908bec7b35b271 Mon Sep 17 00:00:00 2001 From: Eric Salo Date: Thu, 13 Apr 2023 10:38:15 -0700 Subject: [PATCH] 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 --- python/google/protobuf/pyext/descriptor.cc | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/python/google/protobuf/pyext/descriptor.cc b/python/google/protobuf/pyext/descriptor.cc index c1fd20cdbb..fefcca7a0e 100644 --- a/python/google/protobuf/pyext/descriptor.cc +++ b/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.