-
-
Notifications
You must be signed in to change notification settings - Fork 30.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Do not allocate non-PyObjects with PyObject_Malloc() #114569
Comments
Fix usage in Modules, Objects, and Parser subdirectories.
There is some strange usage in unicodeobject.c as well; I did not look closely at it yet. Perhaps it is ok, perhaps not. |
Yeah, it looks like a two of those should use cpython/Objects/unicodeobject.c Line 5206 in 30b7b4f
cpython/Objects/unicodeobject.c Line 14677 in 30b7b4f
|
Did we catch all of them? |
Yeah, looks like it! |
…114574) Fix usage in Modules, Objects, and Parser subdirectories.
…114574) Fix usage in Modules, Objects, and Parser subdirectories.
Feature or enhancement
The free-threaded build requires that Python objects -- and only Python objects -- be allocated through the Python object allocation APIs (like
PyObject_Malloc()
orPyType_GenericNew()
) 1.There are a few places internally 2 that use
PyObject_Malloc()
for non Python objects. We should switch those call sites to usePyMem_Malloc()/Free()
instead.Note that there is not a significant difference between using
PyObject_Malloc()
andPyMem_Malloc()
in the default build. Both calls use obmalloc under the hood, so switching from one to the other should not matter for the default build.Here are some examples, but this list may not be exhaustive:
cpython/Modules/_sre/sre_lib.h
Line 1125 in 841eacd
cpython/Modules/_elementtree.c
Line 270 in 841eacd
cpython/Modules/_elementtree.c
Lines 498 to 499 in 841eacd
https://github.com/python/cpython/blob/main/Modules/mathmodule.c#L2573
cpython/Modules/pyexpat.c
Lines 23 to 24 in 841eacd
cpython/Objects/bytearrayobject.c
Line 135 in 841eacd
cpython/Parser/lexer/lexer.c
Line 132 in 841eacd
Linked PRs
Footnotes
See https://peps.python.org/pep-0703/#backwards-compatibility:~:text=Non%2DPython%20objects%20must%20not%20be%20allocated%20through%20those%20APIs ↩
@DinoV fixed the use in
dictobject.c
in https://github.com/python/cpython/pull/114543 ↩The text was updated successfully, but these errors were encountered: