From a443dd647565e08b6bc91f4dc84435f369aab05e Mon Sep 17 00:00:00 2001 From: wiz Date: Sun, 29 Oct 2023 18:18:03 +0000 Subject: [PATCH] py-uwsgi: add Python 3.12 support From https://github.com/unbit/uwsgi/pull/2542 --- www/py-uwsgi/distinfo | 4 +- www/py-uwsgi/options.mk | 3 +- .../patch-plugins_python_python__plugin.c | 161 ++++++++++++++++++ .../patch-plugins_python_uwsgi__python.h | 35 ++++ 4 files changed, 201 insertions(+), 2 deletions(-) create mode 100644 www/py-uwsgi/patches/patch-plugins_python_python__plugin.c create mode 100644 www/py-uwsgi/patches/patch-plugins_python_uwsgi__python.h diff --git a/www/py-uwsgi/distinfo b/www/py-uwsgi/distinfo index d3e2f4093f8a..c3896b4d79df 100644 --- a/www/py-uwsgi/distinfo +++ b/www/py-uwsgi/distinfo @@ -1,9 +1,11 @@ -$NetBSD: distinfo,v 1.44 2023/08/01 12:33:17 adam Exp $ +$NetBSD: distinfo,v 1.45 2023/10/29 18:18:03 wiz Exp $ BLAKE2s (uwsgi-2.0.22.tar.gz) = b67f868770f3efb3d0ffeec4acdd6bda71ea746c06e49407a657bd22c3a077d5 SHA512 (uwsgi-2.0.22.tar.gz) = 23c68336dd8bf41aa415b90d117be2b7e72773be2f3c1bac720a496f58bc56ae0ac2960c7bac4b8d73b16b459e10096dadd0e545fc3088d1979058bb275810e7 Size (uwsgi-2.0.22.tar.gz) = 809747 bytes SHA1 (patch-base.ini) = 1c5d7693e6c8011e6cc34f5f5d203584c985eb30 SHA1 (patch-core_logging.c) = e1e5f39446baecdcfc1738aa97852ad3d5ca40c7 +SHA1 (patch-plugins_python_python__plugin.c) = a536641efc3a25c7f43c37a507219fae0fe5f214 +SHA1 (patch-plugins_python_uwsgi__python.h) = 80ee323d5928c2e9ec7020d194f51676230c399d SHA1 (patch-uwsgi.h) = 112a325615e517f29b2420ba08f76d6a7a1bd3ef SHA1 (patch-uwsgiconfig.py) = 4945de7da82f3b05508e7d30ee0c3fe3144a2829 diff --git a/www/py-uwsgi/options.mk b/www/py-uwsgi/options.mk index ca9e3d2eada2..28fc16b916f4 100644 --- a/www/py-uwsgi/options.mk +++ b/www/py-uwsgi/options.mk @@ -1,4 +1,4 @@ -# $NetBSD: options.mk,v 1.7 2019/04/29 03:28:39 dholland Exp $ +# $NetBSD: options.mk,v 1.8 2023/10/29 18:18:03 wiz Exp $ PKG_OPTIONS_VAR= PKG_OPTIONS.py-uwsgi PKG_SUPPORTED_OPTIONS= debug openssl pcre uuid uwsgi-sse_offload yaml @@ -58,6 +58,7 @@ UWSGI_SSE= sse_offload=true INSTALL_ENV+= UWSGI_EMBED_PLUGINS=sse_offload post-extract: post-extract-sse +.PHONY: post-extract-sse post-extract-sse: mv ${WRKDIR}/uwsgi-sse-offload-${SSE_REVISION} ${WRKSRC}/plugins/sse_offload .else diff --git a/www/py-uwsgi/patches/patch-plugins_python_python__plugin.c b/www/py-uwsgi/patches/patch-plugins_python_python__plugin.c new file mode 100644 index 000000000000..80ff03ca56e9 --- /dev/null +++ b/www/py-uwsgi/patches/patch-plugins_python_python__plugin.c @@ -0,0 +1,161 @@ +$NetBSD: patch-plugins_python_python__plugin.c,v 1.1 2023/10/29 18:18:03 wiz Exp $ + +Python 3.12 support +https://github.com/unbit/uwsgi/pull/2542 + +--- plugins/python/python_plugin.c.orig 2023-07-27 15:34:12.000000000 +0000 ++++ plugins/python/python_plugin.c +@@ -197,6 +197,21 @@ void uwsgi_python_pthread_child(void) { + PyMethodDef uwsgi_spit_method[] = { {"uwsgi_spit", py_uwsgi_spit, METH_VARARGS, ""} }; + PyMethodDef uwsgi_write_method[] = { {"uwsgi_write", py_uwsgi_write, METH_VARARGS, ""} }; + ++PyDoc_STRVAR(uwsgi_py_doc, "uWSGI api module."); ++ ++#ifdef PYTHREE ++static PyModuleDef uwsgi_module3 = { ++ PyModuleDef_HEAD_INIT, ++ "uwsgi", ++ uwsgi_py_doc, ++ -1, ++ NULL, ++}; ++PyObject *init_uwsgi3(void) { ++ return PyModule_Create(&uwsgi_module3); ++} ++#endif ++ + int uwsgi_python_init() { + + char *pyversion = strchr(Py_GetVersion(), '\n'); +@@ -261,6 +276,9 @@ pep405: + wchar_t *pname = uwsgi_calloc(sizeof(wchar_t) * (strlen(program_name)+1)); + mbstowcs(pname, program_name, strlen(program_name)+1); + Py_SetProgramName(pname); ++#ifdef UWSGI_PY312 ++ PyImport_AppendInittab("uwsgi", init_uwsgi3); ++#endif + #else + Py_SetProgramName(program_name); + #endif +@@ -623,21 +641,6 @@ next: + + + +-PyDoc_STRVAR(uwsgi_py_doc, "uWSGI api module."); +- +-#ifdef PYTHREE +-static PyModuleDef uwsgi_module3 = { +- PyModuleDef_HEAD_INIT, +- "uwsgi", +- uwsgi_py_doc, +- -1, +- NULL, +-}; +-PyObject *init_uwsgi3(void) { +- return PyModule_Create(&uwsgi_module3); +-} +-#endif +- + void init_uwsgi_embedded_module() { + PyObject *new_uwsgi_module, *zero; + int i; +@@ -658,7 +661,9 @@ void init_uwsgi_embedded_module() { + + + #ifdef PYTHREE ++#ifndef UWSGI_PY312 + PyImport_AppendInittab("uwsgi", init_uwsgi3); ++#endif + new_uwsgi_module = PyImport_AddModule("uwsgi"); + #else + new_uwsgi_module = Py_InitModule3("uwsgi", NULL, uwsgi_py_doc); +@@ -1161,7 +1166,10 @@ void uwsgi_python_init_apps() { + + // prepare for stack suspend/resume + if (uwsgi.async > 1) { +-#ifdef UWSGI_PY311 ++#ifdef UWSGI_PY312 ++ up.current_c_recursion_remaining = uwsgi_malloc(sizeof(int)*uwsgi.async); ++ up.current_py_recursion_remaining = uwsgi_malloc(sizeof(int)*uwsgi.async); ++#elif defined UWSGI_PY311 + up.current_recursion_remaining = uwsgi_malloc(sizeof(int)*uwsgi.async); + #else + up.current_recursion_depth = uwsgi_malloc(sizeof(int)*uwsgi.async); +@@ -1324,7 +1332,12 @@ void uwsgi_python_pre_uwsgi_fork() { + // Acquire the gil and import lock before forking in order to avoid + // deadlocks in workers + UWSGI_GET_GIL ++#if defined UWSGI_PY312 ++ PyInterpreterState *interp = PyInterpreterState_Get(); ++ _PyImport_AcquireLock(interp); ++#else + _PyImport_AcquireLock(); ++#endif + } + } + +@@ -1336,7 +1349,12 @@ void uwsgi_python_post_uwsgi_fork(int st + if (uwsgi.has_threads) { + if (step == 0) { + // Release locks within master process ++#if defined UWSGI_PY312 ++ PyInterpreterState *interp = PyInterpreterState_Get(); ++ _PyImport_ReleaseLock(interp); ++#else + _PyImport_ReleaseLock(); ++#endif + UWSGI_RELEASE_GIL + } + else { +@@ -1592,7 +1610,11 @@ void uwsgi_python_suspend(struct wsgi_re + PyGILState_Release(pgst); + + if (wsgi_req) { +-#ifdef UWSGI_PY311 ++#ifdef UWSGI_PY312 ++ up.current_c_recursion_remaining[wsgi_req->async_id] = tstate->c_recursion_remaining; ++ up.current_py_recursion_remaining[wsgi_req->async_id] = tstate->py_recursion_remaining; ++ up.current_frame[wsgi_req->async_id] = tstate->cframe; ++#elif defined UWSGI_PY311 + up.current_recursion_remaining[wsgi_req->async_id] = tstate->recursion_remaining; + up.current_frame[wsgi_req->async_id] = tstate->cframe; + #else +@@ -1601,7 +1623,11 @@ void uwsgi_python_suspend(struct wsgi_re + #endif + } + else { +-#ifdef UWSGI_PY311 ++#ifdef UWSGI_PY312 ++ up.current_main_c_recursion_remaining = tstate->c_recursion_remaining; ++ up.current_main_py_recursion_remaining = tstate->py_recursion_remaining; ++ up.current_main_frame = tstate->cframe; ++#elif defined UWSGI_PY311 + up.current_main_recursion_remaining = tstate->recursion_remaining; + up.current_main_frame = tstate->cframe; + #else +@@ -1835,7 +1861,11 @@ void uwsgi_python_resume(struct wsgi_req + PyGILState_Release(pgst); + + if (wsgi_req) { +-#ifdef UWSGI_PY311 ++#ifdef UWSGI_PY312 ++ tstate->c_recursion_remaining = up.current_c_recursion_remaining[wsgi_req->async_id]; ++ tstate->py_recursion_remaining = up.current_py_recursion_remaining[wsgi_req->async_id]; ++ tstate->cframe = up.current_frame[wsgi_req->async_id]; ++#elif defined UWSGI_PY311 + tstate->recursion_remaining = up.current_recursion_remaining[wsgi_req->async_id]; + tstate->cframe = up.current_frame[wsgi_req->async_id]; + #else +@@ -1844,7 +1874,11 @@ void uwsgi_python_resume(struct wsgi_req + #endif + } + else { +-#ifdef UWSGI_PY311 ++#ifdef UWSGI_PY312 ++ tstate->c_recursion_remaining = up.current_main_c_recursion_remaining; ++ tstate->py_recursion_remaining = up.current_main_py_recursion_remaining; ++ tstate->cframe = up.current_main_frame; ++#elif defined UWSGI_PY311 + tstate->recursion_remaining = up.current_main_recursion_remaining; + tstate->cframe = up.current_main_frame; + #else diff --git a/www/py-uwsgi/patches/patch-plugins_python_uwsgi__python.h b/www/py-uwsgi/patches/patch-plugins_python_uwsgi__python.h new file mode 100644 index 000000000000..45f522ab523b --- /dev/null +++ b/www/py-uwsgi/patches/patch-plugins_python_uwsgi__python.h @@ -0,0 +1,35 @@ +$NetBSD: patch-plugins_python_uwsgi__python.h,v 1.1 2023/10/29 18:18:03 wiz Exp $ + +Python 3.12 support +https://github.com/unbit/uwsgi/pull/2542 + +--- plugins/python/uwsgi_python.h.orig 2023-07-27 15:34:12.000000000 +0000 ++++ plugins/python/uwsgi_python.h +@@ -21,6 +21,10 @@ + # define UWSGI_PY311 + #endif + ++#if (PY_VERSION_HEX >= 0x030c0000) ++# define UWSGI_PY312 ++#endif ++ + #if PY_MAJOR_VERSION == 2 && PY_MINOR_VERSION < 7 + #define HAS_NOT_PyMemoryView_FromBuffer + #endif +@@ -168,7 +172,15 @@ struct uwsgi_python { + + char *callable; + +-#ifdef UWSGI_PY311 ++#ifdef UWSGI_PY312 ++ int *current_c_recursion_remaining; ++ int *current_py_recursion_remaining; ++ _PyCFrame **current_frame; ++ ++ int current_main_c_recursion_remaining; ++ int current_main_py_recursion_remaining; ++ _PyCFrame *current_main_frame; ++#elif defined UWSGI_PY311 + int *current_recursion_remaining; + _PyCFrame **current_frame; +