@@ -48,10 +48,13 @@ InterfaceMakerPythonSimple::
48
48
*/
49
49
void InterfaceMakerPythonSimple::
50
50
write_includes (std::ostream &out) {
51
- out << " #if PY_VERSION_HEX >= 0x30300000\n " ;
51
+ out << " #if PY_VERSION_HEX >= 0x30300000 && !defined(Py_GIL_DISABLED) \n " ;
52
52
out << " #define Py_LIMITED_API 0x30300000\n " ;
53
53
out << " #endif\n\n " ;
54
54
InterfaceMakerPython::write_includes (out);
55
+ out << " \n #ifdef Py_GIL_DISABLED\n " ;
56
+ out << " static PyMutex mutex;\n " ;
57
+ out << " #endif\n\n " ;
55
58
}
56
59
57
60
/* *
@@ -132,7 +135,11 @@ write_module(ostream &out,ostream *out_h, InterrogateModuleDef *def) {
132
135
133
136
<< " INIT_FUNC() {\n "
134
137
<< " #if PY_MAJOR_VERSION >= 3\n "
135
- << " return PyModule_Create(&python_simple_module);\n "
138
+ << " PyObject *module = PyModule_Create(&python_simple_module);\n "
139
+ << " #ifdef Py_GIL_DISABLED\n "
140
+ << " PyUnstable_Module_SetGIL(module, Py_MOD_GIL_NOT_USED);\n "
141
+ << " #endif\n "
142
+ << " return module;\n "
136
143
<< " #else\n "
137
144
<< " Py_InitModule(\" " << def->library_name << " \" , python_simple_funcs);\n "
138
145
<< " #endif\n "
@@ -380,6 +387,9 @@ void InterfaceMakerPythonSimple::write_function_instance(ostream &out, Interface
380
387
<< " }\n " ;
381
388
}
382
389
390
+ out << " #ifdef Py_GIL_DISABLED\n " ;
391
+ out << " PyMutex_Lock(&mutex);\n " ;
392
+ out << " #endif\n " ;
383
393
if (track_interpreter) {
384
394
out << " in_interpreter = 0;\n " ;
385
395
}
@@ -397,6 +407,9 @@ void InterfaceMakerPythonSimple::write_function_instance(ostream &out, Interface
397
407
if (track_interpreter) {
398
408
out << " in_interpreter = 1;\n " ;
399
409
}
410
+ out << " #ifdef Py_GIL_DISABLED\n " ;
411
+ out << " PyMutex_Unlock(&mutex);\n " ;
412
+ out << " #endif\n " ;
400
413
if (!extra_cleanup.empty ()) {
401
414
out << " " << extra_cleanup << " \n " ;
402
415
}
@@ -411,6 +424,9 @@ void InterfaceMakerPythonSimple::write_function_instance(ostream &out, Interface
411
424
if (track_interpreter) {
412
425
out << " in_interpreter = 1;\n " ;
413
426
}
427
+ out << " #ifdef Py_GIL_DISABLED\n " ;
428
+ out << " PyMutex_Unlock(&mutex);\n " ;
429
+ out << " #endif\n " ;
414
430
if (!extra_cleanup.empty ()) {
415
431
out << " " << extra_cleanup << " \n " ;
416
432
}
@@ -425,6 +441,9 @@ void InterfaceMakerPythonSimple::write_function_instance(ostream &out, Interface
425
441
if (track_interpreter) {
426
442
out << " in_interpreter = 1;\n " ;
427
443
}
444
+ out << " #ifdef Py_GIL_DISABLED\n " ;
445
+ out << " PyMutex_Unlock(&mutex);\n " ;
446
+ out << " #endif\n " ;
428
447
if (!extra_cleanup.empty ()) {
429
448
out << " " << extra_cleanup << " \n " ;
430
449
}
0 commit comments