diff --git a/.github/workflows/coverage.yml b/.github/workflows/coverage.yml index e4e2f49a..ff9719c9 100644 --- a/.github/workflows/coverage.yml +++ b/.github/workflows/coverage.yml @@ -10,7 +10,7 @@ jobs: strategy: matrix: os: [ubuntu-24.04] - python-version: [pypy3.11, "graalpy-25.0", "3.x"] + python-version: [pypy3.11, "3.x"] steps: - uses: actions/checkout@v6 with: diff --git a/gmp.c b/gmp.c index 657cf852..f52bd1af 100644 --- a/gmp.c +++ b/gmp.c @@ -7,11 +7,7 @@ #include #include -#if !defined(PYPY_VERSION) -# define MAX_CACHE_SIZE 100 -#else -# define MAX_CACHE_SIZE 0 -#endif +#define MAX_CACHE_SIZE 100 #define MAX_CACHED_NDIGITS 16 typedef struct { @@ -34,7 +30,6 @@ MPZ_new(void) if (global.gmp_cache_size) { res = global.gmp_cache[--global.gmp_cache_size]; (void)zz_set(0, &res->z); - Py_XINCREF((PyObject *)res); } else { res = PyObject_New(MPZ_Object, &MPZ_Type); @@ -683,6 +678,17 @@ new(PyTypeObject *type, PyObject *args, PyObject *keywds) return new_impl(type, arg, base); } +static void +finalize(PyObject *self) +{ + if (global.gmp_cache_size < MAX_CACHE_SIZE + && (((MPZ_Object *)self)->z).alloc <= MAX_CACHED_NDIGITS + && MPZ_CheckExact(self)) + { + Py_INCREF(self); + } +} + typedef void (*Py_tp_free_func)(void *); static void @@ -690,10 +696,7 @@ dealloc(PyObject *self) { MPZ_Object *u = (MPZ_Object *)self; - if (global.gmp_cache_size < MAX_CACHE_SIZE - && (u->z).alloc <= MAX_CACHED_NDIGITS - && MPZ_CheckExact(self)) - { + if (PyObject_CallFinalizerFromDealloc(self)) { global.gmp_cache[global.gmp_cache_size++] = u; } else { @@ -2098,6 +2101,7 @@ PyTypeObject MPZ_Type = { .tp_basicsize = sizeof(MPZ_Object), .tp_new = new, .tp_dealloc = dealloc, + .tp_finalize = finalize, .tp_repr = repr, .tp_str = str, .tp_richcompare = richcompare, diff --git a/pyproject.toml b/pyproject.toml index 1bbf790c..9cd66813 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -63,8 +63,7 @@ select = ["E", "F", "I", "PT", "W", "Q", "SIM"] [tool.cibuildwheel] build-frontend = {name="build", args=["--verbose", "-Csetup-args=--vsenv"]} -enable = "pypy cpython-prerelease cpython-freethreading graalpy" -skip = "gp311_242* gp3*win*amd64*" +enable = "pypy cpython-prerelease cpython-freethreading" before-all = "sh scripts/cibw_before_all.sh" test-extras = "ci"