Skip to content

Commit 2f5d738

Browse files
committed
Update to new APIs for reading/writing plists
These do not cause a problem yet, but the new APIs follow proper Cocoa memory management rules and will make upgrading to ARC easier. Also, since we now return an NSError instead of an NSString, we should not expect upon successful completion that these methods will return nil for the passed NSError object.
1 parent 87a8532 commit 2f5d738

File tree

11 files changed

+21
-21
lines changed

11 files changed

+21
-21
lines changed

CLIProxy.mm

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -140,11 +140,11 @@ - (void)writeStringToError:(NSString*)text;
140140

141141
- (id)readPropertyListFromInput;
142142
{
143-
NSString* error = nil;
144-
id plist = [TMDCommand readPropertyList:[self inputHandle] error:&error];
143+
NSError* error = nil;
144+
id plist = [TMDCommand readPropertyList:[self inputHandle] error:&error];
145145

146-
if(error || !plist)
147-
[self writeStringToError:error ?: @"unknown error parsing property list\n"];
146+
if(!plist)
147+
[self writeStringToError:[error localizedDescription] ?: @"unknown error parsing property list\n"];
148148

149149
return plist;
150150
}

Commands/defaults.mm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ - (void)handleCommand:(CLIProxy*)proxy
1717
{
1818
// FIXME this is needed only because we presently can’t express argument constraints (CLIProxy would otherwise correctly validate/convert CLI arguments)
1919
if([defaults isKindOfClass:[NSString class]])
20-
defaults = [NSPropertyListSerialization propertyListFromData:[(NSString*)defaults dataUsingEncoding:NSUTF8StringEncoding] mutabilityOption:NSPropertyListImmutable format:nil errorDescription:NULL];
20+
defaults = [NSPropertyListSerialization propertyListWithData:[(NSString*)defaults dataUsingEncoding:NSUTF8StringEncoding] options:NSPropertyListImmutable format:NULL error:NULL];
2121

2222
[[NSUserDefaults standardUserDefaults] registerDefaults:defaults];
2323
}

