diff --git a/C/c_interface.c b/C/c_interface.c index eac1cb109..1ecb74f92 100755 --- a/C/c_interface.c +++ b/C/c_interface.c @@ -708,7 +708,7 @@ YAP_MkBlobTerm(unsigned int sz) } I = AbsAppl(H); H[0] = (CELL)FunctorBigInt; - H[1] = BIG_INT; + H[1] = ARRAY_INT; dst = (MP_INT *)(H+2); dst->_mp_size = 0L; dst->_mp_alloc = sz; diff --git a/C/cmppreds.c b/C/cmppreds.c index 757c64329..cc3bc49db 100644 --- a/C/cmppreds.c +++ b/C/cmppreds.c @@ -165,7 +165,7 @@ static int compare_complex(register CELL *pt0, register CELL *pt0_end, register } else if (IsLongIntTerm(d1)) { out = Yap_gmp_tcmp_int_big(d0, LongIntOfTerm(d1)); } else if (IsBigIntTerm(d1)) { - out = Yap_gmp_tcmp_big_big(d1, d1); + out = Yap_gmp_tcmp_big_big(d0, d1); } else if (IsRefTerm(d1)) out = 1 ; else out = -1; diff --git a/C/gmp_support.c b/C/gmp_support.c index c28159da8..7304b0244 100755 --- a/C/gmp_support.c +++ b/C/gmp_support.c @@ -22,6 +22,7 @@ #if HAVE_STRING_H #include #endif +#include #if USE_GMP @@ -1289,6 +1290,7 @@ Yap_gmp_tcmp_big_big(Term t1, Term t2) { CELL *pt1 = RepAppl(t1); CELL *pt2 = RepAppl(t2); + if (pt1[1] == BIG_INT && pt2[1] == BIG_INT) { MP_INT *b1 = Yap_BigIntOfTerm(t1); MP_INT *b2 = Yap_BigIntOfTerm(t2); @@ -1301,7 +1303,50 @@ Yap_gmp_tcmp_big_big(Term t1, Term t2) return 1; } else if (pt1[1] == BIG_RATIONAL) { b1 = Yap_BigRatOfTerm(t1); - } else if (pt1[1] == BIG_RATIONAL) { + } else if (pt1[1] == BLOB_STRING) { + char *s1 = Yap_BlobStringOfTerm(t1); + if (pt2[1] == BLOB_STRING) { + char *s2 = Yap_BlobStringOfTerm(t2); + return strcmp(s1,s2); + } else if (pt2[1] == BLOB_WIDE_STRING) { + wchar_t *wcs2 = Yap_BlobWideStringOfTerm(t2), *wcs1, *tmp1; + int out; + size_t n = strlen(s1); + if (!(wcs1 = (wchar_t *)malloc((n+1)*sizeof(wchar_t)))) { + Yap_Error(OUT_OF_HEAP_ERROR, t1, "compare/3"); + return 0; + } + tmp1 = wcs1; + while (*s1) { + *tmp1++ = *s1++; + } + out = wcscmp(wcs1, wcs2); + free(wcs1); + return out; + } + b1 = Yap_BigRatOfTerm(t1); + } else if (pt1[1] == BLOB_WIDE_STRING) { + wchar_t *wcs1 = Yap_BlobWideStringOfTerm(t1); + if (pt2[1] == BLOB_STRING) { + char *s2 = Yap_BlobStringOfTerm(t2); + wchar_t *wcs2, *tmp2; + int out; + size_t n = strlen(s2); + if (!(wcs2 = (wchar_t *)malloc((n+1)*sizeof(wchar_t)))) { + Yap_Error(OUT_OF_HEAP_ERROR, t2, "compare/3"); + return 0; + } + tmp2 = wcs2; + while (*s2) { + *tmp2++ = *s2++; + } + out = wcscmp(wcs1, wcs2); + free(wcs2); + return out; + } else if (pt2[1] == BLOB_WIDE_STRING) { + wchar_t *wcs2 = Yap_BlobWideStringOfTerm(t2); + return wcscmp(wcs1,wcs2); + } b1 = Yap_BigRatOfTerm(t1); } else { return pt1-pt2; diff --git a/packages/jpl b/packages/jpl index 29151b2fe..73e4e086d 160000 --- a/packages/jpl +++ b/packages/jpl @@ -1 +1 @@ -Subproject commit 29151b2fe68f2dc727cdc07040e1fa1ad4fcca20 +Subproject commit 73e4e086d06c54210100f0faaeccbea276c707eb