diff --git a/build/__native_faster_hexbytes.c b/build/__native_faster_hexbytes.c index e789a56..4c98647 100644 --- a/build/__native_faster_hexbytes.c +++ b/build/__native_faster_hexbytes.c @@ -1,22 +1,22 @@ #ifndef DIFFCHECK_PLACEHOLDER #define DIFFCHECK_PLACEHOLDER 0 #endif -#include "init.c" -#include "getargs.c" -#include "getargsfast.c" -#include "int_ops.c" -#include "float_ops.c" -#include "str_ops.c" -#include "bytes_ops.c" -#include "list_ops.c" -#include "dict_ops.c" -#include "set_ops.c" -#include "tuple_ops.c" -#include "exc_ops.c" -#include "misc_ops.c" -#include "generic_ops.c" -#include "pythonsupport.c" -#include "function_wrapper.c" +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include #include "__native_faster_hexbytes.h" #include "__native_internal_faster_hexbytes.h" static PyMethodDef faster_hexbytesmodule_methods[] = { @@ -4115,6 +4115,7 @@ CPyL125: ; } if (exec_faster_hexbytes__mypyc(module) < 0) { Py_DECREF(module); + module = NULL; return NULL; } return module; diff --git a/build/faster_hexbytes.c b/build/faster_hexbytes.c index f3a5670..78d8c84 100644 --- a/build/faster_hexbytes.c +++ b/build/faster_hexbytes.c @@ -7,7 +7,42 @@ PyMODINIT_FUNC PyInit_faster_hexbytes(void) { PyObject *tmp; - if (!(tmp = PyImport_ImportModule("faster_hexbytes__mypyc"))) return NULL; + // Use ImportModuleLevel with a non-empty fromlist so Python returns the + // leaf submodule via sys.modules lookup, avoiding the top-down getattr + // walk done by PyImport_ImportModule. That walk fails when the shim runs + // during a parent package's __init__.py, because the parent's submodule + // attribute isn't set until after __init__ returns. + static PyObject *fromlist = NULL; + if (!fromlist) { + fromlist = Py_BuildValue("(s)", "*"); + if (!fromlist) return NULL; + } + tmp = PyImport_ImportModuleLevel("faster_hexbytes__mypyc", NULL, NULL, fromlist, 0); + if (!tmp) return NULL; + // Populate cross-group export tables lazily, just before we instantiate + // the per-module real init. Deferring this out of the shared lib's own + // PyInit keeps separate-mode compiled modules from recursively triggering + // sibling-package __init__.py mid-bootstrap. + // PyObject_GetOptionalAttrString would be cleaner, but it's 3.13+ and the + // shim deliberately #includes only , so we can't pull in the + // pythoncapi_compat.h shim from lib-rt here. AttributeError + PyErr_Clear + // is the portable form. + PyObject *deps_capsule = PyObject_GetAttrString(tmp, "ensure_deps"); + if (deps_capsule != NULL) { + int (*deps_func)(void) = (int (*)(void))PyCapsule_GetPointer( + deps_capsule, "faster_hexbytes__mypyc.ensure_deps"); + Py_DECREF(deps_capsule); + if (deps_func == NULL) { + Py_DECREF(tmp); + return NULL; + } + if (deps_func() < 0) { + Py_DECREF(tmp); + return NULL; + } + } else { + PyErr_Clear(); + } PyObject *capsule = PyObject_GetAttrString(tmp, "init_faster_hexbytes"); Py_DECREF(tmp); if (capsule == NULL) return NULL; diff --git a/build/faster_hexbytes/_utils.c b/build/faster_hexbytes/_utils.c index 466da50..600e8dd 100644 --- a/build/faster_hexbytes/_utils.c +++ b/build/faster_hexbytes/_utils.c @@ -4,7 +4,42 @@ PyMODINIT_FUNC PyInit__utils(void) { PyObject *tmp; - if (!(tmp = PyImport_ImportModule("faster_hexbytes__mypyc"))) return NULL; + // Use ImportModuleLevel with a non-empty fromlist so Python returns the + // leaf submodule via sys.modules lookup, avoiding the top-down getattr + // walk done by PyImport_ImportModule. That walk fails when the shim runs + // during a parent package's __init__.py, because the parent's submodule + // attribute isn't set until after __init__ returns. + static PyObject *fromlist = NULL; + if (!fromlist) { + fromlist = Py_BuildValue("(s)", "*"); + if (!fromlist) return NULL; + } + tmp = PyImport_ImportModuleLevel("faster_hexbytes__mypyc", NULL, NULL, fromlist, 0); + if (!tmp) return NULL; + // Populate cross-group export tables lazily, just before we instantiate + // the per-module real init. Deferring this out of the shared lib's own + // PyInit keeps separate-mode compiled modules from recursively triggering + // sibling-package __init__.py mid-bootstrap. + // PyObject_GetOptionalAttrString would be cleaner, but it's 3.13+ and the + // shim deliberately #includes only , so we can't pull in the + // pythoncapi_compat.h shim from lib-rt here. AttributeError + PyErr_Clear + // is the portable form. + PyObject *deps_capsule = PyObject_GetAttrString(tmp, "ensure_deps"); + if (deps_capsule != NULL) { + int (*deps_func)(void) = (int (*)(void))PyCapsule_GetPointer( + deps_capsule, "faster_hexbytes__mypyc.ensure_deps"); + Py_DECREF(deps_capsule); + if (deps_func == NULL) { + Py_DECREF(tmp); + return NULL; + } + if (deps_func() < 0) { + Py_DECREF(tmp); + return NULL; + } + } else { + PyErr_Clear(); + } PyObject *capsule = PyObject_GetAttrString(tmp, "init_faster_hexbytes____utils"); Py_DECREF(tmp); if (capsule == NULL) return NULL; diff --git a/build/faster_hexbytes/main.c b/build/faster_hexbytes/main.c index 54a5b09..cf3af33 100644 --- a/build/faster_hexbytes/main.c +++ b/build/faster_hexbytes/main.c @@ -4,7 +4,42 @@ PyMODINIT_FUNC PyInit_main(void) { PyObject *tmp; - if (!(tmp = PyImport_ImportModule("faster_hexbytes__mypyc"))) return NULL; + // Use ImportModuleLevel with a non-empty fromlist so Python returns the + // leaf submodule via sys.modules lookup, avoiding the top-down getattr + // walk done by PyImport_ImportModule. That walk fails when the shim runs + // during a parent package's __init__.py, because the parent's submodule + // attribute isn't set until after __init__ returns. + static PyObject *fromlist = NULL; + if (!fromlist) { + fromlist = Py_BuildValue("(s)", "*"); + if (!fromlist) return NULL; + } + tmp = PyImport_ImportModuleLevel("faster_hexbytes__mypyc", NULL, NULL, fromlist, 0); + if (!tmp) return NULL; + // Populate cross-group export tables lazily, just before we instantiate + // the per-module real init. Deferring this out of the shared lib's own + // PyInit keeps separate-mode compiled modules from recursively triggering + // sibling-package __init__.py mid-bootstrap. + // PyObject_GetOptionalAttrString would be cleaner, but it's 3.13+ and the + // shim deliberately #includes only , so we can't pull in the + // pythoncapi_compat.h shim from lib-rt here. AttributeError + PyErr_Clear + // is the portable form. + PyObject *deps_capsule = PyObject_GetAttrString(tmp, "ensure_deps"); + if (deps_capsule != NULL) { + int (*deps_func)(void) = (int (*)(void))PyCapsule_GetPointer( + deps_capsule, "faster_hexbytes__mypyc.ensure_deps"); + Py_DECREF(deps_capsule); + if (deps_func == NULL) { + Py_DECREF(tmp); + return NULL; + } + if (deps_func() < 0) { + Py_DECREF(tmp); + return NULL; + } + } else { + PyErr_Clear(); + } PyObject *capsule = PyObject_GetAttrString(tmp, "init_faster_hexbytes___main"); Py_DECREF(tmp); if (capsule == NULL) return NULL; diff --git a/pyproject.toml b/pyproject.toml index 5d3868f..7fd947c 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,5 +1,5 @@ [build-system] -requires = ["setuptools", "wheel", "mypy[mypyc]==2.0.0", "hexbytes==1.3.1"] +requires = ["setuptools", "wheel", "mypy[mypyc]==2.1.0", "hexbytes==1.3.1"] build-backend = "setuptools.build_meta" [tool.autoflake] diff --git a/setup.py b/setup.py index aae897b..cddd4e3 100644 --- a/setup.py +++ b/setup.py @@ -15,7 +15,7 @@ "build>=0.9.0", "bump_my_version>=0.19.0", "ipython", - "mypy==2.0.0", + "mypy==2.1.0", "pre-commit>=3.4.0", "tox>=4.0.0", "twine",