Changeset cbce272 for src/libcfa
- Timestamp:
- Aug 9, 2017, 2:08:14 PM (7 years ago)
- Branches:
- ADT, aaron-thesis, arm-eh, ast-experimental, cleanup-dtors, deferred_resn, demangler, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, pthread-emulation, qualifiedEnum, resolv-new, with_gc
- Children:
- 65cdc1e
- Parents:
- e195093
- Location:
- src/libcfa
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
src/libcfa/exception.c
re195093 rcbce272 10 10 // Created On : Mon Jun 26 15:13:00 2017 11 11 // Last Modified By : Andrew Beach 12 // Last Modified On : Mon Jul 31 13:51:00 201713 // Update Count : 412 // Last Modified On : Fri Aug 4 15:20:00 2017 13 // Update Count : 6 14 14 // 15 16 #include <stddef.h> // for size_t 15 17 16 18 #include "exception.h" … … 32 34 #include "lsda.h" 33 35 36 37 // Base exception vtable is abstract, you should not have base exceptions. 38 struct __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 34 48 // Temperary global exception context. Does not work with concurency. 35 49 struct exception_context_t { … … 39 53 exception * current_exception; 40 54 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}; 45 56 46 57 // Get the current exception context. … … 69 80 70 81 // DEBUG 71 printf("Throwing resumption exception %d\n", *except);82 printf("Throwing resumption exception\n"); 72 83 73 84 struct __cfaehm__try_resume_node * original_head = shared_stack.current_resume; … … 83 94 } 84 95 85 printf("Unhandled exception %d\n", *except);96 printf("Unhandled exception\n"); 86 97 shared_stack.current_resume = original_head; 87 98 … … 124 135 // Allocate memory for the exception. 125 136 struct __cfaehm__node * store = malloc( 126 sizeof( except ) + sizeof( struct __cfaehm__node ));137 sizeof( struct __cfaehm__node ) + except->virtual_table->size ); 127 138 128 139 if ( ! store ) { … … 136 147 137 148 // Copy the exception to storage. 138 *context->current_exception = *except;149 except->virtual_table->copy( context->current_exception, except ); 139 150 } 140 151 … … 144 155 145 156 // DEBUG 146 printf( "Deleting Exception %d\n", *except);157 printf( "Deleting Exception\n"); 147 158 148 159 // Remove the exception from the list. … … 163 174 164 175 // Free the old exception node. 176 except->virtual_table->free( except ); 165 177 free( to_free ); 166 178 } 167 179 168 180 // 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 );181 void __cfaehm__cleanup_terminate( void * except ) { 182 if ( *(void**)except ) __cfaehm__delete_exception( *(exception**)except ); 171 183 } 172 184 -
src/libcfa/exception.h
re195093 rcbce272 10 10 // Created On : Mon Jun 26 15:11:00 2017 11 11 // Last Modified By : Andrew Beach 12 // Last Modified On : Fri Jul 27 12:42:00 201713 // Update Count : 412 // Last Modified On : Fri Aug 4 15:20:00 2017 13 // Update Count : 5 14 14 // 15 15 … … 21 21 #endif 22 22 23 #if 1 24 typedef int exception; 25 #else 26 struct exception_t; 27 struct exception_t_vtable { 28 struct exception_t_vtable const * parent; 23 struct __cfaehm__base_exception_t; 24 typedef struct __cfaehm__base_exception_t exception; 25 struct __cfaehm__base_exception_t_vtable { 26 const struct __cfaehm__base_exception_t_vtable * parent; 29 27 size_t size; 30 void (*copy)(struct exception_t *this, struct exception_t * other); 31 void (*free)(struct exception_t *this); 32 const char (*msg)(struct exception_t *this); 28 void (*copy)(struct __cfaehm__base_exception_t *this, 29 struct __cfaehm__base_exception_t * other); 30 void (*free)(struct __cfaehm__base_exception_t *this); 31 const char (*msg)(struct __cfaehm__base_exception_t *this); 33 32 }; 34 struct exception_t {35 struct exception_vtable const * virtual_table;33 struct __cfaehm__base_exception_t { 34 struct __cfaehm__base_exception_t_vtable const * virtual_table; 36 35 }; 37 typedef struct exception_t exception; 38 #endif 36 extern struct __cfaehm__base_exception_t_vtable 37 ___cfaehm__base_exception_t_vtable_instance; 39 38 40 39 … … 51 50 52 51 // Clean-up the exception in catch blocks. 53 void __cfaehm__cleanup_terminate( exception ** except);52 void __cfaehm__cleanup_terminate(void * except); 54 53 55 54 // Data structure creates a list of resume handlers.
Note: See TracChangeset
for help on using the changeset viewer.