0

I'm trying to port an existing extension for cPython to PyPy. It is written using C API. I've got some question which are connected with the compatibility:

  1. The extension uses opcodes from cPython's opcode.h header file. (https://github.com/python/cpython/blob/8a84aef0123bd8c13cf81fbc3b5f6d45f96c2656/Include/opcode.h) There is no such file in the implementation of C API in PyPy. What could you recommend as the best alternative?
  2. The extension uses some fields of PyThreadState structure. For example, its frame field (https://github.com/python/cpython/blob/8a84aef0123bd8c13cf81fbc3b5f6d45f96c2656/Include/cpython/pystate.h#L59). Is it right to use PyObject_GetAttrString() to access that field in PyPy C API?
  3. There is no function PyFrame_FastToLocals (https://github.com/python/cpython/blob/8a84aef0123bd8c13cf81fbc3b5f6d45f96c2656/Objects/frameobject.c#L931) in the C API of PyPy. Are there any alternatives?
  4. Functions PyEval_SetTrace(), PyEval_SetProfile(), PyFrame_GetLineNumber() are defined only in stubs.py in PyPy. (https://foss.heptapod.net/pypy/pypy/-/blob/branch/py3.7/pypy/module/cpyext/stubs.py#L918) Is there a way to get that information in PyPy except patching of its source code?
  5. Are there any analogues of all PyTrace_* constants (https://github.com/python/cpython/blob/8a84aef0123bd8c13cf81fbc3b5f6d45f96c2656/Include/cpython/pystate.h#L26) in the PyPy C API?
  6. There is no function PyFrame_Check() (https://github.com/python/cpython/blob/8a84aef0123bd8c13cf81fbc3b5f6d45f96c2656/Include/frameobject.h#L53) in the PyPy C API. Are there any alternatives?
Dmitrii
  • 88
  • 1
  • 7

1 Answers1

1

Just so this doesn't go without a response: the PyPy developers responded to this verbatim question on the pypy-dev mailing list. I guesss the poster is aksing the wider stackoverflow community if they have a better answer. A summary of the answer there is that:

  • PyPy does not have CPython equivalents for the many of the interfaces you seek
  • Even if they did, they would not expose them from internal CPython APIs, rather from PyPy-specific APIs.
  • Doing so would drastically slow down the code since it would break JIT optimizations.
mattip
  • 2,360
  • 1
  • 13
  • 13
  • The developers of PyPy have not answered my verbatim question yet. They answered another question which was the first one in that stream of communication. They recommended me an alternative to the missing functionality from the first question and it helped me a lot. Maybe there are some alternative solutions to my current list of problems which I missed in the documentation. So, I defenitely understan your point, however, I anyway need an answer which could help me with the list of the problems above or conclusion that it is not possible to achieve the same goals in PyPy at all. – Dmitrii Feb 20 '22 at 23:37