- Android fixes
- null pointers
This commit is contained in:
@@ -2167,7 +2167,7 @@ X_API FILE *YAP_TermToStream(Term t) {
|
||||
X_API void YAP_EndConsult(int sno, int *osnop, const char *full) {
|
||||
BACKUP_MACHINE_REGS();
|
||||
Yap_CloseStream(sno);
|
||||
Yap_ChDir(full);
|
||||
Yap_ChDir(dirname(full));
|
||||
if (osnop >= 0)
|
||||
Yap_AddAlias(AtomLoopStream, *osnop);
|
||||
Yap_end_consult();
|
||||
|
48
C/globals.c
48
C/globals.c
@@ -351,18 +351,26 @@ static inline void clean_dirty_tr(tr_fr_ptr TR0 USES_REGS) {
|
||||
}
|
||||
}
|
||||
|
||||
#define expand_stack(S0,SP,SF,TYPE) \
|
||||
size_t sz = SF-S0, used = SP-S0; \
|
||||
S0 = Realloc(S0, (1024+sz)*sizeof(TYPE) PASS_REGS); \
|
||||
SP = S0+used; SF = S0+sz;
|
||||
|
||||
static int copy_complex_term(register CELL *pt0, register CELL *pt0_end,
|
||||
int share, int copy_att_vars, CELL *ptf,
|
||||
CELL *HLow USES_REGS) {
|
||||
|
||||
struct cp_frame *to_visit0,
|
||||
*to_visit = (struct cp_frame *)Yap_PreAllocCodeSpace();
|
||||
int lvl = push_text_stack();
|
||||
struct cp_frame *to_visit0, *to_visit = Malloc(1024*sizeof(struct cp_frame));
|
||||
struct cp_frame *to_visit_max;
|
||||
|
||||
CELL *HB0 = HB;
|
||||
tr_fr_ptr TR0 = TR;
|
||||
int ground = TRUE;
|
||||
|
||||
HB = HLow;
|
||||
to_visit0 = to_visit;
|
||||
to_visit_max = to_visit+1024;
|
||||
loop:
|
||||
while (pt0 < pt0_end) {
|
||||
register CELL d0;
|
||||
@@ -382,8 +390,8 @@ loop:
|
||||
*ptf = AbsPair(HR);
|
||||
ptf++;
|
||||
#ifdef RATIONAL_TREES
|
||||
if (to_visit + 1 >= (struct cp_frame *)AuxSp) {
|
||||
goto heap_overflow;
|
||||
if (to_visit >= to_visit_max-32) {
|
||||
expand_stack(to_visit0, to_visit, to_visit_max, struct cp_frame);
|
||||
}
|
||||
to_visit->start_cp = pt0;
|
||||
to_visit->end_cp = pt0_end;
|
||||
@@ -395,8 +403,9 @@ loop:
|
||||
to_visit++;
|
||||
#else
|
||||
if (pt0 < pt0_end) {
|
||||
if (to_visit + 1 >= (CELL **)AuxSp) {
|
||||
goto heap_overflow;
|
||||
if (to_visit + 32 >= to_visit_max - 32) {
|
||||
expand_stack(to_visit0, to_visit, to_visit_max, struct cp_frame);
|
||||
|
||||
}
|
||||
to_visit->start_cp = pt0;
|
||||
to_visit->end_cp = pt0_end;
|
||||
@@ -493,8 +502,8 @@ loop:
|
||||
ptf++;
|
||||
/* store the terms to visit */
|
||||
#ifdef RATIONAL_TREES
|
||||
if (to_visit + 1 >= (struct cp_frame *)AuxSp) {
|
||||
goto heap_overflow;
|
||||
if (to_visit + 1 >= to_visit_max) {
|
||||
expand_stack(to_visit0, to_visit, to_visit_max, struct cp_frame);
|
||||
}
|
||||
to_visit->start_cp = pt0;
|
||||
to_visit->end_cp = pt0_end;
|
||||
@@ -507,7 +516,7 @@ loop:
|
||||
#else
|
||||
if (pt0 < pt0_end) {
|
||||
if (to_visit++ >= (CELL **)AuxSp) {
|
||||
goto heap_overflow;
|
||||
expand_stack(to_visit0, to_visit, to_visit_max, struct cp_frame);
|
||||
}
|
||||
to_visit->start_cp = pt0;
|
||||
to_visit->end_cp = pt0_end;
|
||||
@@ -593,6 +602,7 @@ loop:
|
||||
HB = HB0;
|
||||
clean_dirty_tr(TR0 PASS_REGS);
|
||||
/* follow chain of multi-assigned variables */
|
||||
pop_text_stack(lvl);
|
||||
return 0;
|
||||
|
||||
overflow:
|
||||
@@ -611,26 +621,9 @@ overflow:
|
||||
}
|
||||
#endif
|
||||
reset_trail(TR0);
|
||||
pop_text_stack(lvl);
|
||||
return -1;
|
||||
|
||||
heap_overflow:
|
||||
/* oops, we're in trouble */
|
||||
HR = HLow;
|
||||
/* we've done it */
|
||||
/* restore our nice, friendly, term to its original state */
|
||||
HB = HB0;
|
||||
#ifdef RATIONAL_TREES
|
||||
while (to_visit > to_visit0) {
|
||||
to_visit--;
|
||||
pt0 = to_visit->start_cp;
|
||||
pt0_end = to_visit->end_cp;
|
||||
ptf = to_visit->to;
|
||||
*pt0 = to_visit->oldv;
|
||||
}
|
||||
#endif
|
||||
reset_trail(TR0);
|
||||
return -2;
|
||||
|
||||
trail_overflow:
|
||||
/* oops, we're in trouble */
|
||||
HR = HLow;
|
||||
@@ -647,6 +640,7 @@ trail_overflow:
|
||||
}
|
||||
#endif
|
||||
reset_trail(TR0);
|
||||
pop_text_stack(lvl);
|
||||
return -4;
|
||||
}
|
||||
|
||||
|
9
C/text.c
9
C/text.c
@@ -217,8 +217,7 @@ void *Yap_InitTextAllocator(void) {
|
||||
|
||||
static size_t MaxTmp(USES_REGS1) {
|
||||
|
||||
return ((char *)LOCAL_TextBuffer->buf + LOCAL_TextBuffer->sz) -
|
||||
(char *)LOCAL_TextBuffer->ptr;
|
||||
return 1025;
|
||||
}
|
||||
|
||||
static Term Globalize(Term v USES_REGS) {
|
||||
@@ -282,7 +281,7 @@ static void *codes2buf(Term t0, void *b0, bool *get_codes USES_REGS) {
|
||||
return NULL;
|
||||
}
|
||||
if (!IsAtomTerm(hd)) {
|
||||
Yap_ThrowError(TYPE_ERROR_CHARACTER, hd, "scanning list of atoms");
|
||||
Yap_ThrowError(TYPE_ERROR_CHARACTER, hd, "scanning list of texts");
|
||||
return NULL;
|
||||
}
|
||||
const char *code = RepAtom(AtomOfTerm(hd))->StrOfAE;
|
||||
@@ -441,7 +440,7 @@ unsigned char *Yap_readText(seq_tv_t *inp USES_REGS) {
|
||||
LOCAL_ActiveError->errorRawTerm = inp->val.t;
|
||||
}
|
||||
if (LOCAL_Error_TYPE != YAP_NO_ERROR) {
|
||||
pop_text_stack(lvl);
|
||||
Yap_ThrowError(LOCAL_Error_TYPE, inp->val.t, "Converting to text from term ");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@@ -508,7 +507,6 @@ unsigned char *Yap_readText(seq_tv_t *inp USES_REGS) {
|
||||
s = Malloc(2 * MaxTmp(PASS_REGS1));
|
||||
if (snprintf(s, MaxTmp(PASS_REGS1) - 1, Int_FORMAT,
|
||||
IntegerOfTerm(inp->val.t)) < 0) {
|
||||
pop_text_stack(lvl);
|
||||
AUX_ERROR(inp->val.t, 2 * MaxTmp(PASS_REGS1), s, char);
|
||||
}
|
||||
return pop_output_text_stack(lvl, s);
|
||||
@@ -528,7 +526,6 @@ unsigned char *Yap_readText(seq_tv_t *inp USES_REGS) {
|
||||
char *s;
|
||||
s = Malloc(MaxTmp());
|
||||
if (!Yap_mpz_to_string(Yap_BigIntOfTerm(inp->val.t), s, MaxTmp() - 1, 10)) {
|
||||
pop_text_stack(lvl);
|
||||
AUX_ERROR(inp->val.t, MaxTmp(PASS_REGS1), s, char);
|
||||
}
|
||||
return inp->val.uc = pop_output_text_stack(lvl, s);
|
||||
|
@@ -182,8 +182,6 @@ static bool consult(const char *b_file USES_REGS) {
|
||||
CACHE_REGS
|
||||
YAP_Reset(YAP_FULL_RESET, false);
|
||||
Yap_StartSlots();
|
||||
__android_log_print(ANDROID_LOG_INFO, "YAPDroid", "read %s <%d>", b_file,
|
||||
GLOBAL_Stream[c_stream].linecount);
|
||||
Term vs = MkVarTerm(), pos = MkVarTerm();
|
||||
t = YAP_ReadClauseFromStream(c_stream, vs, pos);
|
||||
// Yap_GetNèwSlot(t);
|
||||
|
Reference in New Issue
Block a user