Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 12 additions & 6 deletions Modules/_ctypes/_ctypes.c
Original file line number Diff line number Diff line change
Expand Up @@ -6062,6 +6062,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) {
Expand Down Expand Up @@ -6189,9 +6201,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