python-gmp 0.4.0b5__tar.gz → 0.4.1__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.
Files changed (35) hide show
  1. {python_gmp-0.4.0b5 → python_gmp-0.4.1}/.github/workflows/os.yml +1 -1
  2. {python_gmp-0.4.0b5 → python_gmp-0.4.1}/.github/workflows/wheels.yml +1 -1
  3. {python_gmp-0.4.0b5 → python_gmp-0.4.1}/PKG-INFO +2 -2
  4. {python_gmp-0.4.0b5 → python_gmp-0.4.1}/gmp.c +20 -10
  5. {python_gmp-0.4.0b5 → python_gmp-0.4.1}/pyproject.toml +1 -1
  6. {python_gmp-0.4.0b5 → python_gmp-0.4.1}/tests/test_mpz.py +4 -0
  7. {python_gmp-0.4.0b5 → python_gmp-0.4.1}/zz.c +2 -2
  8. {python_gmp-0.4.0b5 → python_gmp-0.4.1}/.clang-format +0 -0
  9. {python_gmp-0.4.0b5 → python_gmp-0.4.1}/.github/dependabot.yml +0 -0
  10. {python_gmp-0.4.0b5 → python_gmp-0.4.1}/.github/workflows/ci.yml +0 -0
  11. {python_gmp-0.4.0b5 → python_gmp-0.4.1}/.github/workflows/coverage.yml +0 -0
  12. {python_gmp-0.4.0b5 → python_gmp-0.4.1}/.github/workflows/linter.yml +0 -0
  13. {python_gmp-0.4.0b5 → python_gmp-0.4.1}/.github/workflows/publish.yml +0 -0
  14. {python_gmp-0.4.0b5 → python_gmp-0.4.1}/.gitignore +0 -0
  15. {python_gmp-0.4.0b5 → python_gmp-0.4.1}/.pre-commit-config.yaml +0 -0
  16. {python_gmp-0.4.0b5 → python_gmp-0.4.1}/.readthedocs.yaml +0 -0
  17. {python_gmp-0.4.0b5 → python_gmp-0.4.1}/LICENSE +0 -0
  18. {python_gmp-0.4.0b5 → python_gmp-0.4.1}/README.rst +0 -0
  19. {python_gmp-0.4.0b5 → python_gmp-0.4.1}/docs/conf.py +0 -0
  20. {python_gmp-0.4.0b5 → python_gmp-0.4.1}/docs/index.rst +0 -0
  21. {python_gmp-0.4.0b5 → python_gmp-0.4.1}/fmt.c +0 -0
  22. {python_gmp-0.4.0b5 → python_gmp-0.4.1}/meson.build +0 -0
  23. {python_gmp-0.4.0b5 → python_gmp-0.4.1}/mpz.h +0 -0
  24. {python_gmp-0.4.0b5 → python_gmp-0.4.1}/pythoncapi_compat.h +0 -0
  25. {python_gmp-0.4.0b5 → python_gmp-0.4.1}/scripts/cibw_before_all.sh +0 -0
  26. {python_gmp-0.4.0b5 → python_gmp-0.4.1}/scripts/dll-importexport.diff +0 -0
  27. {python_gmp-0.4.0b5 → python_gmp-0.4.1}/scripts/fat_build_fix.diff +0 -0
  28. {python_gmp-0.4.0b5 → python_gmp-0.4.1}/tests/conftest.py +0 -0
  29. {python_gmp-0.4.0b5 → python_gmp-0.4.1}/tests/test_api.py +0 -0
  30. {python_gmp-0.4.0b5 → python_gmp-0.4.1}/tests/test_functions.py +0 -0
  31. {python_gmp-0.4.0b5 → python_gmp-0.4.1}/tests/test_memory.py +0 -0
  32. {python_gmp-0.4.0b5 → python_gmp-0.4.1}/tests/test_utils.py +0 -0
  33. {python_gmp-0.4.0b5 → python_gmp-0.4.1}/utils.c +0 -0
  34. {python_gmp-0.4.0b5 → python_gmp-0.4.1}/utils.h +0 -0
  35. {python_gmp-0.4.0b5 → python_gmp-0.4.1}/zz.h +0 -0
@@ -7,7 +7,7 @@ jobs:
7
7
  strategy:
8
8
  fail-fast: false
9
9
  matrix:
10
- os: [ubuntu-24.04, ubuntu-24.04-arm, macos-14]
10
+ os: [ubuntu-24.04, ubuntu-24.04-arm, macos-15]
11
11
  env:
12
12
  PYTEST_ADDOPTS: --verbose
13
13
  CFLAGS: -Wall -Wpedantic -Werror -std=c17 -Wconversion
@@ -6,7 +6,7 @@ jobs:
6
6
  runs-on: ${{ matrix.os }}
7
7
  strategy:
8
8
  matrix:
