Skip to content

Optimize C extension with binary integer conversion#29

Merged
kpdyer merged 1 commit into
masterfrom
python3-with-optimized-gmp-bindings
Jan 10, 2026
Merged

Optimize C extension with binary integer conversion#29
kpdyer merged 1 commit into
masterfrom
python3-with-optimized-gmp-bindings

Conversation

@kpdyer

@kpdyer kpdyer commented Jan 10, 2026

Copy link
Copy Markdown
Owner

Replace string-based conversion between Python integers and GMP mpz_class with direct binary conversion using mpz_export/mpz_import and Python's _PyLong_FromByteArray/_PyLong_AsByteArray.

Benefits:

  • Faster: binary conversion vs string parsing
  • Cleaner: removes the sys.set_int_max_str_digits(0) workaround
  • No longer triggers Python 3.11+ integer string conversion limits

Replace string-based conversion between Python integers and GMP mpz_class
with direct binary conversion using mpz_export/mpz_import and Python's
_PyLong_FromByteArray/_PyLong_AsByteArray.

Benefits:
- Faster: binary conversion vs string parsing
- Cleaner: removes the sys.set_int_max_str_digits(0) workaround
- No longer triggers Python 3.11+ integer string conversion limits
@kpdyer kpdyer merged commit 1bc02ef into master Jan 10, 2026
10 checks passed
@kpdyer kpdyer deleted the python3-with-optimized-gmp-bindings branch January 10, 2026 19:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant