source: src/examples/gc_no_raii/bug-repro/field.c @ 3b8e52c

ADTaaron-thesisarm-ehast-experimentalcleanup-dtorsctordeferred_resndemanglerenumforall-pointer-decayjacob/cs343-translationjenkins-sandboxmemorynew-astnew-ast-unique-exprnew-envno_listpersistent-indexerpthread-emulationqualifiedEnumresolv-newwith_gc
Last change on this file since 3b8e52c was 16cfd8c, checked in by Thierry Delisle <tdelisle@…>, 9 years ago

1 error left

  • Property mode set to 100644
File size: 2.6 KB
Line 
1extern "C" {
2#include <stdbool.h>
3#include <stdint.h>
4}
5
6#include <stdlib>
7
8//------------------------------------------------------------------------------
9//Declaration
10trait allocator_c(otype T, otype allocator_t)
11{
12        void ctor(allocator_t* const);
13        void dtor(allocator_t* const);
14        void realloc(allocator_t* const, size_t);
15        T* data(allocator_t* const);
16};
17
18forall(otype T, otype allocator_t | allocator_c(T, allocator_t))
19struct vector
20{
21        allocator_t storage;
22        size_t size;
23};
24
25int global = 3;
26
27struct card_table_t
28{
29        size_t count;
30        void* cards_start[100];
31};
32
33static inline void ctor(card_table_t* const this)
34{
35        this->count = 0;
36}
37
38struct gc_memory_pool
39{
40        struct memory_pool* mirror;
41        struct memory_pool* next;
42
43        uint8_t type_code;
44
45        card_table_t* cards;
46
47        uint8_t* end_p;
48        uint8_t* free_p;
49        uint8_t start_p[1];
50};
51
52void ctor(      gc_memory_pool *const this,
53                size_t size,
54                gc_memory_pool* next,
55                gc_memory_pool* mirror,
56                uint8_t type
57        );
58
59void dtor(gc_memory_pool *const this);
60
61struct gc_pool_object_iterator
62{
63        struct gc_object_header* object;
64        #if _DEBUG
65                intptr_t lower_limit;
66                intptr_t upper_limit;
67        #endif
68};
69
70void ctor(
71                gc_pool_object_iterator* const this,
72                void* start_object
73                #if _DEBUG
74                        , intptr_t pool_start
75                        , intptr_t pool_end
76                #endif
77        );
78
79bool ?!=?(const gc_pool_object_iterator lhs, const gc_pool_object_iterator rhs);
80
81gc_pool_object_iterator begin(gc_memory_pool* const this);
82gc_pool_object_iterator end(gc_memory_pool* const);
83
84gc_pool_object_iterator* ++?(gc_pool_object_iterator* it);
85
86const void* *?(const gc_pool_object_iterator it);
87void* *?(gc_pool_object_iterator it);
88
89static inline bool gc_pool_is_from_space(const gc_memory_pool* pool)
90{
91        return false;
92}
93
94void gc_reset_pool(gc_memory_pool* const pool);
95
96static inline size_t gc_pool_size_used(const gc_memory_pool* pool)
97{
98        return pool->free_p - pool->start_p;
99}
100
101static inline size_t gc_pool_size_total(const gc_memory_pool* pool)
102{
103        return pool->end_p - pool->start_p;
104}
105
106static inline size_t gc_pool_size_left(const gc_memory_pool* pool)
107{
108        return pool->end_p - pool->free_p;
109}
110
111void* gc_pool_allocate(gc_memory_pool* const pool, size_t size, bool zero);
112
113gc_pool_object_iterator gc_pool_iterator_for(gc_memory_pool* const pool, void* member);
114
115void ctor(gc_memory_pool *const this, size_t size, gc_memory_pool* next, gc_memory_pool* mirror, uint8_t type)
116{
117        this->mirror = mirror;
118        this->next = next;
119        this->type_code = type;
120
121        this->cards = malloc();
122        ctor(this->cards);
123
124        this->end_p = ((uint8_t*)this) + size;
125        this->free_p = this->start_p;
126
127        // check(gc_pool_of(this) == this);
128        // check(this->cards);
129        // gc_reset_pool(this);
130}
Note: See TracBrowser for help on using the repository browser.