From 85e9cda72b5f045e8444f0bce21513e487ef4f7e Mon Sep 17 00:00:00 2001 From: Lele Gaifax Date: Fri, 22 Aug 2025 11:15:23 +0200 Subject: [PATCH 1/3] Support the "free-threaded" variant of Python (PEP-703) DISCLAIMER: at this point, this is just an experiment, so don't rely on this branch unless you know what you are doing. --- rapidjson.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/rapidjson.cpp b/rapidjson.cpp index 40ce8fa..e0b6b27 100644 --- a/rapidjson.cpp +++ b/rapidjson.cpp @@ -3,7 +3,7 @@ // :Author: Ken Robbins // :License: MIT License // :Copyright: © 2015 Ken Robbins -// :Copyright: © 2015, 2016, 2017, 2018, 2019, 2020, 2021, 2022, 2023, 2024 Lele Gaifax +// :Copyright: © 2015, 2016, 2017, 2018, 2019, 2020, 2021, 2022, 2023, 2024, 2025 Lele Gaifax // #include @@ -4117,6 +4117,9 @@ module_exec(PyObject* m) static struct PyModuleDef_Slot slots[] = { {Py_mod_exec, (void*) module_exec}, +#ifdef Py_GIL_DISABLED + {Py_mod_gil, Py_MOD_GIL_NOT_USED}, +#endif {0, NULL} }; From fe16103e15cd987420845dda4e114699473775f8 Mon Sep 17 00:00:00 2001 From: Lele Gaifax Date: Fri, 22 Aug 2025 11:23:34 +0200 Subject: [PATCH 2/3] Skip the recursion limit test under free-threaded variant --- tests/test_circular.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/tests/test_circular.py b/tests/test_circular.py index 89e15b3..1a64935 100644 --- a/tests/test_circular.py +++ b/tests/test_circular.py @@ -3,7 +3,7 @@ # :Author: John Anderson # :License: MIT License # :Copyright: © 2015 John Anderson -# :Copyright: © 2017, 2018, 2020, 2023, 2024 Lele Gaifax +# :Copyright: © 2017, 2018, 2020, 2023, 2024, 2025 Lele Gaifax # import sys @@ -74,6 +74,10 @@ def test_max_recursion_depth(dumps): sys.setrecursionlimit(rl) +@pytest.mark.skipif( + not sys._is_gil_enabled(), + reason="Crashes under free-threaded variant, perhaps getrecursionlimit() works differently there?" +) def test_parse_respects_recursion_limit(loads): rl = sys.getrecursionlimit() From 87984832afc482de6ba22c97676a352876bcf88e Mon Sep 17 00:00:00 2001 From: Lele Gaifax Date: Fri, 22 Aug 2025 11:24:29 +0200 Subject: [PATCH 3/3] Skip the tracemalloc-based tests under free-threaded variant --- tests/test_memory_leaks.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/tests/test_memory_leaks.py b/tests/test_memory_leaks.py index 51b5a55..1205fd7 100644 --- a/tests/test_memory_leaks.py +++ b/tests/test_memory_leaks.py @@ -9,10 +9,15 @@ import io import datetime import gc +import sys import pytest import rapidjson as rj +pytestmark = pytest.mark.skipif( + not sys._is_gil_enabled(), + reason="Crashes under free-threaded variant, perhaps tracemalloc does not work there?" +) tracemalloc = pytest.importorskip("tracemalloc")