bugGNUstep - Bugs: bug #15226, Unarchived objects do not equal...

 
 

You are not allowed to post comments on this tracker with your current authentication level.

bug #15226: Unarchived objects do not equal archived objects

Submitted by:  Oliver Langer <kokosmakrone>
Submitted on:  Thu 15 Dec 2005 11:33:49 PM UTC  
 
Category: Base/FoundationSeverity: 3 - Normal
Item Group: BugStatus: Invalid
Privacy: PublicAssigned to: None
Open/Closed: Closed

Wed 21 Dec 2005 09:11:56 AM UTC, comment #2:

This is not a bug ... this report is essentially saying that the internal binary representations of a string may differ, which is fine/normal (and in particular is an expected behavior for objects in a class cluster).

There is absolutely no guarantee that two archives of the same data structure should be identical, and any code which depends on such an assumption is broken ... even where it happens to work, there is no guarantee it will continue to do so.

For instance, even where the binary representations of archived objects themselves don't differ, archives produced by different versions of MacOS-X or GNUstep will differ because of different version numbers encoded into the archive. It's also perfectly possible/legitimate that archives could contain other information (eg a timestamp) which would mean that two archives of the same data structure would differ.

Richard Frith-Macdonald <CaS>
Project Member
Thu 15 Dec 2005 11:35:57 PM UTC, comment #1:

hmm...sorry for this unformated code....

Oliver Langer <kokosmakrone>
Thu 15 Dec 2005 11:33:49 PM UTC, original submission:

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 );

Oliver Langer <kokosmakrone>

 

No files currently attached

 

Depends on the following items: None found

Items that depend on this one: None found

 

CC list is empty

 

Do you think this task is very important?
If so, you can click here to add your encouragement to it.
This task has 0 encouragements so far.

Only logged-in users can vote.

 

Please enter the title of George Orwell's famous dystopian book (it's a date):

 

 

Follow 2 latest changes.

Date Changed By Updated Field Previous Value => Replaced By
Wed 21 Dec 2005 09:11:56 AM UTCCaSStatusNone=>Invalid
  Open/ClosedOpen=>Closed

Back to the top


Powered by Savane 3.1-cleanup1