Implement Halt Hook (request from Bernd).
This commit is contained in:
parent
691d66cca3
commit
99c5a17b12
1
C/agc.c
1
C/agc.c
@ -187,6 +187,7 @@ AtomAdjust(Atom a)
|
|||||||
#define HoldEntryAdjust(P) (P)
|
#define HoldEntryAdjust(P) (P)
|
||||||
#define CodeCharPAdjust(P) (P)
|
#define CodeCharPAdjust(P) (P)
|
||||||
#define CodeVoidPAdjust(P) (P)
|
#define CodeVoidPAdjust(P) (P)
|
||||||
|
#define HaltHookAdjust(P) (P)
|
||||||
|
|
||||||
#define recompute_mask(dbr)
|
#define recompute_mask(dbr)
|
||||||
|
|
||||||
|
@ -505,6 +505,7 @@ X_API Term STD_PROTO(YAP_TermNil,(void));
|
|||||||
X_API int STD_PROTO(YAP_AtomGetHold,(Atom));
|
X_API int STD_PROTO(YAP_AtomGetHold,(Atom));
|
||||||
X_API int STD_PROTO(YAP_AtomReleaseHold,(Atom));
|
X_API int STD_PROTO(YAP_AtomReleaseHold,(Atom));
|
||||||
X_API Agc_hook STD_PROTO(YAP_AGCRegisterHook,(Agc_hook));
|
X_API Agc_hook STD_PROTO(YAP_AGCRegisterHook,(Agc_hook));
|
||||||
|
X_API int STD_PROTO(YAP_HaltRegisterHook,(HaltHookFunc, void *));
|
||||||
X_API char *STD_PROTO(YAP_cwd,(void));
|
X_API char *STD_PROTO(YAP_cwd,(void));
|
||||||
X_API Term STD_PROTO(YAP_OpenList,(int));
|
X_API Term STD_PROTO(YAP_OpenList,(int));
|
||||||
X_API Term STD_PROTO(YAP_ExtendList,(Term, Term));
|
X_API Term STD_PROTO(YAP_ExtendList,(Term, Term));
|
||||||
@ -2957,6 +2958,12 @@ YAP_AGCRegisterHook(Agc_hook hook)
|
|||||||
return old;
|
return old;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
X_API int
|
||||||
|
YAP_HaltRegisterHook(HaltHookFunc hook, void * closure)
|
||||||
|
{
|
||||||
|
return Yap_HaltRegisterHook(hook, closure);
|
||||||
|
}
|
||||||
|
|
||||||
X_API char *
|
X_API char *
|
||||||
YAP_cwd(void)
|
YAP_cwd(void)
|
||||||
{
|
{
|
||||||
|
31
C/init.c
31
C/init.c
@ -1333,6 +1333,33 @@ Yap_InitWorkspace(UInt Heap, UInt Stack, UInt Trail, UInt Atts, UInt max_table_s
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
Yap_HaltRegisterHook (HaltHookFunc f, void * env)
|
||||||
|
{
|
||||||
|
struct halt_hook *h;
|
||||||
|
|
||||||
|
if (!(h = (struct halt_hook *)Yap_AllocCodeSpace(sizeof(struct halt_hook))))
|
||||||
|
return FALSE;
|
||||||
|
h->environment = env;
|
||||||
|
h->hook = f;
|
||||||
|
LOCK(BGL);
|
||||||
|
h->next = Yap_HaltHooks;
|
||||||
|
Yap_HaltHooks = h;
|
||||||
|
UNLOCK(BGL);
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
run_halt_hooks(int code)
|
||||||
|
{
|
||||||
|
struct halt_hook *hooke = Yap_HaltHooks;
|
||||||
|
|
||||||
|
while (hooke) {
|
||||||
|
hooke->hook(code, hooke->environment);
|
||||||
|
hooke = hooke->next;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
Yap_exit (int value)
|
Yap_exit (int value)
|
||||||
{
|
{
|
||||||
@ -1340,6 +1367,7 @@ Yap_exit (int value)
|
|||||||
unmap_memory();
|
unmap_memory();
|
||||||
#endif /* YAPOR */
|
#endif /* YAPOR */
|
||||||
|
|
||||||
|
if (! (Yap_PrologMode & BootMode) ) {
|
||||||
#ifdef LOW_PROF
|
#ifdef LOW_PROF
|
||||||
remove("PROFPREDS");
|
remove("PROFPREDS");
|
||||||
remove("PROFILING");
|
remove("PROFILING");
|
||||||
@ -1347,8 +1375,9 @@ Yap_exit (int value)
|
|||||||
#if defined MYDDAS_MYSQL || defined MYDDAS_ODBC
|
#if defined MYDDAS_MYSQL || defined MYDDAS_ODBC
|
||||||
Yap_MYDDAS_delete_all_myddas_structs();
|
Yap_MYDDAS_delete_all_myddas_structs();
|
||||||
#endif
|
#endif
|
||||||
if (! (Yap_PrologMode & BootMode) )
|
run_halt_hooks(value);
|
||||||
Yap_ShutdownLoadForeign();
|
Yap_ShutdownLoadForeign();
|
||||||
|
}
|
||||||
exit(value);
|
exit(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
10
H/YapHeap.h
10
H/YapHeap.h
@ -62,6 +62,16 @@ typedef struct gc_ma_hash_entry_struct {
|
|||||||
struct gc_ma_hash_entry_struct *next;
|
struct gc_ma_hash_entry_struct *next;
|
||||||
} gc_ma_hash_entry;
|
} gc_ma_hash_entry;
|
||||||
|
|
||||||
|
typedef void (*HaltHookFunc)(int, void *);
|
||||||
|
|
||||||
|
typedef struct halt_hook {
|
||||||
|
void * environment;
|
||||||
|
HaltHookFunc hook;
|
||||||
|
struct halt_hook *next;
|
||||||
|
} halt_hook_entry;
|
||||||
|
|
||||||
|
int STD_PROTO(Yap_HaltRegisterHook,(HaltHookFunc, void *));
|
||||||
|
|
||||||
typedef struct atom_hash_entry {
|
typedef struct atom_hash_entry {
|
||||||
#if defined(YAPOR) || defined(THREADS)
|
#if defined(YAPOR) || defined(THREADS)
|
||||||
rwlock_t AERWLock;
|
rwlock_t AERWLock;
|
||||||
|
@ -263,6 +263,8 @@
|
|||||||
|
|
||||||
#define Stream Yap_heap_regs->yap_streams
|
#define Stream Yap_heap_regs->yap_streams
|
||||||
|
|
||||||
|
#define Yap_HaltHooks Yap_heap_regs->yap_halt_hook
|
||||||
|
|
||||||
#define NOfFileAliases Yap_heap_regs->n_of_file_aliases
|
#define NOfFileAliases Yap_heap_regs->n_of_file_aliases
|
||||||
#define SzOfFileAliases Yap_heap_regs->sz_of_file_aliases
|
#define SzOfFileAliases Yap_heap_regs->sz_of_file_aliases
|
||||||
#define FileAliases Yap_heap_regs->file_aliases
|
#define FileAliases Yap_heap_regs->file_aliases
|
||||||
|
@ -263,6 +263,8 @@
|
|||||||
|
|
||||||
struct stream_desc *yap_streams;
|
struct stream_desc *yap_streams;
|
||||||
|
|
||||||
|
struct halt_hook *yap_halt_hook;
|
||||||
|
|
||||||
UInt n_of_file_aliases;
|
UInt n_of_file_aliases;
|
||||||
UInt sz_of_file_aliases;
|
UInt sz_of_file_aliases;
|
||||||
struct AliasDescS *file_aliases;
|
struct AliasDescS *file_aliases;
|
||||||
|
@ -263,6 +263,8 @@
|
|||||||
|
|
||||||
Yap_heap_regs->yap_streams = NULL;
|
Yap_heap_regs->yap_streams = NULL;
|
||||||
|
|
||||||
|
Yap_heap_regs->yap_halt_hook = NULL;
|
||||||
|
|
||||||
Yap_heap_regs->n_of_file_aliases = 0;
|
Yap_heap_regs->n_of_file_aliases = 0;
|
||||||
Yap_heap_regs->sz_of_file_aliases = 0;
|
Yap_heap_regs->sz_of_file_aliases = 0;
|
||||||
Yap_heap_regs->file_aliases = NULL;
|
Yap_heap_regs->file_aliases = NULL;
|
||||||
|
12
H/rheap.h
12
H/rheap.h
@ -899,6 +899,18 @@ RestoreDBErasedIList(void)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
RestoreHaltHooks(void)
|
||||||
|
{
|
||||||
|
struct halt_hook *hooke = Yap_HaltHooks = HaltHookAdjust(Yap_HaltHooks);
|
||||||
|
|
||||||
|
while (hooke) {
|
||||||
|
hooke->next = HaltHookAdjust(hooke->next);
|
||||||
|
hooke = hooke->next;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
static void
|
static void
|
||||||
RestoreStreams(void)
|
RestoreStreams(void)
|
||||||
{
|
{
|
||||||
|
@ -263,6 +263,8 @@
|
|||||||
|
|
||||||
RestoreStreams();
|
RestoreStreams();
|
||||||
|
|
||||||
|
RestoreHaltHooks();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
RestoreAliases();
|
RestoreAliases();
|
||||||
|
10
H/sshift.h
10
H/sshift.h
@ -610,7 +610,15 @@ CodeVoidPAdjust (void * addr)
|
|||||||
return addr + HDiff;
|
return addr + HDiff;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
inline EXTERN struct halt_hook *HaltHookAdjust (struct halt_hook *);
|
||||||
|
|
||||||
|
inline EXTERN struct halt_hook *
|
||||||
|
HaltHookAdjust (struct halt_hook * addr)
|
||||||
|
{
|
||||||
|
if (!addr)
|
||||||
|
return NULL;
|
||||||
|
return (struct halt_hook *) (CharP (addr) + HDiff);
|
||||||
|
}
|
||||||
|
|
||||||
inline EXTERN BlockHeader *BlockAdjust (BlockHeader *);
|
inline EXTERN BlockHeader *BlockAdjust (BlockHeader *);
|
||||||
|
|
||||||
@ -620,8 +628,6 @@ BlockAdjust (BlockHeader * addr)
|
|||||||
return (BlockHeader *) ((BlockHeader *) (CharP (addr) + HDiff));
|
return (BlockHeader *) ((BlockHeader *) (CharP (addr) + HDiff));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
inline EXTERN yamop *PtoOpAdjust (yamop *);
|
inline EXTERN yamop *PtoOpAdjust (yamop *);
|
||||||
|
|
||||||
inline EXTERN yamop *
|
inline EXTERN yamop *
|
||||||
|
12
docs/yap.tex
12
docs/yap.tex
@ -1384,7 +1384,7 @@ anonymous variables.
|
|||||||
|
|
||||||
Punctuation tokens consist of one of the following characters:
|
Punctuation tokens consist of one of the following characters:
|
||||||
@example
|
@example
|
||||||
@center ( ) , [ ] @{ @} |
|
( ) , [ ] @{ @} |
|
||||||
@end example
|
@end example
|
||||||
|
|
||||||
These characters are used to group terms.
|
These characters are used to group terms.
|
||||||
@ -3346,7 +3346,7 @@ Also refer to @code{copy_term/2}.
|
|||||||
True when @var{List} is a proper list. That is, @var{List}
|
True when @var{List} is a proper list. That is, @var{List}
|
||||||
is bound to the empty list (nil) or a term with functor '.' and arity 2.
|
is bound to the empty list (nil) or a term with functor '.' and arity 2.
|
||||||
|
|
||||||
@item ?@var{Term1} =@= ?@var{Term2}
|
@item ?@var{Term1} =@@= ?@var{Term2}
|
||||||
@findex =@=/2
|
@findex =@=/2
|
||||||
@syindex =@=/2
|
@syindex =@=/2
|
||||||
@cnindex =@=/2
|
@cnindex =@=/2
|
||||||
@ -16695,6 +16695,14 @@ only two boolean flags are accepted: @code{YAPC_ENABLE_GC} and
|
|||||||
@code{YAPC_ENABLE_AGC}. The first enables/disables the standard garbage
|
@code{YAPC_ENABLE_AGC}. The first enables/disables the standard garbage
|
||||||
collector, the second does the same for the atom garbage collector.`
|
collector, the second does the same for the atom garbage collector.`
|
||||||
|
|
||||||
|
@item @code{int} YAP_HaltRegisterHook(@code{YAP_halt_hook f, void *closure})
|
||||||
|
@findex YAP_HaltRegisterHook (C-Interface function)
|
||||||
|
|
||||||
|
Register the function @var{f} to be called if YAP is halted. The
|
||||||
|
function is called with two arguments: the exit code of the process (@code{0}
|
||||||
|
if this cannot be determined on your operating system) and the closure
|
||||||
|
argument @var{closure}.
|
||||||
|
@c See also @code{at_halt/1}.
|
||||||
@end table
|
@end table
|
||||||
|
|
||||||
|
|
||||||
|
@ -470,6 +470,9 @@ extern X_API int PROTO(YAP_AtomReleaseHold,(YAP_Atom));
|
|||||||
/* void YAP_AtomReleaseHold(YAP_Atom) */
|
/* void YAP_AtomReleaseHold(YAP_Atom) */
|
||||||
extern X_API YAP_agc_hook PROTO(YAP_AGCRegisterHook,(YAP_agc_hook));
|
extern X_API YAP_agc_hook PROTO(YAP_AGCRegisterHook,(YAP_agc_hook));
|
||||||
|
|
||||||
|
/* void YAP_AtomReleaseHold(YAP_Atom) */
|
||||||
|
extern X_API int PROTO(YAP_HaltRegisterHook,(YAP_halt_hook, void *));
|
||||||
|
|
||||||
/* char *YAP_cwd(void) */
|
/* char *YAP_cwd(void) */
|
||||||
extern X_API char * PROTO(YAP_cwd,(void));
|
extern X_API char * PROTO(YAP_cwd,(void));
|
||||||
|
|
||||||
|
@ -176,6 +176,8 @@ typedef struct {
|
|||||||
|
|
||||||
typedef int (*YAP_agc_hook)(void *_Atom);
|
typedef int (*YAP_agc_hook)(void *_Atom);
|
||||||
|
|
||||||
|
typedef void (*YAP_halt_hook)(int exit_code, void *closure);
|
||||||
|
|
||||||
/********* execution mode ***********************/
|
/********* execution mode ***********************/
|
||||||
|
|
||||||
typedef enum
|
typedef enum
|
||||||
|
@ -3249,6 +3249,7 @@ X_API void (*PL_signal(int sig, void (*func)(int)))(int)
|
|||||||
|
|
||||||
X_API void PL_on_halt(void (*f)(int, void *), void *closure)
|
X_API void PL_on_halt(void (*f)(int, void *), void *closure)
|
||||||
{
|
{
|
||||||
|
Yap_HaltRegisterHook((HaltHookFunc)f,closure);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Yap_swi_install(void);
|
void Yap_swi_install(void);
|
||||||
|
@ -295,6 +295,9 @@ struct operator_entry *op_list OpList =NULL OpListAdjust
|
|||||||
/* stream array */
|
/* stream array */
|
||||||
struct stream_desc *yap_streams Stream =NULL RestoreStreams()
|
struct stream_desc *yap_streams Stream =NULL RestoreStreams()
|
||||||
|
|
||||||
|
/* halt hooks */
|
||||||
|
struct halt_hook *yap_halt_hook Yap_HaltHooks =NULL RestoreHaltHooks()
|
||||||
|
|
||||||
/* stream aliases */
|
/* stream aliases */
|
||||||
UInt n_of_file_aliases NOfFileAliases =0 void
|
UInt n_of_file_aliases NOfFileAliases =0 void
|
||||||
UInt sz_of_file_aliases SzOfFileAliases =0 void
|
UInt sz_of_file_aliases SzOfFileAliases =0 void
|
||||||
|
Reference in New Issue
Block a user