memory mgmt

This commit is contained in:
Vitor Santos Costa 2017-09-23 02:17:55 +01:00
parent 70f4f7adcf
commit a40fbe420f
24 changed files with 4238 additions and 4265 deletions

3
.gitignore vendored
View File

@ -12,6 +12,7 @@
*.dll
docs/yap.info*
.build
build
tags
TGSautom4te.cache
cscope.*
@ -24,7 +25,6 @@ tmtags*
.Rhistory
.zedstate
config.h
Yap.h
YapConfig.h
YapTermConfig.h
.graffiti
@ -42,7 +42,6 @@ groups
.cproject
.dir-locals.el
.DS_store
.kateproject
.project
.pydevproject
.Rhistory

View File

@ -268,12 +268,11 @@ static Int char_code(USES_REGS1) {
Atom at = AtomOfTerm(t0);
Term tf;
unsigned char *c = RepAtom(at)->UStrOfAE;
int32_t v;
c += get_utf8(c, 1, &v);
if (c[0] != '\0') {
Yap_Error(TYPE_ERROR_CHARACTER, t0, "char_code/2");
return FALSE;
}
int32_t v = IntegerOfTerm(ARG1);
get_utf8(c, -1, &v);
if (!v)
return false;
tf = MkIntTerm(v);
return Yap_unify(ARG2, tf);
}

View File

@ -2239,10 +2239,9 @@ X_API int YAP_WriteDynamicBuffer(YAP_Term t, char *buf, size_t sze,
char *b;
BACKUP_MACHINE_REGS();
b = Yap_TermToString(t, lengthp, enc, flags);
if (*lengthp >= sze)
*lengthp = sze;
b = Yap_TermToString(t, enc, flags);
strncpy(buf, b, sze);
buf[sze] = 0;
RECOVER_MACHINE_REGS();
return true;
}

View File

