@@ -233,6 +233,21 @@ void uwsgi_python_pthread_child(void) {
233
233
PyMethodDef uwsgi_spit_method [] = { {"uwsgi_spit" , py_uwsgi_spit , METH_VARARGS , "" } };
234
234
PyMethodDef uwsgi_write_method [] = { {"uwsgi_write" , py_uwsgi_write , METH_VARARGS , "" } };
235
235
236
+ PyDoc_STRVAR (uwsgi_py_doc , "uWSGI api module." );
237
+
238
+ #ifdef PYTHREE
239
+ static PyModuleDef uwsgi_module3 = {
240
+ PyModuleDef_HEAD_INIT ,
241
+ "uwsgi" ,
242
+ uwsgi_py_doc ,
243
+ -1 ,
244
+ NULL ,
245
+ };
246
+ PyObject * init_uwsgi3 (void ) {
247
+ return PyModule_Create (& uwsgi_module3 );
248
+ }
249
+ #endif
250
+
236
251
int uwsgi_python_init () {
237
252
238
253
char * pyversion = strchr (Py_GetVersion (), '\n' );
@@ -298,6 +313,9 @@ int uwsgi_python_init() {
298
313
wchar_t * pname = uwsgi_calloc (sizeof (wchar_t ) * (strlen (program_name )+ 1 ));
299
314
mbstowcs (pname , program_name , strlen (program_name )+ 1 );
300
315
Py_SetProgramName (pname );
316
+ #ifdef UWSGI_PY312
317
+ PyImport_AppendInittab ("uwsgi" , init_uwsgi3 );
318
+ #endif
301
319
#else
302
320
Py_SetProgramName (program_name );
303
321
#endif
@@ -660,21 +678,6 @@ void init_uwsgi_vars() {
660
678
661
679
662
680
663
- PyDoc_STRVAR (uwsgi_py_doc , "uWSGI api module." );
664
-
665
- #ifdef PYTHREE
666
- static PyModuleDef uwsgi_module3 = {
667
- PyModuleDef_HEAD_INIT ,
668
- "uwsgi" ,
669
- uwsgi_py_doc ,
670
- -1 ,
671
- NULL ,
672
- };
673
- PyObject * init_uwsgi3 (void ) {
674
- return PyModule_Create (& uwsgi_module3 );
675
- }
676
- #endif
677
-
678
681
void init_uwsgi_embedded_module () {
679
682
PyObject * new_uwsgi_module , * zero ;
680
683
int i ;
@@ -695,7 +698,9 @@ void init_uwsgi_embedded_module() {
695
698
696
699
697
700
#ifdef PYTHREE
701
+ #ifndef UWSGI_PY312
698
702
PyImport_AppendInittab ("uwsgi" , init_uwsgi3 );
703
+ #endif
699
704
new_uwsgi_module = PyImport_AddModule ("uwsgi" );
700
705
#else
701
706
new_uwsgi_module = Py_InitModule3 ("uwsgi" , NULL , uwsgi_py_doc );
@@ -1208,7 +1213,10 @@ void uwsgi_python_init_apps() {
1208
1213
1209
1214
// prepare for stack suspend/resume
1210
1215
if (uwsgi .async > 0 ) {
1211
- #ifdef UWSGI_PY311
1216
+ #ifdef UWSGI_PY312
1217
+ up .current_c_recursion_remaining = uwsgi_malloc (sizeof (int )* uwsgi .async );
1218
+ up .current_py_recursion_remaining = uwsgi_malloc (sizeof (int )* uwsgi .async );
1219
+ #elif defined UWSGI_PY311
1212
1220
up .current_recursion_remaining = uwsgi_malloc (sizeof (int )* uwsgi .async );
1213
1221
#else
1214
1222
up .current_recursion_depth = uwsgi_malloc (sizeof (int )* uwsgi .async );
@@ -1360,7 +1368,12 @@ void uwsgi_python_pre_uwsgi_fork() {
1360
1368
// Acquire the gil and import lock before forking in order to avoid
1361
1369
// deadlocks in workers
1362
1370
UWSGI_GET_GIL
1371
+ #if defined UWSGI_PY312
1372
+ PyInterpreterState * interp = PyInterpreterState_Get ();
1373
+ _PyImport_AcquireLock (interp );
1374
+ #else
1363
1375
_PyImport_AcquireLock ();
1376
+ #endif
1364
1377
}
1365
1378
}
1366
1379
@@ -1372,7 +1385,12 @@ void uwsgi_python_post_uwsgi_fork(int step) {
1372
1385
if (uwsgi .has_threads ) {
1373
1386
if (step == 0 ) {
1374
1387
// Release locks within master process
1388
+ #if defined UWSGI_PY312
1389
+ PyInterpreterState * interp = PyInterpreterState_Get ();
1390
+ _PyImport_ReleaseLock (interp );
1391
+ #else
1375
1392
_PyImport_ReleaseLock ();
1393
+ #endif
1376
1394
UWSGI_RELEASE_GIL
1377
1395
}
1378
1396
else {
@@ -1643,7 +1661,11 @@ void uwsgi_python_suspend(struct wsgi_request *wsgi_req) {
1643
1661
PyGILState_Release (pgst );
1644
1662
1645
1663
if (wsgi_req ) {
1646
- #ifdef UWSGI_PY311
1664
+ #ifdef UWSGI_PY312
1665
+ up .current_c_recursion_remaining [wsgi_req -> async_id ] = tstate -> c_recursion_remaining ;
1666
+ up .current_py_recursion_remaining [wsgi_req -> async_id ] = tstate -> py_recursion_remaining ;
1667
+ up .current_frame [wsgi_req -> async_id ] = tstate -> cframe ;
1668
+ #elif defined UWSGI_PY311
1647
1669
up .current_recursion_remaining [wsgi_req -> async_id ] = tstate -> recursion_remaining ;
1648
1670
up .current_frame [wsgi_req -> async_id ] = tstate -> cframe ;
1649
1671
#else
@@ -1652,7 +1674,11 @@ void uwsgi_python_suspend(struct wsgi_request *wsgi_req) {
1652
1674
#endif
1653
1675
}
1654
1676
else {
1655
- #ifdef UWSGI_PY311
1677
+ #ifdef UWSGI_PY312
1678
+ up .current_main_c_recursion_remaining = tstate -> c_recursion_remaining ;
1679
+ up .current_main_py_recursion_remaining = tstate -> py_recursion_remaining ;
1680
+ up .current_main_frame = tstate -> cframe ;
1681
+ #elif defined UWSGI_PY311
1656
1682
up .current_main_recursion_remaining = tstate -> recursion_remaining ;
1657
1683
up .current_main_frame = tstate -> cframe ;
1658
1684
#else
@@ -1886,7 +1912,11 @@ void uwsgi_python_resume(struct wsgi_request *wsgi_req) {
1886
1912
PyGILState_Release (pgst );
1887
1913
1888
1914
if (wsgi_req ) {
1889
- #ifdef UWSGI_PY311
1915
+ #ifdef UWSGI_PY312
1916
+ tstate -> c_recursion_remaining = up .current_c_recursion_remaining [wsgi_req -> async_id ];
1917
+ tstate -> py_recursion_remaining = up .current_py_recursion_remaining [wsgi_req -> async_id ];
1918
+ tstate -> cframe = up .current_frame [wsgi_req -> async_id ];
1919
+ #elif defined UWSGI_PY311
1890
1920
tstate -> recursion_remaining = up .current_recursion_remaining [wsgi_req -> async_id ];
1891
1921
tstate -> cframe = up .current_frame [wsgi_req -> async_id ];
1892
1922
#else
@@ -1895,7 +1925,11 @@ void uwsgi_python_resume(struct wsgi_request *wsgi_req) {
1895
1925
#endif
1896
1926
}
1897
1927
else {
1898
- #ifdef UWSGI_PY311
1928
+ #ifdef UWSGI_PY312
1929
+ tstate -> c_recursion_remaining = up .current_main_c_recursion_remaining ;
1930
+ tstate -> py_recursion_remaining = up .current_main_py_recursion_remaining ;
1931
+ tstate -> cframe = up .current_main_frame ;
1932
+ #elif defined UWSGI_PY311
1899
1933
tstate -> recursion_remaining = up .current_main_recursion_remaining ;
1900
1934
tstate -> cframe = up .current_main_frame ;
1901
1935
#else
0 commit comments