Creating a Python Type in C - tp_init and tp_new

ajayre at gmail.com ajayre at gmail.com
Thu May 17 15:10:54 EDT 2007


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?

Thanks, Andy
(please reply to the newsgroup only - thanks)




More information about the Python-list mailing list