Adding additional field to PyObject base struct causing packages import deprecated

I am hacking CPython base struct, ie., the struct _object {} in Include/object.h. I added an extra field for my need, nothing else is changed. However, when trying to install other packages from source, and the customized python failed to import those libraries. For example, for the pyperformance project:

lyuze@wukong1: ~/pyperformance$ /home/lyuze/workspace/cpython_org/python -m pip install .
lyuze@wukong1:~/pyperformance$ /home/lyuze/workspace/cpython_org/python
Python 3.13.0a4+ (heads/main-dirty:c688c0f130, Feb 23 2024, 18:03:52) [GCC 11.4.0] 
>>> import pyperf
Segmentation fault (core dumped)

gdb shows:

(gdb) bt
#0  __strcmp_evex () at ../sysdeps/x86_64/multiarch/strcmp-evex.S:132
#1  0x00005555557c754a in _PyImport_ResolveNameWithPackageContext (name=name@entry=0x0) at Python/import.c:723
#2  0x00005555556a87b6 in _PyModule_CreateInitialized (module=module@entry=0x7ffff719f3a0 <moduledef>, module_api_version=module_api_version@entry=3)
    at Objects/moduleobject.c:213
[...]

I also tried to reinstall setuptools but not helping. I was thinking the although the changed PyObject memory layout will cause the packages installed from pypi deprecated, but when installing from source should work. So I’m not sure why this happens? Thanks.

The obvious sanity checks here would seem to be:

  • Did you completely recompile Python and run the tests after making the change?

  • When Pip builds the other package, and thus tells the compiler to compile something, does the compiler have access to the modified object.h in that environment?

I cleaned up and recompiled python. make test shows these tests failed in both 3.10 and 3.13 (main) when adding an extra field

== Tests result: FAILURE then FAILURE ==

411 tests OK.

11 tests failed:
    test_array test_buffer test_deque test_itertools test_memoryio
    test_ordered_dict test_peg_generator test_pickle test_struct
    test_sys test_xml_etree_c
[...]

I’m not sure how to debug from here though?

I suggest you to modify the ABI flags to make sure that you recompile everything for this different ABI.