New type objects and PyObject_New
It seems possible to create new type objects still with PyObject_New() instead of calling the type object. Is this a bug? Thomas
"Thomas Heller"
It seems possible to create new type objects still with PyObject_New() instead of calling the type object. Is this a bug?
Not sure what you are asking: I assume you are *not* asking about new type objects (as created by typeobject.c:type_new), but instead about instance of newstyle classes (i.e. instance of type objects). Why would you then think that using PyObject_New is a bad thing? Regards, Martin
From: "Martin v. Loewis"
"Thomas Heller"
writes: It seems possible to create new type objects still with PyObject_New() instead of calling the type object. Is this a bug?
Not sure what you are asking: I assume you are *not* asking about new type objects (as created by typeobject.c:type_new), but instead about instance of newstyle classes (i.e. instance of type objects). Correct.
Why would you then think that using PyObject_New is a bad thing?
IIUC, PyObject_New doesn't call the tp_new, tp_alloc, and tp_init slots. So, the new object probably will be in an invalid state, may be allocated by an allocator not compatible with the tp_dealloc slot?
Regards, Martin
Thanks, Thomas
"Thomas Heller"
IIUC, PyObject_New doesn't call the tp_new, tp_alloc, and tp_init slots. So, the new object probably will be in an invalid state, may be allocated by an allocator not compatible with the tp_dealloc slot?
I see. However, how do you implement tp_new if PyObject_New went away? Regards, Martin
[Thomas Heller]
It seems possible to create new type objects still with PyObject_New() instead of calling the type object. Is this a bug?
[David Abrahams]
I sure hope not! I need that functionality!
Um, PyObject_New() is the low-level allocation function that you should be calling from the type's tp_new, not something you should be calling elsewhere to create an instance of a type. --Guido van Rossum (home page: http://www.python.org/~guido/)
Uh, never mind, I'm actually doing this:
// Don't call the type directly to do the construction, since
// that would require the registration of an appropriate
// __init__ function.
PyObject* raw_result = m_class_object->tp_alloc(m_class_object,
0);
----- Original Message -----
From: "Guido van Rossum"
[Thomas Heller]
It seems possible to create new type objects still with PyObject_New() instead of calling the type object. Is this a bug?
[David Abrahams]
I sure hope not! I need that functionality!
Um, PyObject_New() is the low-level allocation function that you should be calling from the type's tp_new, not something you should be calling elsewhere to create an instance of a type.
--Guido van Rossum (home page: http://www.python.org/~guido/)
----- Original Message -----
From: "David Abrahams"
Uh, never mind, I'm actually doing this:
// Don't call the type directly to do the construction, since // that would require the registration of an appropriate // __init__ function. PyObject* raw_result = m_class_object->tp_alloc(m_class_object, 0);
And no, that's not an emoticon.
participants (4)
-
David Abrahams
-
Guido van Rossum
-
martin@v.loewis.de
-
Thomas Heller