avoid sideffects from MkBigInt
git-svn-id: https://yap.svn.sf.net/svnroot/yap/trunk@1524 b08c6af1-5177-4d33-ba66-4b1c6b8b522a
This commit is contained in:
parent
1c77e3cf32
commit
745fed2679
17
C/absmi.c
17
C/absmi.c
@ -10,8 +10,13 @@
|
||||
* *
|
||||
* File: absmi.c *
|
||||
* comments: Portable abstract machine interpreter *
|
||||
* Last rev: $Date: 2006-01-17 14:10:40 $,$Author: vsc $ *
|
||||
* Last rev: $Date: 2006-01-18 15:34:53 $,$Author: vsc $ *
|
||||
* $Log: not supported by cvs2svn $
|
||||
* Revision 1.192 2006/01/17 14:10:40 vsc
|
||||
* YENV may be an HW register (breaks some tabling code)
|
||||
* All YAAM instructions are now brackedted, so Op introduced an { and EndOp introduces an }. This is because Ricardo assumes that.
|
||||
* Fix attvars when COROUTING is undefined.
|
||||
*
|
||||
* Revision 1.191 2006/01/02 02:16:17 vsc
|
||||
* support new interface between YAP and GMP, so that we don't rely on our own
|
||||
* allocation routines.
|
||||
@ -329,7 +334,15 @@ AritFunctorOfTerm(Term t) {
|
||||
#define TMP_BIG(v) Yap_BigTmp
|
||||
#define RINT(v) return(MkIntegerTerm(v))
|
||||
#define RFLOAT(v) return(MkFloatTerm(v))
|
||||
#define RBIG(v) return(Yap_MkBigIntTerm(v))
|
||||
#define RBIG(v) return(rbig(v))
|
||||
|
||||
static inline Term rbig(MP_INT *big)
|
||||
{
|
||||
Term t = Yap_MkBigIntTerm(big);
|
||||
mpz_clear(big);
|
||||
return t;
|
||||
}
|
||||
|
||||
#define RERROR() return(TermNil)
|
||||
|
||||
#define ArithIEval(t,v) Yap_Eval(Deref(t),v)
|
||||
|
@ -751,7 +751,7 @@ Yap_GetValue(Atom a)
|
||||
}
|
||||
#ifdef USE_GMP
|
||||
else {
|
||||
out = Yap_MkBigIntTermCopy(Yap_BigIntOfTerm(out));
|
||||
out = Yap_MkBigIntTerm(Yap_BigIntOfTerm(out));
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
@ -101,6 +101,7 @@ EvalToTerm(blob_type f, union arith_ret *res)
|
||||
case big_int_e:
|
||||
{
|
||||
Term t = Yap_MkBigIntTerm(res->big);
|
||||
mpz_clear(res->big);
|
||||
return t;
|
||||
}
|
||||
#endif
|
||||
|
@ -67,6 +67,7 @@ EvalToTerm(blob_type f, union arith_ret *res)
|
||||
case big_int_e:
|
||||
{
|
||||
Term t = Yap_MkBigIntTerm(res->big);
|
||||
mpz_clear(res->big);
|
||||
return t;
|
||||
}
|
||||
#endif
|
||||
|
39
C/bignum.c
39
C/bignum.c
@ -37,44 +37,6 @@ Yap_MkBigIntTerm(MP_INT *big)
|
||||
MP_INT *dst = (MP_INT *)(H+1);
|
||||
CELL *ret = H;
|
||||
|
||||
if (mpz_fits_slong_p(big)) {
|
||||
int out = mpz_get_si(big);
|
||||
mpz_clear(big);
|
||||
return MkIntegerTerm(out);
|
||||
}
|
||||
nlimbs = (big->_mp_alloc)*(sizeof(mp_limb_t)/CellSize);
|
||||
if (nlimbs > (ASP-ret)-1024) {
|
||||
mpz_clear(big);
|
||||
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 */
|
||||
mpz_clear(big);
|
||||
return TermNil;
|
||||
}
|
||||
#if GC_NO_TAGS
|
||||
H[0] = (H-ret)*sizeof(CELL)+EndSpecials;
|
||||
#else
|
||||
H[0] = ((H-ret)*sizeof(CELL)+EndSpecials)|MBIT;
|
||||
#endif
|
||||
H++;
|
||||
mpz_clear(big);
|
||||
return AbsAppl(ret);
|
||||
}
|
||||
|
||||
Term
|
||||
Yap_MkBigIntTermCopy(MP_INT *big)
|
||||
{
|
||||
Int nlimbs;
|
||||
MP_INT *dst = (MP_INT *)(H+1);
|
||||
CELL *ret = H;
|
||||
|
||||
if (mpz_fits_slong_p(big)) {
|
||||
int out = mpz_get_si(big);
|
||||
return MkIntegerTerm(out);
|
||||
@ -132,6 +94,7 @@ Yap_MkULLIntTerm(YAP_ULONG_LONG n)
|
||||
return MkIntegerTerm(mpz_get_si(new));
|
||||
}
|
||||
t = Yap_MkBigIntTerm(new);
|
||||
mpz_clear(new);
|
||||
return t;
|
||||
#else
|
||||
return MkIntegerTerm(n);
|
||||
|
@ -10,8 +10,12 @@
|
||||
* File: c_interface.c *
|
||||
* comments: c_interface primitives definition *
|
||||
* *
|
||||
* Last rev: $Date: 2006-01-16 02:57:51 $,$Author: vsc $ *
|
||||
* Last rev: $Date: 2006-01-18 15:34:53 $,$Author: vsc $ *
|
||||
* $Log: not supported by cvs2svn $
|
||||
* Revision 1.81 2006/01/16 02:57:51 vsc
|
||||
* fix bug with very large integers
|
||||
* fix bug where indexing code was looking at code after a cut.
|
||||
*
|
||||
* Revision 1.80 2006/01/02 03:35:44 vsc
|
||||
* fix interface and docs
|
||||
*
|
||||
@ -432,7 +436,7 @@ YAP_MkBigNumTerm(void *big)
|
||||
#if USE_GMP
|
||||
Term I;
|
||||
BACKUP_H();
|
||||
I = Yap_MkBigIntTermCopy((MP_INT *)big);
|
||||
I = Yap_MkBigIntTerm((MP_INT *)big);
|
||||
RECOVER_H();
|
||||
return I;
|
||||
#else
|
||||
|
12
C/eval.c
12
C/eval.c
@ -44,15 +44,19 @@ EvalToTerm(blob_type bt, union arith_ret *res)
|
||||
{
|
||||
switch (bt) {
|
||||
case long_int_e:
|
||||
return(MkIntegerTerm(res->Int));
|
||||
return MkIntegerTerm(res->Int);
|
||||
case double_e:
|
||||
return(MkFloatTerm(res->dbl));
|
||||
return MkFloatTerm(res->dbl);
|
||||
#ifdef USE_GMP
|
||||
case big_int_e:
|
||||
return(Yap_MkBigIntTerm(res->big));
|
||||
{
|
||||
Term t = Yap_MkBigIntTerm(res->big);
|
||||
mpz_clear(res->big);
|
||||
return t;
|
||||
}
|
||||
#endif
|
||||
default:
|
||||
return(TermNil);
|
||||
return TermNil;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -442,6 +442,7 @@ ParseTerm(int prio, JMPBUFF *FailBuff)
|
||||
mpz_init(new);
|
||||
mpz_neg(new, Yap_BigIntOfTerm(t));
|
||||
t = Yap_MkBigIntTerm(new);
|
||||
mpz_clear(new);
|
||||
}
|
||||
#endif
|
||||
else
|
||||
|
@ -229,6 +229,7 @@ read_int_overflow(const char *s, Int base, Int val)
|
||||
|
||||
mpz_init_set_str (new, s, base);
|
||||
t = Yap_MkBigIntTerm(new);
|
||||
mpz_clear(new);
|
||||
return t;
|
||||
#else
|
||||
/* try to scan it as a float */
|
||||
|
@ -10,7 +10,7 @@
|
||||
* File: TermExt.h *
|
||||
* mods: *
|
||||
* comments: Extensions to standard terms for YAP *
|
||||
* version: $Id: TermExt.h,v 1.5 2006-01-02 02:25:45 vsc Exp $ *
|
||||
* version: $Id: TermExt.h,v 1.6 2006-01-18 15:34:54 vsc Exp $ *
|
||||
*************************************************************************/
|
||||
|
||||
#ifdef USE_SYSTEM_MALLOC
|
||||
@ -343,7 +343,6 @@ 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);
|
||||
|
@ -16,6 +16,7 @@
|
||||
|
||||
<h2>Yap-5.1.0:</h2>
|
||||
<ul>
|
||||
<li> FIXED: ok, MkBigInt shouldn't free the bigint.</li>
|
||||
<li> FIXED: MkBigInt already frees bigint.</li>
|
||||
<li> FIXED: don't pass a pointer to a mpz_t. (Nuno Fonseca)</li>
|
||||
<li> FIXED: YENV may be an HW register ('d break some tabling code)
|
||||
|
Reference in New Issue
Block a user