Patches from Kienenberger, Yamato, Frith-MacDonald.

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@2719 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
Adam Fedor 1998-02-03 14:20:00 +00:00
parent b6341c9181
commit 38bdebb9a8
28 changed files with 668 additions and 31541 deletions

106
ChangeLog
View file

@ -1,3 +1,93 @@
Mon Feb 2 10:11:20 1998 Adam Fedor <fedor@ultra.doc.com>
* Version (GCC_VERSION): Change to 2.8.0
* gcc-2.7.2-objc.diff: Remove.
* gcc-2.7.2.1-objc.diff: Likewise.
* NSTimeZones/Makefile.postamble (after-install): Remove
directories before (re-)installing.
* checks/GNUmakefile: Include bundle.make.
* doc/gnustep-howto.tmpl.texi: Make gcc2.8.0 supported compiler.
* doc/news.tmpl.texi: Add recent changes.
* src/NSFileManager.m: Include sys/statvfs for mips-sgi-irix6.2
* Tools/gdomap.c: Add IPPORT_USERRESERVED def for sgi.
* src/TcpPort.m: Likewise.
* src/UdpPort.m: Likewise.
(patches from Mike Kienenberger <mkienen@arsc.edu>)
Fri Jan 30 20:38:56 1998 Masatake Yamato <masata-y@is.aist-nara.ac.jp>
* src/Invocation.m ([MethodInvocation
-initWithTarget:selector:,...]): Add _C_CLASS, a CASE_TYPE to the
switch-case labels. Implement default: in the switch-case. I
used typeof, a gcc extension.
* src/NSMethodSignature.m ([NSMethodSignature -argumentInfoAtIndex:]):
Implemented.
* src/include/NSInvocation.h (NS_INVOCATION, NS_MESSAGE): New macros.
Mon Feb 2 12:54:00 1998 Richard Frith-Macdonald <richard@brainstorm.co.uk>
* Tools/defaults.m: Modified to make sure that defaults are all
written correctly when reading multile defaults settings from stdin.
* src/NSArray.m: Modified or rewrote almost all methods to use
unsigned ints rather than ints and to avoid retain/release
sequences for the sake of efficiency. Also rewrote property list
and sorting methods for much greater efficieny.
* src/NSData.m: (readContentsOfFile(NSString*, void**, unsigned*))
fixed bug leaving file open and modified to use
([NSString -fileSystemRepresentation]). Similarly modified
([-writeToFile:atomically;]) and ([-initWithContentsOfMappedFile:]).
* src/NSDictionary.m: Modified ([-descriptionInStringsFileFormat])
and ([-descriptionWithLocale:indent:]) for better performance.
* src/NSGArray.m: Added implementations of ([-getObjects:]) and
([-getObjects:range:]) so that it is possible to get high speed
access to array contents. Added implementation of
([-sortUsingFunction:context:]) for faster sorting of array contents
so that property descriptions are generated more quickly.
* src/NSGCString.m: Modified various methods so that the _capacity
instance variable has the space available for characters in the
string without the terminator. Added ([-getCharacters:]) and
([-getCharacters:range:]) implementations.
* src/NSGString.m: Modified various methods so that unicode
strings are no longer nul terminated and the _capacity instance
variable has the number of character spaces available in the
string. Added ([-getCharacters:]) and ([-getCharacters:range:])
implementations. Added ([-replaceCharactersInRange:withString:])
implementation.
* src/NSString.m: Fixed a few places where it was assumed that
string buffers include space for a nul terminator. In
([-compare:options:range:]) made modifications so that literal
comparisons now work correctly for ranges other than the entire
string. Made some changes to avoid use of malloc/free sequences
where not necessary. Made efficiency improvements to append
methods.
* src/NSUserDefaults.m: ([-initWithContentsOfFile:]) changed to take
process name as being the last path component of the full process
name. Also added code to retry a few times if the database is locked.
* src/TcpPort.m: ([+newForSendingToSockaddr:withAcceptedSocket:pollingInPort:])
Vague attempt to make rapid shutdown/startup of DO more robust.
* src/UnixFileHandle.m: (getAddr()) Fixed error in handling service
names and permit nil service to mean 'any'.
Also use ([NSString -fileSystemRepresentation]) as appropriate.
* src/include/NSGArray.h: modified to contain same instance variables
as the Array class so we can access them directly in NSGArray.m
Mon Jan 26 09:10:39 1998 Adam Fedor <fedor@doc.com>
* src/NSPage.m (NSRealMemoryAvailable): Add implementation for
@ -34,22 +124,6 @@ Sat Jan 24 15:14:50 1998 Masatake Yamato <masata-y@aist-nara.ac.jp>
[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

View file

@ -64,7 +64,8 @@ of hard disk space while it compiles.
Currently, you pretty much need to get and install the latest versions
of the following packages:
@display
gcc, gdb, and assorted patches to make them work with Objective-C
gcc or egcs
gdb and patch to make it work with better Objective-C
GNU make
tiff library
DGS or Adobe DPS
@ -100,16 +101,14 @@ You need the following packages of either the version given or any later
version, in order to compile GNUstep.
@example
gcc-2.8.0.tar.gz (The GCC compiler), or gcc-2.7.2.x.tar.gz with the patch
listed below.
gcc-2.8.0.tar.gz (The GCC compiler)
ftp://ftp.gnu.org/pub/gnu or from other GNU mirror sites.
You may also use egcs-1.0.1.tar.gz, from ftp://ftp.cygnus.com/pub/egcs
gdb-4.16.tar.gz (The gdb debugger)
make-3.75.tar.gz (You need GNU make to compile GNUstep).
ftp://ftp.gnu.org/pub/gnu or from other GNU mirror sites.
gcc-2.7.2.1-objc-970318.diff.gz (patch needed for using gcc 2.7.2.x)
From the gstep-base distribution (gcc-2.7.2.1-objc.diff) or
ftp://alpha.gnu.org/gnu/gnustep
ftp://zarquon.mathi.uni-heidelberg.de/pub/GNUstep/developer/releases
gdb-4.16-objc-971112.diff.gz (A patch for easier debugging of Objective-C).
ftp://alpha.gnu.org/gnu/gnustep
@ -239,29 +238,17 @@ GNUstep system root as the prefix when you configure the package.
@subsection Patching and Compiling GCC
The following commands assume that all the aforementioned files have been
copied to the /usr/src directory on your machine. GCC version 2.8.0 should
be released soon. If you have this version, you do NOT need to apply the
following patch to it. Version 2.8.0 already has the required changes
included.
copied to the /usr/src directory on your machine.
@table @asis
@item 1. Uncompress gcc:
@format
cd /usr/src
tar fvxz gcc-2.7.2.1.tar.gz
tar fvxz gcc-2.8.0.tar.gz
@end format
@item 2. Apply the Objective-C runtime patch.
Go inside the GCC directory and issue
the command (Make sure you have the correct patch for the version of gcc):
@format
cd gcc-2.7.2.1
cat gcc-2.7.2.1-objc.diff | patch -p1
@end format
@item 3. Configure the gcc compiler's makefile for your machine:
@item 2. Configure the gcc compiler's makefile for your machine:
@format
./configure
@ -271,27 +258,22 @@ the command (Make sure you have the correct patch for the version of gcc):
installed with the GNUstep directory structure; then you should specify the
GNUstep system root as the prefix when you configure the package.
To enable multiple threads in the Objective-C library use the
@var{--enable-threads=lib} argument to configure, where @var{lib} is the
thread library to use or @var{--disable-threads}
to use a single-threaded Objective-C runtime.
@format
./configure --prefix=$GNUSTEP_SYSTEM_ROOT
@end format
@item 4. Compile gcc
4.1 With a single-threaded Objective-C runtime:
make OBJC_THREAD_FILE=thr-single
or
4.2 With thread support appropriate for your system
make
or
4.3 With PCThreads support (Linux/GNU)
make OBJC_THREAD_FILE=thr-pthreads
make bootstrap
@item 5. Wait
@ -313,7 +295,7 @@ make OBJC_THREAD_FILE=thr-pthreads
@item 7. Delete the gcc directory if you're low on disk space
@format
rm -rf /usr/src/gcc-2.7.2.1
rm -rf /usr/src/gcc-2.8.0
@end format
@end table

View file

@ -4,6 +4,19 @@
The currently released version of the library is
@samp{@value{GNUSTEP-BASE-VERSION}}.
@section Noteworthy changes in version @samp{0.5.0}
@itemize @bullet
@item Improvements to the NSInvocation class, from Masatake Yamato
@email{masata-y@aist-nara.ac.jp}.
@item Implemented several new OpenStep methods and classes (e.g. NSTask)
and speed improvements for others (NSArray, NSData, NSString),
from Richard Frith-Macdonald @email{richard@brainstorm.co.uk}.
@end itemize
@section Noteworthy changes in version @samp{0.4.0}
@itemize @bullet

View file

@ -423,7 +423,7 @@ Add or Remove an Item
`NSString *NSStringFromSelector(SEL ASELECTOR)'
@end example
@item [0] Compose a Message To Be Sent Later to an Object
@item [3] Compose a Message To Be Sent Later to an Object
@example
`NSInvocation *NS_INVOCATION(Class ACLASS, INSTANCEMESSAGE)'
`NSInvocation *NS_MESSAGE(id ANOBJECT, INSTANCEMESSAGE)'

View file

@ -30,15 +30,17 @@
@interface NSGArray : NSArray
{
char _NSGArray_placeholder[(sizeof(struct ConstantArray)
- sizeof(struct NSArray))];
id *_contents_array;
unsigned int _count;
}
@end
@interface NSGMutableArray : NSMutableArray
{
char _NSGMutableArray_placeholder[(sizeof(struct Array)
- sizeof(struct NSMutableArray))];
id *_contents_array;
unsigned int _count;
unsigned int _capacity;
int _grow_factor;
}
@end

View file

@ -53,4 +53,28 @@
@end
/* The second argument of the following macros must
be SEL type.
-initWithTarget:selector:, a method used in the macros
is come from the MethodInvocation behavior.
So your gcc warns that NSInvocation doesn't have
-initWithTarget:selector:.
e.g.
NS_INVOCATION([NSObject class] ,
@selector(isKindOfClass:),
[NSObject class]);
NS_MESSAGE([NSObject new] ,
@selector(isKindOfClass:), [NSObject class]); */
#define NS_INVOCATION(ACLASS, INSTANCEMESSAGE...)\
([[[NSInvocation alloc]\
initWithTarget:nil selector: INSTANCEMESSAGE]\
autorelease])
#define NS_MESSAGE(ANOBJECT, INSTANCEMESSAGE...)\
([[[NSInvocation alloc]\
initWithTarget:(ANOBJECT) selector: INSTANCEMESSAGE]\
autorelease])
#endif /* __NSInvocation_h_GNUSTEP_BASE_INCLUDE */

View file

@ -49,6 +49,7 @@ before-install::
after-install::
cp $(TIMEZONE_ARCHIVE) $(resourcedir); \
cd $(resourcedir); \
rm -rf NSTimeZones; \
tar -xf $(TIMEZONE_ARCHIVE); \
rm -f $(TIMEZONE_ARCHIVE)

View file

@ -565,7 +565,7 @@ my_method_get_next_argument (arglist_t argframe,
if (args_retained)
[*(id*)datum retain];
break;
CASE_TYPE(_C_CLASS, Class);
CASE_TYPE(_C_SEL, SEL);
CASE_TYPE(_C_LNG, long);
CASE_TYPE(_C_ULNG, unsigned long);
@ -580,8 +580,13 @@ my_method_get_next_argument (arglist_t argframe,
CASE_TYPE(_C_CHARPTR, char*);
CASE_TYPE(_C_PTR, void*);
default:
[self notImplemented: _cmd];
// memcpy (datum, va_arg (ap, void*), objc_sizeof_type(tmptype));
{
int copysize;
copysize = objc_sizeof_type(tmptype);
memcpy(datum,
va_arg(ap, typeof(char[copysize])),
copysize);
} /* default */
}
datum = my_method_get_next_argument (argframe, &tmptype);
}

View file

@ -5,6 +5,10 @@
From skeleton by: Adam Fedor <fedor@boulder.colorado.edu>
Created: March 1995
Rewrite by: Richard Frith-Macdonald <richard@brainstorm.co.uk>
January 1998 - new methods and changes as documented for Rhapsody plus
changes of array indices to type unsigned, plus major efficiency hacks.
This file is part of the GNUstep Base Library.
This library is free software; you can redistribute it and/or
@ -133,7 +137,7 @@ static Class NSMutableArray_concrete_class;
- (NSArray*) arrayByAddingObject: anObject
{
id na;
int i, c;
unsigned i, c;
id *objects;
c = [self count];
@ -149,7 +153,7 @@ static Class NSMutableArray_concrete_class;
- (NSArray*) arrayByAddingObjectsFromArray: (NSArray*)anotherArray
{
id na;
int i, c, l;
unsigned i, c, l;
id *objects;
c = [self count];
@ -166,10 +170,10 @@ static Class NSMutableArray_concrete_class;
- initWithObjects: firstObject rest: (va_list) ap
{
register int i;
register int curSize;
auto int prevSize;
auto int newSize;
register unsigned i;
register unsigned curSize;
auto unsigned prevSize;
auto unsigned newSize;
auto id *objsArray;
auto id tmpId;
@ -236,7 +240,7 @@ static Class NSMutableArray_concrete_class;
- initWithArray: (NSArray*)array
{
int i, c;
unsigned i, c;
id *objects;
c = [array count];
@ -250,14 +254,14 @@ static Class NSMutableArray_concrete_class;
- (void) getObjects: (id*)aBuffer
{
int i, c = [self count];
unsigned i, c = [self count];
for (i = 0; i < c; i++)
aBuffer[i] = [self objectAtIndex: i];
}
- (void) getObjects: (id*)aBuffer range: (NSRange)aRange
{
int i, j = 0, c = [self count], e = aRange.location + aRange.length;
unsigned i, j = 0, c = [self count], e = aRange.location + aRange.length;
if (c < e)
e = c;
for (i = aRange.location; i < c; i++)
@ -266,7 +270,7 @@ static Class NSMutableArray_concrete_class;
- (unsigned) indexOfObjectIdenticalTo:anObject
{
int i, c = [self count];
unsigned i, c = [self count];
for (i = 0; i < c; i++)
if (anObject == [self objectAtIndex:i])
return i;
@ -275,7 +279,7 @@ static Class NSMutableArray_concrete_class;
- (unsigned) indexOfObjectIdenticalTo:anObject inRange: (NSRange)aRange
{
int i, e = aRange.location + aRange.length, c = [self count];
unsigned i, e = aRange.location + aRange.length, c = [self count];
if (c < e)
e = c;
for (i = aRange.location; i < e; i++)
@ -287,7 +291,7 @@ static Class NSMutableArray_concrete_class;
/* Inefficient, should be overridden. */
- (unsigned) indexOfObject: anObject
{
int i, c = [self count];
unsigned i, c = [self count];
for (i = 0; i < c; i++)
if ([[self objectAtIndex:i] isEqual: anObject])
return i;
@ -297,7 +301,7 @@ static Class NSMutableArray_concrete_class;
/* Inefficient, should be overridden. */
- (unsigned) indexOfObject: anObject inRange: (NSRange)aRange
{
int i, e = aRange.location + aRange.length, c = [self count];
unsigned i, e = aRange.location + aRange.length, c = [self count];
if (c < e)
e = c;
for (i = aRange.location; i < e; i++)
@ -323,7 +327,7 @@ static Class NSMutableArray_concrete_class;
- (BOOL) isEqualToArray: (NSArray*)otherArray
{
int i, c = [self count];
unsigned i, c = [self count];
if (c != [otherArray count])
return NO;
@ -335,7 +339,7 @@ static Class NSMutableArray_concrete_class;
- lastObject
{
int count = [self count];
unsigned count = [self count];
if (count == 0)
return nil;
return [self objectAtIndex: count-1];
@ -343,8 +347,8 @@ static Class NSMutableArray_concrete_class;
- (void) makeObjectsPerform: (SEL)aSelector
{
int i, c = [self count];
for (i = c-1; i >= 0; i--)
unsigned i = [self count];
while (i-- > 0)
[[self objectAtIndex:i] perform:aSelector];
}
@ -355,8 +359,8 @@ static Class NSMutableArray_concrete_class;
- (void) makeObjectsPerform: (SEL)aSelector withObject:argument
{
int i, c = [self count];
for (i = c-1; i >= 0; i--)
unsigned i = [self count];
while (i-- > 0)
[[self objectAtIndex:i] perform:aSelector withObject:argument];
}
@ -403,7 +407,7 @@ static Class NSMutableArray_concrete_class;
- (NSString*) componentsJoinedByString: (NSString*)separator
{
int i, c = [self count];
unsigned i, c = [self count];
id s = [NSMutableString stringWithCapacity:2]; /* arbitrary capacity */
if (!c)
@ -419,7 +423,7 @@ static Class NSMutableArray_concrete_class;
- (NSArray*) pathsMatchingExtensions: (NSArray*)extensions
{
int i, c = [self count];
unsigned i, c = [self count];
NSMutableArray *a = [NSMutableArray arrayWithCapacity: 1];
for (i = 0; i < c; i++)
{
@ -433,7 +437,7 @@ static Class NSMutableArray_concrete_class;
- firstObjectCommonWithArray: (NSArray*)otherArray
{
int i, c = [self count];
unsigned i, c = [self count];
id o;
for (i = 0; i < c; i++)
if ([otherArray containsObject:(o = [self objectAtIndex:i])])
@ -499,17 +503,17 @@ static Class NSMutableArray_concrete_class;
indent: (unsigned int)level
{
NSMutableString *result;
NSMutableArray *plists;
int count;
int size;
NSAutoreleasePool *arp;
int indentSize;
int indentBase;
unsigned size;
unsigned indentSize;
unsigned indentBase;
NSMutableString *iBaseString;
NSMutableString *iSizeString;
int i;
NSAutoreleasePool *arp = [[NSAutoreleasePool alloc] init];
unsigned count = [self count];
NSString *plists[count];
unsigned i;
arp = [[NSAutoreleasePool alloc] init];
[self getObjects: plists];
/*
* Indentation is at four space intervals using tab characters to
@ -558,12 +562,10 @@ static Class NSMutableArray_concrete_class;
size = 4 + indentBase;
count = [self count];
plists = [NSMutableArray arrayWithCapacity: count];
for (i = 0; i < count; i++) {
id item;
item = [self objectAtIndex: i];
item = plists[i];
if ([item isKindOfClass: [NSString class]]) {
item = [item descriptionForPropertyList];
}
@ -578,7 +580,7 @@ static Class NSMutableArray_concrete_class;
else {
item = [item description];
}
[plists addObject: item];
plists[i] = item;
size += [item length] + indentSize;
if (i == count - 1) {
@ -593,7 +595,7 @@ static Class NSMutableArray_concrete_class;
[result appendString: @"(\n"];
for (i = 0; i < count; i++) {
[result appendString: iSizeString];
[result appendString: [plists objectAtIndex: i]];
[result appendString: plists[i]];
if (i == count - 1) {
[result appendString: @"\n"];
}
@ -619,9 +621,9 @@ static Class NSMutableArray_concrete_class;
- copyWithZone: (NSZone*)zone
{
/* a deep copy */
int count = [self count];
unsigned count = [self count];
id objects[count];
int i;
unsigned i;
for (i = 0; i < count; i++)
objects[i] = [[self objectAtIndex:i] copyWithZone:zone];
return [[[[self class] _concreteClass] allocWithZone:zone]
@ -676,13 +678,14 @@ static Class NSMutableArray_concrete_class;
- (void) replaceObjectsInRange: (NSRange)aRange
withObjectsFromArray: (NSArray*)anArray
{
int i;
unsigned i;
if ([self count] <= aRange.location)
[NSException raise: NSRangeException
format: @"Replacing objects beyond end of array."];
[self removeObjectsInRange: aRange];
for (i = [anArray count] - 1; i >= 0; i--)
i = [anArray count];
while (i-- > 0)
[self insertObject: [anArray objectAtIndex: i] atIndex: aRange.location];
}
@ -742,7 +745,7 @@ static Class NSMutableArray_concrete_class;
- initWithObjects: (id*)objects count: (unsigned)count
{
/* xxx Could be made more efficient by increasing capacity all at once. */
int i;
unsigned i;
self = [self initWithCapacity: count];
for (i = 0; i < count; i++)
[self addObject:objects[i]];
@ -751,7 +754,7 @@ static Class NSMutableArray_concrete_class;
- (void) removeLastObject
{
int count = [self count];
unsigned count = [self count];
if (count == 0)
[NSException raise: NSRangeException
format: @"Trying to remove from an empty array."];
@ -760,68 +763,82 @@ static Class NSMutableArray_concrete_class;
- (void) removeObjectIdenticalTo: anObject
{
unsigned index;
unsigned pos = NSNotFound;
unsigned i = [self count];
/* Retain the object. Yuck, but necessary in case the array holds
the last reference to anObject. */
/* xxx Is there an alternative to this expensive retain/release? */
[anObject retain];
for (index = [self indexOfObjectIdenticalTo: anObject];
index != NO_INDEX;
index = [self indexOfObjectIdenticalTo: anObject])
[self removeObjectAtIndex: index];
[anObject release];
while (i-- > 0)
{
id o = [self objectAtIndex: i];
if (o == anObject)
{
if (pos != NSNotFound)
[self removeObjectAtIndex: pos];
pos = i;
}
}
if (pos != NSNotFound)
[self removeObjectAtIndex: pos];
}
- (void) removeObject: anObject inRange:(NSRange)aRange
{
int c = [self count], s = aRange.location;
int i = aRange.location + aRange.length;
unsigned c = [self count], s = aRange.location;
unsigned i = aRange.location + aRange.length;
unsigned pos = NSNotFound;
if (i > c)
i = c;
[anObject retain];
for (i--; i >= s; i--)
while (i-- > s)
{
id o = [self objectAtIndex: i];
if (o == anObject || [o isEqual: anObject])
[self removeObjectAtIndex:i];
{
if (pos != NSNotFound)
[self removeObjectAtIndex: pos];
pos = i;
}
}
[anObject release];
if (pos != NSNotFound)
[self removeObjectAtIndex: pos];
}
- (void) removeObjectIdenticalTo: anObject inRange:(NSRange)aRange
{
int c = [self count], s = aRange.location;
int i = aRange.location + aRange.length;
unsigned c = [self count], s = aRange.location;
unsigned i = aRange.location + aRange.length;
unsigned pos = NSNotFound;
if (i > c)
i = c;
[anObject retain];
for (i--; i >= s; i--)
while (i-- > s)
{
id o = [self objectAtIndex: i];
if (o == anObject)
[self removeObjectAtIndex:i];
{
if (pos != NSNotFound)
[self removeObjectAtIndex: pos];
pos = i;
}
}
[anObject release];
if (pos != NSNotFound)
[self removeObjectAtIndex: pos];
}
- (void) removeObject: anObject
{
unsigned index;
unsigned pos = NSNotFound;
unsigned i = [self count];
/* Retain the object. Yuck, but necessary in case the array holds
the last reference to anObject. */
/* xxx Is there an alternative to this expensive retain/release? */
[anObject retain];
for (index = [self indexOfObject: anObject];
index != NO_INDEX;
index = [self indexOfObject: anObject])
[self removeObjectAtIndex: index];
[anObject release];
while (i-- > 0)
{
id o = [self objectAtIndex: i];
if (o == anObject || [o isEqual: anObject])
{
if (pos != NSNotFound)
[self removeObjectAtIndex: pos];
pos = i;
}
}
if (pos != NSNotFound)
[self removeObjectAtIndex: pos];
}
- (void) removeAllObjects
@ -833,7 +850,7 @@ static Class NSMutableArray_concrete_class;
- (void) addObjectsFromArray: (NSArray*)otherArray
{
/* xxx Could be made more efficient by increasing capacity all at once. */
int i, c = [otherArray count];
unsigned i, c = [otherArray count];
for (i = 0; i < c; i++)
[self addObject: [otherArray objectAtIndex: i]];
}
@ -859,18 +876,18 @@ static Class NSMutableArray_concrete_class;
- (void) removeObjectsInArray: (NSArray*)otherArray
{
int i, c = [otherArray count];
unsigned i, c = [otherArray count];
for (i = 0; i < c; i++)
[self removeObject:[otherArray objectAtIndex:i]];
}
- (void) removeObjectsInRange: (NSRange)aRange
{
int i, s = aRange.location, c = [self count];
unsigned i, s = aRange.location, c = [self count];
i = aRange.location + aRange.length;
if (c < i)
i = c;
for (i--; i >= s; i--)
while (i-- > s)
[self removeObjectAtIndex: i];
}
@ -890,7 +907,7 @@ static Class NSMutableArray_concrete_class;
/* Shell sort algorithm taken from SortingInAction - a NeXT example */
#define STRIDE_FACTOR 3 // good value for stride factor is not well-understood
// 3 is a fairly good choice (Sedgewick)
int c,d, stride;
unsigned c,d, stride;
BOOL found;
int count = [self count];
@ -903,19 +920,21 @@ static Class NSMutableArray_concrete_class;
stride = stride / STRIDE_FACTOR;
for (c = stride; c < count; c++) {
found = NO;
if (stride > c)
break;
d = c - stride;
while ((d >= 0) && !found) {
while (!found) {
// move to left until correct place
id a = [self objectAtIndex:d + stride];
id b = [self objectAtIndex:d];
if ((*compare)(a, b, context) == NSOrderedAscending) {
[a retain];
[b retain];
[self replaceObjectAtIndex:d + stride withObject:b];
[self replaceObjectAtIndex:d withObject:a];
d -= stride; // jump by stride factor
[a release];
[b release];
if (stride > d)
break;
d -= stride; // jump by stride factor
}
else found = YES;
}

View file

@ -97,7 +97,7 @@
static BOOL
readContentsOfFile(NSString* path, void** buf, unsigned* len)
{
const char *theFileName;
char thePath[BUFSIZ*2];
FILE *theFile = 0;
unsigned int fileLength;
void *tmp = 0;
@ -110,12 +110,17 @@ readContentsOfFile(NSString* path, void** buf, unsigned* len)
* bidirectional, this simple translation might not be the proper
* one. */
theFileName = [path cStringNoCopy];
theFile = fopen(theFileName, "r");
if ([path getFileSystemRepresentation: thePath
maxLength: sizeof(thePath)-1] == NO)
{
NSLog(@"Open (%s) attempt failed - bad path", thePath);
return NO;
}
theFile = fopen(thePath, "r");
if (theFile == NULL) /* We failed to open the file. */
{
NSLog(@"Open (%s) attempt failed - %s", theFileName, strerror(errno));
NSLog(@"Open (%s) attempt failed - %s", thePath, strerror(errno));
goto failure;
}
@ -162,6 +167,7 @@ readContentsOfFile(NSString* path, void** buf, unsigned* len)
*buf = tmp;
*len = fileLength;
fclose(theFile);
return YES;
/* Just in case the failure action needs to be changed. */
@ -431,51 +437,48 @@ readContentsOfFile(NSString* path, void** buf, unsigned* len)
- (BOOL) writeToFile: (NSString *)path
atomically: (BOOL)useAuxiliaryFile
{
char *theFileName = NULL;
const char *theRealFileName = NULL;
char thePath[BUFSIZ*2+8];
char theRealPath[BUFSIZ*2];
FILE *theFile;
int c;
if ([path getFileSystemRepresentation: theRealPath
maxLength: sizeof(theRealPath)-1] == NO)
{
NSLog(@"Open (%s) attempt failed - bad path", theRealPath);
return NO;
}
/* FIXME: The docs say nothing about the raising of any exceptions,
* but if someone can provide evidence as to the proper handling of
* bizarre situations here, I'll add whatever functionality is
* needed. For the time being, I'm returning the success or failure
* of the write as a boolean YES or NO. */
/* FIXME: I believe that we should take the name of the file to be
* the cString of the path provided. It is unclear, however, that
* this is correct for fully internationalized functionality. If
* the cString <--> Unicode translation isn't completely
* bidirectional, this simple translation might not be the proper
* one. */
if (useAuxiliaryFile)
{
/* Use the path name of the destination file as a prefix for the
* mktemp() call so that we can be sure that both files are on
* the same filesystem and the subsequent rename() will work. */
theRealFileName = [path cString];
theFileName = objc_malloc(strlen(theRealFileName) + 7);
strcpy(theFileName, theRealFileName);
strcat(theFileName, "XXXXXX");
if (mktemp(theFileName) == 0)
strcpy(thePath, theRealPath);
strcat(thePath, "XXXXXX");
if (mktemp(thePath) == 0)
{
NSLog(@"mktemp (%s) failed - %s", theFileName, strerror(errno));
NSLog(@"mktemp (%s) failed - %s", thePath, strerror(errno));
goto failure;
}
}
else
{
theFileName = (char*)[path cString];
strcpy(thePath, theRealPath);
}
/* Open the file (whether temp or real) for writing. */
theFile = fopen(theFileName, "w");
theFile = fopen(thePath, "w");
if (theFile == NULL) /* Something went wrong; we weren't
* even able to open the file. */
{
NSLog(@"Open (%s) failed - %s", theFileName, strerror(errno));
NSLog(@"Open (%s) failed - %s", thePath, strerror(errno));
goto failure;
}
@ -490,7 +493,7 @@ readContentsOfFile(NSString* path, void** buf, unsigned* len)
if (c < [self length]) /* We failed to write everything for
* some reason. */
{
NSLog(@"Fwrite (%s) failed - %s", theFileName, strerror(errno));
NSLog(@"Fwrite (%s) failed - %s", thePath, strerror(errno));
goto failure;
}
@ -501,7 +504,7 @@ readContentsOfFile(NSString* path, void** buf, unsigned* len)
* closing the file, but we got here,
* so we need to deal with it. */
{
NSLog(@"Fclose (%s) failed - %s", theFileName, strerror(errno));
NSLog(@"Fclose (%s) failed - %s", thePath, strerror(errno));
goto failure;
}
@ -509,15 +512,14 @@ readContentsOfFile(NSString* path, void** buf, unsigned* len)
* real file. Am I forgetting anything here? */
if (useAuxiliaryFile)
{
c = rename(theFileName, theRealFileName);
c = rename(thePath, theRealPath);
if (c != 0) /* Many things could go wrong, I
* guess. */
{
NSLog(@"Rename (%s) failed - %s", theFileName, strerror(errno));
NSLog(@"Rename (%s) failed - %s", thePath, strerror(errno));
goto failure;
}
objc_free(theFileName);
}
/* success: */
@ -525,8 +527,6 @@ readContentsOfFile(NSString* path, void** buf, unsigned* len)
/* Just in case the failure action needs to be changed. */
failure:
if (useAuxiliaryFile && theFileName != 0)
objc_free(theFileName);
return NO;
}
@ -1335,12 +1335,18 @@ readContentsOfFile(NSString* path, void** buf, unsigned* len)
- (id) initWithContentsOfMappedFile: (NSString*)path
{
int fd;
const char *theFileName = [path cStringNoCopy];
char thePath[BUFSIZ*2];
fd = open(theFileName, O_RDONLY);
if ([path getFileSystemRepresentation: thePath
maxLength: sizeof(thePath)-1] == NO)
{
NSLog(@"Open (%s) attempt failed - bad path", thePath);
return NO;
}
fd = open(thePath, O_RDONLY);
if (fd < 0)
{
NSLog(@"[NSDataMappedFile -initWithContentsOfMappedFile:] unable to open %s - %s", theFileName, strerror(errno));
NSLog(@"[NSDataMappedFile -initWithContentsOfMappedFile:] unable to open %s - %s", thePath, strerror(errno));
[self dealloc];
return nil;
}
@ -1348,7 +1354,7 @@ readContentsOfFile(NSString* path, void** buf, unsigned* len)
length = lseek(fd, 0, SEEK_END);
if (length < 0)
{
NSLog(@"[NSDataMappedFile -initWithContentsOfMappedFile:] unable to seek to eof %s - %s", theFileName, strerror(errno));
NSLog(@"[NSDataMappedFile -initWithContentsOfMappedFile:] unable to seek to eof %s - %s", thePath, strerror(errno));
close(fd);
[self dealloc];
return nil;
@ -1356,7 +1362,7 @@ readContentsOfFile(NSString* path, void** buf, unsigned* len)
/* Position at start of file. */
if (lseek(fd, 0, SEEK_SET) != 0)
{
NSLog(@"[NSDataMappedFile -initWithContentsOfMappedFile:] unable to seek to sof %s - %s", theFileName, strerror(errno));
NSLog(@"[NSDataMappedFile -initWithContentsOfMappedFile:] unable to seek to sof %s - %s", thePath, strerror(errno));
close(fd);
[self dealloc];
return nil;
@ -1364,7 +1370,7 @@ readContentsOfFile(NSString* path, void** buf, unsigned* len)
bytes = mmap(0, length, PROT_READ, MAP_SHARED, fd, 0);
if (bytes == MAP_FAILED)
{
NSLog(@"[NSDataMappedFile -initWithContentsOfMappedFile:] mapping failed for %s - %s", theFileName, strerror(errno));
NSLog(@"[NSDataMappedFile -initWithContentsOfMappedFile:] mapping failed for %s - %s", thePath, strerror(errno));
close(fd);
[self dealloc];
self = [NSDataMalloc alloc];

View file

@ -395,27 +395,24 @@ compareIt(id o1, id o2, void* context)
- (NSString*) descriptionInStringsFileFormat
{
NSMutableString *result;
NSMutableArray *plists;
NSMutableArray *theKeys;
int numKeys;
int size;
NSAutoreleasePool *arp;
int i;
NSAutoreleasePool *arp = [[NSAutoreleasePool alloc] init];
NSArray *keysArray = [self allKeys];
int numKeys = [keysArray count];
NSString *plists[numKeys];
NSString *keys[numKeys];
arp = [[NSAutoreleasePool alloc] init];
[keysArray getObjects: keys];
size = 1;
theKeys = [NSMutableArray arrayWithArray: [self allKeys]];
numKeys = [theKeys count];
plists = [NSMutableArray arrayWithCapacity: numKeys];
for (i = 0; i < numKeys; i++) {
NSString *newKey;
id key;
id item;
key = [theKeys objectAtIndex:i];
key = keys[i];
item = [self objectForKey: key];
if ([key respondsToSelector: @selector(descriptionForPropertyList)]) {
newKey = [key descriptionForPropertyList];
@ -423,10 +420,7 @@ compareIt(id o1, id o2, void* context)
else {
newKey = [key description];
}
if (newKey != key) {
key = newKey;
[theKeys replaceObjectAtIndex: i withObject: key];
}
keys[i] = newKey;
if (item == nil) {
item = @"";
@ -437,9 +431,9 @@ compareIt(id o1, id o2, void* context)
else {
item = [item description];
}
[plists addObject: item];
plists[i] = item;
size += [key length] + [item length];
size += [newKey length] + [item length];
if ([item length]) {
size += 5;
}
@ -450,9 +444,9 @@ compareIt(id o1, id o2, void* context)
result = [[NSMutableString alloc] initWithCapacity: size];
for (i = 0; i < numKeys; i++) {
NSString* item = [plists objectAtIndex: i];
NSString* item = plists[i];
[result appendString: [theKeys objectAtIndex: i]];
[result appendString: keys[i]];
if ([item length]) {
[result appendString: @" = "];
[result appendString: item];
@ -475,21 +469,21 @@ compareIt(id o1, id o2, void* context)
{
NSMutableString *result;
NSEnumerator *enumerator;
NSMutableArray *plists;
NSMutableArray *theKeys;
id key;
BOOL canCompare = YES;
int numKeys;
int count;
int size;
NSAutoreleasePool *arp;
int indentSize;
int indentBase;
NSMutableString *iBaseString;
NSMutableString *iSizeString;
int i;
arp = [[NSAutoreleasePool alloc] init];
NSAutoreleasePool *arp = [[NSAutoreleasePool alloc] init];
NSArray *keyArray = [self allKeys];
NSMutableArray *theKeys = [NSMutableArray arrayWithArray: keyArray];
int numKeys = [theKeys count];
NSString *plists[numKeys];
NSString *keys[numKeys];
/*
* Indentation is at four space intervals using tab characters to
@ -546,21 +540,15 @@ compareIt(id o1, id o2, void* context)
}
if (canCompare) {
theKeys = [NSMutableArray arrayWithArray:
[[self allKeys] sortedArrayUsingSelector: @selector(compare:)]];
}
else {
theKeys = [NSMutableArray arrayWithArray: [self allKeys]];
[theKeys sortUsingSelector: @selector(compare:)];
}
numKeys = [theKeys count];
plists = [NSMutableArray arrayWithCapacity: numKeys];
[theKeys getObjects: keys];
for (i = 0; i < numKeys; i++) {
NSString *newKey;
id item;
key = [theKeys objectAtIndex:i];
key = keys[i];
item = [self objectForKey: key];
if ([key respondsToSelector: @selector(descriptionForPropertyList)]) {
newKey = [key descriptionForPropertyList];
@ -568,10 +556,7 @@ compareIt(id o1, id o2, void* context)
else {
newKey = [key description];
}
if (newKey != key) {
key = newKey;
[theKeys replaceObjectAtIndex: i withObject: key];
}
keys[i] = newKey;
if ([item isKindOfClass: [NSString class]]) {
item = [item descriptionForPropertyList];
@ -587,9 +572,9 @@ compareIt(id o1, id o2, void* context)
else {
item = [item description];
}
[plists addObject: item];
plists[i] = item;
size += [key length] + [item length] + indentSize;
size += [newKey length] + [item length] + indentSize;
if (i == numKeys - 1) {
size += 4; /* ' = ' and newline */
}
@ -602,9 +587,9 @@ compareIt(id o1, id o2, void* context)
[result appendString: @"{\n"];
for (i = 0; i < numKeys; i++) {
[result appendString: iSizeString];
[result appendString: [theKeys objectAtIndex: i]];
[result appendString: keys[i]];
[result appendString: @" = "];
[result appendString: [plists objectAtIndex: i]];
[result appendString: plists[i]];
if (i == numKeys - 1) {
[result appendString: @"\n"];
}

View file

@ -84,6 +84,7 @@
#ifdef HAVE_SYS_VFS_H
# include <sys/vfs.h>
# include <sys/statvfs.h>
#endif
#ifdef HAVE_SYS_STATFS_H

View file

@ -75,8 +75,25 @@
format: @"Index out of bounds"];
return self->_contents_array[index];
}
#endif
- (void) getObjects: (id*)aBuffer
{
unsigned i;
for (i = 0; i < _count; i++)
aBuffer[i] = _contents_array[i];
}
- (void) getObjects: (id*)aBuffer range: (IndexRange)aRange
{
unsigned i, j = 0, e = aRange.location + aRange.length;
if (_count < e)
e = _count;
for (i = aRange.location; i < _count; i++)
aBuffer[j++] = _contents_array[i];
}
@end
@class NSMutableArrayNonCore;
@ -93,17 +110,43 @@
}
}
#if 0
/* Comes in from Array behavior
- initWithCapacity:
- (void) addObject: anObject
- (void) insertObject: anObject atIndex: (unsigned)index
*/
- (void) replaceObjectAtIndex: (unsigned)index withObject: anObject
- (void) sortUsingFunction: (int(*)(id,id,void*))compare
context: (void*)context
{
[self replaceObjectAtIndex: index with: anObject];
/* Shell sort algorithm taken from SortingInAction - a NeXT example */
#define STRIDE_FACTOR 3 // good value for stride factor is not well-understood
// 3 is a fairly good choice (Sedgewick)
unsigned c,d, stride;
BOOL found;
int count = _count;
stride = 1;
while (stride <= count)
stride = stride * STRIDE_FACTOR + 1;
while(stride > (STRIDE_FACTOR - 1)) {
// loop to sort for each value of stride
stride = stride / STRIDE_FACTOR;
for (c = stride; c < count; c++) {
found = NO;
if (stride > c)
break;
d = c - stride;
while (!found) {
// move to left until correct place
id a = _contents_array[d + stride];
id b = _contents_array[d];
if ((*compare)(a, b, context) == NSOrderedAscending) {
_contents_array[d+stride] = b;
_contents_array[d] = a;
if (stride > d)
break;
d -= stride; // jump by stride factor
}
else found = YES;
}
}
}
}
#endif
@end

View file

@ -268,13 +268,13 @@ stringDecrementCountAndFillHoleAt(NSGMutableCStringStruct *self,
}
/* This is the designated initializer for this class */
/* xxx Should capacity include the '\0' terminator? */
/* NB. capacity does not include the '\0' terminator */
- initWithCapacity: (unsigned)capacity
{
[super init];
_count = 0;
_capacity = MAX(capacity, 2);
OBJC_MALLOC(_contents_chars, char, _capacity);
_capacity = MAX(capacity, 3);
OBJC_MALLOC(_contents_chars, char, _capacity+1);
_contents_chars[0] = '\0';
_free_contents = YES;
return self;
@ -297,10 +297,10 @@ stringDecrementCountAndFillHoleAt(NSGMutableCStringStruct *self,
- (void) insertString: (NSString*)aString atIndex:(unsigned)index
{
unsigned c = [aString cStringLength];
if (_count + c >= _capacity)
if (_count + c > _capacity)
{
_capacity = MAX(_capacity*2, _count+c);
OBJC_REALLOC(_contents_chars, char, _capacity);
OBJC_REALLOC(_contents_chars, char, _capacity+1);
}
stringIncrementCountAndMakeHoleAt((NSGMutableCStringStruct*)self, index, c);
memcpy(_contents_chars + index, [aString cStringNoCopy], c);
@ -310,10 +310,10 @@ stringDecrementCountAndFillHoleAt(NSGMutableCStringStruct *self,
- (void) appendString: (NSString*)aString
{
unsigned c = [aString cStringLength];
if (_count + c >= _capacity)
if (_count + c > _capacity)
{
_capacity = MAX(_capacity*2, _count+c);
OBJC_REALLOC(_contents_chars, char, _capacity);
OBJC_REALLOC(_contents_chars, char, _capacity+1);
}
memcpy(_contents_chars + _count, [aString cStringNoCopy], c);
_count += c;
@ -324,10 +324,10 @@ stringDecrementCountAndFillHoleAt(NSGMutableCStringStruct *self,
{
const char *s = [aString cStringNoCopy];
unsigned length = strlen(s);
if (_capacity < length+1)
if (_capacity < length)
{
_capacity = length+1;
OBJC_REALLOC(_contents_chars, char, _capacity);
_capacity = length;
OBJC_REALLOC(_contents_chars, char, _capacity+1);
}
memcpy(_contents_chars, s, length);
_contents_chars[length] = '\0';
@ -337,10 +337,10 @@ stringDecrementCountAndFillHoleAt(NSGMutableCStringStruct *self,
/* xxx This method may be removed in future. */
- (void) setCString: (const char *)byteString length: (unsigned)length
{
if (_capacity < length+1)
if (_capacity < length)
{
_capacity = length+1;
OBJC_REALLOC(_contents_chars, char, _capacity);
_capacity = length;
OBJC_REALLOC(_contents_chars, char, _capacity+1);
}
memcpy(_contents_chars, byteString, length);
_contents_chars[length] = '\0';
@ -354,7 +354,7 @@ stringDecrementCountAndFillHoleAt(NSGMutableCStringStruct *self,
{
[super init];
_count = length;
_capacity = length+1;
_capacity = length;
_contents_chars = byteString;
_free_contents = flag;
return self;
@ -424,10 +424,10 @@ stringDecrementCountAndFillHoleAt(NSGMutableCStringStruct *self,
{
CHECK_INDEX_RANGE_ERROR(index, _count+1);
// one for the next char, one for the '\0';
if (_count+1 >= _capacity)
if (_count >= _capacity)
{
_capacity *= 2;
OBJC_REALLOC(_contents_chars, char, _capacity);
OBJC_REALLOC(_contents_chars, char, _capacity+1);
}
stringIncrementCountAndMakeHoleAt((NSGMutableCStringStruct*)self, index, 1);
_contents_chars[index] = [newObject charValue];

View file

@ -74,10 +74,9 @@
length: (unsigned int)length
{
unichar *s;
OBJC_MALLOC(s, unichar, length+1);
OBJC_MALLOC(s, unichar, length);
if (chars)
memcpy(s, chars,2*length);
s[length] = (unichar)0;
return [self initWithCharactersNoCopy:s length:length freeWhenDone:YES];
}
@ -94,10 +93,7 @@
- (id) init
{
unichar *u;
OBJC_MALLOC(u, unichar,1);
u[0]=(unichar)0;
return [self initWithCharactersNoCopy:u length:0 freeWhenDone: YES];
return [self initWithCharactersNoCopy:0 length:0 freeWhenDone: NO];
}
// Getting a String's Length
@ -111,11 +107,25 @@
- (unichar) characterAtIndex: (unsigned int)index
{
/* xxx This should raise an NSException. */
CHECK_INDEX_RANGE_ERROR(index, _count);
if (index >= _count)
[NSException raise: NSRangeException format:@"Invalid index."];
return _contents_chars[index];
}
- (void)getCharacters: (unichar*)buffer
{
memcpy(buffer, _contents_chars, _count*2);
}
- (void)getCharacters: (unichar*)buffer range: (NSRange)aRange
{
if (aRange.location >= _count)
[NSException raise: NSRangeException format:@"Invalid location."];
if (aRange.length > (_count - aRange.location))
[NSException raise: NSRangeException format:@"Invalid location+length."];
memcpy(buffer, _contents_chars + aRange.location, aRange.length*2);
}
// Dividing Strings into Substrings
- (NSString*) substringFromRange: (NSRange)aRange
@ -208,7 +218,6 @@
count:_count
at:_contents_chars
withName:NULL];
_contents_chars[_count] = 0;
_free_contents = YES;
return self;
}
@ -314,16 +323,33 @@ stringDecrementCountAndFillHoleAt(NSGMutableStringStruct *self,
// Initializing Newly Allocated Strings
- (id) init
{
return [self initWithCapacity: 0];
}
// This is the designated initializer for this class
// xxx Should capacity include the '\0' terminator?
- initWithCapacity: (unsigned)capacity
- (id) initWithCharactersNoCopy: (unichar*)chars
length: (unsigned int)length
freeWhenDone: (BOOL)flag
{
[super init];
_count = 0;
_capacity = MAX(capacity, 2);
OBJC_MALLOC(_contents_chars, unichar, _capacity);
_contents_chars[0] = 0;
_free_contents = YES;
_count = length;
_capacity = length;
_contents_chars = chars;
_free_contents = flag;
return self;
}
// NB capacity does not include the '\0' terminator.
- initWithCapacity: (unsigned)capacity
{
unichar *tmp;
if (capacity < 2)
capacity = 2;
OBJC_MALLOC(tmp, unichar, capacity);
[self initWithCharactersNoCopy: tmp length: 0 freeWhenDone: YES];
_capacity = capacity;
return self;
}
@ -339,62 +365,60 @@ stringDecrementCountAndFillHoleAt(NSGMutableStringStruct *self,
withString: (NSString*)aString
{
int offset;
int i;
unsigned stringLength;
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)
stringLength = (aString == nil) ? 0 : [aString length];
offset = stringLength - aRange.length;
if (_count + stringLength > _capacity + aRange.length)
{
_capacity += [aString length] - aRange.length;
_capacity += stringLength - aRange.length;
if (_capacity < 2)
_capacity = 2;
OBJC_REALLOC(_contents_chars, unichar, _capacity);
}
offset = [aString length] - aRange.length;
#ifdef HAVE_MEMMOVE
if (offset != 0)
{
unichar *src = _contents_chars + aRange.location + aRange.length;
memmove(src + offset, src, (_count - aRange.location - aRange.length)*2);
}
#else
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];
int i;
for (i = _count - 1; i >= first; i--)
_contents_chars[i+offset] = _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];
int i;
for (i = aRange.location + aRange.length; i < _count; i++)
_contents_chars[i+offset] = _contents_chars[i];
}
(self->_count) += offset;
[aString getCharacters: &self->_contents_chars[aRange.location]];
#endif
[aString getCharacters: &_contents_chars[aRange.location]];
_count += offset;
}
// xxx Check this
- (void) insertString: (NSString*)aString atIndex:(unsigned)index
{
unsigned c = [aString length];
unichar * u;
OBJC_MALLOC(u, unichar, c+1);
if (_count + c >= _capacity)
{
_capacity = MAX(_capacity*2, _count+2*c);
OBJC_REALLOC(_contents_chars, unichar, _capacity);
}
stringIncrementCountAndMakeHoleAt((NSGMutableStringStruct*)self, index, c);
[aString getCharacters:u];
memcpy(_contents_chars + index,u, 2*c);
OBJC_FREE(u);
_contents_chars[_count] = 0;
}
- (void) setString: (NSString*)aString
{
int len = [aString length];
if (_capacity < len+1)
if (_capacity < len)
{
_capacity = len+1;
_capacity = len;
if (_capacity < 2)
_capacity = 2;
OBJC_REALLOC(_contents_chars, unichar, _capacity);
}
[aString getCharacters: _contents_chars];
_contents_chars[len] = 0;
_count = len;
}
@ -403,13 +427,14 @@ stringDecrementCountAndFillHoleAt(NSGMutableStringStruct *self,
/* xxx This method may be removed in future. */
- (void) setCString: (const char *)byteString length: (unsigned)length
{
if (_capacity < length+1)
if (_capacity < length)
{
_capacity = length+1;
_capacity = length;
if (_capacity < 2)
_capacity = 2;
OBJC_REALLOC(_contents_chars, unichar, _capacity);
}
strtoustr(_contents_chars, byteString, length);
_contents_chars[length] = 0;
_count = length;
}
@ -425,27 +450,6 @@ stringDecrementCountAndFillHoleAt(NSGMutableStringStruct *self,
return a;
}
/* Override NSString's designated initializer for Unicode Strings. */
- (id) initWithCharactersNoCopy: (unichar*)chars
length: (unsigned int)length
freeWhenDone: (BOOL)flag
{
[super init];
_count = length;
_capacity = length+1;
_contents_chars = chars;
_free_contents = flag;
return self;
}
- (id) init
{
unichar *u;
OBJC_MALLOC(u, unichar,1);
u[0]=(unichar)0;
return [self initWithCharactersNoCopy:u length:0 freeWhenDone: YES];
}
/* For IndexedCollecting Protocol and other GNU libobjects conformity. */
/* xxx This should be made to return void, but we need to change
@ -480,9 +484,6 @@ stringDecrementCountAndFillHoleAt(NSGMutableStringStruct *self,
count:_count
at:_contents_chars
withName:NULL];
_contents_chars[_count] = 0;
_capacity = cap;
_free_contents = YES;
return self;
}
@ -502,14 +503,15 @@ stringDecrementCountAndFillHoleAt(NSGMutableStringStruct *self,
{
CHECK_INDEX_RANGE_ERROR(index, _count+1);
// one for the next char, one for the '\0';
if (_count+1 >= _capacity)
if (_count >= _capacity)
{
_capacity *= 2;
_capacity = _count;
if (_capacity < 2)
_capacity = 2;
OBJC_REALLOC(_contents_chars, unichar, _capacity);
}
stringIncrementCountAndMakeHoleAt((NSGMutableStringStruct*)self, index, 1);
_contents_chars[index] = [newObject charValue];
_contents_chars[_count] = 0;
}
@ -517,7 +519,6 @@ stringDecrementCountAndFillHoleAt(NSGMutableStringStruct *self,
{
CHECK_INDEX_RANGE_ERROR(index, _count);
stringDecrementCountAndFillHoleAt((NSGMutableStringStruct*)self, index, 1);
_contents_chars[_count] = 0;
}
@end

View file

@ -21,7 +21,6 @@
Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#if 1
/* Deal with memchr: */
#if STDC_HEADERS || HAVE_STRING_H
#include <string.h>
@ -37,7 +36,6 @@
#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>
@ -65,7 +63,6 @@ types_get_number_of_arguments (const char *types)
return i - 1;
}
#if 1
static BOOL
rtn_type_is_oneway(const char * types)
{
@ -75,7 +72,6 @@ rtn_type_is_oneway(const char * types)
else
return NO;
}
#endif
@implementation NSMethodSignature
@ -109,11 +105,72 @@ rtn_type_is_oneway(const char * types)
- (NSArgumentInfo) argumentInfoAtIndex: (unsigned)index
{
/* 0 1 2 3 position
"C0@+8:+12C+19C+23" types
^ ^ ^ ^
(index == 0) tmptype->0, pretmptype->0
(index == 1) tmptype->1, pretmptype->0
(index == 2) tmptype->2, pretmptype->1
(index == 3) tmptype->3, pretmptype->2
and so on... */
const char *tmptype = types;
const char *pretmptype = NULL;
int offset, preoffset, size;
const char * result_type;
if (index >= numArgs)
[NSException raise:NSInvalidArgumentException
format:@"Index too high."];
[self notImplemented:_cmd];
return (NSArgumentInfo){0,0,""};
do
{
pretmptype = tmptype;
tmptype = objc_skip_argspec (tmptype);
}
while (index--);
result_type = tmptype;
if (pretmptype == types) // index == 0
{
tmptype = objc_skip_typespec(tmptype);
if (*tmptype == '+')
offset = atoi(tmptype + 1);
else
#if m68k
offset = (atoi(tmptype) - 8);
#else
offset = atoi(tmptype);
#endif // m68k
size = offset;
}
else // index != 0
{
tmptype = objc_skip_typespec(tmptype);
pretmptype = objc_skip_typespec(pretmptype);
if (*tmptype == '+')
offset = atoi(tmptype + 1);
else
#if m68k
offset = (atoi(tmptype) - 8);
#else
offset = atoi(tmptype);
#endif // m68k
if (*pretmptype == '+')
preoffset = atoi(pretmptype + 1);
else
#if m68k
preoffset = (atoi(pretmptype) - 8);
#else
preoffset = atoi(pretmptype);
size = offset - preoffset;
}
#endif // m68k
return (NSArgumentInfo){offset, size, result_type};
}
- (unsigned) frameLength
@ -123,12 +180,7 @@ rtn_type_is_oneway(const char * types)
- (BOOL) isOneway
{
#if 1
return rtn_type_is_oneway(returnTypes);
#else
[self notImplemented:_cmd];
return NO;
#endif
}
- (unsigned) methodReturnLength
@ -155,11 +207,9 @@ rtn_type_is_oneway(const char * types)
@end
#if 1
@implementation NSMethodSignature(GNU)
- (char*) methodType
{
return types;
}
@end
#endif

View file

@ -1056,7 +1056,6 @@ static int debug_run_loop = 0;
NSFreeMapTable (rfd_2_object);
NSFreeMapTable (wfd_2_object);
[NSNotificationQueue runLoopIdle];
[NSNotificationQueue runLoopASAP];
[self _checkPerformers];
_current_mode = saved_mode;
return;
@ -1086,6 +1085,7 @@ static int debug_run_loop = 0;
NSFreeMapTable (wfd_2_object);
[self _checkPerformers];
[NSNotificationQueue runLoopASAP];
_current_mode = saved_mode;
}

View file

@ -357,10 +357,13 @@ handle_printf_atsign (FILE *stream,
- (id) initWithString: (NSString*)string
{
unichar *s;
OBJC_MALLOC(s, unichar, [string length]+1);
unsigned length = [string length];
OBJC_MALLOC(s, unichar, length+1);
[string getCharacters:s];
s[[string length]] = (unichar)0;
return [self initWithCharactersNoCopy:s length:[string length] freeWhenDone:YES];
s[length] = (unichar)0;
return [self initWithCharactersNoCopy: s
length: length
freeWhenDone: YES];
}
- (id) initWithFormat: (NSString*)format,...
@ -608,15 +611,17 @@ handle_printf_atsign (FILE *stream,
- (NSString*) stringByAppendingString: (NSString*)aString
{
unsigned len = [self length];
unsigned otherLength = [aString length];
unichar *s;
NSString *tmp;
OBJC_MALLOC(s, unichar, len + [aString length]+1);
OBJC_MALLOC(s, unichar, len+otherLength+1);
[self getCharacters:s];
[aString getCharacters:s+len];
s[len + [aString length]]=(unichar) 0;
tmp = [NSString stringWithCharacters:s length: len + [aString length]];
OBJC_FREE(s);
return tmp;
s[len + otherLength]=(unichar) 0;
tmp = [[[self class] alloc] initWithCharactersNoCopy: s
length: len+otherLength
freeWhenDone: YES];
return [tmp autorelease];
}
// Dividing Strings into Substrings
@ -669,9 +674,10 @@ handle_printf_atsign (FILE *stream,
return @"";
OBJC_MALLOC(buf, unichar, aRange.length+1);
[self getCharacters:buf range:aRange];
ret = [[self class] stringWithCharacters:buf length:aRange.length];
OBJC_FREE(buf);
return ret;
ret = [[[self class] alloc] initWithCharactersNoCopy: buf
length: aRange.length
freeWhenDone: YES];
return [ret autorelease];
}
- (NSString*) substringWithRange: (NSRange)aRange
@ -1285,7 +1291,7 @@ handle_printf_atsign (FILE *stream,
options: (unsigned int)mask
{
return [self compare:aString options:mask
range:((NSRange){0, MAX([self length], [aString length])})];
range:((NSRange){0, [self length]})];
}
// xxx Should implement full POSIX.2 collate
@ -1293,8 +1299,12 @@ handle_printf_atsign (FILE *stream,
options: (unsigned int)mask
range: (NSRange)aRange
{
if (aRange.location > [self length])
[NSException raise: NSRangeException format:@"Invalid location."];
if (aRange.length > ([self length] - aRange.location))
[NSException raise: NSRangeException format:@"Invalid location+length."];
if(((![self length]) && (![aString length])))
if((([self length] - aRange.location == 0) && (![aString length])))
return NSOrderedSame;
if(![self length])
return NSOrderedAscending;
@ -1303,22 +1313,24 @@ handle_printf_atsign (FILE *stream,
if (mask & NSLiteralSearch)
{
int i, start, end, increment;
unichar *s1;
unichar *s2;
int i;
int s1len = aRange.length;
int s2len = [aString length];
int end;
unichar s1[s1len+1];
unichar s2[s2len+1];
OBJC_MALLOC(s1, unichar,[self length] +1);
OBJC_MALLOC(s2, unichar,[aString length] +1);
[self getCharacters:s1];
[self getCharacters:s1 range: aRange];
s1[s1len] = (unichar)0;
[aString getCharacters:s2];
start = aRange.location;
end = aRange.location + aRange.length;
increment = 1;
s2[s2len] = (unichar)0;
end = s1len+1;
if (s2len > s1len)
end = s2len+1;
if (mask & NSCaseInsensitiveSearch)
{
for (i = start; i < end; i += increment)
for (i = 0; i < end; i++)
{
int c1 = uni_tolower(s1[i]);
int c2 = uni_tolower(s2[i]);
@ -1328,14 +1340,12 @@ if (mask & NSLiteralSearch)
}
else
{
for (i = start; i < end; i += increment)
for (i = 0; i < end; i++)
{
if (s1[i] < s2[i]) return NSOrderedAscending;
if (s1[i] > s2[i]) return NSOrderedDescending;
}
}
OBJC_FREE(s1);
OBJC_FREE(s2);
return NSOrderedSame;
} /* if NSLiteralSearch */
else
@ -1368,9 +1378,10 @@ else
if(result != NSOrderedSame)
return result;
} /* while */
if(strCount<[aString length])
return NSOrderedDescending;
return NSOrderedSame;
} /* else */
return NSOrderedSame;
}
- (BOOL) hasPrefix: (NSString*)aString
@ -1389,6 +1400,8 @@ else
- (BOOL) isEqual: (id)anObject
{
if (anObject == self)
return YES;
if ([anObject isKindOf:[NSString class]])
return [self isEqualToString:anObject];
return NO;
@ -1440,7 +1453,6 @@ else
return YES;
else
return NO;
return YES;
}
- (unsigned int) hash
@ -1794,6 +1806,7 @@ else
OBJC_MALLOC(s, unichar,len +1);
[self getCharacters:s];
s[len] = (unichar)0;
while(count<len)
{
if([white characterIsMember:s[count]])
@ -1831,7 +1844,9 @@ else
for(count=0;count<len;count++)
s[count]=uni_tolower([self characterAtIndex:count]);
s[len] = (unichar)0;
return [NSString stringWithCharacters:s length:len];
return [[[[self class] alloc] initWithCharactersNoCopy: s
length: len
freeWhenDone: YES] autorelease];
}
- (NSString*) uppercaseString;
@ -1843,7 +1858,9 @@ else
for(count=0;count<len;count++)
s[count]=uni_toupper([self characterAtIndex:count]);
s[len] = (unichar)0;
return [NSString stringWithCharacters:s length:len];
return [[[[self class] alloc] initWithCharactersNoCopy: s
length: len
freeWhenDone: YES] autorelease];
}
// Storing the String
@ -2260,10 +2277,9 @@ else
NSString *homedir;
NSRange first_slash_range;
OBJC_MALLOC(s, unichar,[self length] +1);
[self getCharacters:s];
if (s[0] != 0x007E)
if ([self length] == 0)
return [[self copy] autorelease];
if ([self characterAtIndex: 0] != 0x007E)
return [[self copy] autorelease];
first_slash_range = [self rangeOfString: @"/"];
@ -2382,9 +2398,9 @@ else
}
*upoint = (unichar)0;
ret = [NSString stringWithCharacters:u
length: uslen(u)];
OBJC_FREE(u);
ret = [[[[self class] alloc] initWithCharactersNoCopy: u
length: uslen(u)
freeWhenDone: YES] autorelease];
return ret;
}
@ -2639,9 +2655,8 @@ else
length: (unsigned)length
{
id n;
n = [self stringWithCapacity:length];
[n setString: [NSString stringWithCharacters:characters length:length]];
return n;
n = [[self alloc] initWithCharacters: characters length: length];
return [n autorelease];
}
+ (NSString*) stringWithCString: (const char*)byteString

View file

@ -204,7 +204,8 @@ static NSMutableString *processName = nil;
[[NSDistributedLock lockWithPath: defaultsDatabaseLockName] retain];
}
if (processName == nil)
processName = [[[NSProcessInfo processInfo] processName] retain];
processName = [[[[NSProcessInfo processInfo] processName]
lastPathComponent] retain];
// Create an empty search list
searchList = [[NSMutableArray arrayWithCapacity:10] retain];

View file

@ -53,6 +53,12 @@
#include <fcntl.h>
#include <sys/socket.h>
#include <sys/file.h>
/* For IRIX machines, which don't define this */
#ifndef IPPORT_USERRESERVED
#define IPPORT_USERRESERVED 5000
#endif /* IPPORT_USERRESERVED */
/*
* Stuff for setting the sockets into non-blocking mode.
*/
@ -1399,6 +1405,7 @@ static NSMapTable *out_port_bag = NULL;
/* See if the _remote_in_port_address is already set */
if (p->_remote_in_port_address.sin_family)
{
#if 0
/* It is set; make sure no one is trying to change it---that
isn't allowed. */
if ((p->_remote_in_port_address.sin_port
@ -1406,6 +1413,18 @@ static NSMapTable *out_port_bag = NULL;
|| (p->_remote_in_port_address.sin_addr.s_addr
!= sockaddr->sin_addr.s_addr))
[self error:"Can't change reply port of an out port once set"];
#else
/* If someone is trying to change the port of this socket, the
old one must have died - invalidate it. */
if ((p->_remote_in_port_address.sin_port
!= sockaddr->sin_port)
|| (p->_remote_in_port_address.sin_addr.s_addr
!= sockaddr->sin_addr.s_addr))
{
[p invalidate];
p = nil;
}
#endif
}
else
{
@ -1418,8 +1437,11 @@ static NSMapTable *out_port_bag = NULL;
[[self description] cStringNoCopy]);
}
}
assert (p->is_valid);
return [p retain];
if (p)
{
assert (p->is_valid);
return [p retain];
}
}
/* There isn't already an in port for this sockaddr or sock,
@ -1475,8 +1497,8 @@ static NSMapTable *out_port_bag = NULL;
sizeof(p->_remote_in_port_address))
< 0)
{
close(p->_port_socket);
#if 0
close(p->_port_socket);
[NSException raise: NSInternalInconsistencyException
format: @"[TcpInPort newForSendingToSockaddr:...] connect(): %s",
strerror(errno)];
@ -1492,14 +1514,14 @@ static NSMapTable *out_port_bag = NULL;
if ((rval = fcntl(p->_port_socket, F_GETFL, 0)) >= 0) {
rval |= NBLK_OPT;
if (fcntl(p->_port_socket, F_SETFL, rval) < 0) {
close(p->_port_socket);
[p release];
[NSException raise: NSInternalInconsistencyException
format: @"[TcpInPort newForSendingToSockaddr:...] fcntl(SET): %s",
strerror(errno)];
}
}
else {
close(p->_port_socket);
[p release];
[NSException raise: NSInternalInconsistencyException
format: @"[TcpInPort newForSendingToSockaddr:...] fcntl(GET): %s",
strerror(errno)];

View file

@ -43,6 +43,11 @@
#include <sys/time.h>
#endif /* !__WIN32__ */
/* For IRIX machines, which don't define this */
#ifndef IPPORT_USERRESERVED
#define IPPORT_USERRESERVED 5000
#endif /* IPPORT_USERRESERVED */
@interface UdpInPort (Private)
@end
@interface UdpOutPort (Private)

View file

@ -83,9 +83,6 @@ getAddr(NSString* name, NSString* svc, NSString* pcl, struct sockaddr_in *sin)
const char* proto = "tcp";
struct servent* sp;
if (svc == nil)
svc = @"localhost";
if (pcl)
proto = [pcl cStringNoCopy];
@ -114,7 +111,12 @@ getAddr(NSString* name, NSString* svc, NSString* pcl, struct sockaddr_in *sin)
else
sin->sin_addr.s_addr = htonl(INADDR_ANY);
if ((sp = getservbyname([svc cStringNoCopy], proto)) == 0)
if (svc == nil)
{
sin->sin_port = 0;
return YES;
}
else if ((sp = getservbyname([svc cStringNoCopy], proto)) == 0)
{
const char* ptr = [svc cStringNoCopy];
int val = atoi(ptr);
@ -190,6 +192,12 @@ getAddr(NSString* name, NSString* svc, NSString* pcl, struct sockaddr_in *sin)
int net;
struct sockaddr_in sin;
if (s == nil)
{
[self dealloc];
NSLog(@"bad argument - service is nil");
return nil;
}
if (getAddr(a, s, p, &sin) == NO)
{
[self dealloc];
@ -276,7 +284,13 @@ getAddr(NSString* name, NSString* svc, NSString* pcl, struct sockaddr_in *sin)
return nil;
}
getsockname(net, (struct sockaddr*)&sin, &size);
if (getsockname(net, (struct sockaddr*)&sin, &size) < 0)
{
(void) close(net);
[self dealloc];
NSLog(@"unable to get socket name - %s", strerror(errno));
return nil;
}
self = [self initWithFileDescriptor:net closeOnDealloc:YES];
if (self)
@ -291,7 +305,7 @@ getAddr(NSString* name, NSString* svc, NSString* pcl, struct sockaddr_in *sin)
- (id)initForReadingAtPath:(NSString*)path
{
int d = open([path cString], O_RDONLY);
int d = open([path fileSystemRepresentation], O_RDONLY);
if (d < 0)
{
@ -309,7 +323,7 @@ getAddr(NSString* name, NSString* svc, NSString* pcl, struct sockaddr_in *sin)
- (id)initForWritingAtPath:(NSString*)path
{
int d = open([path cString], O_WRONLY);
int d = open([path fileSystemRepresentation], O_WRONLY);
if (d < 0)
{
@ -327,7 +341,7 @@ getAddr(NSString* name, NSString* svc, NSString* pcl, struct sockaddr_in *sin)
- (id)initForUpdatingAtPath:(NSString*)path
{
int d = open([path cString], O_RDWR);
int d = open([path fileSystemRepresentation], O_RDWR);
if (d < 0)
{

View file

@ -56,6 +56,7 @@ nsarchiver \
oldclient \
oldserver \
invocation \
invocation2 \
diningPhilosophers \
nsmaptable \
nshashtable \
@ -104,6 +105,7 @@ nsarchiver_OBJC_FILES = nsarchiver.m
oldclient_OBJC_FILES = oldclient.m
oldserver_OBJC_FILES = oldserver.m
invocation_OBJC_FILES = invocation.m
invocation2_OBJC_FILES = invocation2.m
diningPhilosophers_OBJC_FILES = diningPhilosophers.m
nsmaptable_OBJC_FILES = nsmaptable.m
nshashtable_OBJC_FILES = nshashtable.m
@ -128,7 +130,7 @@ create-abbrevs_OBJC_FILES = create-abbrevs.m
create-regions_OBJC_FILES = create-regions.m
# The bundles to be compiled
TEST_BUNDLE_NAME=LoadMe
BUNDLE_NAME=LoadMe
# The bundle Objective-C source files to be compiled
LoadMe_OBJC_FILES = LoadMe.m MyCategory.m SecondClass.m
@ -159,5 +161,6 @@ DIST_FILES = $(SRCS) $(HDRS) $(DYNAMIC_MFILES) $(DYNAMIC_HFILES) \
-include Makefile.preamble
include $(GNUSTEP_SYSTEM_ROOT)/Makefiles/test-tool.make
include $(GNUSTEP_SYSTEM_ROOT)/Makefiles/bundle.make
-include Makefile.postamble

View file

@ -461,6 +461,7 @@ property list which is set as the value of a default.\n\n");
domain = [NSMutableDictionary dictionaryWithCapacity:1];
}
[domain setObject: obj forKey: name];
[defs setPersistentDomain: domain forName: owner];
}
else {
domain = [name propertyList];
@ -470,7 +471,6 @@ property list which is set as the value of a default.\n\n");
exit(0);
}
}
[defs setPersistentDomain: domain forName: owner];
}
if ([defs synchronize] == NO) {

View file

@ -78,6 +78,11 @@
* the include file.
*/
/* For IRIX machines, which don't define this */
#ifndef IPPORT_USERRESERVED
#define IPPORT_USERRESERVED 5000
#endif /* IPPORT_USERRESERVED */
#define QUEBACKLOG (16) /* How many coonections to queue. */
#define MAX_IFACE (256) /* How many network interfaces. */
#define IASIZE (sizeof(struct in_addr))

View file

@ -1,7 +1,7 @@
# This file is included in various Makefile's to get version information.
# The gcc version required to compile the library.
GCC_VERSION=2.7.2
GCC_VERSION=2.8.0
# The version number of this release.
MAJOR_VERSION=0

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff