mirror of
https://github.com/gnustep/libs-base.git
synced 2025-05-29 16:01:38 +00:00
([Encoder -_encodeObject:withName:isBycopy:isForwardReference:]): See
if object satisfies a forward reference *after* encoding it. This is necessary because the encoding of subobjects may generate forward references. (In a sense, this undoes the last change, but it is significantly different in that we test whether the object is in the object_2_fref table *after* encoding the object; before we looked in the table before encoding the object.) As a consequence, the CODER_OBJECT_FORWARD_SATISFIER tag is no longer necessary; this was used to tag an object before it was encoded, but now we understand that we cannot know whether this object satisfies a forward reference until after it has been encoded. Thus, for all objects we encode an unsigned int after encoding the object itself. This unsigned int is either the forward reference number of zero, depending on whether this object satisfies any forward references. git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@1358 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
parent
919f4e6955
commit
5b21ec95f4
1 changed files with 35 additions and 25 deletions
|
@ -645,38 +645,48 @@ my_object_is_class(id object)
|
|||
NSIntMapValueCallBacks, 0);
|
||||
NSMapInsert (in_progress_table, anObj, (void*)1);
|
||||
|
||||
/* Find out if this object satisfies any previous forward
|
||||
references. */
|
||||
fref = [self _coderForwardReferenceForObject: anObj];
|
||||
if (fref)
|
||||
{
|
||||
|
||||
/* It does satisfy a forward reference; write the forward
|
||||
reference number, so the decoder can know. */
|
||||
[self encodeTag: CODER_OBJECT_FORWARD_SATISFIER];
|
||||
[self encodeValueOfCType: @encode(unsigned)
|
||||
at: &fref
|
||||
withName: @"Object forward cross-reference number"];
|
||||
/* xxx This code used to be below at the place marked `1234' */
|
||||
/* Remove it from the forward reference table, since we'll never
|
||||
have another forward reference for this object. */
|
||||
[self _coderRemoveForwardReferenceForObject: anObj];
|
||||
}
|
||||
else
|
||||
{
|
||||
/* It does not satisfy a forward reference. Note: in future
|
||||
encoding we may have backward references to this object,
|
||||
but we will never need forward references to this object. */
|
||||
[self encodeTag: CODER_OBJECT];
|
||||
}
|
||||
/* Encode the object. */
|
||||
[self encodeTag: CODER_OBJECT];
|
||||
[self encodeIndent];
|
||||
if (bycopy_flag)
|
||||
[self _doEncodeBycopyObject:anObj];
|
||||
else
|
||||
[self _doEncodeObject:anObj];
|
||||
[self encodeUnindent];
|
||||
/* The code above marked `1234' used to be here. */
|
||||
|
||||
/* Find out if this object satisfies any forward references,
|
||||
and encode either the forward reference number, or a
|
||||
zero. NOTE: This test is here, and not before the
|
||||
_doEncode.., because the encoding of this object may,
|
||||
itself, generate a "forward reference" to this object,
|
||||
(ala the in_progress_table). That is, we cannot know
|
||||
whether this object satisfies a forward reference until
|
||||
after it has been encoded. */
|
||||
fref = [self _coderForwardReferenceForObject: anObj];
|
||||
if (fref)
|
||||
{
|
||||
/* It does satisfy a forward reference; write the forward
|
||||
reference number, so the decoder can know. */
|
||||
[self encodeValueOfCType: @encode(unsigned)
|
||||
at: &fref
|
||||
withName: @"Object forward cross-reference number"];
|
||||
/* Remove it from the forward reference table, since we'll never
|
||||
have another forward reference for this object. */
|
||||
[self _coderRemoveForwardReferenceForObject: anObj];
|
||||
}
|
||||
else
|
||||
{
|
||||
/* It does not satisfy any forward references. Let the
|
||||
decoder know this by encoding NULL. Note: in future
|
||||
encoding we may have backward references to this
|
||||
object, but we will never need forward references to
|
||||
this object. */
|
||||
unsigned null_fref = 0;
|
||||
[self encodeValueOfCType: @encode(unsigned)
|
||||
at: &null_fref
|
||||
withName: @"Object forward cross-reference number"];
|
||||
}
|
||||
|
||||
/* Register that we have encoded it so that future encoding can
|
||||
do backward references properly. */
|
||||
[self _coderInternalCreateReferenceForObject: anObj];
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue