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" <thomas.heller@ion-tof.com> writes:
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" <martin@v.loewis.de>
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]
[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" <guido@python.org> To: "David Abrahams" <david.abrahams@rcn.com> Cc: "Thomas Heller" <thomas.heller@ion-tof.com>; <python-dev@python.org> Sent: Tuesday, April 09, 2002 5:54 PM Subject: Re: [Python-Dev] New type objects and PyObject_New

----- Original Message ----- From: "David Abrahams" <david.abrahams@rcn.com> To: "Guido van Rossum" <guido@python.org> Cc: "Thomas Heller" <thomas.heller@ion-tof.com>; <python-dev@python.org> Sent: Tuesday, April 09, 2002 6:33 PM Subject: Re: [Python-Dev] New type objects and PyObject_New
And no, that's not an emoticon.

"Thomas Heller" <thomas.heller@ion-tof.com> writes:
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" <martin@v.loewis.de>
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]
[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" <guido@python.org> To: "David Abrahams" <david.abrahams@rcn.com> Cc: "Thomas Heller" <thomas.heller@ion-tof.com>; <python-dev@python.org> Sent: Tuesday, April 09, 2002 5:54 PM Subject: Re: [Python-Dev] New type objects and PyObject_New

----- Original Message ----- From: "David Abrahams" <david.abrahams@rcn.com> To: "Guido van Rossum" <guido@python.org> Cc: "Thomas Heller" <thomas.heller@ion-tof.com>; <python-dev@python.org> Sent: Tuesday, April 09, 2002 6:33 PM Subject: Re: [Python-Dev] New type objects and PyObject_New
And no, that's not an emoticon.
participants (4)
-
David Abrahams
-
Guido van Rossum
-
martin@v.loewis.de
-
Thomas Heller