Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Restore previous memory allocation behavior of GMP integers in ForeignFunctions package #3132

Merged
merged 4 commits into from
Feb 14, 2024

Conversation

d-torrance
Copy link
Member

In #3124, I switched the memory allocation of mpzT objects (GMP integers) in the ForeignFunctions package from GMP's own mpz_init (with a call to mpz_clear when finalizing the pointer) to the one we use for ZZ at top level that uses GC to allocate memory. This caused Macaulay2 to crash when calling certain GMP functions using the foreign function interface.

In particular, the examples were failing in Ubuntu 18.04 using GMP 6.1 (before lazy allocation was added in GMP 6.2). Even using GMP 6.2, we'd get these same crashes using large enough integers to trigger memory allocation.

In this PR, we restore the previous behavior of using mpz_init. We also make a few other related changes:

  • Check that some of the ZZ's that we call toInt on really fit inside an int.
  • Remove a couple functions from gmp.d that were created for #3124 that are no longer used.
  • Make the corresponding change for allocation of mpfrT objects (MPFR reals). Until I figure out what's going on, the finalization code is commented out because otherwise we get segfaults during garbage collection.

Closes: #3128

Use GMP's own allocation functions rather than allocating memory using
the garbage collector.  This was causing crashes when calling GMP
functions, especially with GMP < 6.2.

Closes: Macaulay2#3128
@DanGrayson DanGrayson merged commit 6a51eca into Macaulay2:development Feb 14, 2024
6 checks passed
@d-torrance d-torrance deleted the ffi-gmp branch March 11, 2024 12:27
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.

2 participants