This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author njs
Recipients njs
Date 2014-12-02.23:39:20
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1417563561.24.0.575634102448.issue22986@psf.upfronthosting.co.za>
In-reply-to
Content
Following on from the discussion starting here:

http://thread.gmane.org/gmane.comp.python.devel/150438/focus=150604

Here's a patch to improve __class__ assignment.

1) We remove the HEAPTYPE check from object_set_class, and move it to same_slots_added. This fixes an outright bug: previously it was possible for non-HEAPTYPE types to get passed into same_slots_added (either b/c the loop in compatible_for_assignment ended up with non-HEAPTYPE types, or via __bases__ assignment), and it would then wander off following pointers through random memory.

2) Now that object_set_class can potentially accept non-HEAPTYPE types, adjust the reference counting appropriately.

3) To clarify the logic of compatible_for_assignment, rename equiv_structs to compatible_with_tp_base, tweak accordingly, and add a nice comment explaining the logic. (compatible_for_assignment is equiv_structs's only caller so this is totally safe.)

4) Now that equiv_structs/compatible_with_tp_base has a clearer purpose, also move the tp_dealloc check from compatible_for_assignment into compatible_with_tp_base. In the process, add special-case handling for subclass_dealloc, b/c subclass_dealloc delegates to the parent class tp_dealloc anyway.

These changes together make it possible to assign to module instances's __class__ slot, which is useful for reasons described in the above thread. So I added a test for this to check the new code.
History
Date User Action Args
2014-12-02 23:39:21njssetrecipients: + njs
2014-12-02 23:39:21njssetmessageid: <1417563561.24.0.575634102448.issue22986@psf.upfronthosting.co.za>
2014-12-02 23:39:21njslinkissue22986 messages
2014-12-02 23:39:20njscreate