From 74572348e23db9363db628d7a53f162bb3294b6c Mon Sep 17 00:00:00 2001 From: Jan Wielemaker Date: Mon, 18 Nov 2024 09:31:06 +0100 Subject: [PATCH] FIXED: Handling return values in stack expansion. Introduce more `bool` to correctly distinguish functions returning true/false/*_OVERFLOW from those raising exceptions and only returning true/false. --- src/pl-attvar.c | 12 ++++++------ src/pl-attvar.h | 8 ++++---- src/pl-gc.h | 21 ++++++++++++++------- src/pl-vmi.c | 2 -- src/pl-wam.c | 9 +++++---- src/pl-wam.h | 4 ++-- 6 files changed, 31 insertions(+), 25 deletions(-) diff --git a/src/pl-attvar.c b/src/pl-attvar.c index e62aa61c85..305d209dc2 100644 --- a/src/pl-attvar.c +++ b/src/pl-attvar.c @@ -75,7 +75,7 @@ assignment. The attribute list remains accessible through the trailed assignment until this is GC'ed. - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */ -int +bool PL_get_attr(DECL_LD term_t t, term_t a) { Word p = valTermRef(t); @@ -84,10 +84,10 @@ PL_get_attr(DECL_LD term_t t, term_t a) { Word ap = valPAttVar(*p); *valTermRef(a) = makeRefG(ap); /* reference, so we can assign */ - succeed; + return true; } - fail; + return false; } /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -204,7 +204,7 @@ assignAttVar(DECL_LD Word av, Word value) return; } -int +bool bind_attvar_const(DECL_LD Word p, word c) { if ( !hasGlobalSpace(0) ) { PushPtr(p); PushVal(c); @@ -249,7 +249,7 @@ alloc_attvar(DECL_LD) } -int +bool on_attvar_chain(Word avp) { GET_LD Word p, next; @@ -532,7 +532,7 @@ apply. The environment has size 1 if there is a pending exception, 2 if a wakeup was saved and 3 if both where saved. - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */ -int +bool saveWakeup(DECL_LD wakeup_state *state, int forceframe) { state->flags = 0; state->outofstack = LD->outofstack; diff --git a/src/pl-attvar.h b/src/pl-attvar.h index 6ac23cf0eb..a712186487 100644 --- a/src/pl-attvar.h +++ b/src/pl-attvar.h @@ -56,11 +56,11 @@ #define LDFUNC_DECLARATIONS void assignAttVar(Word av, Word value); -int bind_attvar_const(Word p, word c); -int saveWakeup(wakeup_state *state, int forceframe); +bool bind_attvar_const(Word p, word c); +bool saveWakeup(wakeup_state *state, int forceframe); void restoreWakeup(wakeup_state *state); -int PL_get_attr(term_t t, term_t a); -int on_attvar_chain(Word avp); +bool PL_get_attr(term_t t, term_t a); +bool on_attvar_chain(Word avp); Word alloc_attvar(void); #undef LDFUNC_DECLARATIONS diff --git a/src/pl-gc.h b/src/pl-gc.h index 79b3bd8352..770158f72c 100644 --- a/src/pl-gc.h +++ b/src/pl-gc.h @@ -96,7 +96,7 @@ void unblockGC(int flags); /* re-allow garbage collect */ *******************************/ #define ensureLocalSpace_ex(bytes) LDFUNC(ensureLocalSpace_ex, bytes) -static inline int +static inline bool ensureLocalSpace_ex(DECL_LD size_t bytes) { int rc; @@ -109,15 +109,22 @@ ensureLocalSpace_ex(DECL_LD size_t bytes) return raiseStackOverflow(rc); } -#define ensureStackSpace_ex(gcells, tcells, flags) LDFUNC(ensureStackSpace_ex, gcells, tcells, flags) -static inline int +#define ensureStackSpace_ex(gcells, tcells, flags) \ + LDFUNC(ensureStackSpace_ex, gcells, tcells, flags) + +static inline bool ensureStackSpace_ex(DECL_LD size_t gcells, size_t tcells, int flags) -{ if ( hasStackSpace(gcells, tcells) ) +{ int rc; + + if ( hasStackSpace(gcells, tcells) ) return true; - return f_ensureStackSpace(gcells+BIND_GLOBAL_SPACE, - tcells+BIND_TRAIL_SPACE, - flags); + if ( (rc=f_ensureStackSpace(gcells+BIND_GLOBAL_SPACE, + tcells+BIND_TRAIL_SPACE, + flags)) == true ) + return true; + + return raiseStackOverflow(rc); } #endif /*_PL_GC_H*/ diff --git a/src/pl-vmi.c b/src/pl-vmi.c index 888fa24597..c8639e27df 100644 --- a/src/pl-vmi.c +++ b/src/pl-vmi.c @@ -231,9 +231,7 @@ END_VMH __rc = ensureStackSpace(g, t); \ LOAD_REGISTERS(QID); \ if ( __rc != true ) \ - { raiseStackOverflow(__rc); \ THROW_EXCEPTION; \ - } \ } while(0) /* Can be used for debugging to always force GC at a place */ diff --git a/src/pl-wam.c b/src/pl-wam.c index 5b12a78625..07e0bd7a37 100644 --- a/src/pl-wam.c +++ b/src/pl-wam.c @@ -256,7 +256,8 @@ raiseSignal(PL_local_data_t *ld, int sig) do { alerted = ld->alerted; - } while ( !COMPARE_AND_SWAP_INT(&ld->alerted, alerted, alerted|ALERT_SIGNAL) ); + } while ( !COMPARE_AND_SWAP_INT(&ld->alerted, alerted, + alerted|ALERT_SIGNAL) ); return true; } @@ -268,7 +269,7 @@ raiseSignal(PL_local_data_t *ld, int sig) int pendingSignal(PL_local_data_t *ld, int sig) { if ( IS_VALID_SIGNAL(sig) && ld ) - { return WSIGMASK_ISSET(ld->signal.pending, sig) ? true : false; + { return WSIGMASK_ISSET(ld->signal.pending, sig); } return -1; @@ -1440,10 +1441,10 @@ callBreakHook(DECL_LD LocalFrame frame, Choice bfr, Trail a raw pointer after we know there is insufficient tail space. - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */ -int +bool grow_trail_ptr(DECL_LD Word p) { PushPtr(p); - int rc = ensureGlobalSpace(0, ALLOW_GC); + bool rc = ensureGlobalSpace(0, ALLOW_GC); PopPtr(p); if ( !rc ) return false; diff --git a/src/pl-wam.h b/src/pl-wam.h index 5210c8010f..e7acdb02c0 100644 --- a/src/pl-wam.h +++ b/src/pl-wam.h @@ -79,7 +79,7 @@ Module contextModule(LocalFrame fr); void setContextModule(LocalFrame fr, Module context); bool existingChoice(Choice ch); bool existingFrame(LocalFrame fr); -int grow_trail_ptr(Word p); +bool grow_trail_ptr(Word p); bool handles_unwind(qid_t qid, unsigned int flags); #ifdef O_DEBUG char * chp_chars(Choice ch); @@ -90,7 +90,7 @@ char * chp_chars(Choice ch); #define getProcDefinition(proc) getLocalProcDefinition(proc->definition) #define trail_ptr(p) LDFUNC(trail_ptr, p) -static inline int +static inline bool trail_ptr(DECL_LD Word p) { if ( hasTrailSpace(1) ) { (tTop++)->address = p;