diff --git a/bindings/python/tree_sitter_ruby/binding.c b/bindings/python/tree_sitter_ruby/binding.c index 6a02dfd1..2d01d92d 100644 --- a/bindings/python/tree_sitter_ruby/binding.c +++ b/bindings/python/tree_sitter_ruby/binding.c @@ -8,6 +8,13 @@ static PyObject* _binding_language(PyObject *Py_UNUSED(self), PyObject *Py_UNUSE return PyCapsule_New(tree_sitter_ruby(), "tree_sitter.Language", NULL); } +static struct PyModuleDef_Slot slots[] = { +#ifdef Py_GIL_DISABLED + {Py_mod_gil, Py_MOD_GIL_NOT_USED}, +#endif + {0, NULL} +}; + static PyMethodDef methods[] = { {"language", _binding_language, METH_NOARGS, "Get the tree-sitter language for this grammar."}, @@ -18,10 +25,11 @@ static struct PyModuleDef module = { .m_base = PyModuleDef_HEAD_INIT, .m_name = "_binding", .m_doc = NULL, - .m_size = -1, - .m_methods = methods + .m_size = 0, + .m_methods = methods, + .m_slots = slots, }; PyMODINIT_FUNC PyInit__binding(void) { - return PyModule_Create(&module); + return PyModuleDef_Init(&module); } diff --git a/setup.py b/setup.py index 2c0384fa..e65f9b37 100644 --- a/setup.py +++ b/setup.py @@ -1,5 +1,6 @@ from os.path import isdir, join from platform import system +from sysconfig import get_config_var from setuptools import Extension, find_packages, setup from setuptools.command.build import build @@ -17,7 +18,7 @@ def run(self): class BdistWheel(bdist_wheel): def get_tag(self): python, abi, platform = super().get_tag() - if python.startswith("cp"): + if python.startswith("cp") and not get_config_var("Py_GIL_DISABLED"): python, abi = "cp39", "abi3" return python, abi, platform @@ -46,12 +47,11 @@ def get_tag(self): "/utf-8", ], define_macros=[ - ("Py_LIMITED_API", "0x03090000"), ("PY_SSIZE_T_CLEAN", None), ("TREE_SITTER_HIDE_SYMBOLS", None), - ], + ] + ([("Py_LIMITED_API", "0x03090000")] if not get_config_var("Py_GIL_DISABLED") else []), include_dirs=["src"], - py_limited_api=True, + py_limited_api=not get_config_var("Py_GIL_DISABLED"), ) ], cmdclass={