Skip to content

Commit

Permalink
FIXED: Handling return values in stack expansion.
Browse files Browse the repository at this point in the history
Introduce more `bool` to correctly distinguish functions returning
true/false/*_OVERFLOW from those raising exceptions and only returning
true/false.
  • Loading branch information
JanWielemaker committed Nov 18, 2024
1 parent c1ce6d3 commit 7457234
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 25 deletions.
12 changes: 6 additions & 6 deletions src/pl-attvar.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand All @@ -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;
}

/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -249,7 +249,7 @@ alloc_attvar(DECL_LD)
}


int
bool
on_attvar_chain(Word avp)
{ GET_LD
Word p, next;
Expand Down Expand Up @@ -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;
Expand Down
8 changes: 4 additions & 4 deletions src/pl-attvar.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
21 changes: 14 additions & 7 deletions src/pl-gc.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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*/
2 changes: 0 additions & 2 deletions src/pl-vmi.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down
9 changes: 5 additions & 4 deletions src/pl-wam.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions src/pl-wam.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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;
Expand Down

0 comments on commit 7457234

Please sign in to comment.