mirror of
https://github.com/gnustep/libs-base.git
synced 2025-04-22 16:33:29 +00:00
Pathces from Frith-MacDonald, Yamato, Jenkins.
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@2709 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
parent
49be21f6c3
commit
142cab5d90
10 changed files with 210 additions and 23 deletions
49
ChangeLog
49
ChangeLog
|
@ -1,3 +1,52 @@
|
|||
Mon Jan 26 09:10:39 1998 Adam Fedor <fedor@doc.com>
|
||||
|
||||
* NSPage.m (NSRealMemoryAvailable): Add implementation for
|
||||
GNU/Linux (Patch from Matt Jenkins <mdj@arcadia.cs.rmit.EDU.AU>).
|
||||
|
||||
Sat Jan 24 15:14:50 1998 Masatake Yamato <masata-y@aist-nara.ac.jp>
|
||||
|
||||
* 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 <richard@brainstorm.co.uk>
|
||||
|
||||
* 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 <richard@brainstorm.co.uk>
|
||||
|
||||
* Tools/defaults.m: Fixed bug in handling 'write' operations reading
|
||||
|
|
|
@ -55,4 +55,7 @@ typedef struct
|
|||
|
||||
@end
|
||||
|
||||
@interface NSMethodSignature(GNU)
|
||||
- (char*) methodType;
|
||||
@end
|
||||
#endif /* __NSMethodSignature_h_GNUSTEP_BASE_INCLUDE */
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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
|
||||
{
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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 <string.h>
|
||||
/* An ANSI string.h and pre-ANSI memory.h might conflict. */
|
||||
#if !STDC_HEADERS && HAVE_MEMORY_H
|
||||
#include <memory.h>
|
||||
#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 <strings.h>
|
||||
/* memory.h and strings.h conflict on some systems. */
|
||||
#endif /* not STDC_HEADERS and not HAVE_STRING_H */
|
||||
#endif
|
||||
|
||||
#include <config.h>
|
||||
#include <gnustep/base/preface.h>
|
||||
#include <Foundation/NSMethodSignature.h>
|
||||
|
@ -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
|
||||
|
|
|
@ -32,6 +32,11 @@
|
|||
#include <mach.h>
|
||||
#endif
|
||||
|
||||
#if __linux__
|
||||
#include <linux/kernel.h>
|
||||
#include <linux/sys.h>
|
||||
#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
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -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. */
|
||||
|
|
|
@ -49,6 +49,7 @@
|
|||
#include <Foundation/NSTimer.h>
|
||||
#include <Foundation/NSProcessInfo.h>
|
||||
#include <Foundation/NSDistributedLock.h>
|
||||
#include <Foundation/NSRunLoop.h>
|
||||
|
||||
/* 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;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue