cannot release space from external GMPs.
git-svn-id: https://yap.svn.sf.net/svnroot/yap/trunk@1491 b08c6af1-5177-4d33-ba66-4b1c6b8b522a
This commit is contained in:
parent
e10213929a
commit
2d4d1f1ea8
35
C/bignum.c
35
C/bignum.c
@ -69,6 +69,41 @@ Yap_MkBigIntTerm(MP_INT *big)
|
|||||||
return AbsAppl(ret);
|
return AbsAppl(ret);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Term
|
||||||
|
Yap_MkBigIntTermCopy(MP_INT *big)
|
||||||
|
{
|
||||||
|
int sz0 = mpz_sizeinbase(big, 2);
|
||||||
|
Int nlimbs;
|
||||||
|
MP_INT *dst = (MP_INT *)(H+1);
|
||||||
|
CELL *ret = H;
|
||||||
|
|
||||||
|
if (sz0 < SIZEOF_LONG_INT*8-1) {
|
||||||
|
int out = mpz_get_si(big);
|
||||||
|
return MkIntegerTerm(out);
|
||||||
|
}
|
||||||
|
nlimbs = (big->_mp_alloc)*(sizeof(mp_limb_t)/CellSize);
|
||||||
|
if (nlimbs > (ASP-ret)-1024) {
|
||||||
|
return TermNil;
|
||||||
|
}
|
||||||
|
H[0] = (CELL)FunctorBigInt;
|
||||||
|
|
||||||
|
dst->_mp_size = big->_mp_size;
|
||||||
|
dst->_mp_alloc = big->_mp_alloc;
|
||||||
|
memmove((void *)(dst+1), (const void *)(big->_mp_d), nlimbs*CellSize);
|
||||||
|
H = (CELL *)(dst+1)+nlimbs;
|
||||||
|
if ((char *)H-(char *)ret > MAX_SPECIALS_TAG-EndSpecials) {
|
||||||
|
/* too large */
|
||||||
|
return TermNil;
|
||||||
|
}
|
||||||
|
#if GC_NO_TAGS
|
||||||
|
H[0] = (H-ret)*sizeof(CELL)+EndSpecials;
|
||||||
|
#else
|
||||||
|
H[0] = ((H-ret)*sizeof(CELL)+EndSpecials)|MBIT;
|
||||||
|
#endif
|
||||||
|
H++;
|
||||||
|
return AbsAppl(ret);
|
||||||
|
}
|
||||||
|
|
||||||
MP_INT *
|
MP_INT *
|
||||||
Yap_BigIntOfTerm(Term t)
|
Yap_BigIntOfTerm(Term t)
|
||||||
{
|
{
|
||||||
|
@ -10,8 +10,13 @@
|
|||||||
* File: c_interface.c *
|
* File: c_interface.c *
|
||||||
* comments: c_interface primitives definition *
|
* comments: c_interface primitives definition *
|
||||||
* *
|
* *
|
||||||
* Last rev: $Date: 2006-01-02 02:16:18 $,$Author: vsc $ *
|
* Last rev: $Date: 2006-01-02 02:25:44 $,$Author: vsc $ *
|
||||||
* $Log: not supported by cvs2svn $
|
* $Log: not supported by cvs2svn $
|
||||||
|
* Revision 1.78 2006/01/02 02:16:18 vsc
|
||||||
|
* support new interface between YAP and GMP, so that we don't rely on our own
|
||||||
|
* allocation routines.
|
||||||
|
* Several big fixes.
|
||||||
|
*
|
||||||
* Revision 1.77 2005/11/18 18:48:51 tiagosoares
|
* Revision 1.77 2005/11/18 18:48:51 tiagosoares
|
||||||
* support for executing c code when a cut occurs
|
* support for executing c code when a cut occurs
|
||||||
*
|
*
|
||||||
@ -421,7 +426,7 @@ YAP_MkBigNumTerm(void *big)
|
|||||||
#if USE_GMP
|
#if USE_GMP
|
||||||
Term I;
|
Term I;
|
||||||
BACKUP_H();
|
BACKUP_H();
|
||||||
I = Yap_MkBigIntTerm((MP_INT *)big);
|
I = Yap_MkBigIntTermCopy((MP_INT *)big);
|
||||||
RECOVER_H();
|
RECOVER_H();
|
||||||
return I;
|
return I;
|
||||||
#else
|
#else
|
||||||
|
@ -10,7 +10,7 @@
|
|||||||
* File: TermExt.h *
|
* File: TermExt.h *
|
||||||
* mods: *
|
* mods: *
|
||||||
* comments: Extensions to standard terms for YAP *
|
* comments: Extensions to standard terms for YAP *
|
||||||
* version: $Id: TermExt.h,v 1.4 2006-01-02 02:16:18 vsc Exp $ *
|
* version: $Id: TermExt.h,v 1.5 2006-01-02 02:25:45 vsc Exp $ *
|
||||||
*************************************************************************/
|
*************************************************************************/
|
||||||
|
|
||||||
#ifdef USE_SYSTEM_MALLOC
|
#ifdef USE_SYSTEM_MALLOC
|
||||||
@ -343,6 +343,7 @@ IsLongIntTerm (Term t)
|
|||||||
|
|
||||||
|
|
||||||
Term STD_PROTO (Yap_MkBigIntTerm, (MP_INT *));
|
Term STD_PROTO (Yap_MkBigIntTerm, (MP_INT *));
|
||||||
|
Term STD_PROTO (Yap_MkBigIntTermCopy, (MP_INT *));
|
||||||
MP_INT *STD_PROTO (Yap_BigIntOfTerm, (Term));
|
MP_INT *STD_PROTO (Yap_BigIntOfTerm, (Term));
|
||||||
|
|
||||||
inline EXTERN int IsBigIntTerm (Term);
|
inline EXTERN int IsBigIntTerm (Term);
|
||||||
|
Reference in New Issue
Block a user