f->f_locals is NULL for a method call

Discussion in 'Python' started by Vijay Kumar, May 27, 2005.

  1. Vijay Kumar

    Vijay Kumar Guest

    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.
    Vijay Kumar, May 27, 2005
    #1
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    10
    Views:
    889
    Thomas G. Marshall
    Aug 2, 2005
  2. Replies:
    5
    Views:
    26,614
    Mike Schilling
    Mar 29, 2006
  3. Replies:
    0
    Views:
    2,738
  4. Paul Drummond

    f_locals is NULL inside a method

    Paul Drummond, Nov 29, 2005, in forum: C++
    Replies:
    2
    Views:
    376
    Paul Drummond
    Nov 30, 2005
  5. Ron Garret

    f_locals

    Ron Garret, Aug 23, 2007, in forum: Python
    Replies:
    0
    Views:
    480
    Ron Garret
    Aug 23, 2007
Loading...

Share This Page