En Thu, 17 May 2007 16:10:54 -0300, <[EMAIL PROTECTED]> escribió: > I'm creating a type in a C function as follows: > > static PyObject *Receive(PyObject *self, PyObject *args) { > pyMessageObject *msgobj = PyObject_New(pyMessageObject, > &pyMessageType); > return (PyObject *)msgobj; > } > > I have (some lines omitted): > > static PyTypeObject pyMessageType = > { > PyObject_HEAD_INIT(NULL) > ... > pyMessage_Init, /*tp_init*/ > 0, /*tp_alloc*/ > pyMessage_New, /*tp_new*/ > }; > > I have noticed that pyMessage_New and pyMessage_Init are not called. > However if the type is created in Python then they are called. Why is > this and how can I solve it?
I think tp_new and tp_init are used when you create an instance by calling the type (in Python would be your_type()) At least it's in type's tp_call (type_call in typeobject.c) where __new__ and __init__ are checked and processed. So I think you should create your object using PyObject_CallObject(pyMessageType, NULL) but I'm not sure... just try and post your results! Or perhaps there is another way, I don't know. -- Gabriel Genellina -- http://mail.python.org/mailman/listinfo/python-list