Getting params in callback function.

  • Thread starter Stephen Kellett
  • Start date
S

Stephen Kellett

Hello everyone. I've written a tracing function in C which is called
when Python executes each function and line and exceptions etc.

I don't know much about Python (I've been using assembly, C++ and Java
in varying amounts since 1983), so I'd very much appreciate some help
trying to get this information. If this is not the correct newsgroup to
ask this question, please suggest an alternative.

How can I determine what the parameters to a function are when the
callback is called when Python enters a function?

I've included a code snippet below for clarity.

int pythonCallback(PyObject *obj,
PyFrameObject *frame,
int what,
PyObject *arg)
{
switch(what)
{
case PyTrace_CALL:
{
// entering a function, arg is always NULL

// my attempt at getting the params
// I thought they may be here, but this code
fails
// I initially thought of getting the type name
// and if that worked I could move on to getting
// the value, but even getting the type name
failed

int i;

wprintf(_T("Num locals: %d\n"),
frame->f_nlocals);
for(i = 0; i < frame->f_nlocals; i++)
{
PyObject *po;
char *objTypeName;

po = frame->f_localsplus;
objTypeName = po->ob_type->tp_name;
wprintf(_T("Local %d: type: %s\n"), i,
objTypeName);
}
}
break;

case PyTrace_EXCEPTION:
{
// exiting a function via an exception
// arg is Exception information as returned by
// sys.exc_info()
}
break;

case PyTrace_LINE:
{
// line number event, arg is always NULL
}
break;

case PyTrace_RETURN:
{
// leaving a function
// arg is Value being returned to the caller
}
break;

default:
{
// unknown operation
}
break;
}

return 0;
}

Thank you for reading, hope you can shed some light on this.

Stephen
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,013
Latest member
KatriceSwa

Latest Threads

Top