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 @@ -6062,6 +6062,18 @@ _ctypes_add_objects(PyObject *mod)
60626062static int
60636063_ctypes_mod_exec (PyObject * mod )
60646064{
6065+ // See https://github.com/python/cpython/issues/128485
6066+ // This allocates some memory and then frees it to ensure that the
6067+ // the dlmalloc allocator initializes itself to avoid data races
6068+ // in free-threading.
6069+ void * codeloc = NULL ;
6070+ void * ptr = Py_ffi_closure_alloc (sizeof (void * ), & codeloc );
6071+ if (ptr == NULL ) {
6072+ PyErr_NoMemory ();
6073+ return -1 ;
6074+ }
6075+ Py_ffi_closure_free (ptr );
6076+
60656077 ctypes_state * st = get_module_state (mod );
60666078 st -> _unpickle = PyObject_GetAttrString (mod , "_unpickle" );
60676079 if (st -> _unpickle == NULL ) {
@@ -6189,9 +6201,3 @@ PyInit__ctypes(void)
61896201{
61906202 return PyModuleDef_Init (& _ctypesmodule );
61916203}
6192-
6193- /*
6194- Local Variables:
6195- compile-command: "cd .. && python setup.py -q build -g && python setup.py -q build install --home ~"
6196- End:
6197- */
You can’t perform that action at this time.
0 commit comments