mirror of
https://github.com/gnustep/libs-base.git
synced 2025-04-23 00:41:02 +00:00
add methods to keep the entire tree from getting deallocated while there are any external references to any object in the tree
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/branches/nsxml_using_libxml2@34579 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
parent
e1ac9467bf
commit
01ed308814
3 changed files with 56 additions and 3 deletions
|
@ -335,6 +335,10 @@ extern void clearPrivatePointers(xmlNodePtr aNode);
|
|||
{
|
||||
nextNode->prev = newNode;
|
||||
}
|
||||
if(prevNode != NULL)
|
||||
{
|
||||
prevNode->next = newNode;
|
||||
}
|
||||
|
||||
if(MY_NODE->children == NULL)
|
||||
{
|
||||
|
@ -342,7 +346,8 @@ extern void clearPrivatePointers(xmlNodePtr aNode);
|
|||
}
|
||||
|
||||
((xmlNodePtr)[child _node])->parent = [self _node];
|
||||
GSIVar(child, parent) = self;
|
||||
//GSIVar(child, parent) = self;
|
||||
[self _addSubNode:child];
|
||||
}
|
||||
|
||||
- (void) insertChildren: (NSArray*)children atIndex: (NSUInteger)index
|
||||
|
|
|
@ -540,6 +540,50 @@ NSArray *execute_xpath(NSXMLNode *node,
|
|||
return c;
|
||||
}
|
||||
|
||||
- (void) recordExternalRetain
|
||||
{
|
||||
id parent = [self parent];
|
||||
if (parent)
|
||||
[parent recordExternalRetain];
|
||||
else
|
||||
{
|
||||
if (internal->externalRetains == 0)
|
||||
[super retain]; // the top of the tree retains itself whenever there are external retains anywhere
|
||||
internal->externalRetains++;
|
||||
}
|
||||
}
|
||||
|
||||
- (void) releaseExternalRetain
|
||||
{
|
||||
id parent = [self parent];
|
||||
if (parent)
|
||||
[parent releaseExternalRetain];
|
||||
else
|
||||
{
|
||||
internal->externalRetains--;
|
||||
if (internal->externalRetains == 0)
|
||||
[super release]; // the top of the tree retains itself whenever there are external retains anywhere
|
||||
}
|
||||
}
|
||||
|
||||
- (id) retain
|
||||
{
|
||||
if ([self retainCount] == 1)
|
||||
{
|
||||
[self recordExternalRetain];
|
||||
}
|
||||
return [super retain];
|
||||
}
|
||||
|
||||
- (void) release
|
||||
{
|
||||
if ([self retainCount] == 2)
|
||||
{
|
||||
[self releaseExternalRetain];
|
||||
}
|
||||
[super release];
|
||||
}
|
||||
|
||||
- (void) dealloc
|
||||
{
|
||||
if (GS_EXISTS_INTERNAL)
|
||||
|
@ -548,8 +592,10 @@ NSArray *execute_xpath(NSXMLNode *node,
|
|||
[internal->URI release];
|
||||
[internal->objectValue release];
|
||||
[internal->subNodes release];
|
||||
[self detach];
|
||||
xmlFree(node);
|
||||
if (node->parent == NULL)
|
||||
{
|
||||
xmlFree(node); // the top level node frees the entire tree
|
||||
}
|
||||
GS_DESTROY_INTERNAL(NSXMLNode);
|
||||
}
|
||||
[super dealloc];
|
||||
|
|
|
@ -113,6 +113,8 @@ StringFromXMLString(const unsigned char *bytes, unsigned length)
|
|||
void *node; \
|
||||
NSMutableArray *subNodes; \
|
||||
NSString *xpath; \
|
||||
int externalRetains; \
|
||||
|
||||
|
||||
/* When using the non-fragile ABI, the instance variables are exposed to the
|
||||
* compiler within the class declaration, so we don't need to incorporate
|
||||
|
|
Loading…
Reference in a new issue