Skip to content

Commit 54cbf04

Browse files
committed
Update emitclass.py
1 parent e464d5c commit 54cbf04

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

mypyc/codegen/emitclass.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -313,6 +313,16 @@ def emit_line() -> None:
313313
if emitter.capi_version < (3, 12):
314314
fields["tp_dictoffset"] = base_size
315315
fields["tp_weaklistoffset"] = weak_offset
316+
elif cl.supports_weakref:
317+
# __weakref__ lives right after the struct
318+
# TODO: It should get a member in the struct instead of doing this nonsense.
319+
weak_offset = base_size
320+
emitter.emit_lines(
321+
f"PyMemberDef {members_name}[] = {{",
322+
f'{{"__weakref__", T_OBJECT_EX, {base_size}, 0, NULL}},',
323+
"{0}",
324+
"};",
325+
)
316326
else:
317327
fields["tp_basicsize"] = base_size
318328

0 commit comments

Comments
 (0)