Jump and Throw need to store the term away, if they try to use arena
the term will hang in the stack (#152).
This commit is contained in:
parent
8213d52af4
commit
06d30b9fc9
48
C/exec.c
48
C/exec.c
@ -1453,7 +1453,7 @@ JumpToEnv(Term t) {
|
||||
if (EX)
|
||||
return FALSE;
|
||||
/* just keep the throwed object away, we don't need to care about it */
|
||||
if (!(t = Yap_SetGlobalVal(AtomCatch, t))) {
|
||||
if (!(BallTerm = Yap_StoreTermInDB(t, 0))) {
|
||||
/* fat chance */
|
||||
siglongjmp(Yap_RestartEnv,1);
|
||||
}
|
||||
@ -1685,11 +1685,52 @@ p_debug_on(void)
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static Term
|
||||
GetException(void)
|
||||
{
|
||||
Term t = 0L;
|
||||
if (BallTerm) {
|
||||
do {
|
||||
t = Yap_PopTermFromDB(BallTerm);
|
||||
if (t == 0) {
|
||||
if (Yap_Error_TYPE == OUT_OF_ATTVARS_ERROR) {
|
||||
Yap_Error_TYPE = YAP_NO_ERROR;
|
||||
if (!Yap_growglobal(NULL)) {
|
||||
Yap_Error(OUT_OF_ATTVARS_ERROR, TermNil, Yap_ErrorMessage);
|
||||
return FALSE;
|
||||
}
|
||||
} else {
|
||||
Yap_Error_TYPE = YAP_NO_ERROR;
|
||||
if (!Yap_growstack(BallTerm->NOfCells*CellSize)) {
|
||||
Yap_Error(OUT_OF_STACK_ERROR, TermNil, Yap_ErrorMessage);
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
}
|
||||
} while (t == 0);
|
||||
BallTerm = NULL;
|
||||
}
|
||||
return t;
|
||||
}
|
||||
|
||||
static Int
|
||||
p_reset_exception(void)
|
||||
{
|
||||
Term t;
|
||||
EX = 0L;
|
||||
return TRUE;
|
||||
t = GetException();
|
||||
if (!t)
|
||||
return FALSE;
|
||||
return Yap_unify(t, ARG1);
|
||||
}
|
||||
|
||||
static Int
|
||||
p_get_exception(void)
|
||||
{
|
||||
Term t = GetException();
|
||||
if (!t)
|
||||
return FALSE;
|
||||
return Yap_unify(t, ARG1);
|
||||
}
|
||||
|
||||
void
|
||||
@ -1745,7 +1786,8 @@ Yap_InitExecFs(void)
|
||||
Yap_InitCPred("$creep_allowed", 0, p_creep_allowed, HiddenPredFlag);
|
||||
Yap_InitCPred("$generate_pred_info", 4, p_generate_pred_info, HiddenPredFlag);
|
||||
Yap_InitCPred("$uncaught_throw", 0, p_uncaught_throw, HiddenPredFlag);
|
||||
Yap_InitCPred("$reset_exception", 0, p_reset_exception, HiddenPredFlag);
|
||||
Yap_InitCPred("$reset_exception", 1, p_reset_exception, HiddenPredFlag);
|
||||
Yap_InitCPred("$get_exception", 1, p_get_exception, HiddenPredFlag);
|
||||
}
|
||||
|
||||
|
||||
|
1
C/init.c
1
C/init.c
@ -1199,6 +1199,7 @@ InitCodes(void)
|
||||
Yap_heap_regs->wl.consultbase = Yap_heap_regs->wl.consultsp =
|
||||
Yap_heap_regs->wl.consultlow + Yap_heap_regs->wl.consultcapacity;
|
||||
#endif /* YAPOR */
|
||||
Yap_heap_regs->wl.ball_term = NULL;
|
||||
|
||||
/* make sure no one else can use these two atoms */
|
||||
CurrentModule = 0;
|
||||
|
@ -109,6 +109,7 @@ typedef struct worker_local_struct {
|
||||
Int depth_arenas;
|
||||
char *scanner_stack;
|
||||
struct scanner_extra_alloc *scanner_extra_blocks;
|
||||
struct DB_TERM *ball_term;
|
||||
#if defined(YAPOR) || defined(THREADS)
|
||||
lockvar signal_lock; /* protect signal handlers from IPIs */
|
||||
struct pred_entry *wpp;
|
||||
@ -325,6 +326,7 @@ extern struct various_codes *Yap_heap_regs;
|
||||
#define DepthArenas Yap_heap_regs->WL.depth_arenas
|
||||
#define ScannerStack Yap_heap_regs->WL.scanner_stack
|
||||
#define ScannerExtraBlocks Yap_heap_regs->WL.scanner_extra_blocks
|
||||
#define BallTerm Yap_heap_regs->WL.ball_term
|
||||
#define Yap_BigTmp Yap_heap_regs->WL.big_tmp
|
||||
#define ActiveSignals Yap_heap_regs->WL.active_signals
|
||||
#define IPredArity Yap_heap_regs->WL.i_pred_arity
|
||||
|
@ -967,6 +967,11 @@ restore_codes(void)
|
||||
/* restore consult stack. It consists of heap pointers, so it
|
||||
is easy to fix.
|
||||
*/
|
||||
if (Yap_heap_regs->wl.ball_term) {
|
||||
Yap_heap_regs->wl.ball_term =
|
||||
DBTermAdjust(Yap_heap_regs->wl.ball_term);
|
||||
RestoreDBTerm(Yap_heap_regs->wl.ball_term, TRUE);
|
||||
}
|
||||
Yap_heap_regs->wl.consultlow =
|
||||
ConsultObjAdjust(Yap_heap_regs->wl.consultlow);
|
||||
Yap_heap_regs->wl.consultbase =
|
||||
|
@ -1 +1 @@
|
||||
Subproject commit c325e4564bb8d4e32c27f2061df85f13d315974e
|
||||
Subproject commit f6a79007615bf46dc79712c41d61289834f28ba3
|
@ -1 +1 @@
|
||||
Subproject commit a2d2f03107eecd45462cd61a678035132cf06326
|
||||
Subproject commit eb6d27251c2548c25e6d37fff2a27a014caaa7aa
|
@ -1165,8 +1165,7 @@ catch(G, C, A) :-
|
||||
%
|
||||
throw(_Ball) :-
|
||||
% use existing ball
|
||||
nb_getval('$catch',Ball),
|
||||
nb_delete('$catch'),
|
||||
'$get_exception'(Ball),
|
||||
!,
|
||||
'$jump_env_and_store_ball'(Ball).
|
||||
throw(Ball) :-
|
||||
@ -1180,9 +1179,7 @@ throw(Ball) :-
|
||||
|
||||
'$handle_throw'(_, _, _).
|
||||
'$handle_throw'(C, A, _Ball) :-
|
||||
nb_getval('$catch',Ball),
|
||||
nb_delete('$catch'),
|
||||
'$reset_exception',
|
||||
'$reset_exception'(Ball),
|
||||
% reset info
|
||||
('catch_ball'(Ball, C) ->
|
||||
'$execute'(A)
|
||||
|
@ -237,9 +237,9 @@ print_message(force(_Severity), Msg) :- !,
|
||||
print_message(error, error(Msg,Info)) :- var(Info), !,
|
||||
print_message(error, error(Msg, '')).
|
||||
print_message(error, error(Msg,[Info|local_sp(P,CP,Envs,CPs)])) :- !,
|
||||
nb_setval(sp_info,local_sp(P,CP,Envs,CPs)),
|
||||
recorda(sp_info,local_sp(P,CP,Envs,CPs),R),
|
||||
print_message(error, error(Msg, Info)),
|
||||
nb_setval(sp_info,[]).
|
||||
erase(R).
|
||||
print_message(Severity, Msg) :-
|
||||
nonvar(Severity), nonvar(Msg),
|
||||
'$notrace'(user:portray_message(Severity, Msg)), !.
|
||||
|
@ -75,7 +75,7 @@ generate_message(M) -->
|
||||
|
||||
stack_dump(error(_,_)) -->
|
||||
{ fail },
|
||||
{ nb_getval(sp_info,local_sp(P,CP,Envs,CPs)) },
|
||||
{ recorded(sp_info,local_sp(P,CP,Envs,CPs),_) },
|
||||
{ Envs = [_|_] ; CPs = [_|_] }, !,
|
||||
[nl],
|
||||
'$hacks':display_stack_info(CPs, Envs, 20, CP).
|
||||
@ -490,7 +490,7 @@ prefix(warning, '% ', user_error) -->
|
||||
; ['Warning: [Thread ~d ]' - Id, nl ]
|
||||
).
|
||||
prefix(error, ' ', user_error) -->
|
||||
{ nb_getval(sp_info,local_sp(P,_,_,_)) },
|
||||
{ recorded(sp_info,local_sp(P,_,_,_),_) },
|
||||
{ thread_self(Id) },
|
||||
( { Id == main }
|
||||
-> [ 'ERROR at ' ]
|
||||
|
Reference in New Issue
Block a user