mirror of
https://github.com/gnustep/libs-base.git
synced 2025-05-03 13:21:00 +00:00
([Coder -encodeConditionalObject:]): Comment additions.
([Coder -decodeObject]): Likewise. git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@1523 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
parent
e9aff2a6ef
commit
fb05cbcb97
1 changed files with 23 additions and 14 deletions
|
@ -194,23 +194,27 @@ static BOOL debug_coder = NO;
|
||||||
|
|
||||||
- (void) encodeConditionalObject: (id)anObject
|
- (void) encodeConditionalObject: (id)anObject
|
||||||
{
|
{
|
||||||
/* Apparently, NeXT's implementation doesn't actually
|
/* NeXT's implementation handles *forward* references by running
|
||||||
handle *forward* references, (hence it's use of -decodeObject,
|
through the entire encoding process twice! GNU Coding can handle
|
||||||
instead of decodeObjectAt:.)
|
forward references with only one pass. Therefore, however, GNU
|
||||||
So here, we only encode the object for real if the object has
|
Coding cannot return a *forward* reference from -decodeObject, so
|
||||||
already been written.
|
here, assuming this call to -encodeConditionalObject: is mirrored
|
||||||
This means that if you encode a web of objects with the more
|
by a -decodeObject, we don't try to encode *forward*
|
||||||
powerful GNU Coder, and then try to decode them with NSArchiver,
|
references.
|
||||||
you could get corrupt data on the stack when Coder resolves its
|
|
||||||
forward references. I recommend just using the GNU Coder. */
|
Note that this means objects that use -encodeConditionalObject:
|
||||||
#if 1
|
that are encoded in the GNU style might decode a nil where
|
||||||
|
NeXT-style encoded would not. I don't see this a huge problem;
|
||||||
|
at least not as bad as NeXT coding mechanism that actually causes
|
||||||
|
crashes in situations where GNU's does fine. Still, if we wanted
|
||||||
|
to fix this, we might be able to build a kludgy fix based on
|
||||||
|
detecting when this would happen, rewinding the stream to the
|
||||||
|
"conditional" point, and encoding again. Yuck. */
|
||||||
|
|
||||||
if ([self _coderReferenceForObject: anObject])
|
if ([self _coderReferenceForObject: anObject])
|
||||||
[self encodeObject: anObject];
|
[self encodeObject: anObject];
|
||||||
else
|
else
|
||||||
[self encodeObject: nil];
|
[self encodeObject: nil];
|
||||||
#else
|
|
||||||
[self encodeObjectReference: anObject withName: NULL];
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void) encodeRootObject: (id)rootObject
|
- (void) encodeRootObject: (id)rootObject
|
||||||
|
@ -220,7 +224,12 @@ static BOOL debug_coder = NO;
|
||||||
|
|
||||||
- (id) decodeObject
|
- (id) decodeObject
|
||||||
{
|
{
|
||||||
/* xxx This won't work for decoding forward references!!! */
|
/* This won't work for decoding GNU-style forward references because
|
||||||
|
once the GNU decoder finds the object later in the decoding, it
|
||||||
|
will back-patch by storing the id in &o... &o will point to some
|
||||||
|
weird location on the stack! This is why we make the GNU
|
||||||
|
implementation of -encodeConditionalObject: not encode forward
|
||||||
|
references. */
|
||||||
id o;
|
id o;
|
||||||
[self decodeObjectAt: &o withName: NULL];
|
[self decodeObjectAt: &o withName: NULL];
|
||||||
return o;
|
return o;
|
||||||
|
|
Loading…
Reference in a new issue