forked from programming-nu/nu
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
improved handling of init* methods that don't return self.
NSXMLDocument is one of many classes whose init methods return something other than self. Others include NSArray and NSDictionary, which return a special "placeholder" subclass instance from alloc. NSXMLDocument behaves similarly but without an explicit placeholder subclass. This change should eliminate a crash that occurred when placeholders were overreleased. In past versions of Nu, we looked for known explicit placeholders and handled them specially, but this was removed in Lion when the NSArray and NSDictionary placeholders subclasses appeared to to ignore release messages. However, this was not true for NSXMLDocument, which implicitly uses the placeholder pattern and does not have a placeholder subclass. Now we watch methods whose names begin with "init" to see if they return their original target or not, which allows us to properly handle the placeholder pattern whether it is used from an explicit placeholder subclass or not.
- Loading branch information
Showing
2 changed files
with
38 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
;; test_xml.nu | ||
;; tests for Nu usage of NSXMLDocument. | ||
;; | ||
;; Copyright (c) 2011 Tim Burks, Radtastical Inc. | ||
|
||
(unless (eq (uname) "iOS") | ||
|
||
(class TestXML is NuTestCase | ||
|
||
(- (id) testNoCrash is | ||
(set xmlText "<sample><one/><two/><three/></sample>") | ||
(set xmlData (xmlText dataUsingEncoding:NSUTF8StringEncoding)) | ||
(set doc ((NSXMLDocument alloc) initWithData:xmlData options:0 error:nil))))) |