Skip to content

Commit fa93c5a

Browse files
glebmxzyfer
authored andcommitted
Revert "SharedPtr: Remove explicit detached bool"
This reverts commit 2ebf465.
1 parent fdff442 commit fa93c5a

File tree

2 files changed

+18
-10
lines changed

2 files changed

+18
-10
lines changed

src/memory/SharedPtr.cpp

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,12 @@ namespace Sass {
3232
bool SharedObj::taint = false;
3333

3434
SharedObj::SharedObj()
35-
: refcounter(0)
35+
: detached(false)
3636
#ifdef DEBUG_SHARED_PTR
3737
, dbg(false)
3838
#endif
3939
{
40+
refcounter = 0;
4041
#ifdef DEBUG_SHARED_PTR
4142
if (taint) all.push_back(this);
4243
#endif
@@ -62,14 +63,17 @@ namespace Sass {
6263
// AST_Node_Ptr ast = dynamic_cast<AST_Node*>(node);
6364
if (node->dbg) std::cerr << "DELETE NODE " << node << "\n";
6465
#endif
65-
delete(node);
66+
if (!node->detached) {
67+
delete(node);
68+
}
6669
}
6770
}
6871
}
6972

7073
void SharedPtr::incRefCount() {
7174
if (node) {
7275
++ node->refcounter;
76+
node->detached = false;
7377
#ifdef DEBUG_SHARED_PTR
7478
if (node->dbg) {
7579
std::cerr << "+ " << node << " X " << node->refcounter << " (" << this << ") " << "\n";
@@ -107,4 +111,4 @@ namespace Sass {
107111
incRefCount();
108112
}
109113

110-
}
114+
}

src/memory/SharedPtr.hpp

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@ namespace Sass {
4949
#endif
5050
static bool taint;
5151
long refcounter;
52+
// long refcount;
53+
bool detached;
5254
#ifdef DEBUG_SHARED_PTR
5355
bool dbg;
5456
#endif
@@ -80,7 +82,7 @@ namespace Sass {
8082
virtual const std::string to_string() const = 0;
8183

8284
virtual ~SharedObj();
83-
long getRefCount() const {
85+
long getRefCount() {
8486
return refcounter;
8587
}
8688
};
@@ -121,10 +123,11 @@ namespace Sass {
121123
bool isNull () const {
122124
return node == NULL;
123125
};
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;
128131
};
129132
operator bool() const {
130133
return node != NULL;
@@ -194,7 +197,8 @@ namespace Sass {
194197
T* ptr () const {
195198
return static_cast<T*>(this->obj());
196199
};
197-
T* detach() {
200+
T* detach() const {
201+
if (this->obj() == NULL) return NULL;
198202
return static_cast<T*>(SharedPtr::detach());
199203
}
200204
bool isNull() const {
@@ -210,4 +214,4 @@ namespace Sass {
210214

211215
}
212216

213-
#endif
217+
#endif

0 commit comments

Comments
 (0)