Changeset 8ad5752


Ignore:
Timestamp:
May 21, 2020, 12:22:33 PM (4 years ago)
Author:
Andrew Beach <ajbeach@…>
Branches:
ADT, arm-eh, ast-experimental, enum, forall-pointer-decay, jacob/cs343-translation, master, new-ast, new-ast-unique-expr, pthread-emulation, qualifiedEnum
Children:
66ba544
Parents:
918b90c
Message:

Added tests for default exception handlers. Fixed a memory leak they revealed.

Files:
2 added
1 edited

Legend:

Unmodified
Added
Removed
  • libcfa/src/exception.c

    r918b90c r8ad5752  
    1010// Created On       : Mon Jun 26 15:13:00 2017
    1111// Last Modified By : Andrew Beach
    12 // Last Modified On : Tue May 19 14:17:00 2020
    13 // Update Count     : 19
     12// Last Modified On : Thr May 21 12:18:00 2020
     13// Update Count     : 20
    1414//
    1515
     
    237237}
    238238
     239static void __cfaehm_cleanup_default( exception_t ** except ) {
     240        __cfaehm_delete_exception( *except );
     241        *except = NULL;
     242}
     243
    239244// The exception that is being thrown must already be stored.
    240245static void __cfaehm_begin_unwind(void(*defaultHandler)(exception_t *)) {
    241         if ( ! this_exception_context()->current_exception ) {
     246        struct exception_context_t * context = this_exception_context();
     247        struct _Unwind_Exception * storage = &this_exception_storage;
     248        if ( NULL == context->current_exception ) {
    242249                printf("UNWIND ERROR missing exception in begin unwind\n");
    243250                abort();
     
    245252
    246253        // Call stdlibc to raise the exception
    247         _Unwind_Reason_Code ret = _Unwind_RaiseException( &this_exception_storage );
     254        __cfadbg_print_safe(exception, "Begin unwinding (storage &p, context %p)\n", storage, context);
     255        _Unwind_Reason_Code ret = _Unwind_RaiseException( storage );
    248256
    249257        // If we reach here it means something happened. For resumption to work we need to find a way
     
    254262        // the whole stack.
    255263
     264        // We did not simply reach the end of the stack without finding a handler. This is an error.
     265        if ( ret != _URC_END_OF_STACK ) {
     266                printf("UNWIND ERROR %d after raise exception\n", ret);
     267                abort();
     268        }
     269
    256270        // No handler found, go to the default operation.
    257         if ( ret == _URC_END_OF_STACK ) {
    258                 __cfadbg_print_safe(exception, "Uncaught exception %p\n", &this_exception_storage);
    259 
    260                 defaultHandler( this_exception_context()->current_exception );
    261         }
    262 
    263         // We did not simply reach the end of the stack without finding a handler. This is an error.
    264         printf("UNWIND ERROR %d after raise exception\n", ret);
    265         abort();
     271        __cfadbg_print_safe(exception, "Uncaught exception %p\n", storage);
     272
     273        __attribute__((cleanup(__cfaehm_cleanup_default)))
     274        exception_t * exception = context->current_exception;
     275        defaultHandler( exception );
    266276}
    267277
Note: See TracChangeset for help on using the changeset viewer.