diff --git a/src/pl-trace.c b/src/pl-trace.c index ae69b7364f..5db944a784 100644 --- a/src/pl-trace.c +++ b/src/pl-trace.c @@ -112,7 +112,7 @@ PL_put_frame(term_t t, LocalFrame fr) } -static int +static bool PL_get_frame(term_t r, LocalFrame *fr) { GET_LD intptr_t i; @@ -121,18 +121,16 @@ PL_get_frame(term_t r, LocalFrame *fr) if ( PL_get_intptr(r, &i) ) { LocalFrame f = ((LocalFrame)((Word)lBase + i)); - if ( !(f >= lBase && f < lTop) ) - fail; - *fr = f; - - succeed; + if ( existingFrame(f) ) + { *fr = f; + return true; + } } else if ( PL_get_atom(r, &a) && a == ATOM_none ) { *fr = NULL; - - succeed; + return true; } - fail; + return false; } @@ -149,7 +147,7 @@ PL_put_choice(term_t t, Choice ch) } -static int +static bool PL_unify_choice(term_t t, Choice ch) { GET_LD @@ -163,7 +161,7 @@ PL_unify_choice(term_t t, Choice ch) #define valid_choice(ch) LDFUNC(valid_choice, ch) -static inline int +static inline bool valid_choice(DECL_LD Choice ch) { if ( (int)ch->type >= 0 && (int)ch->type <= CHP_DEBUG && onStack(local, ch->frame) ) @@ -173,12 +171,12 @@ valid_choice(DECL_LD Choice ch) } -static int +static bool PL_get_choice(term_t r, Choice *chp) { GET_LD - long i; + intptr_t i; - if ( PL_get_long(r, &i) ) + if ( PL_get_intptr(r, &i) ) { Choice ch = ((Choice)((Word)lBase + i)); if ( !(ch >= (Choice)lBase && ch < (Choice)lTop) || @@ -186,7 +184,7 @@ PL_get_choice(term_t r, Choice *chp) return PL_error(NULL, 0, NULL, ERR_EXISTENCE, ATOM_choice, r); *chp = ch; - succeed; + return true; } else return PL_error(NULL, 0, NULL, ERR_TYPE, ATOM_choice, r); } @@ -200,7 +198,7 @@ tracer. `No-debug' code has HIDE_CHILDS. Calls to it must be visible if the parent is a debug frame. - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */ -int +bool isDebugFrame(LocalFrame FR) { if ( isoff(FR->predicate, TRACE_ME) ) return false; /* hidden predicate */ @@ -224,7 +222,7 @@ isDebugFrame(LocalFrame FR) } else { QueryFrame qf = queryOfFrame(FR); - return (qf->flags & PL_Q_NODEBUG) ? false : true; + return !(qf->flags & PL_Q_NODEBUG); } } @@ -1782,8 +1780,8 @@ interruptHandler(int sig) if ( (ex=PL_new_term_ref()) && PL_unify_term(ex, PL_FUNCTOR, FUNCTOR_unwind1, - PL_FUNCTOR, FUNCTOR_thread_exit1, - PL_ATOM, ATOM_true) ) + PL_FUNCTOR, FUNCTOR_thread_exit1, + PL_ATOM, ATOM_true) ) return; } #endif diff --git a/src/pl-trace.h b/src/pl-trace.h index ba2c8fd8f9..f0c0e13edf 100644 --- a/src/pl-trace.h +++ b/src/pl-trace.h @@ -52,7 +52,7 @@ #define LDFUNC_DECLARATIONS void suspendTrace(int suspend); /* suspend/resume tracing */ -int isDebugFrame(LocalFrame FR); +bool isDebugFrame(LocalFrame FR); int tracePort(LocalFrame frame, Choice bfr, int port, Code PC); void initTracer(void); diff --git a/src/pl-wam.c b/src/pl-wam.c index c4b730e888..5b12a78625 100644 --- a/src/pl-wam.c +++ b/src/pl-wam.c @@ -2521,7 +2521,7 @@ chp_chars(Choice ch) #endif -int +bool existingChoice(DECL_LD Choice ch) { if ( onStack(local, ch) && onStack(local, ch->frame) && (int)ch->type >= 0 && (int)ch->type <= CHP_DEBUG ) @@ -2537,6 +2537,24 @@ existingChoice(DECL_LD Choice ch) } +bool +existingFrame(DECL_LD LocalFrame fr) +{ for(;;) + { if ( !onStack(local, fr) ) + return false; + if ( !isFrame(fr) ) + return false; + + if ( fr->parent ) + { fr = fr->parent; + } else + { QueryFrame qf = queryOfFrame(fr); + return qf->magic == QID_MAGIC; + } + } +} + + /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - discardChoicesAfter() discards all choicepoints created after fr, while calling possible hooks on the frames. If the `reason` is diff --git a/src/pl-wam.h b/src/pl-wam.h index ffa29d2499..5210c8010f 100644 --- a/src/pl-wam.h +++ b/src/pl-wam.h @@ -52,6 +52,7 @@ #define PL_next_solution(qid) LDFUNC(PL_next_solution, qid) #define foreignWakeup(ex) LDFUNC(foreignWakeup, ex) #define existingChoice(ch) LDFUNC(existingChoice, ch) +#define existingFrame(fr) LDFUNC(existingFrame, fr) #define grow_trail_ptr(p) LDFUNC(grow_trail_ptr, p) #define handles_unwind(qid, flags) LDFUNC(handles_unwind, qid, flags) #endif /*USE_LD_MACROS*/ @@ -76,7 +77,8 @@ bool raiseSignal(PL_local_data_t *ld, int sig); int pendingSignal(PL_local_data_t *ld, int sig); Module contextModule(LocalFrame fr); void setContextModule(LocalFrame fr, Module context); -int existingChoice(Choice ch); +bool existingChoice(Choice ch); +bool existingFrame(LocalFrame fr); int grow_trail_ptr(Word p); bool handles_unwind(qid_t qid, unsigned int flags); #ifdef O_DEBUG