Skip to content

Conversation

@jackyk02
Copy link
Contributor

@jackyk02 jackyk02 commented Nov 9, 2023

Issue
Segfault due to Python 3.11 changes to object layout and memory allocation methods.

Background
Python 3.11 introduced changes to optimize CPython. One of the significant changes, as mentioned in this PR, modifies the object layout to place pointers to dict and values immediately before the GC header. This change potentially affected the memory layout of custom python objects.

Before:
Untitled1
After:
Untitled2
Moreover, this commit removed _PyObject_GC_Calloc and _PyObject_GC_Malloc, affecting the memory allocation for objects that participate in garbage collection.

Solution
The new memory allocation relies on PyObject_New instead of PyObject_GC_New.

Updates in this PR
The earlier PR #293 only updates the memory allocation for convert_C_port_to_py. However, updates are also necessary for convert_C_mode_to_py and convert_C_tag_to_py.

Test
./gradlew targetTest -Ptarget=Python is expected to pass now with the modifications introduced in this PR.

@lhstrh
Copy link
Member

lhstrh commented Jul 25, 2024

Haven't seen any activity on this since last fall. Can I go ahead and close the PR? Please weigh in on this, @jackyk02 and @edwardalee.

@edwardalee
Copy link
Contributor

Haven't seen any activity on this since last fall. Can I go ahead and close the PR? Please weigh in on this, @jackyk02 and @edwardalee.

This is probably a necessary part of supporting Python 3.11, but I have no idea what else would be required and we would probably have to either require Python 3.11 or find a way to support both 3.10 and 3.11. I suspect eventually we will need to support later versions of Python, so I don't know what to do with this either.

@edwardalee
Copy link
Contributor

Closing this PR as we seem to already work with Python 3.11.

@edwardalee edwardalee closed this Jun 17, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants