mirror of
https://github.com/python/cpython.git
synced 2025-09-26 18:29:57 +00:00
gh-128485: ensure that dlmalloc initializes itself at import time in ctypes (#131633)
This commit is contained in:
parent
9c4fb92e12
commit
04d4aacaac
1 changed files with 12 additions and 6 deletions
|
@ -6070,6 +6070,18 @@ _ctypes_add_objects(PyObject *mod)
|
|||
static int
|
||||
_ctypes_mod_exec(PyObject *mod)
|
||||
{
|
||||
// See https://github.com/python/cpython/issues/128485
|
||||
// This allocates some memory and then frees it to ensure that the
|
||||
// the dlmalloc allocator initializes itself to avoid data races
|
||||
// in free-threading.
|
||||
void *codeloc = NULL;
|
||||
void *ptr = Py_ffi_closure_alloc(sizeof(void *), &codeloc);
|
||||
if (ptr == NULL) {
|
||||
PyErr_NoMemory();
|
||||
return -1;
|
||||
}
|
||||
Py_ffi_closure_free(ptr);
|
||||
|
||||
ctypes_state *st = get_module_state(mod);
|
||||
st->_unpickle = PyObject_GetAttrString(mod, "_unpickle");
|
||||
if (st->_unpickle == NULL) {
|
||||
|
@ -6197,9 +6209,3 @@ PyInit__ctypes(void)
|
|||
{
|
||||
return PyModuleDef_Init(&_ctypesmodule);
|
||||
}
|
||||
|
||||
/*
|
||||
Local Variables:
|
||||
compile-command: "cd .. && python setup.py -q build -g && python setup.py -q build install --home ~"
|
||||
End:
|
||||
*/
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue