mirror of
https://github.com/gnustep/libs-base.git
synced 2025-05-29 16:01:38 +00:00
(debug_coder): Make it a static var instead of a #define.
([Encoder -_objectWillBeInProgress:]): New method. ([Encoder -_objectNoLongerInProgress:]): New method. Depending on whether we are doing GNU or OpenStep style forward references one of these two methods will create a backward reference to the object by calling -_coderInternalCreateReferenceForObject:. This will effect whether encoding make forward or backward references to objects in progress. GNU uses forward references, which is robust even when the object's -initWithCoder substitutes another object for self. ([Encoder -_encodeObject:withName:isBycopy:isForwardReference:]): Use new methods. Don't call -_coderInternalCreateReferenceForObject here, let one of the ...InProgress methods do it. git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@1481 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
parent
1e171d13a7
commit
6687fc397a
1 changed files with 44 additions and 17 deletions
|
@ -34,7 +34,7 @@ static int default_format_version;
|
|||
static id default_stream_class;
|
||||
static id default_cstream_class;
|
||||
|
||||
#define debug_coder 0
|
||||
static int debug_coder = 0;
|
||||
#define DEFAULT_FORMAT_VERSION 0
|
||||
|
||||
|
||||
|
@ -325,6 +325,41 @@ my_object_is_class(id object)
|
|||
[self _coderCreateReferenceForObject: anObj];
|
||||
}
|
||||
|
||||
|
||||
/* Handling the in_progress_table. These are called before and after
|
||||
the actual object (not a forward or backward reference) is encoded.
|
||||
|
||||
One of these objects should also call
|
||||
-_coderInternalCreateReferenceForObject:. GNU archiving calls it
|
||||
in the first, in order to force forward references to objects that
|
||||
are in progress; this allows for -initWithCoder: methods that
|
||||
deallocate self, and return another object. OpenStep-style coding
|
||||
calls it in the second, meaning that we never create forward
|
||||
references to objects that are in progress; we encode a backward
|
||||
reference to the in progress object, and assume that it will not
|
||||
change location. */
|
||||
|
||||
- (void) _objectWillBeInProgress: anObj
|
||||
{
|
||||
if (!in_progress_table)
|
||||
in_progress_table =
|
||||
/* This is "NonOwnedPointer", and not "Object", because
|
||||
with "Object" we would get an infinite loop with distributed
|
||||
objects when we try to put a Proxy in in the table, and
|
||||
send the proxy the -hash method. */
|
||||
NSCreateMapTable (NSNonOwnedPointerMapKeyCallBacks,
|
||||
NSIntMapValueCallBacks, 0);
|
||||
NSMapInsert (in_progress_table, anObj, (void*)1);
|
||||
}
|
||||
|
||||
- (void) _objectNoLongerInProgress: anObj
|
||||
{
|
||||
NSMapRemove (in_progress_table, anObj);
|
||||
/* Register that we have encoded it so that future encoding can
|
||||
do backward references properly. */
|
||||
[self _coderInternalCreateReferenceForObject: anObj];
|
||||
}
|
||||
|
||||
|
||||
/* Method for encoding things. */
|
||||
|
||||
|
@ -634,16 +669,10 @@ my_object_is_class(id object)
|
|||
the object. */
|
||||
unsigned fref;
|
||||
|
||||
/* Register the object as being in progress of encoding. */
|
||||
if (!in_progress_table)
|
||||
in_progress_table =
|
||||
/* This is "NonOwnedPointer", and not "Object", because
|
||||
with "Object" we would get an infinite loop with distributed
|
||||
objects when we try to put a Proxy in in the table, and
|
||||
send the proxy the -hash method. */
|
||||
NSCreateMapTable (NSNonOwnedPointerMapKeyCallBacks,
|
||||
NSIntMapValueCallBacks, 0);
|
||||
NSMapInsert (in_progress_table, anObj, (void*)1);
|
||||
/* Register the object as being in progress of encoding. In
|
||||
OpenStep-style archiving, this method also calls
|
||||
-_coderInternalCreateReferenceForObject:. */
|
||||
[self _objectWillBeInProgress: anObj];
|
||||
|
||||
/* Encode the object. */
|
||||
[self encodeTag: CODER_OBJECT];
|
||||
|
@ -687,12 +716,10 @@ my_object_is_class(id object)
|
|||
withName: @"Object forward cross-reference number"];
|
||||
}
|
||||
|
||||
/* Register that we have encoded it so that future encoding can
|
||||
do backward references properly. */
|
||||
[self _coderInternalCreateReferenceForObject: anObj];
|
||||
|
||||
/* We're done encoding the object, it's no longer in progress. */
|
||||
NSMapRemove (in_progress_table, anObj);
|
||||
/* We're done encoding the object, it's no longer in progress.
|
||||
In GNU-style archiving, this method also calls
|
||||
-_coderInternalCreateReferenceForObject:. */
|
||||
[self _objectNoLongerInProgress: anObj];
|
||||
}
|
||||
}
|
||||
[self encodeUnindent];
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue