Ticket #595: handle_null_exceptions.patch

File handle_null_exceptions.patch, 2.0 KB (added by whiteknight, 6 years ago)
  • src/exceptions.c

     
    3737        __attribute__nonnull__(1) 
    3838        __attribute__nonnull__(3); 
    3939 
     40PARROT_DOES_NOT_RETURN 
     41static void die_from_null_exception(PARROT_INTERP) 
     42        __attribute__nonnull__(1); 
     43 
    4044PARROT_CAN_RETURN_NULL 
    4145static opcode_t * pass_exception_args(PARROT_INTERP, 
    4246    ARGIN(const char *sig), 
     
    5155#define ASSERT_ARGS_build_exception_from_args __attribute__unused__ int _ASSERT_ARGS_CHECK = \ 
    5256       PARROT_ASSERT_ARG(interp) \ 
    5357    || PARROT_ASSERT_ARG(format) 
     58#define ASSERT_ARGS_die_from_null_exception __attribute__unused__ int _ASSERT_ARGS_CHECK = \ 
     59       PARROT_ASSERT_ARG(interp) 
    5460#define ASSERT_ARGS_pass_exception_args __attribute__unused__ int _ASSERT_ARGS_CHECK = \ 
    5561       PARROT_ASSERT_ARG(interp) \ 
    5662    || PARROT_ASSERT_ARG(sig) \ 
     
    201207{ 
    202208    ASSERT_ARGS(Parrot_ex_throw_from_op) 
    203209    opcode_t   *address; 
     210    if(PMC_IS_NULL(exception) || exception->vtable->base_type != enum_class_Exception) 
     211        die_from_null_exception(interp); 
    204212    PMC * const handler = Parrot_cx_find_handler_local(interp, exception); 
    205213    if (PMC_IS_NULL(handler)) { 
    206214        STRING * const message     = VTABLE_get_string(interp, exception); 
     
    461469{ 
    462470    ASSERT_ARGS(Parrot_ex_rethrow_from_op) 
    463471    if (exception->vtable->base_type != enum_class_Exception) 
    464         PANIC(interp, "Illegal rethrow"); 
     472        die_from_null_exception(interp); 
    465473 
    466474    Parrot_ex_mark_unhandled(interp, exception); 
    467475 
     
    753761    DUMPCORE(); 
    754762} 
    755763 
     764/* 
    756765 
     766=item C<static void die_from_null_exception(PARROT_INTERP)> 
     767 
     768Somebody has tried to throw a null exception. This is a fatal error. Print 
     769an error message and exit. 
     770 
     771=cut 
     772 
     773*/ 
     774 
     775PARROT_DOES_NOT_RETURN 
     776static void 
     777die_from_null_exception(PARROT_INTERP) 
     778{ 
     779    fprintf(stderr, "FATAL: Attempt to throw a NULL PMC\n"); 
     780    Parrot_exit(interp, 255); 
     781} 
     782 
     783 
    757784/* 
    758785 
    759786=back