diff --git a/ChangeLog b/ChangeLog index 35e4342ad..407ccbbad 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,35 @@ +Fri Dec 19 13:09:28 1997 Adam Fedor + + * src/NSGeometry.m (NSPointFromString, NSSizeFromString, + NSRectFromString): New functions. + * src/include/NSGeometry.h: New function defs. + * NSCTemplateValue.m (-description): Use them. + +Tue Dec 16 22:35:00 1997 Richard Frith-Macdonald + + * src/Decoder.m: Modified to use a single, class-wide dummy object + as a placeholder in cross-reference tables. This gives a slight + speed and memory usage improvement. + + * src/MemoryStream.m: Avoid using autorelease where possible in order + to improve efficiency. + + * src/NSConnection.m: ([+rootProxyAtPort:]) modified to refrain from + creating a new connection when we already have one for the given + output port. + + * src/Random.m: ([-randomDie:]) Fixed to confirm to description in + comments. + + * src/TcpPort.m: Changed size field in packets to be 4 bytes long + rather than 2. This allows messages to be more than 64K bytes long + and is essential for things like pasteboard operations. + +Thu Dec 18 16:17:22 1997 Yoo C. Chung + + * src/NSProcessInfo.m (_gnu_process_noobjc_args): Use malloc(). + (_gnu_noobjc_free_vars): Use free(). + Thu Dec 11 13:58:39 1997 Adam Fedor * configure.in: Remove unneeded tests. diff --git a/Headers/gnustep/base/NSGeometry.h b/Headers/gnustep/base/NSGeometry.h index 20921af5e..bea8e33bf 100644 --- a/Headers/gnustep/base/NSGeometry.h +++ b/Headers/gnustep/base/NSGeometry.h @@ -135,7 +135,7 @@ NSOffsetRect(NSRect aRect, float dx, float dy); /* Divides ARECT into two rectangles (namely SLICE and REMAINDER) by * "cutting" ARECT---parallel to, and a distance AMOUNT from the edge - * of ARECT determined by EDGE. You may pass 0 in as either of SLICE or +v * of ARECT determined by EDGE. You may pass 0 in as either of SLICE or * REMAINDER to avoid obtaining either of the created rectangles. */ extern void NSDivideRect(NSRect aRect, @@ -222,6 +222,11 @@ NSStringFromRect(NSRect aRect); * W and H are the width and height of ASIZE, respectively. */ extern NSString * NSStringFromSize(NSSize aSize); + +extern NSPoint NSPointFromString(NSString* string); +extern NSSize NSSizeFromString(NSString* string); +extern NSRect NSRectFromString(NSString* string); + #endif /* __OBJC__ */ #endif /* __NSGeometry_h_GNUSTEP_BASE_INCLUDE */ diff --git a/Source/Decoder.m b/Source/Decoder.m index 3f7b63ac4..745d85c42 100644 --- a/Source/Decoder.m +++ b/Source/Decoder.m @@ -35,6 +35,19 @@ static int debug_coder = 0; @implementation Decoder +static id dummyObject; + ++ (void)initialize +{ + BOOL beenHere = NO; + + if (beenHere == NO) + { + beenHere = YES; + dummyObject = [NSObject new]; + } +} + /* Signature Handling. */ @@ -123,8 +136,7 @@ static int debug_coder = 0; xref_2_object = [Array new]; /* Append an object so our xref numbers are in sync with the Encoders, which start at 1. */ - /* xxx Change this to make it more efficient. */ - [xref_2_object appendObject: [[NSObject new] autorelease]]; + [xref_2_object appendObject: dummyObject]; } if (debug_coder) fprintf (stderr, "Decoder registering object xref %u\n", @@ -175,7 +187,7 @@ static int debug_coder = 0; xref_2_object_root = [Array new]; /* Append an object so our xref numbers are in sync with the Encoders, which start at 1. */ - [xref_2_object_root appendObject: [[NSObject new] autorelease]]; + [xref_2_object_root appendObject: dummyObject]; } [xref_2_object_root appendObject: anObj]; /* This return value should be the same as the index of anObj diff --git a/Source/MemoryStream.m b/Source/MemoryStream.m index 3d9e42244..7944517e2 100644 --- a/Source/MemoryStream.m +++ b/Source/MemoryStream.m @@ -83,19 +83,18 @@ static BOOL debug_memory_stream = NO; { if (b) if (f) - data = [NSMutableData dataWithBytesNoCopy: b length: s]; + data = [[NSMutableData alloc] initWithBytesNoCopy: b length: s]; else - data = [NSMutableData dataWithBytes: b length: s]; + data = [[NSMutableData alloc] initWithBytes: b length: s]; else { - data = [NSMutableData dataWithCapacity: s]; + data = [[NSMutableData alloc] initWithCapacity: s]; if (data) [data setLength: s]; } if (data) { - [data retain]; prefix = p; position = i; eof_position = l; diff --git a/Source/NSCTemplateValue.m b/Source/NSCTemplateValue.m index 523088ea5..4a98b05d0 100644 --- a/Source/NSCTemplateValue.m +++ b/Source/NSCTemplateValue.m @@ -93,16 +93,13 @@ #if TYPE_ORDER == 0 return [NSString stringWithFormat: @"{object = %@;}", [data description]]; #elif TYPE_ORDER == 1 - return [NSString stringWithFormat: @"{x = %g; y = %g;}", data.x, data.y]; + return NSStringFromPoint(data); #elif TYPE_ORDER == 2 return [NSString stringWithFormat: @"{pointer = %p;}", data]; #elif TYPE_ORDER == 3 - return [NSString stringWithFormat: - @"{x = %g; y = %g; width = %g; height = %g;}", NSMinX(data), NSMinY(data), - NSWidth(data), NSHeight(data)]; + return NSStringFromRect(data); #elif TYPE_ORDER == 4 - return [NSString stringWithFormat: @"{width = %g; height = %g;}", - data.width, data.height]; + return NSStringFromSize(data); #endif } diff --git a/Source/NSConnection.m b/Source/NSConnection.m index fed6b4fa6..844ec329c 100644 --- a/Source/NSConnection.m +++ b/Source/NSConnection.m @@ -731,9 +731,16 @@ static int messages_received_count; + (NSDistantObject*) rootProxyAtPort: (NSPort*)anOutPort { - id newInPort = [default_receive_port_class newForReceiving]; - return [self rootProxyAtPort: anOutPort + NSConnection *c = [self connectionByOutPort: anOutPort]; + + if (c) + return [c rootProxy]; + else + { + id newInPort = [default_receive_port_class newForReceiving]; + return [self rootProxyAtPort: anOutPort withInPort: [newInPort autorelease]]; + } } + (NSDistantObject*) rootProxyAtPort: (NSPort*)anOutPort diff --git a/Source/NSGeometry.m b/Source/NSGeometry.m index 934798949..29be9cedc 100644 --- a/Source/NSGeometry.m +++ b/Source/NSGeometry.m @@ -27,6 +27,7 @@ #include #include #include +#include /**** Type, Constant, and Macro Definitions **********************************/ @@ -425,3 +426,71 @@ NSStringFromSize(NSSize aSize) aSize.width, aSize.height]; } +NSPoint NSPointFromString(NSString* string) +{ + NSScanner* scanner = [NSScanner scannerWithString:string]; + NSPoint point; + + if ([scanner scanString:@"{" intoString:NULL] + && [scanner scanString:@"x" intoString:NULL] + && [scanner scanString:@"=" intoString:NULL] + && [scanner scanFloat:&point.x] + && [scanner scanString:@";" intoString:NULL] + && [scanner scanString:@"y" intoString:NULL] + && [scanner scanString:@"=" intoString:NULL] + && [scanner scanFloat:&point.y] + && [scanner scanString:@"}" intoString:NULL]) + return point; + else + return NSMakePoint(0, 0); +} + +NSSize NSSizeFromString(NSString* string) +{ + NSScanner* scanner = [NSScanner scannerWithString:string]; + NSSize size; + + if ([scanner scanString:@"{" intoString:NULL] + && [scanner scanString:@"width" intoString:NULL] + && [scanner scanString:@"=" intoString:NULL] + && [scanner scanFloat:&size.width] + && [scanner scanString:@";" intoString:NULL] + && [scanner scanString:@"height" intoString:NULL] + && [scanner scanString:@"=" intoString:NULL] + && [scanner scanFloat:&size.height] + && [scanner scanString:@"}" intoString:NULL]) + return size; + else + return NSMakeSize(0, 0); +} + +NSRect NSRectFromString(NSString* string) +{ + NSScanner* scanner = [NSScanner scannerWithString:string]; + NSRect rect; + + if ([scanner scanString:@"{" intoString:NULL] + && [scanner scanString:@"x" intoString:NULL] + && [scanner scanString:@"=" intoString:NULL] + && [scanner scanFloat:&rect.origin.x] + && [scanner scanString:@";" intoString:NULL] + + && [scanner scanString:@"y" intoString:NULL] + && [scanner scanString:@"=" intoString:NULL] + && [scanner scanFloat:&rect.origin.y] + && [scanner scanString:@";" intoString:NULL] + + && [scanner scanString:@"width" intoString:NULL] + && [scanner scanString:@"=" intoString:NULL] + && [scanner scanFloat:&rect.size.width] + && [scanner scanString:@";" intoString:NULL] + + && [scanner scanString:@"height" intoString:NULL] + && [scanner scanString:@"=" intoString:NULL] + && [scanner scanFloat:&rect.size.height] + && [scanner scanString:@"}" intoString:NULL]) + return rect; + else + return NSMakeRect(0, 0, 0, 0); +} + diff --git a/Source/NSProcessInfo.m b/Source/NSProcessInfo.m index 02de5713f..36632cfbb 100644 --- a/Source/NSProcessInfo.m +++ b/Source/NSProcessInfo.m @@ -61,6 +61,8 @@ #include #endif /* !__WIN32__ */ +#include +#include #include #include #include @@ -191,7 +193,8 @@ static char **_gnu_noobjc_argv; static char **_gnu_noobjc_env; static void -_gnu_process_noobjc_args(int argc, char *argv[], char *env[]) { +_gnu_process_noobjc_args(int argc, char *argv[], char *env[]) +{ int i; /* We have to copy these in case the main() modifies their values @@ -202,12 +205,14 @@ _gnu_process_noobjc_args(int argc, char *argv[], char *env[]) { i=0; while(argv[i]) i++; - _gnu_noobjc_argv = - NSZoneMalloc(NSDefaultMallocZone(),sizeof(char *)*(i+1)); + _gnu_noobjc_argv = malloc(sizeof(char *)*(i+1)); + if (_gnu_noobjc_argv == NULL) + goto error; i=0; while(*argv) { - _gnu_noobjc_argv[i] = - NSZoneMalloc(NSDefaultMallocZone(),strlen(*argv)+1); + _gnu_noobjc_argv[i] = malloc(strlen(*argv)+1); + if (_gnu_noobjc_argv[i] == NULL) + goto error; strcpy(_gnu_noobjc_argv[i],*argv); argv++; i++; @@ -216,18 +221,24 @@ _gnu_process_noobjc_args(int argc, char *argv[], char *env[]) { i=0; while(env[i]) i++; - _gnu_noobjc_env = - NSZoneMalloc(NSDefaultMallocZone(),sizeof(char *)*(i+1)); + _gnu_noobjc_env = malloc(sizeof(char *)*(i+1)); + if (_gnu_noobjc_env == NULL) + goto error; i=0; while(*env) { - _gnu_noobjc_env[i] = - NSZoneMalloc(NSDefaultMallocZone(),strlen(*env)+1); + _gnu_noobjc_env[i] = malloc(strlen(*env)+1); + if (_gnu_noobjc_env[i] == NULL) + goto error; strcpy(_gnu_noobjc_env[i],*env); env++; i++; } _gnu_noobjc_env[i] = 0; + return; + error: + fputs("malloc() error when starting gstep-base\n", stderr); + abort(); } static void _gnu_noobjc_free_vars(void) @@ -236,18 +247,18 @@ static void _gnu_noobjc_free_vars(void) p = _gnu_noobjc_argv; while (*p) { - NSZoneFree(NSDefaultMallocZone(),*p); + free(*p); p++; } - NSZoneFree(NSDefaultMallocZone(),_gnu_noobjc_argv); + free(_gnu_noobjc_argv); _gnu_noobjc_argv = 0; p = _gnu_noobjc_env; while (*p) { - NSZoneFree(NSDefaultMallocZone(),*p); + free(*p); p++; } - NSZoneFree(NSDefaultMallocZone(),_gnu_noobjc_env); + free(_gnu_noobjc_env); _gnu_noobjc_env = 0; } diff --git a/Source/Random.m b/Source/Random.m index c3eaeda4d..b33e9a8cf 100644 --- a/Source/Random.m +++ b/Source/Random.m @@ -217,7 +217,7 @@ static id defaultRNG = nil; /* return between 0 and numSides-1 */ - (long) randomDie: (long)numSides { - return ([rng nextRandom] % (numSides+1) - 1); + return ([rng nextRandom] % numSides); } - (BOOL) randomCoin diff --git a/Source/TcpPort.m b/Source/TcpPort.m index 711d5d5ef..fb7f1597b 100644 --- a/Source/TcpPort.m +++ b/Source/TcpPort.m @@ -1770,9 +1770,9 @@ static NSMapTable *out_port_bag = NULL; /* In and Out Packet classes. */ -/* If you change this "unsigned short", you must change the use - of ntohs() and htons() below. */ -#define PREFIX_LENGTH_TYPE unsigned short +/* If you change this "unsigned long", you must change the use + of ntohl() and htonl() below. */ +#define PREFIX_LENGTH_TYPE unsigned long #define PREFIX_LENGTH_SIZE sizeof (PREFIX_LENGTH_TYPE) #define PREFIX_ADDRESS_TYPE struct sockaddr_in #define PREFIX_ADDRESS_SIZE sizeof (PREFIX_ADDRESS_TYPE) @@ -1815,7 +1815,7 @@ static NSMapTable *out_port_bag = NULL; /* *size is the number of bytes in the packet, not including the PREFIX_SIZE-byte header. */ - *packet_size = ntohs (*(PREFIX_LENGTH_TYPE*) prefix_buffer); + *packet_size = ntohl (*(PREFIX_LENGTH_TYPE*) prefix_buffer); assert (packet_size); /* If the reply address is non-zero, and the TcpOutPort for this socket @@ -1875,9 +1875,9 @@ static NSMapTable *out_port_bag = NULL; { int c; - /* Put the packet size in the first two bytes of the packet. */ + /* Put the packet size in the first four bytes of the packet. */ assert (prefix == PREFIX_SIZE); - *(PREFIX_LENGTH_TYPE*)[data mutableBytes] = htons (eof_position); + *(PREFIX_LENGTH_TYPE*)[data mutableBytes] = htonl (eof_position); /* Put the sockaddr_in for replies in the next bytes of the prefix region. If there is no reply address specified, fill it with zeros. */