File tree Expand file tree Collapse file tree 1 file changed +12
-6
lines changed Expand file tree Collapse file tree 1 file changed +12
-6
lines changed Original file line number Diff line number Diff line change @@ -6070,6 +6070,18 @@ _ctypes_add_objects(PyObject *mod)
60706070static int
60716071_ctypes_mod_exec (PyObject * mod )
60726072{
6073+ // See https://github.com/python/cpython/issues/128485
6074+ // This allocates some memory and then frees it to ensure that the
6075+ // the dlmalloc allocator initializes itself to avoid data races
6076+ // in free-threading.
6077+ void * codeloc = NULL ;
6078+ void * ptr = Py_ffi_closure_alloc (sizeof (void * ), & codeloc );
6079+ if (ptr == NULL ) {
6080+ PyErr_NoMemory ();
6081+ return -1 ;
6082+ }
6083+ Py_ffi_closure_free (ptr );
6084+
60736085 ctypes_state * st = get_module_state (mod );
60746086 st -> _unpickle = PyObject_GetAttrString (mod , "_unpickle" );
60756087 if (st -> _unpickle == NULL ) {
@@ -6197,9 +6209,3 @@ PyInit__ctypes(void)
61976209{
61986210 return PyModuleDef_Init (& _ctypesmodule );
61996211}
6200-
6201- /*
6202- Local Variables:
6203- compile-command: "cd .. && python setup.py -q build -g && python setup.py -q build install --home ~"
6204- End:
6205- */
You can’t perform that action at this time.
0 commit comments