Commit e0018d6
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_01EoWzUsmRRvrZBF2nwQhF951 parent 6397302 commit e0018d6
3 files changed
Lines changed: 269 additions & 25 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
25 | 25 | | |
26 | 26 | | |
27 | 27 | | |
28 | | - | |
| 28 | + | |
29 | 29 | | |
30 | 30 | | |
31 | 31 | | |
32 | 32 | | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
33 | 52 | | |
34 | | - | |
| 53 | + | |
35 | 54 | | |
36 | 55 | | |
37 | 56 | | |
38 | 57 | | |
39 | | - | |
40 | | - | |
41 | | - | |
42 | | - | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
43 | 69 | | |
44 | 70 | | |
45 | 71 | | |
| |||
51 | 77 | | |
52 | 78 | | |
53 | 79 | | |
54 | | - | |
| 80 | + | |
55 | 81 | | |
56 | 82 | | |
57 | 83 | | |
58 | | - | |
59 | | - | |
60 | | - | |
61 | | - | |
| 84 | + | |
| 85 | + | |
62 | 86 | | |
63 | 87 | | |
64 | | - | |
| 88 | + | |
65 | 89 | | |
66 | 90 | | |
67 | 91 | | |
68 | 92 | | |
69 | 93 | | |
70 | 94 | | |
71 | | - | |
| 95 | + | |
72 | 96 | | |
73 | 97 | | |
74 | 98 | | |
75 | 99 | | |
76 | | - | |
| 100 | + | |
77 | 101 | | |
78 | 102 | | |
79 | 103 | | |
| |||
82 | 106 | | |
83 | 107 | | |
84 | 108 | | |
85 | | - | |
| 109 | + | |
86 | 110 | | |
87 | 111 | | |
88 | 112 | | |
| |||
0 commit comments