Skip to content

Commit

Permalink
Add test for free-threaded build
Browse files Browse the repository at this point in the history
  • Loading branch information
adang1345 committed Sep 30, 2024
1 parent 9221a93 commit c33542c
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 1 deletion.
4 changes: 4 additions & 0 deletions tests/run_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -1297,6 +1297,10 @@ def test_signed(self):
check_call(['delvewheel', 'repair', '--add-path', 'simpleext/x64', 'simpleext/simpleext-0.0.1-0sign-cp312-cp312-win_amd64.whl'])
self.assertTrue(import_simpleext_successful('0sign'))

def test_free_threaded(self):
"""Free-threaded wheel can be repaired"""
check_call(['delvewheel', 'repair', '--add-path', 'simpleext/x64', 'simpleext/simpleext-0.0.1-cp313-cp313t-win_amd64.whl'])


class NeededTestCase(unittest.TestCase):
"""Tests for delvewheel needed"""
Expand Down
3 changes: 3 additions & 0 deletions tests/simpleext/build/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
py_limited_api = False # set to True and add --py-limited-api=cp3__ to command line to build with Python limited API
dependent_load_flags = '0' # change to set a different /DEPENDENTLOADFLAG linker option
checksum = False # change to True to set the PE checksum
free_threaded = False # change to True to support free-threading

if sys.maxsize > 2**32:
library_dirs = ['simpledll/x64/Release']
Expand All @@ -21,6 +22,8 @@
python_requires = f">={py_major}.{py_minor}"
else:
python_requires = f"=={py_major}.{py_minor}.*"
if free_threaded:
define_macros.append(('Py_GIL_DISABLED', '1'))
extra_link_args = [f'/DEPENDENTLOADFLAG:{dependent_load_flags}']
if checksum:
extra_link_args.append('/RELEASE')
Expand Down
7 changes: 6 additions & 1 deletion tests/simpleext/build/simpleext.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,10 @@ static struct PyModuleDef simpleextmodule = {

PyMODINIT_FUNC SIMPLEEXT_INIT(void)
{
return PyModule_Create(&simpleextmodule);
PyObject *m = PyModule_Create(&simpleextmodule);
if (!m) return NULL;
#ifdef Py_GIL_DISABLED
PyUnstable_Module_SetGIL(m, Py_MOD_GIL_NOT_USED);
#endif
return m;
}
Binary file not shown.

0 comments on commit c33542c

Please sign in to comment.