Skip to content

Commit

Permalink
WIP: Messing around with catching SIG_FPE
Browse files Browse the repository at this point in the history
  • Loading branch information
c42f committed Oct 24, 2018
1 parent 44f2563 commit adeaa4b
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 1 deletion.
4 changes: 4 additions & 0 deletions base/boot.jl
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,10 @@ struct BoundsError <: Exception
BoundsError(@nospecialize(a), i) = (@_noinline_meta; new(a,i))
end
struct DivideError <: Exception end
struct FloatOverflowError <: Exception end
struct FloatUnderflowError <: Exception end
struct FloatInexactError <: Exception end
struct FloatInvalidOperationError <: Exception end
struct OutOfMemoryError <: Exception end
struct ReadOnlyMemoryError <: Exception end
struct SegmentationFault <: Exception end
Expand Down
4 changes: 4 additions & 0 deletions src/init.c
Original file line number Diff line number Diff line change
Expand Up @@ -842,6 +842,10 @@ void jl_get_builtin_hooks(void)
jl_errorexception_type = (jl_datatype_t*)core("ErrorException");
jl_stackovf_exception = jl_new_struct_uninit((jl_datatype_t*)core("StackOverflowError"));
jl_diverror_exception = jl_new_struct_uninit((jl_datatype_t*)core("DivideError"));
jl_fltovf_exception = jl_new_struct_uninit((jl_datatype_t*)core("FloatOverflowError"));
jl_fltund_exception = jl_new_struct_uninit((jl_datatype_t*)core("FloatUnderflowError"));
jl_fltres_exception = jl_new_struct_uninit((jl_datatype_t*)core("FloatInexactError"));
jl_fltinv_exception = jl_new_struct_uninit((jl_datatype_t*)core("FloatInvalidOperationError"));
jl_undefref_exception = jl_new_struct_uninit((jl_datatype_t*)core("UndefRefError"));
jl_undefvarerror_type = (jl_datatype_t*)core("UndefVarError");
jl_interrupt_exception = jl_new_struct_uninit((jl_datatype_t*)core("InterruptException"));
Expand Down
4 changes: 4 additions & 0 deletions src/jltypes.c
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,10 @@ jl_value_t *jl_stackovf_exception;
jl_value_t *jl_segv_exception;
#endif
JL_DLLEXPORT jl_value_t *jl_diverror_exception;
JL_DLLEXPORT jl_value_t *jl_fltovf_exception;
JL_DLLEXPORT jl_value_t *jl_fltund_exception;
JL_DLLEXPORT jl_value_t *jl_fltres_exception;
JL_DLLEXPORT jl_value_t *jl_fltinv_exception;
JL_DLLEXPORT jl_value_t *jl_domain_exception;
JL_DLLEXPORT jl_value_t *jl_overflow_exception;
JL_DLLEXPORT jl_value_t *jl_undefref_exception;
Expand Down
4 changes: 4 additions & 0 deletions src/julia.h
Original file line number Diff line number Diff line change
Expand Up @@ -569,6 +569,10 @@ extern JL_DLLEXPORT jl_value_t *jl_stackovf_exception JL_GLOBALLY_ROOTED;
extern JL_DLLEXPORT jl_value_t *jl_memory_exception JL_GLOBALLY_ROOTED;
extern JL_DLLEXPORT jl_value_t *jl_readonlymemory_exception JL_GLOBALLY_ROOTED;
extern JL_DLLEXPORT jl_value_t *jl_diverror_exception JL_GLOBALLY_ROOTED;
extern JL_DLLEXPORT jl_value_t *jl_fltovf_exception JL_GLOBALLY_ROOTED;
extern JL_DLLEXPORT jl_value_t *jl_fltund_exception JL_GLOBALLY_ROOTED;
extern JL_DLLEXPORT jl_value_t *jl_fltres_exception JL_GLOBALLY_ROOTED;
extern JL_DLLEXPORT jl_value_t *jl_fltinv_exception JL_GLOBALLY_ROOTED;
extern JL_DLLEXPORT jl_value_t *jl_undefref_exception JL_GLOBALLY_ROOTED;
extern JL_DLLEXPORT jl_value_t *jl_interrupt_exception JL_GLOBALLY_ROOTED;
extern JL_DLLEXPORT jl_datatype_t *jl_boundserror_type JL_GLOBALLY_ROOTED;
Expand Down
12 changes: 11 additions & 1 deletion src/signals-unix.c
Original file line number Diff line number Diff line change
Expand Up @@ -745,7 +745,17 @@ static void fpe_handler(int sig, siginfo_t *info, void *context)
{
(void)info;
jl_ptls_t ptls = jl_get_ptls_states();
jl_throw_in_ctx(ptls, jl_diverror_exception, sig, context);
jl_value_t *exc = NULL;
switch (info->si_code)
{
case FPE_FLTDIV: exc = jl_diverror_exception; break; // Floating-point divide by zero.
case FPE_FLTOVF: exc = jl_fltovf_exception; break; // Floating-point overflow.
case FPE_FLTUND: exc = jl_fltund_exception; break; // Floating-point underflow.
case FPE_FLTRES: exc = jl_fltres_exception; break; // Floating-point inexact result.
case FPE_FLTINV: exc = jl_fltinv_exception; break; // Floating-point invalid operation.
default: exc = jl_diverror_exception; assert(0);
}
jl_throw_in_ctx(ptls, exc, sig, context);
}

static void sigint_handler(int sig)
Expand Down

0 comments on commit adeaa4b

Please sign in to comment.