Byref patches from Frith-MacDonald

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@2777 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
Adam Fedor 1998-03-23 20:49:54 +00:00
parent 60070d1e6e
commit 5f22cd9f54
17 changed files with 218 additions and 30 deletions

View file

@ -1,3 +1,47 @@
Fri Mar 20 11:15:00 1998 Richard Frith-Macdonald <richard@brainstorm.co.uk>
* checks/client.m: Added some tests for passing objects byref
* checks/server.h: Added ([-sendByref:]) to protocol.
* checks/server.m: Added ([-sendByref:]) for testing 'byref'.
* src/Coder.m: Added ([-encodeByrefObject:])
* src/Encoder.m: Added ([-_doEncodeByrefObject:]) and changed the
designated encoding method throughout from
([-_encodeObject:withName:isBycopy:isForwardReference:]) to
([-_encodeObject:withName:isBycopy:isByref:isForwardReference:])
* src/NSCoder.m: Added ([-encodeBytes:length:]),
([-encodeByrefObject:]) and ([-decodeBytesWithReturnedLength:])
* src/NSConnection.m: Modified ([-forwardForProxy:selector:argFrame:])
and ([-_service_forwardForProxy:]) methods to handle byref flag.
* src/NSDictionary.m: Added ([+dictionaryWithDictionary:])
* src/NSPortCoder.m: Added ([-isByref]) and ([-_doEncodeByrefObject:])
methods and modified ([-_doEncodeBycopyObject:]) to handle byref flag.
* src/include/Coding.h: Added ([-encodeByrefObject:])
* src/include/NSCoder.h: Added ([-encodeBytes:length:]),
([-encodeByrefObject:]) and ([-decodeBytesWithReturnedLength:])
* src/include/NSDictionary.h: Fixed prototype for the
([+dictionaryWithDictionary:]) method.
* src/include/NSPortCoder.h: Added ([-isByref])
* src/objc-gnu2next.m: Added _F_BYREF flag code
Fri Mar 13 15:05:00 1998 Richard Frith-Macdonald <richard@brainstorm.co.uk>
* src/NSCalendarDate.m: ([-descriptionWithCalendarFormat:locale:])
Fixed bug in displaying time-zone - was displaying minutes and
seconds when should have been showing hours and minutes.
Wed Mar 11 11:56:00 1998 Richard Frith-Macdonald <richard@brainstorm.co.uk>
* src/NSArray.m: ([-copyWithZone:]) changed to use the

View file

@ -373,7 +373,7 @@ threads, you need to specify the thread package you are using when
running configure:
@example
LIBS=-lpthread; ./configure --prefix=/usr/local/GNUstep
LIBS=-lpcthread; ./configure --prefix=/usr/local/GNUstep
@end example
After this you should add the shell script @file{GNUstep.sh} in the makefile

View file

@ -60,6 +60,8 @@
withName: (id /*<String>*/)name;
- (void) encodeBycopyObject: anObj
withName: (id /*<String>*/)name;
- (void) encodeByrefObject: anObj
withName: (id /*<String>*/)name;
- (void) encodeRootObject: anObj
withName: (id /*<String>*/)name;

View file

@ -44,6 +44,8 @@
count: (unsigned)count
at: (const void*)array;
- (void) encodeBycopyObject: (id)anObject;
- (void) encodeByrefObject: (id)anObject;
- (void) encodeBytes: (void*)addr length: (unsigned)l;
- (void) encodeConditionalObject: (id)anObject;
- (void) encodeDataObject: (NSData*)data;
- (void) encodeObject: (id)anObject;
@ -61,6 +63,7 @@
- (void) decodeArrayOfObjCType: (const char*)type
count: (unsigned)count
at: (void*)address;
- (void*) decodeBytesWithReturnedLength: (unsigned*)l;
- (NSData*) decodeDataObject;
- (id) decodeObject;
- (id) decodePropertyList;

View file

@ -43,7 +43,7 @@
+ allocWithZone: (NSZone*)zone;
+ dictionary;
+ dictionaryWithContentsOfFile:(NSString *)path;
+ dictionaryWithDictionary: (NSDictionary)aDict;
+ dictionaryWithDictionary: (NSDictionary*)aDict;
+ dictionaryWithObjects: (NSArray*)objects forKeys: (NSArray*)keys;
+ dictionaryWithObjects: (id*)objects forKeys: (id*)keys
count: (unsigned)count;

View file

@ -38,6 +38,7 @@
- (NSPort*) decodePortObject;
- (void) encodePortObject: (NSPort*)aPort;
- (BOOL) isBycopy;
- (BOOL) isByref;
@end

