Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > always getting 'None' return value fromPyObject_CallObject

Reply
Thread Tools

always getting 'None' return value fromPyObject_CallObject

 
 
Gal Aviel
Guest
Posts: n/a
 
      03-23-2008
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.






 
Reply With Quote
 
 
 
 
John Machin
Guest
Posts: n/a
 
      03-24-2008
On Mar 24, 10:43 am, Gal Aviel <(E-Mail Removed)> 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?
 
Reply With Quote
 
 
 
 
NotGuru
Guest
Posts: n/a
 
      03-24-2008
On Mar 23, 6:43*pm, Gal Aviel <(E-Mail Removed)> 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.

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: always getting 'None' return value from PyObject_CallObject Carsten Haese Python 0 03-24-2008 12:05 AM
Getting ID, calling url, search for value, return value Tim Fröglich ASP .Net Web Services 1 01-10-2006 09:18 PM
what value does lack of return or empty "return;" return Greenhorn C Programming 15 03-06-2005 08:19 PM
Trying to create a CSS box that is always is always the width of an image placed inside it (and no wider) Deryck HTML 4 06-22-2004 08:25 PM
getting return value from function without return statement. Seong-Kook Shin C Programming 1 06-18-2004 08:19 AM



Advertisments