[ python-Bugs-1174712 ] subclassing ModuleType and another built-in
type
SourceForge.net
noreply at sourceforge.net
Sun Apr 3 15:39:30 CEST 2005
Bugs item #1174712, was opened at 2005-04-01 10:22
Message generated for change (Comment added) made by mwh
You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=1174712&group_id=5470
Category: Python Interpreter Core
Group: None
Status: Open
Resolution: None
Priority: 5
Submitted By: Armin Rigo (arigo)
Assigned to: Nobody/Anonymous (nobody)
Summary: subclassing ModuleType and another built-in type
Initial Comment:
class X(types.ModuleType, str): pass
X('name')
-> segfault
This buggy subclassing goes through typeobject.c's checks because PyModuleObject looks exactly like a user-defined subclass of 'object': it has a PyObject_HEAD followed only by the dict, as specified by tp_dictoffset.
A fix would be to forbid any subclassing to move the tp_dictoffset of a non-heap type.
----------------------------------------------------------------------
>Comment By: Michael Hudson (mwh)
Date: 2005-04-03 14:39
Message:
Logged In: YES
user_id=6656
> This might point to the need for cleaning up typeobject.c's
> darker corners...
No kidding. Maybe Samuele, you and I can gang up on Guido at
EuroPython (is he sprinting? Perhaps we should ask).
----------------------------------------------------------------------
Comment By: Armin Rigo (arigo)
Date: 2005-04-02 13:27
Message:
Logged In: YES
user_id=4771
The proposed fix is not good enough. If another built-in C type similar to PyModuleObject is defined (say by a C extension module), then it would become possible to subclass both this new type and ModuleType. This might lead to unwanted behavior if e.g. one parent class allows rebinding __dict__ and the other not (and crashes if __dict__ is rebound).
This might point to the need for cleaning up typeobject.c's darker corners...
----------------------------------------------------------------------
You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=1174712&group_id=5470
More information about the Python-bugs-list
mailing list