python-gmp 0.5.0a2__tar.gz → 0.5.0a4__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {python_gmp-0.5.0a2 → python_gmp-0.5.0a4}/.github/workflows/ci.yml +4 -3
- {python_gmp-0.5.0a2 → python_gmp-0.5.0a4}/.github/workflows/coverage.yml +5 -6
- {python_gmp-0.5.0a2 → python_gmp-0.5.0a4}/.github/workflows/linter.yml +3 -4
- {python_gmp-0.5.0a2 → python_gmp-0.5.0a4}/.github/workflows/os.yml +4 -5
- {python_gmp-0.5.0a2 → python_gmp-0.5.0a4}/.github/workflows/publish.yml +4 -4
- {python_gmp-0.5.0a2 → python_gmp-0.5.0a4}/.github/workflows/wheels.yml +4 -4
- {python_gmp-0.5.0a2 → python_gmp-0.5.0a4}/PKG-INFO +2 -2
- {python_gmp-0.5.0a2 → python_gmp-0.5.0a4}/README.rst +1 -1
- {python_gmp-0.5.0a2 → python_gmp-0.5.0a4}/gmp.c +58 -55
- {python_gmp-0.5.0a2 → python_gmp-0.5.0a4}/libzz/zz.c +7 -5
- {python_gmp-0.5.0a2 → python_gmp-0.5.0a4}/pyproject.toml +2 -2
- {python_gmp-0.5.0a2 → python_gmp-0.5.0a4}/scripts/dll-importexport.diff +2 -0
- {python_gmp-0.5.0a2 → python_gmp-0.5.0a4}/tests/test_api.py +3 -0
- {python_gmp-0.5.0a2 → python_gmp-0.5.0a4}/tests/test_functions.py +13 -0
- {python_gmp-0.5.0a2 → python_gmp-0.5.0a4}/tests/test_mpz.py +19 -16
- {python_gmp-0.5.0a2 → python_gmp-0.5.0a4}/.clang-format +0 -0
- {python_gmp-0.5.0a2 → python_gmp-0.5.0a4}/.github/dependabot.yml +0 -0
- {python_gmp-0.5.0a2 → python_gmp-0.5.0a4}/.gitignore +0 -0
- {python_gmp-0.5.0a2 → python_gmp-0.5.0a4}/.gitmodules +0 -0
- {python_gmp-0.5.0a2 → python_gmp-0.5.0a4}/.pre-commit-config.yaml +0 -0
- {python_gmp-0.5.0a2 → python_gmp-0.5.0a4}/.readthedocs.yaml +0 -0
- {python_gmp-0.5.0a2 → python_gmp-0.5.0a4}/LICENSE +0 -0
- {python_gmp-0.5.0a2 → python_gmp-0.5.0a4}/docs/conf.py +0 -0
- {python_gmp-0.5.0a2 → python_gmp-0.5.0a4}/docs/index.rst +0 -0
- {python_gmp-0.5.0a2 → python_gmp-0.5.0a4}/fmt.c +0 -0
- {python_gmp-0.5.0a2 → python_gmp-0.5.0a4}/libzz/.gitignore +0 -0
- {python_gmp-0.5.0a2 → python_gmp-0.5.0a4}/libzz/AUTHORS +0 -0
- {python_gmp-0.5.0a2 → python_gmp-0.5.0a4}/libzz/COPYING +0 -0
- {python_gmp-0.5.0a2 → python_gmp-0.5.0a4}/libzz/COPYING.LESSER +0 -0
- {python_gmp-0.5.0a2 → python_gmp-0.5.0a4}/libzz/ChangeLog +0 -0
- {python_gmp-0.5.0a2 → python_gmp-0.5.0a4}/libzz/NEWS +0 -0
- {python_gmp-0.5.0a2 → python_gmp-0.5.0a4}/libzz/README +0 -0
- {python_gmp-0.5.0a2 → python_gmp-0.5.0a4}/libzz/configure.ac +0 -0
- {python_gmp-0.5.0a2 → python_gmp-0.5.0a4}/libzz/makefile.am +0 -0
- {python_gmp-0.5.0a2 → python_gmp-0.5.0a4}/libzz/zz.h +0 -0
- {python_gmp-0.5.0a2 → python_gmp-0.5.0a4}/libzz/zz.pc.in +0 -0
- {python_gmp-0.5.0a2 → python_gmp-0.5.0a4}/meson.build +0 -0
- {python_gmp-0.5.0a2 → python_gmp-0.5.0a4}/mpz.h +0 -0
- {python_gmp-0.5.0a2 → python_gmp-0.5.0a4}/pythoncapi_compat.h +0 -0
- {python_gmp-0.5.0a2 → python_gmp-0.5.0a4}/scripts/cibw_before_all.sh +0 -0
- {python_gmp-0.5.0a2 → python_gmp-0.5.0a4}/scripts/fat_build_fix.diff +0 -0
- {python_gmp-0.5.0a2 → python_gmp-0.5.0a4}/scripts/gcc15.diff +0 -0
- {python_gmp-0.5.0a2 → python_gmp-0.5.0a4}/tests/conftest.py +0 -0
- {python_gmp-0.5.0a2 → python_gmp-0.5.0a4}/tests/test_memory.py +0 -0
- {python_gmp-0.5.0a2 → python_gmp-0.5.0a4}/tests/test_utils.py +0 -0
- {python_gmp-0.5.0a2 → python_gmp-0.5.0a4}/utils.c +0 -0
- {python_gmp-0.5.0a2 → python_gmp-0.5.0a4}/utils.h +0 -0
|
@@ -2,6 +2,7 @@ name: Run CI tests
|
|
|
2
2
|
on:
|
|
3
3
|
push:
|
|
4
4
|
pull_request:
|
|
5
|
+
workflow_dispatch:
|
|
5
6
|
schedule:
|
|
6
7
|
- cron: '0 0 * * 2'
|
|
7
8
|
jobs:
|
|
@@ -17,18 +18,18 @@ jobs:
|
|
|
17
18
|
fail-fast: true
|
|
18
19
|
matrix:
|
|
19
20
|
os: [ubuntu-24.04]
|
|
20
|
-
python-version: [3.9, '3.10', pypy3.11, graalpy-
|
|
21
|
+
python-version: [3.9, '3.10', pypy3.11, graalpy-25.0,
|
|
21
22
|
3.11, 3.12, 3.13, 3.13t, 3.14, 3.14t]
|
|
22
23
|
runs-on: ${{ matrix.os }}
|
|
23
24
|
env:
|
|
24
25
|
PYTEST_ADDOPTS: --verbose
|
|
25
26
|
CFLAGS: -Wall -Wpedantic -Werror -std=c17 -Wconversion
|
|
26
27
|
steps:
|
|
27
|
-
- uses: actions/checkout@
|
|
28
|
+
- uses: actions/checkout@v5
|
|
28
29
|
with:
|
|
29
30
|
fetch-depth: 0
|
|
30
31
|
submodules: true
|
|
31
|
-
- uses: actions/setup-python@
|
|
32
|
+
- uses: actions/setup-python@v6
|
|
32
33
|
with:
|
|
33
34
|
python-version: ${{ matrix.python-version }}
|
|
34
35
|
allow-prereleases: true
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
name: Run coverage tests
|
|
2
|
-
on:
|
|
3
|
-
workflow_call:
|
|
2
|
+
on: [workflow_dispatch, workflow_call]
|
|
4
3
|
jobs:
|
|
5
4
|
coverage:
|
|
6
5
|
runs-on: ${{ matrix.os }}
|
|
@@ -13,11 +12,11 @@ jobs:
|
|
|
13
12
|
os: [ubuntu-24.04]
|
|
14
13
|
python-version: [pypy3.11, "3.x", 3.14]
|
|
15
14
|
steps:
|
|
16
|
-
- uses: actions/checkout@
|
|
15
|
+
- uses: actions/checkout@v5
|
|
17
16
|
with:
|
|
18
17
|
fetch-depth: 0
|
|
19
18
|
submodules: true
|
|
20
|
-
- uses: actions/setup-python@
|
|
19
|
+
- uses: actions/setup-python@v6
|
|
21
20
|
with:
|
|
22
21
|
python-version: ${{ matrix.python-version }}
|
|
23
22
|
allow-prereleases: true
|
|
@@ -62,13 +61,13 @@ jobs:
|
|
|
62
61
|
needs:
|
|
63
62
|
- coverage
|
|
64
63
|
steps:
|
|
65
|
-
- uses: actions/checkout@
|
|
64
|
+
- uses: actions/checkout@v5
|
|
66
65
|
with:
|
|
67
66
|
fetch-depth: 0
|
|
68
67
|
submodules: true
|
|
69
68
|
- run: sudo apt-get update
|
|
70
69
|
- run: sudo apt-get install lcov
|
|
71
|
-
- uses: actions/download-artifact@
|
|
70
|
+
- uses: actions/download-artifact@v5
|
|
72
71
|
with:
|
|
73
72
|
pattern: coverage-*
|
|
74
73
|
path: build/
|
|
@@ -1,15 +1,14 @@
|
|
|
1
1
|
name: Run pre-commit
|
|
2
|
-
on:
|
|
3
|
-
workflow_call:
|
|
2
|
+
on: [workflow_dispatch, workflow_call]
|
|
4
3
|
jobs:
|
|
5
4
|
linter:
|
|
6
5
|
runs-on: ubuntu-24.04
|
|
7
6
|
steps:
|
|
8
|
-
- uses: actions/checkout@
|
|
7
|
+
- uses: actions/checkout@v5
|
|
9
8
|
with:
|
|
10
9
|
fetch-depth: 0
|
|
11
10
|
submodules: true
|
|
12
|
-
- uses: actions/setup-python@
|
|
11
|
+
- uses: actions/setup-python@v6
|
|
13
12
|
with:
|
|
14
13
|
python-version: "3.x"
|
|
15
14
|
- uses: pre-commit/action@v3.0.1
|
|
@@ -1,22 +1,21 @@
|
|
|
1
1
|
name: Run tests on different OS
|
|
2
|
-
on:
|
|
3
|
-
workflow_call:
|
|
2
|
+
on: [workflow_dispatch, workflow_call]
|
|
4
3
|
jobs:
|
|
5
4
|
os:
|
|
6
5
|
runs-on: ${{ matrix.os }}
|
|
7
6
|
strategy:
|
|
8
7
|
fail-fast: false
|
|
9
8
|
matrix:
|
|
10
|
-
os: [ubuntu-24.04, ubuntu-24.04-arm, macos-
|
|
9
|
+
os: [ubuntu-24.04, ubuntu-24.04-arm, macos-15]
|
|
11
10
|
env:
|
|
12
11
|
PYTEST_ADDOPTS: --verbose
|
|
13
12
|
CFLAGS: -Wall -Wpedantic -Werror -std=c17 -Wconversion
|
|
14
13
|
steps:
|
|
15
|
-
- uses: actions/checkout@
|
|
14
|
+
- uses: actions/checkout@v5
|
|
16
15
|
with:
|
|
17
16
|
fetch-depth: 0
|
|
18
17
|
submodules: true
|
|
19
|
-
- uses: actions/setup-python@
|
|
18
|
+
- uses: actions/setup-python@v6
|
|
20
19
|
with:
|
|
21
20
|
python-version: "3.x"
|
|
22
21
|
- run: brew install autoconf automake libtool
|
|
@@ -6,11 +6,11 @@ jobs:
|
|
|
6
6
|
if: startsWith(github.ref, 'refs/tags/')
|
|
7
7
|
runs-on: ubuntu-24.04
|
|
8
8
|
steps:
|
|
9
|
-
- uses: actions/checkout@
|
|
9
|
+
- uses: actions/checkout@v5
|
|
10
10
|
with:
|
|
11
11
|
fetch-depth: 0
|
|
12
12
|
submodules: true
|
|
13
|
-
- uses: actions/setup-python@
|
|
13
|
+
- uses: actions/setup-python@v6
|
|
14
14
|
with:
|
|
15
15
|
python-version: "3.x"
|
|
16
16
|
- run: pip install build
|
|
@@ -34,7 +34,7 @@ jobs:
|
|
|
34
34
|
permissions:
|
|
35
35
|
id-token: write
|
|
36
36
|
steps:
|
|
37
|
-
- uses: actions/download-artifact@
|
|
37
|
+
- uses: actions/download-artifact@v5
|
|
38
38
|
with:
|
|
39
39
|
pattern: python-gmp-*
|
|
40
40
|
path: dist/
|
|
@@ -51,7 +51,7 @@ jobs:
|
|
|
51
51
|
contents: write
|
|
52
52
|
id-token: write
|
|
53
53
|
steps:
|
|
54
|
-
- uses: actions/download-artifact@
|
|
54
|
+
- uses: actions/download-artifact@v5
|
|
55
55
|
with:
|
|
56
56
|
pattern: python-gmp-*
|
|
57
57
|
path: dist/
|
|
@@ -6,14 +6,14 @@ jobs:
|
|
|
6
6
|
runs-on: ${{ matrix.os }}
|
|
7
7
|
strategy:
|
|
8
8
|
matrix:
|
|
9
|
-
os: [ubuntu-24.04, ubuntu-24.04-arm, macos-
|
|
9
|
+
os: [ubuntu-24.04, ubuntu-24.04-arm, macos-15-intel, macos-15,
|
|
10
10
|
windows-2022]
|
|
11
11
|
steps:
|
|
12
|
-
- uses: actions/checkout@
|
|
12
|
+
- uses: actions/checkout@v5
|
|
13
13
|
with:
|
|
14
14
|
fetch-depth: 0
|
|
15
15
|
submodules: true
|
|
16
|
-
- uses: msys2/setup-msys2@v2.
|
|
16
|
+
- uses: msys2/setup-msys2@v2.29.0
|
|
17
17
|
name: Setup msys2
|
|
18
18
|
with:
|
|
19
19
|
install: >-
|
|
@@ -33,7 +33,7 @@ jobs:
|
|
|
33
33
|
- run: echo "PKG_CONFIG_PATH=${{ github.workspace }}/.local/lib/pkgconfig" >> $env:GITHUB_ENV
|
|
34
34
|
if: ${{ startsWith( matrix.os , 'windows' ) }}
|
|
35
35
|
- name: Build wheels
|
|
36
|
-
uses: pypa/cibuildwheel@v3.
|
|
36
|
+
uses: pypa/cibuildwheel@v3.2.0
|
|
37
37
|
- uses: actions/upload-artifact@v4
|
|
38
38
|
with:
|
|
39
39
|
name: wheels-${{ matrix.os }}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: python-gmp
|
|
3
|
-
Version: 0.5.
|
|
3
|
+
Version: 0.5.0a4
|
|
4
4
|
Summary: Safe bindings to the GNU GMP library
|
|
5
5
|
Keywords: gmp,multiple-precision,arbitrary-precision,bignum
|
|
6
6
|
Author-Email: Sergey B Kirpichev <skirpichev@gmail.com>
|
|
@@ -60,7 +60,7 @@ functions (`comb`_, `factorial`_, `gcd`_, `isqrt`_, `lcm`_ and `perm`_),
|
|
|
60
60
|
compatible with the Python stdlib's module `math`_.
|
|
61
61
|
|
|
62
62
|
This module requires Python 3.9 or later versions and has been tested with
|
|
63
|
-
CPython 3.9 through 3.14, with PyPy 3.11 and with GraalPy
|
|
63
|
+
CPython 3.9 through 3.14, with PyPy 3.11 and with GraalPy 25.0. Free-threading
|
|
64
64
|
builds of the CPython are supported.
|
|
65
65
|
|
|
66
66
|
Releases are available in the Python Package Index (PyPI) at
|
|
@@ -10,7 +10,7 @@ functions (`comb`_, `factorial`_, `gcd`_, `isqrt`_, `lcm`_ and `perm`_),
|
|
|
10
10
|
compatible with the Python stdlib's module `math`_.
|
|
11
11
|
|
|
12
12
|
This module requires Python 3.9 or later versions and has been tested with
|
|
13
|
-
CPython 3.9 through 3.14, with PyPy 3.11 and with GraalPy
|
|
13
|
+
CPython 3.9 through 3.14, with PyPy 3.11 and with GraalPy 25.0. Free-threading
|
|
14
14
|
builds of the CPython are supported.
|
|
15
15
|
|
|
16
16
|
Releases are available in the Python Package Index (PyPI) at
|
|
@@ -374,17 +374,24 @@ MPZ_to_bytes(MPZ_Object *u, Py_ssize_t length, int is_little, int is_signed)
|
|
|
374
374
|
}
|
|
375
375
|
return bytes;
|
|
376
376
|
}
|
|
377
|
-
Py_DECREF(bytes);
|
|
378
377
|
if (ret == ZZ_BUF) {
|
|
379
378
|
if (zz_isneg(&u->z) && !is_signed) {
|
|
380
379
|
PyErr_SetString(PyExc_OverflowError,
|
|
381
380
|
"can't convert negative mpz to unsigned");
|
|
382
381
|
}
|
|
383
382
|
else {
|
|
383
|
+
#if (PY_VERSION_HEX < 0x030D08F0 || (PY_VERSION_HEX >= 0x030E0000 \
|
|
384
|
+
&& PY_VERSION_HEX < 0x030E00C3))
|
|
385
|
+
if (!length && zz_cmp_i32(&u->z, -1) == ZZ_EQ) {
|
|
386
|
+
return bytes;
|
|
387
|
+
}
|
|
388
|
+
#endif
|
|
384
389
|
PyErr_SetString(PyExc_OverflowError, "int too big to convert");
|
|
385
390
|
}
|
|
391
|
+
Py_DECREF(bytes);
|
|
386
392
|
return NULL;
|
|
387
393
|
}
|
|
394
|
+
Py_DECREF(bytes);
|
|
388
395
|
return PyErr_NoMemory(); /* LCOV_EXCL_LINE */
|
|
389
396
|
}
|
|
390
397
|
|
|
@@ -783,45 +790,6 @@ to_bool(PyObject *self)
|
|
|
783
790
|
return !zz_iszero(&((MPZ_Object *)self)->z);
|
|
784
791
|
}
|
|
785
792
|
|
|
786
|
-
#define BINOP_INT(suff) \
|
|
787
|
-
static PyObject * \
|
|
788
|
-
nb_##suff(PyObject *self, PyObject *other) \
|
|
789
|
-
{ \
|
|
790
|
-
MPZ_Object *u = NULL, *v = NULL, *res = NULL; \
|
|
791
|
-
\
|
|
792
|
-
CHECK_OP(u, self); \
|
|
793
|
-
CHECK_OP(v, other); \
|
|
794
|
-
\
|
|
795
|
-
res = MPZ_new(0); \
|
|
796
|
-
zz_err ret = ZZ_OK; \
|
|
797
|
-
\
|
|
798
|
-
if (!res || (ret = zz_##suff(&u->z, &v->z, &res->z))) { \
|
|
799
|
-
/* LCOV_EXCL_START */ \
|
|
800
|
-
Py_CLEAR(res); \
|
|
801
|
-
if (ret == ZZ_VAL) { \
|
|
802
|
-
PyErr_SetString(PyExc_ValueError, \
|
|
803
|
-
"negative shift count"); \
|
|
804
|
-
} \
|
|
805
|
-
else if (ret == ZZ_BUF) { \
|
|
806
|
-
PyErr_SetString(PyExc_OverflowError, \
|
|
807
|
-
"too many digits in integer"); \
|
|
808
|
-
} \
|
|
809
|
-
else { \
|
|
810
|
-
PyErr_NoMemory(); \
|
|
811
|
-
} \
|
|
812
|
-
/* LCOV_EXCL_STOP */ \
|
|
813
|
-
} \
|
|
814
|
-
end: \
|
|
815
|
-
Py_XDECREF(u); \
|
|
816
|
-
Py_XDECREF(v); \
|
|
817
|
-
return (PyObject *)res; \
|
|
818
|
-
fallback: \
|
|
819
|
-
numbers: \
|
|
820
|
-
Py_XDECREF(u); \
|
|
821
|
-
Py_XDECREF(v); \
|
|
822
|
-
Py_RETURN_NOTIMPLEMENTED; \
|
|
823
|
-
}
|
|
824
|
-
|
|
825
793
|
#define BINOP(suff, slot) \
|
|
826
794
|
static PyObject * \
|
|
827
795
|
nb_##suff(PyObject *self, PyObject *other) \
|
|
@@ -1038,6 +1006,56 @@ numbers:
|
|
|
1038
1006
|
return res;
|
|
1039
1007
|
}
|
|
1040
1008
|
|
|
1009
|
+
#define CHECK_OP_INT(u, a) \
|
|
1010
|
+
if (MPZ_Check(a)) { \
|
|
1011
|
+
u = (MPZ_Object *)a; \
|
|
1012
|
+
Py_INCREF(u); \
|
|
1013
|
+
} \
|
|
1014
|
+
else { \
|
|
1015
|
+
u = MPZ_from_int(a); \
|
|
1016
|
+
if (!u) { \
|
|
1017
|
+
goto end; \
|
|
1018
|
+
} \
|
|
1019
|
+
} \
|
|
1020
|
+
|
|
1021
|
+
#define BINOP_INT(suff) \
|
|
1022
|
+
static PyObject * \
|
|
1023
|
+
nb_##suff(PyObject *self, PyObject *other) \
|
|
1024
|
+
{ \
|
|
1025
|
+
MPZ_Object *u = NULL, *v = NULL, *res = NULL; \
|
|
1026
|
+
\
|
|
1027
|
+
CHECK_OP_INT(u, self); \
|
|
1028
|
+
CHECK_OP_INT(v, other); \
|
|
1029
|
+
\
|
|
1030
|
+
res = MPZ_new(0); \
|
|
1031
|
+
zz_err ret = ZZ_OK; \
|
|
1032
|
+
\
|
|
1033
|
+
if (!res || (ret = zz_##suff(&u->z, &v->z, &res->z))) { \
|
|
1034
|
+
/* LCOV_EXCL_START */ \
|
|
1035
|
+
Py_CLEAR(res); \
|
|
1036
|
+
if (ret == ZZ_VAL) { \
|
|
1037
|
+
PyErr_SetString(PyExc_ValueError, \
|
|
1038
|
+
"negative shift count"); \
|
|
1039
|
+
} \
|
|
1040
|
+
else if (ret == ZZ_BUF) { \
|
|
1041
|
+
PyErr_SetString(PyExc_OverflowError, \
|
|
1042
|
+
"too many digits in integer"); \
|
|
1043
|
+
} \
|
|
1044
|
+
else { \
|
|
1045
|
+
PyErr_NoMemory(); \
|
|
1046
|
+
} \
|
|
1047
|
+
/* LCOV_EXCL_STOP */ \
|
|
1048
|
+
} \
|
|
1049
|
+
end: \
|
|
1050
|
+
Py_XDECREF(u); \
|
|
1051
|
+
Py_XDECREF(v); \
|
|
1052
|
+
return (PyObject *)res; \
|
|
1053
|
+
}
|
|
1054
|
+
|
|
1055
|
+
BINOP_INT(and)
|
|
1056
|
+
BINOP_INT(or)
|
|
1057
|
+
BINOP_INT(xor)
|
|
1058
|
+
|
|
1041
1059
|
static zz_err
|
|
1042
1060
|
zz_lshift(const zz_t *u, const zz_t *v, zz_t *w)
|
|
1043
1061
|
{
|
|
@@ -1064,21 +1082,6 @@ zz_rshift(const zz_t *u, const zz_t *v, zz_t *w)
|
|
|
1064
1082
|
|
|
1065
1083
|
BINOP_INT(lshift)
|
|
1066
1084
|
BINOP_INT(rshift)
|
|
1067
|
-
BINOP_INT(and)
|
|
1068
|
-
BINOP_INT(or)
|
|
1069
|
-
BINOP_INT(xor)
|
|
1070
|
-
|
|
1071
|
-
#define CHECK_OP_INT(u, a) \
|
|
1072
|
-
if (MPZ_Check(a)) { \
|
|
1073
|
-
u = (MPZ_Object *)a; \
|
|
1074
|
-
Py_INCREF(u); \
|
|
1075
|
-
} \
|
|
1076
|
-
else { \
|
|
1077
|
-
u = MPZ_from_int(a); \
|
|
1078
|
-
if (!u) { \
|
|
1079
|
-
goto end; \
|
|
1080
|
-
} \
|
|
1081
|
-
} \
|
|
1082
1085
|
|
|
1083
1086
|
static PyObject *
|
|
1084
1087
|
power(PyObject *self, PyObject *other, PyObject *module)
|
|
@@ -716,8 +716,8 @@ zz_to_bytes(const zz_t *u, size_t length, bool is_signed, uint8_t **buffer)
|
|
|
716
716
|
size_t nbits = zz_bitlen(u);
|
|
717
717
|
|
|
718
718
|
if (nbits > 8*length
|
|
719
|
-
|| (is_signed && nbits
|
|
720
|
-
&& (nbits == 8 * length ? !is_negative : is_negative)))
|
|
719
|
+
|| (is_signed && ((!nbits && is_negative)
|
|
720
|
+
|| (nbits && (nbits == 8 * length ? !is_negative : is_negative)))))
|
|
721
721
|
{
|
|
722
722
|
overflow:
|
|
723
723
|
zz_clear(&tmp);
|
|
@@ -897,12 +897,14 @@ _zz_addsub_i32(const zz_t *u, int32_t v, bool subtract, zz_t *w)
|
|
|
897
897
|
zz_size_t u_size = u->size, v_size = v != 0;
|
|
898
898
|
zz_limb_t digit = (zz_limb_t)imaxabs(v);
|
|
899
899
|
|
|
900
|
-
if (u_size < v_size) {
|
|
901
|
-
assert(
|
|
900
|
+
if (!u_size || u_size < v_size) {
|
|
901
|
+
assert(!u_size);
|
|
902
902
|
if (zz_resize(v_size, w)) {
|
|
903
903
|
return ZZ_MEM; /* LCOV_EXCL_LINE */
|
|
904
904
|
}
|
|
905
|
-
|
|
905
|
+
if (v_size) {
|
|
906
|
+
w->digits[0] = digit;
|
|
907
|
+
}
|
|
906
908
|
w->negative = negv;
|
|
907
909
|
return ZZ_OK;
|
|
908
910
|
}
|
|
@@ -67,8 +67,8 @@ select = ["E", "F", "I", "PT", "W", "Q", "SIM"]
|
|
|
67
67
|
[tool.cibuildwheel]
|
|
68
68
|
build-frontend = {name="build", args=["--verbose"]}
|
|
69
69
|
enable = "pypy cpython-prerelease cpython-freethreading graalpy"
|
|
70
|
-
skip = """*-win32 *-manylinux_i686 *-musllinux_* \
|
|
71
|
-
*-manylinux_armv7l
|
|
70
|
+
skip = """*-win32 gp311_242* *-manylinux_i686 *-musllinux_* \
|
|
71
|
+
*-manylinux_armv7l pp*aarch64* gp3*win*"""
|
|
72
72
|
before-all = "bash scripts/cibw_before_all.sh"
|
|
73
73
|
test-extras = "tests"
|
|
74
74
|
test-command = "pytest {package}"
|
|
@@ -94,6 +94,9 @@ def test_zz_add_i32():
|
|
|
94
94
|
assert zz_from_i64(0, u) == zz_err.ZZ_OK
|
|
95
95
|
assert zz_add_i32(u, 2, u) == zz_err.ZZ_OK
|
|
96
96
|
assert zz_cmp_i32(u, 2) == zz_ord.ZZ_EQ
|
|
97
|
+
assert zz_from_i64(0, u) == zz_err.ZZ_OK
|
|
98
|
+
assert zz_add_i32(u, 0, u) == zz_err.ZZ_OK
|
|
99
|
+
assert zz_cmp_i32(u, 0) == zz_ord.ZZ_EQ
|
|
97
100
|
|
|
98
101
|
|
|
99
102
|
def test_zz_lsbpos():
|
|
@@ -1,4 +1,7 @@
|
|
|
1
|
+
import inspect
|
|
1
2
|
import math
|
|
3
|
+
import platform
|
|
4
|
+
import sys
|
|
2
5
|
|
|
3
6
|
import gmp
|
|
4
7
|
import pytest
|
|
@@ -236,3 +239,13 @@ def test_interfaces():
|
|
|
236
239
|
with pytest.raises(ValueError, match="invalid rounding mode specified"):
|
|
237
240
|
_mpmath_normalize(1, mpz(111), 11, 12, 13, 1j)
|
|
238
241
|
gmp._free_cache() # just for coverage
|
|
242
|
+
|
|
243
|
+
|
|
244
|
+
@pytest.mark.skipif(platform.python_implementation() != "CPython"
|
|
245
|
+
or sys.version_info < (3, 11),
|
|
246
|
+
reason="no way to specify a signature")
|
|
247
|
+
def test_func_api():
|
|
248
|
+
for fn in ["comb", "factorial", "gcd", "isqrt", "lcm", "perm"]:
|
|
249
|
+
f = getattr(math, fn)
|
|
250
|
+
fz = getattr(gmp, fn)
|
|
251
|
+
assert inspect.signature(f) == inspect.signature(fz)
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import cmath
|
|
2
|
+
import inspect
|
|
2
3
|
import locale
|
|
3
4
|
import math
|
|
4
5
|
import operator
|
|
@@ -461,8 +462,6 @@ def test_mul_distributivity(x, y, z):
|
|
|
461
462
|
assert mul(op(mx, my), mz) == op(mul(mx, mz), mul(my, mz))
|
|
462
463
|
|
|
463
464
|
|
|
464
|
-
@pytest.mark.skipif(platform.python_implementation() == "GraalVM",
|
|
465
|
-
reason="XXX: oracle/graalpython#534")
|
|
466
465
|
@given(bigints(), bigints())
|
|
467
466
|
@example(18446744073709551615, -1)
|
|
468
467
|
@example(-2, 1<<64)
|
|
@@ -471,6 +470,7 @@ def test_mul_distributivity(x, y, z):
|
|
|
471
470
|
@example(int("0x"+"f"*32, 0), -1<<64) # XXX: assuming BITS_PER_LIMB == 64
|
|
472
471
|
@example(-68501870735943706700000000000000000001, 10**20) # issue 117
|
|
473
472
|
@example(0, 123)
|
|
473
|
+
@example(0, -1382074480823709287)
|
|
474
474
|
def test_divmod_bulk(x, y):
|
|
475
475
|
mx = mpz(x)
|
|
476
476
|
my = mpz(y)
|
|
@@ -478,6 +478,8 @@ def test_divmod_bulk(x, y):
|
|
|
478
478
|
with pytest.raises(ZeroDivisionError):
|
|
479
479
|
mx // my
|
|
480
480
|
return
|
|
481
|
+
if y < 0 and platform.python_implementation() == "GraalVM":
|
|
482
|
+
return # issue graalpython#534
|
|
481
483
|
r = x // y
|
|
482
484
|
assert mx // my == r
|
|
483
485
|
assert mx // y == r
|
|
@@ -511,8 +513,6 @@ def test_divmod_errors():
|
|
|
511
513
|
divmod(mx, 0)
|
|
512
514
|
|
|
513
515
|
|
|
514
|
-
@pytest.mark.skipif(platform.python_implementation() == "GraalVM",
|
|
515
|
-
reason="XXX: oracle/graalpython#474")
|
|
516
516
|
@given(bigints(), bigints())
|
|
517
517
|
@example(0, -1)
|
|
518
518
|
@example(0, 123)
|
|
@@ -584,8 +584,6 @@ def test_truediv_errors():
|
|
|
584
584
|
pytest.raises(TypeError, lambda: object() / mx)
|
|
585
585
|
|
|
586
586
|
|
|
587
|
-
@pytest.mark.skipif(platform.python_implementation() == "GraalVM",
|
|
588
|
-
reason="XXX: oracle/graalpython#473")
|
|
589
587
|
@given(bigints(), integers(max_value=100000))
|
|
590
588
|
@example(0, 123)
|
|
591
589
|
@example(123, 0)
|
|
@@ -686,6 +684,8 @@ def test_power_errors():
|
|
|
686
684
|
pow(mpz(10**1000), 1j)
|
|
687
685
|
with pytest.raises(TypeError):
|
|
688
686
|
pow(object(), mpz(321))
|
|
687
|
+
if platform.python_implementation() == "GraalVM":
|
|
688
|
+
return # issue oracle/graalpython#551
|
|
689
689
|
with pytest.raises(MemoryError):
|
|
690
690
|
pow(mpz(123), 111111111111111111)
|
|
691
691
|
|
|
@@ -695,8 +695,6 @@ def test_power_errors():
|
|
|
695
695
|
@example(1, 1<<128)
|
|
696
696
|
@example(90605555449081991889354259339521952450308780844225461, 64)
|
|
697
697
|
def test_lshift(x, y):
|
|
698
|
-
if platform.python_implementation() == "GraalVM" and y < 0:
|
|
699
|
-
return # XXX: oracle/graalpython#516
|
|
700
698
|
mx = mpz(x)
|
|
701
699
|
my = mpz(y)
|
|
702
700
|
try:
|
|
@@ -802,8 +800,6 @@ def test_to_bytes_bulk(x, length, byteorder, signed):
|
|
|
802
800
|
try:
|
|
803
801
|
rx = x.to_bytes(length, byteorder, signed=signed)
|
|
804
802
|
except OverflowError:
|
|
805
|
-
if platform.python_implementation() == "GraalVM" and not length:
|
|
806
|
-
return # XXX: oracle/graalpython#475
|
|
807
803
|
with pytest.raises(OverflowError):
|
|
808
804
|
mpz(x).to_bytes(length, byteorder, signed=signed)
|
|
809
805
|
else:
|
|
@@ -867,10 +863,7 @@ def test_from_bytes_bulk(x, length, byteorder, signed):
|
|
|
867
863
|
else:
|
|
868
864
|
rx = int.from_bytes(bytes, byteorder, signed=signed)
|
|
869
865
|
assert rx == mpz.from_bytes(bytes, byteorder, signed=signed)
|
|
870
|
-
|
|
871
|
-
# XXX: oracle/graalpython#476
|
|
872
|
-
assert rx == mpz.from_bytes(bytearray(bytes), byteorder,
|
|
873
|
-
signed=signed)
|
|
866
|
+
assert rx == mpz.from_bytes(bytearray(bytes), byteorder, signed=signed)
|
|
874
867
|
assert rx == mpz.from_bytes(list(bytes), byteorder, signed=signed)
|
|
875
868
|
|
|
876
869
|
|
|
@@ -977,8 +970,6 @@ def test_digits_interface():
|
|
|
977
970
|
assert x.digits(10) == x.digits(base=10) == x.digits()
|
|
978
971
|
|
|
979
972
|
|
|
980
|
-
@pytest.mark.skipif(platform.python_implementation() == "GraalVM",
|
|
981
|
-
reason="XXX: oracle/graalpython#479")
|
|
982
973
|
@given(bigints(), integers(min_value=2, max_value=36))
|
|
983
974
|
def test_digits_frombase(x, base):
|
|
984
975
|
mx = mpz(x)
|
|
@@ -1032,3 +1023,15 @@ def test_mpz_collatz(xs):
|
|
|
1032
1023
|
with ThreadPoolExecutor(max_workers=7) as tpe:
|
|
1033
1024
|
futures = [tpe.submit(f, mpz(x)) for x in xs]
|
|
1034
1025
|
assert all(f.result() == 1 for f in futures)
|
|
1026
|
+
|
|
1027
|
+
|
|
1028
|
+
@pytest.mark.skipif(platform.python_implementation() != "CPython"
|
|
1029
|
+
or sys.version_info < (3, 13),
|
|
1030
|
+
reason="no way to specify a signature")
|
|
1031
|
+
def test_int_api():
|
|
1032
|
+
for meth in dir(int):
|
|
1033
|
+
m = getattr(int, meth)
|
|
1034
|
+
if meth.startswith("_") or not callable(m):
|
|
1035
|
+
continue
|
|
1036
|
+
mz = getattr(mpz, meth)
|
|
1037
|
+
assert inspect.signature(m) == inspect.signature(mz)
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|