View file

@ -199,6 +199,11 @@ static BOOL debug_coder = NO;
[self encodeBycopyObject: anObject withName: NULL];
}
- (void) encodeByrefObject: (id)anObject
{
[self encodeByrefObject: anObject withName: NULL];
}
- (void) encodeConditionalObject: (id)anObject
{
/* NeXT's implementation handles *forward* references by running

View file

@ -578,7 +578,7 @@ my_object_is_class(id object)
}
/* These next two methods are the designated coder methods called when
/* These next three methods are the designated coder methods called when
we've determined that the object has not already been
encoded---we're not simply going to encode a cross-reference number
to the object, we're actually going to encode an object (either a
@ -611,17 +611,24 @@ my_object_is_class(id object)
[encoded_object encodeWithCoder: (id)self];
}
/* This method overridden by ConnectedCoder */
/* This method overridden by NSPortCoder */
- (void) _doEncodeObject: anObj
{
[self _doEncodeBycopyObject:anObj];
}
/* This method overridden by NSPortCoder */
- (void) _doEncodeByrefObject: anObj
{
[self _doEncodeObject: anObj];
}
/* This is the designated object encoder */
- (void) _encodeObject: anObj
withName: (NSString*) name
isBycopy: (BOOL) bycopy_flag
isByref: (BOOL) byref_flag
isForwardReference: (BOOL) forward_ref_flag
{
[self encodeName:name];
@ -681,6 +688,8 @@ my_object_is_class(id object)
[self encodeIndent];
if (bycopy_flag)
[self _doEncodeBycopyObject:anObj];
else if (byref_flag)
[self _doEncodeByrefObject:anObj];
else
[self _doEncodeObject:anObj];
[self encodeUnindent];
@ -730,20 +739,42 @@ my_object_is_class(id object)
- (void) encodeObject: anObj
withName: (NSString*)name
{
[self _encodeObject:anObj withName:name isBycopy:NO isForwardReference:NO];
[self _encodeObject:anObj
withName:name
isBycopy:NO
isByref:NO
isForwardReference:NO];
}
- (void) encodeBycopyObject: anObj
withName: (NSString*)name
{
[self _encodeObject:anObj withName:name isBycopy:YES isForwardReference:NO];
[self _encodeObject:anObj
withName:name
isBycopy:YES
isByref:NO
isForwardReference:NO];
}
- (void) encodeByrefObject: anObj
withName: (NSString*)name
{
[self _encodeObject:anObj
withName:name
isBycopy:NO
isByref:YES
isForwardReference:NO];
}
- (void) encodeObjectReference: anObj
withName: (NSString*)name
{
[self _encodeObject:anObj withName:name isBycopy:NO isForwardReference:YES];
[self _encodeObject:anObj
withName:name
isBycopy:NO
isByref:NO
isForwardReference:YES];
}

View file

@ -950,9 +950,11 @@ static id long_day[7] = {@"Sunday",
z = [time_zone timeZoneSecondsFromGMT];
if (z < 0) {
z = -z;
z /= 60;
k = VSPRINTF_LENGTH(sprintf(&(buf[j]),"-%02d%02d",z/60,z%60));
}
else {
z /= 60;
k = VSPRINTF_LENGTH(sprintf(&(buf[j]),"+%02d%02d",z/60,z%60));
}
j += k;

View file

@ -24,6 +24,7 @@
#include <config.h>
#include <gnustep/base/preface.h>
#include <gnustep/base/MallocAddress.h>
#include <Foundation/NSCoder.h>
#include <gnustep/base/NSCoder.h>
@ -36,7 +37,7 @@
}
- (void) encodeValueOfObjCType: (const char*)type
at: (const void*)address;
at: (const void*)address
{
[self subclassResponsibility:_cmd];
}
@ -47,18 +48,18 @@
[self subclassResponsibility:_cmd];
}
- (void) encodeDataObject: (NSData*)data;
- (void) encodeDataObject: (NSData*)data
{
[self subclassResponsibility:_cmd];
}
- (NSData*) decodeDataObject;
- (NSData*) decodeDataObject
{
[self subclassResponsibility:_cmd];
return nil;
}
- (unsigned int) versionForClassName: (NSString*)className;
- (unsigned int) versionForClassName: (NSString*)className
{
[self subclassResponsibility:_cmd];
return 0;
@ -84,51 +85,66 @@
at:where];
}
- (void) encodeBycopyObject: (id)anObject;
- (void) encodeBycopyObject: (id)anObject
{
[self encodeObject:anObject];
}
- (void) encodeConditionalObject: (id)anObject;
- (void) encodeByrefObject: (id)anObject
{
[self encodeObject:anObject];
}
- (void) encodeObject: (id)anObject;
- (void) encodeBytes: (void*)d length: (unsigned)l
{
const char *type = @encode(unsigned char);
const unsigned char *where = (const unsigned char*)d;
[self encodeValueOfObjCType:@encode(unsigned) at:&l];
while (l-- > 0)
[self encodeValueOfObjCType:type at:where++];
}
- (void) encodeConditionalObject: (id)anObject
{
[self encodeObject:anObject];
}
- (void) encodeObject: (id)anObject
{
[self encodeValueOfObjCType:@encode(id)
at: &anObject];
}
- (void) encodePropertyList: (id)plist;
- (void) encodePropertyList: (id)plist
{
[self notImplemented:_cmd];
}
- (void) encodePoint: (NSPoint)point;
- (void) encodePoint: (NSPoint)point
{
[self encodeValueOfObjCType:@encode(NSPoint)
at:&point];
}
- (void) encodeRect: (NSRect)rect;
- (void) encodeRect: (NSRect)rect
{
[self encodeValueOfObjCType:@encode(NSRect)
at:&rect];
}
- (void) encodeRootObject: (id)rootObject;
- (void) encodeRootObject: (id)rootObject
{
[self encodeObject:rootObject];
}
- (void) encodeSize: (NSSize)size;
- (void) encodeSize: (NSSize)size
{
[self encodeValueOfObjCType:@encode(NSSize)
at:&size];
}
- (void) encodeValuesOfObjCTypes: (const char*)types,...;
- (void) encodeValuesOfObjCTypes: (const char*)types,...
{
va_list ap;
va_start(ap, types);
@ -145,7 +161,7 @@
- (void) decodeArrayOfObjCType: (const char*)type
count: (unsigned)count
at: (void*)address;
at: (void*)address
{
unsigned encoded_count;
int i, size = objc_sizeof_type(type);
@ -159,7 +175,25 @@
at:where];
}
- (id) decodeObject;
- (void*) decodeBytesWithReturnedLength: (unsigned*)l
{
unsigned count;
const char *type = @encode(unsigned char);
int i;
unsigned char *where;
unsigned char *array;
[self decodeValueOfObjCType:@encode(unsigned) at:&count];
*l = count;
array = objc_malloc(count);
while (count-- > 0)
[self decodeValueOfObjCType:type at:where++];
[[[MallocAddress alloc] initWithAddress: array] autorelease];
return array;
}
- (id) decodeObject
{
id o;
[self decodeValueOfObjCType:@encode(id)
@ -197,7 +231,7 @@
return size;
}
- (void) decodeValuesOfObjCTypes: (const char*)types,...;
- (void) decodeValuesOfObjCTypes: (const char*)types,...
{
va_list ap;
va_start(ap, types);
@ -212,12 +246,12 @@
// Managing Zones
- (NSZone*) objectZone;
- (NSZone*) objectZone
{
return NSDefaultMallocZone();
}
- (void) setObjectZone: (NSZone*)zone;
- (void) setObjectZone: (NSZone*)zone
{
;
}

View file

@ -1018,6 +1018,10 @@ static int messages_received_count;
case _C_ID:
if (flags & _F_BYCOPY)
[op encodeBycopyObject: *(id*)datum withName: ENCODED_ARGNAME];
#ifdef _F_BYREF
else if (flags & _F_BYREF)
[op encodeByrefObject: *(id*)datum withName: ENCODED_ARGNAME];
#endif
else
[op encodeObject: *(id*)datum withName: ENCODED_ARGNAME];
break;
@ -1189,6 +1193,10 @@ static int messages_received_count;
case _C_ID:
if (flags & _F_BYCOPY)
[op encodeBycopyObject:*(id*)datum withName:ENCODED_RETNAME];
#ifdef _F_BYREF
else if (flags & _F_BYREF)
[op encodeByrefObject: *(id*)datum withName: ENCODED_ARGNAME];
#endif
else
[op encodeObject:*(id*)datum withName:ENCODED_RETNAME];
break;

View file

@ -121,6 +121,11 @@ static Class NSMutableDictionary_concrete_class;
autorelease];
}
+ dictionaryWithDictionary: (NSDictionary*)otherDictionary
{
return [[[self alloc] initWithDictionary: otherDictionary] autorelease];
}
+ dictionaryWithObjects: (id*)objects
forKeys: (NSObject**)keys
count: (unsigned)count

