Merge ssh://ssh.dcc.fc.up.pt:31064/home/vsc/yap

This commit is contained in:
Vitor Santos Costa 2018-07-13 14:42:36 +01:00
commit 069fcc875c
145 changed files with 2247 additions and 1952 deletions

View File

@ -147,6 +147,32 @@ static inline Atom SearchAtom(const unsigned char *p, Atom a) {
return (NIL); return (NIL);
} }
Atom
Yap_AtomInUse(const char *atom) { /* lookup atom in atom table */
uint64_t hash;
const unsigned char *p;
Atom a, na = NIL;
AtomEntry *ae;
size_t sz = AtomHashTableSize;
/* compute hash */
p =( const unsigned char *) atom;
hash = HashFunction(p);
hash = hash % sz;
/* we'll start by holding a read lock in order to avoid contention */
READ_LOCK(HashChain[hash].AERWLock);
a = HashChain[hash].Entry;
/* search atom in chain */
na = SearchAtom(p, a);
ae = RepAtom(na);
if (na != NIL ) {
READ_UNLOCK(HashChain[hash].AERWLock);
return (na);
}
READ_UNLOCK(HashChain[hash].AERWLock);
return NIL;
}
static Atom static Atom
LookupAtom(const unsigned char *atom) { /* lookup atom in atom table */ LookupAtom(const unsigned char *atom) { /* lookup atom in atom table */
@ -221,7 +247,7 @@ Atom Yap_LookupAtomWithLength(const char *atom,
ptr = Yap_AllocCodeSpace(len0 + 1); ptr = Yap_AllocCodeSpace(len0 + 1);
if (!ptr) if (!ptr)
return NIL; return NIL;
memcpy(ptr, atom, len0); memmove(ptr, atom, len0);
ptr[len0] = '\0'; ptr[len0] = '\0';
at = LookupAtom(ptr); at = LookupAtom(ptr);
Yap_FreeCodeSpace(ptr); Yap_FreeCodeSpace(ptr);
@ -1010,7 +1036,7 @@ Atom Yap_LookupAtomWithLength(const char *atom,
if (IsApplTerm(t0)) { if (IsApplTerm(t0)) {
Yap_FreeCodeSpace((char *)RepAppl(t0)); Yap_FreeCodeSpace((char *)RepAppl(t0));
} }
memcpy((void *)pt, (void *)ap, sz); memmove((void *)pt, (void *)ap, sz);
p->ValueOfVE = AbsAppl(pt); p->ValueOfVE = AbsAppl(pt);
#endif #endif
} else if (IsStringTerm(v)) { } else if (IsStringTerm(v)) {
@ -1025,7 +1051,7 @@ Atom Yap_LookupAtomWithLength(const char *atom,
if (IsApplTerm(t0)) { if (IsApplTerm(t0)) {
Yap_FreeCodeSpace((char *)RepAppl(t0)); Yap_FreeCodeSpace((char *)RepAppl(t0));
} }
memcpy((void *)pt, (void *)ap, sz); memmove((void *)pt, (void *)ap, sz);
p->ValueOfVE = AbsAppl(pt); p->ValueOfVE = AbsAppl(pt);
} else { } else {
if (IsApplTerm(t0)) { if (IsApplTerm(t0)) {

View File

@ -216,7 +216,7 @@ Atom Yap_LookupAtomWithLength(const char *atom,
ptr = Yap_AllocCodeSpace(len0 + 1); ptr = Yap_AllocCodeSpace(len0 + 1);
if (!ptr) if (!ptr)
return NIL; return NIL;
memcpy(ptr, atom, len0); memmove(ptr, atom, len0);
ptr[len0] = '\0'; ptr[len0] = '\0';
at = LookupAtom(ptr); at = LookupAtom(ptr);
Yap_FreeCodeSpace(ptr); Yap_FreeCodeSpace(ptr);
@ -1004,7 +1004,7 @@ void Yap_PutValue(Atom a, Term v) {
if (IsApplTerm(t0)) { if (IsApplTerm(t0)) {
Yap_FreeCodeSpace((char *)RepAppl(t0)); Yap_FreeCodeSpace((char *)RepAppl(t0));
} }
memcpy((void *)pt, (void *)ap, sz); memmove((void *)pt, (void *)ap, sz);
p->ValueOfVE = AbsAppl(pt); p->ValueOfVE = AbsAppl(pt);
#endif #endif
} else if (IsStringTerm(v)) { } else if (IsStringTerm(v)) {
@ -1019,7 +1019,7 @@ void Yap_PutValue(Atom a, Term v) {
if (IsApplTerm(t0)) { if (IsApplTerm(t0)) {
Yap_FreeCodeSpace((char *)RepAppl(t0)); Yap_FreeCodeSpace((char *)RepAppl(t0));
} }
memcpy((void *)pt, (void *)ap, sz); memmove((void *)pt, (void *)ap, sz);
p->ValueOfVE = AbsAppl(pt); p->ValueOfVE = AbsAppl(pt);
} else { } else {
if (IsApplTerm(t0)) { if (IsApplTerm(t0)) {

View File

@ -1329,7 +1329,7 @@ XX realloc(MALLOC_T ptr, size_t size) {
MALLOC_T new = malloc(size); MALLOC_T new = malloc(size);
if (ptr) if (ptr)
memcpy(new, ptr, size); memmove(new, ptr, size);
free(ptr); free(ptr);
return (new); return (new);
} }

View File

@ -588,13 +588,25 @@ restart_aux:
} }
} }
/** @pred atom_codes(?A, ?L) is iso
The predicate holds when at least one of the arguments is
ground (otherwise, YAP will generate an error event. _A_ must be unifiable
with an atom, and the argument _L_ with the list of the character codes for
string _A_.
*/
static Int atom_codes(USES_REGS1) { static Int atom_codes(USES_REGS1) {
Term t1; Term t1;
t1 = Deref(ARG1); LOCAL_MAX_SIZE = 1024;
int l = push_text_stack(); int l = push_text_stack();
restart_aux: restart_aux:
t1 = Deref(ARG1);
if (IsAtomTerm(t1)) { if (IsAtomTerm(t1)) {
Term tf = Yap_AtomToListOfCodes(t1 PASS_REGS); Term tf = Yap_AtomSWIToListOfCodes(t1 PASS_REGS);
if (tf) { if (tf) {
pop_text_stack(l); pop_text_stack(l);
return Yap_unify(ARG2, tf); return Yap_unify(ARG2, tf);
@ -602,17 +614,16 @@ restart_aux:
} else if (IsVarTerm(t1)) { } else if (IsVarTerm(t1)) {
/* ARG1 unbound */ /* ARG1 unbound */
Term t = Deref(ARG2); Term t = Deref(ARG2);
Atom af = Yap_ListToAtom(t PASS_REGS); Atom af = Yap_ListOfCodesToAtom(t PASS_REGS);
if (af) { if (af) {
pop_text_stack(l); pop_text_stack(l);
return Yap_unify(ARG1, MkAtomTerm(af)); return Yap_unify(ARG1, MkAtomTerm(af));
} }
} else if (IsVarTerm(t1)) { /* error handling */
LOCAL_Error_TYPE = TYPE_ERROR_ATOM; } else {
Yap_ThrowError(TYPE_ERROR_ATOM, t1, NULL);
} }
/* error handling */
if (LOCAL_Error_TYPE && Yap_HandleError("atom_codes/2")) { if (LOCAL_Error_TYPE && Yap_HandleError("atom_codes/2")) {
t1 = Deref(ARG1);
goto restart_aux; goto restart_aux;
} }
{ {
@ -717,14 +728,14 @@ static Int number_chars(USES_REGS1) {
pop_text_stack(l); pop_text_stack(l);
return Yap_unify(ARG1, tf); return Yap_unify(ARG1, tf);
} }
pop_text_stack(l); pop_text_stack(l);
LOCAL_ActiveError->errorRawTerm = 0; LOCAL_ActiveError->errorRawTerm = 0;
Yap_ThrowExistingError(); Yap_ThrowExistingError();
return false; return false;
} }
pop_text_stack(l); pop_text_stack(l);
return true; return true;
} }
@ -1367,7 +1378,7 @@ restart_aux:
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)); 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)); 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;
@ -1455,9 +1466,7 @@ error:
if (LOCAL_Error_TYPE && Yap_HandleError("atom_concat/3")) { if (LOCAL_Error_TYPE && Yap_HandleError("atom_concat/3")) {
goto restart_aux; goto restart_aux;
} }
{ { return FALSE; }
return FALSE;
}
} }
static Int atomics_to_string2(USES_REGS1) { static Int atomics_to_string2(USES_REGS1) {
@ -2070,7 +2079,7 @@ static Int atom_split(USES_REGS1) {
} }
size_t b_mid = skip_utf8(s0, u_mid) - s0; size_t b_mid = skip_utf8(s0, u_mid) - s0;
s1 = s10 = Malloc(b_mid + 1); s1 = s10 = Malloc(b_mid + 1);
memcpy(s1, s, b_mid); memmove(s1, s, b_mid);
s1[b_mid] = '\0'; s1[b_mid] = '\0';
to1 = MkAtomTerm(Yap_ULookupAtom(s10)); to1 = MkAtomTerm(Yap_ULookupAtom(s10));
to2 = MkAtomTerm(Yap_ULookupAtom(s0 + b_mid)); to2 = MkAtomTerm(Yap_ULookupAtom(s0 + b_mid));
@ -2756,6 +2765,8 @@ void Yap_InitAtomPreds(void) {
Yap_InitCPred("downcase_atom", 2, downcase_text_to_atom, 0); Yap_InitCPred("downcase_atom", 2, downcase_text_to_atom, 0);
Yap_InitCPred("upcase_text_to_atom", 2, upcase_text_to_atom, 0); Yap_InitCPred("upcase_text_to_atom", 2, upcase_text_to_atom, 0);
Yap_InitCPred("upcase_atom", 2, upcase_text_to_atom, 0); Yap_InitCPred("upcase_atom", 2, upcase_text_to_atom, 0);
Yap_InitCPred("text_to_string", 2, downcase_text_to_string, 0);
Yap_InitCPred("text_to_atom", 2, downcase_text_to_string, 0);
Yap_InitCPred("downcase_text_to_string", 2, downcase_text_to_string, 0); Yap_InitCPred("downcase_text_to_string", 2, downcase_text_to_string, 0);
Yap_InitCPred("upcase_text_to_string", 2, upcase_text_to_string, 0); Yap_InitCPred("upcase_text_to_string", 2, upcase_text_to_string, 0);
Yap_InitCPred("downcase_text_to_codes", 2, downcase_text_to_codes, 0); Yap_InitCPred("downcase_text_to_codes", 2, downcase_text_to_codes, 0);

View File

@ -48,7 +48,7 @@ char *Yap_blob_to_string(AtomEntry *ref, const char *s0, size_t sz) {
size_t sz0 = strlcpy(s, (char *)RepAtom(AtomSWIStream)->StrOfAE, sz); size_t sz0 = strlcpy(s, (char *)RepAtom(AtomSWIStream)->StrOfAE, sz);
#else #else
size_t sz0; size_t sz0;
char *f = (char *)memcpy(s, (char *)RepAtom(AtomSWIStream)->StrOfAE, sz); char *f = (char *)memmove(s, (char *)RepAtom(AtomSWIStream)->StrOfAE, sz);
f[0] = '\0'; f[0] = '\0';
sz0 = f - s; sz0 = f - s;
#endif #endif
@ -156,7 +156,7 @@ AtomEntry *Yap_lookupBlob(void *blob, size_t len, void *type0, int *new) {
ae->PropsOfAE = AbsBlobProp(b); ae->PropsOfAE = AbsBlobProp(b);
ae->NextOfAE = AbsAtom(Blobs); ae->NextOfAE = AbsAtom(Blobs);
ae->rep.blob->length = len; ae->rep.blob->length = len;
memcpy(ae->rep.blob->data, blob, len); memmove(ae->rep.blob->data, blob, len);
Blobs = ae; Blobs = ae;
if (NOfBlobs > NOfBlobsMax) { if (NOfBlobs > NOfBlobsMax) {
Yap_signal(YAP_CDOVF_SIGNAL); Yap_signal(YAP_CDOVF_SIGNAL);

View File

@ -288,13 +288,23 @@ X_API Term YAP_MkIntTerm(Int n) {
} }
X_API Term YAP_MkStringTerm(const char *n) { X_API Term YAP_MkStringTerm(const char *n) {
CACHE_REGS CACHE_REGS
Term I; Term I;
BACKUP_H(); BACKUP_H();
I = MkStringTerm(n); I = MkStringTerm(n);
RECOVER_H(); RECOVER_H();
return I; return I;
}
X_API Term YAP_MkCharPTerm( char *n) {
CACHE_REGS
Term I;
BACKUP_H();
I = MkStringTerm(n);
RECOVER_H();
return I;
} }
X_API Term YAP_MkUnsignedStringTerm(const unsigned char *n) { X_API Term YAP_MkUnsignedStringTerm(const unsigned char *n) {
@ -1898,7 +1908,7 @@ X_API YAP_opaque_tag_t YAP_NewOpaqueType(struct YAP_opaque_handler_struct *f) {
return -1; return -1;
} }
i = GLOBAL_OpaqueHandlersCount++; i = GLOBAL_OpaqueHandlersCount++;
memcpy(GLOBAL_OpaqueHandlers + i, f, sizeof(YAP_opaque_handler_t)); memmove(GLOBAL_OpaqueHandlers + i, f, sizeof(YAP_opaque_handler_t));
return i; return i;
} }
@ -2129,20 +2139,16 @@ X_API int YAP_InitConsult(int mode, const char *fname, char **full, int *osnop)
char *d = Malloc(strlen(fl)+1); char *d = Malloc(strlen(fl)+1);
strcpy(d,fl); strcpy(d,fl);
bool consulted = (mode == YAP_CONSULT_MODE); bool consulted = (mode == YAP_CONSULT_MODE);
sno = Yap_OpenStream(MkStringTerm(fl), "r", MkAtomTerm(Yap_LookupAtom(fl)), LOCAL_encoding); Term tat = MkAtomTerm(Yap_LookupAtom(d));
sno = Yap_OpenStream(tat, "r", MkAtomTerm(Yap_LookupAtom(fname)), LOCAL_encoding);
if (sno < 0 || if (sno < 0 ||
!Yap_ChDir(dirname((char *)d))) { !Yap_ChDir(dirname((char *)d))) {
pop_text_stack(lvl); pop_text_stack(lvl);
*full = NULL; *full = NULL;
return -1; return -1;
} } LOCAL_PrologMode = UserMode;
LOCAL_PrologMode = UserMode;
Yap_init_consult(consulted, fl); Yap_init_consult(consulted, pop_output_text_stack__(lvl,fl));
GLOBAL_Stream[sno].name = Yap_LookupAtom(fl);
GLOBAL_Stream[sno].user_name = MkAtomTerm(Yap_LookupAtom(fname));
GLOBAL_Stream[sno].encoding = LOCAL_encoding;
*full = pop_output_text_stack(lvl, fl);
RECOVER_MACHINE_REGS(); RECOVER_MACHINE_REGS();
UNLOCK(GLOBAL_Stream[sno].streamlock); UNLOCK(GLOBAL_Stream[sno].streamlock);
return sno; return sno;
@ -2176,7 +2182,8 @@ X_API void YAP_EndConsult(int sno, int *osnop, const char *full) {
if (osnop >= 0) if (osnop >= 0)
Yap_AddAlias(AtomLoopStream, *osnop); Yap_AddAlias(AtomLoopStream, *osnop);
Yap_end_consult(); Yap_end_consult();
__android_log_print(ANDROID_LOG_INFO, "YAPDroid ", " closing %s(%d), %d", full, *osnop, sno); __android_log_print(ANDROID_LOG_INFO, "YAPDroid ", " closing %s:%s(%d), %d",
CurrentModule == 0? "prolog": RepAtom(AtomOfTerm(CurrentModule))->StrOfAE, full, *osnop, sno);
// LOCAL_CurSlot); // LOCAL_CurSlot);
pop_text_stack(lvl); pop_text_stack(lvl);
RECOVER_MACHINE_REGS(); RECOVER_MACHINE_REGS();
@ -2264,8 +2271,8 @@ X_API int YAP_WriteDynamicBuffer(YAP_Term t, char *buf, size_t sze,
char *b; char *b;
BACKUP_MACHINE_REGS(); BACKUP_MACHINE_REGS();
b = Yap_TermToBuffer(t, enc, flags); b = Yap_TermToBuffer(t, flags);
strncpy(buf, b, sze); strncpy(buf, b, sze-1);
buf[sze] = 0; buf[sze] = 0;
RECOVER_MACHINE_REGS(); RECOVER_MACHINE_REGS();
return true; return true;
@ -2364,7 +2371,7 @@ X_API void YAP_FlushAllStreams(void) {
X_API void YAP_Throw(Term t) { X_API void YAP_Throw(Term t) {
BACKUP_MACHINE_REGS(); BACKUP_MACHINE_REGS();
LOCAL_ActiveError->errorNo = THROW_EVENT; LOCAL_ActiveError->errorNo = THROW_EVENT;
LOCAL_ActiveError->errorGoal = Yap_TermToBuffer(t, LOCAL_encoding, 0); LOCAL_ActiveError->errorGoal = Yap_TermToBuffer(t, 0);
Yap_JumpToEnv(); Yap_JumpToEnv();
RECOVER_MACHINE_REGS(); RECOVER_MACHINE_REGS();
} }
@ -2374,7 +2381,7 @@ X_API void YAP_AsyncThrow(Term t) {
BACKUP_MACHINE_REGS(); BACKUP_MACHINE_REGS();
LOCAL_PrologMode |= AsyncIntMode; LOCAL_PrologMode |= AsyncIntMode;
LOCAL_ActiveError->errorNo = THROW_EVENT; LOCAL_ActiveError->errorNo = THROW_EVENT;
LOCAL_ActiveError->errorGoal = Yap_TermToBuffer(t, LOCAL_encoding, 0); LOCAL_ActiveError->errorGoal = Yap_TermToBuffer(t, 0);
Yap_JumpToEnv(); Yap_JumpToEnv();
LOCAL_PrologMode &= ~AsyncIntMode; LOCAL_PrologMode &= ~AsyncIntMode;
RECOVER_MACHINE_REGS(); RECOVER_MACHINE_REGS();
@ -3104,7 +3111,7 @@ X_API Int YAP_AtomToInt(YAP_Atom At) {
"No more room for translations"); "No more room for translations");
return -1; return -1;
} }
memcpy(nt, ot, sizeof(atom_t) * MaxAtomTranslations); memmove(nt, ot, sizeof(atom_t) * MaxAtomTranslations);
TR_Atoms = nt; TR_Atoms = nt;
free(ot); free(ot);
MaxAtomTranslations *= 2; MaxAtomTranslations *= 2;
@ -3132,7 +3139,7 @@ X_API Int YAP_FunctorToInt(YAP_Functor f) {
"No more room for translations"); "No more room for translations");
return -1; return -1;
} }
memcpy(nt, ot, sizeof(functor_t) * MaxFunctorTranslations); memmove(nt, ot, sizeof(functor_t) * MaxFunctorTranslations);
TR_Functors = nt; TR_Functors = nt;
free(ot); free(ot);
MaxFunctorTranslations *= 2; MaxFunctorTranslations *= 2;

View File

@ -301,7 +301,7 @@ void Yap_BuildMegaClause(PredEntry *ap) {
mcl->ClLine = cl->usc.ClLine; mcl->ClLine = cl->usc.ClLine;
ptr = mcl->ClCode; ptr = mcl->ClCode;
while (TRUE) { while (TRUE) {
memcpy((void *)ptr, (void *)cl->ClCode, sz); memmove((void *)ptr, (void *)cl->ClCode, sz);
if (has_blobs) { if (has_blobs) {
LOCAL_ClDiff = (char *)(ptr) - (char *)cl->ClCode; LOCAL_ClDiff = (char *)(ptr) - (char *)cl->ClCode;
restore_opcodes(ptr, NULL PASS_REGS); restore_opcodes(ptr, NULL PASS_REGS);
@ -380,7 +380,7 @@ static void split_megaclause(PredEntry *ap) {
new->ClSize = mcl->ClItemSize; new->ClSize = mcl->ClItemSize;
new->usc.ClLine = Yap_source_line_no(); new->usc.ClLine = Yap_source_line_no();
new->ClNext = NULL; new->ClNext = NULL;
memcpy((void *)new->ClCode, (void *)ptr, mcl->ClItemSize); memmove((void *)new->ClCode, (void *)ptr, mcl->ClItemSize);
if (prev) { if (prev) {
prev->ClNext = new; prev->ClNext = new;
} else { } else {
@ -1386,7 +1386,7 @@ static void expand_consult(void) {
} }
new_cs = new_cl + InitialConsultCapacity; new_cs = new_cl + InitialConsultCapacity;
/* start copying */ /* start copying */
memcpy((void *)new_cs, (void *)LOCAL_ConsultLow, memmove((void *)new_cs, (void *)LOCAL_ConsultLow,
OldConsultCapacity * sizeof(consult_obj)); OldConsultCapacity * sizeof(consult_obj));
/* copying done, release old space */ /* copying done, release old space */
Yap_FreeCodeSpace((char *)LOCAL_ConsultLow); Yap_FreeCodeSpace((char *)LOCAL_ConsultLow);
@ -1768,6 +1768,7 @@ bool Yap_addclause(Term t, yamop *cp, Term tmode, Term mod, Term *t4ref)
disc[2] = Yap_Module_Name(p); disc[2] = Yap_Module_Name(p);
sc[0] = Yap_MkApplTerm(Yap_MkFunctor(AtomDiscontiguous, 3), 3, disc); sc[0] = Yap_MkApplTerm(Yap_MkFunctor(AtomDiscontiguous, 3), 3, disc);
sc[1] = MkIntegerTerm(Yap_source_line_no()); sc[1] = MkIntegerTerm(Yap_source_line_no());
__android_log_print(ANDROID_LOG_INFO, "YAPDroid", "source %s ", RepAtom(LOCAL_SourceFileName)->StrOfAE);
sc[2] = MkAtomTerm(LOCAL_SourceFileName); sc[2] = MkAtomTerm(LOCAL_SourceFileName);
sc[3] = t; sc[3] = t;
t = Yap_MkApplTerm(Yap_MkFunctor(AtomStyleCheck, 4), 4, sc); t = Yap_MkApplTerm(Yap_MkFunctor(AtomStyleCheck, 4), 4, sc);
@ -2064,7 +2065,7 @@ Atom Yap_ConsultingFile(USES_REGS1) {
if (LOCAL_consult_level == 0) { if (LOCAL_consult_level == 0) {
return (AtomUser); return (AtomUser);
} else { } else {
return (Yap_ULookupAtom(LOCAL_ConsultBase[2].f_name)); return LOCAL_ConsultBase[2].f_name;
} }
} }
@ -2078,7 +2079,7 @@ void Yap_init_consult(int mode, const char *filenam) {
expand_consult(); expand_consult();
} }
LOCAL_ConsultSp--; LOCAL_ConsultSp--;
LOCAL_ConsultSp->f_name = (const unsigned char *)filenam; LOCAL_ConsultSp->f_name = Yap_LookupAtom(filenam);
LOCAL_ConsultSp--; LOCAL_ConsultSp--;
LOCAL_ConsultSp->mode = mode; LOCAL_ConsultSp->mode = mode;
LOCAL_ConsultSp--; LOCAL_ConsultSp--;

View File

@ -719,7 +719,7 @@ restart:
dest = Yap_emit_extra_size(blob_op, sz / CellSize, sz, &cglobs->cint); dest = Yap_emit_extra_size(blob_op, sz / CellSize, sz, &cglobs->cint);
/* copy the bignum */ /* copy the bignum */
memcpy(dest, src, sz); memmove(dest, src, sz);
/* note that we don't need to copy size info, unless we wanted /* note that we don't need to copy size info, unless we wanted
to garbage collect clauses ;-) */ to garbage collect clauses ;-) */
cglobs->cint.icpc = cglobs->cint.cpc; cglobs->cint.icpc = cglobs->cint.cpc;
@ -758,7 +758,7 @@ restart:
dest = Yap_emit_extra_size(blob_op, sz / CellSize, sz, &cglobs->cint); dest = Yap_emit_extra_size(blob_op, sz / CellSize, sz, &cglobs->cint);
/* copy the bignum */ /* copy the bignum */
memcpy(dest, src, sz); memmove(dest, src, sz);
/* note that we don't need to copy size info, unless we wanted /* note that we don't need to copy size info, unless we wanted
to garbage collect clauses ;-) */ to garbage collect clauses ;-) */
cglobs->cint.icpc = cglobs->cint.cpc; cglobs->cint.icpc = cglobs->cint.cpc;

View File

@ -642,7 +642,7 @@ static CELL *copy_double(CELL *st, CELL *pt) {
static CELL *copy_string(CELL *st, CELL *pt) { static CELL *copy_string(CELL *st, CELL *pt) {
UInt sz = pt[1] + 3; UInt sz = pt[1] + 3;
/* first thing, store a link to the list before we move on */ /* first thing, store a link to the list before we move on */
memcpy(st, pt, sizeof(CELL) * sz); memmove(st, pt, sizeof(CELL) * sz);
/* now reserve space */ /* now reserve space */
return st + sz; return st + sz;
} }
@ -656,7 +656,7 @@ static CELL *copy_big_int(CELL *st, CELL *pt) {
st[0] = (CELL)FunctorBigInt; st[0] = (CELL)FunctorBigInt;
st[1] = pt[1]; st[1] = pt[1];
/* then the actual number */ /* then the actual number */
memcpy((void *)(st + 2), (void *)(pt + 2), sz); memmove((void *)(st + 2), (void *)(pt + 2), sz);
st = st + 2 + sz / CellSize; st = st + 2 + sz / CellSize;
/* then the tail for gc */ /* then the tail for gc */
st[0] = EndSpecials; st[0] = EndSpecials;
@ -968,7 +968,7 @@ loop:
if (HR + sz >= ASP) { if (HR + sz >= ASP) {
goto error2; goto error2;
} }
memcpy((void *)HR, (void *)(to_visit_base), sz * sizeof(CELL *)); memmove((void *)HR, (void *)(to_visit_base), sz * sizeof(CELL *));
to_visit_base = (CELL **)HR; to_visit_base = (CELL **)HR;
to_visit = to_visit_base + sz; to_visit = to_visit_base + sz;
} }
@ -1684,7 +1684,7 @@ static DBRef CreateDBStruct(Term Tm, DBProp p, int InFlag, int *pstat,
nar = ppt->Contents + Unsigned(NOfCells); nar = ppt->Contents + Unsigned(NOfCells);
} }
woar = (link_entry *)nar; woar = (link_entry *)nar;
memcpy((void *)woar, (const void *)dbg->LinkAr, memmove((void *)woar, (const void *)dbg->LinkAr,
(size_t)(NOfLinks * sizeof(link_entry))); (size_t)(NOfLinks * sizeof(link_entry)));
woar += NOfLinks; woar += NOfLinks;
#ifdef ALIGN_LONGS #ifdef ALIGN_LONGS

View File

@ -1978,7 +1978,7 @@ Void_t* rEALLOc(oldmem, bytes) Void_t* oldmem; size_t bytes;
assert(ncopies >= 3); assert(ncopies >= 3);
if (ncopies > 9) if (ncopies > 9)
memcpy(d, s, copysize); memmove(d, s, copysize);
else { else {
*(d+0) = *(s+0); *(d+0) = *(s+0);
@ -2077,7 +2077,7 @@ Void_t* rEALLOc(oldmem, bytes) Void_t* oldmem; size_t bytes;
/* Must alloc, copy, free. */ /* Must alloc, copy, free. */
newmem = mALLOc(nb - MALLOC_ALIGN_MASK); newmem = mALLOc(nb - MALLOC_ALIGN_MASK);
if (newmem != 0) { if (newmem != 0) {
memcpy(newmem, oldmem, oldsize - 2*SIZE_SZ); memmove(newmem, oldmem, oldsize - 2*SIZE_SZ);
fREe(oldmem); fREe(oldmem);
} }
} }

View File

@ -49,7 +49,7 @@
const char *s = IsAtomTerm(t) ? RepAtom(AtomOfTerm(t))->StrOfAE \ const char *s = IsAtomTerm(t) ? RepAtom(AtomOfTerm(t))->StrOfAE \
: IsStringTerm(t) ? StringOfTerm(t) : NULL; \ : IsStringTerm(t) ? StringOfTerm(t) : NULL; \
if (s) { \ if (s) { \
char *tmp = malloc(strlen(s) + 1); \ char *tmp = calloc(1,strlen(s) + 1); \
strcpy(tmp, s); \ strcpy(tmp, s); \
i->k = tmp; \ i->k = tmp; \
} \ } \
@ -90,21 +90,23 @@ static bool setErr(const char *q, yap_error_descriptor_t *i, Term t) {
return i->k ? TermTrue : TermFalse; \ return i->k ? TermTrue : TermFalse; \
} }
#define query_key_i(k, ks, q, i) \ #define query_key_i(k, ks, q, i) if (strcmp(ks, q) == 0) { \
if (strcmp(ks, q) == 0) { \
return MkIntegerTerm(i->k); \ return MkIntegerTerm(i->k); \
} }
#define query_key_s(k, ks, q, i) \ #define query_key_s(k, ks, q, i) \
if (strcmp(ks, q) == 0 && i->k) { \
return MkAtomTerm(Yap_LookupAtom(i->k)); } else {return TermNil;}
#define query_key_t(k, ks, q, i) \
if (strcmp(ks, q) == 0) { \ if (strcmp(ks, q) == 0) { \
return (i->k && i->k[0] ? MkStringTerm(i->k) : TermNil); \ Term t; if((t = Yap_BufferToTerm(i->k, TermNil) ) == 0 ) return TermNil; return t; }
}
static Term queryErr(const char *q, yap_error_descriptor_t *i) { static Term queryErr(const char *q, yap_error_descriptor_t *i) {
query_key_i(errorNo, "errorNo", q, i); query_key_i(errorNo, "errorNo", q, i);
query_key_i(errorClass, "errorClass", q, i); query_key_i(errorClass, "errorClass", q, i);
query_key_s(errorAsText, "errorAsText", q, i); query_key_s(errorAsText, "errorAsText", q, i);
query_key_s(errorGoal, "errorGoal", q, i); query_key_t(errorGoal, "errorGoal", q, i);
query_key_s(classAsText, "classAsText", q, i); query_key_s(classAsText, "classAsText", q, i);
query_key_i(errorLine, "errorLine", q, i); query_key_i(errorLine, "errorLine", q, i);
query_key_s(errorFunction, "errorFunction", q, i); query_key_s(errorFunction, "errorFunction", q, i);
@ -123,7 +125,7 @@ static Term queryErr(const char *q, yap_error_descriptor_t *i) {
query_key_s(prologParserText, "prologParserText", q, i); query_key_s(prologParserText, "prologParserText", q, i);
query_key_s(prologParserFile, "prologParserFile", q, i); query_key_s(prologParserFile, "prologParserFile", q, i);
query_key_b(prologConsulting, "prologConsulting", q, i); query_key_b(prologConsulting, "prologConsulting", q, i);
query_key_s(culprit, "culprit", q, i); query_key_t(culprit, "culprit", q, i);
query_key_s(errorMsg, "errorMsg", q, i); query_key_s(errorMsg, "errorMsg", q, i);
query_key_i(errorMsgLen, "errorMsgLen", q, i); query_key_i(errorMsgLen, "errorMsgLen", q, i);
return TermNil; return TermNil;
@ -148,10 +150,10 @@ static void printErr(yap_error_descriptor_t *i) {
return; return;
} }
print_key_i("errorNo", i->errorNo); print_key_i("errorNo", i->errorNo);
print_key_i("errorClass", i->errorClass); print_key_i("errorClass", (i->errorClass = Yap_errorClass(i->errorNo)));
print_key_s("errorAsText", i->errorAsText); print_key_s("errorAsText", (i->errorAsText=Yap_errorName(i->errorNo) ) );
print_key_s("errorGoal", i->errorGoal); print_key_s("errorGoal", i->errorGoal);
print_key_s("classAsText", i->classAsText); print_key_s("classAsText", (i->classAsText=Yap_errorClassName(i->errorClass)));
print_key_i("errorLine", i->errorLine); print_key_i("errorLine", i->errorLine);
print_key_s("errorFunction", i->errorFunction); print_key_s("errorFunction", i->errorFunction);
print_key_s("errorFile", i->errorFile); print_key_s("errorFile", i->errorFile);
@ -322,7 +324,7 @@ bool Yap_PrintWarning(Term twarning) {
PredEntry *pred = RepPredProp(PredPropByFunc( PredEntry *pred = RepPredProp(PredPropByFunc(
FunctorPrintMessage, PROLOG_MODULE)); // PROCEDURE_print_message2; FunctorPrintMessage, PROLOG_MODULE)); // PROCEDURE_print_message2;
__android_log_print(ANDROID_LOG_INFO, "YAPDroid ", " warning(%s)", __android_log_print(ANDROID_LOG_INFO, "YAPDroid ", " warning(%s)",
Yap_TermToBuffer(twarning, ENC_ISO_UTF8,Quote_illegal_f | Ignore_ops_f | Unfold_cyclics_f)); Yap_TermToBuffer(twarning, Quote_illegal_f | Ignore_ops_f | Unfold_cyclics_f));
Term cmod = (CurrentModule == PROLOG_MODULE ? TermProlog : CurrentModule); Term cmod = (CurrentModule == PROLOG_MODULE ? TermProlog : CurrentModule);
bool rc; bool rc;
Term ts[2], err; Term ts[2], err;
@ -330,7 +332,7 @@ bool Yap_PrintWarning(Term twarning) {
if (LOCAL_PrologMode & InErrorMode && LOCAL_ActiveError && if (LOCAL_PrologMode & InErrorMode && LOCAL_ActiveError &&
(err = LOCAL_ActiveError->errorNo)) { (err = LOCAL_ActiveError->errorNo)) {
fprintf(stderr, "%% Warning %s while processing error: %s %s\n", fprintf(stderr, "%% Warning %s while processing error: %s %s\n",
Yap_TermToBuffer(twarning, ENC_ISO_UTF8, Yap_TermToBuffer(twarning,
Quote_illegal_f | Ignore_ops_f | Unfold_cyclics_f), Quote_illegal_f | Ignore_ops_f | Unfold_cyclics_f),
Yap_errorClassName(Yap_errorClass(err)), Yap_errorName(err)); Yap_errorClassName(Yap_errorClass(err)), Yap_errorName(err));
return false; return false;
@ -581,23 +583,17 @@ bool Yap_pushErrorContext(bool pass, yap_error_descriptor_t *new_error) {
/* if (Yap_HasException()) */ /* if (Yap_HasException()) */
/* memset(LOCAL_ActiveError, 0, sizeof(*LOCAL_ActiveError)); */ /* memset(LOCAL_ActiveError, 0, sizeof(*LOCAL_ActiveError)); */
/* LOCAL_ActiveError->top_error = bf; */ /* LOCAL_ActiveError->top_error = bf; */
/* } */ /* } */
yap_error_descriptor_t *Yap_popErrorContext(bool mdnew, bool pass) { yap_error_descriptor_t *Yap_popErrorContext(bool mdnew, bool pass) {
yap_error_descriptor_t *e = LOCAL_ActiveError; yap_error_descriptor_t *e = LOCAL_ActiveError, *ep = LOCAL_ActiveError->top_error;
// last block // last block
LOCAL_ActiveError = e->top_error; LOCAL_ActiveError = ep;
if (e->errorNo) { if (e->errorNo && !ep->errorNo && pass) {
if (!LOCAL_ActiveError->errorNo && pass) { yap_error_descriptor_t *epp = ep->top_error;
memcpy(LOCAL_ActiveError, e, sizeof(*LOCAL_ActiveError)); memmove(ep, e, sizeof(*e));
} else { ep->top_error = epp;
return e;
}
} else {
if (e->errorNo)
return e;
} }
return NULL; return LOCAL_ActiveError;
} }
/** /**
* Throw an error directly to the error handler * Throw an error directly to the error handler
@ -652,7 +648,7 @@ bool Yap_MkErrorRecord(yap_error_descriptor_t *r, const char *file,
r->culprit = NULL; r->culprit = NULL;
} else { } else {
r->culprit = Yap_TermToBuffer( r->culprit = Yap_TermToBuffer(
where, ENC_ISO_UTF8, Quote_illegal_f | Ignore_ops_f | Unfold_cyclics_f); where, Quote_illegal_f | Ignore_ops_f | Unfold_cyclics_f);
} }
if (LOCAL_consult_level > 0) { if (LOCAL_consult_level > 0) {
r->prologParserFile = Yap_ConsultingFile(PASS_REGS1)->StrOfAE; r->prologParserFile = Yap_ConsultingFile(PASS_REGS1)->StrOfAE;
@ -941,6 +937,7 @@ typedef struct c_error_info {
; ;
#include <YapErrors.h> #include <YapErrors.h>
#include <iopreds.h>
yap_error_class_number Yap_errorClass(yap_error_number e) { yap_error_class_number Yap_errorClass(yap_error_number e) {
return c_error_list[e].class; return c_error_list[e].class;
@ -956,8 +953,8 @@ yap_error_descriptor_t *Yap_GetException(yap_error_descriptor_t *i) {
CACHE_REGS CACHE_REGS
if (i->errorNo != YAP_NO_ERROR) { if (i->errorNo != YAP_NO_ERROR) {
yap_error_descriptor_t *t = LOCAL_ActiveError, yap_error_descriptor_t *t = LOCAL_ActiveError,
*nt = malloc(sizeof(yap_error_descriptor_t)); *nt = calloc(1,sizeof(yap_error_descriptor_t));
memcpy(nt, t, sizeof(yap_error_descriptor_t)); memmove(nt, t, sizeof(yap_error_descriptor_t));
return nt; return nt;
} }
return 0; return 0;
@ -989,8 +986,11 @@ static Int reset_exception(USES_REGS1) { return Yap_ResetException(worker_id); }
Term MkErrorTerm(yap_error_descriptor_t *t) { Term MkErrorTerm(yap_error_descriptor_t *t) {
if (t->errorClass == EVENT) if (t->errorClass == EVENT)
return t->errorRawTerm; return t->errorRawTerm;
Term tc = t->culprit ? Yap_BufferToTerm(t->culprit, TermNil) : TermNil;
if (tc == 0)
tc = MkAtomTerm(Yap_LookupAtom(t->culprit));
return mkerrort(t->errorNo, return mkerrort(t->errorNo,
t->culprit ? Yap_BufferToTerm(t->culprit, TermNil) : TermNil, tc,
err2list(t)); err2list(t));
} }
@ -1002,8 +1002,13 @@ static Int read_exception(USES_REGS1) {
} }
static Int print_exception(USES_REGS1) { static Int print_exception(USES_REGS1) {
yap_error_descriptor_t *t = AddressOfTerm(Deref(ARG1)); Term t1 = Deref(ARG1);
printErr(t); if (IsAddressTerm(t1)) {
yap_error_descriptor_t *t = AddressOfTerm(t1);
printErr(t);
} else {
return Yap_WriteTerm(LOCAL_c_error_stream,t1,TermNil PASS_REGS);
}
// Yap_DebugPlWriteln(rc); // Yap_DebugPlWriteln(rc);
return true; return true;
} }
@ -1144,7 +1149,7 @@ yap_error_descriptor_t *Yap_UserError(Term t, yap_error_descriptor_t *i) {
n = t2; n = t2;
} }
i->errorGoal = Yap_TermToBuffer( i->errorGoal = Yap_TermToBuffer(
n, ENC_ISO_UTF8, Quote_illegal_f | Ignore_ops_f | Unfold_cyclics_f); n, Quote_illegal_f | Ignore_ops_f | Unfold_cyclics_f);
} }
Yap_prolog_add_culprit(i PASS_REGS); Yap_prolog_add_culprit(i PASS_REGS);
return i; return i;

View File

@ -1460,7 +1460,7 @@ static bool exec_absmi(bool top, yap_reset_t reset_mode USES_REGS) {
*/ */
/* reset the registers so that we don't have trash in abstract /* reset the registers so that we don't have trash in abstract
* machine */ * machine */
pop_text_stack(i+1); pop_text_stack(i + 1);
Yap_set_fpu_exceptions( Yap_set_fpu_exceptions(
getAtomicGlobalPrologFlag(ARITHMETIC_EXCEPTIONS_FLAG)); getAtomicGlobalPrologFlag(ARITHMETIC_EXCEPTIONS_FLAG));
P = (yamop *)FAILCODE; P = (yamop *)FAILCODE;
@ -1470,12 +1470,12 @@ static bool exec_absmi(bool top, yap_reset_t reset_mode USES_REGS) {
} break; } break;
case 3: { /* saved state */ case 3: { /* saved state */
// LOCAL_ActiveError = err_info; // LOCAL_ActiveError = err_info;
pop_text_stack(i+1); pop_text_stack(i + 1);
LOCAL_CBorder = OldBorder; LOCAL_CBorder = OldBorder;
LOCAL_RestartEnv = sighold; LOCAL_RestartEnv = sighold;
LOCAL_PrologMode = UserMode; LOCAL_PrologMode = UserMode;
LOCAL_DoingUndefp = false; LOCAL_DoingUndefp = false;
Yap_CloseSlots(sls); Yap_CloseSlots(sls);
return false; return false;
} }
case 4: case 4:
@ -1485,16 +1485,16 @@ Yap_CloseSlots(sls);
// LOCAL_ActiveError = err_info; // LOCAL_ActiveError = err_info;
while (B) { while (B) {
LOCAL_ActiveError->errorNo = ABORT_EVENT; LOCAL_ActiveError->errorNo = ABORT_EVENT;
pop_text_stack(i+1); pop_text_stack(i + 1);
Yap_CloseSlots(sls); Yap_CloseSlots(sls);
Yap_JumpToEnv(); Yap_JumpToEnv();
} }
LOCAL_PrologMode = UserMode; LOCAL_PrologMode = UserMode;
LOCAL_DoingUndefp = false; LOCAL_DoingUndefp = false;
P = (yamop *)FAILCODE; P = (yamop *)FAILCODE;
LOCAL_RestartEnv = sighold; LOCAL_RestartEnv = sighold;
Yap_CloseSlots(sls); Yap_CloseSlots(sls);
pop_text_stack(i+1); pop_text_stack(i + 1);
return false; return false;
break; break;
case 5: case 5:
@ -1517,15 +1517,15 @@ Yap_CloseSlots(sls);
(CELL *)(B->cp_b) > LCL0 - LOCAL_CBorder) { (CELL *)(B->cp_b) > LCL0 - LOCAL_CBorder) {
LOCAL_RestartEnv = sighold; LOCAL_RestartEnv = sighold;
LOCAL_CBorder = OldBorder; LOCAL_CBorder = OldBorder;
pop_text_stack(i+1); pop_text_stack(i + 1);
return false; return false;
} }
P = FAILCODE; P = FAILCODE;
} }
} }
YENV = ASP; YENV = ASP;
YENV[E_CB] = Unsigned(B); YENV[E_CB] = Unsigned(B);
pop_text_stack(i+1); pop_text_stack(i + 1);
out = Yap_absmi(0); out = Yap_absmi(0);
/* make sure we don't leave a FAIL signal hanging around */ /* make sure we don't leave a FAIL signal hanging around */
Yap_get_signal(YAP_FAIL_SIGNAL); Yap_get_signal(YAP_FAIL_SIGNAL);
@ -1533,7 +1533,7 @@ Yap_CloseSlots(sls);
CalculateStackGap(PASS_REGS1); CalculateStackGap(PASS_REGS1);
LOCAL_CBorder = OldBorder; LOCAL_CBorder = OldBorder;
LOCAL_RestartEnv = sighold; LOCAL_RestartEnv = sighold;
pop_text_stack(i+1); pop_text_stack(i + 1);
return out; return out;
} }
@ -2116,7 +2116,8 @@ static Int jump_env(USES_REGS1) {
} }
// Yap_DebugPlWriteln(t); // Yap_DebugPlWriteln(t);
// char *buf = Yap_TermToBuffer(t, ENC_ISO_UTF8, // char *buf = Yap_TermToBuffer(t, ENC_ISO_UTF8,
// Quote_illegal_f | Ignore_ops_f | Unfold_cyclics_f); // Quote_illegal_f | Ignore_ops_f |
// Unfold_cyclics_f);
// __android_log_print(ANDROID_LOG_INFO, "YAPDroid ", " throw(%s)", buf); // __android_log_print(ANDROID_LOG_INFO, "YAPDroid ", " throw(%s)", buf);
LOCAL_ActiveError = Yap_UserError(t0, LOCAL_ActiveError); LOCAL_ActiveError = Yap_UserError(t0, LOCAL_ActiveError);
bool out = JumpToEnv(PASS_REGS1); bool out = JumpToEnv(PASS_REGS1);
@ -2124,7 +2125,7 @@ static Int jump_env(USES_REGS1) {
LCL0 - (CELL *)B > LOCAL_CBorder) { LCL0 - (CELL *)B > LOCAL_CBorder) {
// we're failing up to the top layer // we're failing up to the top layer
} }
pop_text_stack(LOCAL_MallocDepth+1); pop_text_stack(LOCAL_MallocDepth + 1);
return out; return out;
} }

