fix support for comparing weird terms.

This commit is contained in:
Vítor Santos Costa 2011-02-02 19:37:11 +00:00
parent 83e918ac68
commit cbf6caddbd
4 changed files with 49 additions and 4 deletions

View File

@ -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;

View File

@ -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;

View File

@ -22,6 +22,7 @@
#if HAVE_STRING_H
#include <string.h>
#endif
#include <wchar.h>
#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;

@ -1 +1 @@
Subproject commit 29151b2fe68f2dc727cdc07040e1fa1ad4fcca20
Subproject commit 73e4e086d06c54210100f0faaeccbea276c707eb