Re: PyCodeObject incompatibility
Armin Rigo <[email protected]> Thu, 10 Feb 2022 14:06:49 +0100
| Newsgroups | gmane.comp.python.pypy |
|---|---|
| Message-ID | <CAMSv6X1EzL5LOs5sxSPLsAzNr1f4puR0aaKxX59-zHm-z-89GA@mail.gmail.com> |
Hi, On Thu, 10 Feb 2022 at 14:03, Dmitry Kovner <[email protected]> wrote: > Hello! I'm trying to build a low-level C API extension of cPython to be used in PyPy. The extension extensively uses some fields of PyCodeObject (https://github.com/python/cpython/blob/f87e616af038ee8963185e11b96841c81e8ef15a/Include/code.h#L23): co_firstlineno, co_stacksize, co_consts and so on. However, it seems these fields are not defined in the similar structure of the PyPy implementation: https://foss.heptapod.net/pypy/pypy/-/blob/branch/py3.8/pypy/module/cpyext/include/code.h#L7. Is it possible to get values of these fields using PyPy C API somehow? Yes, it's a limitation of PyPy not to expose these fields. If you want to write portable code that always works, the simplest is to call `PyObject_GetAttrString(code, "__consts__")` etc. Remember that you need to call `Py_DECREF()` on the result at some point. A bientôt, Armin. _______________________________________________ pypy-dev mailing list [email protected] https://mail.python.org/mailman/listinfo/pypy-dev