File tree 1 file changed +12
-6
lines changed
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)
6062
6062
static int
6063
6063
_ctypes_mod_exec (PyObject * mod )
6064
6064
{
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
+
6065
6077
ctypes_state * st = get_module_state (mod );
6066
6078
st -> _unpickle = PyObject_GetAttrString (mod , "_unpickle" );
6067
6079
if (st -> _unpickle == NULL ) {
@@ -6189,9 +6201,3 @@ PyInit__ctypes(void)
6189
6201
{
6190
6202
return PyModuleDef_Init (& _ctypesmodule );
6191
6203
}
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