[issue21922] PyLong: use GMP

Case Van Horsen report at bugs.python.org
Sat Jul 12 18:11:36 CEST 2014


Case Van Horsen added the comment:

Disclaimer: as Mark alluded to, I maintain gmpy2.

Some comments on MPIR/GMP:

For all practical purposes, building GMP on Windows requires some version of the mingw compiler toolchain. None of the performance gains of custom assembly code is available if GMP is build with the VS compiler. When compiled with mingw, GMP supports CPU detection to automatically use code optimized for the specific instruction set. This level of optimization may not be needed for Python, though.

The MPIR fork of GMP can be built with VS. Assembly code is supported via the YASM assembler plugin. Only a single instruction set is supported by the lib/dll.

gmpy2 currently uses MPIR. I've had no issues with its stability.

The mpz type has a maximum precision. IIRC, the maximum length is 2^31 bits on a 32-bit platform and 2^37 on a 64-bit platform. The mpn interface may or may not have the same restrictions. This might impact code that runs correctly, but slowly, with Python's normal PyLong implementation.

GMP does not handle out-of-memory situations gracefully. When GMP encounters a memory allocation failure (exceeding the limits above or when running our of scratch space), it will just abort. It is easy in gmpy2 to trigger an abort that will crash the Python interpreter.

My main concern is tightly linking the Python interpreter to a specific version of GMP (i.e. whatever version is used for the Windows builds or the version provided by the distribution). As long as gmpy2 can continue to use another version of GMP, it shouldn't matter to me.

GMP and MPIR are both licensed under LGPL v3+ (not v2+). I'll reserve any further licensing discussions for python-dev. 

I'll try to test the patch this weekend and that should answer some of my questions.

----------

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue21922>
_______________________________________


More information about the Python-bugs-list mailing list