From 2d4d1f1ea84483b7b937eda5b8749f1f20b8be42 Mon Sep 17 00:00:00 2001 From: vsc Date: Mon, 2 Jan 2006 02:25:45 +0000 Subject: [PATCH] cannot release space from external GMPs. git-svn-id: https://yap.svn.sf.net/svnroot/yap/trunk@1491 b08c6af1-5177-4d33-ba66-4b1c6b8b522a --- C/bignum.c | 35 +++++++++++++++++++++++++++++++++++ C/c_interface.c | 9 +++++++-- H/TermExt.h | 3 ++- 3 files changed, 44 insertions(+), 3 deletions(-) diff --git a/C/bignum.c b/C/bignum.c index b4f93a01d..a85e3fc23 100644 --- a/C/bignum.c +++ b/C/bignum.c @@ -69,6 +69,41 @@ Yap_MkBigIntTerm(MP_INT *big) 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 * Yap_BigIntOfTerm(Term t) { diff --git a/C/c_interface.c b/C/c_interface.c index 3c5a65729..990b3c0cc 100644 --- a/C/c_interface.c +++ b/C/c_interface.c @@ -10,8 +10,13 @@ * File: c_interface.c * * 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 $ +* 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 * support for executing c code when a cut occurs * @@ -421,7 +426,7 @@ YAP_MkBigNumTerm(void *big) #if USE_GMP Term I; BACKUP_H(); - I = Yap_MkBigIntTerm((MP_INT *)big); + I = Yap_MkBigIntTermCopy((MP_INT *)big); RECOVER_H(); return I; #else diff --git a/H/TermExt.h b/H/TermExt.h index 75ed499c9..3e0c1243c 100644 --- a/H/TermExt.h +++ b/H/TermExt.h @@ -10,7 +10,7 @@ * File: TermExt.h * * mods: * * 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 @@ -343,6 +343,7 @@ IsLongIntTerm (Term t) Term STD_PROTO (Yap_MkBigIntTerm, (MP_INT *)); +Term STD_PROTO (Yap_MkBigIntTermCopy, (MP_INT *)); MP_INT *STD_PROTO (Yap_BigIntOfTerm, (Term)); inline EXTERN int IsBigIntTerm (Term);