Skip to content

Commit 88a2ccf

Browse files
committed
Restore the placement vtable to preserve the PyObject layout
1 parent 1d6cacd commit 88a2ccf

File tree

3 files changed

+10
-5
lines changed

3 files changed

+10
-5
lines changed

mypyc/codegen/emitclass.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -380,9 +380,7 @@ def setter_name(cl: ClassIR, attribute: str, names: NameGenerator) -> str:
380380
def generate_object_struct(cl: ClassIR, emitter: Emitter) -> None:
381381
seen_attrs: set[tuple[str, RType]] = set()
382382
lines: list[str] = []
383-
lines += ["typedef struct {", "PyObject_HEAD"]
384-
if not cl.is_final_class:
385-
lines.append("CPyVTableItem *vtable;")
383+
lines += ["typedef struct {", "PyObject_HEAD", "CPyVTableItem *vtable;"]
386384
if cl.has_method("__call__") and emitter.use_vectorcall():
387385
lines.append("vectorcallfunc vectorcall;")
388386
bitmap_attrs = []

mypyc/irbuild/ll_builder.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1889,8 +1889,9 @@ def primitive_op(
18891889
# Does this primitive map into calling a Python C API
18901890
# or an internal mypyc C API function?
18911891
if desc.c_function_name:
1892-
# TODO: Generate PrimitiOps here and transform them into CallC
1892+
# TODO: Generate PrimitiveOps here and transform them into CallC
18931893
# ops only later in the lowering pass
1894+
print(f"primitive_op: {desc.name} {desc.c_function_name} {desc.is_pure} -> {result_type}")
18941895
c_desc = CFunctionDescription(
18951896
desc.name,
18961897
desc.arg_types,
@@ -1908,7 +1909,7 @@ def primitive_op(
19081909
)
19091910
return self.call_c(c_desc, args, line, result_type)
19101911

1911-
# This primitve gets transformed in a lowering pass to
1912+
# This primitive gets transformed in a lowering pass to
19121913
# lower-level IR ops using a custom transform function.
19131914

19141915
coerced = []

mypyc/test-data/run-classes.test

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2527,5 +2527,11 @@ class C(B):
25272527
def a(self) -> int:
25282528
return 1
25292529

2530+
def fn(cl: B) -> int:
2531+
return cl.a()
2532+
25302533
def test_class_final_attribute_inherited() -> None:
25312534
assert C().a() == 1
2535+
assert fn(C()) == 1
2536+
assert B().a() == 2
2537+
assert fn(B()) == 2

0 commit comments

Comments
 (0)