Attempt to fix brain-dead code I stupidly committed while ill with flu.

Probably not right yet - but better.


git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@3629 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
richard 1999-01-29 21:29:32 +00:00
parent 1fc70ead96
commit 723e76469e
4 changed files with 122 additions and 110 deletions

View file

@ -74,12 +74,12 @@ enum {
+ (NSConnection*) connectionByInPort: (NSPort*)ip + (NSConnection*) connectionByInPort: (NSPort*)ip
outPort: (NSPort*)op; outPort: (NSPort*)op;
+ (NSConnection*) connectionByOutPort: (NSPort*)op; + (NSConnection*) connectionByOutPort: (NSPort*)op;
+ (NSDistantObject*) includesLocalTarget: (gsu32)target; + (NSDistantObject*) includesLocalTarget: (unsigned)target;
- (NSDistantObject*) includesLocalTarget: (gsu32)target; - (NSDistantObject*) includesLocalTarget: (unsigned)target;
- (NSDistantObject*) localForObject: (id)object; - (NSDistantObject*) localForObject: (id)object;
- (NSDistantObject*) localForTarget: (gsu32)target; - (NSDistantObject*) localForTarget: (unsigned)target;
- (NSDistantObject*) proxyForTarget: (gsu32)target; - (NSDistantObject*) proxyForTarget: (unsigned)target;
- (void) retainTarget: (gsu32)target; - (void) retainTarget: (unsigned)target;
- (void) setNotOwned; - (void) setNotOwned;
@end @end

View file

@ -34,7 +34,7 @@
@private @private
NSConnection *_connection; NSConnection *_connection;
id _object; id _object;
gsu32 _handle; unsigned _handle;
BOOL _isVended; BOOL _isVended;
Protocol *_protocol; Protocol *_protocol;
} }
@ -43,22 +43,22 @@
connection: (NSConnection*)aConnection; connection: (NSConnection*)aConnection;
/* /*
* NB. Departure from the OpenStep/MacOS spec - the type of a target * NB. Departure from the OpenStep/MacOS spec - the type of a target
* is a 32-bit integer, not an id, since we can't safely pass id's * is an integer, not an id, since we can't safely pass id's
* between address spaces on machines with different pointer sizes. * between address spaces on machines with different pointer sizes.
*/ */
+ (NSDistantObject*) proxyWithTarget: (gsu32)anObject + (NSDistantObject*) proxyWithTarget: (unsigned)anObject
connection: (NSConnection*)aConnection; connection: (NSConnection*)aConnection;
- (NSConnection*) connectionForProxy; - (NSConnection*) connectionForProxy;
- (id) initWithLocal: (id)anObject connection: (NSConnection*)aConnection; - (id) initWithLocal: (id)anObject connection: (NSConnection*)aConnection;
- (id) initWithTarget: (gsu32)anObject connection: (NSConnection*)aConnection; - (id) initWithTarget: (unsigned)anObject connection: (NSConnection*)aConnection;
- (void) setProtocolForProxy: (Protocol*)aProtocol; - (void) setProtocolForProxy: (Protocol*)aProtocol;
@end @end
@interface NSDistantObject(GNUstepExtensions) @interface NSDistantObject(GNUstepExtensions)
+ newForRemoteTarget: (gsu32)target connection: (NSConnection*)conn; + newForRemoteTarget: (unsigned)target connection: (NSConnection*)conn;
- awakeAfterUsingCoder: aDecoder; - awakeAfterUsingCoder: aDecoder;
- classForPortCoder; - classForPortCoder;
@ -66,7 +66,7 @@
- (const char *) selectorTypeForProxy: (SEL)selector; - (const char *) selectorTypeForProxy: (SEL)selector;
- forward: (SEL)aSel :(arglist_t)frame; - forward: (SEL)aSel :(arglist_t)frame;
- (id) localForProxy; - (id) localForProxy;
- (gsu32) targetForProxy; - (unsigned) targetForProxy;
@end @end
#endif /* __NSDistantObject_h_GNUSTEP_BASE_INCLUDE */ #endif /* __NSDistantObject_h_GNUSTEP_BASE_INCLUDE */

View file

