From 877463ffe0ed8215df8d1da492d79c1f29cccdf5 Mon Sep 17 00:00:00 2001 From: fedor Date: Mon, 23 Mar 1998 20:49:54 +0000 Subject: [PATCH] Byref patches from Frith-MacDonald git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@2777 72102866-910b-0410-8b05-ffd578937521 --- ChangeLog | 44 +++++++++++++++++ Documentation/gnustep-howto.tmpl.texi | 2 +- Headers/gnustep/base/Coding.h | 2 + Headers/gnustep/base/NSCoder.h | 3 ++ Headers/gnustep/base/NSDictionary.h | 2 +- Headers/gnustep/base/NSPortCoder.h | 1 + Source/Coder.m | 5 ++ Source/Encoder.m | 41 ++++++++++++++-- Source/NSCalendarDate.m | 2 + Source/NSCoder.m | 70 ++++++++++++++++++++------- Source/NSConnection.m | 8 +++ Source/NSDictionary.m | 5 ++ Source/NSPortCoder.m | 42 ++++++++++++++-- Source/objc-gnu2next.m | 6 +++ Testing/client.m | 5 ++ Testing/server.h | 3 ++ Testing/server.m | 7 +++ 17 files changed, 218 insertions(+), 30 deletions(-) diff --git a/ChangeLog b/ChangeLog index 7b69eac72..f8497de6f 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,47 @@ +Fri Mar 20 11:15:00 1998 Richard Frith-Macdonald + + * 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 + + * 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 * src/NSArray.m: ([-copyWithZone:]) changed to use the diff --git a/Documentation/gnustep-howto.tmpl.texi b/Documentation/gnustep-howto.tmpl.texi index d82783746..5ddedca3d 100644 --- a/Documentation/gnustep-howto.tmpl.texi +++ b/Documentation/gnustep-howto.tmpl.texi @@ -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 diff --git a/Headers/gnustep/base/Coding.h b/Headers/gnustep/base/Coding.h index f7781c990..89c8b93fb 100644 --- a/Headers/gnustep/base/Coding.h +++ b/Headers/gnustep/base/Coding.h @@ -60,6 +60,8 @@ withName: (id /**/)name; - (void) encodeBycopyObject: anObj withName: (id /**/)name; +- (void) encodeByrefObject: anObj + withName: (id /**/)name; - (void) encodeRootObject: anObj withName: (id /**/)name; diff --git a/Headers/gnustep/base/NSCoder.h b/Headers/gnustep/base/NSCoder.h index b30d361ae..b3d978e02 100644 --- a/Headers/gnustep/base/NSCoder.h +++ b/Headers/gnustep/base/NSCoder.h @@ -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; diff --git a/Headers/gnustep/base/NSDictionary.h b/Headers/gnustep/base/NSDictionary.h index d304db852..a8fdb4adb 100644 --- a/Headers/gnustep/base/NSDictionary.h +++ b/Headers/gnustep/base/NSDictionary.h @@ -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; diff --git a/Headers/gnustep/base/NSPortCoder.h b/Headers/gnustep/base/NSPortCoder.h index ac4c72c06..f23902685 100644 --- a/Headers/gnustep/base/NSPortCoder.h +++ b/Headers/gnustep/base/NSPortCoder.h @@ -38,6 +38,7 @@ - (NSPort*) decodePortObject; - (void) encodePortObject: (NSPort*)aPort; - (BOOL) isBycopy; +- (BOOL) isByref; @end diff --git a/Source/Coder.m b/Source/Coder.m index c5f300a6e..d2ffc1e6a 100644 --- a/Source/Coder.m +++ b/Source/Coder.m @@ -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 diff --git a/Source/Encoder.m b/Source/Encoder.m index 3c8287ca5..3976fcbaa 100644 --- a/Source/Encoder.m +++ b/Source/Encoder.m @@ -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]; } diff --git a/Source/NSCalendarDate.m b/Source/NSCalendarDate.m index 73e9606c2..274ea4cc6 100644 --- a/Source/NSCalendarDate.m +++ b/Source/NSCalendarDate.m @@ -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; diff --git a/Source/NSCoder.m b/Source/NSCoder.m index d70b20b3c..a0672f0df 100644 --- a/Source/NSCoder.m +++ b/Source/NSCoder.m @@ -24,6 +24,7 @@ #include #include +#include #include #include @@ -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 { ; } diff --git a/Source/NSConnection.m b/Source/NSConnection.m index e3497699b..f2e245638 100644 --- a/Source/NSConnection.m +++ b/Source/NSConnection.m @@ -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; diff --git a/Source/NSDictionary.m b/Source/NSDictionary.m index 9c7a4ea48..175987064 100644 --- a/Source/NSDictionary.m +++ b/Source/NSDictionary.m @@ -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 diff --git a/Source/NSPortCoder.m b/Source/NSPortCoder.m index 9ae29cdfe..a966a2537 100644 --- a/Source/NSPortCoder.m +++ b/Source/NSPortCoder.m @@ -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]; diff --git a/Source/objc-gnu2next.m b/Source/objc-gnu2next.m index 5c563e929..e9ec71304 100644 --- a/Source/objc-gnu2next.m +++ b/Source/objc-gnu2next.m @@ -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; } diff --git a/Testing/client.m b/Testing/client.m index 0270fc1f2..2794c17dc 100644 --- a/Testing/client.m +++ b/Testing/client.m @@ -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]; diff --git a/Testing/server.h b/Testing/server.h index 0799fc5f9..c5a267021 100644 --- a/Testing/server.h +++ b/Testing/server.h @@ -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; diff --git a/Testing/server.m b/Testing/server.m index 394826e82..726858fef 100644 --- a/Testing/server.m +++ b/Testing/server.m @@ -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 {