f->f_locals is NULL for a method call

V

Vijay Kumar

hi,

I have written a trace function in C using the Python/C API. I want to
find whether the call occured is a function call or method call and if
a method call, its self object.

int tracer(PyObject *obj, PyObject *f, int what, PyObject *args){
PyObject *item,*SelfItem;
switch(what){
case PyTrace_CALL: {
printf("%s",PyString_AS_STRING(f->f_code->co_name));
if(f->f_code->co_argcount>0 &&
strcmp(PyString_AS_STRING(PyTuple_GetItem(f->f_code->co_varnames,0),"self")==0)
{
//checks if the call is a method call
printf("Method\n");
SelfItem = f->f_locals;
} else printf("Function");
} }

The SelfItem obtained is a NULL object (for method call).But when I
wrote the same trace function in python, f->f_locals is a dictionary
with "self" as a keyword.
How can i get the dictionary in C?

Thanks,
Vijay.
 

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

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,053
Latest member
BrodieSola

Latest Threads

Top