From dc2980fc3e7eaaa0648c90b22443bf5b24273886 Mon Sep 17 00:00:00 2001 From: Sergey B Kirpichev Date: Tue, 30 Jun 2026 08:19:07 +0300 Subject: [PATCH 1/8] Drop redundant typedefs --- gmp.c | 24 +++++++++--------------- 1 file changed, 9 insertions(+), 15 deletions(-) diff --git a/gmp.c b/gmp.c index 43c58bba..e6383dcb 100644 --- a/gmp.c +++ b/gmp.c @@ -34,7 +34,7 @@ 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); + Py_INCREF((PyObject *)res); } else { res = PyObject_New(MPZ_Object, &MPZ_Type); @@ -486,8 +486,6 @@ MPZ_from_bytes(PyObject *obj, int is_little, int is_signed) return res; } -typedef PyObject * (*Py_nb_int_func)(PyObject *); - static PyObject * new_impl(PyTypeObject *Py_UNUSED(type), PyObject *arg, PyObject *base_arg) { @@ -506,7 +504,7 @@ new_impl(PyTypeObject *Py_UNUSED(type), PyObject *arg, PyObject *base_arg) # pragma GCC diagnostic push # pragma GCC diagnostic ignored "-Wpedantic" #endif - Py_nb_int_func nb_int = PyType_GetSlot(Py_TYPE(arg), Py_nb_int); + unaryfunc nb_int = PyType_GetSlot(Py_TYPE(arg), Py_nb_int); #ifdef __GNUC__ # pragma GCC diagnostic pop #endif @@ -648,8 +646,6 @@ new(PyTypeObject *type, PyObject *args, PyObject *keywds) return new_impl(type, arg, base); } -typedef void (*Py_tp_free_func)(void *); - static void dealloc(PyObject *self) { @@ -662,22 +658,23 @@ dealloc(PyObject *self) global.gmp_cache[global.gmp_cache_size++] = u; } else { - zz_clear(&u->z); + freefunc tp_free; + if (MPZ_CheckExact(self)) { - PyObject_Free(self); + tp_free = PyObject_Free; } else { #ifdef __GNUC__ # pragma GCC diagnostic push # pragma GCC diagnostic ignored "-Wpedantic" #endif - Py_tp_free_func tp_free = PyType_GetSlot(Py_TYPE(self), Py_tp_free); + tp_free = PyType_GetSlot(Py_TYPE(self), Py_tp_free); #ifdef __GNUC__ # pragma GCC diagnostic pop #endif - - tp_free(self); } + zz_clear(&u->z); + tp_free(self); } } @@ -1409,8 +1406,6 @@ zz_rshift(const zz_t *u, const zz_t *v, zz_t *w) BINOP_INT(lshift) BINOP_INT(rshift) -typedef PyObject * (*Py_nb_power_func)(PyObject *, PyObject *, PyObject *); - static PyObject * power(PyObject *self, PyObject *other, PyObject *module) { @@ -1440,8 +1435,7 @@ power(PyObject *self, PyObject *other, PyObject *module) # pragma GCC diagnostic push # pragma GCC diagnostic ignored "-Wpedantic" #endif - Py_nb_power_func nb_power = PyType_GetSlot(&PyFloat_Type, - Py_nb_power); + ternaryfunc nb_power = PyType_GetSlot(&PyFloat_Type, Py_nb_power); #ifdef __GNUC__ # pragma GCC diagnostic pop #endif From 19ef24997c81a130e7faaf0e42b0176912a1e68d Mon Sep 17 00:00:00 2001 From: Sergey B Kirpichev Date: Wed, 1 Jul 2026 04:11:44 +0300 Subject: [PATCH 2/8] Try GraalPy v25.1.3 --- .github/workflows/coverage.yml | 2 +- tests/test_functions.py | 3 --- tests/test_mpz.py | 2 -- 3 files changed, 1 insertion(+), 6 deletions(-) diff --git a/.github/workflows/coverage.yml b/.github/workflows/coverage.yml index f5292d90..c8faf116 100644 --- a/.github/workflows/coverage.yml +++ b/.github/workflows/coverage.yml @@ -9,7 +9,7 @@ jobs: strategy: matrix: os: [ubuntu-24.04] - python-version: [pypy3.11, "graalpy-25.0", "3.x"] + python-version: [pypy3.11, "graalpy-25.1", "3.x"] steps: - uses: actions/checkout@v6 with: diff --git a/tests/test_functions.py b/tests/test_functions.py index d89efc3c..c8e7b20e 100644 --- a/tests/test_functions.py +++ b/tests/test_functions.py @@ -1,6 +1,5 @@ import inspect import math -import platform import gmp import pytest @@ -235,8 +234,6 @@ def test_interfaces(): _mpmath_normalize(1, mpz(111), 11, 12, 13, 1j) -@pytest.mark.skipif(platform.python_implementation() == "GraalVM", - reason="oracle/graalpython#593") def test_func_api(): for fn in ["comb", "factorial", "gcd", "isqrt", "lcm", "perm"]: f = getattr(math, fn) diff --git a/tests/test_mpz.py b/tests/test_mpz.py index ab89ca49..51a84266 100644 --- a/tests/test_mpz.py +++ b/tests/test_mpz.py @@ -1076,8 +1076,6 @@ def f(n): assert all(f.result() == 1 for f in futures) -@pytest.mark.skipif(platform.python_implementation() == "GraalVM", - reason="oracle/graalpython#593") def test_int_api(): for meth in dir(int): m = getattr(int, meth) From d7f9a211d9c25bebec6196b0564cf68d1f61ccd5 Mon Sep 17 00:00:00 2001 From: Sergey B Kirpichev Date: Wed, 1 Jul 2026 05:26:05 +0300 Subject: [PATCH 3/8] +1 --- tests/test_mpz.py | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/tests/test_mpz.py b/tests/test_mpz.py index 51a84266..43b33530 100644 --- a/tests/test_mpz.py +++ b/tests/test_mpz.py @@ -452,10 +452,6 @@ def test_add_int_subclasses(): def test_binary_mixed(x, y): mx = mpz(x) for op in [operator.add, operator.mul, operator.sub]: - if (platform.python_implementation() == "GraalVM" - and op in [operator.add, operator.sub] - and str(y.imag) == "-0.0"): - continue # issue oracle/graalpython#585 assert str(op(mx, y)) == str(op(x, y)) assert str(op(y, mx)) == str(op(y, x)) if op != operator.sub: @@ -712,8 +708,6 @@ def test_power_errors(): pow(mpz(10**1000), 1j) with pytest.raises(TypeError): pow(object(), mpz(321)) - if platform.python_implementation() == "GraalVM": - return # issue oracle/graalpython#551 with pytest.raises(OverflowError): pow(mpz(2), mpz(1<<64)) if BITCNT_MAX < (1<<64) - 1: @@ -814,8 +808,6 @@ def test_methods(x): assert meth(mx) == meth(x) -@pytest.mark.skipif(platform.python_implementation() == "GraalVM", - reason="oracle/graalpython#883") @given(bigints(), integers(min_value=0, max_value=10000), sampled_from(["big", "little"]), booleans()) @example(0, 0, "big", False) @@ -840,6 +832,7 @@ def test_methods(x): @example(128, 1, "big", False) @example(-32383289396013590652, 0, "big", True) @example(-384, 1, "big", True) +@example(32768, 2, "big", True) def test_to_bytes_bulk(x, length, byteorder, signed): try: rx = x.to_bytes(length, byteorder, signed=signed) From c25797921ad9df22654f0c2768c256434e9b6623 Mon Sep 17 00:00:00 2001 From: Sergey B Kirpichev Date: Wed, 1 Jul 2026 06:27:20 +0300 Subject: [PATCH 4/8] revert --- tests/test_functions.py | 3 +++ tests/test_mpz.py | 2 ++ 2 files changed, 5 insertions(+) diff --git a/tests/test_functions.py b/tests/test_functions.py index c8e7b20e..d89efc3c 100644 --- a/tests/test_functions.py +++ b/tests/test_functions.py @@ -1,5 +1,6 @@ import inspect import math +import platform import gmp import pytest @@ -234,6 +235,8 @@ def test_interfaces(): _mpmath_normalize(1, mpz(111), 11, 12, 13, 1j) +@pytest.mark.skipif(platform.python_implementation() == "GraalVM", + reason="oracle/graalpython#593") def test_func_api(): for fn in ["comb", "factorial", "gcd", "isqrt", "lcm", "perm"]: f = getattr(math, fn) diff --git a/tests/test_mpz.py b/tests/test_mpz.py index 43b33530..5c3f12ea 100644 --- a/tests/test_mpz.py +++ b/tests/test_mpz.py @@ -1069,6 +1069,8 @@ def f(n): assert all(f.result() == 1 for f in futures) +@pytest.mark.skipif(platform.python_implementation() == "GraalVM", + reason="oracle/graalpython#593") def test_int_api(): for meth in dir(int): m = getattr(int, meth) From 855f843748c5ddf44e92b58266cce415c3369e6f Mon Sep 17 00:00:00 2001 From: Sergey B Kirpichev Date: Wed, 1 Jul 2026 06:29:46 +0300 Subject: [PATCH 5/8] adjust issue number --- tests/test_functions.py | 2 +- tests/test_mpz.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/test_functions.py b/tests/test_functions.py index d89efc3c..9b4f49e7 100644 --- a/tests/test_functions.py +++ b/tests/test_functions.py @@ -236,7 +236,7 @@ def test_interfaces(): @pytest.mark.skipif(platform.python_implementation() == "GraalVM", - reason="oracle/graalpython#593") + reason="oracle/graalpython#998") def test_func_api(): for fn in ["comb", "factorial", "gcd", "isqrt", "lcm", "perm"]: f = getattr(math, fn) diff --git a/tests/test_mpz.py b/tests/test_mpz.py index 5c3f12ea..df03e12a 100644 --- a/tests/test_mpz.py +++ b/tests/test_mpz.py @@ -1070,7 +1070,7 @@ def f(n): @pytest.mark.skipif(platform.python_implementation() == "GraalVM", - reason="oracle/graalpython#593") + reason="oracle/graalpython#998") def test_int_api(): for meth in dir(int): m = getattr(int, meth) From 5a31a27ccaac37d352be422034ee32e75385dbf6 Mon Sep 17 00:00:00 2001 From: Sergey B Kirpichev Date: Wed, 1 Jul 2026 07:00:10 +0300 Subject: [PATCH 6/8] skip xdist on coverage --- .github/workflows/coverage.yml | 6 +++--- tests/test_mpz.py | 1 + 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/.github/workflows/coverage.yml b/.github/workflows/coverage.yml index c8faf116..8f2f2517 100644 --- a/.github/workflows/coverage.yml +++ b/.github/workflows/coverage.yml @@ -34,9 +34,9 @@ jobs: if: steps.cache-gmp.outputs.cache-hit != 'true' - run: python -m pip install --upgrade pip - run: | - pip install --verbose .[ci] -Cbuild-dir=build \ - -Csetup-args=-Dbuildtype=debug \ - -Csetup-args=-Db_coverage=true + pip install --verbose .[tests] -Cbuild-dir=build \ + -Csetup-args=-Dbuildtype=debug \ + -Csetup-args=-Db_coverage=true env: PKG_CONFIG_PATH: ${{ github.workspace }}/.local/lib/pkgconfig - run: pytest diff --git a/tests/test_mpz.py b/tests/test_mpz.py index df03e12a..55c8edce 100644 --- a/tests/test_mpz.py +++ b/tests/test_mpz.py @@ -944,6 +944,7 @@ def test_from_bytes_interface(): @example(1<<116) @example(646541478744828163276576707651635923929979156076518566789121) @example((0xfffffffffffff8<<(242*4)) + (1<<970)) +@example(0xa<<10000) def test_to_float(x): mx = mpz(x) try: From ab19d2b85f7258f82ad2bde91679a7af24bea2fb Mon Sep 17 00:00:00 2001 From: Sergey B Kirpichev Date: Wed, 1 Jul 2026 08:09:04 +0300 Subject: [PATCH 7/8] XXX try context manager --- tests/test_mpz.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/test_mpz.py b/tests/test_mpz.py index 55c8edce..3aac4cc7 100644 --- a/tests/test_mpz.py +++ b/tests/test_mpz.py @@ -950,7 +950,8 @@ def test_to_float(x): try: fx = float(x) except OverflowError: - pytest.raises(OverflowError, lambda: float(mx)) + with pytest.raises(OverflowError): + float(mx) else: assert str(float(mx)) == str(fx) From cbb3763bd1abe2c02ffe31beb39b0d4ecab8799c Mon Sep 17 00:00:00 2001 From: Sergey B Kirpichev Date: Wed, 1 Jul 2026 09:02:03 +0300 Subject: [PATCH 8/8] drop special case for GraalVM --- tests/conftest.py | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/tests/conftest.py b/tests/conftest.py index 090ec111..3db02d6d 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -1,17 +1,11 @@ def pytest_configure(config): if "no:hypothesispytest" not in config.getoption("-p"): - import platform - from hypothesis import settings default = settings.get_profile("default") settings.register_profile("default", settings(default, deadline=3000)) ci = settings.get_profile("ci") - if platform.python_implementation() != "GraalVM": - ci = settings(ci, max_examples=10000) - else: - ci = settings(ci, max_examples=1000) - settings.register_profile("ci", ci) + settings.register_profile("ci", settings(ci, max_examples=10000)) def pytest_report_header(config):