Skip to content

Commit e0018d6

Browse files
committed
Fix free-threading builds: convert to heap types on Python 3.13+
Convert Scanner and Encoder from static PyTypeObject to heap types via PyType_FromSpec on Python 3.13+, fixing SIGSEGV crashes on Python 3.14t (free-threaded) builds across macOS and Windows. Changes to _speedups.c (all guarded by #if PY_VERSION_HEX >= 0x030D0000): - Add _speedups_state module state struct holding heap type objects - Create heap types from PyType_Spec in module_exec (multi-phase init) - Proper heap type lifecycle: save tp before tp_free, Py_DECREF(tp) in dealloc; Py_VISIT(Py_TYPE(self)) in traverse - Add speedups_traverse/speedups_clear for module state GC - Declare Py_mod_gil = Py_MOD_GIL_NOT_USED for free-threaded Python - Guard PyScanner_Check/PyEncoder_Check macros for pre-3.13 only - Pre-3.13 code paths remain completely unchanged Changes to CI: - Update cibuildwheel v3.2.1 -> v3.4.1 with CIBW_ENABLE for free-threading wheel builds - Add dedicated test_free_threading CI job for Python 3.14t - Parallelize Linux wheel builds by architecture - Update actions/setup-python to v5.6.0 Tests: - Add TestHeapTypes class verifying Py_TPFLAGS_HEAPTYPE, GC tracking, and basic encode/decode functionality on 3.13+ https://claude.ai/code/session_01EoWzUsmRRvrZBF2nwQhF95
1 parent 6397302 commit e0018d6

3 files changed

Lines changed: 269 additions & 25 deletions

File tree

.github/workflows/build-and-deploy.yml

Lines changed: 39 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -25,21 +25,47 @@ jobs:
2525
- graalpy-25.0
2626
steps:
2727
- uses: actions/checkout@v4
28-
- uses: actions/setup-python@v5
28+
- uses: actions/setup-python@v5.6.0
2929
with:
3030
python-version: ${{ matrix.python }}
3131
- run: python -m simplejson.tests._cibw_runner .
3232

33+
test_free_threading:
34+
name: Tests with free-threading on Python 3.14t
35+
runs-on: ubuntu-latest
36+
steps:
37+
- uses: actions/checkout@v4
38+
- uses: actions/setup-python@v5.6.0.6.0
39+
with:
40+
python-version: '3.14t'
41+
- name: Build extension with free-threading support
42+
run: |
43+
python -m pip install --upgrade pip setuptools wheel
44+
REQUIRE_SPEEDUPS=1 python setup.py build_ext -i
45+
- name: Verify GIL-free import (no RuntimeWarning)
46+
run: PYTHON_GIL=0 python -W error::RuntimeWarning -c "import simplejson._speedups"
47+
- name: Run tests
48+
run: python -m simplejson.tests._cibw_runner .
49+
- name: Run tests with GIL disabled
50+
run: PYTHON_GIL=0 python -m simplejson.tests._cibw_runner .
51+
3352
build_wheels:
34-
name: Build wheels on ${{ matrix.os }}
53+
name: Build wheels (${{ matrix.os }}, ${{ matrix.arch }})
3554
runs-on: ${{ matrix.os }}
3655
strategy:
3756
fail-fast: false
3857
matrix:
39-
os:
40-
- 'ubuntu-latest'
41-
- 'windows-latest'
42-
- 'macos-latest'
58+
include:
59+
- os: ubuntu-latest
60+
arch: x86_64
61+
- os: ubuntu-latest
62+
arch: aarch64
63+
- os: ubuntu-latest
64+
arch: ppc64le
65+
- os: windows-latest
66+
arch: auto
67+
- os: macos-latest
68+
arch: "x86_64 universal2 arm64"
4369

4470
steps:
4571
- uses: actions/checkout@v4
@@ -51,29 +77,27 @@ jobs:
5177
platforms: all
5278

5379
- name: Build wheels
54-
uses: pypa/cibuildwheel@v3.2.1
80+
uses: pypa/cibuildwheel@v3.4.1
5581
env:
5682
CIBW_TEST_COMMAND: >-
5783
python -m simplejson.tests._cibw_runner "{project}"
58-
CIBW_SKIP: "pp*"
59-
CIBW_ARCHS_WINDOWS: "auto"
60-
CIBW_ARCHS_LINUX: "auto aarch64 ppc64le"
61-
CIBW_ARCHS_MACOS: "x86_64 universal2 arm64"
84+
CIBW_ENABLE: "cpython-freethreading"
85+
CIBW_ARCHS: ${{ matrix.arch }}
6286

6387
- name: Build Python 2.7 wheels
64-
if: runner.os == 'Linux'
88+
if: runner.os == 'Linux' && matrix.arch != 'ppc64le'
6589
uses: pypa/cibuildwheel@v1.12.0
6690
env:
6791
CIBW_TEST_COMMAND: >-
6892
python -m simplejson.tests._cibw_runner "{project}"
6993
CIBW_BUILD: "cp27-*"
7094
CIBW_SKIP: "pp*"
71-
CIBW_ARCHS_LINUX: "auto aarch64"
95+
CIBW_ARCHS_LINUX: ${{ matrix.arch }}
7296

7397
- uses: actions/upload-artifact@v4
7498
if: github.event_name == 'push' && startsWith(github.event.ref, 'refs/tags/')
7599
with:
76-
name: wheels-${{ matrix.os }}
100+
name: wheels-${{ matrix.os }}-${{ matrix.arch }}
77101
path: ./wheelhouse/*.whl
78102

79103
build_sdist:
@@ -82,7 +106,7 @@ jobs:
82106
steps:
83107
- uses: actions/checkout@v4
84108

85-
- uses: actions/setup-python@v5
109+
- uses: actions/setup-python@v5.6.0
86110
name: Install Python
87111
with:
88112
python-version: '3.14'

0 commit comments

Comments
 (0)