> This cannot work, because Foo_Type is no PyObject but a PyVarObject > (independent > of the use of PyVarObject_HEAD_INIT or PyObject_HEAD_INIT). The code > line would > work so: > > ((PyObject *)&Foo_Type)->ob_type = &PyType_Type
However, this is not what you should use. Instead, use Py_Type(&Foo_Type) = &PyType_Type > If the type is not subtypable (doesn’t have the > Py_TPFLAGS_BASETYPE flag bit set), it is permissible to call the > object deallocator directly instead of via tp_free. > " > > What ? Where do we "call" these methods ? You should typically call tp_free inside of tp_dealloc. For example, string_dealloc ends with Py_TYPE(op)->tp_free(op); In the specific case (Py_TYPE(op) is not subtypeable), you could alternatively also call PyObject_Del(op); If there are subclasses, they might have used a different allocator (rather than the object allocator), hence you must call the deallocator through tp_free. HTH, Martin -- http://mail.python.org/mailman/listinfo/python-list