diff --git a/ChangeLog b/ChangeLog index d426f8025..e41262409 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,52 @@ +Mon Jan 26 09:10:39 1998 Adam Fedor + + * NSPage.m (NSRealMemoryAvailable): Add implementation for + GNU/Linux (Patch from Matt Jenkins ). + +Sat Jan 24 15:14:50 1998 Masatake Yamato + + * src/include/NSMethodSignature.h(-methodType): + Declare new category NSMethodSignature(GNU). + + * src/Invocation.m ([MethodInvocation -setSelector:]): + Add code to handle a case that sel_pointer is pointing NULL + SEL value. This is far from perfect. Type checking is needed. + + * src/NSMethodSignature.m + Add cpp directives to use `strrchr'. + (rtn_type_is_oneway): New function + for [NSMethodSignature -isOneway]. + ([NSMethodSignature +signatureWithObjCTypes:]): Fix length of + memory allocation for strings. + Do not copy all the encoding string T to returnTypes. + ([NSMethodSignature -isOneway]): Method implemented. + ([NSMethodSignature(GNU) -methodType]): New category and method. + This is not part of OpenStep spec. This method is used in + NSInvocation.m. + + * src/NSInvocation.m ([NSInvocation +initialize]): Add + MethodInvocation class instead of Invocation. + ([NSInvocation -methodSignature]): Method implemented. + ([NSInvocation +invocationWithMethodSignature:]): Invoke + [NSMethodSignature -methodType] instead of + [NSMethodSignature -methodReturnType]. + +Sat Jan 24 23:24:00 1998 Richard Frith-Macdonald + + * src/NSGString.m: Re-wrote ([-replaceCharactersInRange:withString:]) + as a primitive method for greater efficiency. + + * src/NSString.m: ([-getCharacters:range:]) removed code which + incorrectly added nul terminator to characters copied. + The Rhapsody docs specifically say no terminator. + ([-appendString:]) rewrote to be reasonably efficient by using the + ([-replaceCharactersInRange:withString:]) method. + + * src/NSUserDefaults.m: ([-syncronize]) fixed stupid bug I introduced + in checking for lock duration and breaking locks on files. + ([-initWithContentsOfFile:]) Added code to retry a few times when + we are locked out. + Wed Jan 21 17:37:00 1998 Richard Frith-Macdonald * Tools/defaults.m: Fixed bug in handling 'write' operations reading diff --git a/Headers/gnustep/base/NSMethodSignature.h b/Headers/gnustep/base/NSMethodSignature.h index 1c1e72818..6160c7d2c 100644 --- a/Headers/gnustep/base/NSMethodSignature.h +++ b/Headers/gnustep/base/NSMethodSignature.h @@ -55,4 +55,7 @@ typedef struct @end +@interface NSMethodSignature(GNU) +- (char*) methodType; +@end #endif /* __NSMethodSignature_h_GNUSTEP_BASE_INCLUDE */ diff --git a/Source/GetDefEncoding.m b/Source/GetDefEncoding.m index 259a0698e..309fb7dea 100644 --- a/Source/GetDefEncoding.m +++ b/Source/GetDefEncoding.m @@ -112,8 +112,9 @@ NSStringEncoding GetDefEncoding() } else /* envirinment var not found */ { - fprintf(stderr,"WARNING: GNUSTEP_STRING_ENCODING environment variable not found\n"); - fprintf(stderr, "NSASCIIStringEncoding set as default.\n"); + /* This shouldn't be required. It really should be in UserDefaults - asf */ + //fprintf(stderr,"WARNING: GNUSTEP_STRING_ENCODING environment variable not found\n"); + //fprintf(stderr, "NSASCIIStringEncoding set as default.\n"); ret=NSASCIIStringEncoding; } return ret; diff --git a/Source/Invocation.m b/Source/Invocation.m index c21ecfb5d..87e0d337e 100644 --- a/Source/Invocation.m +++ b/Source/Invocation.m @@ -657,7 +657,11 @@ my_method_get_next_argument (arglist_t argframe, - (void) setSelector: (SEL)s { - if (sel_types_match(sel_get_type([self selector]), sel_get_type(s))) + SEL mysel = [self selector]; + if (mysel == (SEL)0) + /* XXX Type check is needed! (masata-y@is.aist-nara.ac.jp) */ + *sel_pointer = sel_get_any_typed_uid (sel_get_name (s)); + else if (sel_types_match(sel_get_type(mysel), sel_get_type(s))) *sel_pointer = s; else { diff --git a/Source/NSGString.m b/Source/NSGString.m index 5fc0e3b9b..66733f789 100644 --- a/Source/NSGString.m +++ b/Source/NSGString.m @@ -335,12 +335,35 @@ stringDecrementCountAndFillHoleAt(NSGMutableStringStruct *self, range.location, range.length); } -// xxx This should be primitive method -- (void) replaceCharactersInRange: (NSRange)range +- (void) replaceCharactersInRange: (NSRange)aRange withString: (NSString*)aString { - [self deleteCharactersInRange:range]; - [self insertString:aString atIndex:range.location]; + int offset; + int i; + + if (aRange.location > _count) + [NSException raise: NSRangeException format:@"Invalid location."]; + if (aRange.length > (_count - aRange.location)) + [NSException raise: NSRangeException format:@"Invalid location+length."]; + if (_count + [aString length] - aRange.length > _capacity) + { + _capacity += [aString length] - aRange.length; + OBJC_REALLOC(_contents_chars, unichar, _capacity); + } + offset = [aString length] - aRange.length; + if (offset > 0) + { + int first = aRange.location + aRange.length; + for (i = self->_count - 1; i >= first; i--) + self->_contents_chars[i+offset] = self->_contents_chars[i]; + } + else if (offset < 0) + { + for (i = aRange.location + aRange.length; i < self->_count; i++) + self->_contents_chars[i+offset] = self->_contents_chars[i]; + } + (self->_count) += offset; + [aString getCharacters: &self->_contents_chars[aRange.location]]; } // xxx Check this diff --git a/Source/NSInvocation.m b/Source/NSInvocation.m index c5d8466aa..081506300 100644 --- a/Source/NSInvocation.m +++ b/Source/NSInvocation.m @@ -33,7 +33,7 @@ + (void) initialize { if (self == [NSInvocation class]) - class_add_behavior (self, [Invocation class]); + class_add_behavior (self, [MethodInvocation class]); } + (NSInvocation*) invocationWithObjCTypes: (const char*) types @@ -43,15 +43,26 @@ + (NSInvocation*) invocationWithMethodSignature: (NSMethodSignature*)ms { - /* This assumes that the methodReturnType also includes the - parameter types. */ - return [self invocationWithObjCTypes: [ms methodReturnType]]; + return [self invocationWithObjCTypes: [ms methodType]]; } - (NSMethodSignature*) methodSignature { +#if 0 /* xxx This isn't really needed by the our implementation anyway. */ [self notImplemented: _cmd]; +#else + SEL mysel = [self selector]; + char * my_sel_type; + if (mysel) + { + my_sel_type = sel_get_type(mysel); + if (my_sel_type) + return [NSMethodSignature signatureWithObjCTypes: my_sel_type]; + else + return nil; + } +#endif return nil; } diff --git a/Source/NSMethodSignature.m b/Source/NSMethodSignature.m index 3d0762f57..80b506dc0 100644 --- a/Source/NSMethodSignature.m +++ b/Source/NSMethodSignature.m @@ -21,6 +21,24 @@ Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ +#if 1 +/* Deal with memchr: */ +#if STDC_HEADERS || HAVE_STRING_H +#include +/* An ANSI string.h and pre-ANSI memory.h might conflict. */ +#if !STDC_HEADERS && HAVE_MEMORY_H +#include +#endif /* not STDC_HEADERS and HAVE_MEMORY_H */ +#define rindex strrchr +#define bcopy(s, d, n) memcpy ((d), (s), (n)) +#define bcmp(s1, s2, n) memcmp ((s1), (s2), (n)) +#define bzero(s, n) memset ((s), 0, (n)) +#else /* not STDC_HEADERS and not HAVE_STRING_H */ +#include +/* memory.h and strings.h conflict on some systems. */ +#endif /* not STDC_HEADERS and not HAVE_STRING_H */ +#endif + #include #include #include @@ -47,19 +65,42 @@ types_get_number_of_arguments (const char *types) return i - 1; } +#if 1 +static BOOL +rtn_type_is_oneway(const char * types) +{ + char * oneway_pos = strrchr(types, _C_ONEWAY); + if (oneway_pos != (char *)0) + return YES; + else + return NO; +} +#endif + @implementation NSMethodSignature + (NSMethodSignature*) signatureWithObjCTypes: (const char*)t { int len; NSMethodSignature *newMs = [NSMethodSignature alloc]; +#if 0 len = strlen(t); +#else + len = strlen(t) + 1; // For the last '\0' +#endif OBJC_MALLOC(newMs->types, char, len); memcpy(newMs->types, t, len); +#if 0 len = strlen(t); /* xxx */ +#else + { + char * endof_ret_encoding = strrchr(t, '0'); + len = endof_ret_encoding - t + 1; // +2? + } +#endif OBJC_MALLOC(newMs->returnTypes, char, len); memcpy(newMs->returnTypes, t, len); - newMs->returnTypes[len-1] = '\0'; + newMs->returnTypes[len-1] = '\0'; // ??? newMs->argFrameLength = types_get_size_of_arguments(t); newMs->returnFrameLength = objc_sizeof_type(t); newMs->numArgs = types_get_number_of_arguments(t); @@ -82,8 +123,12 @@ types_get_number_of_arguments (const char *types) - (BOOL) isOneway { +#if 1 + return rtn_type_is_oneway(returnTypes); +#else [self notImplemented:_cmd]; return NO; +#endif } - (unsigned) methodReturnLength @@ -109,3 +154,12 @@ types_get_number_of_arguments (const char *types) } @end + +#if 1 +@implementation NSMethodSignature(GNU) +- (char*) methodType +{ + return types; +} +@end +#endif diff --git a/Source/NSPage.m b/Source/NSPage.m index b034364a3..f93fcb36a 100644 --- a/Source/NSPage.m +++ b/Source/NSPage.m @@ -32,6 +32,11 @@ #include #endif +#if __linux__ +#include +#include +#endif + #ifdef __WIN32__ #define getpagesize() vm_page_size #endif @@ -92,8 +97,16 @@ NSRoundUpToMultipleOfPageSize (unsigned bytes) unsigned NSRealMemoryAvailable () { +#if __linux__ + struct sysinfo info; + + if ((sysinfo(&info)) != 0) + return 0; + return (unsigned) info.freeram; +#else fprintf (stderr, "NSRealMemoryAvailable() not implemented.\n"); return 0; +#endif } void * @@ -137,3 +150,17 @@ NSCopyMemoryPages (const void *source, void *dest, unsigned bytes) #endif } + + + + + + + + + + + + + + diff --git a/Source/NSString.m b/Source/NSString.m index d918c6735..95f32fe0a 100644 --- a/Source/NSString.m +++ b/Source/NSString.m @@ -590,7 +590,6 @@ handle_printf_atsign (FILE *stream, { buffer[i] = [self characterAtIndex: aRange.location+i]; } - buffer[aRange.length] = (unichar)0; } // Combining Strings @@ -2678,14 +2677,13 @@ else // Modify A String -/* Inefficient. */ - (void) appendString: (NSString*)aString { - id tmp; - if (!aString) - return; - tmp = [self stringByAppendingString:aString]; - [self setString:tmp]; + NSRange aRange; + + aRange.location = [self length]; + aRange.length = 0; + [self replaceCharactersInRange: aRange withString: aString]; } /* Inefficient. */ diff --git a/Source/NSUserDefaults.m b/Source/NSUserDefaults.m index 045da9385..b6cfb491e 100644 --- a/Source/NSUserDefaults.m +++ b/Source/NSUserDefaults.m @@ -49,6 +49,7 @@ #include #include #include +#include /* Wait for access */ #define _MAX_COUNT 5 /* Max 10 sec. */ @@ -212,8 +213,23 @@ static NSMutableString *processName = nil; persDomains = [[NSMutableDictionary dictionaryWithCapacity:10] retain]; if ([self synchronize] == NO) { - [self dealloc]; - return self = nil; + NSRunLoop *runLoop = [NSRunLoop currentRunLoop]; + BOOL done = NO; + int attempts; + + // Retry for a couple of seconds in case we are locked out. + for (attempts = 0; done == NO && attempts < 10; attempts++) + { + [runLoop runMode: [runLoop currentMode] + beforeDate: [NSDate dateWithTimeIntervalSinceNow: 0.2]]; + if ([self synchronize] == YES) + done = YES; + } + if (done == NO) + { + [self dealloc]; + return self = nil; + } } // Check and if not existent add the Application and the Global domains @@ -478,12 +494,14 @@ static NSMutableString *processName = nil; // Get file lock - break any lock that is more than five minute old. if ([defaultsDatabaseLock tryLock] == NO) - if ([[defaultsDatabaseLock lockDate] timeIntervalSinceNow] < 300.0) + if ([[defaultsDatabaseLock lockDate] timeIntervalSinceNow] < -300.0) { [defaultsDatabaseLock breakLock]; if ([defaultsDatabaseLock tryLock] == NO) return NO; } + else + return NO; // Read the persistent data from the stored database newDict = [[NSMutableDictionary allocWithZone:[self zone]] @@ -510,7 +528,6 @@ static NSMutableString *processName = nil; // Save the changes if (![persDomains writeToFile:defaultsDatabase atomically:YES]) { -// NSLog(@"failed to write defaults to '%@'\n", defaultsDatabase); [defaultsDatabaseLock unlock]; return NO; }