File tree Expand file tree Collapse file tree 2 files changed +18
-10
lines changed Expand file tree Collapse file tree 2 files changed +18
-10
lines changed Original file line number Diff line number Diff line change @@ -32,11 +32,12 @@ namespace Sass {
32
32
bool SharedObj::taint = false ;
33
33
34
34
SharedObj::SharedObj ()
35
- : refcounter( 0 )
35
+ : detached( false )
36
36
#ifdef DEBUG_SHARED_PTR
37
37
, dbg(false )
38
38
#endif
39
39
{
40
+ refcounter = 0 ;
40
41
#ifdef DEBUG_SHARED_PTR
41
42
if (taint) all.push_back (this );
42
43
#endif
@@ -62,14 +63,17 @@ namespace Sass {
62
63
// AST_Node_Ptr ast = dynamic_cast<AST_Node*>(node);
63
64
if (node->dbg ) std::cerr << " DELETE NODE " << node << " \n " ;
64
65
#endif
65
- delete (node);
66
+ if (!node->detached ) {
67
+ delete (node);
68
+ }
66
69
}
67
70
}
68
71
}
69
72
70
73
void SharedPtr::incRefCount () {
71
74
if (node) {
72
75
++ node->refcounter ;
76
+ node->detached = false ;
73
77
#ifdef DEBUG_SHARED_PTR
74
78
if (node->dbg ) {
75
79
std::cerr << " + " << node << " X " << node->refcounter << " (" << this << " ) " << " \n " ;
@@ -107,4 +111,4 @@ namespace Sass {
107
111
incRefCount ();
108
112
}
109
113
110
- }
114
+ }
Original file line number Diff line number Diff line change @@ -49,6 +49,8 @@ namespace Sass {
49
49
#endif
50
50
static bool taint;
51
51
long refcounter;
52
+ // long refcount;
53
+ bool detached;
52
54
#ifdef DEBUG_SHARED_PTR
53
55
bool dbg;
54
56
#endif
@@ -80,7 +82,7 @@ namespace Sass {
80
82
virtual const std::string to_string () const = 0;
81
83
82
84
virtual ~SharedObj ();
83
- long getRefCount () const {
85
+ long getRefCount () {
84
86
return refcounter;
85
87
}
86
88
};
@@ -121,10 +123,11 @@ namespace Sass {
121
123
bool isNull () const {
122
124
return node == NULL ;
123
125
};
124
- SharedObj* detach () {
125
- SharedObj* result = node;
126
- node = NULL ;
127
- return result;
126
+ SharedObj* detach () const {
127
+ if (node) {
128
+ node->detached = true ;
129
+ }
130
+ return node;
128
131
};
129
132
operator bool () const {
130
133
return node != NULL ;
@@ -194,7 +197,8 @@ namespace Sass {
194
197
T* ptr () const {
195
198
return static_cast <T*>(this ->obj ());
196
199
};
197
- T* detach () {
200
+ T* detach () const {
201
+ if (this ->obj () == NULL ) return NULL ;
198
202
return static_cast <T*>(SharedPtr::detach ());
199
203
}
200
204
bool isNull () const {
@@ -210,4 +214,4 @@ namespace Sass {
210
214
211
215
}
212
216
213
- #endif
217
+ #endif
You can’t perform that action at this time.
0 commit comments