Ignore:
Timestamp:
Aug 9, 2017, 2:08:14 PM (4 years ago)
Author:
Andrew Beach <ajbeach@…>
Branches:
aaron-thesis, arm-eh, cleanup-dtors, deferred_resn, demangler, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, resolv-new, with_gc
Children:
65cdc1e
Parents:
e195093
Message:

Structure based exception handling.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/libcfa/exception.c

    re195093 rcbce272  
    1010// Created On       : Mon Jun 26 15:13:00 2017
    1111// Last Modified By : Andrew Beach
    12 // Last Modified On : Mon Jul 31 13:51:00 2017
    13 // Update Count     : 4
     12// Last Modified On : Fri Aug  4 15:20:00 2017
     13// Update Count     : 6
    1414//
     15
     16#include <stddef.h> // for size_t
    1517
    1618#include "exception.h"
     
    3234#include "lsda.h"
    3335
     36
     37// Base exception vtable is abstract, you should not have base exceptions.
     38struct __cfaehm__base_exception_t_vtable
     39                ___cfaehm__base_exception_t_vtable_instance = {
     40        .parent = NULL,
     41        .size = 0,
     42        .copy = NULL,
     43        .free = NULL,
     44        .msg = NULL
     45};
     46
     47
    3448// Temperary global exception context. Does not work with concurency.
    3549struct exception_context_t {
     
    3953    exception * current_exception;
    4054    int current_handler_index;
    41 
    42         // Storage to avoid using the heap for exceptions.
    43         exception built_in_storage;
    44 } shared_stack = {NULL, NULL, 0, 0, 0};
     55} shared_stack = {NULL, NULL, 0, 0};
    4556
    4657// Get the current exception context.
     
    6980
    7081        // DEBUG
    71         printf("Throwing resumption exception %d\n", *except);
     82        printf("Throwing resumption exception\n");
    7283
    7384        struct __cfaehm__try_resume_node * original_head = shared_stack.current_resume;
     
    8394        }
    8495
    85         printf("Unhandled exception %d\n", *except);
     96        printf("Unhandled exception\n");
    8697        shared_stack.current_resume = original_head;
    8798
     
    124135        // Allocate memory for the exception.
    125136        struct __cfaehm__node * store = malloc(
    126                 sizeof( except ) + sizeof( struct __cfaehm__node ) );
     137                sizeof( struct __cfaehm__node ) + except->virtual_table->size );
    127138
    128139        if ( ! store ) {
     
    136147
    137148        // Copy the exception to storage.
    138         *context->current_exception = *except;
     149        except->virtual_table->copy( context->current_exception, except );
    139150}
    140151
     
    144155
    145156        // DEBUG
    146         printf( "Deleting Exception %d\n", *except);
     157        printf( "Deleting Exception\n");
    147158
    148159        // Remove the exception from the list.
     
    163174
    164175        // Free the old exception node.
     176        except->virtual_table->free( except );
    165177        free( to_free );
    166178}
    167179
    168180// If this isn't a rethrow (*except==0), delete the provided exception.
    169 void __cfaehm__cleanup_terminate( exception ** except ) {
    170         if ( *except ) __cfaehm__delete_exception( *except );
     181void __cfaehm__cleanup_terminate( void * except ) {
     182        if ( *(void**)except ) __cfaehm__delete_exception( *(exception**)except );
    171183}
    172184
Note: See TracChangeset for help on using the changeset viewer.