M
mauro
Hi all!
I am trying to call within a C extension a Python function provided as
an argument by the user with: PyObject_Call(). The C extension should
work also if the user supplies a class method, but in this case I am
getting an error. Do I need to explicitly pass 'self' as an argument
to PyObject_Call()? If so, how can I do that?
Now, I am using:
if ((tmp_args = PyTuple_New(1)) == NULL)
PyErr_SetString( PyExc_ReferenceError, "attempt to access a null-
pointer" );
PyTuple_SetItem(tmp_args, 0, paramlist);
to create the tuple required by PyObject_Call(), but I have no idea on
how to add a reference to 'self'.
Here is what I would like to obtain:
##
import mymodule
def myfunc(x):
# Do something
return [z]
class MyClass:
def mymethod(self, x):
# Do something
return z
def runme(self):
mymodule.main(myfunc) # This will work
mymodule.main(self.mymethod) # This will not work (Segmentation
fault)
x = MyClass()
x.runme()
##
Thanks in advance.
Mauro
I am trying to call within a C extension a Python function provided as
an argument by the user with: PyObject_Call(). The C extension should
work also if the user supplies a class method, but in this case I am
getting an error. Do I need to explicitly pass 'self' as an argument
to PyObject_Call()? If so, how can I do that?
Now, I am using:
if ((tmp_args = PyTuple_New(1)) == NULL)
PyErr_SetString( PyExc_ReferenceError, "attempt to access a null-
pointer" );
PyTuple_SetItem(tmp_args, 0, paramlist);
to create the tuple required by PyObject_Call(), but I have no idea on
how to add a reference to 'self'.
Here is what I would like to obtain:
##
import mymodule
def myfunc(x):
# Do something
return [z]
class MyClass:
def mymethod(self, x):
# Do something
return z
def runme(self):
mymodule.main(myfunc) # This will work
mymodule.main(self.mymethod) # This will not work (Segmentation
fault)
x = MyClass()
x.runme()
##
Thanks in advance.
Mauro