Skip to content

Commit

Permalink
added python3.13t (free threading) support
Browse files Browse the repository at this point in the history
  • Loading branch information
westandskif committed Sep 1, 2024
1 parent 48b0cf7 commit 0b26b07
Show file tree
Hide file tree
Showing 8 changed files with 41 additions and 23 deletions.
2 changes: 1 addition & 1 deletion .ccls
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
clang
-I/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include
-I/Users/nik/.pyenv/versions/convtools-3.10/include
-I/Users/nik/.pyenv/versions/3.10.9/include/python3.10
-I/Users/nik/.pyenv/versions/3.10.14/include/python3.10
4 changes: 3 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@


install:
poetry install --with=test,lint,docs
find src/convtools -type f -name "*.so" -delete
pip install -e .
ls -la src/convtools

dynamic_docs_examples:
python build-docs-examples.py
Expand Down
4 changes: 4 additions & 0 deletions docs/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 1.14.1 (2024-09-01)

- python 3.13t (free threading) support

## 1.14.0 (2024-09-01)

- added `c.unordered_chunk_by`
Expand Down
3 changes: 0 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,6 @@ lint = [
"mypy",
"pylint",
]
build = [
"hatch",
]
doc = [
"markdown-include",
"mdx-truly-sane-lists",
Expand Down
4 changes: 0 additions & 4 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,3 @@ install_requires =

[options.packages.find]
where=src

[bdist_wheel]
py_limited_api = cp310

19 changes: 14 additions & 5 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,15 @@


ext_modules = []
setup_kwargs = {}
ext_kwargs = {}
is_free_threading = "t" in sys.abiflags

if not is_free_threading:
ext_kwargs["py_limited_api"] = True
ext_kwargs["define_macros"] = [("Py_LIMITED_API", 0x03A00000)]
opts = setup_kwargs.setdefault("options", {})
opts["bdist_wheel"] = {"py_limited_api": "cp310"}

if (
sys.implementation.name == "cpython"
Expand All @@ -13,17 +22,17 @@
):
ext_modules.append(
Extension(
name="convtools._cext", # as it would be imported
sources=[
"src/convtools/c_extensions/getters.c"
], # all sources are compiled into a single binary file
name="convtools._cext",
sources=["src/convtools/c_extensions/getters.c"],
optional=True,
py_limited_api=True,
extra_compile_args=["-w"],
**ext_kwargs,
)
)


setup(
ext_modules=ext_modules,
packages=find_packages("src", exclude=["tests"]),
**setup_kwargs,
)
2 changes: 1 addition & 1 deletion src/convtools/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@
from ._dt import DateGrid, DateTimeGrid


__version__ = "1.14.0"
__version__ = "1.14.1"
26 changes: 18 additions & 8 deletions src/convtools/c_extensions/getters.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#define Py_LIMITED_API 0x03A00000
#define PY_SSIZE_T_CLEAN /* Make "s#" use Py_ssize_t rather than int. */
#include <Python.h>

Expand Down Expand Up @@ -140,7 +139,7 @@ static PyObject *get_attr_deep_default_callable(PyObject *self,
}
}

static PyMethodDef CExtMethods[] = {
static PyMethodDef cext_methods[] = {
{"get_item_deep_default_simple", (PyCFunction)get_item_deep_default_simple,
METH_FASTCALL, "c-level fail-safe __getitem__ with default"},
{"get_item_deep_default_callable",
Expand All @@ -155,13 +154,24 @@ static PyMethodDef CExtMethods[] = {
{NULL, NULL, 0, NULL} /* Sentinel */
};
static struct PyModuleDef cext_module = {
PyModuleDef_HEAD_INIT, "_cext", /* name of module */
NULL, /* module documentation, may be NULL */
-1, /* size of per-interpreter state of the module,
or -1 if the module keeps state in global variables. */
CExtMethods};
PyModuleDef_HEAD_INIT,
"_cext", /* name of module */
NULL, /* module documentation, may be NULL */
-1, /* size of per-interpreter state of the module,
or -1 if the module keeps state in global variables. */
cext_methods,
};

PyMODINIT_FUNC PyInit__cext(void) { return PyModule_Create(&cext_module); };
PyMODINIT_FUNC PyInit__cext(void) {
PyObject *module = PyModule_Create(&cext_module);
if (module == NULL) {
return NULL;
}
#ifdef Py_GIL_DISABLED
PyUnstable_Module_SetGIL(module, Py_MOD_GIL_NOT_USED);
#endif
return module;
};

// PySys_WriteStdout(PyUnicode_AsUTF8AndSize(PyObject_Repr(config), NULL));
// PySys_WriteStdout("DBG2 ref count: %i\n", (int)context->tuple->ob_refcnt);

0 comments on commit 0b26b07

Please sign in to comment.