From d8e0d36ebad1a042866a9355959e99e0bf90a3c0 Mon Sep 17 00:00:00 2001 From: Lysandros Nikolaou Date: Thu, 1 May 2025 20:42:30 +0200 Subject: [PATCH] build: Fix free-threaded build, mark speedups module as no-GIL --- setup.py | 2 +- tornado/speedups.c | 22 +++++++++++++++++++--- 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/setup.py b/setup.py index de6cd3f0a..e2a699124 100644 --- a/setup.py +++ b/setup.py @@ -51,7 +51,7 @@ if ( # Use the stable ABI so our wheels are compatible across python # versions. py_limited_api=can_use_limited_api, - define_macros=[("Py_LIMITED_API", "0x03090000")], + define_macros=[("Py_LIMITED_API", "0x03090000")] if can_use_limited_api else [], ) ] diff --git a/tornado/speedups.c b/tornado/speedups.c index 525d66034..992c29c15 100644 --- a/tornado/speedups.c +++ b/tornado/speedups.c @@ -51,20 +51,36 @@ static PyObject* websocket_mask(PyObject* self, PyObject* args) { return result; } +static int speedups_exec(PyObject *module) { + return 0; +} + static PyMethodDef methods[] = { {"websocket_mask", websocket_mask, METH_VARARGS, ""}, {NULL, NULL, 0, NULL} }; +static PyModuleDef_Slot slots[] = { + {Py_mod_exec, speedups_exec}, +#if (!defined(Py_LIMITED_API) && PY_VERSION_HEX >= 0x030c0000) || Py_LIMITED_API >= 0x030c0000 + {Py_mod_multiple_interpreters, Py_MOD_PER_INTERPRETER_GIL_SUPPORTED}, +#endif +#if (!defined(Py_LIMITED_API) && PY_VERSION_HEX >= 0x030d0000) || Py_LIMITED_API >= 0x030d0000 + {Py_mod_gil, Py_MOD_GIL_NOT_USED}, +#endif + {0, NULL} +}; + static struct PyModuleDef speedupsmodule = { PyModuleDef_HEAD_INIT, "speedups", NULL, - -1, - methods + 0, + methods, + slots, }; PyMODINIT_FUNC PyInit_speedups(void) { - return PyModule_Create(&speedupsmodule); + return PyModuleDef_Init(&speedupsmodule); } -- 2.47.3