[Python-bugs-list] [ python-Bugs-540965 ] PyType_GenericNew broken
noreply@sourceforge.net
noreply@sourceforge.net
Sun, 14 Apr 2002 17:09:05 -0700
Bugs item #540965, was opened at 2002-04-08 08:24
You can respond by visiting:
http://sourceforge.net/tracker/?func=detail&atid=105470&aid=540965&group_id=5470
Category: Type/class unification
>Group: Python 2.3
Status: Open
Resolution: None
Priority: 5
Submitted By: Ralf Juengling (rjuengling)
>Assigned to: Guido van Rossum (gvanrossum)
Summary: PyType_GenericNew broken
Initial Comment:
A new Python type/class _A is implemented in C.
It needs a special allocator function, thus
tp_alloc=_A_alloc for this type. There is no need
for a special new-method, however, thus
tp_new=PyType_GenericNew for this type.
The class A inherits from _A and is implemented
in Python:
class A(_A):
pass
When an instance of _A is created, its allocator
function _A_alloc gets invoked. When an instance
of A is created, the _A_alloc does not get invoked.
PyType_GenericNew should also invoke all allocator
functions of the argument type's superclasses (in
reverse mro, I think).
----------------------------------------------------------------------
>Comment By: Guido van Rossum (gvanrossum)
Date: 2002-04-14 20:09
Message:
Logged In: YES
user_id=6380
> PyType_GenericNew should also invoke all allocator
> functions of the argument type's superclasses (in
> reverse mro, I think).
No, this doesn't make sense; you can't invoke
more than one allocator. (Each allocator would
create a whole new object.)
The cause of your problem is in type_new(): it
always overrides tp_alloc with PyType_GenericAlloc.
You'd have to write a new metaclass (inheriting
from type) in C to change the tp_alloc (and tp_free)
settings.
But why do you want this? Why do you want
A instances to use the same allocator as _A?
This is not how subclassing built-in types works
elsewhere; e.g. int uses a special allocator,
but subclasses of int don't inherit that.
Before I do anything about this I'd like to
understand what you are trying to accomplish.
----------------------------------------------------------------------
You can respond by visiting:
http://sourceforge.net/tracker/?func=detail&atid=105470&aid=540965&group_id=5470