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)
|
if (EX)
|
||||||
return FALSE;
|
return FALSE;
|
||||||
/* just keep the throwed object away, we don't need to care about it */
|
/* 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 */
|
/* fat chance */
|
||||||
siglongjmp(Yap_RestartEnv,1);
|
siglongjmp(Yap_RestartEnv,1);
|
||||||
}
|
}
|
||||||
@ -1685,11 +1685,52 @@ p_debug_on(void)
|
|||||||
return TRUE;
|
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
|
static Int
|
||||||
p_reset_exception(void)
|
p_reset_exception(void)
|
||||||
{
|
{
|
||||||
|
Term t;
|
||||||
EX = 0L;
|
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
|
void
|
||||||
@ -1745,7 +1786,8 @@ Yap_InitExecFs(void)
|
|||||||
Yap_InitCPred("$creep_allowed", 0, p_creep_allowed, HiddenPredFlag);
|
Yap_InitCPred("$creep_allowed", 0, p_creep_allowed, HiddenPredFlag);
|
||||||
Yap_InitCPred("$generate_pred_info", 4, p_generate_pred_info, HiddenPredFlag);
|
Yap_InitCPred("$generate_pred_info", 4, p_generate_pred_info, HiddenPredFlag);
|
||||||
Yap_InitCPred("$uncaught_throw", 0, p_uncaught_throw, 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.consultbase = Yap_heap_regs->wl.consultsp =
|
||||||
Yap_heap_regs->wl.consultlow + Yap_heap_regs->wl.consultcapacity;
|
Yap_heap_regs->wl.consultlow + Yap_heap_regs->wl.consultcapacity;
|
||||||
#endif /* YAPOR */
|
#endif /* YAPOR */
|
||||||
|
Yap_heap_regs->wl.ball_term = NULL;
|
||||||
|
|
||||||
/* make sure no one else can use these two atoms */
|
/* make sure no one else can use these two atoms */
|
||||||
CurrentModule = 0;
|
CurrentModule = 0;
|
||||||
|
@ -109,6 +109,7 @@ typedef struct worker_local_struct {
|
|||||||
Int depth_arenas;
|
Int depth_arenas;
|
||||||
char *scanner_stack;
|
char *scanner_stack;
|
||||||
struct scanner_extra_alloc *scanner_extra_blocks;
|
struct scanner_extra_alloc *scanner_extra_blocks;
|
||||||
|
struct DB_TERM *ball_term;
|
||||||
#if defined(YAPOR) || defined(THREADS)
|
#if defined(YAPOR) || defined(THREADS)
|
||||||
lockvar signal_lock; /* protect signal handlers from IPIs */
|
lockvar signal_lock; /* protect signal handlers from IPIs */
|
||||||
struct pred_entry *wpp;
|
struct pred_entry *wpp;
|
||||||
@ -325,6 +326,7 @@ extern struct various_codes *Yap_heap_regs;
|
|||||||
#define DepthArenas Yap_heap_regs->WL.depth_arenas
|
#define DepthArenas Yap_heap_regs->WL.depth_arenas
|
||||||
#define ScannerStack Yap_heap_regs->WL.scanner_stack
|
#define ScannerStack Yap_heap_regs->WL.scanner_stack
|
||||||
#define ScannerExtraBlocks Yap_heap_regs->WL.scanner_extra_blocks
|
#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 Yap_BigTmp Yap_heap_regs->WL.big_tmp
|
||||||
#define ActiveSignals Yap_heap_regs->WL.active_signals
|
#define ActiveSignals Yap_heap_regs->WL.active_signals
|
||||||
#define IPredArity Yap_heap_regs->WL.i_pred_arity
|
#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
|
/* restore consult stack. It consists of heap pointers, so it
|
||||||
is easy to fix.
|
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 =
|
Yap_heap_regs->wl.consultlow =
|
||||||
ConsultObjAdjust(Yap_heap_regs->wl.consultlow);
|
ConsultObjAdjust(Yap_heap_regs->wl.consultlow);
|
||||||
Yap_heap_regs->wl.consultbase =
|
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) :-
|
throw(_Ball) :-
|
||||||
% use existing ball
|
% use existing ball
|
||||||
nb_getval('$catch',Ball),
|
'$get_exception'(Ball),
|
||||||
nb_delete('$catch'),
|
|
||||||
!,
|
!,
|
||||||
'$jump_env_and_store_ball'(Ball).
|
'$jump_env_and_store_ball'(Ball).
|
||||||
throw(Ball) :-
|
throw(Ball) :-
|
||||||
@ -1180,9 +1179,7 @@ throw(Ball) :-
|
|||||||
|
|
||||||
'$handle_throw'(_, _, _).
|
'$handle_throw'(_, _, _).
|
||||||
'$handle_throw'(C, A, _Ball) :-
|
'$handle_throw'(C, A, _Ball) :-
|
||||||
nb_getval('$catch',Ball),
|
'$reset_exception'(Ball),
|
||||||
nb_delete('$catch'),
|
|
||||||
'$reset_exception',
|
|
||||||
% reset info
|
% reset info
|
||||||
('catch_ball'(Ball, C) ->
|
('catch_ball'(Ball, C) ->
|
||||||
'$execute'(A)
|
'$execute'(A)
|
||||||
|
@ -237,9 +237,9 @@ print_message(force(_Severity), Msg) :- !,
|
|||||||
print_message(error, error(Msg,Info)) :- var(Info), !,
|
print_message(error, error(Msg,Info)) :- var(Info), !,
|
||||||
print_message(error, error(Msg, '')).
|
print_message(error, error(Msg, '')).
|
||||||
print_message(error, error(Msg,[Info|local_sp(P,CP,Envs,CPs)])) :- !,
|
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)),
|
print_message(error, error(Msg, Info)),
|
||||||
nb_setval(sp_info,[]).
|
erase(R).
|
||||||
print_message(Severity, Msg) :-
|
print_message(Severity, Msg) :-
|
||||||
nonvar(Severity), nonvar(Msg),
|
nonvar(Severity), nonvar(Msg),
|
||||||
'$notrace'(user:portray_message(Severity, Msg)), !.
|
'$notrace'(user:portray_message(Severity, Msg)), !.
|
||||||
|
@ -75,7 +75,7 @@ generate_message(M) -->
|
|||||||
|
|
||||||
stack_dump(error(_,_)) -->
|
stack_dump(error(_,_)) -->
|
||||||
{ fail },
|
{ fail },
|
||||||
{ nb_getval(sp_info,local_sp(P,CP,Envs,CPs)) },
|
{ recorded(sp_info,local_sp(P,CP,Envs,CPs),_) },
|
||||||
{ Envs = [_|_] ; CPs = [_|_] }, !,
|
{ Envs = [_|_] ; CPs = [_|_] }, !,
|
||||||
[nl],
|
[nl],
|
||||||
'$hacks':display_stack_info(CPs, Envs, 20, CP).
|
'$hacks':display_stack_info(CPs, Envs, 20, CP).
|
||||||
@ -490,7 +490,7 @@ prefix(warning, '% ', user_error) -->
|
|||||||
; ['Warning: [Thread ~d ]' - Id, nl ]
|
; ['Warning: [Thread ~d ]' - Id, nl ]
|
||||||
).
|
).
|
||||||
prefix(error, ' ', user_error) -->
|
prefix(error, ' ', user_error) -->
|
||||||
{ nb_getval(sp_info,local_sp(P,_,_,_)) },
|
{ recorded(sp_info,local_sp(P,_,_,_),_) },
|
||||||
{ thread_self(Id) },
|
{ thread_self(Id) },
|
||||||
( { Id == main }
|
( { Id == main }
|
||||||
-> [ 'ERROR at ' ]
|
-> [ 'ERROR at ' ]
|
||||||
|
Reference in New Issue
Block a user