From 545348b5c62da57f69b857a2ed323cf8847aedf2 Mon Sep 17 00:00:00 2001 From: Stef Walter Date: Wed, 1 Sep 2004 18:07:23 +0000 Subject: Fix problems with reference counting --- src/domcxx.h | 29 +++++++++++++++++------------ 1 file changed, 17 insertions(+), 12 deletions(-) (limited to 'src/domcxx.h') diff --git a/src/domcxx.h b/src/domcxx.h index 9ebc023..abdd622 100644 --- a/src/domcxx.h +++ b/src/domcxx.h @@ -141,9 +141,9 @@ namespace DOM /* We only perform ref counting on nodes outside the tree */ #define INC_NODE_REF(n) \ - if(LOOSE_NODE(n)) incref(n) + if(n) incref(n) #define DEC_NODE_REF(n) \ - if(LOOSE_NODE(n)) decref(n) + if(n) decref(n) /** * Thin wrapper class for a DOM Node @@ -440,13 +440,16 @@ namespace DOM inline void decref(DOM_Node* node) { ASSERT(node); - ASSERT(node->parentNode == NULL); --(node->rtfxRefCount); - if(node->rtfxRefCount <= 0) + if(LOOSE_NODE(node)) { - ASSERT(node->nodeType == DOM_DOCUMENT_NODE || node->ownerDocument); - DOM_Document_destroyNode(node->nodeType == DOM_DOCUMENT_NODE ? - node : node->ownerDocument, node); + ASSERT(node->parentNode == NULL); + if(node->rtfxRefCount <= 0) + { + ASSERT(node->nodeType == DOM_DOCUMENT_NODE || node->ownerDocument); + DOM_Document_destroyNode(node->nodeType == DOM_DOCUMENT_NODE ? + node : node->ownerDocument, node); + } } } }; @@ -1380,7 +1383,7 @@ namespace DOM return *this; } - ~NodeList() + virtual ~NodeList() { DEC_NODELIST_REF(*this); } bool operator==(const NodeList& other) const @@ -1473,13 +1476,15 @@ namespace DOM NamedNodeMap(const NamedNodeMap& list) : NodeList(list) { } + virtual ~NamedNodeMap() {} + NamedNodeMap& operator=(const NamedNodeMap& other) { NodeList::operator=(other); return *this; } NamedNodeMap& operator=(void* null) { NodeList::operator=(null); return *this; } - const NamedNodeMap* operator->() const + const NamedNodeMap* operator->() const { return (const NamedNodeMap*)this; } - NamedNodeMap* operator->() + NamedNodeMap* operator->() { return this; } virtual int getLength() const @@ -1516,7 +1521,7 @@ namespace DOM return node; } - virtual Node removeNamedItem(const dom_str& name) + Node removeNamedItem(const dom_str& name) throw(DOMException) { ASSERT_VALID(); @@ -1536,7 +1541,7 @@ namespace DOM } #endif - virtual Node setNamedItem(const Node& arg) + Node setNamedItem(const Node& arg) throw(DOMException) { ASSERT_VALID(); -- cgit v1.2.3