memmgr
This commit is contained in:
parent
67a88a196d
commit
d7c4ac95e0
123
C/atomic.c
123
C/atomic.c
@ -23,19 +23,19 @@ static char SccsId[] = "%W% %G%";
|
|||||||
*
|
*
|
||||||
* @namespace prolog
|
* @namespace prolog
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @defgroup Predicates_on_Atoms Predicates on Atoms and Strings
|
* @defgroup Predicates_on_Atoms Predicates on Atoms and Strings
|
||||||
* @ingroup builtins
|
* @ingroup builtins
|
||||||
* @{
|
* @{
|
||||||
*
|
*
|
||||||
* @brief The following predicates are used to manipulate atoms, strings, lists of
|
* @brief The following predicates are used to manipulate atoms, strings, lists
|
||||||
* codes and lists of chars:
|
* of codes and lists of chars:
|
||||||
*
|
*
|
||||||
* \toc
|
* \toc
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#define HAS_CACHE_REGS 1
|
#define HAS_CACHE_REGS 1
|
||||||
/*
|
/*
|
||||||
@ -713,18 +713,17 @@ static Int number_chars(USES_REGS1) {
|
|||||||
/* ARG1 unbound */
|
/* ARG1 unbound */
|
||||||
Term t = Deref(ARG2);
|
Term t = Deref(ARG2);
|
||||||
Term tf = Yap_ListToNumber(t PASS_REGS);
|
Term tf = Yap_ListToNumber(t PASS_REGS);
|
||||||
if (tf)
|
if (tf) {
|
||||||
{
|
pop_text_stack(l);
|
||||||
pop_text_stack(l);
|
return Yap_unify(ARG1, tf);
|
||||||
return Yap_unify(ARG1, tf);
|
}
|
||||||
}
|
|
||||||
|
|
||||||
LOCAL_ActiveError->errorRawTerm = 0;
|
LOCAL_ActiveError->errorRawTerm = 0;
|
||||||
Yap_ThrowExistingError();
|
Yap_ThrowExistingError();
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @pred number_atom(? _I_,? _A_){te
|
/** @pred number_atom(? _I_,? _A_){te
|
||||||
@ -1326,8 +1325,7 @@ restart_aux:
|
|||||||
}
|
}
|
||||||
|
|
||||||
while (t1 != TermNil) {
|
while (t1 != TermNil) {
|
||||||
inpv[i].type = YAP_STRING_ATOM,
|
inpv[i].type = YAP_STRING_ATOM, inpv[i].val.t = HeadOfTerm(t1);
|
||||||
inpv[i].val.t = HeadOfTerm(t1);
|
|
||||||
i++;
|
i++;
|
||||||
t1 = TailOfTerm(t1);
|
t1 = TailOfTerm(t1);
|
||||||
}
|
}
|
||||||
@ -1365,12 +1363,11 @@ restart_aux:
|
|||||||
if (*tailp != TermNil) {
|
if (*tailp != TermNil) {
|
||||||
LOCAL_Error_TYPE = TYPE_ERROR_LIST;
|
LOCAL_Error_TYPE = TYPE_ERROR_LIST;
|
||||||
} else {
|
} 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;
|
int i = 0;
|
||||||
|
|
||||||
if (!inpv) {
|
if (!inpv) {
|
||||||
LOCAL_Error_TYPE = RESOURCE_ERROR_HEAP;
|
LOCAL_Error_TYPE = RESOURCE_ERROR_HEAP;
|
||||||
free(inpv);
|
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1380,15 +1377,14 @@ restart_aux:
|
|||||||
i++;
|
i++;
|
||||||
t1 = TailOfTerm(t1);
|
t1 = TailOfTerm(t1);
|
||||||
}
|
}
|
||||||
out.type = YAP_STRING_STRING;
|
out->type = YAP_STRING_STRING;
|
||||||
if (!Yap_Concat_Text(n, inpv, &out PASS_REGS)) {
|
if (!Yap_Concat_Text(n, inpv, out PASS_REGS)) {
|
||||||
free(inpv);
|
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
free(inpv);
|
if (out->val.t) {
|
||||||
if (out.val.t) {
|
bool rc = Yap_unify(ARG2, out->val.t);
|
||||||
pop_text_stack(l);
|
pop_text_stack(l);
|
||||||
return Yap_unify(ARG2, out.val.t);
|
return rc;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
error:
|
error:
|
||||||
@ -1417,17 +1413,18 @@ restart_aux:
|
|||||||
if (*tailp != TermNil) {
|
if (*tailp != TermNil) {
|
||||||
LOCAL_Error_TYPE = TYPE_ERROR_LIST;
|
LOCAL_Error_TYPE = TYPE_ERROR_LIST;
|
||||||
} else {
|
} 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;
|
int i = 0;
|
||||||
Atom at;
|
Atom at;
|
||||||
|
|
||||||
if (n == 1) {
|
if (n == 1) {
|
||||||
|
bool rc = Yap_unify(ARG2, HeadOfTerm(t1));
|
||||||
pop_text_stack(l);
|
pop_text_stack(l);
|
||||||
return Yap_unify(ARG2, HeadOfTerm(t1));
|
return rc;
|
||||||
}
|
}
|
||||||
if (!inpv) {
|
if (!inpv) {
|
||||||
LOCAL_Error_TYPE = RESOURCE_ERROR_HEAP;
|
LOCAL_Error_TYPE = RESOURCE_ERROR_HEAP;
|
||||||
free(inpv);
|
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1439,16 +1436,15 @@ restart_aux:
|
|||||||
i++;
|
i++;
|
||||||
t1 = TailOfTerm(t1);
|
t1 = TailOfTerm(t1);
|
||||||
}
|
}
|
||||||
out.type = YAP_STRING_ATOM;
|
out->type = YAP_STRING_ATOM;
|
||||||
if (!Yap_Concat_Text(n, inpv, &out PASS_REGS)) {
|
if (!Yap_Concat_Text(n, inpv, out PASS_REGS)) {
|
||||||
free(inpv);
|
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
free(inpv);
|
pop_text_stack(l);
|
||||||
at = out.val.a;
|
at = out->val.a;
|
||||||
if (at) {
|
if (at) {
|
||||||
pop_text_stack(l);
|
bool rc = Yap_unify(ARG2, MkAtomTerm(at));
|
||||||
return Yap_unify(ARG2, MkAtomTerm(at));
|
return rc;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
error:
|
error:
|
||||||
@ -1457,7 +1453,6 @@ error:
|
|||||||
goto restart_aux;
|
goto restart_aux;
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
pop_text_stack(l);
|
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1473,13 +1468,12 @@ restart_aux:
|
|||||||
if (*tailp != TermNil) {
|
if (*tailp != TermNil) {
|
||||||
LOCAL_Error_TYPE = TYPE_ERROR_LIST;
|
LOCAL_Error_TYPE = TYPE_ERROR_LIST;
|
||||||
} else {
|
} 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;
|
int i = 0;
|
||||||
Atom at;
|
Atom at;
|
||||||
|
|
||||||
if (!inpv) {
|
if (!inpv) {
|
||||||
LOCAL_Error_TYPE = RESOURCE_ERROR_HEAP;
|
LOCAL_Error_TYPE = RESOURCE_ERROR_HEAP;
|
||||||
free(inpv);
|
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1492,10 +1486,8 @@ restart_aux:
|
|||||||
}
|
}
|
||||||
out.type = YAP_STRING_STRING;
|
out.type = YAP_STRING_STRING;
|
||||||
if (!Yap_Concat_Text(n, inpv, &out PASS_REGS)) {
|
if (!Yap_Concat_Text(n, inpv, &out PASS_REGS)) {
|
||||||
free(inpv);
|
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
free(inpv);
|
|
||||||
at = out.val.a;
|
at = out.val.a;
|
||||||
if (at) {
|
if (at) {
|
||||||
pop_text_stack(l);
|
pop_text_stack(l);
|
||||||
@ -1525,13 +1517,12 @@ restart_aux:
|
|||||||
if (*tailp != TermNil) {
|
if (*tailp != TermNil) {
|
||||||
LOCAL_Error_TYPE = TYPE_ERROR_LIST;
|
LOCAL_Error_TYPE = TYPE_ERROR_LIST;
|
||||||
} else {
|
} 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;
|
int i = 0;
|
||||||
Atom at;
|
Atom at;
|
||||||
|
|
||||||
if (!inpv) {
|
if (!inpv) {
|
||||||
LOCAL_Error_TYPE = RESOURCE_ERROR_HEAP;
|
LOCAL_Error_TYPE = RESOURCE_ERROR_HEAP;
|
||||||
free(inpv);
|
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1548,10 +1539,8 @@ restart_aux:
|
|||||||
}
|
}
|
||||||
out.type = YAP_STRING_STRING;
|
out.type = YAP_STRING_STRING;
|
||||||
if (!Yap_Concat_Text(2 * n - 1, inpv, &out PASS_REGS)) {
|
if (!Yap_Concat_Text(2 * n - 1, inpv, &out PASS_REGS)) {
|
||||||
free(inpv);
|
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
free(inpv);
|
|
||||||
at = out.val.a;
|
at = out.val.a;
|
||||||
if (at) {
|
if (at) {
|
||||||
pop_text_stack(l);
|
pop_text_stack(l);
|
||||||
@ -2301,8 +2290,8 @@ static Int cont_sub_atomic(USES_REGS1) {
|
|||||||
}
|
}
|
||||||
} else if (mask & SUB_ATOM_HAS_SIZE) {
|
} else if (mask & SUB_ATOM_HAS_SIZE) {
|
||||||
Term nat = build_new_atomic(mask, p, minv, len PASS_REGS);
|
Term nat = build_new_atomic(mask, p, minv, len PASS_REGS);
|
||||||
if (nat == 0)
|
if (nat == 0)
|
||||||
Yap_ThrowExistingError();
|
Yap_ThrowExistingError();
|
||||||
Yap_unify(ARG2, MkIntegerTerm(minv));
|
Yap_unify(ARG2, MkIntegerTerm(minv));
|
||||||
Yap_unify(ARG4, MkIntegerTerm(after));
|
Yap_unify(ARG4, MkIntegerTerm(after));
|
||||||
Yap_unify(ARG5, nat);
|
Yap_unify(ARG5, nat);
|
||||||
@ -2313,8 +2302,8 @@ static Int cont_sub_atomic(USES_REGS1) {
|
|||||||
} else if (mask & SUB_ATOM_HAS_MIN) {
|
} else if (mask & SUB_ATOM_HAS_MIN) {
|
||||||
after = sz - (minv + len);
|
after = sz - (minv + len);
|
||||||
Term nat = build_new_atomic(mask, p, minv, len PASS_REGS);
|
Term nat = build_new_atomic(mask, p, minv, len PASS_REGS);
|
||||||
if (nat == 0)
|
if (nat == 0)
|
||||||
Yap_ThrowExistingError();
|
Yap_ThrowExistingError();
|
||||||
Yap_unify(ARG3, MkIntegerTerm(len));
|
Yap_unify(ARG3, MkIntegerTerm(len));
|
||||||
Yap_unify(ARG4, MkIntegerTerm(after));
|
Yap_unify(ARG4, MkIntegerTerm(after));
|
||||||
Yap_unify(ARG5, nat);
|
Yap_unify(ARG5, nat);
|
||||||
@ -2325,8 +2314,8 @@ static Int cont_sub_atomic(USES_REGS1) {
|
|||||||
} else if (mask & SUB_ATOM_HAS_AFTER) {
|
} else if (mask & SUB_ATOM_HAS_AFTER) {
|
||||||
len = sz - (minv + after);
|
len = sz - (minv + after);
|
||||||
Term nat = build_new_atomic(mask, p, minv, len PASS_REGS);
|
Term nat = build_new_atomic(mask, p, minv, len PASS_REGS);
|
||||||
if (nat == 0)
|
if (nat == 0)
|
||||||
Yap_ThrowExistingError();
|
Yap_ThrowExistingError();
|
||||||
Yap_unify(ARG2, MkIntegerTerm(minv));
|
Yap_unify(ARG2, MkIntegerTerm(minv));
|
||||||
Yap_unify(ARG3, MkIntegerTerm(len));
|
Yap_unify(ARG3, MkIntegerTerm(len));
|
||||||
Yap_unify(ARG5, nat);
|
Yap_unify(ARG5, nat);
|
||||||
@ -2336,8 +2325,8 @@ static Int cont_sub_atomic(USES_REGS1) {
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
Term nat = build_new_atomic(mask, p, minv, len PASS_REGS);
|
Term nat = build_new_atomic(mask, p, minv, len PASS_REGS);
|
||||||
if (nat == 0)
|
if (nat == 0)
|
||||||
Yap_ThrowExistingError();
|
Yap_ThrowExistingError();
|
||||||
Yap_unify(ARG2, MkIntegerTerm(minv));
|
Yap_unify(ARG2, MkIntegerTerm(minv));
|
||||||
Yap_unify(ARG3, MkIntegerTerm(len));
|
Yap_unify(ARG3, MkIntegerTerm(len));
|
||||||
Yap_unify(ARG4, MkIntegerTerm(after));
|
Yap_unify(ARG4, MkIntegerTerm(after));
|
||||||
@ -2483,25 +2472,24 @@ static Int sub_atomic(bool sub_atom, bool sub_string USES_REGS) {
|
|||||||
(SUB_ATOM_HAS_MIN | SUB_ATOM_HAS_VAL | SUB_ATOM_HAS_AFTER)) {
|
(SUB_ATOM_HAS_MIN | SUB_ATOM_HAS_VAL | SUB_ATOM_HAS_AFTER)) {
|
||||||
const unsigned char *sm;
|
const unsigned char *sm;
|
||||||
if (sub_atom)
|
if (sub_atom)
|
||||||
sm = RepAtom(AtomOfTerm(tout))->UStrOfAE;
|
sm = RepAtom(AtomOfTerm(tout))->UStrOfAE;
|
||||||
else
|
else
|
||||||
sm = UStringOfTerm(tout);
|
sm = UStringOfTerm(tout);
|
||||||
if (mask & SUB_ATOM_HAS_SIZE) {
|
if (mask & SUB_ATOM_HAS_SIZE) {
|
||||||
if (len != strlen_utf8(sm) ) {
|
if (len != strlen_utf8(sm)) {
|
||||||
cut_fail();
|
cut_fail();
|
||||||
} else {
|
} else {
|
||||||
len = strlen_utf8(sm);
|
len = strlen_utf8(sm);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (sz != minv+len+after) {
|
if (sz != minv + len + after) {
|
||||||
cut_fail();
|
cut_fail();
|
||||||
}
|
}
|
||||||
return do_cut(check_sub_string_at(
|
return do_cut(check_sub_string_at(minv, p, sm, len));
|
||||||
minv, p, sm, len));
|
|
||||||
} else if ((mask & (SUB_ATOM_HAS_MIN | SUB_ATOM_HAS_VAL)) ==
|
} else if ((mask & (SUB_ATOM_HAS_MIN | SUB_ATOM_HAS_VAL)) ==
|
||||||
(SUB_ATOM_HAS_MIN | SUB_ATOM_HAS_VAL)) {
|
(SUB_ATOM_HAS_MIN | SUB_ATOM_HAS_VAL)) {
|
||||||
if (! Yap_unify(ARG4,MkIntegerTerm(sz-minv-len)) )
|
if (!Yap_unify(ARG4, MkIntegerTerm(sz - minv - len)))
|
||||||
cut_fail();
|
cut_fail();
|
||||||
if (sub_atom)
|
if (sub_atom)
|
||||||
return do_cut(check_sub_string_at(
|
return do_cut(check_sub_string_at(
|
||||||
minv, p, RepAtom(AtomOfTerm(tout))->UStrOfAE, len));
|
minv, p, RepAtom(AtomOfTerm(tout))->UStrOfAE, len));
|
||||||
@ -2509,13 +2497,14 @@ static Int sub_atomic(bool sub_atom, bool sub_string USES_REGS) {
|
|||||||
return do_cut(check_sub_string_at(minv, p, UStringOfTerm(tout), len));
|
return do_cut(check_sub_string_at(minv, p, UStringOfTerm(tout), len));
|
||||||
} else if ((mask & (SUB_ATOM_HAS_AFTER | SUB_ATOM_HAS_VAL)) ==
|
} else if ((mask & (SUB_ATOM_HAS_AFTER | SUB_ATOM_HAS_VAL)) ==
|
||||||
(SUB_ATOM_HAS_AFTER | SUB_ATOM_HAS_VAL)) {
|
(SUB_ATOM_HAS_AFTER | SUB_ATOM_HAS_VAL)) {
|
||||||
if (! Yap_unify(ARG2,MkIntegerTerm(sz-after-len)) )
|
if (!Yap_unify(ARG2, MkIntegerTerm(sz - after - len)))
|
||||||
cut_fail();
|
cut_fail();
|
||||||
if (sub_atom) {
|
if (sub_atom) {
|
||||||
return do_cut(check_sub_string_bef(
|
return do_cut(check_sub_string_bef(
|
||||||
sz - after, p, RepAtom(AtomOfTerm(tout))->UStrOfAE));
|
sz - after, p, RepAtom(AtomOfTerm(tout))->UStrOfAE));
|
||||||
} else {
|
} 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)) ==
|
} else if ((mask & (SUB_ATOM_HAS_MIN | SUB_ATOM_HAS_SIZE)) ==
|
||||||
(SUB_ATOM_HAS_MIN | SUB_ATOM_HAS_SIZE)) {
|
(SUB_ATOM_HAS_MIN | SUB_ATOM_HAS_SIZE)) {
|
||||||
if (minv + len + after > sz) {
|
if (minv + len + after > sz) {
|
||||||
|
119
C/text.c
119
C/text.c
@ -32,7 +32,9 @@ inline static size_t min_size(size_t i, size_t j) { return (i < j ? i : j); }
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if !defined(HAVE_STPCPY) && !defined(__APPLE__)
|
#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
|
#define stpcpy __stpcpy
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@ -89,7 +91,7 @@ void *pop_output_text_stack__(int i, const void *export) {
|
|||||||
while (p) {
|
while (p) {
|
||||||
struct mblock *np = p->next;
|
struct mblock *np = p->next;
|
||||||
if (p + 1 == export) {
|
if (p + 1 == export) {
|
||||||
size_t sz = p->sz-sizeof(struct mblock) ;
|
size_t sz = p->sz - sizeof(struct mblock);
|
||||||
memcpy(p, p + 1, sz);
|
memcpy(p, p + 1, sz);
|
||||||
export = p;
|
export = p;
|
||||||
} else {
|
} else {
|
||||||
@ -185,19 +187,19 @@ void *Realloc(void *pt, size_t sz USES_REGS) {
|
|||||||
return o + 1;
|
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
|
* @param pt pointer to object
|
||||||
* @return new object
|
* @return new object
|
||||||
*/
|
*/
|
||||||
const void *MallocExportAsRO(const void *pt USES_REGS) {
|
const void *MallocExportAsRO(const void *pt USES_REGS) {
|
||||||
struct mblock *old = (void *)pt, *o = old-1;
|
struct mblock *old = (void *)pt, *o = old - 1;
|
||||||
if (old == NULL)
|
if (old == NULL)
|
||||||
return NULL;
|
return NULL;
|
||||||
size_t sz = o->sz;
|
size_t sz = o->sz;
|
||||||
release_block(o);
|
release_block(o);
|
||||||
memcpy((void*)o, pt,sz);
|
memcpy((void *)o, pt, sz);
|
||||||
return realloc((void *)o, sz);
|
return realloc((void *)o, sz);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -258,8 +260,7 @@ static void *codes2buf(Term t0, void *b0, bool *get_codes USES_REGS) {
|
|||||||
}
|
}
|
||||||
Int code = IntegerOfTerm(hd);
|
Int code = IntegerOfTerm(hd);
|
||||||
if (code < 0) {
|
if (code < 0) {
|
||||||
Yap_ThrowError(TYPE_ERROR_CHARACTER_CODE, hd,
|
Yap_ThrowError(TYPE_ERROR_CHARACTER_CODE, hd, "scanning list of codes");
|
||||||
"scanning list of codes");
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
length += put_utf8(ar, code);
|
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;
|
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;
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
if (IsAtomTerm(inp->val.t) && inp->type & YAP_STRING_ATOM) {
|
if (IsAtomTerm(inp->val.t) && inp->type & YAP_STRING_ATOM) {
|
||||||
// this is a term, extract to a buffer, and representation is wide
|
// 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);
|
memset(o, 0, 4);
|
||||||
return pop_output_text_stack(lvl, o);
|
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;
|
return at->UStrOfAE;
|
||||||
|
}
|
||||||
size_t sz = strlen(at->StrOfAE);
|
size_t sz = strlen(at->StrOfAE);
|
||||||
inp->type |= YAP_STRING_IN_TMP;
|
inp->type |= YAP_STRING_IN_TMP;
|
||||||
void *o = Malloc(sz + 1);
|
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);
|
return (unsigned char *)UStringOfTerm(inp->val.t);
|
||||||
inp->type |= YAP_STRING_IN_TMP;
|
inp->type |= YAP_STRING_IN_TMP;
|
||||||
size_t sz = strlen(s);
|
size_t sz = strlen(s);
|
||||||
char *o = BaseMalloc(sz + 1);
|
char *o = Malloc(sz + 1);
|
||||||
strcpy(o, s);
|
strcpy(o, s);
|
||||||
return pop_output_text_stack(lvl, o);
|
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)) &&
|
(YAP_STRING_CODES | YAP_STRING_ATOMS)) &&
|
||||||
IsPairOrNilTerm(inp->val.t)) {
|
IsPairOrNilTerm(inp->val.t)) {
|
||||||
// Yap_DebugPlWriteln(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
|
// this is a term, extract to a sfer, and representation is wide
|
||||||
}
|
}
|
||||||
if (inp->type & YAP_STRING_CODES && IsPairOrNilTerm(inp->val.t)) {
|
if (inp->type & YAP_STRING_CODES && IsPairOrNilTerm(inp->val.t)) {
|
||||||
// Yap_DebugPlWriteln(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
|
// this is a term, extract to a sfer, and representation is wide
|
||||||
}
|
}
|
||||||
if (inp->type & YAP_STRING_ATOMS && IsPairOrNilTerm(inp->val.t)) {
|
if (inp->type & YAP_STRING_ATOMS && IsPairOrNilTerm(inp->val.t)) {
|
||||||
// Yap_DebugPlWriteln(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
|
// this is a term, extract to a buffer, and representation is wide
|
||||||
}
|
}
|
||||||
if (inp->type & YAP_STRING_INT && IsIntegerTerm(inp->val.t)) {
|
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;
|
char *s;
|
||||||
// Yap_DebugPlWriteln(inp->val.t);
|
// Yap_DebugPlWriteln(inp->val.t);
|
||||||
if (!Yap_FormatFloat(FloatOfTerm(inp->val.t), &s, 1024)) {
|
if (!Yap_FormatFloat(FloatOfTerm(inp->val.t), &s, 1024)) {
|
||||||
|
pop_text_stack(lvl);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
return pop_output_text_stack(lvl, s);
|
return pop_output_text_stack(lvl, s);
|
||||||
@ -525,7 +534,7 @@ unsigned char *Yap_readText(seq_tv_t *inp USES_REGS) {
|
|||||||
#endif
|
#endif
|
||||||
if (inp->type & YAP_STRING_TERM) {
|
if (inp->type & YAP_STRING_TERM) {
|
||||||
// Yap_DebugPlWriteln(inp->val.t);
|
// Yap_DebugPlWriteln(inp->val.t);
|
||||||
char *s = (char *) Yap_TermToBuffer(inp->val.t, ENC_ISO_UTF8, 0);
|
char *s = (char *)Yap_TermToBuffer(inp->val.t, ENC_ISO_UTF8, 0);
|
||||||
return inp->val.uc = pop_output_text_stack(lvl, s);
|
return inp->val.uc = pop_output_text_stack(lvl, s);
|
||||||
}
|
}
|
||||||
if (inp->type & YAP_STRING_CHARS) {
|
if (inp->type & YAP_STRING_CHARS) {
|
||||||
@ -562,7 +571,7 @@ static Term write_strings(unsigned char *s0, seq_tv_t *out USES_REGS) {
|
|||||||
Term t = init_tstring(PASS_REGS1);
|
Term t = init_tstring(PASS_REGS1);
|
||||||
LOCAL_TERM_ERROR(t, 2 * max);
|
LOCAL_TERM_ERROR(t, 2 * max);
|
||||||
unsigned char *buf = buf_from_tstring(HR);
|
unsigned char *buf = buf_from_tstring(HR);
|
||||||
if (max==0)
|
if (max == 0)
|
||||||
buf[0] = '\0';
|
buf[0] = '\0';
|
||||||
else
|
else
|
||||||
strcpy((char *)buf, s);
|
strcpy((char *)buf, s);
|
||||||
@ -689,7 +698,7 @@ void *write_buffer(unsigned char *s0, seq_tv_t *out USES_REGS) {
|
|||||||
size_t leng = strlen((char *)s0);
|
size_t leng = strlen((char *)s0);
|
||||||
size_t min = 0, max = leng;
|
size_t min = 0, max = leng;
|
||||||
if (out->enc == ENC_ISO_UTF8) {
|
if (out->enc == ENC_ISO_UTF8) {
|
||||||
if ( out->val.uc == NULL) { // this should always be the case
|
if (out->val.uc == NULL) { // this should always be the case
|
||||||
out->val.uc = BaseMalloc(leng + 1);
|
out->val.uc = BaseMalloc(leng + 1);
|
||||||
strcpy(out->val.c, (char *)s0);
|
strcpy(out->val.c, (char *)s0);
|
||||||
} else if (out->val.uc != s0) {
|
} else if (out->val.uc != s0) {
|
||||||
@ -760,19 +769,19 @@ static Term write_number(unsigned char *s, seq_tv_t *out,
|
|||||||
bool error_on USES_REGS) {
|
bool error_on USES_REGS) {
|
||||||
Term t;
|
Term t;
|
||||||
LOCAL_delay = !error_on;
|
LOCAL_delay = !error_on;
|
||||||
t = Yap_StringToNumberTerm((char *)s, &out->enc,error_on);
|
t = Yap_StringToNumberTerm((char *)s, &out->enc, error_on);
|
||||||
LOCAL_delay = false;
|
LOCAL_delay = false;
|
||||||
return t;
|
return t;
|
||||||
}
|
}
|
||||||
|
|
||||||
static Term string_to_term(void *s, seq_tv_t *out USES_REGS) {
|
static Term string_to_term(void *s, seq_tv_t *out USES_REGS) {
|
||||||
Term o;
|
Term o;
|
||||||
yap_error_descriptor_t new_error;
|
yap_error_descriptor_t new_error;
|
||||||
bool mdnew = Yap_pushErrorContext(true, &new_error);
|
bool mdnew = Yap_pushErrorContext(true, &new_error);
|
||||||
o = out->val.t = Yap_BufferToTerm(s, TermNil);
|
o = out->val.t = Yap_BufferToTerm(s, TermNil);
|
||||||
Yap_popErrorContext(mdnew, true);
|
Yap_popErrorContext(mdnew, true);
|
||||||
|
|
||||||
return o;
|
return o;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool write_Text(unsigned char *inp, seq_tv_t *out USES_REGS) {
|
bool write_Text(unsigned char *inp, seq_tv_t *out USES_REGS) {
|
||||||
@ -896,34 +905,34 @@ bool Yap_CVT_Text(seq_tv_t *inp, seq_tv_t *out USES_REGS) {
|
|||||||
return 0L;
|
return 0L;
|
||||||
}
|
}
|
||||||
if (buf[0]) {
|
if (buf[0]) {
|
||||||
size_t leng = strlen_utf8(buf);
|
size_t leng = strlen_utf8(buf);
|
||||||
if (out->type & (YAP_STRING_NCHARS | YAP_STRING_TRUNC)) {
|
if (out->type & (YAP_STRING_NCHARS | YAP_STRING_TRUNC)) {
|
||||||
if (out->max < leng) {
|
if (out->max < leng) {
|
||||||
const unsigned char *ptr = skip_utf8(buf, out->max);
|
const unsigned char *ptr = skip_utf8(buf, out->max);
|
||||||
size_t diff = (ptr - buf);
|
size_t diff = (ptr - buf);
|
||||||
char *nbuf = Malloc(diff + 1);
|
char *nbuf = Malloc(diff + 1);
|
||||||
memcpy(nbuf, buf, diff);
|
memcpy(nbuf, buf, diff);
|
||||||
nbuf[diff] = '\0';
|
nbuf[diff] = '\0';
|
||||||
leng = diff;
|
leng = diff;
|
||||||
|
}
|
||||||
|
// else if (out->type & YAP_STRING_NCHARS &&
|
||||||
|
// const unsigned char *ptr = skip_utf8(buf)
|
||||||
}
|
}
|
||||||
// else if (out->type & YAP_STRING_NCHARS &&
|
|
||||||
// const unsigned char *ptr = skip_utf8(buf)
|
|
||||||
}
|
|
||||||
|
|
||||||
if (out->type & (YAP_STRING_UPCASE | YAP_STRING_DOWNCASE)) {
|
if (out->type & (YAP_STRING_UPCASE | YAP_STRING_DOWNCASE)) {
|
||||||
if (out->type & YAP_STRING_UPCASE) {
|
if (out->type & YAP_STRING_UPCASE) {
|
||||||
if (!upcase(buf, out)) {
|
if (!upcase(buf, out)) {
|
||||||
pop_text_stack(l);
|
pop_text_stack(l);
|
||||||
return false;
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (out->type & YAP_STRING_DOWNCASE) {
|
||||||
|
if (!downcase(buf, out)) {
|
||||||
|
pop_text_stack(l);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (out->type & YAP_STRING_DOWNCASE) {
|
|
||||||
if (!downcase(buf, out)) {
|
|
||||||
pop_text_stack(l);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
rc = write_Text(buf, out PASS_REGS);
|
rc = write_Text(buf, out PASS_REGS);
|
||||||
/* fprintf(stderr, " -> ");
|
/* fprintf(stderr, " -> ");
|
||||||
@ -989,9 +998,10 @@ bool Yap_Concat_Text(int tot, seq_tv_t inp[], seq_tv_t *out USES_REGS) {
|
|||||||
void **bufv;
|
void **bufv;
|
||||||
unsigned char *buf;
|
unsigned char *buf;
|
||||||
int i, j;
|
int i, j;
|
||||||
|
//int lvl = push_text_stack();
|
||||||
bufv = Malloc(tot * sizeof(unsigned char *));
|
bufv = Malloc(tot * sizeof(unsigned char *));
|
||||||
if (!bufv) {
|
if (!bufv) {
|
||||||
|
//pop_text_stack(lvl);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
for (i = 0, j = 0; i < tot; i++) {
|
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);
|
unsigned char *nbuf = Yap_readText(inp + i PASS_REGS);
|
||||||
|
|
||||||
if (!nbuf) {
|
if (!nbuf) {
|
||||||
|
//pop_text_stack(lvl);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
// if (!nbuf[0])
|
// 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);
|
buf = concat(tot, bufv PASS_REGS);
|
||||||
}
|
}
|
||||||
bool rc = write_Text(buf, out PASS_REGS);
|
bool rc = write_Text(buf, out PASS_REGS);
|
||||||
|
//pop_text_stack( lvl );
|
||||||
|
|
||||||
return rc;
|
return rc;
|
||||||
}
|
}
|
||||||
@ -1080,8 +1092,8 @@ bool Yap_Splice_Text(int n, size_t cuts[], seq_tv_t *inp,
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
buf0 = slice(0, u_l0, buf PASS_REGS);
|
buf0 = slice(0, u_l0, buf PASS_REGS);
|
||||||
|
buf0 = pop_output_text_stack(lvl, buf0);
|
||||||
bool rc = write_Text(buf0, outv PASS_REGS);
|
bool rc = write_Text(buf0, outv PASS_REGS);
|
||||||
pop_text_stack(lvl);
|
|
||||||
return rc;
|
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)
|
if (i > 0 && cuts[i] == 0)
|
||||||
break;
|
break;
|
||||||
void *bufi = slice(next, cuts[i], buf PASS_REGS);
|
void *bufi = slice(next, cuts[i], buf PASS_REGS);
|
||||||
|
bufi = pop_output_text_stack(lvl, bufi);
|
||||||
if (!write_Text(bufi, outv + i PASS_REGS)) {
|
if (!write_Text(bufi, outv + i PASS_REGS)) {
|
||||||
pop_text_stack(lvl);
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1105,7 +1117,6 @@ bool Yap_Splice_Text(int n, size_t cuts[], seq_tv_t *inp,
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Convert from a predicate structure to an UTF-8 string of the form
|
* Convert from a predicate structure to an UTF-8 string of the form
|
||||||
*
|
*
|
||||||
|
Reference in New Issue
Block a user