[C-API] Weird sys.exc_info reference segfault

Jonas H. jonas at lophus.org
Tue Oct 5 10:17:57 EDT 2010


On 10/04/2010 11:41 PM, Antoine Pitrou wrote:
> Well, it should work, but you have to call PyType_Ready() to fill in
> the NULL fields with default values (for those where it's necessary).
> Does it solve it for you?

Yes, thank you! Although I do not understand which fields I have to 
provide. I want an object that behaves like a function: it should be 
callable and have a __dict__, but it should not be subclass of object - 
so now new instances of the object's type should be allowed to create 
and no subclasses, either.

Right now I have this minimal struct:

static PyTypeObject StartResponse_Type = {
     PyObject_HEAD_INIT(&PyType_Type)
     0,                          /* ob_size */
     "start_response",           /* tp_name */
     sizeof(StartResponse),      /* tp_basicsize */
     0,                          /* tp_itemsize */
     (destructor)PyObject_FREE,  /* tp_dealloc */
     0, 0, 0, 0, 0, 0, 0, 0, 0,  /* tp_print, tp_{get,set}attr, stuff */
     start_response              /* tp_call */
};

I'm not sure about the `PyObject_HEAD_INIT` argument, but passing NULL 
to it made `dir(obj)` crash.  So does setting `GenericGetAttr` as 
`tp_getattr`.



More information about the Python-list mailing list