source: src/examples/gc_no_raii/gcpointers.c @ e47f529

aaron-thesisarm-ehcleanup-dtorsctordeferred_resndemanglerenumforall-pointer-decaygc_noraiijacob/cs343-translationjenkins-sandboxmemorynew-astnew-ast-unique-exprnew-envno_listpersistent-indexerpthread-emulationresolv-newwith_gc
Last change on this file since e47f529 was e47f529, checked in by Thierry Delisle <tdelisle@…>, 7 years ago

more conversion and compile seems to work well

  • Property mode set to 100644
File size: 1.9 KB
Line 
1#include "gcpointers.h"
2
3#include "gc.h"
4#include "internal/collector.h"
5#include "internal/object_header.h"
6#include "internal/state.h"
7
8void register_ptr(gcpointer_t* this)
9{
10        if(gcpointer_null(this)) return;
11
12        _Bool managed = gc_is_managed(this);
13
14        if(managed)
15        {
16                gc_object_header* obj = gc_get_object_for_ref(this);
17                check(obj);
18                check(gc_obj_is_valide(obj));
19                check(gc_is_managed(this) == gc_is_managed(obj->type_chain) || obj->type_chain == NULL);
20                m_next = obj->type_chain;
21                obj->type_chain = this;
22                check(obj->is_valide());
23        }
24        else
25        {
26                gc_object_header* obj = gc_get_object_ptr(this->ptr);
27                check(obj);
28                check(gc_obj_is_valide(obj));
29                check(gc_is_managed(this) == gc_is_managed(obj->root_chain) || obj->root_chain == NULL);
30                m_next = obj->root_chain;
31                obj->root_chain = this;
32                check(gc_obj_is_valide(obj));
33        }
34}
35
36void unregister_ptr(gcpointer_t* this)
37{
38        if(gcpointer_null(this)) return;
39
40        gcpointer_t** prev_next_ptr = gc_find_previous_ref(this);
41        check((*prev_next_ptr) == this);
42
43        (*prev_next_ptr) = this->next;
44}
45
46void gcpointer_ctor(gcpointer_t* this)
47{
48        this->ptr = NULL;
49        this->next = NULL;
50}
51
52void gcpointer_ctor(gcpointer_t* this, void* address)
53{
54        this->ptr = address;
55        this->next = NULL;
56
57        register_ptr(this);
58}
59
60void gcpointer_ctor(gcpointer_t* this, gcpointer_t* other)
61{
62        this->ptr = other->ptr;
63        this->next = NULL;
64
65        register_ptr(this);
66}
67
68void gcpointer_dtor(gcpointer_t* this)
69{
70        unregister_ptr(this);
71}
72
73gcpointer_t* gcpointer_assign(gcpointer_t* this, gcpointer_t* rhs)
74{
75        if(this != rhs && this->ptr != rhs->ptr)
76        {
77                unregister_ptr(this);
78
79                this->ptr = rhs->ptr;
80
81                register_ptr(this);
82        }
83
84        return this;
85}
86
87//Logical operators
88int gcpointer_equal(gcpointer_t* this, gcpointer_t* rhs)
89{
90        return this->ptr == rhs->ptr;
91}
92
93int gcpointer_not_equal(gcpointer_t* this, gcpointer_t* rhs)
94{
95        return this->ptr != rhs->ptr;
96}
97
98int gcpointer_null(gcpointer_t* this)
99{
100        return this->ptr == NULL;
101}
Note: See TracBrowser for help on using the repository browser.