Question

Maybe I'm missing something, but here is a problem:

I'm tracing python code by C extensions and my trace function got PyFrameObject* frame. Now I want to process the frame by Python code(embedded or converted to C by Cython) but it deals with PyObject*.

How do I convert PyFrameObject* to PyObject*? I don't find appropriate convertion funciton in frameobject.h.

Thanks.

Was it helpful?

Solution

Use a cast:

PyObject *myObject = (PyObject *)myFrameObject

This is standard for the Python C API; everything that "inherits" from PyObject has a PyObject_VAR_HEAD at the top of the object so a pointer to the object is convertible to a pointer to PyObject.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top