@ -53,6 +53,7 @@ static ModEntry *initMod(AtomEntry *toname, AtomEntry *ae) {
n->NextME = CurrentModules;
CurrentModules = n;
n->AtomOfME = ae;
n->NextOfPE =NULL;
n->OwnerFile = Yap_ConsultingFile(PASS_REGS1);
AddPropToAtom(ae, (PropEntry *)n);
Yap_setModuleFlags(n, parent);
@ -385,24 +386,19 @@ static Int strip_module(USES_REGS1) {
}
static Int yap_strip_clause(USES_REGS1) {
Functor f;
Term t1 = Deref(ARG1), tmod = LOCAL_SourceModule;
if (tmod == PROLOG_MODULE) {
tmod = TermProlog;
}
t1 = Yap_StripModule(t1, &tmod);
if (IsVarTerm(t1)) {
if (IsVarTerm(t1) || IsVarTerm(tmod)) {
Yap_Error(INSTANTIATION_ERROR, t1, "trying to obtain module");
return false;
} else if (IsVarTerm(tmod)) {
Yap_Error(INSTANTIATION_ERROR, tmod, "trying to obtain module");
return false;
} else if (IsIntTerm(t1) || (IsApplTerm(t1) && IsExtensionFunctor((f = FunctorOfTerm(t1))))) {
} else if (IsApplTerm(t1)) {
Functor f = FunctorOfTerm(t1);
if (IsExtensionFunctor(f)) {
Yap_Error(TYPE_ERROR_CALLABLE, t1, "trying to obtain module");
return false;
} else if (!IsAtomTerm(tmod)) {
Yap_Error(TYPE_ERROR_ATOM, tmod, "trying to obtain module");
return false;
}
if (f == FunctorAssert || f == FunctorDoubleArrow) {
Term thmod = tmod;
@ -422,6 +418,11 @@ static Int yap_strip_clause(USES_REGS1) {
return false;
}
}
} else if (IsIntTerm(t1) || IsIntTerm(tmod) ) {
Yap_Error(TYPE_ERROR_CALLABLE, t1, "trying to obtain module");
return false;
}
return Yap_unify(ARG3, t1) && Yap_unify(ARG2, tmod);
}

View File

@ -404,10 +404,10 @@ writing, writing a BOM can be requested using the option
*/
#include "Yap.h"
#include "YapEval.h"
#include "YapHeap.h"
#include "Yatom.h"
#include "alloc.h"
#include "YapEval.h"
#include "yapio.h"
/* stuff we want to use in standard YAP code */
#include "YapText.h"
@ -1104,7 +1104,7 @@ Term Yap_scan_num(StreamDesc *inp, bool error_on) {
CACHE_REGS
Term out;
int sign = 1;
int ch, cherr;
int ch, cherr = 0;
char *ptr;
void *old_tr = TR;
@ -1604,7 +1604,6 @@ TokEntry *Yap_tokenizer(struct stream_desc *inp_stream, bool store_comments,
if (!(t->TokInfo)) {
return CodeSpaceError(t, p, l);
}
Free(TokImage);
t->Tok = Ord(kind = String_tok);
} else if (quote == '`') {
t->TokInfo = Yap_CharsToTBQ((char *)TokImage, CurrentModule,
@ -1612,7 +1611,6 @@ TokEntry *Yap_tokenizer(struct stream_desc *inp_stream, bool store_comments,
if (!(t->TokInfo)) {
return CodeSpaceError(t, p, l);
}
Free(TokImage);
t->Tok = Ord(kind = String_tok);
} else {
t->TokInfo = MkAtomTerm(Yap_ULookupAtom(TokImage));

View File

@ -948,9 +948,10 @@ static Int current_predicate(USES_REGS1) {
static OpEntry *NextOp(Prop pp USES_REGS) {
while (!EndOfPAEntr(pp) && pp->KindOfPE != OpProperty &&
(RepOpProp(pp)->OpModule != PROLOG_MODULE
|| RepOpProp(pp)->OpModule != CurrentModule) )
while (!EndOfPAEntr(pp) &&
pp->KindOfPE != OpProperty &&
(RepOpProp(pp)->OpModule != PROLOG_MODULE || RepOpProp(pp)->OpModule != CurrentModule)
)
pp = pp->NextOfPE;
return RepOpProp(pp);
}

350
C/text.c
View File

@ -51,10 +51,7 @@ typedef struct TextBuffer_manager {
int lvl;
} text_buffer_t;
int push_text_stack(USES_REGS1) {
return LOCAL_TextBuffer->lvl++;
}
int push_text_stack(USES_REGS1) { return LOCAL_TextBuffer->lvl++; }
int pop_text_stack(int i) {
int lvl = LOCAL_TextBuffer->lvl;
@ -73,43 +70,9 @@ int pop_text_stack(int i) {
return lvl;
}
void *protected_pop_text_stack(int i, void *protected, bool tmp,
size_t sz USES_REGS) {
void *out = protected;
int lvl = LOCAL_TextBuffer->lvl;
while (lvl > i) {
struct mblock *p = LOCAL_TextBuffer->first[lvl];
while (p) {
struct mblock *np = p->next;
if (p + 1 == protected) {
if (tmp)
out = LOCAL_FileNameBuf;
else
out = p;
memcpy(out, protected, sz);
} else {
free(p);
}
p = np;
}
LOCAL_TextBuffer->first[lvl] = NULL;
LOCAL_TextBuffer->last[lvl] = NULL;
lvl--;
}
LOCAL_TextBuffer->lvl = lvl;
return out;
}
// void pop_text_stack(int i) { LOCAL_TextBuffer->lvl = i; }
void *Malloc(size_t sz USES_REGS) {
int lvl = LOCAL_TextBuffer->lvl;
if (sz == 0)
sz = 1024;
sz = ALIGN_BY_TYPE(sz + sizeof(struct mblock), CELL);
struct mblock *o = malloc(sz);
if (!o)
return NULL;
void insert_block(struct mblock *o) {
int lvl = o->lvl;
o->prev = LOCAL_TextBuffer->last[lvl];
if (o->prev) {
o->prev->next = o;
@ -120,8 +83,36 @@ void *Malloc(size_t sz USES_REGS) {
LOCAL_TextBuffer->first[lvl] = LOCAL_TextBuffer->last[lvl] = o;
}
o->next = NULL;
}
void release_block(struct mblock *o) {
if (o->prev)
o->prev->next = o->next;
if (o->next)
o->next->prev = o->prev;
int lvl = o->lvl;
if (LOCAL_TextBuffer->first[lvl] == o) {
if (LOCAL_TextBuffer->last[lvl] == o) {
LOCAL_TextBuffer->first[lvl] = LOCAL_TextBuffer->last[lvl] = NULL;
}
LOCAL_TextBuffer->first[lvl] = o->next;
} else if (LOCAL_TextBuffer->last[lvl] == o) {
LOCAL_TextBuffer->last[lvl] = o->prev;
}
}
void *Malloc(size_t sz USES_REGS) {
int lvl = LOCAL_TextBuffer->lvl;
if (sz == 0)
sz = 1024;
sz = ALIGN_BY_TYPE(sz + sizeof(struct mblock), CELL);
struct mblock *o = malloc(sz);
if (!o)
return NULL;
o->sz = sz;
o->lvl = lvl;
o->prev = o->next = 0;
insert_block(o);
return o + 1;
}
@ -141,26 +132,28 @@ void *Realloc(void *pt, size_t sz USES_REGS) {
if (LOCAL_TextBuffer->last[lvl] == old) {
LOCAL_TextBuffer->last[lvl] = o;
}
o->sz = sz;
return o + 1;
}
void *export_block(int i, void *protected USES_REGS) {
struct mblock *o = ((struct mblock *)protected) - 1;
release_block(o);
if (i >= 0) {
o->lvl = i;
insert_block(o);
return protected;
} else {
memcpy(o, protected, o->sz);
return o;
}
}
void Free(void *pt USES_REGS) {
struct mblock *o = pt;
o--;
if (o->prev)
o->prev->next = o->next;
if (o->next)
o->next->prev = o->prev;
int lvl = o->lvl;
if (LOCAL_TextBuffer->first[lvl] == o) {
if (LOCAL_TextBuffer->last[lvl] == o) {
LOCAL_TextBuffer->first[lvl] = LOCAL_TextBuffer->last[lvl] = NULL;
}
LOCAL_TextBuffer->first[lvl] = o->next;
} else if (LOCAL_TextBuffer->last[lvl] == o) {
LOCAL_TextBuffer->last[lvl] = o->prev;
}
release_block(o);
free(o);
}
@ -262,7 +255,6 @@ static Int SkipListCodes(unsigned char **bufp, Term *l, Term **tailp,
l = RepPair(*l) + 1;
do_derefa(v, l, derefa2_unk, derefa2_nonvar);
}
}
if (IsVarTerm(*l)) {
@ -279,13 +271,12 @@ static Int SkipListCodes(unsigned char **bufp, Term *l, Term **tailp,
return length;
}
static unsigned char *latin2utf8(seq_tv_t *inp, size_t *lengp) {
static unsigned char *latin2utf8(seq_tv_t *inp) {
unsigned char *b0 = inp->val.uc;
size_t sz = *lengp = strlen(inp->val.c);
size_t sz = strlen(inp->val.c);
sz *= 2;
int ch;
unsigned char *buf = Malloc(sz + 1), *pt = buf;
*lengp = strlen(inp->val.c);
if (!buf)
return NULL;
while ((ch = *b0++)) {
@ -298,9 +289,8 @@ static unsigned char *latin2utf8(seq_tv_t *inp, size_t *lengp) {
return buf;
}
static unsigned char *wchar2utf8(seq_tv_t *inp, size_t *lengp) {
*lengp = wcslen(inp->val.w);
size_t sz = *lengp * 4;
static unsigned char *wchar2utf8(seq_tv_t *inp) {
size_t sz = wcslen(inp->val.w) * 4;
wchar_t *b0 = inp->val.w;
unsigned char *buf = Malloc(sz + 1), *pt = buf;
int ch;
@ -315,43 +305,40 @@ static unsigned char *wchar2utf8(seq_tv_t *inp, size_t *lengp) {
static void *slice(size_t min, size_t max, const unsigned char *buf USES_REGS);
static unsigned char *to_buffer(unsigned char *buf, Term t, seq_tv_t *inp,
bool *widep, Int *atoms,
size_t *lenp USES_REGS) {
bool *widep, Int *atoms USES_REGS) {
CELL *r = NULL;
Int n;
if (!buf) {
inp->max = *lenp;
}
unsigned char *bufc = buf;
if (bufc == NULL) {
bufc = malloc(1024);
}
n = SkipListCodes(&bufc, &t, &r, atoms, widep, inp PASS_REGS);
if (n < 0) {
LOCAL_Error_TYPE = -n;
return NULL;
}
*lenp = n;
return bufc;
}
static unsigned char *Yap_ListOfCodesToBuffer(unsigned char *buf, Term t,
seq_tv_t *inp, bool *widep,
size_t *lenp USES_REGS) {
seq_tv_t *inp,
bool *widep USES_REGS) {
Int atoms = 1; // we only want lists of atoms
return to_buffer(buf, t, inp, widep, &atoms, lenp PASS_REGS);
return to_buffer(buf, t, inp, widep, &atoms PASS_REGS);
}
static unsigned char *Yap_ListOfAtomsToBuffer(unsigned char *buf, Term t,
seq_tv_t *inp, bool *widep,
size_t *lenp USES_REGS) {
seq_tv_t *inp,
bool *widep USES_REGS) {
Int atoms = 2; // we only want lists of integer codes
return to_buffer(buf, t, inp, widep, &atoms, lenp PASS_REGS);
return to_buffer(buf, t, inp, widep, &atoms PASS_REGS);
}
static unsigned char *Yap_ListToBuffer(unsigned char *buf, Term t,
seq_tv_t *inp, bool *widep,
size_t *lenp USES_REGS) {
seq_tv_t *inp, bool *widep USES_REGS) {
Int atoms = 0; // we accept both types of lists.
return to_buffer(buf, t, inp, widep, &atoms, lenp PASS_REGS);
return to_buffer(buf, t, inp, widep, &atoms PASS_REGS);
}
#if USE_GEN_TYPE_ERROR
@ -381,7 +368,7 @@ static yap_error_number gen_type_error(int flags) {
// static int cnt;
unsigned char *Yap_readText(seq_tv_t *inp, size_t *lengp) {
unsigned char *Yap_readText(seq_tv_t *inp USES_REGS) {
unsigned char *s0 = NULL;
bool wide;
@ -401,8 +388,8 @@ unsigned char *Yap_readText(seq_tv_t *inp, size_t *lengp) {
} else if (!IsPairOrNilTerm(inp->val.t) && !IsStringTerm(inp->val.t) &&
inp->type == (YAP_STRING_ATOMS_CODES | YAP_STRING_STRING)) {
LOCAL_Error_TYPE = TYPE_ERROR_LIST;
} else if (!IsPairOrNilTerm(inp->val.t) && !IsStringTerm(inp->val.t)
&& !IsAtomTerm(inp->val.t) && !(inp->type & YAP_STRING_DATUM)) {
} else if (!IsPairOrNilTerm(inp->val.t) && !IsStringTerm(inp->val.t) &&
!IsAtomTerm(inp->val.t) && !(inp->type & YAP_STRING_DATUM)) {
LOCAL_Error_TYPE = TYPE_ERROR_TEXT;
}
}
@ -414,27 +401,25 @@ unsigned char *Yap_readText(seq_tv_t *inp, size_t *lengp) {
// this is a term, extract to a buffer, and representation is wide
// Yap_DebugPlWriteln(inp->val.t);
Atom at = AtomOfTerm(inp->val.t);
size_t sz = strlen(at->StrOfAE);
if (lengp)
*lengp = sz;
if (inp->type & YAP_STRING_WITH_BUFFER)
return at->UStrOfAE;
size_t sz = strlen(at->StrOfAE);
inp->type |= YAP_STRING_IN_TMP;
char *o = Malloc(sz + 1);
strcpy(o, at->StrOfAE);
o = export_block(0, o);
return (unsigned char *)o;
}
if (IsStringTerm(inp->val.t) && inp->type & YAP_STRING_STRING) {
// this is a term, extract to a buffer, and representation is wide
// Yap_DebugPlWriteln(inp->val.t);
const char *s = StringOfTerm(inp->val.t);
size_t sz = strlen(s);
if (lengp)
*lengp = sz;
if (inp->type & YAP_STRING_WITH_BUFFER)
return (unsigned char *)UStringOfTerm(inp->val.t);
inp->type |= YAP_STRING_IN_TMP;
size_t sz = strlen(s);
char *o = Malloc(sz + 1);
o = export_block(0, o);
strcpy(o, s);
return (unsigned char *)o;
}
@ -442,30 +427,28 @@ unsigned char *Yap_readText(seq_tv_t *inp, size_t *lengp) {
(YAP_STRING_CODES | YAP_STRING_ATOMS)) &&
IsPairOrNilTerm(inp->val.t)) {
// Yap_DebugPlWriteln(inp->val.t);
return Yap_ListToBuffer(s0, inp->val.t, inp, &wide, lengp PASS_REGS);
return Yap_ListToBuffer(s0, inp->val.t, inp, &wide 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(s0, inp->val.t, inp, &wide, lengp PASS_REGS);
return Yap_ListOfCodesToBuffer(s0, inp->val.t, inp, &wide 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(s0, inp->val.t, inp, &wide, lengp PASS_REGS);
return Yap_ListOfAtomsToBuffer(s0, inp->val.t, inp, &wide PASS_REGS);
// this is a term, extract to a buffer, and representation is wide
}
if (inp->type & YAP_STRING_INT && IsIntegerTerm(inp->val.t)) {
// ASCII, so both LATIN1 and UTF-8
// Yap_DebugPlWriteln(inp->val.t);
char *s;
s = Malloc(0);
s = Malloc(2 * MaxTmp(PASS_REGS1));
if (snprintf(s, MaxTmp(PASS_REGS1) - 1, Int_FORMAT,
IntegerOfTerm(inp->val.t)) < 0) {
AUX_ERROR(inp->val.t, 2 * MaxTmp(PASS_REGS1), s, char);
}
if (lengp)
*lengp = strlen(s);
return (unsigned char *)s;
}
if (inp->type & YAP_STRING_FLOAT && IsFloatTerm(inp->val.t)) {
@ -474,51 +457,42 @@ unsigned char *Yap_readText(seq_tv_t *inp, size_t *lengp) {
if (!Yap_FormatFloat(FloatOfTerm(inp->val.t), &s, 1024)) {
return NULL;
}
if (lengp)
*lengp = strlen(s);
return (unsigned char *)s;
}
#if USE_GMP
if (inp->type & YAP_STRING_BIG && IsBigIntTerm(inp->val.t)) {
// Yap_DebugPlWriteln(inp->val.t);
char *s;
s = Malloc(0);
s = Malloc(MaxTmp());
if (!Yap_mpz_to_string(Yap_BigIntOfTerm(inp->val.t), s, MaxTmp() - 1, 10)) {
AUX_ERROR(inp->val.t, MaxTmp(PASS_REGS1), s, char);
}
if (lengp)
*lengp = strlen(s);
return inp->val.uc = (unsigned char *)s;
}
#endif
if (inp->type & YAP_STRING_TERM) {
// Yap_DebugPlWriteln(inp->val.t);
char *s = (char *) Yap_TermToString(inp->val.t, lengp, ENC_ISO_UTF8, 0);
char *s = (char *)Yap_TermToString(inp->val.t, ENC_ISO_UTF8, 0);
return inp->val.uc = (unsigned char *)s;
}
if (inp->type & YAP_STRING_CHARS) {
if (inp->enc == ENC_ISO_LATIN1) {
return latin2utf8(inp, lengp);
return latin2utf8(inp);
} else if (inp->enc == ENC_ISO_ASCII) {
if (lengp)
*lengp = strlen(inp->val.c);
return inp->val.uc;
} else { // if (inp->enc == ENC_ISO_UTF8) {
if (lengp)
*lengp = strlen(inp->val.c);
return inp->val.uc;
}
}
if (inp->type & YAP_STRING_WCHARS) {
// printf("%S\n",inp->val.w);
return wchar2utf8(inp, lengp);
return wchar2utf8(inp);
}
return NULL;
}
static Term write_strings(unsigned char *s0, seq_tv_t *out,
size_t leng USES_REGS) {
size_t min = 0, max = leng;
static Term write_strings(unsigned char *s0, seq_tv_t *out USES_REGS) {
size_t min = 0, max = strlen((char *)s0);
if (out->type & (YAP_STRING_NCHARS | YAP_STRING_TRUNC)) {
if (out->type & YAP_STRING_NCHARS)
@ -547,12 +521,13 @@ static Term write_strings(unsigned char *s0, seq_tv_t *out,
return out->val.t;
}
static Term write_atoms(void *s0, seq_tv_t *out, size_t leng USES_REGS) {
static Term write_atoms(void *s0, seq_tv_t *out USES_REGS) {
Term t = AbsPair(HR);
char *s1 = (char *)s0;
size_t sz = 0;
size_t max = leng;
if (leng == 0) {
out->val.t = t;
size_t max = strlen(s1);
if (s1[0] == '\0') {
out->val.t = TermNil;
return TermNil;
}
if (out->type & (YAP_STRING_NCHARS | YAP_STRING_TRUNC)) {
@ -598,23 +573,23 @@ static Term write_atoms(void *s0, seq_tv_t *out, size_t leng USES_REGS) {
return (t);
}
static Term write_codes(void *s0, seq_tv_t *out, size_t leng USES_REGS) {
Term t = AbsPair(HR);
size_t sz = 0;
size_t max = leng;
if (leng == 0) {
out->val.t = t;
return TermNil;
static Term write_codes(void *s0, seq_tv_t *out USES_REGS) {
Term t;
size_t sz = strlen(s0);
if (sz == 0) {
if (out->type & YAP_STRING_DIFF) {
out->val.t = Globalize(out->dif PASS_REGS);
} else {
out->val.t = TermNil;
}
if (out->type & (YAP_STRING_NCHARS | YAP_STRING_TRUNC)) {
if (out->type & YAP_STRING_TRUNC && out->max < max)
max = out->max;
return out->val.t;
}
unsigned char *s = s0, *lim = s + strlen((char *) s);
unsigned char *s = s0, *lim = s + sz;
unsigned char *cp = s;
t = AbsPair(HR);
LOCAL_TERM_ERROR(t, 2 * (lim - s));
t = AbsPair(HR);
while (*cp) {
utf8proc_int32_t chr;
CELL *cl;
@ -625,28 +600,20 @@ static Term write_codes(void *s0, seq_tv_t *out, size_t leng USES_REGS) {
HR += 2;
cl[0] = MkIntegerTerm(chr);
cl[1] = AbsPair(HR);
sz++;
if (sz == max)
break;
}
if (out->type & YAP_STRING_DIFF) {
if (sz == 0)
t = out->dif;
else
if (sz == 0) {
HR[-1] = Globalize(out->dif PASS_REGS);
} else {
if (sz == 0)
t = TermNil;
else
HR[-1] = TermNil;
}
out->val.t = t;
return (t);
}
static Atom write_atom(void *s0, seq_tv_t *out, size_t leng USES_REGS) {
static Atom write_atom(void *s0, seq_tv_t *out USES_REGS) {
unsigned char *s = s0;
int32_t ch;
size_t leng = strlen(s0);
if (leng == 0) {
return Yap_LookupAtom("");
}
@ -660,7 +627,8 @@ static Atom write_atom(void *s0, seq_tv_t *out, size_t leng USES_REGS) {
}
}
size_t write_buffer(unsigned char *s0, seq_tv_t *out, size_t leng USES_REGS) {
size_t write_buffer(unsigned char *s0, seq_tv_t *out USES_REGS) {
size_t leng = strlen((char *)s0);
size_t min = 0, max = leng, room_end;
if (out->enc == ENC_ISO_UTF8) {
room_end = strlen((char *)s0) + 1;
@ -728,12 +696,11 @@ size_t write_buffer(unsigned char *s0, seq_tv_t *out, size_t leng USES_REGS) {
return room_end;
}
static size_t write_length(const unsigned char *s0, seq_tv_t *out,
size_t leng USES_REGS) {
return leng;
static size_t write_length(const unsigned char *s0, seq_tv_t *out USES_REGS) {
return strlen_utf8(s0);
}
static Term write_number(unsigned char *s, seq_tv_t *out, int size,
static Term write_number(unsigned char *s, seq_tv_t *out,
bool error_on USES_REGS) {
Term t;
yap_error_number erro = LOCAL_Error_TYPE;
@ -744,28 +711,28 @@ static Term write_number(unsigned char *s, seq_tv_t *out, int size,
return t;
}
static Term string_to_term(void *s, seq_tv_t *out, size_t leng USES_REGS) {
static Term string_to_term(void *s, seq_tv_t *out USES_REGS) {
Term o;
yap_error_number erro = LOCAL_Error_TYPE;
o = out->val.t = Yap_BufferToTerm(s, strlen(s) + 1, TermNil);
o = out->val.t = Yap_BufferToTerm(s, TermNil);
LOCAL_Error_TYPE = erro;
return o;
}
bool write_Text(unsigned char *inp, seq_tv_t *out, size_t leng USES_REGS) {
bool write_Text(unsigned char *inp, seq_tv_t *out USES_REGS) {
/* we know what the term is */
if (out->type == 0) {
return true;
}
if (out->type & YAP_STRING_DATUM) {
if ((out->val.t = string_to_term(inp, out, leng PASS_REGS)) != 0L)
if ((out->val.t = string_to_term(inp, out PASS_REGS)) != 0L)
return out->val.t != 0;
}
if (out->type & (YAP_STRING_INT | YAP_STRING_FLOAT | YAP_STRING_BIG)) {
if ((out->val.t = write_number(
inp, out, leng, !(out->type & YAP_STRING_ATOM) PASS_REGS)) != 0L) {
inp, out, !(out->type & YAP_STRING_ATOM) PASS_REGS)) != 0L) {
// Yap_DebugPlWriteln(out->val.t);
return true;
@ -775,7 +742,7 @@ bool write_Text(unsigned char *inp, seq_tv_t *out, size_t leng USES_REGS) {
return false;
}
if (out->type & (YAP_STRING_ATOM)) {
if ((out->val.a = write_atom(inp, out, leng PASS_REGS)) != NIL) {
if ((out->val.a = write_atom(inp, out PASS_REGS)) != NIL) {
Atom at = out->val.a;
if (at && (out->type & YAP_STRING_OUTPUT_TERM))
out->val.t = MkAtomTerm(at);
@ -786,42 +753,40 @@ bool write_Text(unsigned char *inp, seq_tv_t *out, size_t leng USES_REGS) {
switch (out->type & YAP_TYPE_MASK) {
case YAP_STRING_CHARS: {
size_t room = write_buffer(inp, out, leng PASS_REGS);
size_t room = write_buffer(inp, out PASS_REGS);
// printf("%s\n", out->val.c);
return ((Int)room > 0);
}
case YAP_STRING_WCHARS: {
size_t room = write_buffer(inp, out, leng PASS_REGS);
size_t room = write_buffer(inp, out PASS_REGS);
// printf("%S\n", out->val.w);
return ((Int)room > 0);
}
case YAP_STRING_STRING:
out->val.t = write_strings(inp, out, leng PASS_REGS);
out->val.t = write_strings(inp, out PASS_REGS);
// Yap_DebugPlWriteln(out->val.t);
return out->val.t != 0;
case YAP_STRING_ATOMS:
out->val.t = write_atoms(inp, out, leng PASS_REGS);
out->val.t = write_atoms(inp, out PASS_REGS);
// Yap_DebugPlWriteln(out->val.t);
return out->val.t != 0;
case YAP_STRING_CODES:
out->val.t = write_codes(inp, out, leng PASS_REGS);
out->val.t = write_codes(inp, out PASS_REGS);
// Yap_DebugPlWriteln(out->val.t);
return out->val.t != 0;
case YAP_STRING_LENGTH:
out->val.l = write_length(inp, out, leng PASS_REGS);
out->val.l = write_length(inp, out PASS_REGS);
// printf("s\n",out->val.l);
return out->val.l != (size_t)(-1);
case YAP_STRING_ATOM:
out->val.a = write_atom(inp, out, leng PASS_REGS);
out->val.a = write_atom(inp, out PASS_REGS);
// Yap_DebugPlWriteln(out->val.t);
return out->val.a != NULL;
case YAP_STRING_INT | YAP_STRING_FLOAT | YAP_STRING_BIG:
out->val.t = write_number(inp, out, leng, true PASS_REGS);
out->val.t = write_number(inp, out, true PASS_REGS);
// Yap_DebugPlWriteln(out->val.t);
return out->val.t != 0;
default: {
return true;
}
default: { return true; }
}
return false;
}
@ -855,8 +820,6 @@ static size_t downcase(void *s0, seq_tv_t *out USES_REGS) {
bool Yap_CVT_Text(seq_tv_t *inp, seq_tv_t *out USES_REGS) {
unsigned char *buf;
bool rc;
size_t leng;
/*
f//printfmark(stderr, "[ %d ", n++) ;
if (inp->type & (YAP_STRING_TERM|YAP_STRING_ATOM|YAP_STRING_ATOMS_CODES
@ -867,10 +830,13 @@ bool Yap_CVT_Text(seq_tv_t *inp, seq_tv_t *out USES_REGS) {
else fprintf(stderr,"s %s\n", inp->val.c);
*/
// cnt++;
buf = Yap_readText(inp, &leng PASS_REGS);
int l = push_text_stack();
buf = Yap_readText(inp PASS_REGS);
if (!buf) {
pop_text_stack(l);
return 0L;
}
size_t leng = strlen_utf8(buf);
if (out->type & (YAP_STRING_NCHARS | YAP_STRING_TRUNC)) {
if (out->max < leng) {
const unsigned char *ptr = skip_utf8(buf, out->max);
@ -881,23 +847,25 @@ bool Yap_CVT_Text(seq_tv_t *inp, seq_tv_t *out USES_REGS) {
leng = diff;
}
// else if (out->type & YAP_STRING_NCHARS &&
// const unsigned char *ptr = skip_utf8(buf, leng)
// const unsigned char *ptr = skip_utf8(buf)
}
if (out->type & (YAP_STRING_UPCASE | YAP_STRING_DOWNCASE)) {
if (out->type & YAP_STRING_UPCASE) {
if (!upcase(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, leng PASS_REGS);
rc = write_Text(buf, out PASS_REGS);
/* fprintf(stderr, " -> ");
if (!rc) fprintf(stderr, "NULL");
else if (out->type &
@ -910,10 +878,10 @@ bool Yap_CVT_Text(seq_tv_t *inp, seq_tv_t *out USES_REGS) {
else
fprintf(stderr, "%s", out->val.c);
fprintf(stderr, "\n]\n"); */
pop_text_stack(l);
return rc;
}
static unsigned char *concat(int n, void *sv[] USES_REGS) {
void *buf;
unsigned char *buf0;
@ -921,16 +889,21 @@ static unsigned char *concat(int n, void *sv[] USES_REGS) {
int i;
for (i = 0; i < n; i++) {
room += strlen((char *) sv[i]);
char *s = sv[i];
if (s[0])
room += strlen(s);
}
buf = Malloc(room + 1);
buf0 = buf;
for (i = 0; i < n; i++) {
char *s = sv[i];
if (!s[0])
continue;
#if _WIN32 || defined(__ANDROID__)
strcpy(buf, sv[i]);
strcpy(buf, s);
buf = (char *)buf + strlen(buf);
#else
buf = stpcpy(buf, sv[i]);
buf = stpcpy(buf, s);
#endif
}
return buf0;
@ -955,25 +928,32 @@ static void *slice(size_t min, size_t max, const unsigned char *buf USES_REGS) {
bool Yap_Concat_Text(int tot, seq_tv_t inp[], seq_tv_t *out USES_REGS) {
void **bufv;
unsigned char *buf;
int i;
size_t leng;
int i, j;
bufv = Malloc(tot * sizeof(unsigned char *));
if (!bufv) {
return NULL;
}
for (i = 0; i < tot; i++) {
inp[i].type |= YAP_STRING_WITH_BUFFER;
unsigned char *nbuf = Yap_readText(inp + i, &leng PASS_REGS);
for (i = 0, j = 0; i < tot; i++) {
inp[j].type |= YAP_STRING_WITH_BUFFER;
unsigned char *nbuf = Yap_readText(inp + i PASS_REGS);
if (!nbuf) {
return NULL;
}
bufv[i] = nbuf;
if (!nbuf[0])
continue;
bufv[j++] = nbuf;
}
if (j == 0) {
buf = malloc(8);
memset(buf, 0, 4);
} else if (j == 1) {
buf = bufv[0];
} else {
buf = concat(tot, bufv PASS_REGS);
bool rc = write_Text(buf, out, strlen_utf8(buf) PASS_REGS);
}
bool rc = write_Text(buf, out PASS_REGS);
return rc;
}
@ -985,10 +965,11 @@ bool Yap_Splice_Text(int n, size_t cuts[], seq_tv_t *inp,
size_t b_l, u_l;
inp->type |= YAP_STRING_IN_TMP;
buf = Yap_readText(inp, &b_l PASS_REGS);
buf = Yap_readText(inp PASS_REGS);
if (!buf) {
return false;
}
b_l = strlen((char *)buf);
u_l = strlen_utf8(buf);
if (!cuts) {
if (n == 2) {
@ -996,28 +977,31 @@ bool Yap_Splice_Text(int n, size_t cuts[], seq_tv_t *inp,
unsigned char *buf0, *buf1;
if (outv[0].val.t) {
buf0 = Yap_readText(outv, &b_l0 PASS_REGS);
buf0 = Yap_readText(outv PASS_REGS);
if (!buf0) {
return false;
}
b_l0 = strlen((const char *)buf0);
if (bcmp(buf, buf0, b_l0) != 0) {
return false;
}
u_l0 = strlen_utf8(buf0);
u_l1 = u_l - u_l0;
b_l1 = b_l - b_l0;
buf1 = slice(u_l0, u_l, buf PASS_REGS);
b_l1 = strlen((const char *)buf1);
bool rc = write_Text(buf1, outv + 1, b_l1 PASS_REGS);
bool rc = write_Text(buf1, outv + 1 PASS_REGS);
if (!rc) {
return false;
}
return rc;
} else /* if (outv[1].val.t) */ {
buf1 = Yap_readText(outv + 1, &b_l1 PASS_REGS);
buf1 = Yap_readText(outv + 1 PASS_REGS);
if (!buf1) {
return false;
}
b_l1 = strlen((char *)buf1);
u_l1 = strlen_utf8(buf1);
b_l0 = b_l - b_l1;
u_l0 = u_l - u_l1;
@ -1026,7 +1010,7 @@ bool Yap_Splice_Text(int n, size_t cuts[], seq_tv_t *inp,
return false;
}
buf0 = slice(0, u_l0, buf PASS_REGS);
bool rc = write_Text(buf0, outv, b_l0 PASS_REGS);
bool rc = write_Text(buf0, outv PASS_REGS);
return rc;
}
}
@ -1040,7 +1024,7 @@ 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);
if (!write_Text(bufi, outv + i, strlen(bufi) PASS_REGS)) {
if (!write_Text(bufi, outv + i PASS_REGS)) {
return false;
}
}
@ -1063,8 +1047,7 @@ bool Yap_Splice_Text(int n, size_t cuts[], seq_tv_t *inp,
* @return the buffer, or NULL in case of failure. If so, Yap_Error may be
called.
*/
const char *Yap_TextTermToText(Term t, char *buf, size_t len, encoding_t enc) {
CACHE_REGS
const char *Yap_TextTermToText(Term t, char *buf, encoding_t enc USES_REGS) {
seq_tv_t inp, out;
inp.val.t = t;
if (IsAtomTerm(t) && t != TermNil) {
@ -1127,8 +1110,7 @@ const char *Yap_PredIndicatorToUTF8String(PredEntry *ap) {
if (ap->ModuleOfPred == IDB_MODULE) {
if (ap->PredFlags & NumberDBPredFlag) {
Int key = ap->src.IndxId;
snprintf(s, smax - s, "%"
PRIdPTR, key);
snprintf(s, smax - s, "%" PRIdPTR, key);
return LOCAL_FileNameBuf;
} else if (ap->PredFlags & AtomDBPredFlag) {
at = (Atom)(ap->FunctorOfPred);
@ -1151,8 +1133,7 @@ const char *Yap_PredIndicatorToUTF8String(PredEntry *ap) {
return NULL;
}
s += strlen(s);
snprintf(s, smax - s, "/%"
PRIdPTR, arity);
snprintf(s, smax - s, "/%" PRIdPTR, arity);
return s0;
}
@ -1165,8 +1146,7 @@ const char *Yap_PredIndicatorToUTF8String(PredEntry *ap) {
*
* @return the term
*/
Term Yap_MkTextTerm(const char *s, encoding_t enc, Term tguide) {
CACHE_REGS
Term Yap_MkTextTerm(const char *s, encoding_t enc, Term tguide USES_REGS) {
if (IsAtomTerm(tguide))
return MkAtomTerm(Yap_LookupAtom(s));
if (IsStringTerm(tguide))

View File

@ -87,7 +87,7 @@ static char *send_tracer_message(char *start, char *name, arity_t arity,
continue;
}
}
const char *sn = Yap_TermToString(args[i], NULL, LOCAL_encoding,
const char *sn = Yap_TermToString(args[i], LOCAL_encoding,
Quote_illegal_f | Handle_vars_f);
size_t sz;
if (sn == NULL) {

View File

@ -4585,6 +4585,9 @@ renumbervar(Term t, Int id USES_REGS)
ts[1] = MkIntegerTerm(id);
}
extern int vsc;
int vsc;
static Int numbervars_in_complex_term(register CELL *pt0, register CELL *pt0_end, Int numbv, int singles USES_REGS)
{
@ -4604,6 +4607,7 @@ static Int numbervars_in_complex_term(register CELL *pt0, register CELL *pt0_end
deref_head(d0, vars_in_term_unk);
vars_in_term_nvar:
{
vsc++;
if (IsPairTerm(d0)) {
if (to_visit + 1024 >= (CELL **)AuxSp) {
goto aux_overflow;

View File

@ -390,7 +390,7 @@ int Yap_FormatFloat(Float f, char **s, size_t sz) {
wglb.stream = GLOBAL_Stream + sno;
wrputf(f, &wglb);
so = Yap_MemExportStreamPtr(sno);
*s = Malloc( strlen(so) )+1;
*s = Malloc( strlen(so)+1 );
strcpy(*s, so );
Yap_CloseStream(sno);
return true;
@ -1255,7 +1255,7 @@ void Yap_plwrite(Term t, StreamDesc *mywrite, int max_depth, int flags,
Yap_CloseSlots(sls);
}
char *Yap_TermToString(Term t, size_t *lengthp, encoding_t enc, int flags) {
char *Yap_TermToString(Term t, encoding_t enc, int flags) {
CACHE_REGS
int sno = Yap_open_buf_write_stream(enc, flags);
const char *sf;

View File

@ -12,7 +12,7 @@ extern "C" {
#include "YapInterface.h"
#include "blobs.h"
X_API char *Yap_TermToString(Term t, size_t *length, encoding_t encodingp,
X_API char *Yap_TermToString(Term t, encoding_t encodingp,
int flags);
X_API void YAP_UserCPredicate(const char *, YAP_UserCPred, arity_t arity);

View File

@ -226,18 +226,17 @@ public:
/// return a string with a textual representation of the term
virtual const char *text() {
CACHE_REGS
size_t length = 0;
encoding_t enc = LOCAL_encoding;
char *os;
BACKUP_MACHINE_REGS();
if (!(os = Yap_TermToString(Yap_GetFromSlot(t), &length, enc,
if (!(os = Yap_TermToString(Yap_GetFromSlot(t), enc,
Handle_vars_f))) {
RECOVER_MACHINE_REGS();
return 0;
}
RECOVER_MACHINE_REGS();
length = strlen(os) + 1;
size_t length = strlen(os);
char *sm = (char *)malloc(length + 1);
strcpy(sm, os);
return sm;

View File

@ -47,7 +47,6 @@
cut_succeed(); \
}
/// allocate a temporary text block
///
extern void *Malloc(size_t sz USES_REGS);
@ -56,8 +55,7 @@ extern void Free(void *buf USES_REGS);
extern int push_text_stack(USES_REGS1);
extern int pop_text_stack(int lvl USES_REGS);
extern void *protected_pop_text_stack(int lvl, void *safe, bool tmp,
size_t sz USES_REGS);
extern void *export_block(int lvl, void *exp USES_REGS);
#ifndef Yap_Min
#define Yap_Min(x, y) (x < y ? x : y)
@ -187,8 +185,10 @@ INLINE_ONLY inline EXTERN utf8proc_ssize_t get_utf8(const utf8proc_uint8_t *ptr,
utf8proc_int32_t *valp) {
utf8proc_ssize_t rc = utf8proc_iterate(ptr, n, valp);
if (rc < 0) {
if (rc == UTF8PROC_ERROR_INVALIDUTF8) Yap_Warning("get_utf8 found bad UTF-8 char %s, skipping...", ptr);
else Yap_Warning("UTF-8 error %d, skipping...", *ptr);
if (rc == UTF8PROC_ERROR_INVALIDUTF8)
Yap_Warning("get_utf8 found bad UTF-8 char %s, skipping...", ptr);
else
Yap_Warning("UTF-8 error %d, skipping...", *ptr);
rc = 1;
}
return rc;
@ -200,7 +200,8 @@ INLINE_ONLY inline EXTERN utf8proc_ssize_t put_utf8(utf8proc_uint8_t *ptr,
INLINE_ONLY inline EXTERN utf8proc_ssize_t put_utf8(utf8proc_uint8_t *ptr,
utf8proc_int32_t val) {
utf8proc_ssize_t rc = utf8proc_encode_char(val, ptr);
if (rc == 0) Yap_Warning("UTF-8 error at %s", ptr);
if (rc == 0)
Yap_Warning("UTF-8 error at %s", ptr);
return rc;
}
@ -213,8 +214,11 @@ inline static const utf8proc_uint8_t *skip_utf8(const utf8proc_uint8_t *pt,
if (b == 0)
return pt;
if (l < 0) {
if (l == UTF8PROC_ERROR_INVALIDUTF8) Yap_Warning("skip_utf8: found bad UTF-8 in char %s[%d], skipping...", pt, i);
else Yap_Warning("UTF-8 error %d at %s[%d], skipping...", l,pt,i);
if (l == UTF8PROC_ERROR_INVALIDUTF8)
Yap_Warning("skip_utf8: found bad UTF-8 in char %s[%d], skipping...",
pt, i);
else
Yap_Warning("UTF-8 error %d at %s[%d], skipping...", l, pt, i);
l = 1;
}
pt += l;
@ -237,8 +241,10 @@ inline static utf8proc_ssize_t strlen_utf8(const utf8proc_uint8_t *pt) {
pt += l;
rc++;
} else {
if (l == UTF8PROC_ERROR_INVALIDUTF8) Yap_Warning("found bad UTF-8 char %d, skipping %s...", *pt, pt);
else Yap_Warning("UTF-8 error %d, skipping...", l);
if (l == UTF8PROC_ERROR_INVALIDUTF8)
Yap_Warning("found bad UTF-8 char %d, skipping %s...", *pt, pt);
else
Yap_Warning("UTF-8 error %d, skipping...", l);
pt++;
}
}
@ -451,9 +457,8 @@ static inline seq_type_t mod_to_bqtype(Term mod USES_REGS) {
// the routines
extern unsigned char *Yap_readText(seq_tv_t *inp, size_t *lengp USES_REGS);
extern bool write_Text(unsigned char *inp, seq_tv_t *out,
size_t leng USES_REGS);
extern unsigned char *Yap_readText(seq_tv_t *inp USES_REGS);
extern bool write_Text(unsigned char *inp, seq_tv_t *out USES_REGS);
extern bool Yap_CVT_Text(seq_tv_t *inp, seq_tv_t *out USES_REGS);
extern bool Yap_Concat_Text(int n, seq_tv_t inp[], seq_tv_t *out USES_REGS);
extern bool Yap_Splice_Text(int n, size_t cuts[], seq_tv_t *inp,
@ -1376,6 +1381,7 @@ static inline size_t Yap_AtomToLength(Term t0 USES_REGS) {
out.type =
YAP_STRING_INT | YAP_STRING_FLOAT | YAP_STRING_BIG | YAP_STRING_TERM;
out.val.uc = NULL;
out.enc = ENC_ISO_UTF8;
if (!Yap_CVT_Text(&inp, &out PASS_REGS))
return 0L;
return out.val.t;
@ -1629,5 +1635,6 @@ static inline size_t Yap_AtomToLength(Term t0 USES_REGS) {
#endif // ≈YAP_TEXT_H
const char *Yap_TextTermToText(Term t, char *buf, size_t len, encoding_t enc);
const char *Yap_TextTermToText(Term t, char *bufwrite_Text,
encoding_t e USES_REGS);
Term Yap_MkTextTerm(const char *s, encoding_t e, Term tguide);

View File

@ -227,9 +227,7 @@ X_API int PL_get_nchars(term_t l, size_t *lengthp, char **s, unsigned flags) {
pop_text_stack(lvl);
return false;
}
out.val.c = protected_pop_text_stack(lvl, out.val.c,
flags & (BUF_RING | BUF_DISCARDABLE),
strlen(out.val.c) + 1 PASS_REGS);
out.val.c = export_block(-1, out.val.c PASS_REGS);
*s = out.val.c;
return true;
}
@ -1786,7 +1784,8 @@ int PL_unify_termv(term_t l, va_list ap) {
Term t = Yap_MkNewApplTerm(ff, arity);
if (nels) {
if (depth == MAX_DEPTH) {
fprintf(stderr, "ERROR: very deep term in PL_unify_term, change "
fprintf(stderr,
"ERROR: very deep term in PL_unify_term, change "
"MAX_DEPTH from %d\n",
MAX_DEPTH);
return FALSE;
@ -2525,7 +2524,8 @@ X_API void PL_register_foreign_in_module(const char *module, const char *name,
#ifdef DEBUG
if (flags & (PL_FA_CREF)) {
fprintf(stderr, "PL_register_foreign_in_module called with non-implemented "
fprintf(stderr,
"PL_register_foreign_in_module called with non-implemented "
"flag %x when creating predicate %s:%s/%d\n",
flags, module, name, arity);
}

View File

@ -42,7 +42,7 @@ bool Yap_GetFileName(Term t, char *buf, size_t len, encoding_t enc) {
t = ArgOfTerm(2, t);
len -= (szl + 1);
}
return Yap_TextTermToText(t, buf, len, enc);
return Yap_TextTermToText(t, buf, enc);
}
static Int file_name_extension(USES_REGS1) {
@ -78,8 +78,7 @@ static Int file_name_extension(USES_REGS1) {
Yap_unify(t2, t);
} else {
f2 = ss + (strlen(ss) + 1);
if (!Yap_TextTermToText(t2, f2, YAP_FILENAME_MAX - 1 - (f2 - f),
ENC_ISO_UTF8))
if (!Yap_TextTermToText(t2, f2, ENC_ISO_UTF8))
return false;
#if __APPLE__ || _WIN32
Yap_OverwriteUTF8BufferToLowCase(f2);
@ -113,12 +112,11 @@ static Int file_name_extension(USES_REGS1) {
return true;
} else {
char *f2;
if (!Yap_TextTermToText(t1, f, YAP_FILENAME_MAX - 2, ENC_ISO_UTF8)) {
if (!Yap_TextTermToText(t1, f, ENC_ISO_UTF8)) {
return false;
}
f2 = f + strlen(f);
if (!Yap_TextTermToText(t2, f2, YAP_FILENAME_MAX - 2 - (f2 - f),
ENC_ISO_UTF8)) {
if (!Yap_TextTermToText(t2, f2, ENC_ISO_UTF8)) {
return false;
}
if (f2[0] != '.') {
@ -460,7 +458,7 @@ static Int is_absolute_file_name(USES_REGS1) { /* file_base_name(Stream,N) */
Yap_Error(INSTANTIATION_ERROR, t, "file_base_name/2");
return false;
}
const char *buf = Yap_TextTermToText(t, NULL, 0, LOCAL_encoding);
const char *buf = Yap_TextTermToText(t, NULL, LOCAL_encoding);
if (buf) {
rc = Yap_IsAbsolutePath(buf);
} else {

View File

@ -23,13 +23,11 @@ static char SccsId[] = "%W% %G%";
*
*/
#include "sysbits.h"
#include "format.h"
#include "sysbits.h"
#if HAVE_FMEMOPEN
int format_synch(int sno, int sno0, format_info *fg) {
const char *s;
int n;
@ -115,8 +113,8 @@ static char SccsId[] = "%W% %G%";
return true;
}
bool Yap_set_stream_to_buf(StreamDesc *st, const char *buf, encoding_t enc, size_t nchars) {
bool Yap_set_stream_to_buf(StreamDesc *st, const char *buf, encoding_t enc,
size_t nchars) {
FILE *f;
// like any file stream.
@ -139,8 +137,7 @@ int Yap_open_buf_read_stream(const char *buf, size_t nchars, enc
sno = GetFreeStreamD();
if (sno < 0)
return (PlIOError(RESOURCE_ERROR_MAX_STREAMS,
TermNil,
return (PlIOError(RESOURCE_ERROR_MAX_STREAMS, TermNil,
"new stream not available for open_mem_read_stream/1"));
st = GLOBAL_Stream + sno;
if (encp)
@ -165,7 +162,7 @@ open_mem_read_stream(USES_REGS1) /* $open_mem_read_stream(+List,-Stream) */
const char *buf;
ti = Deref(ARG1);
buf = Yap_TextTermToText(ti, NULL, 0, LOCAL_encoding);
buf = Yap_TextTermToText(ti, NULL, LOCAL_encoding);
if (!buf) {
return false;
}
@ -290,7 +287,6 @@ void Yap_MemOps(StreamDesc *st) {
st->stream_putc = FilePutc;
st->stream_getc = PlGetc;
}
static int sssno;

View File

@ -1,8 +1,10 @@
#define FORMAT_MAX_SIZE 1024
#include <Yap.h>
typedef struct {
Int filler;
intptr_t filler;
/* character to dump */
int phys;
/* position in buffer */

View File

@ -294,7 +294,7 @@ static void InitStdStream(int sno, SMALLUNSGN flags, FILE *file, VFS_t *vfsp) {
s->status = flags;
s->linepos = 0;
s->linecount = 1;
s->charcount = 0.;
s->charcount = 0;
s->vfs = vfsp;
s->encoding = ENC_ISO_UTF8;
INIT_LOCK(s->streamlock);

View File

@ -286,7 +286,7 @@ form:
+ symbols, including `(`, `)`, `,`, `;`
*/
static Int scan_to_list(USES_ARGS1) {
static Int scan_to_list(USES_REGS1) {
int inp_stream;
Term tpos, tout;
@ -1350,11 +1350,11 @@ static Int style_checker(USES_REGS1) {
return TRUE;
}
Term Yap_BufferToTerm(const unsigned char *s, size_t len, Term opts) {
Term Yap_BufferToTerm(const unsigned char *s, Term opts) {
Term rval;
int sno;
encoding_t l = ENC_ISO_UTF8;
sno = Yap_open_buf_read_stream((char *)s, len, &l, MEM_BUF_USER);
sno = Yap_open_buf_read_stream((char *)s, strlen((const char*)s), &l, MEM_BUF_USER);
rval = Yap_read_term(sno, opts, false);
Yap_CloseStream(sno);
@ -1374,7 +1374,7 @@ X_API Term Yap_BufferToTermWithPrioBindings(const unsigned char *s, size_t len,
if (prio != 1200) {
ctl = add_priority(bindings, ctl);
}
return Yap_BufferToTerm(s, len, ctl);
return Yap_BufferToTerm(s, ctl);
}
/**
@ -1397,7 +1397,6 @@ static Int read_term_from_atom(USES_REGS1) {
Term t1 = Deref(ARG1);
Atom at;
const unsigned char *s;
size_t len;
if (IsVarTerm(t1)) {
Yap_Error(INSTANTIATION_ERROR, t1, "style_check/1");
@ -1408,11 +1407,10 @@ static Int read_term_from_atom(USES_REGS1) {
} else {
at = AtomOfTerm(t1);
s = at->UStrOfAE;
len = strlen_utf8(s);
}
Term ctl = add_output(ARG2, ARG3);
return Yap_BufferToTerm(s, len, ctl);
return Yap_BufferToTerm(s, ctl);
}
/**
@ -1433,7 +1431,7 @@ static Int read_term_from_atom(USES_REGS1) {
static Int read_term_from_atomic(USES_REGS1) {
Term t1 = Deref(ARG1);
const unsigned char *s;
size_t len;
if (IsVarTerm(t1)) {
Yap_Error(INSTANTIATION_ERROR, t1, "read_term_from_atomic/3");
return (FALSE);
@ -1443,11 +1441,10 @@ static Int read_term_from_atomic(USES_REGS1) {
} else {
Term t = Yap_AtomicToString(t1 PASS_REGS);
s = UStringOfTerm(t);
len = strlen_utf8(s);
}
Term ctl = add_output(ARG2, ARG3);
return Yap_BufferToTerm(s, len, ctl);
return Yap_BufferToTerm(s, ctl);
}
/**
@ -1488,7 +1485,6 @@ static Int read_term_from_string(USES_REGS1) {
static Int atomic_to_term(USES_REGS1) {
Term t1 = Deref(ARG1);
size_t len;
if (IsVarTerm(t1)) {
Yap_Error(INSTANTIATION_ERROR, t1, "read_term_from_string/3");
return (FALSE);
@ -1498,15 +1494,13 @@ static Int atomic_to_term(USES_REGS1) {
} else {
Term t = Yap_AtomicToString(t1 PASS_REGS);
const unsigned char *us = UStringOfTerm(t);
len = strlen_utf8(us);
return Yap_BufferToTerm(us, len,
return Yap_BufferToTerm(us,
add_output(ARG2, add_names(ARG3, TermNil)));
}
}
static Int atom_to_term(USES_REGS1) {
Term t1 = Deref(ARG1);
size_t len;
if (IsVarTerm(t1)) {
Yap_Error(INSTANTIATION_ERROR, t1, "read_term_from_string/3");
return (FALSE);
@ -1516,15 +1510,14 @@ static Int atom_to_term(USES_REGS1) {
} else {
Term t = Yap_AtomicToString(t1 PASS_REGS);
const unsigned char *us = UStringOfTerm(t);
len = strlen_utf8(us);
return Yap_BufferToTerm(us, len,
return Yap_BufferToTerm(us,
add_output(ARG2, add_names(ARG3, TermNil)));
}
}
static Int string_to_term(USES_REGS1) {
Term t1 = Deref(ARG1);
size_t len;
if (IsVarTerm(t1)) {
Yap_Error(INSTANTIATION_ERROR, t1, "read_term_from_string/3");
return (FALSE);
@ -1533,8 +1526,7 @@ static Int string_to_term(USES_REGS1) {
return (FALSE);
} else {
const unsigned char *us = UStringOfTerm(t1);
len = strlen_utf8(us);
return Yap_BufferToTerm(us, len,
return Yap_BufferToTerm(us,
add_output(ARG2, add_names(ARG3, TermNil)));
}
}

View File

@ -847,7 +847,7 @@ static Int absolute_file_system_path(USES_REGS1) {
const char *fp;
bool rc;
char s[MAXPATHLEN + 1];
const char *text = Yap_TextTermToText(t, s, MAXPATHLEN, LOCAL_encoding);
const char *text = Yap_TextTermToText(t, s, LOCAL_encoding);
if (text == NULL) {
return false;
@ -1359,7 +1359,7 @@ static Int p_expand_file_name(USES_REGS1) {
Yap_Error(INSTANTIATION_ERROR, t, "argument to true_file_name unbound");
return FALSE;
}
text = Yap_TextTermToText(t, NULL, 0, LOCAL_encoding);
text = Yap_TextTermToText(t, NULL, LOCAL_encoding);
if (!text)
return false;
if (!(text2 = PlExpandVars(text, NULL, NULL)))
@ -1980,8 +1980,7 @@ pop_text_stack(l);
Atom at = Yap_NWCharsToAtom((wchar_t *)data, len PASS_REGS);
pop_text_stack(l);
return Yap_unify(MkAtomTerm(at), ARG3);
case REG_DWORD:
{
case REG_DWORD: {
DWORD *d = (DWORD *)data;
pop_text_stack(l);
return Yap_unify(MkIntegerTerm((Int)d[0]), ARG3);

View File

@ -25,10 +25,10 @@ static char SccsId[] = "%W% %G%";
*/
#include "Yap.h"
#include "YapEval.h"
#include "YapHeap.h"
#include "YapText.h"
#include "Yatom.h"
#include "YapEval.h"
#include "yapio.h"
#include <stdlib.h>
#if HAVE_STDARG_H
@ -678,8 +678,7 @@ static Int term_to_string(USES_REGS1) {
Term t2 = Deref(ARG2), rc = false, t1 = Deref(ARG1);
const char *s;
if (IsVarTerm(t2)) {
size_t length;
s = Yap_TermToString(ARG1, &length, LOCAL_encoding,
s = Yap_TermToString(ARG1,LOCAL_encoding,
Quote_illegal_f | Handle_vars_f);
if (!s || !MkStringTerm(s)) {
Yap_Error(RESOURCE_ERROR_HEAP, t1,
@ -700,8 +699,7 @@ static Int term_to_atom(USES_REGS1) {
Term t2 = Deref(ARG2), ctl, rc = false;
Atom at;
if (IsVarTerm(t2)) {
size_t length;
const char *s = Yap_TermToString(Deref(ARG1), &length, LOCAL_encoding,
const char *s = Yap_TermToString(Deref(ARG1), LOCAL_encoding,
Quote_illegal_f | Handle_vars_f);
if (!s || !(at = Yap_UTF8ToAtom((const unsigned char *)s))) {
Yap_Error(RESOURCE_ERROR_HEAP, t2,
@ -716,8 +714,7 @@ static Int term_to_atom(USES_REGS1) {
at = AtomOfTerm(t2);
}
ctl = TermNil;
return (rc = Yap_BufferToTerm(RepAtom(at)->UStrOfAE,
strlen(RepAtom(at)->StrOfAE), ctl)) &&
return ((rc = Yap_BufferToTerm(RepAtom(at)->UStrOfAE, ctl))) &&
Yap_unify(rc, ARG1);
}

View File

@ -8,10 +8,9 @@
* *
**************************************************************************
* *
* File: yapio.h *
* Last rev: 22/1/03 *
* mods: *
* comments: Input/Output information *
* File: yapio.h * Last
*rev: 22/1/03 * mods:
** comments: Input/Output information *
* *
*************************************************************************/
@ -78,8 +77,7 @@ extern int Yap_PlFGetchar(void);
extern int Yap_GetCharForSIGINT(void);
extern Int Yap_StreamToFileNo(Term);
extern int Yap_OpenStream(FILE *, char *, Term, int);
extern char *Yap_TermToString(Term t, size_t *length, encoding_t encoding,
int flags);
extern char *Yap_TermToString(Term t, encoding_t encoding, int flags);
extern char *Yap_HandleToString(yhandle_t l, size_t sz, size_t *length,
encoding_t *encoding, int flags);
extern int Yap_GetFreeStreamD(void);
@ -110,10 +108,10 @@ extern Term Yap_StringToNumberTerm(const char *s, encoding_t *encp,
extern int Yap_FormatFloat(Float f, char **s, size_t sz);
extern int Yap_open_buf_read_stream(const char *buf, size_t nchars,
encoding_t *encp, memBufSource src);
extern bool Yap_set_stream_to_buf(struct stream_desc *st, const char *buf, encoding_t enc,
size_t nchars);
extern bool Yap_set_stream_to_buf(struct stream_desc *st, const char *buf,
encoding_t enc, size_t nchars);
extern int Yap_open_buf_write_stream(encoding_t enc, memBufSource src);
extern Term Yap_BufferToTerm(const unsigned char *s, size_t sz, Term opts);
extern Term Yap_BufferToTerm(const unsigned char *s, Term opts);
extern X_API Term Yap_BufferToTermWithPrioBindings(const unsigned char *s,
size_t sz, Term opts,
int prio, Term bindings);

File diff suppressed because one or more lines are too long

View File

@ -97,25 +97,29 @@ if any(a.startswith(('bdist', 'build', 'install')) for a in sys.argv):
argv = make_yap_kernel_cmd(executable='python')
dest = os.path.join(here, 'resources')
if os.path.exists(dest):
try:
shutil.rmtree(dest)
os.makedirs( dest )
shutil.copy2('${CMAKE_SOURCE_DIR}/docs/icons/yap_32x32x32.png',dest)
shutil.copy2('${CMAKE_SOURCE_DIR}/docs/icons/yap_64x64x32.png',dest)
write_kernel_spec(dest, overrides={'argv': argv})
shutil.copy('${CMAKE_CURRENT_SOURCE_DIR}/kernel.js',dest)
shutil.copy('${CMAKE_SOURCE_DIR}/misc/editors/prolog.js',dest)
shutil.copy('${CMAKE_SOURCE_DIR}/docs/icons/yap_32x32x32.png',os.path.join(dest,'logo-32x32.png'))
shutil.copy('${CMAKE_SOURCE_DIR}/docs/icons/yap_64x64x32.png',os.path.join(dest,'logo-64x64.png'))
except:
pass
# shutil.copy('${CMAKE_CURRENT_SOURCE_DIR}/kernel.js',dest)
# shutil.copy('${CMAKE_SOURCE_DIR}/misc/editors/prolog.js',dest)
setup_args['data_files'] = [
(pjoin('share', 'jupyter', 'kernels', KERNEL_NAME), glob(pjoin(dest, '*'))),
]
mode_loc = pjoin( sysconfig.get_path('platlib'), 'notebook', 'static', 'components', 'codemirror', 'mode', 'prolog')
custom_loc = pjoin( sysconfig.get_path('platlib'), 'notebook', 'static', 'custom')
try:
shutil.copy( pjoin( custom_loc, "custom.js") , pjoin( custom_loc, "custom.js.orig"))
shutil.copy( "${CMAKE_CURRENT_SOURCE_DIR}/custom.js" , pjoin( custom_loc, "custom.js"))
if not os.path.exists(mode_loc):
os.makedirs(mode_loc)
shutil.copy( "${CMAKE_SOURCE_DIR}/misc/editors/prolog.js" , mode_loc)
except:
pass
shutil.copy( pjoin( custom_loc, "custom.js") , pjoin( custom_loc, "custom.js.orig"))
shutil.copy( "${CMAKE_CURRENT_SOURCE_DIR}/custom.js" , pjoin( custom_loc, "custom.js"))
extras_require = setuptools_args['extras_require'] = {
'test:python_version=="2.7"': ['mock'],