View file

@ -57,6 +57,7 @@ static BOOL debug_connected_coder = NO;
unsigned sequence_number;
int identifier;
BOOL _is_by_copy;
BOOL _is_by_ref;
}
+ newForWritingWithConnection: (NSConnection*)c
@ -143,6 +144,11 @@ static BOOL debug_connected_coder = NO;
return _is_by_copy;
}
- (BOOL) isByref
{
return _is_by_ref;
}
- (unsigned) sequenceNumber
{
return sequence_number;
@ -164,10 +170,10 @@ static BOOL debug_connected_coder = NO;
/*
* These two methods are called by Coder's designated object encoder when
* an object is to be sent over the wire with/without bycopy.
* These three methods are called by Coder's designated object encoder when
* an object is to be sent over the wire with/without bycopy/byref.
* We make sure that if the object asks us whether it is to be sent bycopy
* it is told the right thing.
* or byref it is told the right thing.
*/
- (void) _doEncodeObject: anObj
{
@ -182,16 +188,36 @@ static BOOL debug_connected_coder = NO;
- (void) _doEncodeBycopyObject: anObj
{
BOOL old = _is_by_copy;
BOOL oldBycopy = _is_by_copy;
BOOL oldByref = _is_by_ref;
id obj;
Class cls;
_is_by_copy = YES;
_is_by_ref = NO;
obj = [anObj replacementObjectForPortCoder: (NSPortCoder*)self];
cls = [obj classForPortCoder];
[self encodeClass: cls];
[obj encodeWithCoder: (NSCoder*)self];
_is_by_copy = old;
_is_by_copy = oldBycopy;
_is_by_ref = oldByref;
}
- (void) _doEncodeByrefObject: anObj
{
BOOL oldBycopy = _is_by_copy;
BOOL oldByref = _is_by_ref;
id obj;
Class cls;
_is_by_copy = NO;
_is_by_ref = YES;
obj = [anObj replacementObjectForPortCoder: (NSPortCoder*)self];
cls = [obj classForPortCoder];
[self encodeClass: cls];
[obj encodeWithCoder: (NSCoder*)self];
_is_by_copy = oldBycopy;
_is_by_ref = oldByref;
}
- (void) writeSignature
@ -427,6 +453,12 @@ static BOOL debug_connected_coder = NO;
return NO;
}
- (BOOL) isByref
{
[self subclassResponsibility:_cmd];
return NO;
}
- (NSPort*) replyPort
{
[self subclassResponsibility:_cmd];

View file

@ -302,6 +302,9 @@ objc_skip_type_qualifiers (const char* type)
|| *type == _C_INOUT
|| *type == _C_OUT
|| *type == _C_BYCOPY
#ifdef _C_BYREF
|| *type == _C_BYREF
#endif
|| *type == _C_ONEWAY)
{
type += 1;
@ -424,6 +427,9 @@ objc_get_type_qualifiers (const char* type)
case _C_INOUT: res |= _F_INOUT; break;
case _C_OUT: res |= _F_OUT; break;
case _C_BYCOPY: res |= _F_BYCOPY; break;
#ifdef _C_BYREF
case _C_BYREF: res |= _F_BYREF; break;
#endif
case _C_ONEWAY: res |= _F_ONEWAY; break;
default: flag = NO;
}

View file

@ -126,6 +126,11 @@ int main(int argc, char *argv[])
[p sendBycopy:callback_receiver];
printf(">>returned float %f\n", [p returnFloat]);
printf(">>returned double %f\n", [p returnDouble]);
#ifdef _F_BYREF
[p sendByref:callback_receiver];
[p sendByref:@"hello"];
[p sendByref:[NSDate date]];
#endif
[p addObject:localObj];
k = [p count];

View file

@ -42,6 +42,9 @@ struct myarray {
- (double*) doDoublePointer: (double*)d;
- sendCharPtrPtr: (char**)sp;
- sendBycopy: (bycopy id)o;
#ifdef _F_BYREF
- sendByref: (byref id)o;
#endif
- manyArgs: (int)i1 : (int)i2 : (int)i3 : (int)i4 : (int)i5 : (int)i6
: (int)i7 : (int)i8 : (int)i9 : (int)i10 : (int)i11 : (int)i12;
- (float) returnFloat;

View file

@ -159,6 +159,13 @@
printf(">> bycopy class is %s\n", object_get_class_name (o));
return self;
}
#ifdef _F_BYREF
- sendByref: (ref id)o
{
printf(">> byref class is %s\n", object_get_class_name (o));
return self;
}
#endif
- manyArgs: (int)i1 : (int)i2 : (int)i3 : (int)i4 : (int)i5 : (int)i6
: (int)i7 : (int)i8 : (int)i9 : (int)i10 : (int)i11 : (int)i12
{