Re: [RFC] Big Integer Support
| From: | Andrea Faulds | Date: | Fri, 17 Oct 2014 19:00:20 +0000 |
| Subject: | Re: [RFC] Big Integer Support | ||
| References: | 1 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-78149@lists.php.net to get a copy of this message | ||
> On 10 Oct 2014, at 22:33, Andrea Faulds <ajf@ajf.me> wrote:
>
> The RFC can be found here: https://wiki.php.net/rfc/bigint
>
> The patch is, as I mentioned, incomplete. Additionally, there are quite a few matters left to
> be decided (see Open Questions). However, I think I should put this formally under discussion now.
I promise not to mail the list for every change I make to this RFC. ;)
But I do have quite a big one to announce. Previously, some issues with the GNU Multiple Precision
Arithmetic Library (GMP) had been discovered. In particular, it is not liberally licensed (LGPL), it
only has one set of custom allocators, which causes segfaults from other libraries which use it
because PHP defines its own allocators, and it immediately calls an un-hookable abort() in certain
failure cases.
I was unaware of any good alternatives, however today I was pointed by Chris Wright (DaveRandom) on
StackOverflow towards a new possibility: LibTomMath. It is liberally licensed (dual-licensed as
Public Domain and WTFPL), written in pure C, packaged for multiple platforms, and it lacks the
immediate abort() problem to the best of my knowledge. Plus, it will not cause any segfaults when we
use custom allocators, as I do not believe PHP uses any libraries which use LibTomMath at present.
If you’re worried about whether it’s battle-tested, it’s used by another dynamic language,
Tcl.
Because it appears to solve all three major issues with GMP, I am currently porting my bigint branch
to use it. This is possible because the entire implementation of bigints is abstracted, meaning you
can swap out back-ends. If we wished to, we could quite simply allow the choice of GMP at
compile-time, or indeed any other back-end.
I should note that LibTomMath certainly isn’t perfect. I don’t believe it is optimised to the
same degree GMP is. That being said, again, it does seem to solve all the major problems I had with
GMP. So I have few qualms in making the patch use it, especially given that it is easy to swap out
the back-end.
I’ve updated the RFC to reflect this new state of affairs: https://wiki.php.net/rfc/bigint
Thoughts?
--
Andrea Faulds
http://ajf.me/