Skip to content

Commit d8e0d36

Browse files
authored
build: Fix free-threaded build, mark speedups module as no-GIL
1 parent bfe7489 commit d8e0d36

File tree

2 files changed

+20
-4
lines changed

2 files changed

+20
-4
lines changed

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@
5151
# Use the stable ABI so our wheels are compatible across python
5252
# versions.
5353
py_limited_api=can_use_limited_api,
54-
define_macros=[("Py_LIMITED_API", "0x03090000")],
54+
define_macros=[("Py_LIMITED_API", "0x03090000")] if can_use_limited_api else [],
5555
)
5656
]
5757

tornado/speedups.c

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,20 +51,36 @@ static PyObject* websocket_mask(PyObject* self, PyObject* args) {
5151
return result;
5252
}
5353

54+
static int speedups_exec(PyObject *module) {
55+
return 0;
56+
}
57+
5458
static PyMethodDef methods[] = {
5559
{"websocket_mask", websocket_mask, METH_VARARGS, ""},
5660
{NULL, NULL, 0, NULL}
5761
};
5862

63+
static PyModuleDef_Slot slots[] = {
64+
{Py_mod_exec, speedups_exec},
65+
#if (!defined(Py_LIMITED_API) && PY_VERSION_HEX >= 0x030c0000) || Py_LIMITED_API >= 0x030c0000
66+
{Py_mod_multiple_interpreters, Py_MOD_PER_INTERPRETER_GIL_SUPPORTED},
67+
#endif
68+
#if (!defined(Py_LIMITED_API) && PY_VERSION_HEX >= 0x030d0000) || Py_LIMITED_API >= 0x030d0000
69+
{Py_mod_gil, Py_MOD_GIL_NOT_USED},
70+
#endif
71+
{0, NULL}
72+
};
73+
5974
static struct PyModuleDef speedupsmodule = {
6075
PyModuleDef_HEAD_INIT,
6176
"speedups",
6277
NULL,
63-
-1,
64-
methods
78+
0,
79+
methods,
80+
slots,
6581
};
6682

6783
PyMODINIT_FUNC
6884
PyInit_speedups(void) {
69-
return PyModule_Create(&speedupsmodule);
85+
return PyModuleDef_Init(&speedupsmodule);
7086
}

0 commit comments

Comments
 (0)