New comment by tornaria on void-packages repository https://github.com/void-linux/void-packages/pull/34030#issuecomment-1000816549 Comment: Then the library is ok, so this points to an issue with `PY_NEW()` not allocating properly, in such a way that it only triggers the second branch of `mpz_fac_ui`... Try `sage.rings.integer.Integer.factorial(27)` on `sage --valgrind`; but if that doesn't give good information the only thing I can think of is to patch the function to print stuff about z.value after `PY_NEW(Integer)` but before `sig_on()`. Maybe something like: ``` cdef mpz_ptr zz zz = (z.value) print(zz._mp_alloc, zz._mp_size, zz._mp_d) ``` Alternatively, try to step this function in gdb and look at these values. Edit: add cast to `` so it works.