Commit 8ff4809
committed
py/objtype: Fix 32-bit crash when calling super().__init__() in metaclass.
When super().__init__() was called from within a custom metaclass __init__,
the super_attr() function incorrectly mapped __init__ lookups to the make_new
slot for all objects. For type objects, this caused type_make_new() to be
invoked, which called mp_obj_new_type() again, creating a duplicate type
object that overwrote the original's memory.
On 32-bit architectures, this memory corruption manifested as corrupted
slot_index fields, causing assertion failures when accessing locals_dict.
The fix:
- Add type.__init__() as a no-op that accepts standard metaclass arguments
- In super_attr(), detect when super().__init__() is called on a type object
(metaclass context) and return type.__init__() instead of mapping to make_new
- Only map __init__ to make_new for regular instance initialization
This preserves the existing behavior for regular instances while fixing
metaclass super().__init__() calls to not recreate type objects.
Fixes: #XXXXX
Signed-off-by: Corona <[email protected]>
Signed-off-by: Andrew Leech <[email protected]>1 parent ca58524 commit 8ff4809
1 file changed
+35
-1
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1152 | 1152 | | |
1153 | 1153 | | |
1154 | 1154 | | |
| 1155 | + | |
| 1156 | + | |
| 1157 | + | |
| 1158 | + | |
| 1159 | + | |
| 1160 | + | |
| 1161 | + | |
| 1162 | + | |
| 1163 | + | |
| 1164 | + | |
| 1165 | + | |
| 1166 | + | |
1155 | 1167 | | |
1156 | 1168 | | |
1157 | 1169 | | |
| |||
1205 | 1217 | | |
1206 | 1218 | | |
1207 | 1219 | | |
| 1220 | + | |
| 1221 | + | |
| 1222 | + | |
| 1223 | + | |
| 1224 | + | |
| 1225 | + | |
| 1226 | + | |
1208 | 1227 | | |
1209 | 1228 | | |
1210 | 1229 | | |
| |||
1672 | 1691 | | |
1673 | 1692 | | |
1674 | 1693 | | |
| 1694 | + | |
| 1695 | + | |
1675 | 1696 | | |
1676 | | - | |
| 1697 | + | |
| 1698 | + | |
| 1699 | + | |
| 1700 | + | |
| 1701 | + | |
| 1702 | + | |
| 1703 | + | |
| 1704 | + | |
| 1705 | + | |
| 1706 | + | |
| 1707 | + | |
| 1708 | + | |
| 1709 | + | |
| 1710 | + | |
1677 | 1711 | | |
1678 | 1712 | | |
1679 | 1713 | | |
| |||
0 commit comments