source: src/examples/gc_no_raii/bug-repro/push_back.c @ 385c130

ADTaaron-thesisarm-ehast-experimentalcleanup-dtorsctordeferred_resndemanglerenumforall-pointer-decaygc_noraiijacob/cs343-translationjenkins-sandboxmemorynew-astnew-ast-unique-exprnew-envno_listpersistent-indexerpthread-emulationqualifiedEnumresolv-newwith_gc
Last change on this file since 385c130 was 385c130, checked in by Thierry Delisle <tdelisle@…>, 8 years ago

pre merge

  • Property mode set to 100644
File size: 1.0 KB
Line 
1#include <stddef.h>
2#include <stdint.h>
3
4//------------------------------------------------------------------------------
5//Declaration
6trait allocator_c(otype T, otype allocator_t) {
7        void realloc(allocator_t*, size_t);
8        T* data(allocator_t*);
9};
10
11forall(otype T, otype allocator_t | allocator_c(T, allocator_t))
12struct vector
13{
14        allocator_t storage;
15        size_t size;
16};
17
18//------------------------------------------------------------------------------
19//Allocator
20forall(otype T)
21struct heap_allocator
22{
23        T* storage;
24        size_t capacity;
25};
26
27forall(otype T)
28void realloc(heap_allocator(T)* this, size_t size);
29
30forall(otype T)
31inline T* data(heap_allocator(T)* this)
32{
33        return this->storage;
34}
35
36//------------------------------------------------------------------------------
37//Modifiers
38forall(otype T, otype allocator_t | allocator_c(T, allocator_t))
39void push_back(vector(T, allocator_t)* this, T value);
40
41typedef vector(intptr_t*, heap_allocator(intptr_t*)) worklist_t;
42
43inline void test()
44{
45        worklist_t w;
46        intptr_t zero = 0;
47        push_back(&w, &zero);
48}
Note: See TracBrowser for help on using the repository browser.