always getting 'None' return value from PyObject_CallObject

John Machin sjmachin at lexicon.net
Sun Mar 23 20:29:13 EDT 2008


On Mar 24, 10:43 am, Gal Aviel <galav... at yahoo.com> 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?



More information about the Python-list mailing list