Add [caml_fatal_error_hook].
When not NULL, this hook is called when a fatal error is encountered instead of printing an error message on stderr.master
parent
97656b1498
commit
cddec18fde
3
Changes
3
Changes
|
@ -36,7 +36,8 @@ Working version
|
|||
OCaml heap.
|
||||
(Jacques-Henri Jourdan, review by Damien Doligez)
|
||||
|
||||
- #8630: Use abort() instead of exit(2) in caml_fatal_error.
|
||||
- #8630: Use abort() instead of exit(2) in caml_fatal_error, and add
|
||||
the new hook caml_fatal_error_hook.
|
||||
(Jacques-Henri Jourdan, review by Xavier Leroy)
|
||||
|
||||
### Standard library:
|
||||
|
|
|
@ -27,6 +27,7 @@
|
|||
|
||||
#include <stddef.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
|
||||
/* Basic types and constants */
|
||||
|
||||
|
@ -125,6 +126,15 @@ CAMLnoreturn_end;
|
|||
#define CAMLassert(x) ((void) 0)
|
||||
#endif
|
||||
|
||||
/* This hook is called when a fatal error occurs in the OCaml
|
||||
runtime. It is given arguments to be passed to the [vprintf]-like
|
||||
functions in order to synthetize the error message.
|
||||
If it returns, the runtime calls [abort()].
|
||||
|
||||
If it is [NULL], the error message is printed on stderr and then
|
||||
[abort()] is called. */
|
||||
extern void (*caml_fatal_error_hook) (char *msg, va_list args);
|
||||
|
||||
CAMLnoreturn_start
|
||||
CAMLextern void caml_fatal_error (char *, ...)
|
||||
#ifdef __GNUC__
|
||||
|
|
|
@ -76,14 +76,20 @@ void caml_gc_message (int level, char *msg, ...)
|
|||
}
|
||||
}
|
||||
|
||||
void (*caml_fatal_error_hook) (char *msg, va_list args) = NULL;
|
||||
|
||||
CAMLexport void caml_fatal_error (char *msg, ...)
|
||||
{
|
||||
va_list ap;
|
||||
va_start(ap, msg);
|
||||
fprintf (stderr, "Fatal error: ");
|
||||
vfprintf (stderr, msg, ap);
|
||||
if(caml_fatal_error_hook != NULL) {
|
||||
caml_fatal_error_hook(msg, ap);
|
||||
} else {
|
||||
fprintf (stderr, "Fatal error: ");
|
||||
vfprintf (stderr, msg, ap);
|
||||
fprintf (stderr, "\n");
|
||||
}
|
||||
va_end(ap);
|
||||
fprintf (stderr, "\n");
|
||||
abort();
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue