source: src/examples/gc_no_raii/src/internal/object_header.c@ 16cfd8c

ADT aaron-thesis arm-eh ast-experimental cleanup-dtors ctor deferred_resn demangler enum forall-pointer-decay gc_noraii jacob/cs343-translation jenkins-sandbox memory new-ast new-ast-unique-expr new-env no_list persistent-indexer pthread-emulation qualifiedEnum resolv-new with_gc
Last change on this file since 16cfd8c was 16cfd8c, checked in by Thierry Delisle <tdelisle@…>, 10 years ago

1 error left

  • Property mode set to 100644
File size: 2.2 KB
Line 
1#include "object_header.h"
2
3#include <stdint.h>
4
5#include "globals.h"
6#include "gcpointers.h"
7
8void ctor(gc_object_header* const this, size_t inSize)
9{
10 #if _DEBUG
11 this->canary_start = CANARY_VALUE;
12 #endif
13
14 this->size = inSize;
15 this->root_chain = NULL;
16 this->type_chain = NULL;
17 this->forward = NULL;
18 this->is_forwarded = false;
19
20 #if _DEBUG
21 this->canary_end = CANARY_VALUE;
22 #endif
23}
24
25void copy_ctor(gc_object_header* const this, const gc_object_header* const other)
26{
27 #if _DEBUG
28 this->canary_start = CANARY_VALUE;
29 #endif
30
31 this->size = other->size;
32 this->root_chain = other->root_chain;
33 this->type_chain = NULL;
34 this->forward = NULL;
35 this->is_forwarded = false;
36
37 #if _DEBUG
38 this->canary_end = CANARY_VALUE;
39 #endif
40
41 gcpointer_t* root = this->root_chain;
42 while(root)
43 {
44 check(get_object_ptr(root->ptr) == other);
45 root->ptr = ((intptr_t)this) + sizeof(gc_object_header);
46
47 check(get_object_ptr(root->ptr) == this);
48 root = root->next;
49 }
50
51 gcpointer_t* type = other->type_chain;
52
53 while(type)
54 {
55 check((intptr_t)type < (intptr_t)((intptr_t)other + other->size));
56
57 size_t offset = (intptr_t)type - (intptr_t)other;
58 check(offset < size);
59
60 gcpointer_t* member_ptr = (gcpointer_t*)( (intptr_t)this + offset );
61
62 if(!this->type_chain) this->type_chain = member_ptr;
63
64 size_t next_offset = type->next ? (intptr_t)type->next - (intptr_t)other : 0;
65 check(next_offset < size);
66
67 gcpointer_t* next_ptr = type->next ? (gcpointer_t*)((intptr_t)this + next_offset) : NULL;
68
69 member_ptr->ptr = type->ptr;
70 member_ptr->next = next_ptr;
71
72 type = type->next;
73 }
74
75 check(is_valide(this));
76}
77
78#if _DEBUG
79 bool is_valide(const gc_object_header* const this)
80 {
81 check(this->canary_start == CANARY_VALUE);
82 check(this->canary_end == CANARY_VALUE);
83
84 check(this->is_forwarded == (this->forward != nullptr));
85
86 check(this->size < POOL_SIZE_BYTES);
87
88 gcpointer_t* root = this->root_chain;
89 while(root)
90 {
91 check(get_object_ptr(root->ptr) == this);
92
93 root = root->next;
94 }
95
96 gcpointer_t* type = type_chain;
97 while(type)
98 {
99 check((intptr_t)type > (intptr_t)this);
100 check((intptr_t)type < (intptr_t)((intptr_t)this + size));
101
102 type = type->next;
103 }
104
105 return true;
106 }
107#endif
Note: See TracBrowser for help on using the repository browser.