Commands/filepanel.mm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ - (NSSavePanel*)setupSavePanel:(NSSavePanel*)savePanel usingParameters:(NSDictio
4747

4848
if(NSString* typesStr = args[@"allowedFileTypes"])
4949
{
50-
id rawTypes = [NSPropertyListSerialization propertyListFromData:[typesStr dataUsingEncoding:NSUTF8StringEncoding] mutabilityOption:NSPropertyListImmutable format:nil errorDescription:NULL];
50+
id rawTypes = [NSPropertyListSerialization propertyListWithData:[typesStr dataUsingEncoding:NSUTF8StringEncoding] options:NSPropertyListImmutable format:NULL error:NULL];
5151
NSArray* types = nil;
5252
if([rawTypes isKindOfClass:[NSString class]])
5353
types = [NSArray arrayWithObject:rawTypes];

Commands/images.mm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ - (void)handleCommand:(CLIProxy*)proxy
1717
// Convert image paths to NSImages
1818
NSDictionary* imagePaths = [args objectForKey:@"register"];
1919
if([imagePaths isKindOfClass:[NSString class]])
20-
imagePaths = [NSPropertyListSerialization propertyListFromData:[(NSString*)imagePaths dataUsingEncoding:NSUTF8StringEncoding] mutabilityOption:NSPropertyListImmutable format:nil errorDescription:NULL];
20+
imagePaths = [NSPropertyListSerialization propertyListWithData:[(NSString*)imagePaths dataUsingEncoding:NSUTF8StringEncoding] options:NSPropertyListImmutable format:NULL error:NULL];
2121

2222
for(NSString* imageName in [imagePaths allKeys])
2323
{

Commands/menu.mm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ - (void)handleCommand:(CLIProxy*)proxy
5555

5656
// FIXME this is needed only because we presently can’t express argument constraints (CLIProxy would otherwise correctly validate/convert CLI arguments)
5757
if([menuItems isKindOfClass:[NSString class]])
58-
menuItems = [NSPropertyListSerialization propertyListFromData:[(NSString*)menuItems dataUsingEncoding:NSUTF8StringEncoding] mutabilityOption:NSPropertyListImmutable format:nil errorDescription:NULL];
58+
menuItems = [NSPropertyListSerialization propertyListWithData:[(NSString*)menuItems dataUsingEncoding:NSUTF8StringEncoding] options:NSPropertyListImmutable format:NULL error:NULL];
5959

6060
NSMenu* menu = [[[NSMenu alloc] init] autorelease];
6161
[menu setFont:[NSFont menuFontOfSize:([[NSUserDefaults standardUserDefaults] integerForKey:@"OakBundleManagerDisambiguateMenuFontSize"] ?: [NSFont smallSystemFontSize])]];

Commands/nib/nib.mm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ - (void)handleCommand:(CLIProxy*)proxy
8383

8484
// FIXME this is needed only because we presently can’t express argument constraints (CLIProxy would otherwise correctly validate/convert CLI arguments)
8585
if([model isKindOfClass:[NSString class]])
86-
model = [NSPropertyListSerialization propertyListFromData:[(NSString*)model dataUsingEncoding:NSUTF8StringEncoding] mutabilityOption:NSPropertyListImmutable format:nil errorDescription:NULL];
86+
model = [NSPropertyListSerialization propertyListWithData:[(NSString*)model dataUsingEncoding:NSUTF8StringEncoding] options:NSPropertyListImmutable format:NULL error:NULL];
8787

8888
if(NSString* updateToken = [args objectForKey:@"update"])
8989
{

Commands/popup/popup.mm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ - (void)handleCommand:(CLIProxy*)proxy
3131

3232
NSArray* suggestions = [args objectForKey:@"suggestions"];
3333
if([suggestions isKindOfClass:[NSString class]])
34-
suggestions = [NSPropertyListSerialization propertyListFromData:[(NSString*)suggestions dataUsingEncoding:NSUTF8StringEncoding] mutabilityOption:NSPropertyListImmutable format:nil errorDescription:NULL];
34+
suggestions = [NSPropertyListSerialization propertyListWithData:[(NSString*)suggestions dataUsingEncoding:NSUTF8StringEncoding] options:NSPropertyListImmutable format:NULL error:NULL];
3535

3636
TMDIncrementalPopUpMenu* xPopUp = [[TMDIncrementalPopUpMenu alloc] initWithItems:suggestions alreadyTyped:filter staticPrefix:prefix additionalWordCharacters:allow caseSensitive:!caseInsensitive writeChoiceToFileDescriptor:(wait ? [proxy outputHandle] : nil)];
3737

Commands/prototype/prototype.mm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ - (void)handleCommand:(CLIProxy*)proxy
1919
{
2020
// FIXME this is needed only because we presently can’t express argument constraints (CLIProxy would otherwise correctly validate/convert CLI arguments)
2121
if([values isKindOfClass:[NSString class]])
22-
values = [NSPropertyListSerialization propertyListFromData:[(NSString*)values dataUsingEncoding:NSUTF8StringEncoding] mutabilityOption:NSPropertyListImmutable format:nil errorDescription:NULL];
22+
values = [NSPropertyListSerialization propertyListWithData:[(NSString*)values dataUsingEncoding:NSUTF8StringEncoding] options:NSPropertyListImmutable format:NULL error:NULL];
2323

2424
for(id key in [values allKeys])
2525
[TMD2Chameleon createSubclassNamed:key withValues:[values objectForKey:key]];

OptionParser.mm

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -136,13 +136,13 @@ id create_type (std::string const& str, option_t::type_t const& type, NSString**
136136

137137
case option_t::plist:
138138
{
139-
NSString* error = nil;
139+
NSError* error = nil;
140140

141141
if (str.size() > 0)
142142
{
143-
res = [NSPropertyListSerialization propertyListFromData:[NSData dataWithBytes:str.data() length:str.size()] mutabilityOption:NSPropertyListMutableContainersAndLeaves format:nil errorDescription:&error];
144-
if(error || !res)
145-
*err_out = [NSString stringWithFormat:@"%@\n%s\n", (error ?: @"unknown error parsing property list"), str.c_str()];
143+
res = [NSPropertyListSerialization propertyListWithData:[NSData dataWithBytes:str.data() length:str.size()] options:NSPropertyListMutableContainersAndLeaves format:NULL error:&error];
144+
if(!res)
145+
*err_out = [NSString stringWithFormat:@"%@\n%s\n", ([error localizedDescription] ?: @"unknown error parsing property list"), str.c_str()];
146146
}
147147
else
148148
{

TMDCommand.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
+ (id)objectForCommand:(NSString*)aCommand;
88

9-
+ (id)readPropertyList:(NSFileHandle*)aFileHandle error:(NSString**)error;
9+
+ (id)readPropertyList:(NSFileHandle*)aFileHandle error:(NSError**)error;
1010
+ (void)writePropertyList:(id)aPlist toFileHandle:(NSFileHandle*)aFileHandle;
1111

1212
- (NSString*)commandDescription;

0 commit comments

Comments
 (0)