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

Group
 
 

bug #15226: Unarchived objects do not equal archived objects

Submitter:  Oliver Langer <kokosmakrone>
Submitted:  Thu 15 Dec 2005 11:33:49 PM UTC
   
 
Category:  Base/Foundation Severity:  3 - Normal
Priority:  5 - Normal Item Group:  Bug
Status:  Invalid Privacy:  Public
Assigned to:  None Open/Closed:  Closed
* Mandatory Fields

Post a Comment

Add a New Comment Rich Markup
   

Discussion

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>
Group 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>

 

Attached Files

This item currently has no attached files.

(Note: upload size limit is set to 4.0MiB, after insertion of the required escape characters.)

Attach Files:
   
   
Comment:
   

 

Dependencies

This item does not depend on any other items.

No items depend on this one.

 

Mail Notification Carbon-Copy List

 

Votes

There are 0 votes so far. Votes easily highlight which items people would like to see resolved in priority, independently of the priority of the item set by tracker managers.

Only logged-in users can vote.

 

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

History

Follow 2 latest changes.

Date Changed by Updated Field Previous Value => Replaced by
2005-12-21 CaS StatusNone Invalid
    Open/ClosedOpen Closed

Back to the top

Powered by Savane 3.16-2753.
Corresponding source code