Skip to content

Commit

Permalink
Revert "SharedPtr: Remove explicit detached bool"
Browse files Browse the repository at this point in the history
This reverts commit 2ebf465.
  • Loading branch information
glebm authored and xzyfer committed Nov 20, 2018
1 parent fdff442 commit fa93c5a
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 10 deletions.
10 changes: 7 additions & 3 deletions src/memory/SharedPtr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,12 @@ namespace Sass {
bool SharedObj::taint = false;

SharedObj::SharedObj()
: refcounter(0)
: detached(false)
#ifdef DEBUG_SHARED_PTR
, dbg(false)
#endif
{
refcounter = 0;
#ifdef DEBUG_SHARED_PTR
if (taint) all.push_back(this);
#endif
Expand All @@ -62,14 +63,17 @@ namespace Sass {
// AST_Node_Ptr ast = dynamic_cast<AST_Node*>(node);
if (node->dbg) std::cerr << "DELETE NODE " << node << "\n";
#endif
delete(node);
if (!node->detached) {
delete(node);
}
}
}
}

void SharedPtr::incRefCount() {
if (node) {
++ node->refcounter;
node->detached = false;
#ifdef DEBUG_SHARED_PTR
if (node->dbg) {
std::cerr << "+ " << node << " X " << node->refcounter << " (" << this << ") " << "\n";
Expand Down Expand Up @@ -107,4 +111,4 @@ namespace Sass {
incRefCount();
}

}
}
18 changes: 11 additions & 7 deletions src/memory/SharedPtr.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ namespace Sass {
#endif
static bool taint;
long refcounter;
// long refcount;
bool detached;
#ifdef DEBUG_SHARED_PTR
bool dbg;
#endif
Expand Down Expand Up @@ -80,7 +82,7 @@ namespace Sass {
virtual const std::string to_string() const = 0;

virtual ~SharedObj();
long getRefCount() const {
long getRefCount() {
return refcounter;
}
};
Expand Down Expand Up @@ -121,10 +123,11 @@ namespace Sass {
bool isNull () const {
return node == NULL;
};
SharedObj* detach() {
SharedObj* result = node;
node = NULL;
return result;
SharedObj* detach() const {
if (node) {
node->detached = true;
}
return node;
};
operator bool() const {
return node != NULL;
Expand Down Expand Up @@ -194,7 +197,8 @@ namespace Sass {
T* ptr () const {
return static_cast<T*>(this->obj());
};
T* detach() {
T* detach() const {
if (this->obj() == NULL) return NULL;
return static_cast<T*>(SharedPtr::detach());
}
bool isNull() const {
Expand All @@ -210,4 +214,4 @@ namespace Sass {

}

#endif
#endif

0 comments on commit fa93c5a

Please sign in to comment.