always getting 'None' return value fromPyObject_CallObject

G

Gal Aviel

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.
 
J

John Machin

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?
 
N

NotGuru

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.
 

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

No members online now.

Forum statistics

Threads
473,756
Messages
2,569,540
Members
45,025
Latest member
KetoRushACVFitness

Latest Threads

Top