On Aug 27, 5:16 pm, Juanjo <juanjose.garciarip...@googlemail.com>
wrote:
> I have just uploaded some patches to our source repositories that
> allow ECL coexist with a GMP library which uses other memory
> allocation functions. The changes are available in the CVS and git
> repositorieshttp://ecls.sf.net/download.html
> and will undergo automated testing during the following days.

Wow, thank you very much! this is wonderful. The coredump doesn't
happen anymore. There is one problem:

In big_register0_get(void), a bignum gets initialized by a limb
pointer to a preallocated array big_register_limbs.
If GMP wants to reallocate the limbs of a register, it will be calling
a free or a realloc on that memory area, which has not been allocated
by GMP's memory manager. The memory manager that ECL normally
installs, mp_free, explicitly checks for a pointer in that range and
avoids deallocating them. Another memory manager will likely cause a
crash at this point.

Indeed, if one sets ECL_OPT_SET_GMP_MEMORY_FUNCTIONS = 0

and executes something like (expt 2 2000) , which need more limbs than
BIGNUM_REGISTER_SIZE ( = 16), ecl crashes.

One fix would be (if ECL_OPT_SET_GMP_MEMORY_FUNCTIONS = 0):

 - In the init-env, do an mpz_init2(big_register
[i],BITS_PER_LIMB*BIGNUM_REGISTER_SIZE) for i=0,1,2
 - In big_register*_get, don't do anything except return *big_register
[i] (or possibly zero out the register)
 - In big_register_free, optionally (if you're worried about one big
integer computation eating up buffer space forever):
   if (x->big.big_dim > BIGNUM_REGISTER_SIZE) { mpz_realloc2( x-
>big_num, BITS_PER_LIMB*BIGNUM_REGISTER_SIZE) }

Still not very expensive in runtime, except that every register_get
and register_free has to check ECL_OPT_SET_GMP_MEMORY_FUNCTIONS.

Note that the approach above would also work with ecl's own memory
manager. The only disadvantage might be that the register limbs might
be jumping around a bit in the Boehm-Weiser heap, rather than always
starting out life in the environment array.

Thanks for the wonderful work!

--~--~---------~--~----~------------~-------~--~----~
To post to this group, send an email to sage-devel@googlegroups.com
To unsubscribe from this group, send an email to 
sage-devel-unsubscr...@googlegroups.com
For more options, visit this group at http://groups.google.com/group/sage-devel
URLs: http://www.sagemath.org
-~----------~----~----~----~------~----~------~--~---

Reply via email to