This commit is contained in:
Vitor Santos Costa 2018-05-16 02:58:37 +01:00
parent 67a88a196d
commit d7c4ac95e0
2 changed files with 123 additions and 123 deletions

View File

@ -30,8 +30,8 @@ static char SccsId[] = "%W% %G%";
* @ingroup builtins
* @{
*
* @brief The following predicates are used to manipulate atoms, strings, lists of
* codes and lists of chars:
* @brief The following predicates are used to manipulate atoms, strings, lists
* of codes and lists of chars:
*
* \toc
*
@ -713,8 +713,7 @@ static Int number_chars(USES_REGS1) {
/* ARG1 unbound */
Term t = Deref(ARG2);
Term tf = Yap_ListToNumber(t PASS_REGS);
if (tf)
{
if (tf) {
pop_text_stack(l);
return Yap_unify(ARG1, tf);
}
@ -1326,8 +1325,7 @@ restart_aux:
}
while (t1 != TermNil) {
inpv[i].type = YAP_STRING_ATOM,
inpv[i].val.t = HeadOfTerm(t1);
inpv[i].type = YAP_STRING_ATOM, inpv[i].val.t = HeadOfTerm(t1);
i++;
t1 = TailOfTerm(t1);
}
@ -1365,12 +1363,11 @@ restart_aux:
if (*tailp != TermNil) {
LOCAL_Error_TYPE = TYPE_ERROR_LIST;
} else {
seq_tv_t *inpv = (seq_tv_t *)malloc(n * sizeof(seq_tv_t)), out;
seq_tv_t *inpv = (seq_tv_t *)Malloc(n * sizeof(seq_tv_t));
seq_tv_t *out = (seq_tv_t *)Malloc( sizeof(seq_tv_t));
int i = 0;
if (!inpv) {
LOCAL_Error_TYPE = RESOURCE_ERROR_HEAP;
free(inpv);
goto error;
}
@ -1380,15 +1377,14 @@ restart_aux:
i++;
t1 = TailOfTerm(t1);
}
out.type = YAP_STRING_STRING;
if (!Yap_Concat_Text(n, inpv, &out PASS_REGS)) {
free(inpv);
out->type = YAP_STRING_STRING;
if (!Yap_Concat_Text(n, inpv, out PASS_REGS)) {
goto error;
}
free(inpv);
if (out.val.t) {
if (out->val.t) {
bool rc = Yap_unify(ARG2, out->val.t);
pop_text_stack(l);
return Yap_unify(ARG2, out.val.t);
return rc;
}
}
error:
@ -1417,17 +1413,18 @@ restart_aux:
if (*tailp != TermNil) {
LOCAL_Error_TYPE = TYPE_ERROR_LIST;
} else {
seq_tv_t *inpv = (seq_tv_t *)malloc(n * sizeof(seq_tv_t)), out;
seq_tv_t *inpv = (seq_tv_t *)Malloc(n * sizeof(seq_tv_t));
seq_tv_t *out = (seq_tv_t *)Malloc(sizeof(seq_tv_t));
int i = 0;
Atom at;
if (n == 1) {
bool rc = Yap_unify(ARG2, HeadOfTerm(t1));
pop_text_stack(l);
return Yap_unify(ARG2, HeadOfTerm(t1));
return rc;
}
if (!inpv) {
LOCAL_Error_TYPE = RESOURCE_ERROR_HEAP;
free(inpv);
goto error;
}
@ -1439,16 +1436,15 @@ restart_aux:
i++;
t1 = TailOfTerm(t1);
}
out.type = YAP_STRING_ATOM;
if (!Yap_Concat_Text(n, inpv, &out PASS_REGS)) {
free(inpv);
out->type = YAP_STRING_ATOM;
if (!Yap_Concat_Text(n, inpv, out PASS_REGS)) {
goto error;
}
free(inpv);
at = out.val.a;
if (at) {
pop_text_stack(l);
return Yap_unify(ARG2, MkAtomTerm(at));
at = out->val.a;
if (at) {
bool rc = Yap_unify(ARG2, MkAtomTerm(at));
return rc;
}
}
error:
@ -1457,7 +1453,6 @@ error:
goto restart_aux;
}
{
pop_text_stack(l);
return FALSE;
}
}
@ -1473,13 +1468,12 @@ restart_aux:
if (*tailp != TermNil) {
LOCAL_Error_TYPE = TYPE_ERROR_LIST;
} else {
seq_tv_t *inpv = (seq_tv_t *)malloc(n * sizeof(seq_tv_t)), out;
seq_tv_t *inpv = (seq_tv_t *)Malloc(n * sizeof(seq_tv_t)), out;
int i = 0;
Atom at;
if (!inpv) {
LOCAL_Error_TYPE = RESOURCE_ERROR_HEAP;
free(inpv);
goto error;
}
@ -1492,10 +1486,8 @@ restart_aux:
}
out.type = YAP_STRING_STRING;
if (!Yap_Concat_Text(n, inpv, &out PASS_REGS)) {
free(inpv);
goto error;
}
free(inpv);
at = out.val.a;
if (at) {
pop_text_stack(l);
@ -1525,13 +1517,12 @@ restart_aux:
if (*tailp != TermNil) {
LOCAL_Error_TYPE = TYPE_ERROR_LIST;
} else {
seq_tv_t *inpv = (seq_tv_t *)malloc((n * 2 - 1) * sizeof(seq_tv_t)), out;
seq_tv_t *inpv = (seq_tv_t *)Malloc((n * 2 - 1) * sizeof(seq_tv_t)), out;
int i = 0;
Atom at;
if (!inpv) {
LOCAL_Error_TYPE = RESOURCE_ERROR_HEAP;
free(inpv);
goto error;
}
@ -1548,10 +1539,8 @@ restart_aux:
}
out.type = YAP_STRING_STRING;
if (!Yap_Concat_Text(2 * n - 1, inpv, &out PASS_REGS)) {
free(inpv);
goto error;
}
free(inpv);
at = out.val.a;
if (at) {
pop_text_stack(l);
@ -2496,8 +2485,7 @@ static Int sub_atomic(bool sub_atom, bool sub_string USES_REGS) {
if (sz != minv + len + after) {
cut_fail();
}
return do_cut(check_sub_string_at(
minv, p, sm, len));
return do_cut(check_sub_string_at(minv, p, sm, len));
} else if ((mask & (SUB_ATOM_HAS_MIN | SUB_ATOM_HAS_VAL)) ==
(SUB_ATOM_HAS_MIN | SUB_ATOM_HAS_VAL)) {
if (!Yap_unify(ARG4, MkIntegerTerm(sz - minv - len)))
@ -2515,7 +2503,8 @@ static Int sub_atomic(bool sub_atom, bool sub_string USES_REGS) {
return do_cut(check_sub_string_bef(
sz - after, p, RepAtom(AtomOfTerm(tout))->UStrOfAE));
} else {
return do_cut(check_sub_string_bef(sz - after, p, UStringOfTerm(tout)));}
return do_cut(check_sub_string_bef(sz - after, p, UStringOfTerm(tout)));
}
} else if ((mask & (SUB_ATOM_HAS_MIN | SUB_ATOM_HAS_SIZE)) ==
(SUB_ATOM_HAS_MIN | SUB_ATOM_HAS_SIZE)) {
if (minv + len + after > sz) {

View File

@ -32,7 +32,9 @@ inline static size_t min_size(size_t i, size_t j) { return (i < j ? i : j); }
#endif
#if !defined(HAVE_STPCPY) && !defined(__APPLE__)
inline static void* __stpcpy(void * i, const void * j) { return strcpy(i,j)+strlen(j);}
inline static void *__stpcpy(void *i, const void *j) {
return strcpy(i, j) + strlen(j);
}
#define stpcpy __stpcpy
#endif
@ -185,9 +187,9 @@ void *Realloc(void *pt, size_t sz USES_REGS) {
return o + 1;
}
/**
* Export a local memory object as a RO object to the outside world, that is, recovering as much storage as one can.
* Export a local memory object as a RO object to the outside world, that is,
* recovering as much storage as one can.
* @param pt pointer to object
* @return new object
*/
@ -258,8 +260,7 @@ static void *codes2buf(Term t0, void *b0, bool *get_codes USES_REGS) {
}
Int code = IntegerOfTerm(hd);
if (code < 0) {
Yap_ThrowError(TYPE_ERROR_CHARACTER_CODE, hd,
"scanning list of codes");
Yap_ThrowError(TYPE_ERROR_CHARACTER_CODE, hd, "scanning list of codes");
return NULL;
}
length += put_utf8(ar, code);
@ -439,8 +440,10 @@ unsigned char *Yap_readText(seq_tv_t *inp USES_REGS) {
}
LOCAL_ActiveError->errorRawTerm = inp->val.t;
}
if (LOCAL_Error_TYPE != YAP_NO_ERROR)
if (LOCAL_Error_TYPE != YAP_NO_ERROR) {
pop_text_stack(lvl);
return NULL;
}
if (IsAtomTerm(inp->val.t) && inp->type & YAP_STRING_ATOM) {
// this is a term, extract to a buffer, and representation is wide
@ -451,8 +454,10 @@ unsigned char *Yap_readText(seq_tv_t *inp USES_REGS) {
memset(o, 0, 4);
return pop_output_text_stack(lvl, o);
}
if (inp->type & YAP_STRING_WITH_BUFFER)
if (inp->type & YAP_STRING_WITH_BUFFER) {
pop_text_stack(lvl);
return at->UStrOfAE;
}
size_t sz = strlen(at->StrOfAE);
inp->type |= YAP_STRING_IN_TMP;
void *o = Malloc(sz + 1);
@ -472,7 +477,7 @@ unsigned char *Yap_readText(seq_tv_t *inp USES_REGS) {
return (unsigned char *)UStringOfTerm(inp->val.t);
inp->type |= YAP_STRING_IN_TMP;
size_t sz = strlen(s);
char *o = BaseMalloc(sz + 1);
char *o = Malloc(sz + 1);
strcpy(o, s);
return pop_output_text_stack(lvl, o);
}
@ -480,17 +485,20 @@ unsigned char *Yap_readText(seq_tv_t *inp USES_REGS) {
(YAP_STRING_CODES | YAP_STRING_ATOMS)) &&
IsPairOrNilTerm(inp->val.t)) {
// Yap_DebugPlWriteln(inp->val.t);
return Yap_ListToBuffer(NULL, inp->val.t, inp PASS_REGS);
return pop_output_text_stack(lvl,
Yap_ListToBuffer(NULL, inp->val.t, inp PASS_REGS) );
// this is a term, extract to a sfer, and representation is wide
}
if (inp->type & YAP_STRING_CODES && IsPairOrNilTerm(inp->val.t)) {
// Yap_DebugPlWriteln(inp->val.t);
return Yap_ListOfCodesToBuffer(NULL, inp->val.t, inp PASS_REGS);
return pop_output_text_stack(lvl,
Yap_ListOfCodesToBuffer(NULL, inp->val.t, inp PASS_REGS));
// this is a term, extract to a sfer, and representation is wide
}
if (inp->type & YAP_STRING_ATOMS && IsPairOrNilTerm(inp->val.t)) {
// Yap_DebugPlWriteln(inp->val.t);
return Yap_ListOfAtomsToBuffer(NULL, inp->val.t, inp PASS_REGS);
return pop_output_text_stack(lvl,
Yap_ListOfAtomsToBuffer(NULL, inp->val.t, inp PASS_REGS));
// this is a term, extract to a buffer, and representation is wide
}
if (inp->type & YAP_STRING_INT && IsIntegerTerm(inp->val.t)) {
@ -508,6 +516,7 @@ unsigned char *Yap_readText(seq_tv_t *inp USES_REGS) {
char *s;
// Yap_DebugPlWriteln(inp->val.t);
if (!Yap_FormatFloat(FloatOfTerm(inp->val.t), &s, 1024)) {
pop_text_stack(lvl);
return NULL;
}
return pop_output_text_stack(lvl, s);
@ -989,9 +998,10 @@ bool Yap_Concat_Text(int tot, seq_tv_t inp[], seq_tv_t *out USES_REGS) {
void **bufv;
unsigned char *buf;
int i, j;
//int lvl = push_text_stack();
bufv = Malloc(tot * sizeof(unsigned char *));
if (!bufv) {
//pop_text_stack(lvl);
return NULL;
}
for (i = 0, j = 0; i < tot; i++) {
@ -999,6 +1009,7 @@ bool Yap_Concat_Text(int tot, seq_tv_t inp[], seq_tv_t *out USES_REGS) {
unsigned char *nbuf = Yap_readText(inp + i PASS_REGS);
if (!nbuf) {
//pop_text_stack(lvl);
return NULL;
}
// if (!nbuf[0])
@ -1014,6 +1025,7 @@ bool Yap_Concat_Text(int tot, seq_tv_t inp[], seq_tv_t *out USES_REGS) {
buf = concat(tot, bufv PASS_REGS);
}
bool rc = write_Text(buf, out PASS_REGS);
//pop_text_stack( lvl );
return rc;
}
@ -1080,8 +1092,8 @@ bool Yap_Splice_Text(int n, size_t cuts[], seq_tv_t *inp,
return false;
}
buf0 = slice(0, u_l0, buf PASS_REGS);
buf0 = pop_output_text_stack(lvl, buf0);
bool rc = write_Text(buf0, outv PASS_REGS);
pop_text_stack(lvl);
return rc;
}
}
@ -1095,8 +1107,8 @@ bool Yap_Splice_Text(int n, size_t cuts[], seq_tv_t *inp,
if (i > 0 && cuts[i] == 0)
break;
void *bufi = slice(next, cuts[i], buf PASS_REGS);
bufi = pop_output_text_stack(lvl, bufi);
if (!write_Text(bufi, outv + i PASS_REGS)) {
pop_text_stack(lvl);
return false;
}
}
@ -1105,7 +1117,6 @@ bool Yap_Splice_Text(int n, size_t cuts[], seq_tv_t *inp,
return true;
}
/**
* Convert from a predicate structure to an UTF-8 string of the form
*