@ -64,6 +64,7 @@ NSString *NSConnectionProxyCount = @"NSConnectionProxyCount";
@interface NSDistantObject (NSConnection) @interface NSDistantObject (NSConnection)
- (BOOL) isVended; - (BOOL) isVended;
- (void) setProxyTarget: (unsigned)target;
- (void) setVended; - (void) setVended;
@end @end
@ -72,12 +73,18 @@ NSString *NSConnectionProxyCount = @"NSConnectionProxyCount";
{ {
return _isVended; return _isVended;
} }
- (void) setProxyTarget: (unsigned)target
{
_handle = target;
}
- (void) setVended - (void) setVended
{ {
_isVended = YES; _isVended = YES;
} }
@end @end
static unsigned local_object_counter = 0;
/* /*
* ConnectionLocalCounter is a trivial class to keep track of how * ConnectionLocalCounter is a trivial class to keep track of how
* many different connections a particular local object is vended * many different connections a particular local object is vended
@ -87,7 +94,10 @@ NSString *NSConnectionProxyCount = @"NSConnectionProxyCount";
*/ */
@interface ConnectionLocalCounter : NSObject @interface ConnectionLocalCounter : NSObject
{ {
unsigned ref; @public
unsigned ref;
unsigned target;
id object;
} }
- (void)decrement; - (void)decrement;
- (void)increment; - (void)increment;
@ -98,26 +108,27 @@ NSString *NSConnectionProxyCount = @"NSConnectionProxyCount";
- (void) decrement - (void) decrement
{ {
ref--; ref--;
} }
- (void) increment - (void) increment
{ {
ref++; ref++;
} }
- init - init
{ {
self = [super init]; self = [super init];
if (self) { if (self)
ref = 1; {
ref = 1;
} }
return self; return self;
} }
- (unsigned int) value - (unsigned int) value
{ {
return ref; return ref;
} }
@end @end
@ -132,8 +143,8 @@ NSString *NSConnectionProxyCount = @"NSConnectionProxyCount";
*/ */
@interface CachedLocalObject : NSObject @interface CachedLocalObject : NSObject
{ {
id obj; id obj;
int time; int time;
} }
- (BOOL)countdown; - (BOOL)countdown;
- (id) obj; - (id) obj;
@ -144,29 +155,29 @@ NSString *NSConnectionProxyCount = @"NSConnectionProxyCount";
+ (CachedLocalObject*) itemWithObject: (id)o time: (int)t + (CachedLocalObject*) itemWithObject: (id)o time: (int)t
{ {
CachedLocalObject *item = [[self alloc] init]; CachedLocalObject *item = [[self alloc] init];
item->obj = [o retain]; item->obj = [o retain];
item->time = t; item->time = t;
return [item autorelease]; return [item autorelease];
} }
- (void) dealloc - (void) dealloc
{ {
[obj release]; [obj release];
[super dealloc]; [super dealloc];
} }
- (BOOL) countdown - (BOOL) countdown
{ {
if (time-- > 0) if (time-- > 0)
return YES; return YES;
return NO; return NO;
} }
- (id) obj - (id) obj
{ {
return obj; return obj;
} }
@end @end
@ -1432,67 +1443,75 @@ static int messages_received_count;
- (void) _service_release: rmc forConnection: receiving_connection - (void) _service_release: rmc forConnection: receiving_connection
{ {
unsigned int count; unsigned int count;
unsigned int pos; unsigned int pos;
NSParameterAssert (is_valid); NSParameterAssert (is_valid);
if ([rmc connection] != self) { if ([rmc connection] != self)
[NSException raise: @"ProxyDecodedBadTarget" {
format: @"request to release object on bad connection"]; [NSException raise: @"ProxyDecodedBadTarget"
format: @"request to release object on bad connection"];
} }
[rmc decodeValueOfCType: @encode(typeof(count)) [rmc decodeValueOfCType: @encode(typeof(count))
at: &count at: &count
withName: NULL]; withName: NULL];
for (pos = 0; pos < count; pos++) { for (pos = 0; pos < count; pos++)
gsu32 target; {
char vended; unsigned target;
NSDistantObject *prox; char vended;
NSDistantObject *prox;
[rmc decodeValueOfCType: @encode(typeof(target)) [rmc decodeValueOfCType: @encode(typeof(target))
at: &target at: &target
withName: NULL]; withName: NULL];
[rmc decodeValueOfCType: @encode(typeof(char)) [rmc decodeValueOfCType: @encode(typeof(char))
at: &vended at: &vended
withName: NULL]; withName: NULL];
prox = [self includesLocalObject:(void*)target]; prox = (NSDistantObject*)[self includesLocalTarget: target];
if (prox != nil) { if (prox != nil)
if (vended) { {
[prox setVended]; if (vended)
{
[prox setVended];
} }
[self removeLocalObject: (id)target]; [self removeLocalObject: [prox localForProxy]];
} }
} }
[rmc dismiss]; [rmc dismiss];
} }
- (void) _service_retain: rmc forConnection: receiving_connection - (void) _service_retain: rmc forConnection: receiving_connection
{ {
gsu32 target; unsigned target;
NSParameterAssert (is_valid); NSParameterAssert (is_valid);
if ([rmc connection] != self) { if ([rmc connection] != self)
[NSException raise: @"ProxyDecodedBadTarget" {
format: @"request to retain object on bad connection"]; [NSException raise: @"ProxyDecodedBadTarget"
format: @"request to retain object on bad connection"];
} }
[rmc decodeValueOfCType: @encode(typeof(target)) [rmc decodeValueOfCType: @encode(typeof(target))
at: &target at: &target
withName: NULL]; withName: NULL];
if ([self includesLocalObject:(void*)target] == nil) { if ([self includesLocalTarget: target] == nil)
if ([[self class] includesLocalObject:(void*)target] != nil) { {
[NSDistantObject proxyWithLocal: (id)target connection: self]; ConnectionLocalCounter *counter;
}
counter = (ConnectionLocalCounter*)[[self class] includesLocalTarget: target];
if (counter != nil)
[NSDistantObject proxyWithLocal: counter->object connection: self];
} }
[rmc dismiss]; [rmc dismiss];
} }
- (void) shutdown - (void) shutdown
@ -1518,7 +1537,7 @@ static int messages_received_count;
[rmc dismiss]; [rmc dismiss];
} }
- (const char *) typeForSelector: (SEL)sel remoteTarget: (gsu32)target - (const char *) typeForSelector: (SEL)sel remoteTarget: (unsigned)target
{ {
id op, ip; id op, ip;
char *type = 0; char *type = 0;
@ -1534,7 +1553,7 @@ static int messages_received_count;
[op encodeValueOfObjCType:":" [op encodeValueOfObjCType:":"
at:&sel at:&sel
withName:NULL]; withName:NULL];
[op encodeValueOfCType:@encode(gsu32) [op encodeValueOfCType:@encode(unsigned)
at:&target at:&target
withName:NULL]; withName:NULL];
[op dismiss]; [op dismiss];
@ -1549,7 +1568,7 @@ static int messages_received_count;
- (void) _service_typeForSelector: rmc - (void) _service_typeForSelector: rmc
{ {
NSPortCoder* op; NSPortCoder* op;
gsu32 target; unsigned target;
NSDistantObject *p; NSDistantObject *p;
id o; id o;
SEL sel; SEL sel;
@ -1567,7 +1586,7 @@ static int messages_received_count;
[rmc decodeValueOfObjCType:":" [rmc decodeValueOfObjCType:":"
at:&sel at:&sel
withName:NULL]; withName:NULL];
[rmc decodeValueOfCType:@encode(gsu32) [rmc decodeValueOfCType:@encode(unsigned)
at:&target at:&target
withName:NULL]; withName:NULL];
p = [self includesLocalTarget: target]; p = [self includesLocalTarget: target];
@ -1779,16 +1798,15 @@ static int messages_received_count;
/* Managing objects and proxies. */ /* Managing objects and proxies. */
- (void) addLocalObject: anObj - (void) addLocalObject: anObj
{ {
id object = [anObj localForProxy]; id object = [anObj localForProxy];
gsu32 target = [anObj targetForProxy]; unsigned target;
id counter; ConnectionLocalCounter *counter;
NSParameterAssert (is_valid); NSParameterAssert (is_valid);
[proxiesHashGate lock]; [proxiesHashGate lock];
/* xxx Do we need to check to make sure it's not already there? */ /* xxx Do we need to check to make sure it's not already there? */
/* This retains anObj. */ /* This retains anObj. */
NSMapInsert(local_objects, (void*)object, anObj); NSMapInsert(local_objects, (void*)object, anObj);
NSMapInsert(local_targets, (void*)target, anObj);
/* /*
* Keep track of local objects accross all connections. * Keep track of local objects accross all connections.
@ -1797,14 +1815,20 @@ static int messages_received_count;
if (counter) if (counter)
{ {
[counter increment]; [counter increment];
target = counter->target;
} }
else else
{ {
counter = [ConnectionLocalCounter new]; counter = [ConnectionLocalCounter new];
target = ++local_object_counter;
counter->target = target;
counter->object = object;
NSMapInsert(all_connections_local_objects, (void*)object, counter); NSMapInsert(all_connections_local_objects, (void*)object, counter);
NSMapInsert(all_connections_local_targets, (void*)target, counter); NSMapInsert(all_connections_local_targets, (void*)target, counter);
[counter release]; [counter release];
} }
[anObj setProxyTarget: target];
NSMapInsert(local_targets, (void*)target, anObj);
if (debug_connection > 2) if (debug_connection > 2)
NSLog(@"add local object (0x%x) to connection (0x%x) (ref %d)\n", NSLog(@"add local object (0x%x) to connection (0x%x) (ref %d)\n",
(unsigned)object, (unsigned) self, [counter value]); (unsigned)object, (unsigned) self, [counter value]);
@ -1840,13 +1864,16 @@ static int messages_received_count;
- (void) removeLocalObject: anObj - (void) removeLocalObject: anObj
{ {
NSDistantObject *prox = NSMapGet(local_objects, (void*)anObj); NSDistantObject *prox;
gsu32 target = [prox targetForProxy]; unsigned target;
id counter; id counter;
unsigned val = 0; unsigned val = 0;
[proxiesHashGate lock]; [proxiesHashGate lock];
prox = NSMapGet(local_objects, (void*)anObj);
target = [prox targetForProxy];
/* /*
* If all references to a local proxy have gone - remove the * If all references to a local proxy have gone - remove the
* global reference as well. * global reference as well.
@ -1914,7 +1941,7 @@ static int messages_received_count;
withName: NULL]; withName: NULL];
for (i = 0; i < number; i++) { for (i = 0; i < number; i++) {
gsu32 target = [list[i] targetForProxy]; unsigned target = [list[i] targetForProxy];
char vended = [list[i] isVended]; char vended = [list[i] isVended];
[op encodeValueOfCType: @encode(typeof(target)) [op encodeValueOfCType: @encode(typeof(target))
@ -1936,7 +1963,7 @@ static int messages_received_count;
NS_ENDHANDLER NS_ENDHANDLER
} }
- (void) retainTarget: (gsu32)target - (void) retainTarget: (unsigned)target
{ {
NS_DURING NS_DURING
{ {
@ -2009,7 +2036,7 @@ static int messages_received_count;
return c; return c;
} }
- (NSDistantObject*) proxyForTarget: (gsu32)target - (NSDistantObject*) proxyForTarget: (unsigned)target
{ {
NSDistantObject *p; NSDistantObject *p;
@ -2036,7 +2063,7 @@ static int messages_received_count;
[proxiesHashGate unlock]; [proxiesHashGate unlock];
} }
- (id) includesProxyForTarget: (gsu32)target - (id) includesProxyForTarget: (unsigned)target
{ {
NSDistantObject *ret; NSDistantObject *ret;
@ -2058,7 +2085,7 @@ static int messages_received_count;
return ret; return ret;
} }
- (id) includesLocalTarget: (gsu32)target - (id) includesLocalTarget: (unsigned)target
{ {
NSDistantObject* ret; NSDistantObject* ret;
@ -2075,16 +2102,16 @@ static int messages_received_count;
for the Proxy to check the Proxy's connection only (using for the Proxy to check the Proxy's connection only (using
-includesLocalTarget), because the proxy may have come from a -includesLocalTarget), because the proxy may have come from a
triangle connection. */ triangle connection. */
+ (id) includesLocalTarget: (gsu32)anObj + (id) includesLocalTarget: (unsigned)target
{ {
id ret; id ret;
/* Don't assert (is_valid); */ /* Don't assert (is_valid); */
NSParameterAssert (all_connections_local_targets); NSParameterAssert (all_connections_local_targets);
[proxiesHashGate lock]; [proxiesHashGate lock];
ret = NSMapGet (all_connections_local_targets, (void*)anObj); ret = NSMapGet (all_connections_local_targets, (void*)target);
if (ret == nil) { if (ret == nil) {
ret = NSMapGet (all_connections_local_cached, (void*)anObj); ret = NSMapGet (all_connections_local_cached, (void*)target);
} }
[proxiesHashGate unlock]; [proxiesHashGate unlock];
return ret; return ret;

View file

@ -53,17 +53,6 @@ enum
PROXY_REMOTE_FOR_BOTH PROXY_REMOTE_FOR_BOTH
}; };
static gsu32 handle_counter = 0;
static NSRecursiveLock *handle_lock = nil;
+ (void) initialize
{
if (self == [NSDistantObject class])
{
handle_lock = [NSRecursiveLock new];
}
}
+ (NSDistantObject*) proxyWithLocal: (id)anObject + (NSDistantObject*) proxyWithLocal: (id)anObject
connection: (NSConnection*)aConnection connection: (NSConnection*)aConnection
{ {
@ -78,7 +67,7 @@ static NSRecursiveLock *handle_lock = nil;
connection: aConnection] autorelease]; connection: aConnection] autorelease];
} }
+ (NSDistantObject*) proxyWithTarget: (gsu32)anObject + (NSDistantObject*) proxyWithTarget: (unsigned)anObject
connection: (NSConnection*)aConnection connection: (NSConnection*)aConnection
{ {
NSDistantObject *new_proxy; NSDistantObject *new_proxy;
@ -122,7 +111,7 @@ static NSRecursiveLock *handle_lock = nil;
- (void) encodeWithCoder: (NSCoder*)aRmc - (void) encodeWithCoder: (NSCoder*)aRmc
{ {
gsu32 proxy_target; unsigned proxy_target;
gsu8 proxy_tag; gsu8 proxy_tag;
NSConnection *encoder_connection; NSConnection *encoder_connection;
@ -264,10 +253,6 @@ format: @"NSDistantObject objects only encode with PortEncoder class"];
*/ */
_object = [anObject retain]; _object = [anObject retain];
[handle_lock lock];
_handle = ++handle_counter;
[handle_lock unlock];
/* /*
* We register this object with the connection using it. * We register this object with the connection using it.
*/ */
@ -280,7 +265,7 @@ format: @"NSDistantObject objects only encode with PortEncoder class"];
return self; return self;
} }
- (id) initWithTarget: (gsu32)target connection: (NSConnection*)aConnection - (id) initWithTarget: (unsigned)target connection: (NSConnection*)aConnection
{ {
NSDistantObject *new_proxy; NSDistantObject *new_proxy;
@ -388,7 +373,7 @@ format: @"NSDistantObject objects only encode with PortEncoder class"];
@implementation NSDistantObject(GNUstepExtensions) @implementation NSDistantObject(GNUstepExtensions)
+ newForRemoteTarget: (gsu32)target connection: (NSConnection*)conn + newForRemoteTarget: (unsigned)target connection: (NSConnection*)conn
{ {
return [[NSDistantObject alloc] initWithTarget: target connection: conn]; return [[NSDistantObject alloc] initWithTarget: target connection: conn];
} }
@ -413,7 +398,7 @@ static inline BOOL class_is_kind_of (Class self, Class aClassObject)
+ newWithCoder: aRmc + newWithCoder: aRmc
{ {
gsu8 proxy_tag; gsu8 proxy_tag;
gsu32 target; unsigned target;
id decoder_connection; id decoder_connection;
if ([aRmc class] != [PortDecoder class]) if ([aRmc class] != [PortDecoder class])
@ -586,7 +571,7 @@ format: @"NSDistantObject objects only decode with PortDecoder class"];
return _object; return _object;
} }
- (gsu32) targetForProxy - (unsigned) targetForProxy
{ {
return _handle; return _handle;
} }