always getting 'None' return value fromPyObject_CallObject

Discussion in 'Python' started by Gal Aviel, Mar 23, 2008.

  1. Gal Aviel

    Gal Aviel Guest

    Hello all,

    Kinda desperate over here .. Any help would be greatly appreciated !

    I'm trying to embed a Python interpreter inside a Verilog simulator as a
    SystemVerilog DPI application. The python side implements a few SV exported
    tasks. I've got a thin C shared library as the dpi app; all it does it get the
    task arguments from the simulator and hand those to the Python side using the
    Python C API.

    I followed '5.3 Pure Embedding' under Python 2.5 documentation very closely.

    When calling a function defined in my module, the function executes Ok - it sees
    the correct arguments being passed from C, and executes 100% - only the return
    value is always 'None' (I tried returning a simple integer like '5' which
    doesn't work).

    Any ideas?

    Maybe scope issues? the module goes out of scope, and there is no place to store
    the temporary return value from the function? Where is that stored anyway with
    embedded python?

    Thanks- Gal Aviel.
    Gal Aviel, Mar 23, 2008
    #1
    1. Advertising

  2. Gal Aviel

    John Machin Guest

    Re: always getting 'None' return value from PyObject_CallObject

    On Mar 24, 10:43 am, Gal Aviel <> wrote:
    > Hello all,
    >
    > Kinda desperate over here .. Any help would be greatly appreciated !
    >
    > I'm trying to embed a Python interpreter inside a Verilog simulator as a
    > SystemVerilog DPI application. The python side implements a few SV exported
    > tasks. I've got a thin C shared library as the dpi app; all it does it get the
    > task arguments from the simulator and hand those to the Python side using the
    > Python C API.
    >
    > I followed '5.3 Pure Embedding' under Python 2.5 documentation very closely.
    >
    > When calling a function defined in my module, the function executes Ok - it sees
    > the correct arguments being passed from C, and executes 100% - only the return
    > value is always 'None' (I tried returning a simple integer like '5' which
    > doesn't work).
    >
    > Any ideas?
    >


    So you are saying that your Python functions does:
    return 5
    [are you sure it's not falling off the end and thus implicitly
    returning None?]
    but PyObject_CallObject transmogrifies that into the Python object
    None -- or do you mean a C NULL pointer?

    It might be a good idea if you showed us the exact C code that you are
    using instead of this snippet from the manual:

    pValue = PyObject_CallObject(pFunc, pArgs);
    Py_DECREF(pArgs);
    if (pValue != NULL) {
    printf("Result of call: %ld\n", PyInt_AsLong(pValue));
    Py_DECREF(pValue);
    }
    else {
    Py_DECREF(pFunc);
    Py_DECREF(pModule);
    PyErr_Print();
    fprintf(stderr,"Call failed\n");
    return 1;
    }
    including the part where you demonstrate that the returned pointer
    points to the None object.

    It might be a good idea if you showed us the minimal Python function
    that exhibits this behaviour with your C code ... does it happen with:
    def myfunc():
    return 5
    ?
    And what version of Python on what platform?
    John Machin, Mar 24, 2008
    #2
    1. Advertising

  3. Gal Aviel

    NotGuru Guest

    Re: always getting 'None' return value from PyObject_CallObject

    On Mar 23, 6:43 pm, Gal Aviel <> wrote:
    > Hello all,
    >
    > Kinda desperate over here .. Any help would be greatly appreciated !
    >
    > I'm trying to embed a Python interpreter inside a Verilog simulator as a
    > SystemVerilog DPI application. The python side implements a few SV exported
    > tasks. I've got a thin C shared library as the dpi app; all it does it get the
    > task arguments from the simulator and hand those to the Python side using the
    > Python C API.
    >
    > I followed '5.3 Pure Embedding' under Python 2.5 documentation very closely.
    >
    > When calling a function defined in my module, the function executes Ok - it sees
    > the correct arguments being passed from C, and executes 100% - only the return
    > value is always 'None' (I tried returning a simple integer like '5' which
    > doesn't work).
    >


    I met similar problems before and I guess you can try to start from a
    minimum version that f takes no arguments. If your can't pass the
    right argument to f, it will always return none without any prompt.
    NotGuru, Mar 24, 2008
    #3
    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. Carsten Haese
    Replies:
    0
    Views:
    466
    Carsten Haese
    Mar 24, 2008
  2. length power
    Replies:
    2
    Views:
    65
    Rustom Mody
    Apr 10, 2014
  3. Skip Montanaro
    Replies:
    0
    Views:
    48
    Skip Montanaro
    Apr 10, 2014
  4. Johannes Schneider

    Re: why i have the output of [None, None, None]

    Johannes Schneider, Apr 10, 2014, in forum: Python
    Replies:
    0
    Views:
    43
    Johannes Schneider
    Apr 10, 2014
  5. Terry Reedy
    Replies:
    0
    Views:
    53
    Terry Reedy
    Apr 10, 2014
Loading...

Share This Page