)]}'
{
  "commit": "98295b7ec198ebbfecfc7f28cf2622c7c704f634",
  "tree": "84b48f37428a90d752ddb86287e68b6d9982ce7b",
  "parents": [
    "a98ea67f4ebaee0c4746173d80bd6e84a76abcc3"
  ],
  "author": {
    "name": "Jahongir Qurbonov",
    "email": "109198731+Jahongir-Qurbonov@users.noreply.github.com",
    "time": "Fri Nov 20 20:10:04 2026 +0500"
  },
  "committer": {
    "name": "GitHub",
    "email": "noreply@github.com",
    "time": "Fri Nov 20 16:10:04 2026 +0100"
  },
  "message": "[mypyc] Fix attribute offsets when only a subclass defines __call__ (#22483)\n\nThe object struct of a native class that has a `__call__` method has a\n`vectorcall` field (used through `tp_vectorcall_offset`). It was placed\nright after `vtable`, before the attributes. A class inherits `__call__`\nfrom its bases, so if only a subclass defines it, the subclass struct\nhas the extra field while the base class struct doesn\u0027t. All attributes\ninherited from the base class were then at different offsets in the\nsubclass, and code compiled for the base class (methods, attribute\naccess through the base type) read and wrote the wrong fields. This is a\nsegfault or memory corruption:\n\n```python\nclass A:\n    def __init__(self, x: str) -\u003e None:\n        self.x \u003d x\n\n    def get_x(self) -\u003e str:\n        return self.x\n\nclass B(A):\n    def __call__(self) -\u003e str:\n        return self.x\n\nB(\"b\")()  # Segfault\n```\n\nGenerated struct of `B`:\n\n```c\ntypedef struct {\n    PyObject_HEAD\n    CPyVTableItem *vtable;\n    vectorcallfunc vectorcall;  // not in the struct of A\n    PyObject *_x;               // at a different offset than in A\n} B;\n```\n\n`A.__init__` (compiled for the struct of `A`) stores `x` in the\n`vectorcall` field of the `B` instance, so calling it jumps to the\naddress of a `str` object. With more attributes, base class methods and\nsubclass code also see each other\u0027s attributes in the wrong fields.\n\nNow the `vectorcall` field goes after the attributes, so the attributes\nof a base class are at the same offsets in all subclasses. The field is\nonly accessed through the struct of the class itself (in its setup\nfunction, which isn\u0027t shared with native subclasses) and through\n`tp_vectorcall_offset`, which is set for each class, so it\u0027s fine for\nits offset to differ between a class and its subclasses. This also works\nwith separate compilation, since each module computes the layout from\nthe class IR in the same way.\n\nClasses where the base class also defines `__call__` were not affected,\nand neither were classes without attributes.\n\nTests: a run test with `__call__` defined only in a subclass, accessing\ninherited attributes through base class methods, directly and through\n`Any`; `__call__` overridden in a sub-subclass; an intermediate class\nwith attributes; a base class with weak reference support; and\ninterpreted subclasses (one inheriting `__call__`, one defining it). A\nmulti-module test has the base class in another module (another group in\nseparate compilation mode). The new run test fails on master.",
  "tree_diff": [
    {
      "type": "modify",
      "old_id": "30bd66095e5d9eb0d8505222354fd42c074ed04b",
      "old_mode": 33188,
      "old_path": "mypyc/codegen/emitclass.py",
      "new_id": "2e0090010c14ac35cf6ccf298e3ec1c5ebbd374c",
      "new_mode": 33188,
      "new_path": "mypyc/codegen/emitclass.py"
    },
    {
      "type": "modify",
      "old_id": "1304837c9925572149b5fb2929f91c5894d2ed58",
      "old_mode": 33188,
      "old_path": "mypyc/test-data/run-classes.test",
      "new_id": "17428ab2f68788fc12acf51e09928979c6b80ae5",
      "new_mode": 33188,
      "new_path": "mypyc/test-data/run-classes.test"
    },
    {
      "type": "modify",
      "old_id": "3c8b4ceb99957f2ce8be1567f8c13441569defc0",
      "old_mode": 33188,
      "old_path": "mypyc/test-data/run-multimodule.test",
      "new_id": "5dc8151fd3fecc2cfb4da66739ec421ab93dd0c9",
      "new_mode": 33188,
      "new_path": "mypyc/test-data/run-multimodule.test"
    }
  ]
}