View File

@ -253,7 +253,7 @@ IntervalUDIRefitIndex(struct index_t **ip, UInt b[] USES_REGS)
qsort(s0+1, (size_t)*s0, sizeof(BITS32), compar); qsort(s0+1, (size_t)*s0, sizeof(BITS32), compar);
it->links[offset0] = s0-sorted0; it->links[offset0] = s0-sorted0;
if (it->udi_free_args) { if (it->udi_free_args) {
memcpy(sorted, s0+1, sizeof(BITS32)*(*s0)); memmove(sorted, s0+1, sizeof(BITS32)*(*s0));
qsort(sorted, (size_t)*s0, sizeof(BITS32), compar2); qsort(sorted, (size_t)*s0, sizeof(BITS32), compar2);
sorted += *s0; sorted += *s0;
} }

159
C/flags.c
View File

@ -1,19 +1,19 @@
/************************************************************************* /*************************************************************************
* * * *
* YAP Prolog * * YAP Prolog *
* * * *
* Yap Prolog was developed at NCCUP - Universidade do Porto * * Yap Prolog was developed at NCCUP - Universidade do Porto *
* * * *
* Copyright L.Damas, V.S.Costa and Universidade do Porto 2015- * * Copyright L.Damas, V.S.Costa and Universidade do Porto 2015- *
* * * *
************************************************************************** **************************************************************************
* * * *
* File: flags.c * * File: flags.c *
* Last rev: * * Last rev: *
* mods: * * mods: *
* comments: abstract machine definitions * * comments: abstract machine definitions *
* * * *
*************************************************************************/ *************************************************************************/
/** @file C/flags.c /** @file C/flags.c
@ -80,22 +80,29 @@ static void newFlag(Term fl, Term val);
static Int current_prolog_flag(USES_REGS1); static Int current_prolog_flag(USES_REGS1);
static Int set_prolog_flag(USES_REGS1); static Int set_prolog_flag(USES_REGS1);
#include "Yatom.h"
#include "YapEval.h" #include "YapEval.h"
#include "Yatom.h"
#include "yapio.h" #include "yapio.h"
#define YAP_FLAG(ID, NAME, WRITABLE, DEF, INIT, HELPER) { NAME, WRITABLE, DEF, INIT, HELPER } #define YAP_FLAG(ID, NAME, WRITABLE, DEF, INIT, HELPER) \
{ NAME, WRITABLE, DEF, INIT, HELPER }
#define START_LOCAL_FLAGS static flag_info local_flags_setup[] = { #define START_LOCAL_FLAGS static flag_info local_flags_setup[] = {
#define END_LOCAL_FLAGS LZERO_FLAG}; #define END_LOCAL_FLAGS \
LZERO_FLAG \
} \
;
#define START_GLOBAL_FLAGS static flag_info global_flags_setup[] = { #define START_GLOBAL_FLAGS static flag_info global_flags_setup[] = {
#define END_GLOBAL_FLAGS GZERO_FLAG}; #define END_GLOBAL_FLAGS \
GZERO_FLAG \
} \
#define GZERO_FLAG { NULL, false, NULL, NULL, NULL } ;
#define LZERO_FLAG { NULL, false, NULL, NULL, NULL }
#define GZERO_FLAG \
{ NULL, false, NULL, NULL, NULL }
#define LZERO_FLAG \
{ NULL, false, NULL, NULL, NULL }
#include "YapGFlagInfo.h" #include "YapGFlagInfo.h"
@ -111,8 +118,7 @@ static Term indexer(Term inp) {
"set_prolog_flag index in {off,single,compact,multi,on,max}"); "set_prolog_flag index in {off,single,compact,multi,on,max}");
return TermZERO; return TermZERO;
} }
Yap_Error(TYPE_ERROR_ATOM, inp, Yap_Error(TYPE_ERROR_ATOM, inp, "set_prolog_flag index to an atom");
"set_prolog_flag in {dec10,error,fail,quiet}");
return TermZERO; return TermZERO;
} }
@ -133,14 +139,16 @@ static bool dqf1(ModEntry *new, Term t2 USES_REGS) {
return true; return true;
} }
/* bad argument, but still an atom */ /* bad argument, but still an atom */
Yap_Error(DOMAIN_ERROR_OUT_OF_RANGE, t2, "bad option %s for backquoted " Yap_Error(DOMAIN_ERROR_OUT_OF_RANGE, t2,
"string flag, use one string, " "bad option %s for backquoted "
"atom, codes or chars", "string flag, use one string, "
"atom, codes or chars",
RepAtom(AtomOfTerm(t2))->StrOfAE); RepAtom(AtomOfTerm(t2))->StrOfAE);
return false; return false;
} else { } else {
Yap_Error(TYPE_ERROR_ATOM, t2, "set_prolog_flag(double_quotes, %s), should " Yap_Error(TYPE_ERROR_ATOM, t2,
"be {string,atom,codes,chars}", "set_prolog_flag(double_quotes, %s), should "
"be {string,atom,codes,chars}",
RepAtom(AtomOfTerm(t2))->StrOfAE); RepAtom(AtomOfTerm(t2))->StrOfAE);
return false; return false;
} }
@ -168,9 +176,10 @@ static bool bqf1(ModEntry *new, Term t2 USES_REGS) {
new->flags |= BCKQ_CHARS; new->flags |= BCKQ_CHARS;
return true; return true;
} }
Yap_Error(DOMAIN_ERROR_OUT_OF_RANGE, t2, "bad option %s for backquoted " Yap_Error(DOMAIN_ERROR_OUT_OF_RANGE, t2,
"string flag, use one string, " "bad option %s for backquoted "
"atom, codes or chars", "string flag, use one string, "
"atom, codes or chars",
RepAtom(AtomOfTerm(t2))->StrOfAE); RepAtom(AtomOfTerm(t2))->StrOfAE);
return false; return false;
} else { } else {
@ -186,7 +195,6 @@ static bool bqs(Term t2) {
return bqf1(new, t2 PASS_REGS); return bqf1(new, t2 PASS_REGS);
} }
static bool sqf1(ModEntry *new, Term t2 USES_REGS) { static bool sqf1(ModEntry *new, Term t2 USES_REGS) {
new->flags &= ~(SNGQ_CHARS | SNGQ_CODES | SNGQ_ATOM | SNGQ_STRING); new->flags &= ~(SNGQ_CHARS | SNGQ_CODES | SNGQ_ATOM | SNGQ_STRING);
if (IsAtomTerm(t2)) { if (IsAtomTerm(t2)) {
@ -203,9 +211,10 @@ static bool sqf1(ModEntry *new, Term t2 USES_REGS) {
new->flags |= SNGQ_CHARS; new->flags |= SNGQ_CHARS;
return true; return true;
} }
Yap_Error(DOMAIN_ERROR_OUT_OF_RANGE, t2, "bad option %s for backquoted " Yap_Error(DOMAIN_ERROR_OUT_OF_RANGE, t2,
"string flag, use one string, " "bad option %s for backquoted "
"atom, codes or chars", "string flag, use one string, "
"atom, codes or chars",
RepAtom(AtomOfTerm(t2))->StrOfAE); RepAtom(AtomOfTerm(t2))->StrOfAE);
return false; return false;
} else { } else {
@ -215,7 +224,6 @@ static bool sqf1(ModEntry *new, Term t2 USES_REGS) {
} }
} }
static bool sqf(Term t2) { static bool sqf(Term t2) {
CACHE_REGS CACHE_REGS
ModEntry *new = Yap_GetModuleEntry(CurrentModule); ModEntry *new = Yap_GetModuleEntry(CurrentModule);
@ -239,8 +247,9 @@ static Term isaccess(Term inp) {
static Term stream(Term inp) { static Term stream(Term inp) {
if (IsVarTerm(inp)) if (IsVarTerm(inp))
return inp; return inp;
if (Yap_CheckStream(inp, Input_Stream_f | Output_Stream_f | Append_Stream_f | if (Yap_CheckStream(inp,
Socket_Stream_f, Input_Stream_f | Output_Stream_f | Append_Stream_f |
Socket_Stream_f,
"yap_flag/3") >= 0) "yap_flag/3") >= 0)
return inp; return inp;
return 0; return 0;
@ -249,19 +258,19 @@ static Term stream(Term inp) {
static bool set_error_stream(Term inp) { static bool set_error_stream(Term inp) {
if (IsVarTerm(inp)) if (IsVarTerm(inp))
return Yap_unify(inp, Yap_StreamUserName(LOCAL_c_error_stream)); return Yap_unify(inp, Yap_StreamUserName(LOCAL_c_error_stream));
return Yap_SetErrorStream( inp ); return Yap_SetErrorStream(inp);
} }
static bool set_input_stream(Term inp) { static bool set_input_stream(Term inp) {
if (IsVarTerm(inp)) if (IsVarTerm(inp))
return Yap_unify(inp, Yap_StreamUserName(LOCAL_c_input_stream)); return Yap_unify(inp, Yap_StreamUserName(LOCAL_c_input_stream));
return Yap_SetInputStream( inp ); return Yap_SetInputStream(inp);
} }
static bool set_output_stream(Term inp) { static bool set_output_stream(Term inp) {
if (IsVarTerm(inp)) if (IsVarTerm(inp))
return Yap_unify(inp, Yap_StreamUserName(LOCAL_c_output_stream)); return Yap_unify(inp, Yap_StreamUserName(LOCAL_c_output_stream));
return Yap_SetOutputStream( inp ); return Yap_SetOutputStream(inp);
} }
static Term isground(Term inp) { static Term isground(Term inp) {
@ -468,7 +477,7 @@ static bool typein(Term inp) {
return true; return true;
} }
static bool list_atom( Term inp ) { x static bool list_atom( Term inp ) {
if (IsVarTerm(inp)) { if (IsVarTerm(inp)) {
Yap_Error(INSTANTIATION_ERROR, inp, "set_prolog_flag in \"...\""); Yap_Error(INSTANTIATION_ERROR, inp, "set_prolog_flag in \"...\"");
return false; return false;
@ -731,10 +740,10 @@ static bool setYapFlagInModule(Term tflag, Term t2, Term mod) {
if (IsVarTerm(tout)) { if (IsVarTerm(tout)) {
Term t; Term t;
while ((t = Yap_PopTermFromDB(tarr[fv->FlagOfVE].DBT)) == 0) { while ((t = Yap_PopTermFromDB(tarr[fv->FlagOfVE].DBT)) == 0) {
if (!Yap_gc(2, ENV, gc_P(P, CP))) { if (!Yap_gc(2, ENV, gc_P(P, CP))) {
Yap_Error(RESOURCE_ERROR_STACK, TermNil, LOCAL_ErrorMessage); Yap_Error(RESOURCE_ERROR_STACK, TermNil, LOCAL_ErrorMessage);
return false; return false;
} }
} }
} else if (IsAtomOrIntTerm(t2)) } else if (IsAtomOrIntTerm(t2))
tarr[fv->FlagOfVE].at = t2; tarr[fv->FlagOfVE].at = t2;
@ -782,7 +791,6 @@ static bool setYapFlagInModule(Term tflag, Term t2, Term mod) {
return bqf1(me, t2 PASS_REGS); return bqf1(me, t2 PASS_REGS);
} else if (fv->FlagOfVE == SINGLE_QUOTES_FLAG) { } else if (fv->FlagOfVE == SINGLE_QUOTES_FLAG) {
return sqf1(me, t2 PASS_REGS); return sqf1(me, t2 PASS_REGS);
} }
// bad key? // bad key?
return false; return false;
@ -850,8 +858,7 @@ static Int cont_yap_flag(USES_REGS1) {
Term modt = CurrentModule; Term modt = CurrentModule;
tflag = Yap_StripModule(tflag, &modt); tflag = Yap_StripModule(tflag, &modt);
while (i != gmax && i != UNKNOWN_FLAG && i != CHARACTER_ESCAPES_FLAG && while (i != gmax && i != UNKNOWN_FLAG && i != CHARACTER_ESCAPES_FLAG &&
i != BACK_QUOTES_FLAG && i != BACK_QUOTES_FLAG && i != SINGLE_QUOTES_FLAG &&
i != SINGLE_QUOTES_FLAG &&
i != DOUBLE_QUOTES_FLAG) i != DOUBLE_QUOTES_FLAG)
i++; i++;
if (i == gmax) if (i == gmax)
@ -1056,14 +1063,16 @@ void Yap_setModuleFlags(ModEntry *new, ModEntry *cme) {
Atom at = new->AtomOfME; Atom at = new->AtomOfME;
if (at == AtomProlog || CurrentModule == PROLOG_MODULE) { if (at == AtomProlog || CurrentModule == PROLOG_MODULE) {
new->flags = new->flags = M_SYSTEM | UNKNOWN_ERROR | M_CHARESCAPE | DBLQ_CODES |
M_SYSTEM | UNKNOWN_ERROR | M_CHARESCAPE | DBLQ_CODES | BCKQ_STRING |SNGQ_ATOM; BCKQ_STRING | SNGQ_ATOM;
if (at == AtomUser) if (at == AtomUser)
new->flags = UNKNOWN_ERROR | M_CHARESCAPE | DBLQ_CODES | BCKQ_STRING |SNGQ_ATOM; new->flags =
UNKNOWN_ERROR | M_CHARESCAPE | DBLQ_CODES | BCKQ_STRING | SNGQ_ATOM;
} else if (cme && cme->flags && cme != new) { } else if (cme && cme->flags && cme != new) {
new->flags = cme->flags; new->flags = cme->flags;
} else { } else {
new->flags = (UNKNOWN_ERROR | M_CHARESCAPE | DBLQ_CODES | BCKQ_STRING |SNGQ_ATOM); new->flags =
(UNKNOWN_ERROR | M_CHARESCAPE | DBLQ_CODES | BCKQ_STRING | SNGQ_ATOM);
} }
// printf("cme=%s new=%s flags=%x\n",cme,at->StrOfAE,new->flags); // printf("cme=%s new=%s flags=%x\n",cme,at->StrOfAE,new->flags);
} }
@ -1391,8 +1400,9 @@ static bool setInitialValue(bool bootstrap, flag_func f, const char *s,
return false; return false;
} }
CACHE_REGS CACHE_REGS
const char *us = (const char *)s; const char *us = (const char *)s;
t0 = Yap_BufferToTermWithPrioBindings(us, TermNil, 0L, strlen(s) + 1, GLOBAL_MaxPriority); t0 = Yap_BufferToTermWithPrioBindings(us, TermNil, 0L, strlen(s) + 1,
GLOBAL_MaxPriority);
if (!t0) if (!t0)
return false; return false;
if (IsAtomTerm(t0) || IsIntTerm(t0)) { if (IsAtomTerm(t0) || IsIntTerm(t0)) {
@ -1439,8 +1449,9 @@ do_prolog_flag_property(Term tflag,
xarg *args; xarg *args;
prolog_flag_property_choices_t i; prolog_flag_property_choices_t i;
bool rc = true; bool rc = true;
args = Yap_ArgList2ToVector(opts, prolog_flag_property_defs, args =
PROLOG_FLAG_PROPERTY_END, DOMAIN_ERROR_PROLOG_FLAG); Yap_ArgList2ToVector(opts, prolog_flag_property_defs,
PROLOG_FLAG_PROPERTY_END, DOMAIN_ERROR_PROLOG_FLAG);
if (args == NULL) { if (args == NULL) {
Yap_Error(LOCAL_Error_TYPE, opts, NULL); Yap_Error(LOCAL_Error_TYPE, opts, NULL);
return false; return false;
@ -1527,9 +1538,8 @@ static Int cont_prolog_flag_property(USES_REGS1) { /* current_prolog_flag */
lab = MkAtomTerm(Yap_LookupAtom(local_flags_setup[i - gmax].name)); lab = MkAtomTerm(Yap_LookupAtom(local_flags_setup[i - gmax].name));
} else { } else {
if (i == UNKNOWN_FLAG || i == CHARACTER_ESCAPES_FLAG || if (i == UNKNOWN_FLAG || i == CHARACTER_ESCAPES_FLAG ||
i == SINGLE_QUOTES_FLAG || i == SINGLE_QUOTES_FLAG || i == DOUBLE_QUOTES_FLAG ||
i == DOUBLE_QUOTES_FLAG || i == BACK_QUOTES_FLAG) {
i == BACK_QUOTES_FLAG) {
Term labs[2]; Term labs[2];
labs[0] = MkVarTerm(); labs[0] = MkVarTerm();
labs[1] = MkAtomTerm(Yap_LookupAtom(global_flags_setup[i].name)); labs[1] = MkAtomTerm(Yap_LookupAtom(global_flags_setup[i].name));
@ -1607,8 +1617,9 @@ static Int do_create_prolog_flag(USES_REGS1) {
prolog_flag_property_choices_t i; prolog_flag_property_choices_t i;
Term tflag = Deref(ARG1), tval = Deref(ARG2), opts = Deref(ARG3); Term tflag = Deref(ARG1), tval = Deref(ARG2), opts = Deref(ARG3);
args = Yap_ArgList2ToVector(opts, prolog_flag_property_defs, args =
PROLOG_FLAG_PROPERTY_END, DOMAIN_ERROR_PROLOG_FLAG); Yap_ArgList2ToVector(opts, prolog_flag_property_defs,
PROLOG_FLAG_PROPERTY_END, DOMAIN_ERROR_PROLOG_FLAG);
if (args == NULL) { if (args == NULL) {
Yap_Error(LOCAL_Error_TYPE, opts, NULL); Yap_Error(LOCAL_Error_TYPE, opts, NULL);
return false; return false;
@ -1660,15 +1671,15 @@ static Int do_create_prolog_flag(USES_REGS1) {
} }
/** /**
* Init System Prolog flags. This is done in two phases: * Init System Prolog flags. This is done in two phases:
* early on, it takes care of the atomic flags that are required by other * early on, it takes care of the atomic flags that are required by other
*modules; *modules;
* later, it looks at flags that are structured terms * later, it looks at flags that are structured terms
* *
* @param bootstrap: wether this is done before stack initialization, or * @param bootstrap: wether this is done before stack initialization, or
*afterwards. *afterwards.
* Complex terms can only be built in the second step. * Complex terms can only be built in the second step.
*/ */
void Yap_InitFlags(bool bootstrap) { void Yap_InitFlags(bool bootstrap) {
CACHE_REGS CACHE_REGS
@ -1722,7 +1733,7 @@ void Yap_InitFlags(bool bootstrap) {
*/ */
Yap_InitCPredBack("prolog_flag", 3, 1, current_prolog_flag, cont_yap_flag, Yap_InitCPredBack("prolog_flag", 3, 1, current_prolog_flag, cont_yap_flag,
0); 0);
Yap_InitCPredBack("yap_flag", 3, 1, prolog_flag, cont_yap_flag, 0); Yap_InitCPredBack("yap_flag", 3, 1, yap_flag, cont_yap_flag, 0);
Yap_InitCPredBack("prolog_flag", 2, 1, current_prolog_flag2, Yap_InitCPredBack("prolog_flag", 2, 1, current_prolog_flag2,
cont_current_prolog_flag, 0); cont_current_prolog_flag, 0);
Yap_InitCPredBack("current_prolog_flag", 2, 1, current_prolog_flag2, Yap_InitCPredBack("current_prolog_flag", 2, 1, current_prolog_flag2,

View File

@ -56,7 +56,7 @@
CPredicate f = PREG->y_u.Osbpp.p->cs.f_code; CPredicate f = PREG->y_u.Osbpp.p->cs.f_code;
PREG = NEXTOP(PREG, Osbpp); PREG = NEXTOP(PREG, Osbpp);
saveregs(); saveregs();
d0 = (f)(PASS_REGS1); d0 = f(PASS_REGS1);
setregs(); setregs();
#ifdef SHADOW_S #ifdef SHADOW_S
SREG = Yap_REGS.S_; SREG = Yap_REGS.S_;

View File

@ -475,7 +475,7 @@ loop:
goto overflow; goto overflow;
} }
*ptf++ = AbsAppl(HR); *ptf++ = AbsAppl(HR);
memcpy(HR, ap2, sizeof(CELL) * (3 + ap2[1])); memmove(HR, ap2, sizeof(CELL) * (3 + ap2[1]));
HR += ap2[1] + 3; HR += ap2[1] + 3;
break; break;
default: { default: {
@ -756,7 +756,7 @@ restart:
res = -1; res = -1;
goto error_handler; goto error_handler;
} }
memcpy(HR, ap, sizeof(CELL) * (3 + ap[1])); memmove(HR, ap, sizeof(CELL) * (3 + ap[1]));
HR += ap[1] + 3; HR += ap[1] + 3;
break; break;
default: { default: {

View File

@ -205,13 +205,13 @@ CopyLocalAndTrail( USES_REGS1 )
static void static void
IncrementalCopyStacksFromWorker( USES_REGS1 ) IncrementalCopyStacksFromWorker( USES_REGS1 )
{ {
memcpy((void *) PtoGloAdjust((CELL *)LOCAL_start_global_copy), memmove((void *) PtoGloAdjust((CELL *)LOCAL_start_global_copy),
(void *) (LOCAL_start_global_copy), (void *) (LOCAL_start_global_copy),
(size_t) (LOCAL_end_global_copy - LOCAL_start_global_copy)); (size_t) (LOCAL_end_global_copy - LOCAL_start_global_copy));
memcpy((void *) PtoLocAdjust((CELL *)LOCAL_start_local_copy), memmove((void *) PtoLocAdjust((CELL *)LOCAL_start_local_copy),
(void *) LOCAL_start_local_copy, (void *) LOCAL_start_local_copy,
(size_t) (LOCAL_end_local_copy - LOCAL_start_local_copy)); (size_t) (LOCAL_end_local_copy - LOCAL_start_local_copy));
memcpy((void *) PtoTRAdjust((tr_fr_ptr)LOCAL_start_trail_copy), memmove((void *) PtoTRAdjust((tr_fr_ptr)LOCAL_start_trail_copy),
(void *) (LOCAL_start_trail_copy), (void *) (LOCAL_start_trail_copy),
(size_t) (LOCAL_end_trail_copy - LOCAL_start_trail_copy)); (size_t) (LOCAL_end_trail_copy - LOCAL_start_trail_copy));
} }

View File

@ -825,7 +825,7 @@ static inline int smaller_or_eq(Term t1, Term t2) {
} }
static inline void clcpy(ClauseDef *d, ClauseDef *s) { static inline void clcpy(ClauseDef *d, ClauseDef *s) {
memcpy((void *)d, (void *)s, sizeof(ClauseDef)); memmove((void *)d, (void *)s, sizeof(ClauseDef));
} }
static void insort(ClauseDef base[], CELL *p, CELL *q, int my_p) { static void insort(ClauseDef base[], CELL *p, CELL *q, int my_p) {
@ -2670,7 +2670,7 @@ static ClauseDef *copy_clauses(ClauseDef *max0, ClauseDef *min0, CELL *top,
save_machine_regs(); save_machine_regs();
siglongjmp(cint->CompilerBotch, 4); siglongjmp(cint->CompilerBotch, 4);
} }
memcpy((void *)top, (void *)min0, sz); memmove((void *)top, (void *)min0, sz);
return (ClauseDef *)top; return (ClauseDef *)top;
} }

View File

@ -301,7 +301,7 @@ bool Yap_dup_op(OpEntry *op, ModEntry *she) {
OpEntry *info = (OpEntry *)Yap_AllocAtomSpace(sizeof(OpEntry)); OpEntry *info = (OpEntry *)Yap_AllocAtomSpace(sizeof(OpEntry));
if (!info) if (!info)
return false; return false;
memcpy(info, op, sizeof(OpEntry)); memmove(info, op, sizeof(OpEntry));
info->NextForME = she->OpForME; info->NextForME = she->OpForME;
she->OpForME = info; she->OpForME = info;
info->OpModule = MkAtomTerm(she->AtomOfME); info->OpModule = MkAtomTerm(she->AtomOfME);
@ -1162,7 +1162,7 @@ void Yap_init_yapor_workers(void) {
worker_id = proc; worker_id = proc;
Yap_remap_yapor_memory(); Yap_remap_yapor_memory();
LOCAL = REMOTE(worker_id); LOCAL = REMOTE(worker_id);
memcpy(REMOTE(worker_id), REMOTE(0), sizeof(struct worker_local)); memmove(REMOTE(worker_id), REMOTE(0), sizeof(struct worker_local));
InitWorker(worker_id); InitWorker(worker_id);
break; break;
} else } else

View File

@ -447,7 +447,7 @@ static void Yap_setCurrentSourceLocation(struct stream_desc *s) {
if (s->status & Pipe_Stream_f) if (s->status & Pipe_Stream_f)
LOCAL_SourceFileName = AtomPipe; LOCAL_SourceFileName = AtomPipe;
else if (s->status & InMemory_Stream_f) else if (s->status & InMemory_Stream_f)
LOCAL_SourceFileName = AtomCharsio; LOCAL_SourceFileName = s->name;
else else
LOCAL_SourceFileName = s->name; LOCAL_SourceFileName = s->name;
LOCAL_SourceFileLineno = s->linecount; LOCAL_SourceFileLineno = s->linecount;

View File

@ -1808,7 +1808,7 @@ void Yap_dump_stack(void) {
yap_error_class_number classno = Yap_errorClass(errnbr); yap_error_class_number classno = Yap_errorClass(errnbr);
fprintf(stderr, "%% Error STATUS: %s/%s\n\n", Yap_errorName(errnbr), fprintf(stderr, "%% Error STATUS: %s/%s\n\n", Yap_errorName(errnbr),
Yap_errorName(classno)); Yap_errorClassName(classno));
fprintf(stderr, "%% Execution mode\n"); fprintf(stderr, "%% Execution mode\n");
if (LOCAL_PrologMode & BootMode) if (LOCAL_PrologMode & BootMode)

205
C/text.c
View File

@ -199,7 +199,7 @@ const void *MallocExportAsRO(const void *pt USES_REGS) {
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); memmove((void *)o, pt, sz);
return realloc((void *)o, sz); return realloc((void *)o, sz);
} }
@ -215,10 +215,7 @@ void *Yap_InitTextAllocator(void) {
return new; return new;
} }
static size_t MaxTmp(USES_REGS1) { static size_t MaxTmp(USES_REGS1) { return 1025; }
return 1025;
}
static Term Globalize(Term v USES_REGS) { static Term Globalize(Term v USES_REGS) {
if (!IsVarTerm(v = Deref(v))) { if (!IsVarTerm(v = Deref(v))) {
@ -231,7 +228,8 @@ static Term Globalize(Term v USES_REGS) {
return v; return v;
} }
static void *codes2buf(Term t0, void *b0, bool *get_codes USES_REGS) { static void *codes2buf(Term t0, void *b0, bool get_codes,
bool fixed USES_REGS) {
unsigned char *st0, *st, ar[16]; unsigned char *st0, *st, ar[16];
Term t = t0; Term t = t0;
size_t length = 0; size_t length = 0;
@ -241,11 +239,19 @@ static void *codes2buf(Term t0, void *b0, bool *get_codes USES_REGS) {
st0[0] = 0; st0[0] = 0;
return st0; return st0;
} }
if (!IsPairTerm(t)) if (!IsPairTerm(t)) {
Yap_ThrowError(TYPE_ERROR_LIST, t, "scanning list of codes");
return NULL; return NULL;
}
bool codes = IsIntegerTerm(HeadOfTerm(t)); bool codes = IsIntegerTerm(HeadOfTerm(t));
if (get_codes) if (get_codes != codes && fixed) {
*get_codes = codes; if (codes) {
Yap_ThrowError(TYPE_ERROR_INTEGER, HeadOfTerm(t),
"scanning list of codes");
} else {
Yap_ThrowError(TYPE_ERROR_ATOM, HeadOfTerm(t), "scanning list of atoms");
}
}
if (codes) { if (codes) {
while (IsPairTerm(t)) { while (IsPairTerm(t)) {
Term hd = HeadOfTerm(t); Term hd = HeadOfTerm(t);
@ -259,7 +265,8 @@ 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, "scanning list of codes"); Yap_ThrowError(REPRESENTATION_ERROR_CHARACTER_CODE, hd,
"scanning list of character codes, found %d", code);
return NULL; return NULL;
} }
length += put_utf8(ar, code); length += put_utf8(ar, code);
@ -368,26 +375,21 @@ static void *slice(size_t min, size_t max, const unsigned char *buf USES_REGS);
static unsigned char *Yap_ListOfCodesToBuffer(unsigned char *buf, Term t, static unsigned char *Yap_ListOfCodesToBuffer(unsigned char *buf, Term t,
seq_tv_t *inp USES_REGS) { seq_tv_t *inp USES_REGS) {
bool codes; bool codes = true, fixed = true;
unsigned char *nbuf = codes2buf(t, buf, &codes PASS_REGS); unsigned char *nbuf = codes2buf(t, buf, codes, fixed PASS_REGS);
if (!codes)
return NULL;
return nbuf; return nbuf;
} }
static unsigned char *Yap_ListOfAtomsToBuffer(unsigned char *buf, Term t, static unsigned char *Yap_ListOfAtomsToBuffer(unsigned char *buf, Term t,
seq_tv_t *inp USES_REGS) { seq_tv_t *inp USES_REGS) {
bool codes; bool codes = false;
unsigned char *nbuf = codes2buf(t, buf, &codes PASS_REGS); unsigned char *nbuf = codes2buf(t, buf, codes, true PASS_REGS);
if (codes)
return NULL;
return nbuf; return nbuf;
} }
static unsigned char *Yap_ListToBuffer(unsigned char *buf, Term t, static unsigned char *Yap_ListToBuffer(unsigned char *buf, Term t,
seq_tv_t *inp USES_REGS) { seq_tv_t *inp USES_REGS) {
unsigned char *nbuf = codes2buf(t, buf, NULL PASS_REGS); return codes2buf(t, buf, NULL, false PASS_REGS);
return nbuf;
} }
#if USE_GEN_TYPE_ERROR #if USE_GEN_TYPE_ERROR
@ -418,8 +420,10 @@ static yap_error_number gen_type_error(int flags) {
// static int cnt; // static int cnt;
unsigned char *Yap_readText(seq_tv_t *inp USES_REGS) { unsigned char *Yap_readText(seq_tv_t *inp USES_REGS) {
#define POPRET(x) return pop_output_text_stack(lvl, x)
int lvl = push_text_stack(); int lvl = push_text_stack();
char *out = NULL;
yap_error_number err0 = LOCAL_Error_TYPE;
/* we know what the term is */ /* we know what the term is */
if (!(inp->type & (YAP_STRING_CHARS | YAP_STRING_WCHARS))) { if (!(inp->type & (YAP_STRING_CHARS | YAP_STRING_WCHARS))) {
if (!(inp->type & YAP_STRING_TERM)) { if (!(inp->type & YAP_STRING_TERM)) {
@ -431,128 +435,131 @@ unsigned char *Yap_readText(seq_tv_t *inp USES_REGS) {
LOCAL_Error_TYPE = TYPE_ERROR_STRING; LOCAL_Error_TYPE = TYPE_ERROR_STRING;
} else if (!IsPairOrNilTerm(inp->val.t) && !IsStringTerm(inp->val.t) && } else if (!IsPairOrNilTerm(inp->val.t) && !IsStringTerm(inp->val.t) &&
inp->type == (YAP_STRING_ATOMS_CODES | YAP_STRING_STRING)) { inp->type == (YAP_STRING_ATOMS_CODES | YAP_STRING_STRING)) {
LOCAL_Error_TYPE = TYPE_ERROR_LIST; LOCAL_ActiveError->errorRawTerm = inp->val.t;
} else if (!IsPairOrNilTerm(inp->val.t) && !IsStringTerm(inp->val.t) && } else if (!IsPairOrNilTerm(inp->val.t) && !IsStringTerm(inp->val.t) &&
!IsAtomTerm(inp->val.t) && !(inp->type & YAP_STRING_DATUM)) { !IsAtomTerm(inp->val.t) && !(inp->type & YAP_STRING_DATUM)) {
LOCAL_Error_TYPE = TYPE_ERROR_TEXT; LOCAL_Error_TYPE = TYPE_ERROR_TEXT;
} }
} }
if (LOCAL_Error_TYPE != YAP_NO_ERROR) { if (err0 != LOCAL_Error_TYPE) {
if (inp->val.uc != NULL) { Yap_ThrowError(LOCAL_Error_TYPE, inp->val.t, "while reading text in");
LOCAL_ActiveError->errorRawTerm = MkUStringTerm(inp->val.uc); }
}
Yap_ThrowError(LOCAL_Error_TYPE, LOCAL_ActiveError->errorRawTerm, "Converting to text from term ");
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
// Yap_DebugPlWriteln(inp->val.t); // Yap_DebugPlWriteln(inp->val.t);
Atom at = AtomOfTerm(inp->val.t); Atom at = AtomOfTerm(inp->val.t);
if (RepAtom(at)->UStrOfAE[0] == 0) { if (RepAtom(at)->UStrOfAE[0] == 0) {
unsigned char *o = Malloc(4); out = Malloc(4);
memset(o, 0, 4); memset(out, 0, 4);
return pop_output_text_stack(lvl, o); POPRET( out );
} }
if (inp->type & YAP_STRING_WITH_BUFFER) { if (inp->type & YAP_STRING_WITH_BUFFER) {
pop_text_stack(lvl); pop_text_stack(lvl);
return at->UStrOfAE; return at->UStrOfAE;
} }
size_t sz = strlen(at->StrOfAE); {
void *o = Malloc(sz + 1); size_t sz = strlen(at->StrOfAE);
strcpy(o, at->StrOfAE); out = Malloc(sz + 1);
return pop_output_text_stack(lvl, o); strcpy(out, at->StrOfAE);
POPRET( out );
}
} }
if (IsStringTerm(inp->val.t) && inp->type & YAP_STRING_STRING) { if (IsStringTerm(inp->val.t) && inp->type & YAP_STRING_STRING) {
// this is a term, extract to a buffer, and representation is wide // this is a term, extract to a buffer, and representation is wide
// Yap_DebugPlWriteln(inp->val.t); // Yap_DebugPlWriteln(inp->val.t);
const char *s = StringOfTerm(inp->val.t); const char *s = StringOfTerm(inp->val.t);
if (s[0] == 0) { if (s[0] == 0) {
char *o = Malloc(4); out = Malloc(4);
memset(o, 0, 4); memset(out, 0, 4);
return pop_output_text_stack(lvl, o); POPRET( out );
}
if (inp->type & YAP_STRING_WITH_BUFFER) {
pop_text_stack(lvl);
return (unsigned char *)UStringOfTerm(inp->val.t);
}
{
inp->type |= YAP_STRING_IN_TMP;
size_t sz = strlen(s);
out = Malloc(sz + 1);
strcpy(out, s);
POPRET( out );
}
} else if (IsPairOrNilTerm(inp->val.t)) {
if (((inp->type & (YAP_STRING_CODES | YAP_STRING_ATOMS)) ==
(YAP_STRING_CODES | YAP_STRING_ATOMS))) {
// Yap_DebugPlWriteln(inp->val.t);
out = (char *)Yap_ListToBuffer(NULL, inp->val.t, inp PASS_REGS);
POPRET( out );
// this is a term, extract to a sfer, and representation is wide
}
if (inp->type & YAP_STRING_CODES) {
// Yap_DebugPlWriteln(inp->val.t);
out = (char *)Yap_ListOfCodesToBuffer(NULL, inp->val.t, inp PASS_REGS);
// this is a term, extract to a sfer, and representation is wide
POPRET( out );
}
if (inp->type & YAP_STRING_ATOMS) {
// Yap_DebugPlWriteln(inp->val.t);
out = (char *)Yap_ListOfAtomsToBuffer(NULL, inp->val.t, inp PASS_REGS);
// this is a term, extract to a buffer, and representation is wide
POPRET( out );
} }
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);
strcpy(o, s);
return pop_output_text_stack(lvl, o);
}
if (((inp->type & (YAP_STRING_CODES | YAP_STRING_ATOMS)) ==
(YAP_STRING_CODES | YAP_STRING_ATOMS)) &&
IsPairOrNilTerm(inp->val.t)) {
// Yap_DebugPlWriteln(inp->val.t);
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 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 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)) { if (inp->type & YAP_STRING_INT && IsIntegerTerm(inp->val.t)) {
// ASCII, so both LATIN1 and UTF-8 // ASCII, so both LATIN1 and UTF-8
// Yap_DebugPlWriteln(inp->val.t); // Yap_DebugPlWriteln(inp->val.t);
char *s; out = Malloc(2 * MaxTmp(PASS_REGS1));
s = Malloc(2 * MaxTmp(PASS_REGS1)); if (snprintf(out, MaxTmp(PASS_REGS1) - 1, Int_FORMAT,
if (snprintf(s, MaxTmp(PASS_REGS1) - 1, Int_FORMAT,
IntegerOfTerm(inp->val.t)) < 0) { IntegerOfTerm(inp->val.t)) < 0) {
AUX_ERROR(inp->val.t, 2 * MaxTmp(PASS_REGS1), s, char); AUX_ERROR(inp->val.t, 2 * MaxTmp(PASS_REGS1), out, char);
} }
return pop_output_text_stack(lvl, s); POPRET( out );
} }
if (inp->type & YAP_STRING_FLOAT && IsFloatTerm(inp->val.t)) { if (inp->type & YAP_STRING_FLOAT && IsFloatTerm(inp->val.t)) {
char *s; out = Malloc(2 * MaxTmp(PASS_REGS1));
// Yap_DebugPlWriteln(inp->val.t); if (!Yap_FormatFloat(FloatOfTerm(inp->val.t), &out, 1024)) {
if (!Yap_FormatFloat(FloatOfTerm(inp->val.t), &s, 1024)) {
pop_text_stack(lvl); pop_text_stack(lvl);
return NULL; return NULL;
} }
return pop_output_text_stack(lvl, s); POPRET(out);
} }
#if USE_GMP #if USE_GMP
if (inp->type & YAP_STRING_BIG && IsBigIntTerm(inp->val.t)) { if (inp->type & YAP_STRING_BIG && IsBigIntTerm(inp->val.t)) {
// Yap_DebugPlWriteln(inp->val.t); // Yap_DebugPlWriteln(inp->val.t);
char *s; out = Malloc(MaxTmp());
s = Malloc(MaxTmp()); if (!Yap_mpz_to_string(Yap_BigIntOfTerm(inp->val.t), out, MaxTmp() - 1,
if (!Yap_mpz_to_string(Yap_BigIntOfTerm(inp->val.t), s, MaxTmp() - 1, 10)) { 10)) {
AUX_ERROR(inp->val.t, MaxTmp(PASS_REGS1), s, char); AUX_ERROR(inp->val.t, MaxTmp(PASS_REGS1), out, char);
} }
return inp->val.uc = pop_output_text_stack(lvl, s); POPRET(out);
} }
#endif #endif
if (inp->type & YAP_STRING_TERM) { if (inp->type & YAP_STRING_TERM) {
// Yap_DebugPlWriteln(inp->val.t);
char *s = (char *)Yap_TermToBuffer(inp->val.t, ENC_ISO_UTF8, 0);
return inp->val.uc = pop_output_text_stack(lvl, s);
}
if (inp->type & YAP_STRING_CHARS) {
pop_text_stack(lvl); pop_text_stack(lvl);
if (inp->enc == ENC_ISO_LATIN1) { return Yap_TermToBuffer(inp->val.t, 0);
return latin2utf8(inp); }
} else if (inp->enc == ENC_ISO_ASCII) {
return inp->val.uc; if (inp->type & YAP_STRING_CHARS) {
} else { // if (inp->enc == ENC_ISO_UTF8) { if (inp->enc == ENC_ISO_ASCII) {
pop_text_stack(lvl);
return inp->val.uc; return inp->val.uc;
} }
if (inp->enc == ENC_ISO_LATIN1) {
POPRET( (char*)latin2utf8(inp));
}
if (inp->enc == ENC_ISO_UTF8) {
pop_text_stack(lvl);
return inp->val.c;
}
} }
pop_text_stack(lvl);
if (inp->type & YAP_STRING_WCHARS) { if (inp->type & YAP_STRING_WCHARS) {
// printf("%S\n",inp->val.w); // printf("%S\n",inp->val.w);
return wchar2utf8(inp); POPRET( (char *)wchar2utf8(inp) );
} }
pop_text_stack(lvl);
return NULL; return NULL;
} }
@ -681,16 +688,16 @@ static Term write_codes(void *s0, seq_tv_t *out USES_REGS) {
static Atom write_atom(void *s0, seq_tv_t *out USES_REGS) { static Atom write_atom(void *s0, seq_tv_t *out USES_REGS) {
unsigned char *s = s0; unsigned char *s = s0;
int32_t ch; int32_t ch;
size_t leng = strlen(s0); if (s[0] == '\0') {
if (leng == 0) {
return Yap_LookupAtom(""); return Yap_LookupAtom("");
} }
size_t leng = strlen(s0);
if (strlen_utf8(s0) <= leng) { if (strlen_utf8(s0) <= leng) {
return Yap_LookupAtom(s0); return Yap_LookupAtom(s0);
} else { } else {
size_t n = get_utf8(s, -1, &ch); size_t n = get_utf8(s, -1, &ch);
unsigned char *buf = Malloc(n + 1); unsigned char *buf = Malloc(n + 1);
memcpy(buf, s0, n + 1); memmove(buf, s0, n + 1);
return Yap_ULookupAtom(buf); return Yap_ULookupAtom(buf);
} }
} }
@ -921,7 +928,7 @@ bool Yap_CVT_Text(seq_tv_t *inp, seq_tv_t *out USES_REGS) {
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); memmove(nbuf, buf, diff);
nbuf[diff] = '\0'; nbuf[diff] = '\0';
leng = diff; leng = diff;
} }

View File

@ -85,7 +85,7 @@ void *protected_pop_text_stack(int i, void *protected, bool tmp,
out = LOCAL_FileNameBuf; out = LOCAL_FileNameBuf;
else else
out = p; out = p;
memcpy(out, protected, sz); memmove(out, protected, sz);
} else { } else {
free(p); free(p);
} }
@ -661,7 +661,7 @@ static Atom write_atom(void *s0, seq_tv_t *out, size_t leng USES_REGS) {
return Yap_LookupAtom(s0); return Yap_LookupAtom(s0);
} else { } else {
unsigned char *buf = Malloc(leng + 1); unsigned char *buf = Malloc(leng + 1);
memcpy(buf, s0, leng); memmove(buf, s0, leng);
buf[leng] = \0; buf[leng] = \0;
return Yap_ULookupAtom(buf); return Yap_ULookupAtom(buf);
} }
@ -872,7 +872,7 @@ bool Yap_CVT_Text(seq_tv_t *inp, seq_tv_t *out USES_REGS) {
size_t max_s = skip_utf8( buf, out-> max )-buf; size_t max_s = skip_utf8( buf, out-> max )-buf;
if (max_s < leng_s) { if (max_s < leng_s) {
char *nbuf = Malloc(max_s + 1); char *nbuf = Malloc(max_s + 1);
memcpy(nbuf, buf, max_s); memmove(nbuf, buf, max_s);
nbuf[max_s] = '\0'; nbuf[max_s] = '\0';
leng_s = out->max; leng_s = out->max;
} }

View File

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

View File

@ -182,7 +182,7 @@ copy_complex_term(CELL *pt0, CELL *pt0_end, int share, int newattvs, CELL *ptf,
if (HR+sz > ASP - 2048) { if (HR+sz > ASP - 2048) {
goto overflow; goto overflow;
} }
memcpy((void *)HR, (void *)ap2, sz*sizeof(CELL)); memmove((void *)HR, (void *)ap2, sz*sizeof(CELL));
HR += sz; HR += sz;
} else { } else {
*ptf++ = d0; /* you can just copy other extensions. */ *ptf++ = d0; /* you can just copy other extensions. */
@ -845,7 +845,7 @@ export_term_to_buffer(Term inpt, char *buf, char *bptr, CELL *t0 , CELL *tf, siz
if (buf + len < (char *)((CELL *)td + (tf-t0))) { if (buf + len < (char *)((CELL *)td + (tf-t0))) {
return FALSE; return FALSE;
} }
memcpy((void *)td, (void *)t0, (tf-t0)* sizeof(CELL)); memmove((void *)td, (void *)t0, (tf-t0)* sizeof(CELL));
bf[0] = (td-buf); bf[0] = (td-buf);
bf[1] = (tf-t0); bf[1] = (tf-t0);
bf[2] = inpt; bf[2] = inpt;
@ -945,7 +945,7 @@ export_complex_term(Term tf, CELL *pt0, CELL *pt0_end, char * buf, size_t len0,
if (HR+sz > ASP - 2048) { if (HR+sz > ASP - 2048) {
goto overflow; goto overflow;
} }
memcpy((void *)HR, (void *)ap2, sz*sizeof(CELL)); memmove((void *)HR, (void *)ap2, sz*sizeof(CELL));
HR += sz; HR += sz;
continue; continue;
} }
@ -1263,7 +1263,7 @@ Yap_ImportTerm(char * buf) {
return 0L; return 0L;
} }
} }
memcpy(HR, buf+bc[0], sizeof(CELL)*sz); memmove(HR, buf+bc[0], sizeof(CELL)*sz);
if (IsApplTerm(tinp)) { if (IsApplTerm(tinp)) {
tret = AbsAppl(HR); tret = AbsAppl(HR);
import_compound(HR, (char *)HR, buf, HR); import_compound(HR, (char *)HR, buf, HR);
@ -3476,7 +3476,7 @@ hash_complex_term(register CELL *pt0,
*st++ = LongIntOfTerm(d0); *st++ = LongIntOfTerm(d0);
break; break;
case (CELL)FunctorString: case (CELL)FunctorString:
memcpy(st, RepAppl(d0), (3+RepAppl(d0)[1])*sizeof(CELL)); memmove(st, RepAppl(d0), (3+RepAppl(d0)[1])*sizeof(CELL));
st += 3+RepAppl(d0)[1]; st += 3+RepAppl(d0)[1];
break; break;
#ifdef USE_GMP #ifdef USE_GMP
@ -3491,7 +3491,7 @@ hash_complex_term(register CELL *pt0,
goto global_overflow; goto global_overflow;
} }
/* then the actual number */ /* then the actual number */
memcpy((void *)(st+1), (void *)(pt+1), sz); memmove((void *)(st+1), (void *)(pt+1), sz);
st = st+sz/CellSize; st = st+sz/CellSize;
} }
break; break;

View File

@ -384,9 +384,7 @@ int Yap_FormatFloat(Float f, char **s, size_t sz) {
wglb.lw = separator; wglb.lw = separator;
wglb.stream = GLOBAL_Stream + sno; wglb.stream = GLOBAL_Stream + sno;
wrputf(f, &wglb); wrputf(f, &wglb);
so = Yap_MemExportStreamPtr(sno); *s = Yap_MemExportStreamPtr(sno);
*s = BaseMalloc(strlen(so) + 1);
strcpy(*s, so);
Yap_CloseStream(sno); Yap_CloseStream(sno);
return true; return true;
} }
@ -1255,28 +1253,3 @@ void Yap_plwrite(Term t, StreamDesc *mywrite, int max_depth, int flags,
pop_text_stack(lvl); pop_text_stack(lvl);
} }
char *Yap_TermToBuffer(Term t, encoding_t enc, int flags) {
CACHE_REGS
int sno = Yap_open_buf_write_stream(enc, flags);
const char *sf;
if (sno < 0)
return NULL;
if (t == 0)
return NULL;
else
t = Deref(t);
if (enc)
GLOBAL_Stream[sno].encoding = enc;
else
GLOBAL_Stream[sno].encoding = LOCAL_encoding;
GLOBAL_Stream[sno].status |= CloseOnException_Stream_f;
Yap_plwrite(t, GLOBAL_Stream + sno, 0, flags, GLOBAL_MaxPriority);
sf = Yap_MemExportStreamPtr(sno);
size_t len = strlen(sf);
char *new = malloc(len + 1);
strcpy(new, sf);
Yap_CloseStream(sno);
return new;
}

View File

@ -161,8 +161,7 @@ static bool consult(const char *b_file USES_REGS) {
/* consult in C */ /* consult in C */
int lvl = push_text_stack(); int lvl = push_text_stack();
char *full = Malloc(YAP_FILENAME_MAX + 1); char *full;
full[0] = '\0';
/* the consult mode does not matter here, really */ /* the consult mode does not matter here, really */
if ((osno = Yap_CheckAlias(AtomLoopStream)) < 0) { if ((osno = Yap_CheckAlias(AtomLoopStream)) < 0) {
osno = 0; osno = 0;
@ -204,17 +203,21 @@ static bool consult(const char *b_file USES_REGS) {
} else { } else {
YAP_CompileClause(t); YAP_CompileClause(t);
} }
} while (true);
yap_error_descriptor_t *errd; yap_error_descriptor_t *errd;
if ((errd = if ((errd =
Yap_GetException(LOCAL_ActiveError))) { Yap_GetException(LOCAL_ActiveError))) {
fprintf(stderr, "%s:%ld:0: Error %s %s Found\n", errd->errorFile, (long int) errd->errorLine, errd->classAsText, fprintf(stderr, "%s:%ld:0: Error %s %s Found\n", errd->errorFile, (long int) errd->errorLine, errd->classAsText,
errd->errorAsText); errd->errorAsText);
} }
} while (true);
BACKUP_MACHINE_REGS(); BACKUP_MACHINE_REGS();
YAP_EndConsult(c_stream, &osno, full); YAP_EndConsult(c_stream, &osno, full);
pop_text_stack(lvl); if (!Yap_AddAlias(AtomLoopStream, osno)) {
return true; pop_text_stack(lvl);
return false;
}
pop_text_stack(lvl);
return true;
} }
/// ///

View File

@ -554,7 +554,7 @@ IF (WITH_PYTHON)
ENDIF (WITH_PYTHON) ENDIF (WITH_PYTHON)
option(WITH_R option(WITH_R
"Allow YAP->R" ON) "Use R Interface" ON)
IF (WITH_R) IF (WITH_R)
include_directories(packages/real ) include_directories(packages/real )

View File

@ -19,7 +19,7 @@ extern "C" {
#include "YapInterface.h" #include "YapInterface.h"
#include "iopreds.h" #include "iopreds.h"
X_API char *Yap_TermToBuffer(Term t, encoding_t encodingp, int flags); X_API char *Yap_TermToBuffer(Term t, int flags);
X_API void YAP_UserCPredicate(const char *, YAP_UserCPred, arity_t arity); X_API void YAP_UserCPredicate(const char *, YAP_UserCPred, arity_t arity);
X_API void YAP_UserCPredicateWithArgs(const char *, YAP_UserCPred, arity_t, X_API void YAP_UserCPredicateWithArgs(const char *, YAP_UserCPred, arity_t,
@ -30,35 +30,32 @@ X_API void YAP_UserBackCPredicate(const char *, YAP_UserCPred, YAP_UserCPred,
#if YAP_PYTHON #if YAP_PYTHON
X_API bool do_init_python(void); X_API bool do_init_python(void);
#endif #endif
} }
static void YAPCatchError() static void YAPCatchError() {
{ if (LOCAL_CommittedError != nullptr &&
if (LOCAL_CommittedError != nullptr && LOCAL_CommittedError->errorNo != YAP_NO_ERROR) {
LOCAL_CommittedError->errorNo != YAP_NO_ERROR ) { // Yap_PopTermFromDB(info->errorTerm);
// Yap_PopTermFromDB(info->errorTerm); // throw throw YAPError( );
// throw throw YAPError( ); Term es[2];
Term es[2]; es[0] = TermError;
es[0] = TermError; es[1] = MkErrorTerm(LOCAL_CommittedError);
es[1] = MkErrorTerm(LOCAL_CommittedError); Functor f = Yap_MkFunctor(Yap_LookupAtom("print_message"), 2);
Functor f = Yap_MkFunctor(Yap_LookupAtom("print_message"), 2); YAP_RunGoalOnce(Yap_MkApplTerm(f, 2, es));
YAP_RunGoalOnce(Yap_MkApplTerm(f, 2, es)); // Yap_PopTermFromDB(info->errorTerm);
// Yap_PopTermFromDB(info->errorTerm); // throw throw YAPError( SOURCE(), );
// throw throw YAPError( SOURCE(), ); } else if (LOCAL_ActiveError != nullptr &&
} else if (LOCAL_ActiveError != nullptr && LOCAL_ActiveError->errorNo != YAP_NO_ERROR) {
LOCAL_ActiveError->errorNo != YAP_NO_ERROR ) { // Yap_PopTermFromDB(info->errorTerm);
// Yap_PopTermFromDB(info->errorTerm); // throw throw YAPError( );
// throw throw YAPError( ); Term es[2];
Term es[2]; es[0] = TermError;
es[0] = TermError; es[1] = MkErrorTerm(LOCAL_ActiveError);
es[1] = MkErrorTerm(LOCAL_ActiveError); Functor f = Yap_MkFunctor(Yap_LookupAtom("print_message"), 2);
Functor f = Yap_MkFunctor(Yap_LookupAtom("print_message"), 2); YAP_RunGoalOnce(Yap_MkApplTerm(f, 2, es));
YAP_RunGoalOnce(Yap_MkApplTerm(f, 2, es)); // Yap_PopTermFromDB(info->errorTerm);
// Yap_PopTermFromDB(info->errorTerm); // throw throw YAPError( SOURCE(), );
// throw throw YAPError( SOURCE(), ); }
}
} }
YAPPredicate::YAPPredicate(Term &t, Term &tmod, CELL *&ts, const char *pname) { YAPPredicate::YAPPredicate(Term &t, Term &tmod, CELL *&ts, const char *pname) {
@ -189,14 +186,8 @@ YAPStringTerm::YAPStringTerm(char *s) { // build string
BACKUP_H(); BACKUP_H();
CACHE_REGS CACHE_REGS
seq_tv_t inp, out; Term ts = MkStringTerm(s);
inp.val.c = s; mk(ts);
inp.type = YAP_STRING_CHARS;
out.type = YAP_STRING_STRING;
if (Yap_CVT_Text(&inp, &out PASS_REGS))
mk(out.val.t);
else
t = 0L;
RECOVER_H(); RECOVER_H();
} }
@ -340,7 +331,7 @@ std::vector<Term> YAPPairTerm::listToArray() {
if (l < 0) { if (l < 0) {
throw YAPError(SOURCE(), TYPE_ERROR_LIST, (t), nullptr); throw YAPError(SOURCE(), TYPE_ERROR_LIST, (t), nullptr);
} }
std::vector<Term> o = * new std::vector<Term>(l); std::vector<Term> o = *new std::vector<Term>(l);
int i = 0; int i = 0;
Term t = gt(); Term t = gt();
while (t != TermNil) { while (t != TermNil) {
@ -489,7 +480,7 @@ const char *YAPAtom::getName(void) { return Yap_AtomToUTF8Text(a); }
void YAPQuery::openQuery() { void YAPQuery::openQuery() {
CACHE_REGS CACHE_REGS
if (ap == NULL || ap->OpcodeOfPred == UNDEF_OPCODE) { if (ap == NULL || ap->OpcodeOfPred == UNDEF_OPCODE) {
ap = rewriteUndefQuery(); ap = rewriteUndefQuery();
} }
setNext(); setNext();
@ -518,7 +509,7 @@ bool YAPEngine::call(YAPPredicate ap, YAPTerm ts[]) {
YAPCatchError(); YAPCatchError();
Yap_CloseHandles(q.CurSlot); Yap_CloseHandles(q.CurSlot);
pop_text_stack(q.lvl+1); pop_text_stack(q.lvl + 1);
RECOVER_MACHINE_REGS(); RECOVER_MACHINE_REGS();
return result; return result;
@ -528,45 +519,46 @@ bool YAPEngine::mgoal(Term t, Term tmod, bool release) {
#if YAP_PYTHON #if YAP_PYTHON
// PyThreadState *_save; // PyThreadState *_save;
//std::cerr << "mgoal " << YAPTerm(t).text() << "\n"; //std::cerr << "mgoal " << YAPTerm(t).text() << "\n";
// _save = PyEval_SaveThread(); // _save = PyEval_SaveThread();
#endif #endif
CACHE_REGS CACHE_REGS
BACKUP_MACHINE_REGS(); BACKUP_MACHINE_REGS();
Term *ts = nullptr; Term *ts = nullptr;
q.CurSlot = Yap_StartSlots(); q.CurSlot = Yap_StartSlots();
q.p = P; q.p = P;
q.cp = CP; q.cp = CP;
PredEntry *ap = nullptr; PredEntry *ap = nullptr;
if (IsStringTerm(tmod)) if (IsStringTerm(tmod))
tmod = MkAtomTerm(Yap_LookupAtom(StringOfTerm(tmod))); tmod = MkAtomTerm(Yap_LookupAtom(StringOfTerm(tmod)));
YAPPredicate *p = new YAPPredicate(t, tmod, ts, "C++"); YAPPredicate *p = new YAPPredicate(t, tmod, ts, "C++");
if (p == nullptr || (ap = p->ap) == nullptr || if (p == nullptr || (ap = p->ap) == nullptr ||
ap->OpcodeOfPred == UNDEF_OPCODE) { ap->OpcodeOfPred == UNDEF_OPCODE) {
ap = rewriteUndefEngineQuery(ap, t, tmod); ap = rewriteUndefEngineQuery(ap, t, tmod);
} }
if (IsApplTerm(t)) if (IsApplTerm(t))
ts = RepAppl(t) + 1; ts = RepAppl(t) + 1;
else if (IsPairTerm(t)) else if (IsPairTerm(t))
ts = RepPair(t); ts = RepPair(t);
/* legal ap */ /* legal ap */
arity_t arity = ap->ArityOfPE; arity_t arity = ap->ArityOfPE;
for (arity_t i = 0; i < arity; i++) { for (arity_t i = 0; i < arity; i++) {
XREGS[i + 1] = ts[i]; XREGS[i + 1] = ts[i];
} }
ts = nullptr; ts = nullptr;
bool result; bool result;
// allow Prolog style exception handling // allow Prolog style exception handling
// don't forget, on success these guys may create slots // don't forget, on success these guys may create slots
//__android_log_print(ANDROID_LOG_INFO, "YAPDroid", "exec "); //__android_log_print(ANDROID_LOG_INFO, "YAPDroid", "exec ");
result = (bool)YAP_EnterGoal(ap, nullptr, &q); result = (bool)YAP_EnterGoal(ap, nullptr, &q);
YAP_LeaveGoal(result && !release, &q); //std::cerr << "mgoal " << YAPTerm(t).text() << "\n";
// PyEval_RestoreThread(_save);
RECOVER_MACHINE_REGS(); YAP_LeaveGoal(result && !release, &q);
return result; // PyEval_RestoreThread(_save);
RECOVER_MACHINE_REGS();
return result;
} }
/** /**
* called when a query must be terminated and its state fully recovered, * called when a query must be terminated and its state fully recovered,
@ -672,31 +664,29 @@ goal = YAPApplTerm(f, nts);
} }
#endif #endif
YAPQuery::YAPQuery(YAPPredicate p, YAPTerm ts[]) : YAPPredicate(p.ap) { YAPQuery::YAPQuery(YAPPredicate p, YAPTerm ts[]) : YAPPredicate(p.ap) {
BACKUP_MACHINE_REGS(); BACKUP_MACHINE_REGS();
try { try {
arity_t arity = p.ap->ArityOfPE; arity_t arity = p.ap->ArityOfPE;
if (arity) { if (arity) {
goal = YAPApplTerm(YAPFunctor(p.ap->FunctorOfPred), ts).term(); goal = YAPApplTerm(YAPFunctor(p.ap->FunctorOfPred), ts).term();
for (arity_t i = 0; i < arity; i++) for (arity_t i = 0; i < arity; i++)
XREGS[i + 1] = ts[i].term(); XREGS[i + 1] = ts[i].term();
openQuery(); openQuery();
} else { } else {
goal = MkAtomTerm((Atom)(p.ap->FunctorOfPred)); goal = MkAtomTerm((Atom)(p.ap->FunctorOfPred));
openQuery(); openQuery();
}
names = TermNil;
} catch (...) {
} }
names = TermNil; RECOVER_MACHINE_REGS();
} catch (...) {
}
RECOVER_MACHINE_REGS();
} }
bool YAPQuery::next() { bool YAPQuery::next() {
CACHE_REGS CACHE_REGS
bool result = false; bool result = false;
//std::cerr << "next " << YAPTerm(goal).text() << "\n"; // std::cerr << "next " << YAPTerm(goal).text() << "\n";
sigjmp_buf buf, *oldp = LOCAL_RestartEnv; sigjmp_buf buf, *oldp = LOCAL_RestartEnv;
e = nullptr; e = nullptr;
@ -708,6 +698,7 @@ bool YAPQuery::next() {
__android_log_print(ANDROID_LOG_INFO, "YAPDroid", "exec "); __android_log_print(ANDROID_LOG_INFO, "YAPDroid", "exec ");
if (q_state == 0) { if (q_state == 0) {
// Yap_do_low_level_trace = 1;
result = (bool)YAP_EnterGoal(ap, nullptr, &q_h); result = (bool)YAP_EnterGoal(ap, nullptr, &q_h);
} else { } else {
LOCAL_AllowRestart = q_open; LOCAL_AllowRestart = q_open;
@ -715,19 +706,18 @@ bool YAPQuery::next() {
} }
q_state = 1; q_state = 1;
__android_log_print(ANDROID_LOG_INFO, "YAPDroid", "out %d", result); __android_log_print(ANDROID_LOG_INFO, "YAPDroid", "out %d", result);
if (!result) { if (!result) {
YAP_LeaveGoal(result, &q_h); YAP_LeaveGoal(result, &q_h);
q_open = false; q_open = false;
} }
YAPCatchError(); YAPCatchError();
RECOVER_MACHINE_REGS(); RECOVER_MACHINE_REGS();
LOCAL_RestartEnv = oldp; LOCAL_RestartEnv = oldp;
return result; return result;
} }
PredEntry *YAPQuery::rewriteUndefQuery() { PredEntry *YAPQuery::rewriteUndefQuery() {
ARG1 = goal = Yap_SaveTerm(Yap_MkApplTerm(FunctorCall ARG1 = goal = Yap_SaveTerm(Yap_MkApplTerm(FunctorCall, 1, &goal));
, 1, &goal));
return ap = PredCall; return ap = PredCall;
} }
@ -899,7 +889,7 @@ PredEntry *YAPPredicate::getPred(Term &t, CELL *&out) {
ap = RepPredProp(PredPropByAtom(AtomOfTerm(t), m)); ap = RepPredProp(PredPropByAtom(AtomOfTerm(t), m));
return ap; return ap;
} else if (IsPairTerm(t)) { } else if (IsPairTerm(t)) {
Term ts[2], *s = ( out ? out : ts ); Term ts[2], *s = (out ? out : ts);
Functor FunctorConsult = Yap_MkFunctor(Yap_LookupAtom("consult"), 1); Functor FunctorConsult = Yap_MkFunctor(Yap_LookupAtom("consult"), 1);
s[1] = t; s[1] = t;
s[0] = m; s[0] = m;
@ -914,7 +904,7 @@ PredEntry *YAPPredicate::getPred(Term &t, CELL *&out) {
} else { } else {
ap = RepPredProp(PredPropByFunc(f, m)); ap = RepPredProp(PredPropByFunc(f, m));
if (out) if (out)
memcpy( out, RepAppl(t) + 1, ap->ArityOfPE*sizeof(CELL) ); memmove(out, RepAppl(t) + 1, ap->ArityOfPE * sizeof(CELL));
else else
out = RepAppl(t) + 1; out = RepAppl(t) + 1;
} }
@ -1022,12 +1012,12 @@ std::stringstream s;
void YAPEngine::reSet() { void YAPEngine::reSet() {
/* ignore flags for now */ /* ignore flags for now */
if (B && B->cp_b && B->cp_ap != NOCODE ) if (B && B->cp_b && B->cp_ap != NOCODE)
YAP_LeaveGoal(false, &q); YAP_LeaveGoal(false, &q);
LOCAL_ActiveError->errorNo = YAP_NO_ERROR; LOCAL_ActiveError->errorNo = YAP_NO_ERROR;
if (LOCAL_CommittedError) { if (LOCAL_CommittedError) {
LOCAL_CommittedError->errorNo = YAP_NO_ERROR; LOCAL_CommittedError->errorNo = YAP_NO_ERROR;
free(LOCAL_CommittedError ); free(LOCAL_CommittedError);
LOCAL_CommittedError = NULL; LOCAL_CommittedError = NULL;
} }
} }

View File

@ -106,6 +106,7 @@ X_API extern void YAP_UserBackCutCPredicate(const char *name,
X_API extern YAP_Term YAP_ReadBuffer(const char *s, YAP_Term *tp); X_API extern YAP_Term YAP_ReadBuffer(const char *s, YAP_Term *tp);
extern YAP_Term YAP_MkcharPTerm(char *s);
} }

View File

@ -178,6 +178,7 @@ public:
// const std::string *s = new std::string("startup.yss"); // const std::string *s = new std::string("startup.yss");
Embedded = true; Embedded = true;
install = false; install = false;
Yap_InitDefaults(this, nullptr, 0, nullptr); Yap_InitDefaults(this, nullptr, 0, nullptr);
#if YAP_PYTHON #if YAP_PYTHON
Embedded = true; Embedded = true;

View File

@ -27,6 +27,13 @@
class YAPError; class YAPError;
extern "C" {
X_API extern Term YAP_MkCharPTerm( char *n);
}
/** /**
* @brief Generic Prolog Term * @brief Generic Prolog Term
*/ */
@ -39,7 +46,7 @@ class X_API YAPTerm {
friend class YAPApplTerm; friend class YAPApplTerm;
friend class YAPListTerm; friend class YAPListTerm;
protected: protected:
yhandle_t t; /// handle to term, equivalent to term_t yhandle_t t; /// handle to term, equivalent to term_t
public: public:
@ -110,7 +117,7 @@ public:
/// numbervars ( int start, bool process=false ) /// numbervars ( int start, bool process=false )
intptr_t numberVars(intptr_t start, bool skip_singletons = false); intptr_t numberVars(intptr_t start, bool skip_singletons = false);
inline Term term() { inline Term term() {
return gt(); return Deref(gt());
} /// from YAPTerm to Term (internal YAP representation) } /// from YAPTerm to Term (internal YAP representation)
YAPTerm arg(int i) { YAPTerm arg(int i) {
BACKUP_MACHINE_REGS(); BACKUP_MACHINE_REGS();
@ -216,19 +223,15 @@ public:
/// return a string with a textual representation of the term /// return a string with a textual representation of the term
virtual const char *text() { virtual const char *text() {
CACHE_REGS CACHE_REGS
encoding_t enc = LOCAL_encoding;
char *os; char *os;
BACKUP_MACHINE_REGS(); BACKUP_MACHINE_REGS();
if (!(os = Yap_TermToBuffer(Yap_GetFromSlot(t), enc, Handle_vars_f))) { if (!(os = Yap_TermToBuffer(Yap_GetFromSlot(t), Handle_vars_f))) {
RECOVER_MACHINE_REGS(); RECOVER_MACHINE_REGS();
return 0; return 0;
} }
RECOVER_MACHINE_REGS(); RECOVER_MACHINE_REGS();
size_t length = strlen(os); return os;
char *sm = (char *)malloc(length + 1);
strcpy(sm, os);
return sm;
}; };
/// return a handle to the term /// return a handle to the term
@ -315,12 +318,18 @@ public:
RECOVER_MACHINE_REGS(); RECOVER_MACHINE_REGS();
return tf; return tf;
}; };
void putArg(int i, YAPTerm t) { void putArg(int i, Term targ) {
BACKUP_MACHINE_REGS(); //BACKUP_MACHINE_REGS();
Term t0 = gt(); Term t0 = gt();
RepAppl(t0)[i] = t.term(); RepAppl(t0)[i] = Deref(targ);
RECOVER_MACHINE_REGS(); //RECOVER_MACHINE_REGS();
}; };
void putArg(int i, YAPTerm t) {
//BACKUP_MACHINE_REGS();
Term t0 = gt();
RepAppl(t0)[i] = t.term();
//RECOVER_MACHINE_REGS();
};
virtual bool isVar() { return false; } /// type check for unbound virtual bool isVar() { return false; } /// type check for unbound
virtual bool isAtom() { return false; } /// type check for atom virtual bool isAtom() { return false; } /// type check for atom
virtual bool isInteger() { return false; } /// type check for integer virtual bool isInteger() { return false; } /// type check for integer

View File

@ -288,6 +288,8 @@ INLINE_ONLY bool IsLongIntTerm(Term t) {
/* extern Functor FunctorString; */ /* extern Functor FunctorString; */
#define MkStringTerm(i) __MkStringTerm((i)PASS_REGS) #define MkStringTerm(i) __MkStringTerm((i)PASS_REGS)
INLINE_ONLY Term __MkStringTerm(const char *s USES_REGS); INLINE_ONLY Term __MkStringTerm(const char *s USES_REGS);
@ -336,6 +338,31 @@ __MkUStringTerm(const unsigned char *s USES_REGS) {
return t; return t;
} }
#define MkCharPTerm(i) __MkCharPTerm((i)PASS_REGS)
INLINE_ONLY Term __MkCharPTerm(char *s USES_REGS);
INLINE_ONLY Term __MkCharPTerm(char *s USES_REGS) {
Term t = AbsAppl(HR);
size_t sz;
if (s[0] == '\0') {
sz = sizeof(CELL);
HR[0] = (CELL)FunctorString;
HR[1] = (CELL)sz;
HR[2] = 0;
} else {
sz = ALIGN_BY_TYPE(strlen((char *)s) + 1, CELL);
HR[0] = (CELL)FunctorString;
HR[1] = (CELL)sz;
strcpy((char *)(HR + 2), (const char *)s);
}
HR[2 + sz] = EndSpecials;
HR += 3 + sz;
return t;
}
INLINE_ONLY const unsigned char *UStringOfTerm(Term t); INLINE_ONLY const unsigned char *UStringOfTerm(Term t);
INLINE_ONLY const unsigned char *UStringOfTerm(Term t) { INLINE_ONLY const unsigned char *UStringOfTerm(Term t) {

View File

@ -144,12 +144,12 @@ static Term synerr(Term inp) {
return inp; return inp;
if (IsAtomTerm(inp)) { if (IsAtomTerm(inp)) {
Yap_Error(DOMAIN_ERROR_OUT_OF_RANGE, inp, Yap_ThrowError(DOMAIN_ERROR_OUT_OF_RANGE, inp,
"set_prolog_flag in {dec10,error,fail,quiet}"); "set_prolog_flag in {dec10,error,fail,quiet}");
return TermZERO; return TermZERO;
} }
Yap_Error(TYPE_ERROR_ATOM, inp, Yap_ThrowError(TYPE_ERROR_ATOM, inp,
"set_prolog_flag in {dec10,error,fail,quiet}"); "syntax_error flag must be atom");
return TermZERO; return TermZERO;
} }

View File

@ -56,29 +56,26 @@ opportunity. Initial value is 10,000. May be changed. A value of 0
~~~ ~~~
*/ */
YAP_FLAG(ANSWER_FORMAT_FLAG, "answer_format", true, isatom, "~p", NULL), YAP_FLAG(ANSWER_FORMAT_FLAG, "answer_format", true, isatom, "~p", NULL),
/**< how to present answers, default is `~p`. */ /**< how to present answers, default is `~p`. */
#if __ANDROID__ #if __ANDROID__
YAP_FLAG(ANDROID_FLAG, "android", false, booleanFlag, "true", NULL), /**< YAP_FLAG(ANDROID_FLAG, "android", false, booleanFlag, "true", NULL), /**<
read-only boolean, a machine running an Google's Android version of the Linux Operating System */ read-only boolean, a machine running an Google's Android version of the
Linux Operating System */
#endif #endif
#if __APPLE__ #if __APPLE__
YAP_FLAG(APPLE_FLAG, "apple", false, booleanFlag, "true", NULL), /**< YAP_FLAG(APPLE_FLAG, "apple", false, booleanFlag, "true", NULL), /**<
read-only boolean, a machine running an Apple Operating System */ read-only boolean, a machine running an Apple Operating System */
#endif #endif
YAP_FLAG(ARCH_FLAG, "arch", false, isatom, YAP_ARCH, NULL), /**< YAP_FLAG(ARCH_FLAG, "arch", false, isatom, YAP_ARCH, NULL), /**<
read-only atom, it describes the ISA used in this version of YAP. read-only atom, it describes the ISA used in this version of YAP.
Available from YAP_AEH. Available from YAP_ARCH.
*/ */
YAP_FLAG(ARGV_FLAG, "argv", false, argv, "@boot", NULL), YAP_FLAG(ARGV_FLAG, "argv", false, argv, "@boot", NULL),
YAP_FLAG(ARITHMETIC_EXCEPTIONS_FLAG, "arithmetic_exceptions", true, YAP_FLAG(ARITHMETIC_EXCEPTIONS_FLAG, "arithmetic_exceptions", true,
booleanFlag, "true", NULL), booleanFlag, "true", NULL),
/**< `arithmetic_exceptions` /**<
Read-write flag telling whether arithmetic exceptions generate Read-write flag telling whether arithmetic exceptions generate
Prolog exceptions. If enabled: Prolog exceptions. If enabled:
@ -98,8 +95,8 @@ opportunity. Initial value is 10,000. May be changed. A value of 0
It is `true` by default, but it is disabled by packages like CLP(BN) and It is `true` by default, but it is disabled by packages like CLP(BN) and
ProbLog. ProbLog.
*/ */
YAP_FLAG(BACK_QUOTES_FLAG, "back_quotes", true, isatom, "true", NULL), YAP_FLAG(BACK_QUOTES_FLAG, "back_quotes", true, isatom, "true", bqs),
/**> /**<
If _Value_ is unbound, tell whether a back quoted list of characters If _Value_ is unbound, tell whether a back quoted list of characters
token is converted to a list of atoms, `chars`, to a list of integers, token is converted to a list of atoms, `chars`, to a list of integers,
`codes`, or to a single atom, `atom`. If _Value_ is bound, set to `codes`, or to a single atom, `atom`. If _Value_ is bound, set to
@ -132,20 +129,22 @@ opportunity. Initial value is 10,000. May be changed. A value of 0
Writable flag telling whether a character escapes are enabled, Writable flag telling whether a character escapes are enabled,
`true`, or disabled, `false`. The default value for this flag is `true`, or disabled, `false`. The default value for this flag is
`true`. */ `true`. */
YAP_FLAG(COLON_SETS_CALLING_CONTEXT_FLAG, "colon_sets_calling_context", true, booleanFlag, "true", NULL), YAP_FLAG(COLON_SETS_CALLING_CONTEXT_FLAG, "colon_sets_calling_context",
true, booleanFlag, "true", NULL),
/**< `compiled_at ` /**< `compiled_at `
Read-only flag that gives the time when the main YAP binary was compiled. It Read-only flag that gives the time when the main YAP binary was compiled.
is obtained staight from the __TIME__ macro, as defined in the C99. It is obtained staight from the __TIME__ macro, as defined in the C99.
*/ YAP_FLAG(COMPILED_AT_FLAG, "compiled_at", false, isatom, YAP_COMPILED_AT, */
YAP_FLAG(COMPILED_AT_FLAG, "compiled_at", false, isatom, YAP_COMPILED_AT,
NULL), NULL),
YAP_FLAG(DEBUG_FLAG, "debug", true, booleanFlag, "false", NULL), YAP_FLAG(DEBUG_FLAG, "debug", true, booleanFlag, "false", NULL),
/**< /**<
If _Value_ is unbound, tell whether debugging is `true` or If _Value_ is unbound, tell whether debugging is `true` or
`false`. If _Value_ is bound to `true` enable debugging, and if `false`. If _Value_ is bound to `true` enable debugging, and if
it is bound to `false` disable debugging. it is bound to `false` disable debugging.
*/ */
YAP_FLAG(DEBUG_INFO_FLAG, "debug_info", true, booleanFlag, "true", NULL), YAP_FLAG(DEBUG_INFO_FLAG, "debug_info", true, booleanFlag, "true", NULL),
YAP_FLAG(DEBUG_ON_ERROR_FLAG, "debug_on_error", true, booleanFlag, "true", YAP_FLAG(DEBUG_ON_ERROR_FLAG, "debug_on_error", true, booleanFlag, "true",
NULL), NULL),
@ -159,6 +158,15 @@ opportunity. Initial value is 10,000. May be changed. A value of 0
NULL), NULL),
YAP_FLAG(DEBUGGER_SHOW_CONTEXT_FLAG, "debugger_show_context", true, YAP_FLAG(DEBUGGER_SHOW_CONTEXT_FLAG, "debugger_show_context", true,
booleanFlag, "false", NULL), booleanFlag, "false", NULL),
YAP_FLAG(DEFAULT_PARENT_MODULE_FLAG, "default_parent_module", true, isatom,
"user", NULL),
/**<
* A module to be inherited by all other modules. Default is user that
* reexports prolog.
*
* Set it to `prolog` for SICStus Prolog like resolution, to `user` for
* SWI-like.
*/
YAP_FLAG(DIALECT_FLAG, "dialect", false, ro, "yap", NULL), YAP_FLAG(DIALECT_FLAG, "dialect", false, ro, "yap", NULL),
/**< /**<
@ -180,7 +188,7 @@ opportunity. Initial value is 10,000. May be changed. A value of 0
booleanFlag, "false", NULL), booleanFlag, "false", NULL),
/**< /**<
If `off` (default) consider the character `$` a control character, if If `off` (default) consider the character `$` a control character, if
`on` consider `$` a lower case character. vxu `on` consider `$` a lower case character.
*/ */
YAP_FLAG(DOUBLE_QUOTES_FLAG, "double_quotes", true, isatom, "codes", dqs), YAP_FLAG(DOUBLE_QUOTES_FLAG, "double_quotes", true, isatom, "codes", dqs),
/**< iso /**< iso
@ -269,11 +277,11 @@ opportunity. Initial value is 10,000. May be changed. A value of 0
*/ */
YAP_FLAG(INDEX_SUB_TERM_SEARCH_DEPTH_FLAG, "index_sub_term_search_depth", YAP_FLAG(INDEX_SUB_TERM_SEARCH_DEPTH_FLAG, "index_sub_term_search_depth",
true, nat, "0", NULL), true, nat, "0", NULL),
/**< `Index_sub_term_search_depth ` /**< `Index_sub_term_search_depth `
Maximum bound on searching sub-terms for indexing, if `0` (default) no Maximum bound on searching sub-terms for indexing, if `0` (default) no
bound. bound.
*/ */
YAP_FLAG(INFORMATIONAL_MESSAGES_FLAG, "informational_messages", true, YAP_FLAG(INFORMATIONAL_MESSAGES_FLAG, "informational_messages", true,
isatom, "normal", NULL), isatom, "normal", NULL),
/**< `informational_messages ` /**< `informational_messages `
@ -291,6 +299,8 @@ opportunity. Initial value is 10,000. May be changed. A value of 0
value `toward_zero` for the current version of YAP. value `toward_zero` for the current version of YAP.
*/ */
YAP_FLAG(ISO_FLAG, "iso", true, booleanFlag, "false", NULL), YAP_FLAG(ISO_FLAG, "iso", true, booleanFlag, "false", NULL),
YAP_FLAG(JUPYTER_FLAG, "jupyter", false, booleanFlag, "true", NULL), /**<
read-only boolean, a machine running Jupyter */
YAP_FLAG(LANGUAGE_FLAG, "language", true, isatom, "yap", NULL), YAP_FLAG(LANGUAGE_FLAG, "language", true, isatom, "yap", NULL),
/**< `language ` /**< `language `
@ -316,7 +326,7 @@ opportunity. Initial value is 10,000. May be changed. A value of 0
Read-only flag telling the maximum arity of a functor. Takes the value Read-only flag telling the maximum arity of a functor. Takes the value
`unbounded` for the current version of YAP. `unbounded` for the current version of YAP.
*/ */
YAP_FLAG(MAX_TAGGED_INTEGER_FLAG, "max_tagged_integer", false, at2n, YAP_FLAG(MAX_TAGGED_INTEGER_FLAG, "max_tagged_integer", false, at2n,
"INT_MAX", NULL), "INT_MAX", NULL),
YAP_FLAG(MAX_THREADS_FLAG, "max_threads", false, at2n, "MAX_THREADS", NULL), YAP_FLAG(MAX_THREADS_FLAG, "max_threads", false, at2n, "MAX_THREADS", NULL),
YAP_FLAG(MAX_WORKERS_FLAG, "max_workers", false, at2n, "MAX_WORKERS", NULL), YAP_FLAG(MAX_WORKERS_FLAG, "max_workers", false, at2n, "MAX_WORKERS", NULL),
@ -342,15 +352,14 @@ opportunity. Initial value is 10,000. May be changed. A value of 0
providing access to shared libraries (`.so` files) or to dynamic link providing access to shared libraries (`.so` files) or to dynamic link
libraries (`.DLL` files). libraries (`.DLL` files).
*/ */
/**< `module_independent_operators ` /**< `module_independent_operators `
If `true` an operator declaration will be valid for every module in the If `true` an operator declaration will be valid for every module in the
program. This is for compatibility with old software that program. This is for compatibility with old software that
might expect module-independent operators. might expect module-independent operators.
*/ */
YAP_FLAG(MODULE_INDEPENDENT_OPERATORS_FLAG, YAP_FLAG(MODULE_INDEPENDENT_OPERATORS_FLAG, "module_independent_operators",
"module_independent_operators", true, booleanFlag, true, booleanFlag, "false", NULL),
"false", NULL),
YAP_FLAG(OPTIMISE_FLAG, "optimise", true, booleanFlag, "false", NULL), YAP_FLAG(OPTIMISE_FLAG, "optimise", true, booleanFlag, "false", NULL),
YAP_FLAG(OS_ARGV_FLAG, "os_argv", false, os_argv, "@boot", NULL), YAP_FLAG(OS_ARGV_FLAG, "os_argv", false, os_argv, "@boot", NULL),
@ -366,14 +375,14 @@ opportunity. Initial value is 10,000. May be changed. A value of 0
*/ */
YAP_FLAG(PROMPT_ALTERNATIVES_ON_FLAG, "prompt_alternatives_on", true, YAP_FLAG(PROMPT_ALTERNATIVES_ON_FLAG, "prompt_alternatives_on", true,
isatom, "determinism", NULL), isatom, "determinism", NULL),
/**< `prompt_alternatives_on(atom, /**< `prompt_alternatives_on(atom,
changeable) ` changeable) `
SWI-Compatible option, determines prompting for alternatives in the Prolog SWI-Compatible option, determines prompting for alternatives in the Prolog
toplevel. Default is <tt>groundness</tt>, YAP prompts for alternatives if toplevel. Default is <tt>groundness</tt>, YAP prompts for alternatives if
and only if the query contains variables. The alternative, default in and only if the query contains variables. The alternative, default in
SWI-Prolog is <tt>determinism</tt> which implies the system prompts for SWI-Prolog is <tt>determinism</tt> which implies the system prompts for
alternatives if the goal succeeded while leaving choicepoints. */ alternatives if the goal succeeded while leaving choicepoints. */
YAP_FLAG(QUASI_QUOTATIONS_FLAG, "quasi_quotations", true, booleanFlag, YAP_FLAG(QUASI_QUOTATIONS_FLAG, "quasi_quotations", true, booleanFlag,
"true", NULL), "true", NULL),
YAP_FLAG(READLINE_FLAG, "readline", true, booleanFlag, "false", YAP_FLAG(READLINE_FLAG, "readline", true, booleanFlag, "false",
@ -383,6 +392,15 @@ opportunity. Initial value is 10,000. May be changed. A value of 0
enable the use of the readline library for console interactions, true by enable the use of the readline library for console interactions, true by
default if readline was found. */ default if readline was found. */
YAP_FLAG(REDEFINE_WARNINGS_FLAG, "redefine_warnings", true, booleanFlag,
"true", NULL), /**<
If _Value_ is unbound, tell whether warnings for procedures defined
in several different files are `on` or
`off`. If _Value_ is bound to `on` enable these warnings,
and if it is bound to `off` disable them. The default for YAP is
`off`, unless we are in `sicstus` or `iso` mode.
*/
YAP_FLAG(REPORT_ERROR_FLAG, "report_error", true, booleanFlag, "true", YAP_FLAG(REPORT_ERROR_FLAG, "report_error", true, booleanFlag, "true",
NULL), NULL),
YAP_FLAG(RESOURCE_DATABASE_FLAG, "resource_database", false, isatom, YAP_FLAG(RESOURCE_DATABASE_FLAG, "resource_database", false, isatom,
@ -418,6 +436,15 @@ opportunity. Initial value is 10,000. May be changed. A value of 0
/**< `single_quoted text is usuallly interpreted as atoms. This flagTerm /**< `single_quoted text is usuallly interpreted as atoms. This flagTerm
allows other inerpretations such as strings_contains_strings */ allows other inerpretations such as strings_contains_strings */
YAP_FLAG(SINGLE_VAR_WARNINGS_FLAG, "single_var_warnings", true, booleanFlag,
"true", NULL), /**<
If `true` (default `true`) YAP checks for singleton
variables when loading files. A singleton variable is a
variable that appears ony once in a clause. The name
must start with a capital letter, variables whose name
starts with underscore are never considered singleton.
*/
YAP_FLAG(SIGNALS_FLAG, "signals", true, booleanFlag, "true", NULL), YAP_FLAG(SIGNALS_FLAG, "signals", true, booleanFlag, "true", NULL),
/**< `signals` /**< `signals`
@ -476,10 +503,7 @@ opportunity. Initial value is 10,000. May be changed. A value of 0
*/ */
YAP_FLAG(THREADS_FLAG, "threads", false, ro, "MAX_THREADS", NULL), YAP_FLAG(THREADS_FLAG, "threads", false, ro, "MAX_THREADS", NULL),
YAP_FLAG(TIMEZONE_FLAG, "timezone", false, ro, "18000", NULL), YAP_FLAG(TIMEZONE_FLAG, "timezone", false, ro, "18000", NULL),
YAP_FLAG(TOPLEVEL_PRINT_ANON_FLAG, "toplevel_print_anon", true, booleanFlag, YAP_FLAG(TOPLEVEL_HOOK_FLAG, "toplevel_hook", true, booleanFlag, "true",
"true", NULL),
YAP_FLAG(TOPLEVEL_HOOK_FLAG, "toplevel_hook", true,
booleanFlag, "true",
NULL), NULL),
/**< `toplevel_hook ` /**< `toplevel_hook `
@ -489,6 +513,8 @@ opportunity. Initial value is 10,000. May be changed. A value of 0
backtracked into. backtracked into.
*/ */
YAP_FLAG(TOPLEVEL_PRINT_ANON_FLAG, "toplevel_print_anon", true, booleanFlag,
"true", NULL),
YAP_FLAG(TOPLEVEL_PRINT_OPTIONS_FLAG, "toplevel_print_options", true, YAP_FLAG(TOPLEVEL_PRINT_OPTIONS_FLAG, "toplevel_print_options", true,
list_option, "[quoted(true),numbervars(true),portrayed(true)]", list_option, "[quoted(true),numbervars(true),portrayed(true)]",
NULL), NULL),
@ -521,9 +547,9 @@ opportunity. Initial value is 10,000. May be changed. A value of 0
are `silent`, `warning` and `error`. The first two create the flag are `silent`, `warning` and `error`. The first two create the flag
on-the-fly, with `warning` printing a message. The value `error` is on-the-fly, with `warning` printing a message. The value `error` is
consistent with ISO: it raises an existence error and does not create the consistent with ISO: it raises an existence error and does not create the
flag. See also `create_prolog_flag/3`. The default is`error`, and developers flag. See also `create_prolog_flag/3`. The default is`error`, and
are encouraged to use `create_prolog_flag/3` to create flags for their developers are encouraged to use `create_prolog_flag/3` to create flags for
library. their library.
*/ */
YAP_FLAG(UNKNOWN_FLAG, "unknown", true, isatom, "error", Yap_unknown), YAP_FLAG(UNKNOWN_FLAG, "unknown", true, isatom, "error", Yap_unknown),
/**< `unknown is iso` /**< `unknown is iso`

View File

@ -1,21 +1,19 @@
/************************************************************************* /*************************************************************************
* * * *
* YAP Prolog * * YAP Prolog *
* * * *
* Yap Prolog was developed at NCCUP - Universidade do Porto * * Yap Prolog was developed at NCCUP - Universidade do Porto *
* * * *
* Copyright L.Damas, V.S.Costa and Universidade do Porto 2015- * * Copyright L.Damas, V.S.Costa and Universidade do Porto 2015- *
* * * *
************************************************************************** **************************************************************************
* * * *
* File: YapLFlagInfo.h * * File: YapLFlagInfo.h * Last rev:
* Last rev: * ** mods: * comments: local flag enumeration. *
* mods: * * *
* comments: local flag enumeration. * *************************************************************************/
* *
*************************************************************************/
/** @file YapLFlagInfo.h /** @file YapLFlagInfo.h
@ -30,74 +28,75 @@
START_LOCAL_FLAGS START_LOCAL_FLAGS
/** + `autoload`: set the system to look for undefined procedures */ /** + `autoload`: set the system to look for undefined procedures */
YAP_FLAG( AUTOLOAD_FLAG, "autoload", true, booleanFlag, "false" , NULL ), YAP_FLAG(AUTOLOAD_FLAG, "autoload", true, booleanFlag, "false", NULL),
/** + `read-only flag, that tells if Prolog is in an inner top-level */ /** + `read-only flag, that tells if Prolog is in an inner top-level */
YAP_FLAG( BREAK_LEVEL_FLAG, "break_level", true, nat, "0" , NULL ), YAP_FLAG(BREAK_LEVEL_FLAG, "break_level", true, nat, "0", NULL),
YAP_FLAG( CALL_COUNTING_FLAG, "call_counting", true, booleanFlag, "true" , NULL ), /** + `call_counting` YAP_FLAG(CALL_COUNTING_FLAG, "call_counting", true, booleanFlag, "true",
NULL), /** + `call_counting`
Predicates compiled with this flag set maintain a counter on the numbers of proceduree calls and of retries. These counters are decreasing counters, and they can be used as timers. Three counters are available: Predicates compiled with this flag set maintain a counter
on the numbers of proceduree calls and of retries. These counters
are decreasing counters, and they can be used as timers. Three
counters are available:
calls: number of predicate calls since execution started or since system was reset; calls: number of predicate calls since execution started or
retries: number of retries for predicates called since execution started or since counters were reset; since system was reset; retries: number of retries for predicates
calls_and_retries: count both on predicate calls and retries. called since execution started or since counters were reset;
These counters can be used to find out how many calls a certain goal takes to execute. They can also be force the computatiom yp calls_and_retries: count both on predicate calls and
stopping. retries. These counters can be used to find out how many calls a
certain goal takes to execute. They can also be force the
computatiom yp stopping.
If `on` `fileerrors` is `on`, if `off` (default) If `on` `fileerrors` is `on`, if `off` (default)
`fileerrors` is disabled. `fileerrors` is disabled.
*/ */
YAP_FLAG( ENCODING_FLAG, "encoding", true, isatom, "utf-8" , getenc ), YAP_FLAG(ENCODING_FLAG, "encoding", true, isatom, "utf-8", getenc),
YAP_FLAG( FILEERRORS_FLAG, "fileerrors", true, booleanFlag, "true" , NULL ), /** + `fileerrors` YAP_FLAG(FILEERRORS_FLAG, "fileerrors", true, booleanFlag, "true",
NULL), /** + `fileerrors`
If `on` `fileerrors` is `on`, if `off` (default) If `on` `fileerrors` is `on`, if `off` (default)
`fileerrors` is disabled. `fileerrors` is disabled.
*/ */
YAP_FLAG( LANGUAGE_MODE_FLAG, "language_mode", true, isatom, "yap" , NULL ), /** + `language_mode` YAP_FLAG(LANGUAGE_MODE_FLAG, "language_mode", true, isatom, "yap",
NULL), /** + `language_mode`
wweter native mode or trying to emulate a different Prolog. wweter native mode or trying to emulate a different Prolog.
*/ */
YAP_FLAG( REDEFINE_WARNINGS_FLAG, "redefine_warnings", true, booleanFlag, "true" , NULL ), /** + `redefine_warnings ` YAP_FLAG(STACK_DUMP_ON_ERROR_FLAG, "stack_dump_on_error", true, booleanFlag,
"true", NULL), /** + `stack_dump_on_error `
If _Value_ is unbound, tell whether warnings for procedures defined If `true` show a stack dump when YAP finds an error. The default is
in several different files are `on` or
`off`. If _Value_ is bound to `on` enable these warnings,
and if it is bound to `off` disable them. The default for YAP is
`off`, unless we are in `sicstus` or `iso` mode.
*/
YAP_FLAG( SINGLE_VAR_WARNINGS_FLAG, "single_var_warnings", true, booleanFlag, "true" , NULL ), /** + `single_var_warnings`
If `true` (default `true`) YAP checks for singleton variables when loading files. A singleton variable is a variable that appears ony once in a clause. The name must start with a capital letter, variables whose name starts with underscore are never considered singleton.
*/
YAP_FLAG( STACK_DUMP_ON_ERROR_FLAG, "stack_dump_on_error", true, booleanFlag, "false" , NULL ), /** + `stack_dump_on_error `
If `true` show a stack dump when YAP finds an error. The default is
`off`. `off`.
*/ */
YAP_FLAG( STREAM_TYPE_CHECK_FLAG, "stream_type_check", true, isatom, "loose" , NULL ), YAP_FLAG(STREAM_TYPE_CHECK_FLAG, "stream_type_check", true, isatom, "loose",
YAP_FLAG( SYNTAX_ERRORS_FLAG, "syntax_errors", true, synerr, "error" , NULL ), /** + `syntax_errors` NULL),
YAP_FLAG(SYNTAX_ERRORS_FLAG, "syntax_errors", true, synerr, "error",
NULL), /** + `syntax_errors`
Control action to be taken after syntax errors while executing read/1, Control action to be taken after syntax errors while executing read/1,
`read/2`, or `read_term/3`: `read/2`, or `read_term/3`:
+ `dec10` + `dec10`
Report the syntax error and retry reading the term. Report the syntax error and retry reading the term.
+ `fail` + `fail`
Report the syntax error and fail. Report the syntax error and fail.
+ `error` + `error`
Report the syntax error and generate an error (default). Report the syntax error and generate an error (default).
+ `quiet` + `quiet`
Just fail Just fail
*/ */
YAP_FLAG( TYPEIN_MODULE_FLAG, "typein_module", true, isatom, "user" , typein ), /** + `typein_module ` YAP_FLAG(TYPEIN_MODULE_FLAG, "typein_module", true, isatom, "user",
typein), /** + `typein_module `
If bound, set the current working or type-in module to the argument, If bound, set the current working or type-in module to the argument,
which must be an atom. If unbound, unify the argument with the current which must be an atom. If unbound, unify the argument with the current
working module. working module.
*/ */
YAP_FLAG( USER_ERROR_FLAG, "user_error", true, stream, "user_error" , set_error_stream ), /** + `user_error1` YAP_FLAG(USER_ERROR_FLAG, "user_error", true, stream, "user_error",
set_error_stream), /** + `user_error1`
If the second argument is bound to a stream, set user_error to If the second argument is bound to a stream, set user_error to
this stream. If the second argument is unbound, unify the argument with this stream. If the second argument is unbound, unify the argument with
the current user_error stream. the current user_error stream.
By default, the user_error stream is set to a stream By default, the user_error stream is set to a stream
@ -105,30 +104,32 @@ corresponding to the Unix `stderr` stream.
The next example shows how to use this flag: The next example shows how to use this flag:
~~~{.prolog} ~~~{.prolog}
?- open( '/dev/null', append, Error, ?- open( '/dev/null', append, Error,
[alias(mauri_tripa)] ). [alias(mauri_tripa)] ).
Error = '$stream'(3) ? ; Error = '$stream'(3) ? ;
no no
?- set_prolog_flag(user_error, mauri_tripa). ?- set_prolog_flag(user_error, mauri_tripa).
close(mauri_tripa). close(mauri_tripa).
yes yes
?- ?-
~~~ ~~~
We execute three commands. First, we open a stream in write mode and We execute three commands. First, we open a stream in write mode and
give it an alias, in this case `mauri_tripa`. Next, we set give it an alias, in this case `mauri_tripa`. Next, we set
user_error to the stream via the alias. Note that after we did so user_error to the stream via the alias. Note that after we did so
prompts from the system were redirected to the stream prompts from the system were redirected to the stream
`mauri_tripa`. Last, we close the stream. At this point, YAP `mauri_tripa`. Last, we close the stream. At this point, YAP
automatically redirects the user_error alias to the original automatically redirects the user_error alias to the original
`stderr`. `stderr`.
*/ */
YAP_FLAG( USER_INPUT_FLAG, "user_input", true, stream, "user_input" , set_input_stream ), YAP_FLAG(USER_INPUT_FLAG, "user_input", true, stream, "user_input",
YAP_FLAG( USER_OUTPUT_FLAG, "user_output", true, stream, "user_output" , set_output_stream ), set_input_stream),
YAP_FLAG(USER_OUTPUT_FLAG, "user_output", true, stream, "user_output",
set_output_stream),
END_LOCAL_FLAGS END_LOCAL_FLAGS
/// @} /// @}

View File

@ -543,6 +543,22 @@ static inline Term Yap_AtomToListOfCodes(Term t0 USES_REGS) {
return out.val.t; return out.val.t;
} }
static inline Term Yap_AtomSWIToListOfCodes(Term t0 USES_REGS) {
seq_tv_t inp, out;
inp.val.t = t0;
inp.type = YAP_STRING_ATOM | YAP_STRING_STRING | YAP_STRING_INT |
YAP_STRING_FLOAT | YAP_STRING_BIG | YAP_STRING_ATOMS_CODES |YAP_STRING_ATOMS_CODES |YAP_STRING_ATOMS_CODES |
YAP_STRING_TERM;
out.val.uc = NULL;
out.type = YAP_STRING_CODES;
if (!Yap_CVT_Text(&inp, &out PASS_REGS))
return 0L;
return out.val.t;
}
static inline Term Yap_AtomToNumber(Term t0 USES_REGS) { static inline Term Yap_AtomToNumber(Term t0 USES_REGS) {
seq_tv_t inp, out; seq_tv_t inp, out;
inp.val.t = t0; inp.val.t = t0;

View File

@ -35,6 +35,7 @@ extern int Yap_HasOp(Atom);
extern struct operator_entry * extern struct operator_entry *
Yap_GetOpPropForAModuleHavingALock(struct AtomEntryStruct *, Term); Yap_GetOpPropForAModuleHavingALock(struct AtomEntryStruct *, Term);
extern Atom Yap_LookupAtom(const char *); extern Atom Yap_LookupAtom(const char *);
extern Atom Yap_AtomInUse(const char *atom);
extern Atom Yap_ULookupAtom(const unsigned char *); extern Atom Yap_ULookupAtom(const unsigned char *);
extern Atom Yap_LookupAtomWithLength(const char *, size_t); extern Atom Yap_LookupAtomWithLength(const char *, size_t);
extern Atom Yap_FullLookupAtom(const char *); extern Atom Yap_FullLookupAtom(const char *);
@ -309,7 +310,6 @@ extern void Yap_DebugPlWriteln(Term t);
extern void Yap_DebugErrorPutc(int n); extern void Yap_DebugErrorPutc(int n);
extern void Yap_DebugErrorPuts(const char *s); extern void Yap_DebugErrorPuts(const char *s);
extern void Yap_DebugWriteIndicator(struct pred_entry *ap); extern void Yap_DebugWriteIndicator(struct pred_entry *ap);
extern void Yap_PlWriteToStream(Term, int, int);
extern void Yap_CloseReadline(void); extern void Yap_CloseReadline(void);
/* depth_lim.c */ /* depth_lim.c */
extern bool Yap_InitReadline(Term t); extern bool Yap_InitReadline(Term t);

View File

@ -1298,7 +1298,7 @@ INLINE_ONLY bool IsFlagProperty(PropFlags flags) {
/* Proto types */ /* Proto types */
extern char *Yap_TermToBuffer(Term t, encoding_t encoding, int flags); extern char *Yap_TermToBuffer(Term t, int flags);
extern Term Yap_BufferToTerm(const char *s, Term opts); extern Term Yap_BufferToTerm(const char *s, Term opts);

View File

@ -181,14 +181,14 @@ INLINE_ONLY void init_absmi_regs(REGSTORE *absmi_regs);
INLINE_ONLY void init_absmi_regs(REGSTORE *absmi_regs) { INLINE_ONLY void init_absmi_regs(REGSTORE *absmi_regs) {
CACHE_REGS CACHE_REGS
memcpy(absmi_regs, Yap_regp, sizeof(REGSTORE)); memmove(absmi_regs, Yap_regp, sizeof(REGSTORE));
} }
INLINE_ONLY void restore_absmi_regs(REGSTORE *old_regs); INLINE_ONLY void restore_absmi_regs(REGSTORE *old_regs);
INLINE_ONLY void restore_absmi_regs(REGSTORE *old_regs) { INLINE_ONLY void restore_absmi_regs(REGSTORE *old_regs) {
CACHE_REGS CACHE_REGS
memcpy(old_regs, Yap_regp, sizeof(REGSTORE)); memmove(old_regs, Yap_regp, sizeof(REGSTORE));
#ifdef THREADS #ifdef THREADS
pthread_setspecific(Yap_yaamregs_key, (void *)old_regs); pthread_setspecific(Yap_yaamregs_key, (void *)old_regs);
LOCAL_ThreadHandle.current_yaam_regs = old_regs; LOCAL_ThreadHandle.current_yaam_regs = old_regs;

View File

@ -95,7 +95,7 @@ typedef enum{
t_createLowerExpectIntrinsicPass, //Removes llvm.expect intrinsics and creates "block_weights" metadata t_createLowerExpectIntrinsicPass, //Removes llvm.expect intrinsics and creates "block_weights" metadata
t_createLowerInvokePass, //Converts invoke and unwind instructions to use sjlj exception handling mechanisms t_createLowerInvokePass, //Converts invoke and unwind instructions to use sjlj exception handling mechanisms
t_createLowerSwitchPass, //Converts SwitchInst instructions into a sequence of chained binary branch instructions t_createLowerSwitchPass, //Converts SwitchInst instructions into a sequence of chained binary branch instructions
t_createMemCpyOptPass, //Performs optimizations related to eliminating memcpy calls and/or combining multiple stores into memset's t_createMemCpyOptPass, //Performs optimizations related to eliminating memmove calls and/or combining multiple stores into memset's
t_createMergeFunctionsPass, //Discovers identical functions and collapses them t_createMergeFunctionsPass, //Discovers identical functions and collapses them
t_createObjCARCAPElimPass, //ObjC ARC autorelease pool elimination t_createObjCARCAPElimPass, //ObjC ARC autorelease pool elimination
t_createObjCARCContractPass, //Late ObjC ARC cleanups t_createObjCARCContractPass, //Late ObjC ARC cleanups

View File

@ -24,7 +24,7 @@
/* consulting files */ /* consulting files */
typedef union CONSULT_OBJ { typedef union CONSULT_OBJ {
const unsigned char *f_name; Atom f_name;
int mode; int mode;
Prop p; Prop p;
UInt c; UInt c;

View File

@ -95,7 +95,7 @@ typedef struct {
#define utarray_push_back(a,p) do { \ #define utarray_push_back(a,p) do { \
utarray_reserve(a,1); \ utarray_reserve(a,1); \
if ((a)->icd.copy) { (a)->icd.copy( _utarray_eltptr(a,(a)->i++), p); } \ if ((a)->icd.copy) { (a)->icd.copy( _utarray_eltptr(a,(a)->i++), p); } \
else { memcpy(_utarray_eltptr(a,(a)->i++), p, (a)->icd.sz); }; \ else { memmove(_utarray_eltptr(a,(a)->i++), p, (a)->icd.sz); }; \
} while(0) } while(0)
#define utarray_pop_back(a) do { \ #define utarray_pop_back(a) do { \
@ -123,7 +123,7 @@ typedef struct {
((a)->i - (j))*((a)->icd.sz)); \ ((a)->i - (j))*((a)->icd.sz)); \
} \ } \
if ((a)->icd.copy) { (a)->icd.copy( _utarray_eltptr(a,j), p); } \ if ((a)->icd.copy) { (a)->icd.copy( _utarray_eltptr(a,j), p); } \
else { memcpy(_utarray_eltptr(a,j), p, (a)->icd.sz); }; \ else { memmove(_utarray_eltptr(a,j), p, (a)->icd.sz); }; \
(a)->i++; \ (a)->i++; \
} while(0) } while(0)
@ -142,7 +142,7 @@ typedef struct {
(a)->icd.copy(_utarray_eltptr(a,j+_ut_i), _utarray_eltptr(w,_ut_i)); \ (a)->icd.copy(_utarray_eltptr(a,j+_ut_i), _utarray_eltptr(w,_ut_i)); \
} \ } \
} else { \ } else { \
memcpy(_utarray_eltptr(a,j), _utarray_eltptr(w,0), \ memmove(_utarray_eltptr(a,j), _utarray_eltptr(w,0), \
utarray_len(w)*((a)->icd.sz)); \ utarray_len(w)*((a)->icd.sz)); \
} \ } \
(a)->i += utarray_len(w); \ (a)->i += utarray_len(w); \

View File

@ -95,7 +95,7 @@ typedef enum{
t_createLowerExpectIntrinsicPass, //Removes llvm.expect intrinsics and creates "block_weights" metadata t_createLowerExpectIntrinsicPass, //Removes llvm.expect intrinsics and creates "block_weights" metadata
t_createLowerInvokePass, //Converts invoke and unwind instructions to use sjlj exception handling mechanisms t_createLowerInvokePass, //Converts invoke and unwind instructions to use sjlj exception handling mechanisms
t_createLowerSwitchPass, //Converts SwitchInst instructions into a sequence of chained binary branch instructions t_createLowerSwitchPass, //Converts SwitchInst instructions into a sequence of chained binary branch instructions
t_createMemCpyOptPass, //Performs optimizations related to eliminating memcpy calls and/or combining multiple stores into memset's t_createMemCpyOptPass, //Performs optimizations related to eliminating memmove calls and/or combining multiple stores into memset's
t_createMergeFunctionsPass, //Discovers identical functions and collapses them t_createMergeFunctionsPass, //Discovers identical functions and collapses them
t_createObjCARCAPElimPass, //ObjC ARC autorelease pool elimination t_createObjCARCAPElimPass, //ObjC ARC autorelease pool elimination
t_createObjCARCContractPass, //Late ObjC ARC cleanups t_createObjCARCContractPass, //Late ObjC ARC cleanups

View File

@ -66,29 +66,29 @@ static void share_private_nodes(int worker_q);
#endif #endif
#define P_COPY_GLOBAL_TO(Q) \ #define P_COPY_GLOBAL_TO(Q) \
memcpy((void *) (worker_offset(Q) + REMOTE_start_global_copy(Q)), \ memmove((void *) (worker_offset(Q) + REMOTE_start_global_copy(Q)), \
(void *) REMOTE_start_global_copy(Q), \ (void *) REMOTE_start_global_copy(Q), \
(size_t) (REMOTE_end_global_copy(Q) - REMOTE_start_global_copy(Q))) (size_t) (REMOTE_end_global_copy(Q) - REMOTE_start_global_copy(Q)))
#define Q_COPY_GLOBAL_FROM(P) \ #define Q_COPY_GLOBAL_FROM(P) \
memcpy((void *) LOCAL_start_global_copy, \ memmove((void *) LOCAL_start_global_copy, \
(void *) (worker_offset(P) + LOCAL_start_global_copy), \ (void *) (worker_offset(P) + LOCAL_start_global_copy), \
(size_t) (LOCAL_end_global_copy - LOCAL_start_global_copy)) (size_t) (LOCAL_end_global_copy - LOCAL_start_global_copy))
#define P_COPY_LOCAL_TO(Q) \ #define P_COPY_LOCAL_TO(Q) \
memcpy((void *) (worker_offset(Q) + REMOTE_start_local_copy(Q)), \ memmove((void *) (worker_offset(Q) + REMOTE_start_local_copy(Q)), \
(void *) REMOTE_start_local_copy(Q), \ (void *) REMOTE_start_local_copy(Q), \
(size_t) (REMOTE_end_local_copy(Q) - REMOTE_start_local_copy(Q))) (size_t) (REMOTE_end_local_copy(Q) - REMOTE_start_local_copy(Q)))
#define Q_COPY_LOCAL_FROM(P) \ #define Q_COPY_LOCAL_FROM(P) \
memcpy((void *) LOCAL_start_local_copy, \ memmove((void *) LOCAL_start_local_copy, \
(void *) (worker_offset(P) + LOCAL_start_local_copy), \ (void *) (worker_offset(P) + LOCAL_start_local_copy), \
(size_t) (LOCAL_end_local_copy - LOCAL_start_local_copy)) (size_t) (LOCAL_end_local_copy - LOCAL_start_local_copy))
#define P_COPY_TRAIL_TO(Q) \ #define P_COPY_TRAIL_TO(Q) \
memcpy((void *) (worker_offset(Q) + REMOTE_start_trail_copy(Q)), \ memmove((void *) (worker_offset(Q) + REMOTE_start_trail_copy(Q)), \
(void *) REMOTE_start_trail_copy(Q), \ (void *) REMOTE_start_trail_copy(Q), \
(size_t) (REMOTE_end_trail_copy(Q) - REMOTE_start_trail_copy(Q))) (size_t) (REMOTE_end_trail_copy(Q) - REMOTE_start_trail_copy(Q)))
#define Q_COPY_TRAIL_FROM(P) \ #define Q_COPY_TRAIL_FROM(P) \
memcpy((void *) LOCAL_start_trail_copy, \ memmove((void *) LOCAL_start_trail_copy, \
(void *) (worker_offset(P) + LOCAL_start_trail_copy), \ (void *) (worker_offset(P) + LOCAL_start_trail_copy), \
(size_t) (LOCAL_end_trail_copy - LOCAL_start_trail_copy)) (size_t) (LOCAL_end_trail_copy - LOCAL_start_trail_copy))

View File

@ -409,13 +409,13 @@ void resume_suspension_frame(susp_fr_ptr resume_fr, or_fr_ptr top_or_fr) {
sg_fr_ptr sg_frame; sg_fr_ptr sg_frame;
/* copy suspended stacks */ /* copy suspended stacks */
memcpy(SuspFr_global_reg(resume_fr), memmove(SuspFr_global_reg(resume_fr),
SuspFr_global_start(resume_fr), SuspFr_global_start(resume_fr),
SuspFr_global_size(resume_fr)); SuspFr_global_size(resume_fr));
memcpy(SuspFr_local_reg(resume_fr), memmove(SuspFr_local_reg(resume_fr),
SuspFr_local_start(resume_fr), SuspFr_local_start(resume_fr),
SuspFr_local_size(resume_fr)); SuspFr_local_size(resume_fr));
memcpy(SuspFr_trail_reg(resume_fr), memmove(SuspFr_trail_reg(resume_fr),
SuspFr_trail_start(resume_fr), SuspFr_trail_start(resume_fr),
SuspFr_trail_size(resume_fr)); SuspFr_trail_size(resume_fr));

View File

@ -574,9 +574,9 @@ typedef enum {
SuspFr_global_size(SUSP_FR) = H_SIZE; \ SuspFr_global_size(SUSP_FR) = H_SIZE; \
SuspFr_local_size(SUSP_FR) = B_SIZE; \ SuspFr_local_size(SUSP_FR) = B_SIZE; \
SuspFr_trail_size(SUSP_FR) = TR_SIZE; \ SuspFr_trail_size(SUSP_FR) = TR_SIZE; \
memcpy(SuspFr_global_start(SUSP_FR), SuspFr_global_reg(SUSP_FR), H_SIZE); \ memmove(SuspFr_global_start(SUSP_FR), SuspFr_global_reg(SUSP_FR), H_SIZE); \
memcpy(SuspFr_local_start(SUSP_FR), SuspFr_local_reg(SUSP_FR), B_SIZE); \ memmove(SuspFr_local_start(SUSP_FR), SuspFr_local_reg(SUSP_FR), B_SIZE); \
memcpy(SuspFr_trail_start(SUSP_FR), SuspFr_trail_reg(SUSP_FR), TR_SIZE) memmove(SuspFr_trail_start(SUSP_FR), SuspFr_trail_reg(SUSP_FR), TR_SIZE)
#define new_subgoal_trie_node(NODE, ENTRY, CHILD, PARENT, NEXT) \ #define new_subgoal_trie_node(NODE, ENTRY, CHILD, PARENT, NEXT) \
ALLOC_SUBGOAL_TRIE_NODE(NODE); \ ALLOC_SUBGOAL_TRIE_NODE(NODE); \

View File

@ -665,12 +665,12 @@ static void traverse_subgoal_trie(sg_node_ptr current_node, char *str,
bucket = Hash_buckets(hash); bucket = Hash_buckets(hash);
last_bucket = bucket + Hash_num_buckets(hash); last_bucket = bucket + Hash_num_buckets(hash);
current_arity = (int *)malloc(sizeof(int) * (arity[0] + 1)); current_arity = (int *)malloc(sizeof(int) * (arity[0] + 1));
memcpy(current_arity, arity, sizeof(int) * (arity[0] + 1)); memmove(current_arity, arity, sizeof(int) * (arity[0] + 1));
do { do {
if (*bucket) { if (*bucket) {
traverse_subgoal_trie(*bucket, str, str_index, arity, mode, traverse_subgoal_trie(*bucket, str, str_index, arity, mode,
TRAVERSE_POSITION_FIRST PASS_REGS); TRAVERSE_POSITION_FIRST PASS_REGS);
memcpy(arity, current_arity, sizeof(int) * (current_arity[0] + 1)); memmove(arity, current_arity, sizeof(int) * (current_arity[0] + 1));
#ifdef TRIE_COMPACT_PAIRS #ifdef TRIE_COMPACT_PAIRS
if (arity[arity[0]] == -2 && str[str_index - 1] != '[') if (arity[arity[0]] == -2 && str[str_index - 1] != '[')
str[str_index - 1] = ','; str[str_index - 1] = ',';
@ -687,7 +687,7 @@ static void traverse_subgoal_trie(sg_node_ptr current_node, char *str,
/* save current state if first sibling node */ /* save current state if first sibling node */
if (position == TRAVERSE_POSITION_FIRST) { if (position == TRAVERSE_POSITION_FIRST) {
current_arity = (int *)malloc(sizeof(int) * (arity[0] + 1)); current_arity = (int *)malloc(sizeof(int) * (arity[0] + 1));
memcpy(current_arity, arity, sizeof(int) * (arity[0] + 1)); memmove(current_arity, arity, sizeof(int) * (arity[0] + 1));
current_str_index = str_index; current_str_index = str_index;
current_mode = mode; current_mode = mode;
} }
@ -737,7 +737,7 @@ static void traverse_subgoal_trie(sg_node_ptr current_node, char *str,
mode = current_mode; mode = current_mode;
current_node = TrNode_next(current_node); current_node = TrNode_next(current_node);
while (current_node) { while (current_node) {
memcpy(arity, current_arity, sizeof(int) * (current_arity[0] + 1)); memmove(arity, current_arity, sizeof(int) * (current_arity[0] + 1));
#ifdef TRIE_COMPACT_PAIRS #ifdef TRIE_COMPACT_PAIRS
if (arity[arity[0]] == -2 && str[str_index - 1] != '[') if (arity[arity[0]] == -2 && str[str_index - 1] != '[')
str[str_index - 1] = ','; str[str_index - 1] = ',';
@ -768,12 +768,12 @@ static void traverse_answer_trie(ans_node_ptr current_node, char *str,
bucket = Hash_buckets(hash); bucket = Hash_buckets(hash);
last_bucket = bucket + Hash_num_buckets(hash); last_bucket = bucket + Hash_num_buckets(hash);
current_arity = (int *)malloc(sizeof(int) * (arity[0] + 1)); current_arity = (int *)malloc(sizeof(int) * (arity[0] + 1));
memcpy(current_arity, arity, sizeof(int) * (arity[0] + 1)); memmove(current_arity, arity, sizeof(int) * (arity[0] + 1));
do { do {
if (*bucket) { if (*bucket) {
traverse_answer_trie(*bucket, str, str_index, arity, var_index, mode, traverse_answer_trie(*bucket, str, str_index, arity, var_index, mode,
TRAVERSE_POSITION_FIRST PASS_REGS); TRAVERSE_POSITION_FIRST PASS_REGS);
memcpy(arity, current_arity, sizeof(int) * (current_arity[0] + 1)); memmove(arity, current_arity, sizeof(int) * (current_arity[0] + 1));
#ifdef TRIE_COMPACT_PAIRS #ifdef TRIE_COMPACT_PAIRS
if (arity[arity[0]] == -2 && str[str_index - 1] != '[') if (arity[arity[0]] == -2 && str[str_index - 1] != '[')
str[str_index - 1] = ','; str[str_index - 1] = ',';
@ -790,7 +790,7 @@ static void traverse_answer_trie(ans_node_ptr current_node, char *str,
/* save current state if first sibling node */ /* save current state if first sibling node */
if (position == TRAVERSE_POSITION_FIRST) { if (position == TRAVERSE_POSITION_FIRST) {
current_arity = (int *)malloc(sizeof(int) * (arity[0] + 1)); current_arity = (int *)malloc(sizeof(int) * (arity[0] + 1));
memcpy(current_arity, arity, sizeof(int) * (arity[0] + 1)); memmove(current_arity, arity, sizeof(int) * (arity[0] + 1));
current_str_index = str_index; current_str_index = str_index;
current_var_index = var_index; current_var_index = var_index;
current_mode = mode; current_mode = mode;
@ -832,7 +832,7 @@ static void traverse_answer_trie(ans_node_ptr current_node, char *str,
mode = current_mode; mode = current_mode;
current_node = TrNode_next(current_node); current_node = TrNode_next(current_node);
while (current_node) { while (current_node) {
memcpy(arity, current_arity, sizeof(int) * (current_arity[0] + 1)); memmove(arity, current_arity, sizeof(int) * (current_arity[0] + 1));
#ifdef TRIE_COMPACT_PAIRS #ifdef TRIE_COMPACT_PAIRS
if (arity[arity[0]] == -2 && str[str_index - 1] != '[') if (arity[arity[0]] == -2 && str[str_index - 1] != '[')
str[str_index - 1] = ','; str[str_index - 1] = ',';
@ -863,12 +863,12 @@ static void traverse_global_trie(gt_node_ptr current_node, char *str,
bucket = Hash_buckets(hash); bucket = Hash_buckets(hash);
last_bucket = bucket + Hash_num_buckets(hash); last_bucket = bucket + Hash_num_buckets(hash);
current_arity = (int *)malloc(sizeof(int) * (arity[0] + 1)); current_arity = (int *)malloc(sizeof(int) * (arity[0] + 1));
memcpy(current_arity, arity, sizeof(int) * (arity[0] + 1)); memmove(current_arity, arity, sizeof(int) * (arity[0] + 1));
do { do {
if (*bucket) { if (*bucket) {
traverse_global_trie(*bucket, str, str_index, arity, mode, traverse_global_trie(*bucket, str, str_index, arity, mode,
TRAVERSE_POSITION_FIRST PASS_REGS); TRAVERSE_POSITION_FIRST PASS_REGS);
memcpy(arity, current_arity, sizeof(int) * (current_arity[0] + 1)); memmove(arity, current_arity, sizeof(int) * (current_arity[0] + 1));
#ifdef TRIE_COMPACT_PAIRS #ifdef TRIE_COMPACT_PAIRS
if (arity[arity[0]] == -2 && str[str_index - 1] != '[') if (arity[arity[0]] == -2 && str[str_index - 1] != '[')
str[str_index - 1] = ','; str[str_index - 1] = ',';
@ -885,7 +885,7 @@ static void traverse_global_trie(gt_node_ptr current_node, char *str,
/* save current state if first sibling node */ /* save current state if first sibling node */
if (position == TRAVERSE_POSITION_FIRST) { if (position == TRAVERSE_POSITION_FIRST) {
current_arity = (int *)malloc(sizeof(int) * (arity[0] + 1)); current_arity = (int *)malloc(sizeof(int) * (arity[0] + 1));
memcpy(current_arity, arity, sizeof(int) * (arity[0] + 1)); memmove(current_arity, arity, sizeof(int) * (arity[0] + 1));
current_str_index = str_index; current_str_index = str_index;
current_mode = mode; current_mode = mode;
} }
@ -913,7 +913,7 @@ static void traverse_global_trie(gt_node_ptr current_node, char *str,
mode = current_mode; mode = current_mode;
current_node = TrNode_next(current_node); current_node = TrNode_next(current_node);
while (current_node) { while (current_node) {
memcpy(arity, current_arity, sizeof(int) * (current_arity[0] + 1)); memmove(arity, current_arity, sizeof(int) * (current_arity[0] + 1));
#ifdef TRIE_COMPACT_PAIRS #ifdef TRIE_COMPACT_PAIRS
if (arity[arity[0]] == -2 && str[str_index - 1] != '[') if (arity[arity[0]] == -2 && str[str_index - 1] != '[')
str[str_index - 1] = ','; str[str_index - 1] = ',';
@ -1200,7 +1200,7 @@ sg_fr_ptr subgoal_search(yamop *preg, CELL **Yaddr) {
#ifdef MODE_DIRECTED_TABLING #ifdef MODE_DIRECTED_TABLING
if (subs_pos) { if (subs_pos) {
ALLOC_BLOCK(mode_directed, subs_pos * sizeof(int), int); ALLOC_BLOCK(mode_directed, subs_pos * sizeof(int), int);
memcpy((void *)mode_directed, (void *)aux_mode_directed, memmove((void *)mode_directed, (void *)aux_mode_directed,
subs_pos * sizeof(int)); subs_pos * sizeof(int));
} else } else
mode_directed = NULL; mode_directed = NULL;

View File

@ -77,7 +77,7 @@
#define copy_aux_stack() \ #define copy_aux_stack() \
{ arity_t size = 3 + heap_arity + subs_arity + vars_arity; \ { arity_t size = 3 + heap_arity + subs_arity + vars_arity; \
TOP_STACK -= size; \ TOP_STACK -= size; \
memcpy(TOP_STACK, aux_stack, size * sizeof(CELL *)); \ memmove(TOP_STACK, aux_stack, size * sizeof(CELL *)); \
aux_stack = TOP_STACK; \ aux_stack = TOP_STACK; \
}/* macros 'store_trie_node', 'restore_trie_node' and 'pop_trie_node' ** }/* macros 'store_trie_node', 'restore_trie_node' and 'pop_trie_node' **
** do not include 'set_cut' because trie instructions are cut safe */ ** do not include 'set_cut' because trie instructions are cut safe */

View File

@ -77,7 +77,7 @@
#define copy_aux_stack() \ #define copy_aux_stack() \
{ int size = 3 + heap_arity + subs_arity + vars_arity; \ { int size = 3 + heap_arity + subs_arity + vars_arity; \
TOP_STACK -= size; \ TOP_STACK -= size; \
memcpy(TOP_STACK, aux_stack, size * sizeof(CELL *)); \ memmove(TOP_STACK, aux_stack, size * sizeof(CELL *)); \
aux_stack = TOP_STACK; \ aux_stack = TOP_STACK; \
}/* macros 'store_trie_node', 'restore_trie_node' and 'pop_trie_node' ** }/* macros 'store_trie_node', 'restore_trie_node' and 'pop_trie_node' **
** do not include 'set_cut' because trie instructions are cut safe */ ** do not include 'set_cut' because trie instructions are cut safe */

View File

@ -496,7 +496,7 @@
/* Define to 1 if you have the `mbsnrtowcs' function. */ /* Define to 1 if you have the `mbsnrtowcs' function. */
#undef HAVE_MBSNRTOWCS #undef HAVE_MBSNRTOWCS
/* Define to 1 if you have the `memcpy' function. */ /* Define to 1 if you have the `memmove' function. */
#undef HAVE_MEMCPY #undef HAVE_MEMCPY
/* Define to 1 if you have the `memmove' function. */ /* Define to 1 if you have the `memmove' function. */

View File

@ -1767,7 +1767,7 @@ AC_CHECK_FUNCS(localeconv localtime lstat mallinfo)
AC_CHECK_FUNCS(mbscoll) AC_CHECK_FUNCS(mbscoll)
AC_CHECK_FUNCS(mbscasecoll) AC_CHECK_FUNCS(mbscasecoll)
AC_CHECK_FUNCS(mbsnrtowcs) AC_CHECK_FUNCS(mbsnrtowcs)
AC_CHECK_FUNCS(memcpy memmove mkstemp mktemp) AC_CHECK_FUNCS(memmove memmove mkstemp mktemp)
AC_CHECK_FUNCS(nanosleep mktime opendir) AC_CHECK_FUNCS(nanosleep mktime opendir)
AC_CHECK_FUNCS(putenv rand random drand48) AC_CHECK_FUNCS(putenv rand random drand48)
AC_CHECK_FUNCS(readlink realpath regexec) AC_CHECK_FUNCS(readlink realpath regexec)

View File

@ -291,7 +291,7 @@ check_symbol_exists(mallinfo " malloc.h" HAVE_MALLINFO)
check_function_exists(mbscoll HAVE_MBSCOLL) check_function_exists(mbscoll HAVE_MBSCOLL)
check_function_exists(mbscasecoll HAVE_MBSCASECOLL) check_function_exists(mbscasecoll HAVE_MBSCASECOLL)
check_function_exists(mbsnrtowcs HAVE_MBSNRTOWCS) check_function_exists(mbsnrtowcs HAVE_MBSNRTOWCS)
check_function_exists(memcpy HAVE_MEMCPY) check_function_exists(memmove HAVE_MEMCPY)
check_function_exists(memmove HAVE_MEMMOVE) check_function_exists(memmove HAVE_MEMMOVE)
check_function_exists(mkstemp HAVE_MKSTEMP) check_function_exists(mkstemp HAVE_MKSTEMP)
check_function_exists(mktemp HAVE_MKTEMP) check_function_exists(mktemp HAVE_MKTEMP)

View File

@ -1,7 +1,7 @@
# #
# FindLibR.cmake # FindLibR.cmake
# #
# Copyright (C) 2009-11 by RStudio, Inc. # Copyright (C) 2009-18 by RStudio, Inc.
# #
# This program is licensed to you under the terms of version 3 of the # This program is licensed to you under the terms of version 3 of the
# GNU Affero General Public License. This program is distributed WITHOUT # GNU Affero General Public License. This program is distributed WITHOUT
@ -21,11 +21,24 @@
if(APPLE) if(APPLE)
find_library(LIBR_LIBRARIES R) find_library(LIBR_LIBRARIES R)
if(LIBR_LIBRARIES)
if(LIBR_LIBRARIES MATCHES ".*\\.framework")
set(LIBR_HOME "${LIBR_LIBRARIES}/Resources" CACHE PATH "R home directory") set(LIBR_HOME "${LIBR_LIBRARIES}/Resources" CACHE PATH "R home directory")
set(LIBR_INCLUDE_DIRS "${LIBR_HOME}/include" CACHE PATH "R include directory") set(LIBR_INCLUDE_DIRS "${LIBR_HOME}/include" CACHE PATH "R include directory")
set(LIBR_DOC_DIR "${LIBR_HOME}/doc" CACHE PATH "R doc directory") set(LIBR_DOC_DIR "${LIBR_HOME}/doc" CACHE PATH "R doc directory")
set(LIBR_EXECUTABLE "${LIBR_HOME}/R" CACHE PATH "R executable") set(LIBR_EXECUTABLE "${LIBR_HOME}/R" CACHE PATH "R executable")
else()
get_filename_component(_LIBR_LIBRARIES "${LIBR_LIBRARIES}" REALPATH)
get_filename_component(_LIBR_LIBRARIES_DIR "${_LIBR_LIBRARIES}" PATH)
set(LIBR_EXECUTABLE "${_LIBR_LIBRARIES_DIR}/../bin/R")
execute_process(
COMMAND ${LIBR_EXECUTABLE} "--slave" "--vanilla" "-e" "cat(R.home())"
OUTPUT_VARIABLE LIBR_HOME
)
set(LIBR_HOME ${LIBR_HOME} CACHE PATH "R home directory")
set(LIBR_INCLUDE_DIRS "${LIBR_HOME}/include" CACHE PATH "R include directory")
set(LIBR_DOC_DIR "${LIBR_HOME}/doc" CACHE PATH "R doc directory")
set(LIBR_LIB_DIR "${LIBR_HOME}/lib" CACHE PATH "R lib directory")
endif() endif()
# detection for UNIX & Win32 # detection for UNIX & Win32
@ -103,12 +116,15 @@ else()
set(LIBR_INCLUDE_DIRS "${LIBR_HOME}/include" CACHE PATH "R include directory") set(LIBR_INCLUDE_DIRS "${LIBR_HOME}/include" CACHE PATH "R include directory")
set(LIBR_DOC_DIR "${LIBR_HOME}/doc" CACHE PATH "R doc directory") set(LIBR_DOC_DIR "${LIBR_HOME}/doc" CACHE PATH "R doc directory")
# set library hint path based on whether we are doing a special session 64 build # set library hint path for 64-bit build
if(LIBR_FIND_WINDOWS_64BIT) set(LIBR_ARCH "x64")
set(LIBRARY_ARCH_HINT_PATH "${LIBR_HOME}/bin/x64") set(LIBRARY_ARCH_HINT_PATH "${LIBR_HOME}/bin/x64")
else()
set(LIBRARY_ARCH_HINT_PATH "${LIBR_HOME}/bin/i386") # call dll2lib.R to ensure export files are generated
endif() execute_process(
COMMAND "${LIBR_HOME}/bin/${LIBR_ARCH}/Rscript.exe" "dll2lib.R"
WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/tools"
RESULT_VARIABLE LIBR_DLL2LIB_RESULT)
endif() endif()
@ -173,6 +189,7 @@ find_package_handle_standard_args(LibR DEFAULT_MSG
if(LIBR_FOUND) if(LIBR_FOUND)
message(STATUS "Found R: ${LIBR_HOME}") message(STATUS "Found R: ${LIBR_HOME}")
get_filename_component(LIBR_BIN_DIR "${LIBR_EXECUTABLE}" PATH CACHE)
endif() endif()
# mark low-level variables from FIND_* calls as advanced # mark low-level variables from FIND_* calls as advanced

View File

@ -897,7 +897,7 @@ function. */
#cmakedefine HAVE_MBSNRTOWCS ${HAVE_MBSNRTOWCS} #cmakedefine HAVE_MBSNRTOWCS ${HAVE_MBSNRTOWCS}
#endif #endif
/* Define to 1 if you have the `memcpy' function. */ /* Define to 1 if you have the `memmove' function. */
#ifndef HAVE_MEMCPY #ifndef HAVE_MEMCPY
#cmakedefine HAVE_MEMCPY ${HAVE_MEMCPY} #cmakedefine HAVE_MEMCPY ${HAVE_MEMCPY}
#endif #endif

View File

@ -356,7 +356,7 @@ Srlc_write(void *handle, char *buffer, size_t size)
{ char buf[sizeof(TCHAR)]; /* Pad to TCHAR */ { char buf[sizeof(TCHAR)]; /* Pad to TCHAR */
size_t i = sizeof(TCHAR) - (size-n); size_t i = sizeof(TCHAR) - (size-n);
memcpy(buf, buffer+n, i); memmove(buf, buffer+n, i);
for(; i<sizeof(TCHAR); i++) for(; i<sizeof(TCHAR); i++)
buf[i] = '?'; buf[i] = '?';
rlc_write(c, (TCHAR*)buffer, 1); rlc_write(c, (TCHAR*)buffer, 1);

View File

@ -203,6 +203,8 @@ typedef struct yap_boot_params {
const char *INPUT_STARTUP; const char *INPUT_STARTUP;
//> bootstrapping mode: YAP is not properly installed //> bootstrapping mode: YAP is not properly installed
bool install; bool install;
//> jupyter mode: YAP is in space
bool jupyter;
//> generats a saved space at this path //> generats a saved space at this path
const char *OUTPUT_STARTUP; const char *OUTPUT_STARTUP;
//> if NON-0, minimal size for Heap or Code Area //> if NON-0, minimal size for Heap or Code Area

View File

@ -21,7 +21,7 @@ ECLASS(INSTANTIATION_ERROR_CLASS, "instantiation_error", 0)
/// bad access, I/O /// bad access, I/O
ECLASS(PERMISSION_ERROR, "permission_error", 3) ECLASS(PERMISSION_ERROR, "permission_error", 3)
/// something that could not be represented into a type /// something that could not be represented into a type
ECLASS(REPRESENTATION_ERROR, "representation_error", 1) ECLASS(REPRESENTATION_ERROR, "representation_error", 0)
/// not enough .... /// not enough ....
ECLASS(RESOURCE_ERROR, "resource_error", 2) ECLASS(RESOURCE_ERROR, "resource_error", 2)
/// bad text /// bad text

View File

@ -26,7 +26,7 @@
*/ */
:- module(charsio, [ :- module(system(charsio), [
format_to_chars/3, format_to_chars/3,
format_to_chars/4, format_to_chars/4,
write_to_chars/3, write_to_chars/3,

View File

@ -70,7 +70,6 @@ Moyle. All rights reserved.
static atom_t ATOM_nil; static atom_t ATOM_nil;
extern int PL_unify_termv(term_t l, va_list args);
extern X_API Atom YAP_AtomFromSWIAtom(atom_t at); extern X_API Atom YAP_AtomFromSWIAtom(atom_t at);
extern X_API atom_t YAP_SWIAtomFromAtom(Atom at); extern X_API atom_t YAP_SWIAtomFromAtom(Atom at);
@ -818,6 +817,14 @@ X_API int PL_unify_bool(term_t t, int a) {
return Yap_unify(Yap_GetFromSlot(t), iterm); return Yap_unify(Yap_GetFromSlot(t), iterm);
} }
X_API int PL_put_bool(term_t t, int a) {
CACHE_REGS
CELL *pt = Yap_AddressFromHandle( t );
Term iterm = (a ? MkAtomTerm(AtomTrue) : MkAtomTerm(AtomFalse));
*pt = iterm;
return true;
}
#if USE_GMP #if USE_GMP
/******************************* /*******************************
@ -1273,7 +1280,7 @@ YAP: NO EQUIVALENT */
X_API int PL_raise_exception(term_t exception) { X_API int PL_raise_exception(term_t exception) {
CACHE_REGS CACHE_REGS
LOCAL_Error_TYPE = THROW_EVENT; LOCAL_Error_TYPE = THROW_EVENT;
LOCAL_ActiveError->errorGoal = Yap_TermToBuffer(Yap_GetFromHandle(exception), LOCAL_encoding, TermNil); LOCAL_ActiveError->errorGoal = Yap_TermToBuffer(Yap_GetFromHandle(exception), 0);
//Yap_PutException(Yap_GetFromSlot(exception)); //Yap_PutException(Yap_GetFromSlot(exception));
Yap_RaiseException(); Yap_RaiseException();
return 0; return 0;
@ -1321,7 +1328,7 @@ X_API int PL_unify_atom_chars(term_t t, const char *s) {
Atom at; Atom at;
while ((at = Yap_CharsToAtom(s, ENC_ISO_LATIN1 PASS_REGS)) == 0L) { while ((at = Yap_CharsToAtom(s, ENC_ISO_LATIN1 PASS_REGS)) == 0L) {
if (LOCAL_Error_TYPE && !Yap_SWIHandleError("PL_unify_atom_nchars")) if (LOCAL_Error_TYPE && !Yap_SWIHandleError("PL_unify_atom_nchars"))
return FALSE; return true;
} }
Yap_AtomIncreaseHold(at); Yap_AtomIncreaseHold(at);
return Yap_unify(Yap_GetFromSlot(t), MkAtomTerm(at)); return Yap_unify(Yap_GetFromSlot(t), MkAtomTerm(at));

View File

@ -593,7 +593,7 @@ Bfree
} }
} }
#define Bcopy(x,y) memcpy((char *)&x->sign, (char *)&y->sign, \ #define Bcopy(x,y) memmove((char *)&x->sign, (char *)&y->sign, \
y->wds*sizeof(Long) + 2*sizeof(int)) y->wds*sizeof(Long) + 2*sizeof(int))
static Bigint * static Bigint *

View File

@ -42,7 +42,7 @@ growBuffer(Buffer b, size_t minfree)
{ if ( !(new = malloc(sz)) ) { if ( !(new = malloc(sz)) )
return FALSE; return FALSE;
memcpy(new, b->static_buffer, osz); memmove(new, b->static_buffer, osz);
} else } else
{ if ( !(new = realloc(b->base, sz)) ) { if ( !(new = realloc(b->base, sz)) )
return FALSE; return FALSE;

View File

@ -2381,7 +2381,7 @@ re_buffer(IOSTREAM *s, const char *from, size_t len)
{ s->bufp = s->limitp = s->buffer; { s->bufp = s->limitp = s->buffer;
} }
memcpy(s->bufp, from, len); memmove(s->bufp, from, len);
s->bufp += len; s->bufp += len;
} }
@ -5846,7 +5846,7 @@ struct PL_local_data *Yap_InitThreadIO(int wid)
return p; return p;
} }
#if THREADS #if THREADS
memcpy(p, Yap_local[0]->PL_local_data_p_, sizeof(struct PL_local_data)); memmove(p, Yap_local[0]->PL_local_data_p_, sizeof(struct PL_local_data));
#endif #endif
return p; return p;
} }

View File

@ -1426,7 +1426,7 @@ localizeDecimalPoint(PL_locale *locale, Buffer b)
if ( strncmp(e, ddp, ddplen) == 0 ) if ( strncmp(e, ddp, ddplen) == 0 )
{ if ( dplen == ddplen ) { if ( dplen == ddplen )
{ memcpy(e, dp, dplen); { memmove(e, dp, dplen);
} else } else
{ char *ob = baseBuffer(b, char); { char *ob = baseBuffer(b, char);
if ( dplen > ddplen && !growBuffer(b, dplen-ddplen) ) if ( dplen > ddplen && !growBuffer(b, dplen-ddplen) )
@ -1434,7 +1434,7 @@ localizeDecimalPoint(PL_locale *locale, Buffer b)
e += baseBuffer(b, char) - ob; e += baseBuffer(b, char) - ob;
memmove(&e[dplen-ddplen], e, strlen(e)+1); memmove(&e[dplen-ddplen], e, strlen(e)+1);
memcpy(e, dp, dplen); memmove(e, dp, dplen);
} }
} }
} }
@ -1477,7 +1477,7 @@ groupDigits(PL_locale *locale, Buffer b)
{ *o-- = *e--; { *o-- = *e--;
if ( --gsize == 0 && e>=s ) if ( --gsize == 0 && e>=s )
{ o -= thslen-1; { o -= thslen-1;
memcpy(o, ths, thslen); memmove(o, ths, thslen);
o--; o--;
if ( grouping[1] == 0 ) if ( grouping[1] == 0 )
gsize = grouping[0]; gsize = grouping[0];

View File

@ -429,7 +429,7 @@ win_exec(size_t len, const wchar_t *cmd, UINT show)
/* ensure 0-terminated */ /* ensure 0-terminated */
wcmd = PL_malloc((len+1)*sizeof(wchar_t)); wcmd = PL_malloc((len+1)*sizeof(wchar_t));
memcpy(wcmd, cmd, len*sizeof(wchar_t)); memmove(wcmd, cmd, len*sizeof(wchar_t));
wcmd[len] = 0; wcmd[len] = 0;
rval = CreateProcessW(NULL, /* app */ rval = CreateProcessW(NULL, /* app */

View File

@ -953,7 +953,7 @@ getenv3(const char *name, char *buf, size_t len)
if ( s ) if ( s )
{ if ( (l=strlen(s)) < len ) { if ( (l=strlen(s)) < len )
memcpy(buf, s, l+1); memmove(buf, s, l+1);
else if ( len > 0 ) else if ( len > 0 )
buf[0] = EOS; /* empty string if not fit */ buf[0] = EOS; /* empty string if not fit */

View File

@ -253,7 +253,7 @@ static void growToBuffer(int c, ReadData _PL_rd) {
if (rb.base == rb.fast) /* intptr_t clause: jump to use malloc() */ if (rb.base == rb.fast) /* intptr_t clause: jump to use malloc() */
{ {
rb.base = PL_malloc(FASTBUFFERSIZE * 2); rb.base = PL_malloc(FASTBUFFERSIZE * 2);
memcpy(rb.base, rb.fast, FASTBUFFERSIZE); memmove(rb.base, rb.fast, FASTBUFFERSIZE);
} else } else
rb.base = PL_realloc(rb.base, rb.size * 2); rb.base = PL_realloc(rb.base, rb.size * 2);

View File

@ -491,7 +491,7 @@ Sread_readline(void *handle, char *buf, size_t size)
{ PL_warning("Input line too long"); /* must be tested! */ { PL_warning("Input line too long"); /* must be tested! */
l = size-1; l = size-1;
} }
memcpy(buf, line, l); memmove(buf, line, l);
buf[l++] = '\n'; buf[l++] = '\n';
rval = l; rval = l;

View File

@ -239,7 +239,7 @@ S__setbuf(IOSTREAM *s, char *buffer, size_t size)
} }
} }
memcpy(newbuf, s->bufp, copy); memmove(newbuf, s->bufp, copy);
S__removebuf(s); S__removebuf(s);
s->unbuffer = newunbuf; s->unbuffer = newunbuf;
s->bufp = s->buffer = newbuf; s->bufp = s->buffer = newbuf;
@ -1173,7 +1173,7 @@ Speekcode(IOSTREAM *s)
if ( s->bufp + UNDO_SIZE > s->limitp && !(s->flags&SIO_USERBUF) ) if ( s->bufp + UNDO_SIZE > s->limitp && !(s->flags&SIO_USERBUF) )
{ safe = s->limitp - s->bufp; { safe = s->limitp - s->bufp;
memcpy(s->buffer-safe, s->bufp, safe); memmove(s->buffer-safe, s->bufp, safe);
} }
start = s->bufp; start = s->bufp;
@ -1262,11 +1262,11 @@ Sfread(void *data, size_t size, size_t elms, IOSTREAM *s)
{ size_t avail = s->limitp - s->bufp; { size_t avail = s->limitp - s->bufp;
if ( chars <= avail ) if ( chars <= avail )
{ memcpy(buf, s->bufp, chars); { memmove(buf, s->bufp, chars);
s->bufp += chars; s->bufp += chars;
return elms; return elms;
} else } else
{ memcpy(buf, s->bufp, avail); { memmove(buf, s->bufp, avail);
chars -= avail; chars -= avail;
buf += avail; buf += avail;
s->bufp += avail; s->bufp += avail;
@ -1325,7 +1325,7 @@ Sread_pending(IOSTREAM *s, char *buf, size_t limit, int flags)
n = s->limitp - s->bufp; n = s->limitp - s->bufp;
if ( n > limit ) if ( n > limit )
n = limit; n = limit;
memcpy(&buf[done], s->bufp, n); memmove(&buf[done], s->bufp, n);
s->bufp += n; s->bufp += n;
return done+n; return done+n;
@ -3439,7 +3439,7 @@ Swrite_memfile(void *handle, char *buf, size_t size)
} }
if ( !mf->malloced ) if ( !mf->malloced )
{ if ( mf->buffer ) { if ( mf->buffer )
memcpy(nb, mf->buffer, mf->allocated); memmove(nb, mf->buffer, mf->allocated);
mf->malloced = TRUE; mf->malloced = TRUE;
} }
} else } else
@ -3453,7 +3453,7 @@ Swrite_memfile(void *handle, char *buf, size_t size)
*mf->bufferp = mf->buffer = nb; *mf->bufferp = mf->buffer = nb;
} }
memcpy(&mf->buffer[mf->here], buf, size); memmove(&mf->buffer[mf->here], buf, size);
mf->here += size; mf->here += size;
if ( mf->here > mf->size ) if ( mf->here > mf->size )
@ -3478,7 +3478,7 @@ Sread_memfile(void *handle, char *buf, size_t size)
size = mf->size - mf->here; size = mf->size - mf->here;
} }
memcpy(buf, &mf->buffer[mf->here], size); memmove(buf, &mf->buffer[mf->here], size);
mf->here += size; mf->here += size;
return size; return size;

View File

@ -69,7 +69,7 @@ PL_save_text(PL_chars_t *text, int flags)
{ size_t bl = bufsize_text(text, text->length+1); { size_t bl = bufsize_text(text, text->length+1);
void *new = PL_malloc(bl); void *new = PL_malloc(bl);
memcpy(new, text->text.t, bl); memmove(new, text->text.t, bl);
text->text.t = new; text->text.t = new;
text->storage = PL_CHARS_MALLOC; text->storage = PL_CHARS_MALLOC;
} else if ( text->storage == PL_CHARS_LOCAL ) } else if ( text->storage == PL_CHARS_LOCAL )
@ -104,7 +104,7 @@ PL_from_stack_text(PL_chars_t *text)
{ size_t bl = bufsize_text(text, text->length+1); { size_t bl = bufsize_text(text, text->length+1);
if ( bl < sizeof(text->buf) ) if ( bl < sizeof(text->buf) )
{ memcpy(text->buf, text->text.t, bl); { memmove(text->buf, text->text.t, bl);
text->text.t = text->buf; text->text.t = text->buf;
text->storage = PL_CHARS_LOCAL; text->storage = PL_CHARS_LOCAL;
} else } else
@ -135,7 +135,7 @@ ui64toa(uint64_t val, char *out)
} while ( val ); } while ( val );
nbDigs = ptrOrg - ptr; nbDigs = ptrOrg - ptr;
memcpy(out, ptr, nbDigs); memmove(out, ptr, nbDigs);
out += nbDigs; out += nbDigs;
*out = '\0'; *out = '\0';
@ -610,7 +610,7 @@ PL_promote_text(PL_chars_t *text)
unsigned char *e = &buf[text->length]; unsigned char *e = &buf[text->length];
pl_wchar_t *t = (pl_wchar_t*)text->buf; pl_wchar_t *t = (pl_wchar_t*)text->buf;
memcpy(buf, text->buf, text->length*sizeof(char)); memmove(buf, text->buf, text->length*sizeof(char));
while(f<e) while(f<e)
{ *t++ = *f++; { *t++ = *f++;
} }
@ -663,7 +663,7 @@ PL_demote_text(PL_chars_t *text)
pl_wchar_t *e = &buf[text->length]; pl_wchar_t *e = &buf[text->length];
char *t = text->buf; char *t = text->buf;
memcpy(buf, text->buf, text->length*sizeof(pl_wchar_t)); memmove(buf, text->buf, text->length*sizeof(pl_wchar_t));
while(f<e) while(f<e)
{ if ( *f > 0xff ) { if ( *f > 0xff )
return FALSE; return FALSE;
@ -1021,7 +1021,7 @@ PL_canonise_text(PL_chars_t *text)
text->encoding = ENC_WCHAR; text->encoding = ENC_WCHAR;
if ( len+1 < sizeof(text->buf)/sizeof(wchar_t) ) if ( len+1 < sizeof(text->buf)/sizeof(wchar_t) )
{ if ( text->text.t == text->buf ) { if ( text->text.t == text->buf )
{ memcpy(b2, text->buf, sizeof(text->buf)); { memmove(b2, text->buf, sizeof(text->buf));
from = b2; from = b2;
} }
text->text.w = (wchar_t*)text->buf; text->text.w = (wchar_t*)text->buf;
@ -1239,7 +1239,7 @@ PL_concat_text(int n, PL_chars_t **text, PL_chars_t *result)
} }
for(to=result->text.t, i=0; i<n; i++) for(to=result->text.t, i=0; i<n; i++)
{ memcpy(to, text[i]->text.t, text[i]->length); { memmove(to, text[i]->text.t, text[i]->length);
to += text[i]->length; to += text[i]->length;
} }
*to = EOS; *to = EOS;
@ -1257,7 +1257,7 @@ PL_concat_text(int n, PL_chars_t **text, PL_chars_t *result)
for(to=result->text.w, i=0; i<n; i++) for(to=result->text.w, i=0; i<n; i++)
{ if ( text[i]->encoding == ENC_WCHAR ) { if ( text[i]->encoding == ENC_WCHAR )
{ memcpy(to, text[i]->text.w, text[i]->length*sizeof(pl_wchar_t)); { memmove(to, text[i]->text.w, text[i]->length*sizeof(pl_wchar_t));
to += text[i]->length; to += text[i]->length;
} else } else
{ const unsigned char *f = (const unsigned char *)text[i]->text.t; { const unsigned char *f = (const unsigned char *)text[i]->text.t;

View File

@ -137,7 +137,7 @@ format_float(double f, char *buf)
{ *o++ = s[0]; { *o++ = s[0];
*o++ = '.'; *o++ = '.';
if ( end-s > 1 ) if ( end-s > 1 )
{ memcpy(o, s+1, end-s-1); { memmove(o, s+1, end-s-1);
o += end-s-1; o += end-s-1;
} else } else
*o++ = '0'; *o++ = '0';
@ -149,14 +149,14 @@ format_float(double f, char *buf)
*o++ = '.'; *o++ = '.';
for(i=0; i < -decpt; i++) for(i=0; i < -decpt; i++)
*o++ = '0'; *o++ = '0';
memcpy(o, s, end-s); memmove(o, s, end-s);
o[end-s] = 0; o[end-s] = 0;
} }
} else if ( end-s > decpt ) /* decimal dot inside */ } else if ( end-s > decpt ) /* decimal dot inside */
{ memcpy(o, s, decpt); { memmove(o, s, decpt);
o += decpt; o += decpt;
*o++ = '.'; *o++ = '.';
memcpy(o, s+decpt, end-s-decpt); memmove(o, s+decpt, end-s-decpt);
o[end-s-decpt] = 0; o[end-s-decpt] = 0;
} else /* decimal dot after */ } else /* decimal dot after */
{ int i; { int i;
@ -167,13 +167,13 @@ format_float(double f, char *buf)
*o++ = '.'; *o++ = '.';
if ( end-s > 1 ) if ( end-s > 1 )
{ trailing += (int)(end-s)-1; { trailing += (int)(end-s)-1;
memcpy(o, s+1, end-s-1); memmove(o, s+1, end-s-1);
o += end-s-1; o += end-s-1;
} else } else
*o++ = '0'; *o++ = '0';
sprintf(o, "e+%d", trailing); sprintf(o, "e+%d", trailing);
} else /* within precision trail with .0 */ } else /* within precision trail with .0 */
{ memcpy(o, s, end-s); { memmove(o, s, end-s);
o += end-s; o += end-s;
for(i=(int)(end-s); i<decpt; i++) for(i=(int)(end-s); i<decpt; i++)

View File

@ -57,6 +57,7 @@
with the `use_module(library(lists))` command. with the `use_module(library(lists))` command.
*/ */
:- include(pl/bootlists).
/** @pred list_concat(+ _Lists_,? _List_) /** @pred list_concat(+ _Lists_,? _List_)

View File

@ -159,7 +159,7 @@ new_int_matrix(int ndims, int dims[], long int data[])
} }
bdata = matrix_long_data(mat,ndims); bdata = matrix_long_data(mat,ndims);
if (data) if (data)
memcpy((void *)bdata,(void *)data,sizeof(double)*nelems); memmove((void *)bdata,(void *)data,sizeof(double)*nelems);
return blob; return blob;
} }
@ -193,7 +193,7 @@ new_float_matrix(int ndims, int dims[], double data[])
} }
bdata = matrix_double_data(mat,ndims); bdata = matrix_double_data(mat,ndims);
if (data) if (data)
memcpy((void *)bdata,(void *)data,sizeof(double)*nelems); memmove((void *)bdata,(void *)data,sizeof(double)*nelems);
return blob; return blob;
} }

View File

@ -88,7 +88,7 @@ expand_buffer( int space )
Yap_Error(SYSTEM_ERROR_INTERNAL, TermNil, "out of memory" ); Yap_Error(SYSTEM_ERROR_INTERNAL, TermNil, "out of memory" );
Yap_exit( EXIT_FAILURE ); Yap_exit( EXIT_FAILURE );
} }
memcpy( tmp, buf, bufsize ); memmove( tmp, buf, bufsize );
free( buf ); free( buf );
buf = tmp; buf = tmp;
#else /* use realloc */ #else /* use realloc */

View File

@ -1539,7 +1539,7 @@ sopno finish; /* to this less one */
return (ret); return (ret);
enlarge(p, p->ssize + len); /* this many unexpected additions */ enlarge(p, p->ssize + len); /* this many unexpected additions */
assert(p->ssize >= p->slen + len); assert(p->ssize >= p->slen + len);
(void)memcpy((char *)(p->strip + p->slen), (char *)(p->strip + start), (void)memmove((char *)(p->strip + p->slen), (char *)(p->strip + start),
(size_t)len * sizeof(sop)); (size_t)len * sizeof(sop));
p->slen += len; p->slen += len;
return (ret); return (ret);

View File

@ -130,7 +130,7 @@ static int nope = 0; /* for use in asserts; shuts lint up */
#define SET0(v, n) ((v)[n] = 0) #define SET0(v, n) ((v)[n] = 0)
#define SET1(v, n) ((v)[n] = 1) #define SET1(v, n) ((v)[n] = 1)
#define ISSET(v, n) ((v)[n]) #define ISSET(v, n) ((v)[n])
#define ASSIGN(d, s) memcpy(d, s, m->g->nstates) #define ASSIGN(d, s) memmove(d, s, m->g->nstates)
#define EQ(a, b) (memcmp(a, b, m->g->nstates) == 0) #define EQ(a, b) (memcmp(a, b, m->g->nstates) == 0)
#define STATEVARS \ #define STATEVARS \
long vn; \ long vn; \

View File

@ -153,8 +153,8 @@ RL_Tree *copy_rl(RL_Tree *tree) {
free(new); free(new);
return NULL; return NULL;
} }
memcpy(new, tree, sizeof(RL_Tree)); memmove(new, tree, sizeof(RL_Tree));
memcpy(buf_ptr, &tree->root[0], tree->size * NODE_SIZE); memmove(buf_ptr, &tree->root[0], tree->size * NODE_SIZE);
new->root = buf_ptr; new->root = buf_ptr;
new->mem_alloc = tree->size *NODE_SIZE; new->mem_alloc = tree->size *NODE_SIZE;
return new; return new;

View File

@ -167,7 +167,7 @@ md5_process(md5_state_t *pms, const md5_byte_t *data /*[64]*/)
X = (const md5_word_t *)data; X = (const md5_word_t *)data;
} else { } else {
/* not aligned */ /* not aligned */
memcpy(xbuf, data, 64); memmove(xbuf, data, 64);
X = xbuf; X = xbuf;
} }
} }
@ -353,7 +353,7 @@ md5_append(md5_state_t *pms, const md5_byte_t *data, unsigned int nbytes)
if (offset) { if (offset) {
unsigned int copy = (offset + nbytes > 64 ? 64 - offset : nbytes); unsigned int copy = (offset + nbytes > 64 ? 64 - offset : nbytes);
memcpy(pms->buf + offset, p, copy); memmove(pms->buf + offset, p, copy);
if (offset + copy < 64) if (offset + copy < 64)
return; return;
p += copy; p += copy;
@ -367,7 +367,7 @@ md5_append(md5_state_t *pms, const md5_byte_t *data, unsigned int nbytes)
/* Process a final partial block. */ /* Process a final partial block. */
if (left) if (left)
memcpy(pms->buf, p, left); memmove(pms->buf, p, left);
} }
void void

View File

@ -114,7 +114,7 @@ typedef struct itrie_data {
YAP_Int i, new_num_buckets = DEPTH + BASE_TR_DATA_BUCKETS; \ YAP_Int i, new_num_buckets = DEPTH + BASE_TR_DATA_BUCKETS; \
bucket = TrEntry_buckets(TR_ENTRY); \ bucket = TrEntry_buckets(TR_ENTRY); \
new_itrie_buckets(TR_ENTRY, new_num_buckets); \ new_itrie_buckets(TR_ENTRY, new_num_buckets); \
memcpy(TrEntry_buckets(TR_ENTRY), bucket, \ memmove(TrEntry_buckets(TR_ENTRY), bucket, \
TrEntry_num_buckets(TR_ENTRY) * SIZEOF_TR_DATA_BUCKET); \ TrEntry_num_buckets(TR_ENTRY) * SIZEOF_TR_DATA_BUCKET); \
free_itrie_buckets(bucket, TrEntry_num_buckets(TR_ENTRY)); \ free_itrie_buckets(bucket, TrEntry_num_buckets(TR_ENTRY)); \
bucket = TrEntry_buckets(TR_ENTRY); \ bucket = TrEntry_buckets(TR_ENTRY); \

View File

@ -1468,12 +1468,12 @@ void traverse_and_print(TrNode node, int *arity, char *str, int str_index, int m
hash = (TrHash) node; hash = (TrHash) node;
first_bucket = TrHash_buckets(hash); first_bucket = TrHash_buckets(hash);
bucket = first_bucket + TrHash_num_buckets(hash); bucket = first_bucket + TrHash_num_buckets(hash);
memcpy(current_arity, arity, sizeof(int) * (arity[0] + 1)); memmove(current_arity, arity, sizeof(int) * (arity[0] + 1));
do { do {
if (*--bucket) { if (*--bucket) {
node = *bucket; node = *bucket;
traverse_and_print(node, arity, str, str_index, mode); traverse_and_print(node, arity, str, str_index, mode);
memcpy(arity, current_arity, sizeof(int) * (current_arity[0] + 1)); memmove(arity, current_arity, sizeof(int) * (current_arity[0] + 1));
if (mode != TRIE_PRINT_FLOAT2 && arity[arity[0]] < 0) { if (mode != TRIE_PRINT_FLOAT2 && arity[arity[0]] < 0) {
/* restore possible PairEndEmptyTag/PairEndTermTag/CommaEndTag side-effect */ /* restore possible PairEndEmptyTag/PairEndTermTag/CommaEndTag side-effect */
if (str_index > 0 && str[str_index - 1] != '[') if (str_index > 0 && str[str_index - 1] != '[')
@ -1490,9 +1490,9 @@ void traverse_and_print(TrNode node, int *arity, char *str, int str_index, int m
if (TrNode_next(node)) { if (TrNode_next(node)) {
int *current_arity = (int *) malloc(sizeof(int) * (arity[0] + 1)); int *current_arity = (int *) malloc(sizeof(int) * (arity[0] + 1));
memcpy(current_arity, arity, sizeof(int) * (arity[0] + 1)); memmove(current_arity, arity, sizeof(int) * (arity[0] + 1));
traverse_and_print(TrNode_next(node), arity, str, str_index, mode); traverse_and_print(TrNode_next(node), arity, str, str_index, mode);
memcpy(arity, current_arity, sizeof(int) * (current_arity[0] + 1)); memmove(arity, current_arity, sizeof(int) * (current_arity[0] + 1));
if (mode != TRIE_PRINT_FLOAT2 && arity[arity[0]] < 0) { if (mode != TRIE_PRINT_FLOAT2 && arity[arity[0]] < 0) {
/* restore possible PairEndEmptyTag/PairEndTermTag/CommaEndTag side-effect */ /* restore possible PairEndEmptyTag/PairEndTermTag/CommaEndTag side-effect */
if (str_index > 0 && str[str_index - 1] != '[') if (str_index > 0 && str[str_index - 1] != '[')

View File

@ -221,7 +221,7 @@ typedef struct trie_hash {
{ YAP_Term *aux_stack; \ { YAP_Term *aux_stack; \
YAP_Int aux_size = CURRENT_AUXILIARY_TERM_STACK_SIZE * sizeof(YAP_Term); \ YAP_Int aux_size = CURRENT_AUXILIARY_TERM_STACK_SIZE * sizeof(YAP_Term); \
new_struct(aux_stack, YAP_Term, aux_size * 2); \ new_struct(aux_stack, YAP_Term, aux_size * 2); \
memcpy(aux_stack, AUXILIARY_TERM_STACK, aux_size); \ memmove(aux_stack, AUXILIARY_TERM_STACK, aux_size); \
free_struct(AUXILIARY_TERM_STACK); \ free_struct(AUXILIARY_TERM_STACK); \
AUXILIARY_TERM_STACK = aux_stack; \ AUXILIARY_TERM_STACK = aux_stack; \
CURRENT_AUXILIARY_TERM_STACK_SIZE *= 2; \ CURRENT_AUXILIARY_TERM_STACK_SIZE *= 2; \

View File

@ -209,7 +209,7 @@ ExtendAliasArray(void)
UInt new_size = GLOBAL_SzOfFileAliases+ALIASES_BLOCK_SIZE; UInt new_size = GLOBAL_SzOfFileAliases+ALIASES_BLOCK_SIZE;
new = (AliasDesc)Yap_AllocCodeSpace(sizeof(AliasDesc *)*new_size); new = (AliasDesc)Yap_AllocCodeSpace(sizeof(AliasDesc *)*new_size);
memcpy((void *)new, (void *)GLOBAL_FileAliases, sizeof(AliasDesc *)*GLOBAL_SzOfFileAliases); memmove((void *)new, (void *)GLOBAL_FileAliases, sizeof(AliasDesc *)*GLOBAL_SzOfFileAliases);
Yap_FreeCodeSpace((ADDR) GLOBAL_FileAliases); Yap_FreeCodeSpace((ADDR) GLOBAL_FileAliases);
GLOBAL_FileAliases = new; GLOBAL_FileAliases = new;
GLOBAL_SzOfFileAliases = new_size; GLOBAL_SzOfFileAliases = new_size;
@ -221,16 +221,16 @@ Yap_SetAlias (Atom arg, int sno)
CACHE_REGS CACHE_REGS
AliasDesc aliasp = GLOBAL_FileAliases, aliasp_max = GLOBAL_FileAliases+GLOBAL_NOfFileAliases; AliasDesc aliasp = GLOBAL_FileAliases, aliasp_max = GLOBAL_FileAliases+GLOBAL_NOfFileAliases;
while (aliasp < aliasp_max) {
// replace alias
if (aliasp->name == arg) {
aliasp->alias_stream = sno;
if (arg == AtomUserIn) if (arg == AtomUserIn)
LOCAL_c_input_stream = sno; LOCAL_c_input_stream = sno;
if (arg == AtomUserOut) if (arg == AtomUserOut)
LOCAL_c_output_stream = sno; LOCAL_c_output_stream = sno;
if (arg == AtomUserErr) if (arg == AtomUserErr)
LOCAL_c_error_stream = sno; LOCAL_c_error_stream = sno;
while (aliasp < aliasp_max) {
// replace alias
if (aliasp->name == arg) {
aliasp->alias_stream = sno;
return; return;
} }
aliasp++; aliasp++;
@ -317,16 +317,16 @@ ExistsAliasForStream (int sno, Atom al)
while (aliasp < aliasp_max) { while (aliasp < aliasp_max) {
if (aliasp->alias_stream == sno && aliasp->name == al) { if (aliasp->alias_stream == sno && aliasp->name == al) {
if (al == AtomUserIn) { if (al == AtomUserIn) {
LOCAL_c_input_stream = StdInStream; LOCAL_c_input_stream = sno;
aliasp->alias_stream = StdInStream; aliasp->alias_stream = sno;
} } else
if (al == AtomUserOut) { if (al == AtomUserOut) {
LOCAL_c_output_stream = StdOutStream; LOCAL_c_output_stream = sno;
aliasp->alias_stream = StdOutStream; aliasp->alias_stream = sno;
} }
if (al == AtomUserErr) { if (al == AtomUserErr) {
LOCAL_c_error_stream = StdErrStream; LOCAL_c_error_stream = sno;
aliasp->alias_stream = StdErrStream; aliasp->alias_stream = sno;
} }
return true; return true;
} }
@ -387,6 +387,12 @@ Yap_AddAlias (Atom arg, int sno)
AliasDesc aliasp = GLOBAL_FileAliases, aliasp_max = GLOBAL_FileAliases+GLOBAL_NOfFileAliases; AliasDesc aliasp = GLOBAL_FileAliases, aliasp_max = GLOBAL_FileAliases+GLOBAL_NOfFileAliases;
if (arg == AtomUserIn)
LOCAL_c_input_stream = sno;
else if (arg == AtomUserOut)
LOCAL_c_output_stream = sno;
else if (arg == AtomUserErr)
LOCAL_c_error_stream = sno;
while (aliasp < aliasp_max) { while (aliasp < aliasp_max) {
if (aliasp->name == arg) { if (aliasp->name == arg) {
aliasp->alias_stream = sno; aliasp->alias_stream = sno;
@ -394,6 +400,7 @@ Yap_AddAlias (Atom arg, int sno)
} }
aliasp++; aliasp++;
} }
/* we have not found an alias neither a hole */ /* we have not found an alias neither a hole */
if (aliasp == GLOBAL_FileAliases+GLOBAL_SzOfFileAliases) if (aliasp == GLOBAL_FileAliases+GLOBAL_SzOfFileAliases)
ExtendAliasArray(); ExtendAliasArray();

View File

@ -98,12 +98,12 @@ open_asset(VFS_t *me, const char *fname, const char *io_mode, int sno) {
if ((buf = AAsset_getBuffer(am))) { if ((buf = AAsset_getBuffer(am))) {
// copy to memory // copy to memory
char *bf = malloc(sz); char *bf = malloc(sz);
memcpy(bf, buf, sz); memmove(bf, buf, sz);
bool rc = Yap_set_stream_to_buf(st, bf, sz); bool rc = Yap_set_stream_to_buf(st, bf, sz);
if (rc) AAsset_close(am); if (rc) AAsset_close(am);
st->vfs = NULL; st->vfs = NULL;
st->vfs_handle = NULL; st->vfs_handle = NULL;
st->status = InMemory_Stream_f|Seekable_Stream_f|Input_Stream_f; st->status = InMemory_Stream_f|Seekable_Stream_f|Input_Stream_f;
return st; return st;
} else if ((fd = AAsset_openFileDescriptor64(am, &sz0, &sz)) >= 0) { } else if ((fd = AAsset_openFileDescriptor64(am, &sz0, &sz)) >= 0) {
// can use it as read-only file // can use it as read-only file
@ -162,10 +162,10 @@ static bool stat_a(VFS_t *me, const char *fname, vfs_stat *out) {
out->st_dev = bf.st_dev; out->st_dev = bf.st_dev;
out->st_uid = bf.st_uid; out->st_uid = bf.st_uid;
out->st_gid = bf.st_gid; out->st_gid = bf.st_gid;
memcpy(&out->st_atimespec, (const void *) &bf.st_atim, sizeof(struct timespec)); memmove(&out->st_atimespec, (const void *) &bf.st_atim, sizeof(struct timespec));
memcpy(&out->st_mtimespec, (const void *) &bf.st_mtim, sizeof(struct timespec)); memmove(&out->st_mtimespec, (const void *) &bf.st_mtim, sizeof(struct timespec));
memcpy(&out->st_ctimespec, (const void *) &bf.st_ctim, sizeof(struct timespec)); memmove(&out->st_ctimespec, (const void *) &bf.st_ctim, sizeof(struct timespec));
memcpy(&out->st_birthtimespec, (const void *) &bf.st_ctim, memmove(&out->st_birthtimespec, (const void *) &bf.st_ctim,
sizeof(struct timespec)); sizeof(struct timespec));
} }
AAsset *a = AAssetManager_open(Yap_assetManager(), fname, AASSET_MODE_UNKNOWN); AAsset *a = AAssetManager_open(Yap_assetManager(), fname, AASSET_MODE_UNKNOWN);

View File

@ -990,16 +990,11 @@ leaving the current stream position unaltered.
*/ */
static Int peek_code(USES_REGS1) { /* at_end_of_stream */ static Int peek_code(USES_REGS1) { /* at_end_of_stream */
/* the next character is a EOF */ /* the next character is a EOF */
int sno = Yap_CheckTextStream(ARG1, Input_Stream_f, "peek/2"); int sno = Yap_CheckTextStream(ARG1, Input_Stream_f, "peek_code/2");
Int ch; Int ch;
if (sno < 0) if (sno < 0)
return FALSE; return FALSE;
if (GLOBAL_Stream[sno].status & Binary_Stream_f) {
UNLOCK(GLOBAL_Stream[sno].streamlock);
Yap_Error(PERMISSION_ERROR_INPUT_TEXT_STREAM, ARG1, "peek_code/2");
return FALSE;
}
if ((ch = Yap_peek(sno)) < 0) { if ((ch = Yap_peek(sno)) < 0) {
#ifdef PEEK_EOF #ifdef PEEK_EOF
UNLOCK(GLOBAL_Stream[sno].streamlock); UNLOCK(GLOBAL_Stream[sno].streamlock);

View File

@ -82,8 +82,8 @@ Term Yap_StringToNumberTerm(const char *s, encoding_t *encp, bool error_on) {
CACHE_REGS CACHE_REGS
int sno; int sno;
int i = push_text_stack(); int i = push_text_stack();
Atom nat = Yap_LookupAtom(Yap_StrPrefix(s, 16));
sno = Yap_open_buf_read_stream(s, strlen(s), encp, MEM_BUF_USER); sno = Yap_open_buf_read_stream(s, strlen(s), encp, MEM_BUF_USER, nat, MkAtomTerm(Yap_LookupAtom("eval")));
if (sno < 0) if (sno < 0)
return FALSE; return FALSE;
if (encp) if (encp)

View File

@ -98,7 +98,7 @@ static Int file_name_extension(USES_REGS1) {
ext = ""; ext = "";
} }
base = Malloc(lenb_b + 1); base = Malloc(lenb_b + 1);
memcpy(base, f, lenb_b); memmove(base, f, lenb_b);
base[lenb_b] = '\0'; base[lenb_b] = '\0';
if (IsVarTerm(t1 = Deref(ARG1))) { if (IsVarTerm(t1 = Deref(ARG1))) {
// should always succeed // should always succeed

View File

@ -131,8 +131,18 @@ bool Yap_set_stream_to_buf(StreamDesc *st, const char *buf,
return true; return true;
} }
int Yap_open_buf_read_stream(const char *buf, size_t nchars, encoding_t *encp,
memBufSource src) { char *Yap_StrPrefix( const char *buf, size_t n) {
char *b = (char*)malloc(n);
strncpy(b, buf, n - 1);
if (strlen(buf) > n - 1)
b[15] = '\0';
return b;
}
int Yap_open_buf_read_stream(const char *buf, size_t nchars,
encoding_t *encp, memBufSource src, Atom fname,
Term uname) {
CACHE_REGS CACHE_REGS
int sno; int sno;
StreamDesc *st; StreamDesc *st;
@ -153,7 +163,7 @@ int Yap_open_buf_read_stream(const char *buf, size_t nchars, encoding_t *encp,
f = st->file = fmemopen((void *)buf, nchars, "r"); f = st->file = fmemopen((void *)buf, nchars, "r");
st->vfs = NULL; st->vfs = NULL;
flags = Input_Stream_f | InMemory_Stream_f | Seekable_Stream_f; flags = Input_Stream_f | InMemory_Stream_f | Seekable_Stream_f;
Yap_initStream(sno, f, "memStream", "r", TermNone, encoding, flags, NULL); Yap_initStream(sno, f, RepAtom(fname)->StrOfAE, "r", uname, encoding, flags, NULL);
// like any file stream. // like any file stream.
Yap_DefaultStreamOps(st); Yap_DefaultStreamOps(st);
UNLOCK(st->streamlock); UNLOCK(st->streamlock);
@ -176,7 +186,7 @@ open_mem_read_stream(USES_REGS1) /* $open_mem_read_stream(+List,-Stream) */
} }
buf = pop_output_text_stack(l, buf); buf = pop_output_text_stack(l, buf);
sno = Yap_open_buf_read_stream(buf, strlen(buf) + 1, &LOCAL_encoding, sno = Yap_open_buf_read_stream(buf, strlen(buf) + 1, &LOCAL_encoding,
MEM_BUF_MALLOC); MEM_BUF_MALLOC, Yap_LookupAtom(Yap_StrPrefix((char *)buf,16)), TermNone);
t = Yap_MkStream(sno); t = Yap_MkStream(sno);
return Yap_unify(ARG2, t); return Yap_unify(ARG2, t);
} }
@ -193,7 +203,9 @@ int Yap_open_buf_write_stream(encoding_t enc, memBufSource src) {
return -1; return -1;
st = GLOBAL_Stream + sno; st = GLOBAL_Stream + sno;
st->status = Output_Stream_f | InMemory_Stream_f | FreeOnClose_Stream_f; st->status = Output_Stream_f | InMemory_Stream_f;
if (st->nbuf)
st->status |= FreeOnClose_Stream_f;
st->linepos = 0; st->linepos = 0;
st->charcount = 0; st->charcount = 0;
st->linecount = 1; st->linecount = 1;
@ -202,15 +214,15 @@ int Yap_open_buf_write_stream(encoding_t enc, memBufSource src) {
st->buf.on = true; st->buf.on = true;
st->nbuf = NULL; st->nbuf = NULL;
st->nsize = 0; st->nsize = 0;
st->status |= Seekable_Stream_f;
#if HAVE_OPEN_MEMSTREAM #if HAVE_OPEN_MEMSTREAM
st->file = open_memstream(&st->nbuf, &st->nsize); st->file = open_memstream(&st->nbuf, &st->nsize);
// setbuf(st->file, NULL); // setbuf(st->file, NULL);
st->status |= Seekable_Stream_f;
#else
st->file = fmemopen((void *)st->nbuf, st->nsize, "w");
if (!st->nbuf) { if (!st->nbuf) {
return -1; return -1;
} }
#else
st->file = fmemopen((void *)st->nbuf, st->nsize, "w+");
#endif #endif
Yap_DefaultStreamOps(st); Yap_DefaultStreamOps(st);
UNLOCK(st->streamlock); UNLOCK(st->streamlock);
@ -247,35 +259,41 @@ open_mem_write_stream(USES_REGS1) /* $open_mem_write_stream(-Stream) */
* by other writes.. * by other writes..
*/ */
char *Yap_MemExportStreamPtr(int sno) { char *Yap_MemExportStreamPtr(int sno) {
char *s;
if (fflush(GLOBAL_Stream[sno].file) == 0) { if (fflush(GLOBAL_Stream[sno].file) < 0) {
s = GLOBAL_Stream[sno].nbuf; return NULL;
// s[fseek(GLOBAL_Stream[sno].file, 0, SEEK_END)] = '\0';
return s;
} }
return NULL; size_t len = fseek(GLOBAL_Stream[sno].file, 0, SEEK_END);
char *buf = malloc(len+1);
#if HAVE_OPEN_MEMSTREAM
char *s = GLOBAL_Stream[sno].nbuf;
memcpy(buf, s, len);
// s[fseek(GLOBAL_Stream[sno].file, 0, SEEK_END)] = '\0';
#else
fread(buf, sz, 1, GLOBAL_Stream[sno].file);
#endif
buf[len] = '\0';
return buf;
} }
static Int peek_mem_write_stream( static Int peek_mem_write_stream(
USES_REGS1) { /* '$peek_mem_write_stream'(+GLOBAL_Stream,?S0,?S) */ USES_REGS1) { /* '$peek_mem_write_stream'(+GLOBAL_Stream,?S0,?S) */
Int sno = Int sno =
Yap_CheckStream(ARG1, (Output_Stream_f | InMemory_Stream_f), "close/2"); Yap_CheckStream(ARG1, (Output_Stream_f | InMemory_Stream_f), "close/2");
Int i;
Term tf = ARG2; Term tf = ARG2;
CELL *HI; CELL *HI;
const char *ptr; char *ptr;
int ch;
if (sno < 0) if (sno < 0)
return (FALSE); return (FALSE);
restart: char *p = ptr = Yap_MemExportStreamPtr(sno);
restart:
HI = HR; HI = HR;
if (fflush(GLOBAL_Stream[sno].file) == 0) { while ((ch = *p++)) {
i = fseek(GLOBAL_Stream[sno].file, 0, SEEK_END); HR[0] = MkIntTerm(ch);
ptr = GLOBAL_Stream[sno].nbuf; HR[1] = AbsPair(HR+2);
} HR += 2;
while (i > 0) {
--i;
tf = MkPairTerm(MkIntTerm(ptr[i]), tf);
if (HR + 1024 >= ASP) { if (HR + 1024 >= ASP) {
UNLOCK(GLOBAL_Stream[sno].streamlock); UNLOCK(GLOBAL_Stream[sno].streamlock);
HR = HI; HR = HI;
@ -284,14 +302,14 @@ restart:
Yap_Error(RESOURCE_ERROR_STACK, TermNil, LOCAL_ErrorMessage); Yap_Error(RESOURCE_ERROR_STACK, TermNil, LOCAL_ErrorMessage);
return (FALSE); return (FALSE);
} }
i = GLOBAL_Stream[sno].u.mem_string.pos;
tf = ARG2;
LOCK(GLOBAL_Stream[sno].streamlock); LOCK(GLOBAL_Stream[sno].streamlock);
goto restart; goto restart;
} }
} }
HR[-1] = tf;
UNLOCK(GLOBAL_Stream[sno].streamlock); UNLOCK(GLOBAL_Stream[sno].streamlock);
return (Yap_unify(ARG3, tf)); free(ptr);
return (Yap_unify(ARG3, AbsPair(HI)));
} }
void Yap_MemOps(StreamDesc *st) { void Yap_MemOps(StreamDesc *st) {

View File

@ -96,7 +96,7 @@ fmemread(void *cookie, char *buf, int n)
return 0; return 0;
if (n >= c->eof - c->pos) if (n >= c->eof - c->pos)
n = c->eof - c->pos; n = c->eof - c->pos;
memcpy (buf, c->buf + c->pos, n); memmove (buf, c->buf + c->pos, n);
c->pos += n; c->pos += n;
return n; return n;
} }
@ -144,7 +144,7 @@ fmemwrite(void *cookie, const char *buf, int n)
} }
c->pos += n; c->pos += n;
if (n - adjust) if (n - adjust)
memcpy (c->buf + c->pos - n, buf, n - adjust); memmove (c->buf + c->pos - n, buf, n - adjust);
else else
{ {
return EOF; return EOF;

View File

@ -45,7 +45,7 @@ static int readfn(void *handler, char *buf, int size) {
if (size > available) { if (size > available) {
size = available; size = available;
} }
memcpy(buf, mem->buffer + mem->pos, sizeof(char) * size); memmove(buf, mem->buffer + mem->pos, sizeof(char) * size);
mem->pos += size; mem->pos += size;
return size; return size;
@ -58,7 +58,7 @@ static int writefn(void *handler, const char *buf, int size) {
if (size > available) { if (size > available) {
size = available; size = available;
} }
memcpy(mem->buffer + mem->pos, buf, sizeof(char) * size); memmove(mem->buffer + mem->pos, buf, sizeof(char) * size);
mem->pos += size; mem->pos += size;
return size; return size;

View File

@ -1129,10 +1129,14 @@ static void check_bom(int sno, StreamDesc *st) {
bool Yap_initStream(int sno, FILE *fd, const char *name, const char *io_mode, bool Yap_initStream(int sno, FILE *fd, const char *name, const char *io_mode,
Term file_name, encoding_t encoding, stream_flags_t flags, Term file_name, encoding_t encoding, stream_flags_t flags,
void *vfs) { void *vfs) {
// fprintf(stderr,"+ %s --> %d\n", name, sno);
StreamDesc *st = &GLOBAL_Stream[sno]; StreamDesc *st = &GLOBAL_Stream[sno];
__android_log_print(ANDROID_LOG_INFO, "YAPDroid", "init %s %s stream <%d>",io_mode,name, __android_log_print(
sno); ANDROID_LOG_INFO, "YAPDroid", "init %s %s:%s stream <%d>", io_mode,
if (io_mode == NULL) CurrentModule == 0 ? "prolog"
: RepAtom(AtomOfTerm(CurrentModule))->StrOfAE,
name, sno);
if (io_mode == NULL)
Yap_Error(PERMISSION_ERROR_NEW_ALIAS_FOR_STREAM, MkIntegerTerm(sno), Yap_Error(PERMISSION_ERROR_NEW_ALIAS_FOR_STREAM, MkIntegerTerm(sno),
"File opened with NULL Permissions"); "File opened with NULL Permissions");
if (strchr(io_mode, 'a')) { if (strchr(io_mode, 'a')) {
@ -1229,13 +1233,10 @@ typedef enum open_enum_choices { OPEN_DEFS() } open_choices_t;
static const param_t open_defs[] = {OPEN_DEFS()}; static const param_t open_defs[] = {OPEN_DEFS()};
#undef PAR #undef PAR
static bool fill_stream(int sno, StreamDesc *st, Term tin, const char *io_mode,
static bool fill_stream(int sno, StreamDesc *st, Term tin, const char *io_mode, Term user_name, Term user_name, encoding_t enc) {
encoding_t enc)
{
struct vfs *vfsp = NULL; struct vfs *vfsp = NULL;
const char *fname; const char *fname;
if (IsAtomTerm(tin)) if (IsAtomTerm(tin))
fname = RepAtom(AtomOfTerm(tin))->StrOfAE; fname = RepAtom(AtomOfTerm(tin))->StrOfAE;
@ -1287,8 +1288,10 @@ static bool fill_stream(int sno, StreamDesc *st, Term tin, const char *io_mode,
return false; return false;
} }
buf = pop_output_text_stack(i, buf); buf = pop_output_text_stack(i, buf);
Atom nat = Yap_LookupAtom(Yap_StrPrefix(buf, 32));
sno = Yap_open_buf_read_stream(buf, strlen(buf) + 1, &LOCAL_encoding, sno = Yap_open_buf_read_stream(buf, strlen(buf) + 1, &LOCAL_encoding,
MEM_BUF_MALLOC); MEM_BUF_MALLOC, nat,
MkAtomTerm(NameOfFunctor(f)));
return Yap_OpenBufWriteStream(PASS_REGS1); return Yap_OpenBufWriteStream(PASS_REGS1);
} }
} else if (!strcmp(RepAtom(NameOfFunctor(f))->StrOfAE, "popen")) { } else if (!strcmp(RepAtom(NameOfFunctor(f))->StrOfAE, "popen")) {
@ -1360,9 +1363,9 @@ static Int do_open(Term file_name, Term t2, Term tlist USES_REGS) {
} else { } else {
open_mode = AtomOfTerm(t2); open_mode = AtomOfTerm(t2);
} }
/* get options */ /* get options */
xarg *args = Yap_ArgListToVector(tlist, open_defs, OPEN_END, xarg *args =
DOMAIN_ERROR_OPEN_OPTION); Yap_ArgListToVector(tlist, open_defs, OPEN_END, DOMAIN_ERROR_OPEN_OPTION);
if (args == NULL) { if (args == NULL) {
if (LOCAL_Error_TYPE != YAP_NO_ERROR) { if (LOCAL_Error_TYPE != YAP_NO_ERROR) {
Yap_Error(LOCAL_Error_TYPE, tlist, "option handling in open/3"); Yap_Error(LOCAL_Error_TYPE, tlist, "option handling in open/3");
@ -1371,7 +1374,7 @@ static Int do_open(Term file_name, Term t2, Term tlist USES_REGS) {
} }
/* done */ /* done */
st->status = 0; st->status = 0;
const char *s_encoding; const char *s_encoding;
if (args[OPEN_ENCODING].used) { if (args[OPEN_ENCODING].used) {
tenc = args[OPEN_ENCODING].tvalue; tenc = args[OPEN_ENCODING].tvalue;
s_encoding = RepAtom(AtomOfTerm(tenc))->StrOfAE; s_encoding = RepAtom(AtomOfTerm(tenc))->StrOfAE;
@ -1432,14 +1435,14 @@ static Int do_open(Term file_name, Term t2, Term tlist USES_REGS) {
"type is ~a, must be one of binary or text", t); "type is ~a, must be one of binary or text", t);
} }
} }
st = &GLOBAL_Stream[sno]; st = &GLOBAL_Stream[sno];
if (!fill_stream(sno, st, file_name,io_mode,st->user_name,st->encoding)) { if (!fill_stream(sno, st, file_name, io_mode, st->user_name, st->encoding)) {
return false; return false;
} }
if (args[OPEN_BOM].used) { if (args[OPEN_BOM].used) {
if (args[OPEN_BOM].tvalue == TermTrue) { if (args[OPEN_BOM].tvalue == TermTrue) {
avoid_bom = false; avoid_bom = false;
needs_bom = true; needs_bom = true;
@ -1667,9 +1670,8 @@ int Yap_OpenStream(Term tin, const char *io_mode, Term user_name,
st = GLOBAL_Stream + sno; st = GLOBAL_Stream + sno;
// fname = Yap_VF(fname); // fname = Yap_VF(fname);
if (fill_stream(sno, st, tin, io_mode, user_name, enc))
if (fill_stream(sno, st, tin,io_mode,user_name,enc)) return sno;
return sno;
return -1; return -1;
} }
@ -1864,13 +1866,13 @@ static Int always_prompt_user(USES_REGS1) {
return (TRUE); return (TRUE);
} }
/** @pred close(+ _S_) is iso /** @pred close(+ _S_) is iso
Closes the stream _S_. If _S_ does not stand for a stream Closes the stream _S_. If _S_ does not stand for a stream
currently opened an error is reported. The streams user_input, currently opened an error is reported. The streams user_input,
user_output, and user_error can never be closed. user_output, and user_error can never be closed.
*/ */
static Int close1(USES_REGS1) { /* '$close'(+GLOBAL_Stream) */ static Int close1(USES_REGS1) { /* '$close'(+GLOBAL_Stream) */
int sno = CheckStream( int sno = CheckStream(
ARG1, (Input_Stream_f | Output_Stream_f | Socket_Stream_f), "close/2"); ARG1, (Input_Stream_f | Output_Stream_f | Socket_Stream_f), "close/2");
if (sno < 0) if (sno < 0)

View File

@ -124,7 +124,6 @@ extern bool Yap_PrintWarning(Term twarning);
extern void Yap_plwrite(Term, struct stream_desc *, int, int, int); extern void Yap_plwrite(Term, struct stream_desc *, int, int, int);
extern void Yap_WriteAtom(struct stream_desc *s, Atom atom); extern void Yap_WriteAtom(struct stream_desc *s, Atom atom);
extern bool Yap_WriteTerm(int output_stream, Term t, Term opts USES_REGS); extern bool Yap_WriteTerm(int output_stream, Term t, Term opts USES_REGS);
extern Term Yap_scan_num(struct stream_desc *, bool); extern Term Yap_scan_num(struct stream_desc *, bool);
extern void Yap_DefaultStreamOps(StreamDesc *st); extern void Yap_DefaultStreamOps(StreamDesc *st);

View File

@ -85,7 +85,7 @@ mem_write (void *c, const char *buf, int n)
intermediate bytges are NUL. */ intermediate bytges are NUL. */
if (cookie->eof < cookie->pos) if (cookie->eof < cookie->pos)
memset (cbuf + cookie->eof, '\0', cookie->pos - cookie->eof); memset (cbuf + cookie->eof, '\0', cookie->pos - cookie->eof);
memcpy (cbuf + cookie->pos, buf, n); memmove (cbuf + cookie->pos, buf, n);
cookie->pos += n; cookie->pos += n;
/* If the user has previously written beyond the current position, /* If the user has previously written beyond the current position,
remember what the trailing NUL is overwriting. Otherwise, remember what the trailing NUL is overwriting. Otherwise,

File diff suppressed because it is too large Load Diff

View File

@ -683,7 +683,7 @@ static xarg *generate_property(int sno, Term t2,
} }
static Int cont_stream_property(USES_REGS1) { /* current_stream */ static Int cont_stream_property(USES_REGS1) { /* current_stream */
bool det; bool det = false;
xarg *args; xarg *args;
int i = IntOfTerm(EXTRA_CBACK_ARG(2, 1)); int i = IntOfTerm(EXTRA_CBACK_ARG(2, 1));
stream_property_choices_t p = STREAM_PROPERTY_END; stream_property_choices_t p = STREAM_PROPERTY_END;
@ -705,7 +705,7 @@ static Int cont_stream_property(USES_REGS1) { /* current_stream */
if (LOCAL_Error_TYPE != YAP_NO_ERROR) { if (LOCAL_Error_TYPE != YAP_NO_ERROR) {
if (LOCAL_Error_TYPE == DOMAIN_ERROR_GENERIC_ARGUMENT) if (LOCAL_Error_TYPE == DOMAIN_ERROR_GENERIC_ARGUMENT)
LOCAL_Error_TYPE = DOMAIN_ERROR_STREAM_PROPERTY_OPTION; LOCAL_Error_TYPE = DOMAIN_ERROR_STREAM_PROPERTY_OPTION;
Yap_Error(LOCAL_Error_TYPE, t2, NULL); Yap_ThrowError(LOCAL_Error_TYPE, t2, NULL);
return false; return false;
} }
cut_fail(); cut_fail();
@ -714,16 +714,17 @@ static Int cont_stream_property(USES_REGS1) { /* current_stream */
if (IsAtomTerm(args[STREAM_PROPERTY_ALIAS].tvalue)) { if (IsAtomTerm(args[STREAM_PROPERTY_ALIAS].tvalue)) {
// one solution only // one solution only
i = Yap_CheckAlias(AtomOfTerm(args[STREAM_PROPERTY_ALIAS].tvalue)); i = Yap_CheckAlias(AtomOfTerm(args[STREAM_PROPERTY_ALIAS].tvalue));
free(args) UNLOCK(GLOBAL_Stream[i].streamlock); UNLOCK(GLOBAL_Stream[i].streamlock);
if (i < 0 || !Yap_unify(ARG1, Yap_MkStream(i))) { if (i < 0 || !Yap_unify(ARG1, Yap_MkStream(i))) {
free(args);
cut_fail(); cut_fail();
} }
cut_succeed(); det = true;
} }
LOCK(GLOBAL_Stream[i].streamlock); LOCK(GLOBAL_Stream[i].streamlock);
rc = do_stream_property(i, args PASS_REGS); rc = do_stream_property(i, args PASS_REGS);
UNLOCK(GLOBAL_Stream[i].streamlock); UNLOCK(GLOBAL_Stream[i].streamlock);
if (IsVarTerm(t1)) { if (!det && IsVarTerm(t1)) {
if (rc) if (rc)
rc = Yap_unify(ARG1, Yap_MkStream(i)); rc = Yap_unify(ARG1, Yap_MkStream(i));
if (p == STREAM_PROPERTY_END) { if (p == STREAM_PROPERTY_END) {
@ -743,7 +744,7 @@ static Int cont_stream_property(USES_REGS1) { /* current_stream */
} }
} else { } else {
// done // done
det = (p == STREAM_PROPERTY_END); det = det || (p == STREAM_PROPERTY_END);
} }
free(args); free(args);
if (rc) { if (rc) {
@ -998,7 +999,8 @@ static void CloseStream(int sno) {
// __android_log_print(ANDROID_LOG_INFO, "YAPDroid", "close stream <%d>", // __android_log_print(ANDROID_LOG_INFO, "YAPDroid", "close stream <%d>",
// sno); // sno);
VFS_t *me; VFS_t *me;
if ((me = GLOBAL_Stream[sno].vfs) != NULL && //fprintf( stderr, "- %d\n",sno);
if ((me = GLOBAL_Stream[sno].vfs) != NULL &&
GLOBAL_Stream[sno].file == NULL) { GLOBAL_Stream[sno].file == NULL) {
if (me->close) { if (me->close) {
me->close(sno); me->close(sno);

View File

@ -93,7 +93,7 @@ static Term readFromBuffer(const char *s, Term opts) {
int sno; int sno;
encoding_t enc = ENC_ISO_UTF8; encoding_t enc = ENC_ISO_UTF8;
sno = Yap_open_buf_read_stream((char *)s, strlen_utf8((unsigned char *)s), sno = Yap_open_buf_read_stream((char *)s, strlen_utf8((unsigned char *)s),
&enc, MEM_BUF_USER); &enc, MEM_BUF_USER, Yap_LookupAtom(Yap_StrPrefix((char *)s,16)), TermNone);
rval = Yap_read_term(sno, opts, 3); rval = Yap_read_term(sno, opts, 3);
Yap_CloseStream(sno); Yap_CloseStream(sno);
@ -672,7 +672,7 @@ static Int term_to_string(USES_REGS1) {
Term t2 = Deref(ARG2), rc = false, t1 = Deref(ARG1); Term t2 = Deref(ARG2), rc = false, t1 = Deref(ARG1);
const char *s; const char *s;
if (IsVarTerm(t2)) { if (IsVarTerm(t2)) {
s = Yap_TermToBuffer(ARG1, LOCAL_encoding, Quote_illegal_f | Handle_vars_f); s = Yap_TermToBuffer(t1, Quote_illegal_f | Handle_vars_f);
if (!s || !MkStringTerm(s)) { if (!s || !MkStringTerm(s)) {
Yap_Error(RESOURCE_ERROR_HEAP, t1, Yap_Error(RESOURCE_ERROR_HEAP, t1,
"Could not get memory from the operating system"); "Could not get memory from the operating system");
@ -692,7 +692,7 @@ static Int term_to_atom(USES_REGS1) {
Term t2 = Deref(ARG2), ctl, rc = false; Term t2 = Deref(ARG2), ctl, rc = false;
Atom at; Atom at;
if (IsVarTerm(t2)) { if (IsVarTerm(t2)) {
const char *s = Yap_TermToBuffer(Deref(ARG1), LOCAL_encoding, const char *s = Yap_TermToBuffer(Deref(ARG1),
Quote_illegal_f | Handle_vars_f); Quote_illegal_f | Handle_vars_f);
if (!s || !(at = Yap_UTF8ToAtom((const unsigned char *)s))) { if (!s || !(at = Yap_UTF8ToAtom((const unsigned char *)s))) {
Yap_Error(RESOURCE_ERROR_HEAP, t2, Yap_Error(RESOURCE_ERROR_HEAP, t2,
@ -711,6 +711,25 @@ static Int term_to_atom(USES_REGS1) {
Yap_unify(rc, ARG1); Yap_unify(rc, ARG1);
} }
char *Yap_TermToBuffer(Term t, int flags) {
CACHE_REGS
int sno = Yap_open_buf_write_stream(LOCAL_encoding,flags);
if (sno < 0)
return NULL;
if (t == 0)
return NULL;
else
t = Deref(t);
GLOBAL_Stream[sno].encoding = LOCAL_encoding;
GLOBAL_Stream[sno].status |= CloseOnException_Stream_f;
Yap_plwrite(t, GLOBAL_Stream + sno, 0, flags, GLOBAL_MaxPriority);
char *new = Yap_MemExportStreamPtr(sno);
Yap_CloseStream(sno);
return new;
}
void Yap_InitWriteTPreds(void) { void Yap_InitWriteTPreds(void) {
Yap_InitCPred("write_term", 2, write_term2, SyncPredFlag); Yap_InitCPred("write_term", 2, write_term2, SyncPredFlag);
Yap_InitCPred("write_term", 3, write_term3, SyncPredFlag); Yap_InitCPred("write_term", 3, write_term3, SyncPredFlag);

View File

@ -89,7 +89,7 @@ extern int Yap_GetCharForSIGINT(void);
extern Int Yap_StreamToFileNo(Term); extern Int Yap_StreamToFileNo(Term);
extern int Yap_OpenStream(Term tin, const char* io_mode, Term user_name, encoding_t enc); extern int Yap_OpenStream(Term tin, const char* io_mode, Term user_name, encoding_t enc);
extern int Yap_FileStream(FILE*, char *, Term, int, VFS_t *); extern int Yap_FileStream(FILE*, char *, Term, int, VFS_t *);
extern char *Yap_TermToBuffer(Term t, encoding_t encoding, int flags); extern char *Yap_TermToBuffer(Term t, int flags);
extern char *Yap_HandleToString(yhandle_t l, size_t sz, size_t *length, extern char *Yap_HandleToString(yhandle_t l, size_t sz, size_t *length,
encoding_t *encoding, int flags); encoding_t *encoding, int flags);
extern int Yap_GetFreeStreamD(void); extern int Yap_GetFreeStreamD(void);
@ -114,11 +114,14 @@ typedef enum mem_buf_source {
extern char *Yap_MemStreamBuf(int sno); extern char *Yap_MemStreamBuf(int sno);
extern char *Yap_StrPrefix( const char *buf, size_t n) ;
extern Term Yap_StringToNumberTerm(const char *s, encoding_t *encp, extern Term Yap_StringToNumberTerm(const char *s, encoding_t *encp,
bool error_on); bool error_on);
extern int Yap_FormatFloat(Float f, char **s, size_t sz); extern int Yap_FormatFloat(Float f, char **s, size_t sz);
extern int Yap_open_buf_read_stream(const char *buf, size_t nchars, extern int Yap_open_buf_read_stream(const char *buf, size_t nchars,
encoding_t *encp, memBufSource src); encoding_t *encp, memBufSource src, Atom name,
Term uname);
extern int Yap_open_buf_write_stream(encoding_t enc, memBufSource src); extern int Yap_open_buf_write_stream(encoding_t enc, memBufSource src);
extern Term Yap_BufferToTerm(const char *s, Term opts); extern Term Yap_BufferToTerm(const char *s, Term opts);
extern X_API Term Yap_BufferToTermWithPrioBindings(const char *s, Term opts, Term bindings, size_t sz, extern X_API Term Yap_BufferToTermWithPrioBindings(const char *s, Term opts, Term bindings, size_t sz,

View File

@ -202,7 +202,7 @@ void Yap_init_socks(char *host, long interface_port) {
soadr.sin_port = htons((short)interface_port); soadr.sin_port = htons((short)interface_port);
if (he != NULL) { if (he != NULL) {
memcpy((char *)&adr, (char *)he->h_addr_list[0], (size_t)he->h_length); memmove((char *)&adr, (char *)he->h_addr_list[0], (size_t)he->h_length);
} else { } else {
adr.s_addr = inet_addr(host); adr.s_addr = inet_addr(host);
} }
@ -635,7 +635,7 @@ static Int p_socket_bind(USES_REGS1) {
#endif #endif
return (FALSE); return (FALSE);
} }
memcpy((void *)&saddr.sin_addr, (void *)he->h_addr_list[0], he->h_length); memmove((void *)&saddr.sin_addr, (void *)he->h_addr_list[0], he->h_length);
} }
if (IsVarTerm(tport)) { if (IsVarTerm(tport)) {
port = 0; port = 0;
@ -774,7 +774,7 @@ static Int p_socket_connect(USES_REGS1) {
#endif #endif
return (FALSE); return (FALSE);
} }
memcpy((void *)&saddr.sin_addr, (void *)he->h_addr_list[0], he->h_length); memmove((void *)&saddr.sin_addr, (void *)he->h_addr_list[0], he->h_length);
} }
if (IsVarTerm(tport)) { if (IsVarTerm(tport)) {
Yap_Error(INSTANTIATION_ERROR, tport, "socket_connect/3"); Yap_Error(INSTANTIATION_ERROR, tport, "socket_connect/3");
@ -1239,7 +1239,7 @@ static Int p_hostname_address(USES_REGS1) {
#endif #endif
return false; return false;
} }
memcpy((char *)&adr, (char *)he->h_addr_list[0], (size_t)he->h_length); memmove((char *)&adr, (char *)he->h_addr_list[0], (size_t)he->h_length);
out = MkAtomTerm(Yap_LookupAtom(inet_ntoa(adr))); out = MkAtomTerm(Yap_LookupAtom(inet_ntoa(adr)));
return (Yap_unify(out, ARG2)); return (Yap_unify(out, ARG2));
} }

View File

@ -80,7 +80,7 @@ int bpredscpu(int *dop1, int rows, int *bin, int3 numpreds, int **ret)
ptr = fres; ptr = fres;
for(x = 0; x < NUM_T; x++) for(x = 0; x < NUM_T; x++)
{ {
memcpy(ptr, vec[x].data(), ini[x] * sizeof(int)); memmove(ptr, vec[x].data(), ini[x] * sizeof(int));
ptr += ini[x]; ptr += ini[x];
} }
*ret = fres; *ret = fres;

View File

@ -376,12 +376,12 @@ load_rule( void ) {
pred->is_fact = FALSE; pred->is_fact = FALSE;
x = (strlen(strname) + 1) * sizeof(char); x = (strlen(strname) + 1) * sizeof(char);
pred->predname = (char *)malloc(x); pred->predname = (char *)malloc(x);
memcpy(pred->predname, strname, x); memmove(pred->predname, strname, x);
nvec = (int32_t *)malloc(sizeof(int32_t)*(ptr-vec)); nvec = (int32_t *)malloc(sizeof(int32_t)*(ptr-vec));
memcpy(nvec, vec, sizeof(int32_t)*(ptr-vec)); memmove(nvec, vec, sizeof(int32_t)*(ptr-vec));
pred->address_host_table = nvec; pred->address_host_table = nvec;
pred->negatives = (int32_t *)malloc(sizeof(int32_t) * cont); pred->negatives = (int32_t *)malloc(sizeof(int32_t) * cont);
memcpy(pred->negatives, neg, sizeof(int32_t) * cont); memmove(pred->negatives, neg, sizeof(int32_t) * cont);
Cuda_NewRule( pred ); Cuda_NewRule( pred );
return YAP_Unify(YAP_ARG4, YAP_MkIntTerm((YAP_Int)pred)); return YAP_Unify(YAP_ARG4, YAP_MkIntTerm((YAP_Int)pred));
} }

View File

@ -180,7 +180,7 @@ void postgresRead(PGconn **ret, vector<gpunode> *L, int *inpquery, char *names,
{ {
numt = (strlen(tok) + 1) * sizeof(char); numt = (strlen(tok) + 1) * sizeof(char);
qrs[x] = (char *)malloc(numt); qrs[x] = (char *)malloc(numt);
memcpy(qrs[x], tok, numt); memmove(qrs[x], tok, numt);
} }
x += 2; x += 2;
} }
@ -264,7 +264,7 @@ void postgresRead(PGconn **ret, vector<gpunode> *L, int *inpquery, char *names,
L->at(z).address_host_table = mat; L->at(z).address_host_table = mat;
numc = (strlen(tok) + 1) * sizeof(char); numc = (strlen(tok) + 1) * sizeof(char);
L->at(z).predname = (char *)malloc(numc); L->at(z).predname = (char *)malloc(numc);
memcpy(L->at(z).predname, tok, numc); memmove(L->at(z).predname, tok, numc);
PQclear(pgr); PQclear(pgr);
tok = strtok(NULL, " "); tok = strtok(NULL, " ");
z++; z++;

Some files were not shown because too many files have changed in this diff Show More