From 887b27f9b104ff6e29b013f64c9b94d296b518b5 Mon Sep 17 00:00:00 2001 From: CaS Date: Mon, 9 Jan 2006 05:07:09 +0000 Subject: [PATCH] Fixups for keyed archiving under windows. git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@22269 72102866-910b-0410-8b05-ffd578937521 --- ChangeLog | 10 ++++++++++ Source/NSKeyedArchiver.m | 2 +- Source/NSKeyedUnarchiver.m | 7 +++++++ Source/NSPropertyList.m | 40 ++++++++++++++++++++++---------------- 4 files changed, 41 insertions(+), 18 deletions(-) diff --git a/ChangeLog b/ChangeLog index b2142cba9..5968b3cbf 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,13 @@ +2006-01-09 Richard Frith-Macdonald + + * Source/NSPropertyList.m: When generating binary plist, fix bug + in case where we have to increase table size. + * Source/NSKeyedArchiver.m: Update to use binary plist format + by default rather than xml format ... MacOS-X compatible and + works when libxml2 is not available. + * Source/NSKeyedUnarchiver.m: Print NSLog error if attempting to + decode an xml archive when no libxml2 is available. + 2006-01-08 Richard Frith-Macdonald * Source/NSPathUtilities.m: be more consistent in use of defined values diff --git a/Source/NSKeyedArchiver.m b/Source/NSKeyedArchiver.m index a778c8c7d..81e92fe4a 100644 --- a/Source/NSKeyedArchiver.m +++ b/Source/NSKeyedArchiver.m @@ -786,7 +786,7 @@ static NSDictionary *makeReference(unsigned ref) _obj = [NSMutableArray new]; // Array of objects. [_obj addObject: @"$null"]; // Placeholder. - _format = NSPropertyListXMLFormat_v1_0; // FIXME ... should be binary. + _format = NSPropertyListBinaryFormat_v1_0; } return self; } diff --git a/Source/NSKeyedUnarchiver.m b/Source/NSKeyedUnarchiver.m index 4dd49bfa8..cb32b3f1c 100644 --- a/Source/NSKeyedUnarchiver.m +++ b/Source/NSKeyedUnarchiver.m @@ -745,6 +745,13 @@ static NSMapTable globalClassMap = 0; errorDescription: &error]; if (_archive == nil) { +#ifndef HAVE_LIBXML + if (format == NSPropertyListXMLFormat_v1_0) + { + NSLog(@"Unable to parse XML archive as the base " + @"library was not configured with libxml2 support."); + } +#endif DESTROY(self); } else diff --git a/Source/NSPropertyList.m b/Source/NSPropertyList.m index 0301a7812..009dcace7 100644 --- a/Source/NSPropertyList.m +++ b/Source/NSPropertyList.m @@ -2483,7 +2483,8 @@ GSPropertyListMake(id obj, NSDictionary *loc, BOOL xml, [plData getBytes: postfix range: NSMakeRange(length-32, 32)]; offset_size = postfix[6]; index_size = postfix[7]; - table_start = (postfix[28] << 24) + (postfix[29] << 16) + (postfix[30] << 8) + postfix[31]; + table_start = (postfix[28] << 24) + (postfix[29] << 16) + + (postfix[30] << 8) + postfix[31]; if (offset_size < 1 || offset_size > 4) { [NSException raise: NSGenericException @@ -2492,9 +2493,9 @@ GSPropertyListMake(id obj, NSDictionary *loc, BOOL xml, } else if (index_size < 1 || index_size > 4) { + DESTROY(self); // Bad format [NSException raise: NSGenericException format: @"Unknown table size %d", index_size]; - DESTROY(self); // Bad format } else if (table_start > length - 32) { @@ -2541,8 +2542,10 @@ GSPropertyListMake(id obj, NSDictionary *loc, BOOL xml, unsigned char buffer[offset_size]; int i; unsigned long num = 0; + NSRange r; - [data getBytes: &buffer range: NSMakeRange(table_start + offset_size*index, offset_size)]; + r = NSMakeRange(table_start + offset_size*index, offset_size); + [data getBytes: &buffer range: r]; for (i = 0; i < offset_size; i++) { num = (num << 8) + buffer[i]; @@ -2998,27 +3001,32 @@ GSPropertyListMake(id obj, NSDictionary *loc, BOOL xml, @implementation BinaryPLGenerator -+ (void) serializePropertyList: (id)aPropertyList intoData: (NSMutableData *)destination ++ (void) serializePropertyList: (id)aPropertyList + intoData: (NSMutableData *)destination { BinaryPLGenerator *gen; - gen = [[BinaryPLGenerator alloc] initWithPropertyList: aPropertyList intoData: destination]; + gen = [[BinaryPLGenerator alloc] + initWithPropertyList: aPropertyList intoData: destination]; [gen generate]; RELEASE(gen); } -- (id) initWithPropertyList: (id) aPropertyList intoData: (NSMutableData *)destination +- (id) initWithPropertyList: (id) aPropertyList + intoData: (NSMutableData *)destination { ASSIGN(root, aPropertyList); ASSIGN(dest, destination); + [dest setLength: 0]; return self; } - (void) dealloc { - RELEASE(root); + DESTROY(root); [self cleanup]; + DESTROY(dest); [super dealloc]; } @@ -3029,6 +3037,7 @@ GSPropertyListMake(id obj, NSDictionary *loc, BOOL xml, - (void) setup { + [dest setLength: 0]; if (index_size == 1) { table_size = 256; @@ -3048,8 +3057,6 @@ GSPropertyListMake(id obj, NSDictionary *loc, BOOL xml, table = malloc(table_size * sizeof(int)); - // Always restart the destination data - [dest setLength: 0]; objectsToDoList = [[NSMutableArray alloc] init]; objectList = [[NSMutableArray alloc] init]; @@ -3059,7 +3066,6 @@ GSPropertyListMake(id obj, NSDictionary *loc, BOOL xml, - (void) cleanup { - DESTROY(dest); DESTROY(objectsToDoList); DESTROY(objectList); if (table != NULL) @@ -3112,7 +3118,7 @@ GSPropertyListMake(id obj, NSDictionary *loc, BOOL xml, unsigned int last_offset; table_start = [dest length]; - // This is a bit to much, as the length + // This is a bit too much, as the length // of the last object is added. last_offset = table_start; @@ -3135,7 +3141,7 @@ GSPropertyListMake(id obj, NSDictionary *loc, BOOL xml, else { [NSException raise: NSRangeException - format: @"Object table offset out of bounds %d.", last_offset]; + format: @"Object table offset out of bounds %d.", last_offset]; } len = [objectList count]; @@ -3349,12 +3355,12 @@ GSPropertyListMake(id obj, NSDictionary *loc, BOOL xml, [dest appendBytes: [string cString] length: len]; } else - { + { code = 0x5F; [dest appendBytes: &code length: 1]; [self storeCount: len]; [dest appendBytes: [string cString] length: len]; - } + } } else { @@ -3387,7 +3393,7 @@ GSPropertyListMake(id obj, NSDictionary *loc, BOOL xml, } [dest appendBytes: buffer length: sizeof(unichar)*len]; free(buffer); - } + } } } @@ -3484,7 +3490,7 @@ GSPropertyListMake(id obj, NSDictionary *loc, BOOL xml, } default: [NSException raise: NSGenericException - format: @"Attempt to store number with unknown ObjC type"]; + format: @"Attempt to store number with unknown ObjC type"]; } } @@ -3639,7 +3645,7 @@ GSPropertyListMake(id obj, NSDictionary *loc, BOOL xml, } else { - NSLog(@"Unknown object class %@", object); + NSLog(@"Unknown object class %@", object); } }