0

from the call back function of sys.settrace how to pass frame object to a c++ which accepts void *

Limitations (in a given situation): Forced to use sys.settrace (can not use PyEval_SetTrace) Also c++ function can not accept PyObject* or PyFrameObject*

C++ code (using SWIG python bindings are generated for this):

class TEST_DECLS InterpPython{
static int TraceHook(void *frame, hwString what, void * arg);
}

Python code:

sys.settrace(_trace_hook)
def _trace_hook(frame, event, arg):
  InterpPython_TraceHook(frame,event, arg)

Results:

TypeError: in method 'InterpPython_TraceHook', argument 1 of type 'void *'

srinivas M
  • 55
  • 7

1 Answers1

1

Try a typemap to convert the Python input object to a void* when it is a void* frame parameter. You could also add a check that the object is actually a PyFrameObject.

%typemap(in) void* frame %{
    $1 = (void*)$input;
%}
Mark Tolonen
  • 166,664
  • 26
  • 169
  • 251