creating an instance of a C extension type from another C extension type (HOW?)
Maxwell Sayles
sayles at cpsc.ucalgary.ca
Thu Jun 6 15:17:59 EDT 2002
I have two C extension modules that would do the equivalent of the
following python classes:
class A:
def __init__ (self, value):
self.value = value
class B:
def __init__ (self, value):
self.value = value
def makeA (self):
return A (self.value)
now i've written class A and B into python C extensions. I want class B
to create and return an instance of class A in the function makeA. the
.so file for class A has a C function
PyObject* A_init_c (int value)
{
A_struct* self = PyObject_New (A_struct, A_type);
self->value = value;
return (PyObject*)self;
}
this function is also called by the C function for A.__init__ :
PyObject* A_init (PyObject* self, PyObject* args)
{
int value;
if (!PyArg_ParseTuple ("i", &value)) return NULL;
return A_init_c (value);
}
this works... but the function for B.makeA() returns an object that
causes a core dump when i use the 'type' function with the object as a
parameter
PyObject* B_makeA (B_struct* self, PyObject* args)
{
if (!PyArg_ParseTuple ("")) return NULL;
return A_init_c (self->value);
}
now when i do
b = B(5)
a = b.makeA()
print type(a)
it causes a core dump. is there anything wrong with my logic? code?
also.. this isn't the real code from my program.. i just wrote it out
here in the window, so hopefully there aren't any syntactic errors
hope someone can help... could you please reply to the newsgroup and to
my e-mail, as i don't check the newsgroup too often.
thanks!
max
More information about the Python-list
mailing list