diff --git a/ChangeLog b/ChangeLog index 04516ca32..7856ca9c3 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,6 +1,12 @@ +2012-02-27 Fred Kiefer + + * Source/NSXMLNode.m (-copyWithZone:): Copy name spaces as well. + * Source/NSXMLDocument.m (-copyWithZone:): Rewrite copy method. + * Source/NSXMLElement.m: Remove copy method. + 2012-02-27 Doug Simons Merged to trunk by: greg.casamento@gmail.com - + * Source/NSXMLDocument.m: Fix bugs in setCharacterEncoding: and copyWithZone: that cause a memory crash when tree is freed. Doug Simons diff --git a/Source/NSXMLDocument.m b/Source/NSXMLDocument.m index 55f604c95..88d04a6df 100644 --- a/Source/NSXMLDocument.m +++ b/Source/NSXMLDocument.m @@ -76,7 +76,7 @@ extern void clearPrivatePointers(xmlNodePtr aNode); - (NSString*) characterEncoding { if (MY_DOC->encoding) - return [NSString stringWithUTF8String: (const char *)MY_DOC->encoding]; + return StringFromXMLStringPtr(MY_DOC->encoding); else return nil; } @@ -229,7 +229,7 @@ extern void clearPrivatePointers(xmlNodePtr aNode); - (void) setCharacterEncoding: (NSString*)encoding { - MY_DOC->encoding = xmlStrdup(XMLSTRING(encoding)); + MY_DOC->encoding = XMLStringCopy(encoding); } - (void) setDocumentContentKind: (NSXMLDocumentContentKind)kind @@ -475,12 +475,11 @@ extern void clearPrivatePointers(xmlNodePtr aNode); - (id) copyWithZone: (NSZone *)zone { - id c = [[self class] allocWithZone: zone]; - xmlDocPtr newNode = xmlCopyDoc(MY_DOC, 1); // make a deep copy - clearPrivatePointers((xmlNodePtr)newNode); - - c = [c _initWithNode:(xmlNodePtr)newNode kind:internal->kind]; + NSXMLDocument *c = (NSXMLDocument*)[super copyWithZone: zone]; + [c setMIMEType: [self MIMEType]]; + [c setDTD: [self DTD]]; + [c setDocumentContentKind: [self documentContentKind]]; return c; } diff --git a/Source/NSXMLElement.m b/Source/NSXMLElement.m index c30da6207..01c5c4d36 100644 --- a/Source/NSXMLElement.m +++ b/Source/NSXMLElement.m @@ -554,15 +554,6 @@ static void joinTextNodes(xmlNodePtr nodeA, xmlNodePtr nodeB, NSMutableArray *no } } -- (id) copyWithZone: (NSZone *)zone -{ - NSXMLElement *c = [[self class] alloc]; ///(NSXMLElement*)[super copyWithZone: zone]; - xmlNodePtr newNode = (xmlNodePtr)xmlCopyNode(MY_NODE, 1); // copy recursively - clearPrivatePointers(newNode); // clear out all of the _private pointers in the entire tree - c = [c _initWithNode:newNode kind:internal->kind]; - return c; -} - @end #endif diff --git a/Source/NSXMLNode.m b/Source/NSXMLNode.m index 880d14c02..859b5cc08 100644 --- a/Source/NSXMLNode.m +++ b/Source/NSXMLNode.m @@ -937,15 +937,12 @@ NSArray *execute_xpath(NSXMLNode *xmlNode, - (id) copyWithZone: (NSZone*)zone { id c = [[self class] allocWithZone: zone]; - xmlNodePtr newNode = xmlCopyNode([self _node], 1); // make a deep copy + // make a deep copy + xmlNodePtr newNode = xmlCopyNode([self _node], 2); clearPrivatePointers(newNode); - //c = [c initWithKind: internal->kind options: internal->options]; - //[c _setNode: newNode]; c = [c _initWithNode: newNode kind: internal->kind]; - - // [c setName: [self name]]; // [c setURI: [self URI]]; // [c setObjectValue: [self objectValue]];