Changeset 101e0bd for src/examples/gc_no_raii/src/internal/memory_pool.c
- Timestamp:
- Sep 15, 2016, 2:57:03 PM (8 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:
- ba7aa2d, fc4a0fa
- Parents:
- 5b639ee (diff), 50c5cf3 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the(diff)
links above to see all the changes relative to each parent. - File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/examples/gc_no_raii/src/internal/memory_pool.c
r5b639ee r101e0bd 1 1 #include "memory_pool.h" 2 2 3 #include <stdlib> 3 extern "C" { 4 #include <stdlib.h> 5 #include <string.h> 6 } 4 7 8 #include "collector.h" 5 9 #include "object_header.h" 6 10 … … 15 19 card_table_t* new = (card_table_t*)malloc(sizeof(card_table_t)); 16 20 this->cards = new; 17 ctor (this->cards);21 ctor_card(this->cards); 18 22 19 23 this->end_p = ((uint8_t*)this) + size; 20 24 this->free_p = this->start_p; 21 25 22 check( gc_pool_of(this) == this);26 check( gc_pool_of( (void*)this ) == this); 23 27 check(this->cards); 24 28 gc_reset_pool(this); … … 27 31 void dtor(gc_memory_pool *const this) 28 32 { 29 dtor (this->cards);33 dtor_card(this->cards); 30 34 free(this->cards); 31 35 } … … 34 38 { 35 39 this->free_p = this->start_p; 36 #if _DEBUG37 memset(this->start_p, 0xCD, gc_pool_ total_size(this));40 #ifndef NDEBUG 41 memset(this->start_p, 0xCD, gc_pool_size_total(this)); 38 42 #endif 39 43 … … 41 45 reset(this->cards); 42 46 43 check(gc_pool_size_left(this) == gc_pool_ total_size(this));47 check(gc_pool_size_left(this) == gc_pool_size_total(this)); 44 48 } 45 49 … … 58 62 } 59 63 60 void ctor( 61 gc_pool_object_iterator* const this, 64 void ?{}( gc_pool_object_iterator* this, 62 65 struct gc_object_header* start_object 63 #if _DEBUG66 #ifndef NDEBUG 64 67 , intptr_t pool_start 65 68 , intptr_t pool_end … … 68 71 { 69 72 this->object = start_object; 70 #if _DEBUG73 #ifndef NDEBUG 71 74 this->lower_limit = pool_start; 72 75 this->upper_limit = pool_end; 73 76 #endif 74 77 75 check( ((intptr_t)start_object) >= lower_limit );76 check( ((intptr_t)start_object) <= upper_limit );78 check( ((intptr_t)start_object) >= this->lower_limit ); 79 check( ((intptr_t)start_object) <= this->upper_limit ); 77 80 } 81 82 void ^?{}( gc_pool_object_iterator* this ) {} 78 83 79 84 gc_pool_object_iterator gc_pool_iterator_for(gc_memory_pool* const this, void* member) … … 81 86 size_t card = card_of(member); 82 87 intptr_t member_add = (intptr_t)member; 83 void* start_obj; 84 intptr_t start_obj_add; 88 intptr_t start_obj; 85 89 86 90 do 87 91 { 88 92 check(card < CARDS_COUNT); 89 start_obj = object_at(this->cards, card);93 start_obj = (intptr_t)object_at(this->cards, card); 90 94 check(card != 0 || start_obj); 91 95 card--; 92 start_obj_add = (intptr_t)start_obj;93 96 } 94 while(start_obj _add > member_add || start_obj_add != 0);97 while(start_obj > member_add || !(start_obj)); 95 98 96 check( start_obj);97 99 check( start_obj ); 100 98 101 struct gc_object_header* start_obj_typed = (struct gc_object_header*)start_obj; 99 102 100 gc_pool_object_iterator it; 101 ctor( &it, 102 start_obj_typed, 103 #if _DEBUG 103 return (gc_pool_object_iterator) { 104 start_obj_typed 105 #ifndef NDEBUG 104 106 , (intptr_t)this->start_p 105 107 , (intptr_t)this->free_p 106 108 #endif 107 ); 108 return it; 109 }; 109 110 } 110 111 … … 117 118 { 118 119 struct gc_object_header* start_obj = (struct gc_object_header*)this->start_p; 119 gc_pool_object_iterator it; 120 ctor( &it, 121 start_obj, 122 #if _DEBUG 120 return (gc_pool_object_iterator) { 121 start_obj 122 #ifndef NDEBUG 123 123 , (intptr_t)this->start_p 124 124 , (intptr_t)this->free_p 125 125 #endif 126 ); 127 return it; 126 }; 128 127 } 129 128 130 129 gc_pool_object_iterator end(gc_memory_pool* const this) 131 130 { 132 gc_pool_object_iterator it; 133 ctor( &it, 134 (struct gc_object_header*)this->free_p, 135 #if _DEBUG 131 return (gc_pool_object_iterator) { 132 (struct gc_object_header*)this->free_p 133 #ifndef NDEBUG 136 134 , (intptr_t)this->start_p 137 135 , (intptr_t)this->free_p 138 136 #endif 139 ); 140 return it; 137 }; 141 138 } 142 139 … … 145 142 struct gc_object_header* object = it->object; 146 143 intptr_t next_ptr = ((intptr_t)object) + object->size; 147 check(next_ptr > lower_limit);148 check(next_ptr <= upper_limit);144 check(next_ptr > it->lower_limit); 145 check(next_ptr <= it->upper_limit); 149 146 150 147 struct gc_object_header* next_obj = ((struct gc_object_header*)next_ptr); 151 check(next_ptr == upper_limit || is_valide(next_obj));148 check(next_ptr == it->upper_limit || is_valid(next_obj)); 152 149 153 150 it->object = next_obj;
Note: See TracChangeset
for help on using the changeset viewer.