[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[bug #15226] Unarchived objects do not equal archived objects
From: |
Oliver Langer |
Subject: |
[bug #15226] Unarchived objects do not equal archived objects |
Date: |
Thu, 15 Dec 2005 23:33:49 +0000 |
User-agent: |
Mozilla/5.0 (X11; U; Linux i686; de-DE; rv:1.7.12) Gecko/20050920 Firefox/1.0.7 |
URL:
<http://savannah.gnu.org/bugs/?func=detailitem&item_id=15226>
Summary: Unarchived objects do not equal archived objects
Project: GNUstep
Submitted by: kokosmakrone
Submitted on: Do 15.12.2005 um 23:33
Category: Base/Foundation
Severity: 3 - Normal
Item Group: Bug
Status: None
Privacy: Public
Assigned to: None
Open/Closed: Open
_______________________________________________________
Details:
Take the following scenario into account: You store/archive a string in a
NSData d1 object. Afterwards you run a query and want to load this string by
loading/unarchiving. After, you want this previously loaded string being
stored in another NSData d2 object. You would expect that the content of d2
equals d1 which is not the case.
Behind the scene: The first string is being allocated as an instance of
GSInlineString. Encoding and afterwards decoding this object returns an
instance of GSUnicodeBufferString. Encoding this instance seems to differ
from encoding an instance of GSInlineString.
The following code shows this bug when leaving KEYED_ARCHIVER undefined.
Defining it shows the potential workaround (which costs much more space):
//#define KEYED_ARCHIVER 1
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
NSString *sOriginal, *sLoaded;
NSMutableData *dataOriginal, *dataLoaded;
#if defined(KEYED_ARCHIVER)
NSKeyedArchiver *arOriginal, *arLoaded;
#else
NSArchiver *arOriginal, *arLoaded;
#endif
char *b1, *b2;
sOriginal = [[[NSString alloc] initWithString: @"bla"] autorelease];
dataOriginal = [[[NSMutableData alloc] init] autorelease];
#if defined(KEYED_ARCHIVER)
arOriginal = [[[NSKeyedArchiver alloc]
initForWritingWithMutableData: dataOriginal] autorelease];
#else
arOriginal = [[[NSArchiver alloc]
initForWritingWithMutableData: dataOriginal] autorelease];
#endif
#if defined(KEYED_ARCHIVER)
[arOriginal encodeObject: sOriginal forKey: @"bla"];
#else
[arOriginal encodeObject: sOriginal];
#endif
#if defined(KEYED_ARCHIVER)
[arOriginal finishEncoding];
#endif
#if defined(KEYED_ARCHIVER)
arOriginal = [[[NSKeyedUnarchiver alloc]
initForReadingWithData: dataOriginal] autorelease];
#else
arOriginal = [[[NSUnarchiver alloc]
initForReadingWithData: dataOriginal] autorelease];
#endif
#if defined(KEYED_ARCHIVER)
sLoaded = [[[arOriginal decodeObjectForKey: @"bla" ] retain] autorelease];
#else
sLoaded = [[[arOriginal decodeObject] retain] autorelease];
#endif
NSLog( @"LOADED: %@", sLoaded );
dataLoaded = [[[NSMutableData alloc] init] autorelease];
#if defined(KEYED_ARCHIVER)
arLoaded = [[[NSKeyedArchiver alloc]
initForWritingWithMutableData: dataLoaded] autorelease];
#else
arLoaded = [[[NSArchiver alloc]
initForWritingWithMutableData: dataLoaded] autorelease];
#endif
#if defined(KEYED_ARCHIVER)
[arLoaded encodeObject: sLoaded forKey: @"bla" ];
#else
[arLoaded encodeObject: sLoaded ];
#endif
#if defined(KEYED_ARCHIVER)
[arLoaded finishEncoding];
#endif
NSLog( @"Length: orginal=%d, loaded=%d",
[dataOriginal length], [dataLoaded length] );
if( [dataOriginal length] != [dataLoaded length] ) {
NSLog( @"Data differs!" );
} else {
BOOL buffersAreEqual = YES;
int i;
b1 = [dataOriginal bytes];
b2 = [dataLoaded bytes];
for( i = 0; i < [dataOriginal length]; i++ ) {
if( b1[ i ] != b2[ i ] ) {
buffersAreEqual = NO;
break;
}
}
if( buffersAreEqual ) {
NSLog( @"Buffers are equal!" );
} else {
NSLog( @"Buffers DIFFER!" );
}
}
exit( 0 );
_______________________________________________________
Reply to this item at:
<http://savannah.gnu.org/bugs/?func=detailitem&item_id=15226>
_______________________________________________
Nachricht geschickt von/durch Savannah
http://savannah.gnu.org/
- [bug #15226] Unarchived objects do not equal archived objects,
Oliver Langer <=