9
- os: [ubuntu-24.04, ubuntu-24.04-arm, macos-13, macos-14,
9
+ os: [ubuntu-24.04, ubuntu-24.04-arm, macos-15-intel, macos-15,
10
10
  windows-2022]
11
11
  steps:
12
12
  - uses: actions/checkout@v4
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: python-gmp
3
- Version: 0.4.0b5
3
+ Version: 0.4.1
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>
@@ -39,7 +39,7 @@ Requires-Python: >=3.9
39
39
  Provides-Extra: tests
40
40
  Requires-Dist: pytest; extra == "tests"
41
41
  Requires-Dist: hypothesis; extra == "tests"
42
- Requires-Dist: mpmath>=1.4.0a6; extra == "tests"
42
+ Requires-Dist: mpmath>=1.4.0a7; extra == "tests"
43
43
  Provides-Extra: docs
44
44
  Requires-Dist: sphinx>=8.2; extra == "docs"
45
45
  Provides-Extra: develop
@@ -65,6 +65,7 @@ PyObject *
65
65
  MPZ_to_str(MPZ_Object *u, int base, int options)
66
66
  {
67
67
  size_t len;
68
+ bool negative = zz_isneg(&u->z);
68
69
 
69
70
  if ((base < INT8_MIN || base > INT8_MAX)
70
71
  || zz_sizeinbase(&u->z, (int8_t)base, &len))
@@ -79,8 +80,7 @@ MPZ_to_str(MPZ_Object *u, int base, int options)
79
80
  }
80
81
  len++;
81
82
 
82
- int8_t *buf = malloc(len), *p = buf;
83
- bool negative = zz_isneg(&u->z), cast_abs = false;
83
+ char *buf = malloc(len), *p = buf, saved_char = 0;
84
84
 
85
85
  if (!buf) {
86
86
  return PyErr_NoMemory(); /* LCOV_EXCL_LINE */
@@ -92,7 +92,7 @@ MPZ_to_str(MPZ_Object *u, int base, int options)
92
92
  if (options & OPT_PREFIX) {
93
93
  if (negative) {
94
94
  *(p++) = '-';
95
- cast_abs = true;
95
+ saved_char = '-';
96
96
  }
97
97
  if (base == 2) {
98
98
  *(p++) = '0';
@@ -111,14 +111,15 @@ MPZ_to_str(MPZ_Object *u, int base, int options)
111
111
  *(p++) = 'X';
112
112
  }
113
113
  }
114
- if (cast_abs) {
115
- (void)zz_abs(&u->z, &u->z);
114
+ if (saved_char) {
115
+ saved_char = *(--p);
116
+ assert(saved_char);
116
117
  }
117
118
 
118
- zz_err ret = zz_to_str(&u->z, (int8_t)base, p, &len);
119
+ zz_err ret = zz_to_str(&u->z, (int8_t)base, (int8_t *)p, &len);
119
120
 
120
- if (cast_abs) {
121
- (void)zz_neg(&u->z, &u->z);
121
+ if (saved_char) {
122
+ *p = saved_char;
122
123
  }
123
124
  if (ret) {
124
125
  free(buf);
@@ -374,18 +375,27 @@ MPZ_to_bytes(MPZ_Object *u, Py_ssize_t length, int is_little, int is_signed)
374
375
  }
375
376
  return bytes;
376
377
  }
377
- Py_DECREF(bytes);
378
378
  if (ret == ZZ_BUF) {
379
379
  if (zz_isneg(&u->z) && !is_signed) {
380
380
  PyErr_SetString(PyExc_OverflowError,
381
381
  "can't convert negative mpz to unsigned");
382
382
  }
383
383
  else {
384
+ #if (PY_VERSION_HEX < 0x030D08F0 || (PY_VERSION_HEX >= 0x030E0000 \
385
+ && PY_VERSION_HEX < 0x030E00C3))
386
+ if (!length && zz_cmp_i32(&u->z, -1) == ZZ_EQ) {
387
+ return bytes;
388
+ }
389
+ #endif
384
390
  PyErr_SetString(PyExc_OverflowError, "int too big to convert");
385
391
  }
392
+ Py_DECREF(bytes);
386
393
  return NULL;
387
394
  }
388
- return PyErr_NoMemory(); /* LCOV_EXCL_LINE */
395
+ /* LCOV_EXCL_START */
396
+ Py_DECREF(bytes);
397
+ return PyErr_NoMemory();
398
+ /* LCOV_EXCL_STOP */
389
399
  }
390
400
 
391
401
  static MPZ_Object *
@@ -47,7 +47,7 @@ Documentation = "https://python-gmp.readthedocs.io/en/latest/"
47
47
  [tool.setuptools_scm]
48
48
 
49
49
  [project.optional-dependencies]
50
- tests = ["pytest", "hypothesis", "mpmath>=1.4.0a6"]
50
+ tests = ["pytest", "hypothesis", "mpmath>=1.4.0a7"]
51
51
  docs = ["sphinx>=8.2"]
52
52
  develop = ["python-gmp[tests,docs]", "pre-commit", "pyperf"]
53
53
 
@@ -410,6 +410,10 @@ def test_binary_bulk(x, y):
410
410
 
411
411
 
412
412
  @given(bigints(), bigints())
413
+ @example(1, 1<<67)
414
+ @example(1, -(1<<67))
415
+ @example(-2, -1)
416
+ @example(2, -1)
413
417
  def test_binary_commutative(x, y):
414
418
  mx = mpz(x)
415
419
  my = mpz(y)
@@ -700,8 +700,8 @@ zz_to_bytes(const zz_t *u, size_t length, bool is_signed, uint8_t **buffer)
700
700
  size_t nbits = zz_bitlen(u);
701
701
 
702
702
  if (nbits > 8*length
703
- || (is_signed && nbits
704
- && (nbits == 8 * length ? !is_negative : is_negative)))
703
+ || (is_signed && ((!nbits && is_negative)
704
+ || (nbits && (nbits == 8 * length ? !is_negative : is_negative)))))
705
705
  {
706
706
  overflow:
707
707
  zz_clear(&tmp);
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