Re: How to list the global functions from a C program

Discussion in 'Python' started by Jack Diederich, Jan 14, 2005.

  1. On Fri, Jan 14, 2005 at 04:01:13PM +0100, Francesco Montorsi wrote:
    <snip>
    > PyObject *list = PyObject_Dir(m_pGlobals);
    > if (!list || PyList_Check(list) == FALSE)
    > return;
    >
    > for (int i=0,max=PyList_Size(list); i<max; i++) {
    >
    > PyObject *elem = PyList_GetItem(list, i);
    > if (PyCallable_Check(elem) != 0) {
    >
    > /* this should be a function.. */
    > /* HERE IS THE PROBLEM: this code is never reached */
    > PyObject *str = PyObject_GetAttrString(elem, "func_name");
    > }
    > }
    > ==============================================
    >
    > Everything seems to work but then when scanning the list returned
    > by PyObject_Dir() I never find any callable object....
    > what am I doing wrong ?


    You are checking the list of strings returned from the dir() to
    see if any of them are callable (they aren't). You mean to check
    the thing that the string is a name for, so instead of

    # callable(name)
    PyCallable_Check(elem)

    use

    # callable(globals()[name])
    PyCallable_Check(PyDict_GetItem(m_pGlobals, elem))

    -Jack
     
    Jack Diederich, Jan 14, 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. Xiangliang Meng
    Replies:
    1
    Views:
    1,629
    Victor Bazarov
    Jun 21, 2004
  2. Francesco Montorsi

    How to list the global functions from a C program

    Francesco Montorsi, Jan 14, 2005, in forum: Python
    Replies:
    0
    Views:
    295
    Francesco Montorsi
    Jan 14, 2005
  3. Ross A. Finlayson
    Replies:
    19
    Views:
    622
    Keith Thompson
    Mar 10, 2005
  4. Ali Shirvani

    How get list of functions in current C program

    Ali Shirvani, Nov 17, 2008, in forum: C Programming
    Replies:
    6
    Views:
    1,010
    James Harris
    Nov 18, 2008
  5. User1014
    Replies:
    3
    Views:
    196
    Richard Cornford
    Dec 1, 2006
Loading...

Share This Page