Merge 0.6.6 branch into main.

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@7187 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
Adam Fedor 2000-08-07 22:00:31 +00:00
parent a6a395487a
commit 7b0f402b1c
71 changed files with 4888 additions and 5571 deletions

View file

@ -1,7 +1,7 @@
Announcement Announcement
************ ************
The GNUstep Base Library, version 0.6.5, is now available. The GNUstep Base Library, version 0.6.6, is now available.
What is the GNUstep Base Library? What is the GNUstep Base Library?
================================= =================================
@ -22,8 +22,8 @@ portion of the OpenStep standard (the Foundation library).
Where can you get it? How can you compile it? Where can you get it? How can you compile it?
============================================== ==============================================
The gstepbase-0.6.5.tar.gz distribution file has been placed on The gstepbase-0.6.6.tar.gz distribution file has been placed on
`ftp.gnu.org' in `pub/gnu/gstep'. `ftp.gnustep.org' in `pub/gnustep/core'.
The library requires gcc 2.8.0 or higher. Significant sections of The library requires gcc 2.8.0 or higher. Significant sections of
the library do not work with the NeXT runtime, so we recommend using the library do not work with the NeXT runtime, so we recommend using
@ -40,44 +40,3 @@ two `quit'.
The most recent (not necessarily tested) snapshots of the library The most recent (not necessarily tested) snapshots of the library
will be placed on `alpha.gnu.org'. will be placed on `alpha.gnu.org'.
[ Most GNU software is packed using the GNU `gzip' compression program.
Source code is available on most sites distributing GNU software.
For information on how to order GNU software on tape, floppy or cd-rom, or
printed GNU manuals, check the file etc/ORDERS in the GNU Emacs distribution
or in GNUinfo/ORDERS on prep, or e-mail a request to: gnu@prep.ai.mit.edu
By ordering your GNU software from the FSF, you help us continue to
develop more free software. Media revenues are our primary source of
support. Donations to FSF are deductible on US tax returns.
The above software will soon be at these ftp sites as well.
Please try them before prep.ai.mit.edu as prep is very busy!
thanx -gnu@prep.ai.mit.edu
ASIA: ftp.cs.titech.ac.jp, utsun.s.u-tokyo.ac.jp:/ftpsync/prep,
cair.kaist.ac.kr:/pub/gnu, ftp.nectec.or.th:/pub/mirrors/gnu
AUSTRALIA: archie.au:/gnu (archie.oz or archie.oz.au for ACSnet)
AFRICA: ftp.sun.ac.za:/pub/gnu
MIDDLE-EAST: ftp.technion.ac.il:/pub/unsupported/gnu
EUROPE: irisa.irisa.fr:/pub/gnu, ftp.univ-lyon1.fr:pub/gnu,
ftp.mcc.ac.uk, unix.hensa.ac.uk:/pub/uunet/systems/gnu,
src.doc.ic.ac.uk:/gnu, ftp.ieunet.ie:pub/gnu, ftp.eunet.ch,
nic.switch.ch:/mirror/gnu, ftp.informatik.rwth-aachen.de:/pub/gnu,
ftp.informatik.tu-muenchen.de, ftp.win.tue.nl:/pub/gnu,
ftp.funet.fi:/pub/gnu, ftp.denet.dk, ftp.stacken.kth.se, isy.liu.se,
ftp.luth.se:/pub/unix/gnu, ftp.sunet.se:/pub/gnu, archive.eu.net
SOUTH AMERICA: ftp.unicamp.br:/pub/gnu
WESTERN CANADA: ftp.cs.ubc.ca:/mirror2/gnu
USA: wuarchive.wustl.edu:/systems/gnu, labrea.stanford.edu,
ftp.digex.net:/pub/gnu, ftp.kpc.com:/pub/mirror/gnu, f.ms.uky.edu:/pub3/gnu,
jaguar.utah.edu:/gnustuff, ftp.hawaii.edu:/mirrors/gnu,
vixen.cso.uiuc.edu:/gnu, mrcnext.cso.uiuc.edu:/pub/gnu,
ftp.cs.columbia.edu:/archives/gnu/prep, col.hp.com:/mirrors/gnu,
gatekeeper.dec.com:/pub/GNU, ftp.uu.net:/systems/gnu
]

17
BUGS
View file

@ -1,15 +1,16 @@
TODO TODO
**** ****
* NSZone memory allocation may not work correctly. If you encounter * Some people have reported NSZone memory allocation problems. If
a problem with NSZones, switch to using the default zone instead you encounter a problem with NSZones, switch to using the default
of creating one. zone instead of creating one. Or better yet, fix the problem and
submit a patch.
* Invocations (and by extension, Distributed Objects) work well only * Invocations (and by extension, Distributed Objects) have been well
on ix86 platforms. In particular, they don't work well on PPC and tested only on ix86 platforms. In particular, there are still
Sparc platforms. minor problems on PPC and Sparc platforms.
* Distributed Objects aren't thread safe. Don't use DO between * Distributed Objects is now thread safe, but it hasn't been well
threads in a multi-theaded app. tested.

189
ChangeLog
View file

@ -1,3 +1,7 @@
2000-08-07 Adam Fedor <fedor@gnu.org>
* Merge 0.6.6 branch into main.
2000-07-24 Richard Frith-Macdonald <rfm@gnu.org> 2000-07-24 Richard Frith-Macdonald <rfm@gnu.org>
* Tools/gdomap.c: Permit dumping of internal table of known peer * Tools/gdomap.c: Permit dumping of internal table of known peer
@ -27,6 +31,191 @@
* Source/GNUMakefile: * Source/GNUMakefile:
Add NSDecimal and NSDecimalNumber Add NSDecimal and NSDecimalNumber
2000-08-06 Adam Fedor <fedor@gnu.org>
* Version 0.6.6 released.
* Source/NSTimer.m (-compare:): Add return to quiet warning.
2000-08-04 Richard Frith-Macdonald <rfm@gnu.org>
* Source/NSPortNameServer.m: include netinet/in.h as needed on
FreeBSD to define values used in arpa/inet.h
2000-08-03 Richard Frith-Macdonald <rfm@gnu.org>
* Source/NSHost: ([_initWithHostEntry:key:]) workaround for buggy
host entries with missing h_aliases
2000-08-03 Richard Frith-Macdonald <rfm@gnu.org>
* NSTimeZones/NSTimeZones.tar: Updated to latest (July 31st) info
2000-08-02 Adam Fedor <fedor@gnu.org>
* Version: Update version number
* Documentation/announce.tmpl.texi: Update
* Documentation/readme.tmpl.texi: Likewise.
* Documentation/news.tmpl.texi: Likewise.
* Documentation/todo.tmpl.texi: Likewise.
* ANNOUNCE, BUGS, NEWS, README: Regenerate
2000-08-02 Adam Fedor <fedor@gnu.org>
* Testing/nsconnection_client.m: Rewrite, organize.
* Testing/nsconnection_server.m: Likewise.
2000-08-02 Richard Frith-Macdonald <rfm@gnu.org>
* Source/GSTcpPort.m: ([-removeHandle:]) corrected logic for releasing
self when port was created and retained by an incoming connection.
2000-08-01 Adam Fedor <fedor@gnu.org>
* Source/NSConcreteNumber.m (-compare:): Add return at end to quiet
compiler warning.
* Source/NSFileHandle.m: Change +fileHandle... methods to use
abstracts class's allocWithZone.
* Source/libgnustep-base.def: Update for new/removed classes.
2000-08-01 Richard Frith-Macdonald <rfm@gnu.org>
* Source/NSCalendarDate.m: Correct order of args to
lastDayOfGregorianMonth()
* Source/NSPortCoder.m: Handle classes encoded as objects specially.
* Source/NSArchiver.m: ditto.
* Source/NNSUnarchiver.m: ditto.
2000-07-31 Richard Frith-Macdonald <rfm@gnu.org>
* Source/Foundation/NSDebug.h: removed GS_IMPORT
* Source/Foundation/NSObjCRuntime.h: ditto
* Source/Foundation/GSConfig.h.in: ditto
2000-07-31 Richard Frith-Macdonald <rfm@gnu.org>
* Source/NSString.m: implement -cStringLength correctly in terms of
other methods of the abstract class, rather than making the subclass
do it. Cache [-characterAtIndex:] implementation for speed
throughout.
* Source/Unicode.m: Remove uslen() function - unused and unsafe.
Tidied code and optimised a little.
* Source/Foundation/Unicode.h: Remove uslen()
* Source/NSNumber.m: Check for nul argument to [-compare:]
* Source/NSDate.m: ditto
* Source/NSObject.m: ditto
* Source/NSConcreteNumber.m: ditto
* Source/NSTimer.m: ditto
2000-07-30 Richard Frith-Macdonald <rfm@gnu.org>
* Tools/nconnection.m: Trivial test of basic inter-thread use of
DO taken from example code in Applde documentation.
2000-07-29 Richard Frith-Macdonald <rfm@gnu.org>
Varous cluster classes - Bugfix to let allocWithZone work for
new concrete subclasses in the cluster.
* Source/NSPortCoder.m: Accept classes when asked to decode object.
* Source/NSUnarchiver.m: ditto.
2000-07-28 Richard Frith-Macdonald <rfm@gnu.org>
* Source/NSConnection.m: Don't create/use locks until the app
goes multi-threaded.
* Source/GSTcpPort.m: ditto.
2000-07-27 Richard Frith-Macdonald <rfm@gnu.org>
* Source/GSTcpPort.m: Fix stupid error in last bugfix
* Source/Foundation/GSConfig.h.in: define GS_SIZEOF_VOIDP
* configure.in: provide GS_SIZEOF_VOIDP
2000-07-27 Richard Frith-Macdonald <rfm@gnu.org>
* Source/NSThread.m: clarify code for getting current thread.
2000-07-27 Richard Frith-Macdonald <rfm@gnu.org>
* Source/Foundation/NSDebug.h: Bugfix reported by Frederic.De.Jaeger
to prevent incorrect processor handling of cases where logging format
string has no arguments.
2000-07-26 Richard Frith-Macdonald <rfm@gnu.org>
* Source/GSTcpPort.m: When given bad data on a socket, log a message
and invalidate the socket handle rather than raising an exception
and crashing. Should make system more robust in the face of attacks.
2000-07-24 Adam Fedor <fedor@gnu.org>
* Source/GSTcpPort.m
(-sendBeforeDate:msgid:components:from:reserved:]): Correct typo.
2000-07-24 Richard Frith-Macdonald <rfm@gnu.org>
Testing directory tidied to reflect removal of old classes.
* Source/NSTimer.m: Tidied a little.
2000-07-23 Richard Frith-Macdonald <rfm@gnu.org>
Old DO code removed along with associated libObjects classes that it
required - library slimmed down.
2000-07-21 Richard Frith-Macdonald <rfm@gnu.org>
* Source/NSGCString.m: implement methods to get numeric values.
* Source/NSGString.m: implement methods to get numeric values.
2000-07-19 Adam Fedor <fedor@gnu.org>
* Documentation/news.tmpl.texi: Update.
* Documentation/todo.tmpl.texi: Update.
2000-07-18 Richard Frith-Macdonald <rfm@gnu.org>
* Tools/Makefile.postamble: Improve warning messages for gdomap install
* Source/NSProcessInfo.m: Change __MINGW32__ to __MINGW__
* Source/GSTcpPort.m: improve encoding of local port for send over wire
2000-07-17 Adam Fedor <fedor@gnu.org>
* Source/NSZone.m: Remove duplicate function definitions (when
GS_WITH_GC is 1) already defined in NSZone.h.
2000-07-17 Richard Frith-Macdonald <rfm@gnu.org>
* Source/externs.m: Some evil casts to avoid compiler warnings about
assigning to constant variables when we initiallise them.
* Source/NSGSet.m: implemented [-anyObject] and [-allObjects]
* Source/NSSet.m: Fix to encode subclasses as abstract class.
Remove unused methods for set/get concrete class
* Source/NSCountedSet.m: ditto
* Source/NSNumber.m: Use explicitly signed types for portability -
particularly for systems (eg PPC) where char is not signed by default.
* Source/NSConcrete.m: ditto.
* Source/NSConcreteNumber.m: ditto.
* Source/Foundation/NSValue.h: ditto
* Source/Foundation/NSConcreteNumber.h: ditto
* Source/NSArray.m: Remove unused methods for set/get concrete class
* Source/NSDictionary.m: ditto.
* Source/NSString.m: ditto.
* Source/NSAttributedString.m: ditto.
* Source/NSHost.m: store names and addresses in sets for improved
performance (comparisons).
Encode host as an address other than loopback if possible.
Add code for a new '+localHost' method to try to get ALL
names/addresses of current host.
* Source/NSPortNameServer.m: Use new localHost method.
* Source/GSTcpPort.m: Use new localHost method.
2000-07-16 Adam Fedor <fedor@gnu.org>
* Tools/GNUmakefile (gdomap): Make as a C-tool rather than an
Objective-C program (no need for libobjc).
2000-07-07 Jonathan Gapen <jagapen@home.com> 2000-07-07 Jonathan Gapen <jagapen@home.com>
* Source/NSString.m: (-initWithFormat:), (-initWithFormat:locale:), * Source/NSString.m: (-initWithFormat:), (-initWithFormat:locale:),

View file

@ -54,45 +54,3 @@ with line one @samp{help} and line two @samp{quit}.
The most recent (not necessarily tested) snapshots of the library will The most recent (not necessarily tested) snapshots of the library will
be placed on @samp{@value{GNUSTEP-BASE-SNAP-FTP-MACHINE}}. be placed on @samp{@value{GNUSTEP-BASE-SNAP-FTP-MACHINE}}.
@format
[ Most GNU software is packed using the GNU `gzip' compression program.
Source code is available on most sites distributing GNU software.
For information on how to order GNU software on tape, floppy or cd-rom, or
printed GNU manuals, check the file etc/ORDERS in the GNU Emacs distribution
or in GNUinfo/ORDERS on prep, or e-mail a request to: gnu@@prep.ai.mit.edu
By ordering your GNU software from the FSF, you help us continue to
develop more free software. Media revenues are our primary source of
support. Donations to FSF are deductible on US tax returns.
The above software will soon be at these ftp sites as well.
Please try them before prep.ai.mit.edu as prep is very busy!
thanx -gnu@@prep.ai.mit.edu
ASIA: ftp.cs.titech.ac.jp, utsun.s.u-tokyo.ac.jp:/ftpsync/prep,
cair.kaist.ac.kr:/pub/gnu, ftp.nectec.or.th:/pub/mirrors/gnu
AUSTRALIA: archie.au:/gnu (archie.oz or archie.oz.au for ACSnet)
AFRICA: ftp.sun.ac.za:/pub/gnu
MIDDLE-EAST: ftp.technion.ac.il:/pub/unsupported/gnu
EUROPE: irisa.irisa.fr:/pub/gnu, ftp.univ-lyon1.fr:pub/gnu,
ftp.mcc.ac.uk, unix.hensa.ac.uk:/pub/uunet/systems/gnu,
src.doc.ic.ac.uk:/gnu, ftp.ieunet.ie:pub/gnu, ftp.eunet.ch,
nic.switch.ch:/mirror/gnu, ftp.informatik.rwth-aachen.de:/pub/gnu,
ftp.informatik.tu-muenchen.de, ftp.win.tue.nl:/pub/gnu,
ftp.funet.fi:/pub/gnu, ftp.denet.dk, ftp.stacken.kth.se, isy.liu.se,
ftp.luth.se:/pub/unix/gnu, ftp.sunet.se:/pub/gnu, archive.eu.net
SOUTH AMERICA: ftp.unicamp.br:/pub/gnu
WESTERN CANADA: ftp.cs.ubc.ca:/mirror2/gnu
USA: wuarchive.wustl.edu:/systems/gnu, labrea.stanford.edu,
ftp.digex.net:/pub/gnu, ftp.kpc.com:/pub/mirror/gnu, f.ms.uky.edu:/pub3/gnu,
jaguar.utah.edu:/gnustuff, ftp.hawaii.edu:/mirrors/gnu,
vixen.cso.uiuc.edu:/gnu, mrcnext.cso.uiuc.edu:/pub/gnu,
ftp.cs.columbia.edu:/archives/gnu/prep, col.hp.com:/mirrors/gnu,
gatekeeper.dec.com:/pub/GNU, ftp.uu.net:/systems/gnu
]
@end format

View file

@ -62,6 +62,7 @@ into another language, under the above conditions for modified versions.
* Coding Style:: * Coding Style::
* Memory Management:: * Memory Management::
* Error Handling:: * Error Handling::
* Contributing::
@end menu @end menu
@c ****************************************************************** @c ******************************************************************
@ -248,7 +249,7 @@ of code is involved
@end example @end example
@c ****************************************************************** @c ******************************************************************
@node Memory Management, Error Handling , Coding Style, Top @node Memory Management, Error Handling, Coding Style, Top
@section Memory Management @section Memory Management
In anticipation of the day when we can make the use of a Garbage Collector In anticipation of the day when we can make the use of a Garbage Collector
@ -281,7 +282,7 @@ in use.
@end itemize @end itemize
@c ****************************************************************** @c ******************************************************************
@node Error Handling, , Memory Management, Top @node Error Handling, Contributing, Memory Management, Top
@section Error Handling @section Error Handling
Initialization methods (e.g. -init) should, upon failure to Initialization methods (e.g. -init) should, upon failure to
@ -320,4 +321,40 @@ Java has the "finally" block which is specifically designed for this task. A
similar mechanism exists in libFoundation with the CLEANUP and FINALLY similar mechanism exists in libFoundation with the CLEANUP and FINALLY
blocks. blocks.
@node Contributing, , Error Handling, Top
@section Contributing
Contributing code is not difficult. Here are
some general guidelines:
@itemize @bullet
@item
FSF must maintain the right to accept or reject potential contributions.
Generally, the only reasons for rejecting contributions are cases where
they duplicate existing or nearly-released code, contain unremovable
specific machine dependencies, or are somehow incompatible with the
rest of the library.
@item
Acceptance of contributions means that the code is accepted for adaptation
into libgnustep-base. FSF must reserve the right to make various editorial changes
in code. Very often, this merely entails formatting, maintenance of various
conventions, etc. Contributors are always given authorship credit and shown
the final version for approval.
@item
Contributors must assign their copyright to FSF via a form sent out
upon acceptance. Assigning copyright to FSF ensures that the code
may be freely distributed.
@item
Assistance in providing documentation, test files, and debugging
support is strongly encouraged.
@end itemize
Extensions, comments, and suggested modifications of existing libgnustep-base
features are also very welcome.
@bye @bye

View file

@ -98,20 +98,21 @@ and the MacOS-X Foundation implementation.
* Tools:: * Tools::
* Installation:: * Installation::
* Implementation:: * Implementation::
* Coding Standards::
* Contributing::
* Concept Index:: * Concept Index::
@end menu @end menu
@node Overview, Configuration, Top, Top @node Overview, Configuration, Top, Top
@chapter Overview @chapter Overview
The GNUstep Base Library (gstep-base) requires the GNUstep Makefile *The GNUstep Base Library (gstep-base) requires the GNUstep Makefile
Package (gstep-make) to compile. A recent GCC compiler may also be Package (gstep-make) to compile. A recent GCC compiler may also be
needed as well as other libraries. You should consult the needed as well as other libraries. You should consult the
@file{GNUstep-HOWTO} document that comes with the GNUstep Core Libraries @file{GNUstep-HOWTO} document that comes with the GNUstep Core Libraries
package (gstep-core) or information on supported machines on the web package (gstep-core) or information on supported machines on the web
site @url{http://www.gnustep.org/information} site @url{http://www.gnustep.org/information}.
Documentation for individual classes is included in gsdoc (and html) format
in the gsdoc directory.
@node Configuration, Classes, Overview, Top @node Configuration, Classes, Overview, Top
@chapter Configuration @chapter Configuration
@ -124,15 +125,21 @@ for a list of these. It is not likely that you will need to use the
the directory specified by the @code{GNUSTEP_SYSTEM_ROOT} environment the directory specified by the @code{GNUSTEP_SYSTEM_ROOT} environment
variable (specified when you installed gstep-make). variable (specified when you installed gstep-make).
The only feature you may want to use is the @code{--enable-fake-main} The only feature you may want to use is the
option. Normally, the configure script will determine if a program can @code{--enable-pass-arguments} or the @code{--enable-fake-main}
read process information directly from the system (for use by the class option(s). Normally, the configure script will determine if a program
NSProcessInfo) and enable or disable the fake-main hack automatically, can read process information directly from the system (for use by the
but if you find that configure is not doing this correctly, you can class NSProcessInfo) and enable or disable the fake-main hack
force the fake-main hack to be used, which will always work. Note that automatically, but if you find that configure is not doing this
if the fake-main hack is enabled, you need to include the header file correctly, you can force the fake-main hack to be used, which will
GSConfig.h in you main program -- this is done by default if you include always work. Note that if the fake-main hack is enabled, you need to
NSObject.h or Foundation.h. include the header file GSConfig.h in you main program -- this is done
by default if you include NSObject.h or Foundation.h. If you want to
avoid the whole idea of the fake-main hack, you can use the
pass-arguments option. In this case you will be forced to call the
NSProcessInfo initializeWithArguments method to pass the program
arguments to NSProcessInfo (This would be done automatically if you use
the NSApplicationMain function in a gui application).
Most other important configuration options are already set when you Most other important configuration options are already set when you
configure the gstep-make package. configure the gstep-make package.
@ -148,7 +155,7 @@ configure the gstep-make package.
Type @code{make install} to install the libraries and programs Type @code{make install} to install the libraries and programs
@node Implementation, Coding Standards, Installation, Top @node Implementation, Concept Index, Installation, Top
@chapter Implementation Details @chapter Implementation Details
@menu @menu
@ -166,12 +173,6 @@ The OpenStep standard defines an reference-count based memory management scheme
using the Boehm conservative garbage collecting library, though this is using the Boehm conservative garbage collecting library, though this is
currently (October 1999) in a pre-alpha state. currently (October 1999) in a pre-alpha state.
@menu
* Memory Allocation::
* Reference Counting::
* Garbage Collection::
@end menu
@node Memory Allocation, Reference Counting, Memory Management, Implementation @node Memory Allocation, Reference Counting, Memory Management, Implementation
@section Memory Allocation @section Memory Allocation
@ -269,94 +270,9 @@ implement, and also that time zone names may vary wildly between OSes
(this could be a big problem when archiving is used between different (this could be a big problem when archiving is used between different
systems). systems).
@c ******************************************************************
@node Coding Standards, Contributing, Implementation, Top
@chapter Coding Standards
This chapter explains the official coding standards which developers
for GNUstep base should follow. Note that these standards are in addition
to GNU coding standards, not a replacement of them.
@menu @node Concept Index, , Implementation, Top
* Error Handling::
@end menu
@node Error Handling, , Coding Standards, Coding Standards
@section Error Handling
Initialization methods (e.g. -init) should, upon failure to
initialize the class, deallocate itself and return nil. This may mean
in certain cases, that it should catch exceptions, since the calling
method will be expecting a nil object rather than an exception on
failure. However, init methods should endeavor to provide some
information, via NSLog, on the failure.
All other methods should cause an exception on failure*, unless
returning nil is a valid response (e.g. [dictionary
objectForKey: nil]) or if documented otherwise.
Failure here is a relative term. I'd interpret failure to occur when
either system resources have been exceeded, an operation was performed
on invalid data, or a required precondition was not met.
On the other hand, passing a nil object as a parameter (as in
[(NSMutableData *)data appendData: nil]), or other "unusual"
requests should succeed in a reasonable manner (or return nil, if
appropriate) and/or reasonable default values could be used.
If an error is recoverable or it does not damage the internal state of
an object, it's ok not to raise an error. At the very least, though, a message
should be printed through NSLog.
Special care should be taken in methods that create resources like
allocate memory or open files or obtain general system resources (locks,
shared memory etc.) from the kernel. If an exception is generated
between the allocation of the resource and its disposal, the resource
will be simply lost without any possibility to release. The code should
check for exceptions and if something bad occurs it should release all
the allocated resources and reraise the exception.
Unfortunately there is no nice way to do this automatically in OpenStep.
Java has the "finally" block which is specifically designed for this task. A
similar mechanism exists in libFoundation with the CLEANUP and FINALLY
blocks.
@node Contributing, Concept Index, Coding Standards, Top
@chapter Contributing
Contributing code is not difficult. Here are
some general guidelines:
@itemize @bullet
@item
FSF must maintain the right to accept or reject potential contributions.
Generally, the only reasons for rejecting contributions are cases where
they duplicate existing or nearly-released code, contain unremovable
specific machine dependencies, or are somehow incompatible with the
rest of the library.
@item
Acceptance of contributions means that the code is accepted for adaptation
into libgnustep-base. FSF must reserve the right to make various editorial changes
in code. Very often, this merely entails formatting, maintenance of various
conventions, etc. Contributors are always given authorship credit and shown
the final version for approval.
@item
Contributors must assign their copyright to FSF via a form sent out
upon acceptance. Assigning copyright to FSF ensures that the code
may be freely distributed.
@item
Assistance in providing documentation, test files, and debugging
support is strongly encouraged.
@end itemize
Extensions, comments, and suggested modifications of existing libgnustep-base
features are also very welcome.
@node Concept Index, , Contributing, Top
@unnumbered Concept Index @unnumbered Concept Index
@printindex cp @printindex cp

View file

@ -7,6 +7,22 @@
The currently released version of the library is The currently released version of the library is
@samp{@value{GNUSTEP-BASE-VERSION}}. @samp{@value{GNUSTEP-BASE-VERSION}}.
@section Noteworthy changes in version @samp{0.6.6}
@itemize @bullet
@item Lots of new documentation.
@item Completely rewritten Distributed Object to be much more compatible with
the MacOS-X API (and incidentally, closer to the original OpenStep standard).
@item Support to compile library as a DLL on Windows (still cygwin only).
@item Removed lots of obsolete classes.
@item New tools for handling property lists.
@item More optimization of classes.
@end itemize
@c ====================================================================
@c Keep the next line just below the list of changes in most recent version.
@ifclear ANNOUNCE-ONLY
@section Noteworthy changes in version @samp{0.6.5} @section Noteworthy changes in version @samp{0.6.5}
@itemize @bullet @itemize @bullet
@ -228,10 +244,6 @@ NSAllocateMemoryPages, NSDeallocateMemoryPages, NSCopyMemoryPages.
@end itemize @end itemize
@c ====================================================================
@c Keep the next line just below the list of changes in most recent version.
@ifclear ANNOUNCE-ONLY
@section Noteworthy changes since version @samp{0.1.14} @section Noteworthy changes since version @samp{0.1.14}
@itemize @bullet @itemize @bullet

View file

@ -10,15 +10,16 @@
@itemize @bullet @itemize @bullet
@item NSZone memory allocation may not work correctly. If you @item Some people have reported NSZone memory allocation problems.
encounter a problem with NSZones, switch to using the If you encounter a problem with NSZones, switch to using the
default zone instead of creating one. default zone instead of creating one. Or better yet, fix the problem and
submit a patch.
@item Invocations (and by extension, Distributed Objects) work well only @item Invocations (and by extension, Distributed Objects) have been well tested only
on ix86 platforms. In particular, they don't work well on PPC and Sparc on ix86 platforms. In particular, there are still minor problems on PPC and Sparc
platforms. platforms.
@item Distributed Objects aren't thread safe. Don't use DO @item Distributed Objects is now thread safe, but it hasn't been well
between threads in a multi-theaded app. tested.
@end itemize @end itemize

View file

@ -77,7 +77,7 @@
*/ */
#define main gnustep_base_user_main #define main gnustep_base_user_main
GS_IMPORT int gnustep_base_user_main (/* int argc, char *argv[] */); extern int gnustep_base_user_main (/* int argc, char *argv[] */);
#endif /* GS_FAKE_MAIN */ #endif /* GS_FAKE_MAIN */
@ -97,6 +97,7 @@ GS_IMPORT int gnustep_base_user_main (/* int argc, char *argv[] */);
#define GS_SIZEOF_LONG_LONG @ac_cv_sizeof_long_long@ #define GS_SIZEOF_LONG_LONG @ac_cv_sizeof_long_long@
#define GS_SIZEOF_FLOAT @ac_cv_sizeof_float@ #define GS_SIZEOF_FLOAT @ac_cv_sizeof_float@
#define GS_SIZEOF_DOUBLE @ac_cv_sizeof_double@ #define GS_SIZEOF_DOUBLE @ac_cv_sizeof_double@
#define GS_SIZEOF_VOIDP @ac_cv_sizeof_voidp@
/* /*
* Size information to be places in bits 5 and 6 of type encoding bytes * Size information to be places in bits 5 and 6 of type encoding bytes

View file

@ -135,4 +135,26 @@
@end @end
@interface NSArray (GNUstep)
/*
* Extension methods for working with sorted arrays - use a binary chop
* to determine the insertion location for an nobject. If equal objects
* already exist in the array, they will be located immediately before
* the insertion position.
*
* The comparator function takes two items as arguments, the first is the
* item to be added, the second is the item already in the array.
* The function should return NSOrderedAscending if the item to be
* added is 'less than' the item in the array, NSOrderedDescending
* if it is greater, and NSOrderedSame if it is equal.
*
* The selector version works the same - returning NSOrderedAscending if
* the reciever is 'less than' the item in the array.
*/
- (unsigned) insertionPosition: (id)item
usingFunction: (NSComparisonResult (*)(id, id))sorter;
- (unsigned) insertionPosition: (id)item
usingSelector: (SEL)comp;
@end
#endif /* __NSArray_h_GNUSTEP_BASE_INCLUDE */ #endif /* __NSArray_h_GNUSTEP_BASE_INCLUDE */

View file

@ -26,79 +26,79 @@
@interface NSBoolNumber : NSNumber @interface NSBoolNumber : NSNumber
{ {
BOOL data; BOOL data;
} }
@end @end
@interface NSUCharNumber : NSNumber @interface NSUCharNumber : NSNumber
{ {
unsigned char data; unsigned char data;
} }
@end @end
@interface NSCharNumber : NSNumber @interface NSCharNumber : NSNumber
{ {
char data; signed char data;
} }
@end @end
@interface NSUShortNumber : NSNumber @interface NSUShortNumber : NSNumber
{ {
unsigned short data; unsigned short data;
} }
@end @end
@interface NSShortNumber : NSNumber @interface NSShortNumber : NSNumber
{ {
short data; signed short data;
} }
@end @end
@interface NSUIntNumber : NSNumber @interface NSUIntNumber : NSNumber
{ {
unsigned int data; unsigned int data;
} }
@end @end
@interface NSIntNumber : NSNumber @interface NSIntNumber : NSNumber
{ {
int data; signed int data;
} }
@end @end
@interface NSULongNumber : NSNumber @interface NSULongNumber : NSNumber
{ {
unsigned long data; unsigned long data;
} }
@end @end
@interface NSLongNumber : NSNumber @interface NSLongNumber : NSNumber
{ {
long data; signed long data;
} }
@end @end
@interface NSULongLongNumber : NSNumber @interface NSULongLongNumber : NSNumber
{ {
unsigned long long data; unsigned long long data;
} }
@end @end
@interface NSLongLongNumber : NSNumber @interface NSLongLongNumber : NSNumber
{ {
long long data; signed long long data;
} }
@end @end
@interface NSFloatNumber : NSNumber @interface NSFloatNumber : NSNumber
{ {
float data; float data;
} }
@end @end
@interface NSDoubleNumber : NSNumber @interface NSDoubleNumber : NSNumber
{ {
double data; double data;
} }
@end @end

View file

@ -1,4 +1,3 @@
#if GS_NEW_DO
/* Interface for GNU Objective-C version of NSConnection /* Interface for GNU Objective-C version of NSConnection
Copyright (C) 1997,2000 Free Software Foundation, Inc. Copyright (C) 1997,2000 Free Software Foundation, Inc.
@ -241,318 +240,3 @@ GS_EXPORT NSString *NSConnectionDidInitializeNotification; /* OPENSTEP */
GS_EXPORT NSString *NSFailedAuthenticationException; /* MacOS-X */ GS_EXPORT NSString *NSFailedAuthenticationException; /* MacOS-X */
#endif /* __NSConnection_h_GNUSTEP_BASE_INCLUDE */ #endif /* __NSConnection_h_GNUSTEP_BASE_INCLUDE */
#else
/* Interface for GNU Objective-C version of NSConnection
Copyright (C) 1997 Free Software Foundation, Inc.
Original by: Andrew Kachites McCallum <mccallum@gnu.ai.mit.edu>
Version for OPENSTEP by: Richard Frith-Macdonald <richard@brainstorm.co.uk>
Created: August 1997
This file is part of the GNUstep Base Library.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with this library; if not, write to the Free
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111 USA.
*/
#ifndef __NSConnection_h_GNUSTEP_BASE_INCLUDE
#define __NSConnection_h_GNUSTEP_BASE_INCLUDE
#include <Foundation/NSObject.h>
#include <Foundation/NSDictionary.h>
#include <Foundation/NSString.h>
#include <Foundation/NSTimer.h>
#include <Foundation/NSRunLoop.h>
#include <Foundation/NSMapTable.h>
@class NSDistantObject;
@class NSPort;
@class NSData;
/*
* Keys for the NSDictionary returned by [NSConnection -statistics]
*/
/* These in OPENSTEP 4.2 */
GS_EXPORT NSString *NSConnectionRepliesReceived;
GS_EXPORT NSString *NSConnectionRepliesSent;
GS_EXPORT NSString *NSConnectionRequestsReceived;
GS_EXPORT NSString *NSConnectionRequestsSent;
/* These Are GNUstep extras */
GS_EXPORT NSString *NSConnectionLocalCount; /* Objects sent out */
GS_EXPORT NSString *NSConnectionProxyCount; /* Objects received */
/*
* NSConnection class interface.
*
* A few methods are in the specification but not yet implemented.
*/
@interface NSConnection : NSObject
{
@private
BOOL is_valid;
BOOL independent_queueing;
unsigned request_depth;
NSPort *receive_port;
NSPort *send_port;
unsigned message_count;
unsigned req_out_count;
unsigned req_in_count;
unsigned rep_out_count;
unsigned rep_in_count;
NSMapTable *local_objects;
NSMapTable *local_targets;
NSMapTable *remote_proxies;
NSTimeInterval reply_timeout;
NSTimeInterval request_timeout;
Class receive_port_class;
Class send_port_class;
Class encoding_class;
id delegate;
NSMutableArray *request_modes;
}
+ (NSArray*) allConnections;
+ (NSConnection*) connectionWithRegisteredName: (NSString*)n
host: (NSString*)h;
+ (id)currentConversation;
+ (NSConnection*) defaultConnection;
+ (NSDistantObject*) rootProxyForConnectionWithRegisteredName: (NSString*)name
host: (NSString*)host;
- (void) addRequestMode: (NSString*)mode;
- (void) addRunLoop: (NSRunLoop *)runloop;
- (id) delegate;
- (void) enableMultipleThreads;
- (BOOL) multipleThreadsEnabled;
- (BOOL) independentConversationQueueing;
- (void) invalidate;
- (BOOL) isValid;
- (BOOL) registerName: (NSString*)name;
- (NSArray *) remoteObjects;
- (void) removeRequestMode: (NSString*)mode;
- (void) removeRunLoop: (NSRunLoop *)runloop;
- (NSTimeInterval) replyTimeout;
- (NSArray*) requestModes;
- (NSTimeInterval) requestTimeout;
- (id) rootObject;
- (NSDistantObject*) rootProxy;
- (void) setDelegate: anObj;
- (void) setIndependentConversationQueueing: (BOOL)flag;
- (void) setReplyTimeout: (NSTimeInterval)seconds;
- (void) setRequestMode: (NSString*)mode;
- (void) setRequestTimeout: (NSTimeInterval)seconds;
- (void) setRootObject: anObj;
- (NSDictionary*) statistics;
@end
/*
* This catagory contains methods which were not in the original
* OpenStep specification, but which are in OPENSTEP.
* Some methods are not yet implemented.
*/
@interface NSConnection (OPENSTEP)
+ (NSConnection*) connectionWithReceivePort: (NSPort*)r
sendPort: (NSPort*)s;
- initWithReceivePort: (NSPort*)r
sendPort: (NSPort*)s;
- (NSPort*) receivePort;
- (void) runInNewThread;
- (NSPort*) sendPort;
@end
/*
* This catagory contains legacy methods from the original GNU 'Connection'
* class, and useful extensions to NSConnection.
*/
@interface NSConnection (GNUstepExtensions) <GCFinalization>
- (void) gcFinalize;
/* Setting and getting class configuration */
+ (Class) defaultReceivePortClass;
+ (void) setDefaultReceivePortClass: (Class) aPortClass;
+ (Class) defaultSendPortClass;
+ (void) setDefaultSendPortClass: (Class) aPortClass;
+ (Class) defaultProxyClass;
+ (void) setDefaultProxyClass: (Class) aClass;
+ (int) defaultOutTimeout;
+ (void) setDefaultOutTimeout: (int)to;
+ (int) defaultInTimeout;
+ (void) setDefaultInTimeout: (int)to;
/* Querying the state of all the connections */
+ (int) messagesReceived;
+ (unsigned) connectionsCount;
+ (unsigned) connectionsCountWithInPort: (NSPort*)aPort;
/* Registering your server object on the network.
These methods create a new connection object that must be "run" in order
to start handling requests from clients.
These method names may change when we get the capability to register
ports with names after the ports have been created. */
/* I want the second method name to clearly indicate that we're not
connecting to a pre-existing registration name, we're registering a
new name, and this method will fail if that name has already been
registered. This is why I don't like "newWithRegisteredName:" ---
it's unclear if we're connecting to another NSConnection that already
registered with that name. */
+ (NSConnection*) newWithRootObject: anObj;
+ (NSConnection*) newRegisteringAtName: (NSString*)n
withRootObject: anObj;
+ (NSConnection*) newRegisteringAtName: (NSString*)n
atPort: (int)portn
withRootObject: anObj;
+ (NSConnection*) connectionByOutPort: (NSPort*)aPort;
/* Get a proxy to a remote server object.
A new connection is created if necessary. */
+ (NSDistantObject*) rootProxyAtName: (NSString*)name onHost: (NSString*)host;
+ (NSDistantObject*) rootProxyAtName: (NSString*)name;
+ (NSDistantObject*) rootProxyAtPort: (NSPort*)anOutPort;
+ (NSDistantObject*) rootProxyAtPort: (NSPort*)anOutPort withInPort: (NSPort*)anInPort;
/* This is the designated initializer for the NSConnection class.
You don't need to call it yourself. */
+ (NSConnection*) newForInPort: (NSPort*)anInPort outPort: (NSPort*)anOutPort
ancestorConnection: (NSConnection*)ancestor;
/* Make a connection object start listening for incoming requests. After
after DATE. */
- (void) runConnectionUntilDate: date;
/* Same as above, but never time out. */
- (void) runConnection;
/* When you get an invalidation notification from a connection, use
this method in order to find out if any of the proxy objects you're
using are going away. */
- (id) proxies;
/* For getting the root object of a connection or port */
+ rootObjectForInPort: (NSPort*)aPort;
/* Used for setting the root object of a connection that we
created without one, or changing the root object of a connection
that already has one. */
+ (void) setRootObject: anObj forInPort: (NSPort*)aPort;
/* Querying and setting some instance variables */
- (Class) receivePortClass;
- (Class) sendPortClass;
- (void) setReceivePortClass: (Class)aPortClass;
- (void) setSendPortClass: (Class)aPortClass;
- (Class) proxyClass;
- (Class) encodingClass;
- (Class) decodingClass;
/* Only subclassers and power-users need worry about these */
- (void) addProxy: (NSDistantObject*)aProxy;
- (id) includesProxyForTarget: (gsu32)target;
- (void) removeProxy: (NSDistantObject*)aProxy;
// It seems to be a non pure-OPENSTEP definition...
//
// new def :
- (NSArray*)localObjects;
- (void) addLocalObject: anObj;
- (id) includesLocalObject: anObj;
- (void) removeLocalObject: anObj;
- (retval_t) forwardForProxy: (NSDistantObject*)object
selector: (SEL)sel
argFrame: (arglist_t)frame;
- (const char *) typeForSelector: (SEL)sel remoteTarget: (unsigned)target;
@end
GS_EXPORT NSString *ConnectionBecameInvalidNotification;
@interface Object (NSConnectionDelegate)
- (BOOL) connection: (NSConnection*)parent
shouldMakeNewConnection: (NSConnection*)newConnection;
/*
* This method may be used to ask a delegates permission to create
* a new connection from the old one.
* This method should be implemented in preference to the
* [makeNewConnection:sender:] which is obsolete.
*/
- (BOOL) makeNewConnection: (NSConnection*)newConnection
sender: (NSConnection*)parent;
/*
* This is the old way of doing the same thing as
* [connection:shouldMakeNewConnection:]
* It is obsolete - don't use it.
*/
- (NSConnection*) connection: ancestorConn didConnect: newConn;
/*
* If the delegate responds to this method, it will be used to ask the
* delegate's permission to establish a new connection from the old one.
* Often this is used so that the delegate can register for invalidation
* notification on new child connections.
* This is a GNUstep extension
* Normally return newConn.
*/
@end
@interface Object (NSPortCoder)
- (Class) classForPortCoder;
/*
* Must return the class that will be created on the remote side
* of the connection. If the class to be created is not the same
* as that of the object returned by replacementObjectForPortCoder:
* then the class must be capable of recognising the object it
* actually gets in its initWithCoder: method.
* The default operation is to return NSDistantObject unless the
* object is being sent bycopy, in which case the objects actual
* class is returned. To force bycopy operation the object should
* return its own class.
*/
- (id) replacementObjectForPortCoder: (NSPortCoder*)aCoder;
/*
* This message is sent to an object about to be encoded for sending
* over the wire. The default action is to return an NSDistantObject
* which is a local proxy for the object unless the object is being
* sent bycopy, in which case the actual object is returned.
* To force bycopy, an object should return itsself.
*/
- (BOOL)authenticateComponents: (NSArray *)components
withData: (NSData *)authenticationData;
- (NSData *)authenticationDataForComponents: (NSArray *)components;
@end
#define CONNECTION_DEFAULT_TIMEOUT 15.0 /* in seconds */
/*
* NSRunLoop mode, NSNotification name and NSException strings.
*/
GS_EXPORT NSString *NSConnectionReplyMode;
GS_EXPORT NSString *NSConnectionDidDieNotification;
GS_EXPORT NSString *NSConnectionDidInitializeNotification; /* OPENSTEP */
/*
* For compatibility with old GNU DO code -
*/
#define RunLoopConnectionReplyMode NSConnectionReplyMode
#define ConnectionBecameInvalidNotification NSConnectionDidDieNotification
#define ConnectionWasCreatedNotification NSConnectionDidInitializeNotification
#endif /* __NSConnection_h_GNUSTEP_BASE_INCLUDE */
#endif

View file

@ -160,6 +160,7 @@
#define _GSC_CHARPTR 0x14 #define _GSC_CHARPTR 0x14
#define _GSC_ARY_B 0x15 #define _GSC_ARY_B 0x15
#define _GSC_STRUCT_B 0x16 #define _GSC_STRUCT_B 0x16
#define _GSC_CID 0x17 /* Class encoded as id */
@interface NSData (GNUstepExtensions) @interface NSData (GNUstepExtensions)
+ (id) dataWithShmID: (int)anID length: (unsigned) length; + (id) dataWithShmID: (int)anID length: (unsigned) length;

View file

@ -27,7 +27,7 @@
#include <errno.h> #include <errno.h>
#include <Foundation/NSObject.h> #include <Foundation/NSObject.h>
GS_IMPORT int errno; extern int errno;
/* /*
@ -115,30 +115,30 @@ GS_EXPORT NSString* GSDebugMethodMsg(id obj, SEL sel, const char *file,
#define NSDebugLLog(level, format, args...) \ #define NSDebugLLog(level, format, args...) \
do { if (GSDebugSet(level) == YES) \ do { if (GSDebugSet(level) == YES) \
NSLog(format, ## args); } while (0) NSLog(format , ## args); } while (0)
#define NSDebugLog(format, args...) \ #define NSDebugLog(format, args...) \
do { if (GSDebugSet(@"dflt") == YES) \ do { if (GSDebugSet(@"dflt") == YES) \
NSLog(format, ## args); } while (0) NSLog(format , ## args); } while (0)
#define NSDebugFLLog(level, format, args...) \ #define NSDebugFLLog(level, format, args...) \
do { if (GSDebugSet(level) == YES) { \ do { if (GSDebugSet(level) == YES) { \
NSString *fmt = GSDebugFunctionMsg( \ NSString *fmt = GSDebugFunctionMsg( \
__PRETTY_FUNCTION__, __FILE__, __LINE__, format); \ __PRETTY_FUNCTION__, __FILE__, __LINE__, format); \
NSLog(fmt, ## args); }} while (0) NSLog(fmt , ## args); }} while (0)
#define NSDebugFLog(format, args...) \ #define NSDebugFLog(format, args...) \
do { if (GSDebugSet(@"dflt") == YES) { \ do { if (GSDebugSet(@"dflt") == YES) { \
NSString *fmt = GSDebugFunctionMsg( \ NSString *fmt = GSDebugFunctionMsg( \
__PRETTY_FUNCTION__, __FILE__, __LINE__, format); \ __PRETTY_FUNCTION__, __FILE__, __LINE__, format); \
NSLog(fmt, ## args); }} while (0) NSLog(fmt , ## args); }} while (0)
#define NSDebugMLLog(level, format, args...) \ #define NSDebugMLLog(level, format, args...) \
do { if (GSDebugSet(level) == YES) { \ do { if (GSDebugSet(level) == YES) { \
NSString *fmt = GSDebugMethodMsg( \ NSString *fmt = GSDebugMethodMsg( \
self, _cmd, __FILE__, __LINE__, format); \ self, _cmd, __FILE__, __LINE__, format); \
NSLog(fmt, ## args); }} while (0) NSLog(fmt , ## args); }} while (0)
#define NSDebugMLog(format, args...) \ #define NSDebugMLog(format, args...) \
do { if (GSDebugSet(@"dflt") == YES) { \ do { if (GSDebugSet(@"dflt") == YES) { \
NSString *fmt = GSDebugMethodMsg( \ NSString *fmt = GSDebugMethodMsg( \
self, _cmd, __FILE__, __LINE__, format); \ self, _cmd, __FILE__, __LINE__, format); \
NSLog(fmt, ## args); }} while (0) NSLog(fmt , ## args); }} while (0)
#else #else
#define NSDebugLLog(level, format, args...) #define NSDebugLLog(level, format, args...)
#define NSDebugLog(format, args...) #define NSDebugLog(format, args...)
@ -178,17 +178,17 @@ GS_EXPORT NSString* GSDebugMethodMsg(id obj, SEL sel, const char *file,
#define NSWarnLog(format, args...) \ #define NSWarnLog(format, args...) \
do { \ do { \
NSLog(format, ## args); } while (0) NSLog(format , ## args); } while (0)
#define NSWarnFLog(format, args...) \ #define NSWarnFLog(format, args...) \
do { \ do { \
NSString *fmt = GSDebugFunctionMsg( \ NSString *fmt = GSDebugFunctionMsg( \
__PRETTY_FUNCTION__, __FILE__, __LINE__, format); \ __PRETTY_FUNCTION__, __FILE__, __LINE__, format); \
NSLog(fmt, ## args); } while (0) NSLog(fmt , ## args); } while (0)
#define NSWarnMLog(format, args...) \ #define NSWarnMLog(format, args...) \
do { \ do { \
NSString *fmt = GSDebugMethodMsg( \ NSString *fmt = GSDebugMethodMsg( \
self, _cmd, __FILE__, __LINE__, format); \ self, _cmd, __FILE__, __LINE__, format); \
NSLog(fmt, ## args); } while (0) NSLog(fmt , ## args); } while (0)
#else #else
#define NSWarnLog(format, args...) #define NSWarnLog(format, args...)
#define NSWarnFLog(format, args...) #define NSWarnFLog(format, args...)

View file

@ -25,13 +25,13 @@
#include <Foundation/NSObject.h> #include <Foundation/NSObject.h>
@class NSString, NSArray, NSMutableArray; @class NSString, NSArray, NSSet;
@interface NSHost : NSObject @interface NSHost : NSObject
{ {
@private @private
NSMutableArray *_names; NSSet *_names;
NSMutableArray *_addresses; NSSet *_addresses;
} }
/* /*
@ -78,5 +78,9 @@
@end @end
@interface NSHost (GNUstep)
+ (NSHost*) localHost; /* All local IP addresses */
@end
#endif #endif

View file

@ -34,7 +34,6 @@
#else #else
# define GS_EXPORT extern # define GS_EXPORT extern
#endif #endif
#define GS_IMPORT extern
#define GS_DECLARE #define GS_DECLARE
@class NSString; @class NSString;

View file

@ -1,4 +1,3 @@
#if GS_NEW_DO
/* Interface for NSPortCoder object for distributed objects /* Interface for NSPortCoder object for distributed objects
Copyright (C) 2000 Free Software Foundation, Inc. Copyright (C) 2000 Free Software Foundation, Inc.
@ -100,50 +99,3 @@
#endif /* __NSPortCoder_h */ #endif /* __NSPortCoder_h */
#else
/* Interface for NSPortCoder object for distributed objects
Copyright (C) 1997 Free Software Foundation, Inc.
Written by: Richard Frith-Macdonald <richard@brainstorm.co.uk>
Date: August 1997
This file is part of the GNUstep Base Library.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with this library; if not, write to the Free
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111 USA.
*/
#ifndef __NSPortCoder_h
#define __NSPortCoder_h
#include <Foundation/NSCoder.h>
@class NSConnection;
@class NSPort;
@interface NSPortCoder : NSCoder
{
}
- (NSConnection*) connection;
- (NSPort*) decodePortObject;
- (void) encodePortObject: (NSPort*)aPort;
- (BOOL) isBycopy;
- (BOOL) isByref;
@end
#endif /* __NSPortCoder_h */
#endif

View file

@ -65,13 +65,13 @@
// Allocating and Initializing // Allocating and Initializing
+ (NSNumber*) numberWithBool: (BOOL)value; + (NSNumber*) numberWithBool: (BOOL)value;
+ (NSNumber*) numberWithChar: (char)value; + (NSNumber*) numberWithChar: (signed char)value;
+ (NSNumber*) numberWithDouble: (double)value; + (NSNumber*) numberWithDouble: (double)value;
+ (NSNumber*) numberWithFloat: (float)value; + (NSNumber*) numberWithFloat: (float)value;
+ (NSNumber*) numberWithInt: (int)value; + (NSNumber*) numberWithInt: (signed int)value;
+ (NSNumber*) numberWithLong: (long)value; + (NSNumber*) numberWithLong: (signed long)value;
+ (NSNumber*) numberWithLongLong: (long long)value; + (NSNumber*) numberWithLongLong: (signed long long)value;
+ (NSNumber*) numberWithShort: (short)value; + (NSNumber*) numberWithShort: (signed short)value;
+ (NSNumber*) numberWithUnsignedChar: (unsigned char)value; + (NSNumber*) numberWithUnsignedChar: (unsigned char)value;
+ (NSNumber*) numberWithUnsignedInt: (unsigned int)value; + (NSNumber*) numberWithUnsignedInt: (unsigned int)value;
+ (NSNumber*) numberWithUnsignedLong: (unsigned long)value; + (NSNumber*) numberWithUnsignedLong: (unsigned long)value;
@ -79,13 +79,13 @@
+ (NSNumber*) numberWithUnsignedShort: (unsigned short)value; + (NSNumber*) numberWithUnsignedShort: (unsigned short)value;
- (id) initWithBool: (BOOL)value; - (id) initWithBool: (BOOL)value;
- (id) initWithChar: (char)value; - (id) initWithChar: (signed char)value;
- (id) initWithDouble: (double)value; - (id) initWithDouble: (double)value;
- (id) initWithFloat: (float)value; - (id) initWithFloat: (float)value;
- (id) initWithInt: (int)value; - (id) initWithInt: (signed int)value;
- (id) initWithLong: (long)value; - (id) initWithLong: (signed long)value;
- (id) initWithLongLong: (long long)value; - (id) initWithLongLong: (signed long long)value;
- (id) initWithShort: (short)value; - (id) initWithShort: (signed short)value;
- (id) initWithUnsignedChar: (unsigned char)value; - (id) initWithUnsignedChar: (unsigned char)value;
- (id) initWithUnsignedInt: (unsigned int)value; - (id) initWithUnsignedInt: (unsigned int)value;
- (id) initWithUnsignedLong: (unsigned long)value; - (id) initWithUnsignedLong: (unsigned long)value;
@ -95,13 +95,13 @@
// Accessing Data // Accessing Data
- (BOOL) boolValue; - (BOOL) boolValue;
- (char) charValue; - (signed char) charValue;
- (double) doubleValue; - (double) doubleValue;
- (float) floatValue; - (float) floatValue;
- (int) intValue; - (signed int) intValue;
- (long long) longLongValue; - (signed long long) longLongValue;
- (long) longValue; - (signed long) longValue;
- (short) shortValue; - (signed short) shortValue;
- (NSString*) stringValue; - (NSString*) stringValue;
- (unsigned char) unsignedCharValue; - (unsigned char) unsignedCharValue;
- (unsigned int) unsignedIntValue; - (unsigned int) unsignedIntValue;

View file

@ -32,7 +32,6 @@ unichar chartouni(char c);
char unitochar(unichar u); char unitochar(unichar u);
int strtoustr(unichar * u1,const char *s1,int size); int strtoustr(unichar * u1,const char *s1,int size);
int ustrtostr(char *s2,unichar *u1,int size); int ustrtostr(char *s2,unichar *u1,int size);
int uslen (unichar *u);
unichar uni_tolower(unichar ch); unichar uni_tolower(unichar ch);
unichar uni_toupper(unichar ch); unichar uni_toupper(unichar ch);
unsigned char uni_cop(unichar u); unsigned char uni_cop(unichar u);

19
NEWS
View file

@ -1,7 +1,24 @@
News News
**** ****
The currently released version of the library is `0.6.5'. The currently released version of the library is `0.6.6'.
Noteworthy changes in version `0.6.6'
=====================================
* Lots of new documentation.
* Completely rewritten Distributed Object to be much more compatible
with the MacOS-X API (and incidentally, closer to the original
OpenStep standard).
* Support to compile library as a DLL on Windows (still cygwin only).
* Removed lots of obsolete classes.
* New tools for handling property lists.
* More optimization of classes.
Noteworthy changes in version `0.6.5' Noteworthy changes in version `0.6.5'
===================================== =====================================

Binary file not shown.

View file

@ -69,25 +69,10 @@ FILE_AUTHORS = \
# The GNU source files # The GNU source files
GNU_MFILES = \ GNU_MFILES = \
BinaryCStream.m \
Coder.m \
CStream.m \
Decoder.m \
Encoder.m \
GetDefEncoding.m \ GetDefEncoding.m \
MachPort.m \
MemoryStream.m \
Port.m \
RawCStream.m \
StdioStream.m \
Stream.m \
TcpPort.m \
TextCStream.m \
UdpPort.m \
Unicode.m \ Unicode.m \
UnixFileHandle.m \ UnixFileHandle.m \
behavior.m \ behavior.m \
ostream.m \
o_array.m \ o_array.m \
o_array_bas.m \ o_array_bas.m \
o_array_cbs.m \ o_array_cbs.m \
@ -132,33 +117,11 @@ fast.x \
GSUnion.h \ GSUnion.h \
GSIArray.h \ GSIArray.h \
GSIMap.h \ GSIMap.h \
BinaryCStream.h \
Coder.h \
CoderPrivate.h \
Coding.h \
CStream.h \
CStreaming.h \
Enumerating.h \
GetDefEncoding.h \ GetDefEncoding.h \
Locking.h \
MachPort.h \
MemoryStream.h \
Ordering.h \
Port.h \
RawCStream.h \
Retaining.h \
StdioStream.h \
Stream.h \
Streaming.h \
TcpPort.h \
TextCStream.h \
UdpPort.h \
Unicode.h \ Unicode.h \
UnixFileHandle.h \ UnixFileHandle.h \
ValueHolding.h \
behavior.h \ behavior.h \
numbers.h \ numbers.h \
ostream.h \
o_array.h \ o_array.h \
o_array_bas.h \ o_array_bas.h \
o_array_cbs.h \ o_array_cbs.h \

View file

@ -37,6 +37,7 @@
#include <Foundation/NSPortNameServer.h> #include <Foundation/NSPortNameServer.h>
#include <Foundation/NSLock.h> #include <Foundation/NSLock.h>
#include <Foundation/NSHost.h> #include <Foundation/NSHost.h>
#include <Foundation/NSThread.h>
#include <Foundation/NSDebug.h> #include <Foundation/NSDebug.h>
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
@ -51,6 +52,13 @@
extern int errno; extern int errno;
static BOOL multi_threaded = NO;
/*
* Largest chunk of data possible in DO
*/
static gsu32 maxDataLength = 10 * 1024 * 1024;
#if 0 #if 0
#define DO_LOCK(X) {NSDebugMLLog(@"GSTcpHandle",@"lock %@",X); [X lock];} #define DO_LOCK(X) {NSDebugMLLog(@"GSTcpHandle",@"lock %@",X); [X lock];}
#define DO_UNLOCK(X) {NSDebugMLLog(@"GSTcpHandle",@"unlock %@",X); [X unlock];} #define DO_UNLOCK(X) {NSDebugMLLog(@"GSTcpHandle",@"unlock %@",X); [X unlock];}
@ -151,7 +159,6 @@ typedef enum {
@interface GSTcpHandle : NSObject <GCFinalization, RunLoopEvents> @interface GSTcpHandle : NSObject <GCFinalization, RunLoopEvents>
{ {
NSLock *myLock; /* Lock for this handle. */
int desc; /* File descriptor for I/O. */ int desc; /* File descriptor for I/O. */
unsigned wItem; /* Index of item being written. */ unsigned wItem; /* Index of item being written. */
NSMutableData *wData; /* Data object being written. */ NSMutableData *wData; /* Data object being written. */
@ -167,10 +174,12 @@ typedef enum {
GSHandleState state; /* State of the handle. */ GSHandleState state; /* State of the handle. */
int addrNum; /* Address number within host. */ int addrNum; /* Address number within host. */
@public @public
NSLock *myLock; /* Lock for this handle. */
BOOL caller; /* Did we connect to other end? */ BOOL caller; /* Did we connect to other end? */
BOOL valid; BOOL valid;
GSTcpPort *recvPort; GSTcpPort *recvPort;
GSTcpPort *sendPort; GSTcpPort *sendPort;
struct sockaddr_in clientname; /* Far end of connection. */
} }
+ (GSTcpHandle*) handleWithDescriptor: (int)d; + (GSTcpHandle*) handleWithDescriptor: (int)d;
@ -292,6 +301,10 @@ newDataWithEncodedPort(GSTcpPort *port)
} }
} }
} }
if (addr == nil)
{
addr = @"127.0.0.1"; /* resign ourselves to this */
}
} }
plen = [addr cStringLength] + 3; plen = [addr cStringLength] + 3;
data = [[NSMutableData alloc] initWithLength: sizeof(GSPortItemHeader)+plen]; data = [[NSMutableData alloc] initWithLength: sizeof(GSPortItemHeader)+plen];
@ -350,7 +363,10 @@ static Class runLoopClass;
handle = (GSTcpHandle*)NSAllocateObject(self,0,NSDefaultMallocZone()); handle = (GSTcpHandle*)NSAllocateObject(self,0,NSDefaultMallocZone());
handle->desc = d; handle->desc = d;
handle->wMsgs = [NSMutableArray new]; handle->wMsgs = [NSMutableArray new];
handle->myLock = [NSRecursiveLock new]; if (multi_threaded == YES)
{
handle->myLock = [NSRecursiveLock new];
}
handle->valid = YES; handle->valid = YES;
return AUTORELEASE(handle); return AUTORELEASE(handle);
} }
@ -404,7 +420,8 @@ static Class runLoopClass;
if (addrNum >= [addrs count]) if (addrNum >= [addrs count])
{ {
NSLog(@"run out of addresses to try (tried %d)", addrNum); NSLog(@"run out of addresses to try (tried %d) for port %@",
addrNum, aPort);
return NO; return NO;
} }
addr = [[addrs objectAtIndex: addrNum++] cString]; addr = [[addrs objectAtIndex: addrNum++] cString];
@ -498,6 +515,12 @@ static Class runLoopClass;
[super dealloc]; [super dealloc];
} }
- (NSString*) description
{
return [NSString stringWithFormat: @"Handle (%d) to %s:%d",
desc, inet_ntoa(clientname.sin_addr), ntohs(clientname.sin_port)];
}
- (int) descriptor - (int) descriptor
{ {
return desc; return desc;
@ -669,37 +692,75 @@ static Class runLoopClass;
l = GSSwapBigI32ToHost(h->length); l = GSSwapBigI32ToHost(h->length);
if (rType == GSP_PORT) if (rType == GSP_PORT)
{ {
if (l > 32)
{
NSLog(@"%@ - unreasonable length (%u) for port",
self, l);
[self invalidate];
return;
}
/* /*
* For a port, we leave the item header in the data * For a port, we leave the item header in the data
* so that our decode function can check length info. * so that our decode function can check length info.
*/ */
rWant += l; rWant += l;
} }
else if (rType == GSP_DATA && l == 0) else if (rType == GSP_DATA)
{ {
NSData *d; if (l == 0)
{
NSData *d;
/* /*
* For a zero-length data chunk, we create an empty * For a zero-length data chunk, we create an empty
* data object and add it to the current message. * data object and add it to the current message.
*/ */
rType = GSP_NONE; /* ready for a new item */ rType = GSP_NONE; /* ready for a new item */
rLength -= rWant; rLength -= rWant;
if (rLength > 0) if (rLength > 0)
{ {
memcpy(bytes, bytes + rWant, rLength); memcpy(bytes, bytes + rWant, rLength);
}
rWant = sizeof(GSPortItemHeader);
d = [mutableDataClass new];
[rItems addObject: d];
RELEASE(d);
if (nItems == [rItems count])
{
[self dispatch];
}
} }
rWant = sizeof(GSPortItemHeader); else
d = [mutableDataClass new];
[rItems addObject: d];
RELEASE(d);
if (nItems == [rItems count])
{ {
[self dispatch]; if (l > maxDataLength)
{
NSLog(@"%@ - unreasonable length (%u) for data",
self, l);
[self invalidate];
return;
}
/*
* If not a port or zero length data,
* we discard the data read so far and fill the
* data object with the data item from the msg.
*/
rLength -= rWant;
if (rLength > 0)
{
memcpy(bytes, bytes + rWant, rLength);
}
rWant = l;
} }
} }
else else if (rType == GSP_HEAD)
{ {
if (l > maxDataLength)
{
NSLog(@"%@ - unreasonable length (%u) for data",
self, l);
[self invalidate];
return;
}
/* /*
* If not a port or zero length data, * If not a port or zero length data,
* we discard the data read so far and fill the * we discard the data read so far and fill the
@ -712,6 +773,12 @@ static Class runLoopClass;
} }
rWant = l; rWant = l;
} }
else
{
NSLog(@"%@ - bad data received on port handle", self);
[self invalidate];
return;
}
} }
break; break;
@ -1020,14 +1087,79 @@ static NSRecursiveLock *tcpPortLock = nil;
static NSMapTable *tcpPortMap = 0; static NSMapTable *tcpPortMap = 0;
static Class tcpPortClass; static Class tcpPortClass;
/*
* When the system becomes multithreaded, we set a flag to say so and
* make sure that port and handle locking is enabled.
*/
+ (void) _becomeThreaded: (NSNotification*)notification
{
if (multi_threaded == NO)
{
NSMapEnumerator pEnum;
NSMapTable *m;
void *dummy;
multi_threaded = YES;
if (tcpPortLock == nil)
{
tcpPortLock = [NSRecursiveLock new];
}
pEnum = NSEnumerateMapTable(tcpPortMap);
while (NSNextMapEnumeratorPair(&pEnum, &dummy, (void**)&m))
{
NSMapEnumerator mEnum;
GSTcpPort *p;
mEnum = NSEnumerateMapTable(m);
while (NSNextMapEnumeratorPair(&mEnum, &dummy, (void**)&p))
{
if ([p isValid] == YES)
{
NSMapEnumerator hEnum;
GSTcpHandle *h;
if (p->myLock == nil)
{
p->myLock = [NSRecursiveLock new];
}
hEnum = NSEnumerateMapTable(p->handles);
while (NSNextMapEnumeratorPair(&hEnum, &dummy, (void**)&h))
{
if ([h isValid] == YES && h->myLock == nil)
{
h->myLock = [NSRecursiveLock new];
}
}
}
}
}
}
[[NSNotificationCenter defaultCenter]
removeObserver: self
name: NSWillBecomeMultiThreadedNotification
object: nil];
}
+ (void) initialize + (void) initialize
{ {
if (self == [GSTcpPort class]) if (self == [GSTcpPort class])
{ {
tcpPortClass = self; tcpPortClass = self;
tcpPortLock = [NSRecursiveLock new];
tcpPortMap = NSCreateMapTable(NSIntMapKeyCallBacks, tcpPortMap = NSCreateMapTable(NSIntMapKeyCallBacks,
NSNonOwnedPointerMapValueCallBacks, 0); NSNonOwnedPointerMapValueCallBacks, 0);
if ([NSThread isMultiThreaded])
{
[self _becomeThreaded: nil];
}
else
{
[[NSNotificationCenter defaultCenter]
addObserver: self
selector: @selector(_becomeThreaded:)
name: NSWillBecomeMultiThreadedNotification
object: nil];
}
} }
} }
@ -1080,7 +1212,7 @@ static Class tcpPortClass;
{ {
unsigned i; unsigned i;
GSTcpPort *port = nil; GSTcpPort *port = nil;
NSHost *thisHost = [NSHost currentHost]; NSHost *thisHost = [NSHost localHost];
NSMapTable *thePorts; NSMapTable *thePorts;
if (thisHost == nil) if (thisHost == nil)
@ -1122,10 +1254,13 @@ static Class tcpPortClass;
port->address = [addr copy]; port->address = [addr copy];
port->handles = NSCreateMapTable(NSIntMapKeyCallBacks, port->handles = NSCreateMapTable(NSIntMapKeyCallBacks,
NSObjectMapValueCallBacks, 0); NSObjectMapValueCallBacks, 0);
port->myLock = [NSRecursiveLock new]; if (multi_threaded == YES)
{
port->myLock = [NSRecursiveLock new];
}
port->_is_valid = YES; port->_is_valid = YES;
if (shouldListen == YES && [thisHost isEqual: aHost] == YES) if (shouldListen == YES && [thisHost isEqual: aHost])
{ {
int reuse = 1; /* Should we re-use ports? */ int reuse = 1; /* Should we re-use ports? */
int desc; int desc;
@ -1206,12 +1341,11 @@ static Class tcpPortClass;
*/ */
port->listener = desc; port->listener = desc;
port->portNum = GSSwapBigI16ToHost(sockaddr.sin_port); port->portNum = GSSwapBigI16ToHost(sockaddr.sin_port);
/* /*
* Make sure we have the map table for this port. * Make sure we have the map table for this port.
*/ */
thePorts = (NSMapTable*)NSMapGet(tcpPortMap, thePorts = (NSMapTable*)NSMapGet(tcpPortMap,
(void*)(gsaddr)port->portNum); (void*)(gsaddr)port->portNum);
if (thePorts == 0) if (thePorts == 0)
{ {
/* /*
@ -1527,6 +1661,7 @@ static Class tcpPortClass;
* the other end. * the other end.
*/ */
handle = [GSTcpHandle handleWithDescriptor: desc]; handle = [GSTcpHandle handleWithDescriptor: desc];
memcpy(&handle->clientname, &clientname, sizeof(clientname));
[handle setState: GS_H_ACCEPT]; [handle setState: GS_H_ACCEPT];
[self addHandle: handle forSend: NO]; [self addHandle: handle forSend: NO];
} }
@ -1557,8 +1692,15 @@ static Class tcpPortClass;
DO_LOCK(myLock); DO_LOCK(myLock);
if ([handle sendPort] == self) if ([handle sendPort] == self)
{ {
if (handle->caller == YES) if (handle->caller != YES)
{ {
/*
* This is a handle for a send port, and the handle was not formed
* by calling the remote process, so this port object must have
* been created to deal with an incoming connection and will have
* been retained - we must therefore release this port since the
* handle no longer uses it.
*/
AUTORELEASE(self); AUTORELEASE(self);
} }
handle->sendPort = nil; handle->sendPort = nil;
@ -1696,7 +1838,7 @@ static Class tcpPortClass;
* word boundary, so we work with an aligned buffer * word boundary, so we work with an aligned buffer
* and use memcmpy() * and use memcmpy()
*/ */
if ((*hLength % __alignof__(gsu32)) != 0) if ((hLength % __alignof__(gsu32)) != 0)
{ {
GSPortItemHeader itemHeader; GSPortItemHeader itemHeader;

View file

@ -39,7 +39,7 @@
# #
# Additional flags to pass to the preprocessor # Additional flags to pass to the preprocessor
ADDITIONAL_CPPFLAGS = $(DEFS) -Wall -DGS_NEW_DO=1 ADDITIONAL_CPPFLAGS = $(DEFS) -Wall
# Additional flags to pass to the Objective-C compiler # Additional flags to pass to the Objective-C compiler
ADDITIONAL_OBJCFLAGS = ADDITIONAL_OBJCFLAGS =

View file

@ -712,14 +712,6 @@ static SEL eValSel = @selector(encodeValueOfObjCType:at:);
(*_tagImp)(_dst, tagSel, _GSC_ID | _GSC_XREF, _GSC_X_0); (*_tagImp)(_dst, tagSel, _GSC_ID | _GSC_XREF, _GSC_X_0);
} }
} }
else if (fastIsInstance(anObject) == NO)
{
/*
* If the object we have been given is actually a class,
* we encode it as a class instead.
*/
(*_eValImp)(self, eValSel, @encode(Class), &anObject);
}
else else
{ {
GSIMapNode node; GSIMapNode node;
@ -769,22 +761,33 @@ static SEL eValSel = @selector(encodeValueOfObjCType:at:);
} }
obj = [anObject replacementObjectForArchiver: self]; obj = [anObject replacementObjectForArchiver: self];
cls = [obj classForArchiver]; if (fastIsInstance(obj) == NO)
(*_xRefImp)(_dst, xRefSel, _GSC_ID, node->value.uint);
if (_namMap->nodeCount)
{ {
GSIMapNode node; /*
* If the object we have been given is actually a class,
node = GSIMapNodeForKey(_namMap, (GSIMapKey)cls); * we encode it as a special case.
*/
if (node) (*_xRefImp)(_dst, xRefSel, _GSC_CID, node->value.uint);
{ (*_eValImp)(self, eValSel, @encode(Class), &obj);
cls = (Class)node->value.ptr; }
} else
{
cls = [obj classForArchiver];
if (_namMap->nodeCount)
{
GSIMapNode n;
n = GSIMapNodeForKey(_namMap, (GSIMapKey)cls);
if (n)
{
cls = (Class)n->value.ptr;
}
}
(*_xRefImp)(_dst, xRefSel, _GSC_ID, node->value.uint);
(*_eValImp)(self, eValSel, @encode(Class), &cls);
[obj encodeWithCoder: self];
} }
(*_eValImp)(self, eValSel, @encode(Class), &cls);
[obj encodeWithCoder: self];
} }
else else
{ {

View file

@ -80,31 +80,16 @@ static SEL rlSel = @selector(removeLastObject);
} }
} }
+ (void) _setConcreteClass: (Class)c
{
NSArray_concrete_class = c;
}
+ (void) _setMutableConcreteClass: (Class)c
{
NSMutableArray_concrete_class = c;
}
+ (Class) _concreteClass
{
return NSArray_concrete_class;
}
+ (Class) _mutableConcreteClass
{
return NSMutableArray_concrete_class;
}
+ (id) allocWithZone: (NSZone*)z + (id) allocWithZone: (NSZone*)z
{ {
if (self == NSArray_abstract_class) if (self == NSArray_abstract_class)
return NSAllocateObject(NSArray_concrete_class, 0, z); {
return [super allocWithZone: z]; return NSAllocateObject(NSArray_concrete_class, 0, z);
}
else
{
return NSAllocateObject(self, 0, z);
}
} }
+ (id) array + (id) array
@ -799,8 +784,13 @@ static NSString *indentStrings[] = {
+ (id) allocWithZone: (NSZone*)z + (id) allocWithZone: (NSZone*)z
{ {
if (self == NSMutableArray_abstract_class) if (self == NSMutableArray_abstract_class)
return NSAllocateObject(NSMutableArray_concrete_class, 0, z); {
return [super allocWithZone: z]; return NSAllocateObject(NSMutableArray_concrete_class, 0, z);
}
else
{
return NSAllocateObject(self, 0, z);
}
} }
/* The NSCopying Protocol */ /* The NSCopying Protocol */
@ -1347,3 +1337,130 @@ static NSString *indentStrings[] = {
return (*get)(array, oaiSel, --pos); return (*get)(array, oaiSel, --pos);
} }
@end @end
@implementation NSArray (GNUstep)
/*
* The comparator function takes two items as arguments, the first is the
* item to be added, the second is the item already in the array.
* The function should return NSOrderedAscending if the item to be
* added is 'less than' the item in the array, NSOrderedDescending
* if it is greater, and NSOrderedSame if it is equal.
*/
- (unsigned) insertionPosition: (id)item
usingFunction: (NSComparisonResult (*)(id, id))sorter
{
unsigned count = [self count];
unsigned upper = count;
unsigned lower = 0;
unsigned index;
IMP oai;
if (item == nil)
{
[NSException raise: NSGenericException
format: @"Attempt to find position for nil object in array"];
}
if (sorter == 0)
{
[NSException raise: NSGenericException
format: @"Attempt to find position with null comparator"];
}
oai = [self methodForSelector: oaiSel];
/*
* Binary search for an item equal to the one to be inserted.
*/
for (index = upper/2; upper != lower; index = lower+(upper-lower)/2)
{
NSComparisonResult comparison;
comparison = (*sorter)(item, (*oai)(self, oaiSel, index));
if (comparison == NSOrderedAscending)
{
upper = index;
}
else if (comparison == NSOrderedDescending)
{
lower = index + 1;
}
else
{
break;
}
}
/*
* Now skip past any equal items so the insertion point is AFTER any
* items that are equal to the new one.
*/
while (index < count
&& (*sorter)(item, (*oai)(self, oaiSel, index)) != NSOrderedAscending)
{
index++;
}
return index;
}
- (unsigned) insertionPosition: (id)item
usingSelector: (SEL)comp
{
unsigned count = [self count];
unsigned upper = count;
unsigned lower = 0;
unsigned index;
NSComparisonResult (*imp)(id, SEL, id);
IMP oai;
if (item == nil)
{
[NSException raise: NSGenericException
format: @"Attempt to find position for nil object in array"];
}
if (comp == 0)
{
[NSException raise: NSGenericException
format: @"Attempt to find position with null comparator"];
}
imp = (NSComparisonResult (*)(id, SEL, id))[item methodForSelector: comp];
if (imp == 0)
{
[NSException raise: NSGenericException
format: @"Attempt to find position with unknown method"];
}
oai = [self methodForSelector: oaiSel];
/*
* Binary search for an item equal to the one to be inserted.
*/
for (index = upper/2; upper != lower; index = lower+(upper-lower)/2)
{
NSComparisonResult comparison;
comparison = (*imp)(item, comp, (*oai)(self, oaiSel, index));
if (comparison == NSOrderedAscending)
{
upper = index;
}
else if (comparison == NSOrderedDescending)
{
lower = index + 1;
}
else
{
break;
}
}
/*
* Now skip past any equal items so the insertion point is AFTER any
* items that are equal to the new one.
*/
while (index < count
&& (*imp)(item, comp, (*oai)(self, oaiSel, index)) != NSOrderedAscending)
{
index++;
}
return index;
}
@end

View file

@ -89,27 +89,6 @@ static Class NSAttributedString_concrete_class;
static Class NSMutableAttributedString_abstract_class; static Class NSMutableAttributedString_abstract_class;
static Class NSMutableAttributedString_concrete_class; static Class NSMutableAttributedString_concrete_class;
//Internal methods
+ (void) _setConcreteClass: (Class)c
{
NSAttributedString_concrete_class = c;
}
+ (void) _setMutableConcreteClass: (Class)c
{
NSMutableAttributedString_concrete_class = c;
}
+ (Class) _concreteClass
{
return NSAttributedString_concrete_class;
}
+ (Class) _mutableConcreteClass
{
return NSMutableAttributedString_concrete_class;
}
+ (void) initialize + (void) initialize
{ {
if (self == [NSAttributedString class]) if (self == [NSAttributedString class])
@ -133,7 +112,7 @@ static Class NSMutableAttributedString_concrete_class;
+ (id) allocWithZone: (NSZone*)z + (id) allocWithZone: (NSZone*)z
{ {
if (self == NSAttributedString_abstract_class) if (self == NSAttributedString_abstract_class)
return NSAllocateObject([self _concreteClass], 0, z); return NSAllocateObject(NSAttributedString_concrete_class, 0, z);
else else
return NSAllocateObject(self, 0, z); return NSAllocateObject(self, 0, z);
} }
@ -166,7 +145,7 @@ static Class NSMutableAttributedString_concrete_class;
{ {
if ([self isKindOfClass: [NSMutableAttributedString class]] if ([self isKindOfClass: [NSMutableAttributedString class]]
|| NSShouldRetainWithZone(self, zone) == NO) || NSShouldRetainWithZone(self, zone) == NO)
return [[[[self class] _concreteClass] allocWithZone: zone] return [[NSAttributedString_concrete_class allocWithZone: zone]
initWithAttributedString: self]; initWithAttributedString: self];
else else
return RETAIN(self); return RETAIN(self);
@ -175,7 +154,7 @@ static Class NSMutableAttributedString_concrete_class;
//NSMutableCopying protocol //NSMutableCopying protocol
- (id) mutableCopyWithZone: (NSZone*)zone - (id) mutableCopyWithZone: (NSZone*)zone
{ {
return [[[[self class] _mutableConcreteClass] allocWithZone: zone] return [[NSMutableAttributedString_concrete_class allocWithZone: zone]
initWithAttributedString: self]; initWithAttributedString: self];
} }
@ -498,7 +477,7 @@ static Class NSMutableAttributedString_concrete_class;
+ allocWithZone: (NSZone*)z + allocWithZone: (NSZone*)z
{ {
if (self == NSMutableAttributedString_abstract_class) if (self == NSMutableAttributedString_abstract_class)
return NSAllocateObject([self _mutableConcreteClass], 0, z); return NSAllocateObject(NSMutableAttributedString_concrete_class, 0, z);
else else
return NSAllocateObject(self, 0, z); return NSAllocateObject(self, 0, z);
} }

View file

@ -48,7 +48,7 @@
#define GREGORIAN_REFERENCE 730486 #define GREGORIAN_REFERENCE 730486
static inline int static inline int
lastDayOfGregorianMonth(int year, int month) lastDayOfGregorianMonth(int month, int year)
{ {
switch (month) switch (month)
{ {

View file

@ -45,7 +45,7 @@
#elif TYPE_ORDER == 1 #elif TYPE_ORDER == 1
# define NumberTemplate NSCharNumber # define NumberTemplate NSCharNumber
# define TYPE_FORMAT @"%c" # define TYPE_FORMAT @"%c"
# define TYPE_TYPE char # define TYPE_TYPE signed char
#elif TYPE_ORDER == 2 #elif TYPE_ORDER == 2
# define NumberTemplate NSUCharNumber # define NumberTemplate NSUCharNumber
# define TYPE_FORMAT @"%c" # define TYPE_FORMAT @"%c"
@ -53,7 +53,7 @@
#elif TYPE_ORDER == 3 #elif TYPE_ORDER == 3
# define NumberTemplate NSShortNumber # define NumberTemplate NSShortNumber
# define TYPE_FORMAT @"%hd" # define TYPE_FORMAT @"%hd"
# define TYPE_TYPE short # define TYPE_TYPE signed short
#elif TYPE_ORDER == 4 #elif TYPE_ORDER == 4
# define NumberTemplate NSUShortNumber # define NumberTemplate NSUShortNumber
# define TYPE_FORMAT @"%hu" # define TYPE_FORMAT @"%hu"
@ -61,7 +61,7 @@
#elif TYPE_ORDER == 5 #elif TYPE_ORDER == 5
# define NumberTemplate NSIntNumber # define NumberTemplate NSIntNumber
# define TYPE_FORMAT @"%d" # define TYPE_FORMAT @"%d"
# define TYPE_TYPE int # define TYPE_TYPE signed int
#elif TYPE_ORDER == 6 #elif TYPE_ORDER == 6
# define NumberTemplate NSUIntNumber # define NumberTemplate NSUIntNumber
# define TYPE_FORMAT @"%u" # define TYPE_FORMAT @"%u"
@ -69,7 +69,7 @@
#elif TYPE_ORDER == 7 #elif TYPE_ORDER == 7
# define NumberTemplate NSLongNumber # define NumberTemplate NSLongNumber
# define TYPE_FORMAT @"%ld" # define TYPE_FORMAT @"%ld"
# define TYPE_TYPE long # define TYPE_TYPE signed long
#elif TYPE_ORDER == 8 #elif TYPE_ORDER == 8
# define NumberTemplate NSULongNumber # define NumberTemplate NSULongNumber
# define TYPE_FORMAT @"%lu" # define TYPE_FORMAT @"%lu"
@ -77,7 +77,7 @@
#elif TYPE_ORDER == 9 #elif TYPE_ORDER == 9
# define NumberTemplate NSLongLongNumber # define NumberTemplate NSLongLongNumber
# define TYPE_FORMAT @"%lld" # define TYPE_FORMAT @"%lld"
# define TYPE_TYPE long long # define TYPE_TYPE signed long long
#elif TYPE_ORDER == 10 #elif TYPE_ORDER == 10
# define NumberTemplate NSULongLongNumber # define NumberTemplate NSULongLongNumber
# define TYPE_FORMAT @"%llu" # define TYPE_FORMAT @"%llu"
@ -144,9 +144,9 @@
return (BOOL)data; return (BOOL)data;
} }
- (char) charValue - (signed char) charValue
{ {
return (char)data; return (signed char)data;
} }
- (double) doubleValue - (double) doubleValue
@ -159,24 +159,24 @@
return (float)data; return (float)data;
} }
- (int) intValue - (signed int) intValue
{ {
return (int)data; return (signed int)data;
} }
- (long long) longLongValue - (signed long long) longLongValue
{ {
return (long long)data; return (signed long long)data;
} }
- (long) longValue - (signed long) longValue
{ {
return (long)data; return (signed long)data;
} }
- (short) shortValue - (signed short) shortValue
{ {
return (short)data; return (signed short)data;
} }
- (unsigned char) unsignedCharValue - (unsigned char) unsignedCharValue
@ -206,177 +206,184 @@
- (NSComparisonResult) compare: (NSNumber*)other - (NSComparisonResult) compare: (NSNumber*)other
{ {
GSNumberInfo *info;
if (other == self) if (other == self)
{ {
return NSOrderedSame; return NSOrderedSame;
} }
info = GSNumberInfoFromObject(other); else if (other == nil)
switch (info->typeLevel)
{ {
case 0: [NSException raise: NSInvalidArgumentException
{ format: @"nil argument for compare:"];
BOOL oData;
(*(info->getValue))(other, @selector(getValue:), (void*)&oData);
if (data == oData)
return NSOrderedSame;
else if (data < oData)
return NSOrderedAscending;
else
return NSOrderedDescending;
}
case 1:
{
char oData;
(*(info->getValue))(other, @selector(getValue:), (void*)&oData);
if (data == oData)
return NSOrderedSame;
else if (data < oData)
return NSOrderedAscending;
else
return NSOrderedDescending;
}
case 2:
{
unsigned char oData;
(*(info->getValue))(other, @selector(getValue:), (void*)&oData);
if (data == oData)
return NSOrderedSame;
else if (data < oData)
return NSOrderedAscending;
else
return NSOrderedDescending;
}
case 3:
{
short oData;
(*(info->getValue))(other, @selector(getValue:), (void*)&oData);
if (data == oData)
return NSOrderedSame;
else if (data < oData)
return NSOrderedAscending;
else
return NSOrderedDescending;
}
case 4:
{
unsigned short oData;
(*(info->getValue))(other, @selector(getValue:), (void*)&oData);
if (data == oData)
return NSOrderedSame;
else if (data < oData)
return NSOrderedAscending;
else
return NSOrderedDescending;
}
case 5:
{
int oData;
(*(info->getValue))(other, @selector(getValue:), (void*)&oData);
if (data == oData)
return NSOrderedSame;
else if (data < oData)
return NSOrderedAscending;
else
return NSOrderedDescending;
}
case 6:
{
unsigned int oData;
(*(info->getValue))(other, @selector(getValue:), (void*)&oData);
if (data == oData)
return NSOrderedSame;
else if (data < oData)
return NSOrderedAscending;
else
return NSOrderedDescending;
}
case 7:
{
long oData;
(*(info->getValue))(other, @selector(getValue:), (void*)&oData);
if (data == oData)
return NSOrderedSame;
else if (data < oData)
return NSOrderedAscending;
else
return NSOrderedDescending;
}
case 8:
{
unsigned long oData;
(*(info->getValue))(other, @selector(getValue:), (void*)&oData);
if (data == oData)
return NSOrderedSame;
else if (data < oData)
return NSOrderedAscending;
else
return NSOrderedDescending;
}
case 9:
{
long long oData;
(*(info->getValue))(other, @selector(getValue:), (void*)&oData);
if (data == oData)
return NSOrderedSame;
else if (data < oData)
return NSOrderedAscending;
else
return NSOrderedDescending;
}
case 10:
{
unsigned long long oData;
(*(info->getValue))(other, @selector(getValue:), (void*)&oData);
if (data == oData)
return NSOrderedSame;
else if (data < oData)
return NSOrderedAscending;
else
return NSOrderedDescending;
}
case 11:
{
float oData;
(*(info->getValue))(other, @selector(getValue:), (void*)&oData);
if (data == oData)
return NSOrderedSame;
else if (data < oData)
return NSOrderedAscending;
else
return NSOrderedDescending;
}
case 12:
{
double oData;
(*(info->getValue))(other, @selector(getValue:), (void*)&oData);
if (data == oData)
return NSOrderedSame;
else if (data < oData)
return NSOrderedAscending;
else
return NSOrderedDescending;
}
default:
[NSException raise: NSInvalidArgumentException
format: @"number type value for comparison"];
return NSOrderedSame;
} }
else
{
GSNumberInfo *info = GSNumberInfoFromObject(other);
switch (info->typeLevel)
{
case 0:
{
BOOL oData;
(*(info->getValue))(other, @selector(getValue:), (void*)&oData);
if (data == oData)
return NSOrderedSame;
else if (data < oData)
return NSOrderedAscending;
else
return NSOrderedDescending;
}
case 1:
{
signed char oData;
(*(info->getValue))(other, @selector(getValue:), (void*)&oData);
if (data == oData)
return NSOrderedSame;
else if (data < oData)
return NSOrderedAscending;
else
return NSOrderedDescending;
}
case 2:
{
unsigned char oData;
(*(info->getValue))(other, @selector(getValue:), (void*)&oData);
if (data == oData)
return NSOrderedSame;
else if (data < oData)
return NSOrderedAscending;
else
return NSOrderedDescending;
}
case 3:
{
signed short oData;
(*(info->getValue))(other, @selector(getValue:), (void*)&oData);
if (data == oData)
return NSOrderedSame;
else if (data < oData)
return NSOrderedAscending;
else
return NSOrderedDescending;
}
case 4:
{
unsigned short oData;
(*(info->getValue))(other, @selector(getValue:), (void*)&oData);
if (data == oData)
return NSOrderedSame;
else if (data < oData)
return NSOrderedAscending;
else
return NSOrderedDescending;
}
case 5:
{
signed int oData;
(*(info->getValue))(other, @selector(getValue:), (void*)&oData);
if (data == oData)
return NSOrderedSame;
else if (data < oData)
return NSOrderedAscending;
else
return NSOrderedDescending;
}
case 6:
{
unsigned int oData;
(*(info->getValue))(other, @selector(getValue:), (void*)&oData);
if (data == oData)
return NSOrderedSame;
else if (data < oData)
return NSOrderedAscending;
else
return NSOrderedDescending;
}
case 7:
{
signed long oData;
(*(info->getValue))(other, @selector(getValue:), (void*)&oData);
if (data == oData)
return NSOrderedSame;
else if (data < oData)
return NSOrderedAscending;
else
return NSOrderedDescending;
}
case 8:
{
unsigned long oData;
(*(info->getValue))(other, @selector(getValue:), (void*)&oData);
if (data == oData)
return NSOrderedSame;
else if (data < oData)
return NSOrderedAscending;
else
return NSOrderedDescending;
}
case 9:
{
signed long long oData;
(*(info->getValue))(other, @selector(getValue:), (void*)&oData);
if (data == oData)
return NSOrderedSame;
else if (data < oData)
return NSOrderedAscending;
else
return NSOrderedDescending;
}
case 10:
{
unsigned long long oData;
(*(info->getValue))(other, @selector(getValue:), (void*)&oData);
if (data == oData)
return NSOrderedSame;
else if (data < oData)
return NSOrderedAscending;
else
return NSOrderedDescending;
}
case 11:
{
float oData;
(*(info->getValue))(other, @selector(getValue:), (void*)&oData);
if (data == oData)
return NSOrderedSame;
else if (data < oData)
return NSOrderedAscending;
else
return NSOrderedDescending;
}
case 12:
{
double oData;
(*(info->getValue))(other, @selector(getValue:), (void*)&oData);
if (data == oData)
return NSOrderedSame;
else if (data < oData)
return NSOrderedAscending;
else
return NSOrderedDescending;
}
default:
[NSException raise: NSInvalidArgumentException
format: @"number type value for comparison"];
return NSOrderedSame;
}
}
return 0; /* Quiet warnings */
} }
- (NSString*) descriptionWithLocale: (NSDictionary*)locale - (NSString*) descriptionWithLocale: (NSDictionary*)locale

File diff suppressed because it is too large Load diff

View file

@ -23,8 +23,10 @@
#include <config.h> #include <config.h>
#include <base/behavior.h> #include <base/behavior.h>
#include <base/fast.x>
#include <Foundation/NSSet.h> #include <Foundation/NSSet.h>
#include <Foundation/NSGSet.h> #include <Foundation/NSGSet.h>
#include <Foundation/NSCoder.h>
#include <Foundation/NSArray.h> #include <Foundation/NSArray.h>
#include <Foundation/NSUtilities.h> #include <Foundation/NSUtilities.h>
#include <Foundation/NSString.h> #include <Foundation/NSString.h>
@ -77,21 +79,16 @@ static Class NSCountedSet_concrete_class;
} }
} }
+ (void) _setCountedSetConcreteClass: (Class)c
{
NSCountedSet_concrete_class = c;
}
+ (Class) _concreteClass
{
return NSCountedSet_concrete_class;
}
+ (id) allocWithZone: (NSZone*)z + (id) allocWithZone: (NSZone*)z
{ {
if (self == NSCountedSet_abstract_class) if (self == NSCountedSet_abstract_class)
return NSAllocateObject(NSCountedSet_concrete_class, 0, z); {
return [super allocWithZone: z]; return NSAllocateObject(NSCountedSet_concrete_class, 0, z);
}
else
{
return NSAllocateObject(self, 0, z);
}
} }
- (unsigned int) countForObject: (id)anObject - (unsigned int) countForObject: (id)anObject
@ -112,13 +109,59 @@ static Class NSCountedSet_concrete_class;
- (id) initWithCoder: (NSCoder*)aCoder - (id) initWithCoder: (NSCoder*)aCoder
{ {
[self subclassResponsibility: _cmd]; unsigned count;
return nil; Class c = fastClass(self);
if (c == NSCountedSet_abstract_class)
{
RELEASE(self);
self = [NSCountedSet_concrete_class allocWithZone: NSDefaultMallocZone()];
return [self initWithCoder: aCoder];
}
[aCoder decodeValueOfObjCType: @encode(unsigned) at: &count];
{
id objs[count];
unsigned refs[count];
unsigned i;
IMP addImp = [self methodForSelector: @selector(addObject:)];
for (i = 0; i < count; i++)
{
[aCoder decodeValueOfObjCType: @encode(id) at: &objs[i]];
[aCoder decodeValueOfObjCType: @encode(unsigned) at: &refs[i]];
}
self = [self initWithObjects: objs count: count];
for (i = 0; i < count; i++)
{
unsigned j = refs[i];
while (j-- > 1)
{
(*addImp)(self, @selector(addObject:), objs[i]);
}
}
}
return self;
}
- (Class) classForCoder
{
return NSCountedSet_abstract_class;
} }
- (void) encodeWithCoder: (NSCoder*)aCoder - (void) encodeWithCoder: (NSCoder*)aCoder
{ {
[self subclassResponsibility: _cmd]; unsigned count = [self count];
NSEnumerator *e = [self objectEnumerator];
id o;
[aCoder encodeValueOfObjCType: @encode(unsigned) at: &count];
while ((o = [e nextObject]) != nil)
{
[aCoder encodeValueOfObjCType: @encode(id) at: &o];
count = [self countForObject: o];
[aCoder encodeValueOfObjCType: @encode(unsigned) at: &count];
}
} }
- (id) initWithSet: (NSSet*)other copyItems: (BOOL)flag - (id) initWithSet: (NSSet*)other copyItems: (BOOL)flag
@ -147,14 +190,15 @@ static Class NSCountedSet_concrete_class;
{ {
unsigned extra = [(NSCountedSet*)other countForObject: os[j]]; unsigned extra = [(NSCountedSet*)other countForObject: os[j]];
if (extra > 1) while (extra-- > 1)
while (--extra) (*addImp)(self, @selector(addObject:), os[j]);
(*addImp)(self, @selector(addObject:), os[j]);
} }
} }
#if !GS_WITH_GC
if (flag) if (flag)
while (i--) while (i--)
[os[i] release]; [os[i] release];
#endif
return self; return self;
} }

View file

@ -110,6 +110,8 @@ static SEL appendSel = @selector(appendBytes:length:);
static Class dataStatic; static Class dataStatic;
static Class dataMalloc; static Class dataMalloc;
static Class mutableDataMalloc; static Class mutableDataMalloc;
static Class NSDataAbstract;
static Class NSMutableDataAbstract;
static IMP appendImp; static IMP appendImp;
static BOOL static BOOL
@ -326,6 +328,8 @@ failure:
{ {
if (self == [NSData class]) if (self == [NSData class])
{ {
NSDataAbstract = self;
NSMutableDataAbstract = [NSMutableData class];
dataMalloc = [NSDataMalloc class]; dataMalloc = [NSDataMalloc class];
dataStatic = [NSDataStatic class]; dataStatic = [NSDataStatic class];
mutableDataMalloc = [NSMutableDataMalloc class]; mutableDataMalloc = [NSMutableDataMalloc class];
@ -335,7 +339,14 @@ failure:
+ (id) allocWithZone: (NSZone*)z + (id) allocWithZone: (NSZone*)z
{ {
return (NSData*)NSAllocateObject(dataMalloc, 0, z); if (self == NSDataAbstract)
{
return NSAllocateObject(dataMalloc, 0, z);
}
else
{
return NSAllocateObject(self, 0, z);
}
} }
+ (id) data + (id) data
@ -1269,7 +1280,14 @@ failure:
@implementation NSMutableData @implementation NSMutableData
+ (id) allocWithZone: (NSZone*)z + (id) allocWithZone: (NSZone*)z
{ {
return (NSData*)NSAllocateObject(mutableDataMalloc, 0, z); if (self == NSMutableDataAbstract)
{
return NSAllocateObject(mutableDataMalloc, 0, z);
}
else
{
return NSAllocateObject(self, 0, z);
}
} }
+ (id) data + (id) data

View file

@ -877,7 +877,7 @@ GSTimeNow()
return abstractClass; return abstractClass;
} }
- replacementObjectForPortCoder: aRmc - (id) replacementObjectForPortCoder: (NSPortCoder*)aRmc
{ {
return self; return self;
} }
@ -928,13 +928,13 @@ GSTimeNow()
{ {
// Get the current time, add the secs and init thyself // Get the current time, add the secs and init thyself
return [self initWithTimeIntervalSinceReferenceDate: return [self initWithTimeIntervalSinceReferenceDate:
GSTimeNow() + secsToBeAdded]; GSTimeNow() + secsToBeAdded];
} }
- (id)initWithTimeIntervalSince1970: (NSTimeInterval)seconds - (id)initWithTimeIntervalSince1970: (NSTimeInterval)seconds
{ {
return [self initWithTimeIntervalSinceReferenceDate: return [self initWithTimeIntervalSinceReferenceDate:
UNIX_REFERENCE_INTERVAL + seconds]; UNIX_REFERENCE_INTERVAL + seconds];
} }
- (id) initWithTimeIntervalSinceReferenceDate: (NSTimeInterval)secs - (id) initWithTimeIntervalSinceReferenceDate: (NSTimeInterval)secs
@ -1017,6 +1017,11 @@ GSTimeNow()
- (NSTimeInterval) timeIntervalSinceDate: (NSDate*)otherDate - (NSTimeInterval) timeIntervalSinceDate: (NSDate*)otherDate
{ {
if (otherDate == nil)
{
[NSException raise: NSInvalidArgumentException
format: @"nil argument for timeIntervalSinceDate:"];
}
return otherTime(self) - otherTime(otherDate); return otherTime(self) - otherTime(otherDate);
} }
@ -1035,17 +1040,33 @@ GSTimeNow()
- (NSComparisonResult) compare: (NSDate*)otherDate - (NSComparisonResult) compare: (NSDate*)otherDate
{ {
if (otherDate == self)
{
return NSOrderedSame;
}
if (otherDate == nil)
{
[NSException raise: NSInvalidArgumentException
format: @"nil argument for compare:"];
}
if (otherTime(self) > otherTime(otherDate)) if (otherTime(self) > otherTime(otherDate))
return NSOrderedDescending; {
return NSOrderedDescending;
}
if (otherTime(self) < otherTime(otherDate)) if (otherTime(self) < otherTime(otherDate))
return NSOrderedAscending; {
return NSOrderedAscending;
}
return NSOrderedSame; return NSOrderedSame;
} }
- (NSDate*) earlierDate: (NSDate*)otherDate - (NSDate*) earlierDate: (NSDate*)otherDate
{ {
if (otherDate == nil)
{
[NSException raise: NSInvalidArgumentException
format: @"nil argument for earlierDate:"];
}
if (otherTime(self) > otherTime(otherDate)) if (otherTime(self) > otherTime(otherDate))
return otherDate; return otherDate;
return self; return self;
@ -1053,6 +1074,8 @@ GSTimeNow()
- (BOOL) isEqual: (id)other - (BOOL) isEqual: (id)other
{ {
if (other == nil)
return NO;
if ([other isKindOf: abstractClass] if ([other isKindOf: abstractClass]
&& 1.0 > ABS(otherTime(self) - otherTime(other))) && 1.0 > ABS(otherTime(self) - otherTime(other)))
return YES; return YES;
@ -1061,6 +1084,8 @@ GSTimeNow()
- (BOOL) isEqualToDate: (NSDate*)other - (BOOL) isEqualToDate: (NSDate*)other
{ {
if (other == nil)
return NO;
if (1.0 > ABS(otherTime(self) - otherTime(other))) if (1.0 > ABS(otherTime(self) - otherTime(other)))
return YES; return YES;
return NO; return NO;
@ -1068,6 +1093,11 @@ GSTimeNow()
- (NSDate*) laterDate: (NSDate*)otherDate - (NSDate*) laterDate: (NSDate*)otherDate
{ {
if (otherDate == nil)
{
[NSException raise: NSInvalidArgumentException
format: @"nil argument for laterDate:"];
}
if (otherTime(self) if (otherTime(self)
< otherTime(otherDate)) < otherTime(otherDate))
return otherDate; return otherDate;
@ -1091,19 +1121,21 @@ GSTimeNow()
return [self class]; return [self class];
} }
- replacementObjectForPortCoder: aRmc - (id) replacementObjectForPortCoder: (NSPortCoder*)aRmc
{ {
return self; return self;
} }
- (void) encodeWithCoder: (NSCoder*)coder - (void) encodeWithCoder: (NSCoder*)coder
{ {
[coder encodeValueOfObjCType: @encode(NSTimeInterval) at: &_seconds_since_ref]; [coder encodeValueOfObjCType: @encode(NSTimeInterval)
at: &_seconds_since_ref];
} }
- (id) initWithCoder: (NSCoder*)coder - (id) initWithCoder: (NSCoder*)coder
{ {
[coder decodeValueOfObjCType: @encode(NSTimeInterval) at: &_seconds_since_ref]; [coder decodeValueOfObjCType: @encode(NSTimeInterval)
at: &_seconds_since_ref];
return self; return self;
} }
@ -1123,6 +1155,11 @@ GSTimeNow()
- (NSTimeInterval) timeIntervalSinceDate: (NSDate*)otherDate - (NSTimeInterval) timeIntervalSinceDate: (NSDate*)otherDate
{ {
if (otherDate == nil)
{
[NSException raise: NSInvalidArgumentException
format: @"nil argument for timeIntervalSinceDate:"];
}
return _seconds_since_ref - otherTime(otherDate); return _seconds_since_ref - otherTime(otherDate);
} }
@ -1140,17 +1177,33 @@ GSTimeNow()
- (NSComparisonResult) compare: (NSDate*)otherDate - (NSComparisonResult) compare: (NSDate*)otherDate
{ {
if (otherDate == self)
{
return NSOrderedSame;
}
if (otherDate == nil)
{
[NSException raise: NSInvalidArgumentException
format: @"nil argument for compare:"];
}
if (_seconds_since_ref > otherTime(otherDate)) if (_seconds_since_ref > otherTime(otherDate))
return NSOrderedDescending; {
return NSOrderedDescending;
}
if (_seconds_since_ref < otherTime(otherDate)) if (_seconds_since_ref < otherTime(otherDate))
return NSOrderedAscending; {
return NSOrderedAscending;
}
return NSOrderedSame; return NSOrderedSame;
} }
- (NSDate*) earlierDate: (NSDate*)otherDate - (NSDate*) earlierDate: (NSDate*)otherDate
{ {
if (otherDate == nil)
{
[NSException raise: NSInvalidArgumentException
format: @"nil argument for earlierDate:"];
}
if (_seconds_since_ref > otherTime(otherDate)) if (_seconds_since_ref > otherTime(otherDate))
return otherDate; return otherDate;
return self; return self;
@ -1158,6 +1211,8 @@ GSTimeNow()
- (BOOL) isEqual: (id)other - (BOOL) isEqual: (id)other
{ {
if (other == nil)
return NO;
if ([other isKindOfClass: abstractClass] if ([other isKindOfClass: abstractClass]
&& 1.0 > ABS(_seconds_since_ref - otherTime(other))) && 1.0 > ABS(_seconds_since_ref - otherTime(other)))
return YES; return YES;
@ -1166,6 +1221,8 @@ GSTimeNow()
- (BOOL) isEqualToDate: (NSDate*)other - (BOOL) isEqualToDate: (NSDate*)other
{ {
if (other == nil)
return NO;
if (1.0 > ABS(_seconds_since_ref - otherTime(other))) if (1.0 > ABS(_seconds_since_ref - otherTime(other)))
return YES; return YES;
return NO; return NO;
@ -1173,6 +1230,11 @@ GSTimeNow()
- (NSDate*) laterDate: (NSDate*)otherDate - (NSDate*) laterDate: (NSDate*)otherDate
{ {
if (otherDate == nil)
{
[NSException raise: NSInvalidArgumentException
format: @"nil argument for laterDate:"];
}
if (_seconds_since_ref < otherTime(otherDate)) if (_seconds_since_ref < otherTime(otherDate))
return otherDate; return otherDate;
return self; return self;
@ -1202,7 +1264,7 @@ GSTimeNow()
return [self class]; return [self class];
} }
- replacementObjectForPortCoder: aRmc - (id) replacementObjectForPortCoder: (NSPortCoder*)aRmc
{ {
return self; return self;
} }

View file

@ -59,26 +59,6 @@ static SEL remSel = @selector(removeObjectForKey:);
static SEL setSel = @selector(setObject:forKey:); static SEL setSel = @selector(setObject:forKey:);
static SEL appSel = @selector(appendString:); static SEL appSel = @selector(appendString:);
+ (void) _setConcreteClass: (Class)c
{
NSDictionary_concrete_class = c;
}
+ (void) _setMutableConcreteClass: (Class)c
{
NSMutableDictionary_concrete_class = c;
}
+ (Class) _concreteClass
{
return NSDictionary_concrete_class;
}
+ (Class) _mutableConcreteClass
{
return NSMutableDictionary_concrete_class;
}
+ (void) initialize + (void) initialize
{ {
if (self == [NSDictionary class]) if (self == [NSDictionary class])
@ -95,8 +75,13 @@ static SEL appSel = @selector(appendString:);
+ (id) allocWithZone: (NSZone*)z + (id) allocWithZone: (NSZone*)z
{ {
if (self == NSDictionary_abstract_class) if (self == NSDictionary_abstract_class)
return NSAllocateObject(NSDictionary_concrete_class, 0, z); {
return [super allocWithZone: z]; return NSAllocateObject(NSDictionary_concrete_class, 0, z);
}
else
{
return NSAllocateObject(self, 0, z);
}
} }
/* This is the designated initializer */ /* This is the designated initializer */
@ -863,8 +848,13 @@ static NSString *indentStrings[] = {
+ (id) allocWithZone: (NSZone*)z + (id) allocWithZone: (NSZone*)z
{ {
if (self == NSMutableDictionary_abstract_class) if (self == NSMutableDictionary_abstract_class)
return NSAllocateObject(NSMutableDictionary_concrete_class, 0, z); {
return [super allocWithZone: z]; return NSAllocateObject(NSMutableDictionary_concrete_class, 0, z);
}
else
{
return NSAllocateObject(self, 0, z);
}
} }
- (id) copyWithZone: (NSZone*)z - (id) copyWithZone: (NSZone*)z

View file

@ -29,6 +29,7 @@
#include <Foundation/NSFileHandle.h> #include <Foundation/NSFileHandle.h>
#include <Foundation/UnixFileHandle.h> #include <Foundation/UnixFileHandle.h>
static Class NSFileHandle_abstract_class = nil;
static Class NSFileHandle_concrete_class = nil; static Class NSFileHandle_concrete_class = nil;
@implementation NSFileHandle @implementation NSFileHandle
@ -37,63 +38,72 @@ static Class NSFileHandle_concrete_class = nil;
{ {
if (self == [NSFileHandle class]) if (self == [NSFileHandle class])
{ {
NSFileHandle_abstract_class = self;
NSFileHandle_concrete_class = [UnixFileHandle class]; NSFileHandle_concrete_class = [UnixFileHandle class];
} }
} }
+ (void)_setConcreteClass: (Class)c
{
NSFileHandle_concrete_class = c;
}
+ (Class)_concreteClass
{
return NSFileHandle_concrete_class;
}
+ (id) allocWithZone: (NSZone*)z + (id) allocWithZone: (NSZone*)z
{ {
return NSAllocateObject ([self _concreteClass], 0, z); if (self == NSFileHandle_abstract_class)
{
return NSAllocateObject (NSFileHandle_concrete_class, 0, z);
}
else
{
return NSAllocateObject (self, 0, z);
}
} }
// Allocating and Initializing a FileHandle Object // Allocating and Initializing a FileHandle Object
+ (id) fileHandleForReadingAtPath: (NSString*)path + (id) fileHandleForReadingAtPath: (NSString*)path
{ {
return AUTORELEASE([[[self _concreteClass] alloc] id o = [self allocWithZone: NSDefaultMallocZone()];
initForReadingAtPath: path]);
return AUTORELEASE([o initForReadingAtPath: path]);
} }
+ (id) fileHandleForWritingAtPath: (NSString*)path + (id) fileHandleForWritingAtPath: (NSString*)path
{ {
return AUTORELEASE([[[self _concreteClass] alloc] id o = [self allocWithZone: NSDefaultMallocZone()];
initForWritingAtPath: path]);
return AUTORELEASE([o initForWritingAtPath: path]);
} }
+ (id) fileHandleForUpdatingAtPath: (NSString*)path + (id) fileHandleForUpdatingAtPath: (NSString*)path
{ {
return AUTORELEASE([[[self _concreteClass] alloc] id o = [self allocWithZone: NSDefaultMallocZone()];
initForUpdatingAtPath: path]);
return AUTORELEASE([o initForUpdatingAtPath: path]);
} }
+ (id) fileHandleWithStandardError + (id) fileHandleWithStandardError
{ {
return AUTORELEASE([[[self _concreteClass] alloc] initWithStandardError]); id o = [self allocWithZone: NSDefaultMallocZone()];
return AUTORELEASE([o initWithStandardError]);
} }
+ (id) fileHandleWithStandardInput + (id) fileHandleWithStandardInput
{ {
return AUTORELEASE([[[self _concreteClass] alloc] initWithStandardInput]); id o = [self allocWithZone: NSDefaultMallocZone()];
return AUTORELEASE([o initWithStandardInput]);
} }
+ (id) fileHandleWithStandardOutput + (id) fileHandleWithStandardOutput
{ {
return AUTORELEASE([[[self _concreteClass] alloc] initWithStandardOutput]); id o = [self allocWithZone: NSDefaultMallocZone()];
return AUTORELEASE([o initWithStandardOutput]);
} }
+ (id) fileHandleWithNullDevice + (id) fileHandleWithNullDevice
{ {
return AUTORELEASE([[[self _concreteClass] alloc] initWithNullDevice]); id o = [self allocWithZone: NSDefaultMallocZone()];
return AUTORELEASE([o initWithNullDevice]);
} }
- (id) initWithFileDescriptor: (int)desc - (id) initWithFileDescriptor: (int)desc
@ -277,21 +287,23 @@ NSString* NSFileHandleOperationException =
service: (NSString*)service service: (NSString*)service
protocol: (NSString*)protocol protocol: (NSString*)protocol
{ {
return AUTORELEASE([[[self _concreteClass] alloc] id o = [self allocWithZone: NSDefaultMallocZone()];
initAsClientAtAddress: address
service: service return AUTORELEASE([o initAsClientAtAddress: address
protocol: protocol]); service: service
protocol: protocol]);
} }
+ (id) fileHandleAsClientInBackgroundAtAddress: (NSString*)address + (id) fileHandleAsClientInBackgroundAtAddress: (NSString*)address
service: (NSString*)service service: (NSString*)service
protocol: (NSString*)protocol protocol: (NSString*)protocol
{ {
return AUTORELEASE([[[self _concreteClass] alloc] id o = [self allocWithZone: NSDefaultMallocZone()];
initAsClientInBackgroundAtAddress: address
service: service return AUTORELEASE([o initAsClientInBackgroundAtAddress: address
protocol: protocol service: service
forModes: nil]); protocol: protocol
forModes: nil]);
} }
+ (id) fileHandleAsClientInBackgroundAtAddress: (NSString*)address + (id) fileHandleAsClientInBackgroundAtAddress: (NSString*)address
@ -299,21 +311,23 @@ NSString* NSFileHandleOperationException =
protocol: (NSString*)protocol protocol: (NSString*)protocol
forModes: (NSArray*)modes forModes: (NSArray*)modes
{ {
return AUTORELEASE([[[self _concreteClass] alloc] id o = [self allocWithZone: NSDefaultMallocZone()];
initAsClientInBackgroundAtAddress: address
service: service return AUTORELEASE([o initAsClientInBackgroundAtAddress: address
protocol: protocol service: service
forModes: modes]); protocol: protocol
forModes: modes]);
} }
+ (id) fileHandleAsServerAtAddress: (NSString*)address + (id) fileHandleAsServerAtAddress: (NSString*)address
service: (NSString*)service service: (NSString*)service
protocol: (NSString*)protocol protocol: (NSString*)protocol
{ {
return AUTORELEASE([[[self _concreteClass] alloc] id o = [self allocWithZone: NSDefaultMallocZone()];
initAsServerAtAddress: address
service: service return AUTORELEASE([o initAsServerAtAddress: address
protocol: protocol]); service: service
protocol: protocol]);
} }
- (BOOL) readInProgress - (BOOL) readInProgress

View file

@ -683,3 +683,122 @@ static SEL eqSel = @selector(isEqual:);
return array->_contents_array[--pos]; return array->_contents_array[--pos];
} }
@end @end
@implementation NSGArray (GNUstep)
/*
* The comparator function takes two items as arguments, the first is the
* item to be added, the second is the item already in the array.
* The function should return NSOrderedAscending if the item to be
* added is 'less than' the item in the array, NSOrderedDescending
* if it is greater, and NSOrderedSame if it is equal.
*/
- (unsigned) insertionPosition: (id)item
usingFunction: (NSComparisonResult (*)(id, id))sorter
{
unsigned upper = _count;
unsigned lower = 0;
unsigned index;
if (item == nil)
{
[NSException raise: NSGenericException
format: @"Attempt to find position for nil object in array"];
}
if (sorter == 0)
{
[NSException raise: NSGenericException
format: @"Attempt to find position with null comparator"];
}
/*
* Binary search for an item equal to the one to be inserted.
*/
for (index = upper/2; upper != lower; index = lower+(upper-lower)/2)
{
NSComparisonResult comparison;
comparison = (*sorter)(item, _contents_array[index]);
if (comparison == NSOrderedAscending)
{
upper = index;
}
else if (comparison == NSOrderedDescending)
{
lower = index + 1;
}
else
{
break;
}
}
/*
* Now skip past any equal items so the insertion point is AFTER any
* items that are equal to the new one.
*/
while (index < _count
&& (*sorter)(item, _contents_array[index]) != NSOrderedAscending)
{
index++;
}
return index;
}
- (unsigned) insertionPosition: (id)item
usingSelector: (SEL)comp
{
unsigned upper = _count;
unsigned lower = 0;
unsigned index;
NSComparisonResult (*imp)(id, SEL, id);
if (item == nil)
{
[NSException raise: NSGenericException
format: @"Attempt to find position for nil object in array"];
}
if (comp == 0)
{
[NSException raise: NSGenericException
format: @"Attempt to find position with null comparator"];
}
imp = (NSComparisonResult (*)(id, SEL, id))[item methodForSelector: comp];
if (imp == 0)
{
[NSException raise: NSGenericException
format: @"Attempt to find position with unknown method"];
}
/*
* Binary search for an item equal to the one to be inserted.
*/
for (index = upper/2; upper != lower; index = lower+(upper-lower)/2)
{
NSComparisonResult comparison;
comparison = (*imp)(item, comp, _contents_array[index]);
if (comparison == NSOrderedAscending)
{
upper = index;
}
else if (comparison == NSOrderedDescending)
{
lower = index + 1;
}
else
{
break;
}
}
/*
* Now skip past any equal items so the insertion point is AFTER any
* items that are equal to the new one.
*/
while (index < _count
&& (*imp)(item, comp, _contents_array[index]) != NSOrderedAscending)
{
index++;
}
return index;
}
@end

View file

@ -800,6 +800,77 @@ static IMP msInitImp; /* designated initialiser for mutable */
return strRangeCsNs(self, aString, mask, aRange); return strRangeCsNs(self, aString, mask, aRange);
} }
- (BOOL) boolValue
{
if (_count == 0)
{
return 0;
}
else if (_count == 3
&& (_contents_chars[0] == 'Y' || _contents_chars[0] == 'y')
&& (_contents_chars[1] == 'E' || _contents_chars[1] == 'e')
&& (_contents_chars[2] == 'S' || _contents_chars[2] == 's'))
{
return YES;
}
else
{
char buf[_count+1];
memcpy(buf, _contents_chars, _count);
buf[_count] = '\0';
return atoi(buf);
}
}
- (double) doubleValue
{
if (_count == 0)
{
return 0;
}
else
{
char buf[_count+1];
memcpy(buf, _contents_chars, _count);
buf[_count] = '\0';
return atof(buf);
}
}
- (float) floatValue
{
if (_count == 0)
{
return 0;
}
else
{
char buf[_count+1];
memcpy(buf, _contents_chars, _count);
buf[_count] = '\0';
return (float) atof(buf);
}
}
- (int) intValue
{
if (_count == 0)
{
return 0;
}
else
{
char buf[_count+1];
memcpy(buf, _contents_chars, _count);
buf[_count] = '\0';
return atoi(buf);
}
}
@end @end

View file

@ -25,7 +25,9 @@
#include <config.h> #include <config.h>
#include <Foundation/NSSet.h> #include <Foundation/NSSet.h>
#include <base/behavior.h> #include <base/behavior.h>
#include <base/fast.x>
#include <Foundation/NSAutoreleasePool.h> #include <Foundation/NSAutoreleasePool.h>
#include <Foundation/NSArray.h>
#include <Foundation/NSException.h> #include <Foundation/NSException.h>
#include <Foundation/NSUtilities.h> #include <Foundation/NSUtilities.h>
#include <Foundation/NSString.h> #include <Foundation/NSString.h>
@ -65,9 +67,12 @@
- (id) initWithSet: (NSSet*)d - (id) initWithSet: (NSSet*)d
{ {
[super init]; self = [super init];
set = (NSGSet*)RETAIN(d); if (self != nil)
node = set->map.firstNode; {
set = (NSGSet*)RETAIN(d);
node = set->map.firstNode;
}
return self; return self;
} }
@ -94,11 +99,18 @@
@implementation NSGSet @implementation NSGSet
static Class arrayClass;
static Class setClass;
static Class mutableSetClass;
+ (void) initialize + (void) initialize
{ {
if (self == [NSGSet class]) if (self == [NSGSet class])
{ {
class_add_behavior(self, [NSSetNonCore class]); class_add_behavior(self, [NSSetNonCore class]);
arrayClass = [NSArray class];
setClass = [NSGSet class];
mutableSetClass = [NSGMutableSet class];
} }
} }
@ -113,46 +125,6 @@
[super dealloc]; [super dealloc];
} }
- (void) encodeWithCoder: (NSCoder*)aCoder
{
unsigned count = map.nodeCount;
GSIMapNode node = map.firstNode;
SEL sel = @selector(encodeObject:);
IMP imp = [aCoder methodForSelector: sel];
[aCoder encodeValueOfObjCType: @encode(unsigned) at: &count];
while (node != 0)
{
(*imp)(aCoder, sel, node->key.obj);
node = node->nextInMap;
}
}
- (unsigned) hash
{
return map.nodeCount;
}
- (id) initWithCoder: (NSCoder*)aCoder
{
unsigned count;
id value;
SEL sel = @selector(decodeValueOfObjCType:at:);
IMP imp = [aCoder methodForSelector: sel];
const char *type = @encode(id);
(*imp)(aCoder, sel, @encode(unsigned), &count);
GSIMapInitWithZoneAndCapacity(&map, [self zone], count);
while (count-- > 0)
{
(*imp)(aCoder, sel, type, &value);
GSIMapAddKeyNoRetain(&map, (GSIMapKey)value);
}
return self;
}
/* Designated initialiser */ /* Designated initialiser */
- (id) initWithObjects: (id*)objs count: (unsigned)c - (id) initWithObjects: (id*)objs count: (unsigned)c
{ {
@ -199,6 +171,247 @@
@end @end
@implementation NSGSet (NonCore)
- (NSArray*) allObjects
{
id objs[map.nodeCount];
GSIMapNode node = map.firstNode;
unsigned i = 0;
while (node != 0)
{
objs[i++] = node->key.obj;
node = node->nextInMap;
}
return AUTORELEASE([[arrayClass allocWithZone: NSDefaultMallocZone()]
initWithObjects: objs count: i]);
}
- (id) anyObject
{
if (map.nodeCount > 0)
return map.firstNode->key.obj;
else
return nil;
}
- (void) encodeWithCoder: (NSCoder*)aCoder
{
unsigned count = map.nodeCount;
GSIMapNode node = map.firstNode;
SEL sel = @selector(encodeObject:);
IMP imp = [aCoder methodForSelector: sel];
[aCoder encodeValueOfObjCType: @encode(unsigned) at: &count];
while (node != 0)
{
(*imp)(aCoder, sel, node->key.obj);
node = node->nextInMap;
}
}
- (unsigned) hash
{
return map.nodeCount;
}
- (id) initWithCoder: (NSCoder*)aCoder
{
unsigned count;
id value;
SEL sel = @selector(decodeValueOfObjCType:at:);
IMP imp = [aCoder methodForSelector: sel];
const char *type = @encode(id);
(*imp)(aCoder, sel, @encode(unsigned), &count);
GSIMapInitWithZoneAndCapacity(&map, [self zone], count);
while (count-- > 0)
{
(*imp)(aCoder, sel, type, &value);
GSIMapAddKeyNoRetain(&map, (GSIMapKey)value);
}
return self;
}
- (BOOL) intersectsSet: (NSSet*) otherSet
{
Class c;
/*
* If this set is empty, or the other is nil, this method should return NO.
*/
if (map.nodeCount == 0)
return NO;
if (otherSet == nil)
return NO;
// Loop for all members in otherSet
c = fastClass(otherSet);
if (c == setClass || c == mutableSetClass)
{
GSIMapNode node = ((NSGSet*)otherSet)->map.firstNode;
while (node != 0)
{
if (GSIMapNodeForKey(&map, node->key) != 0)
{
return YES;
}
node = node->nextInMap;
}
}
else
{
NSEnumerator *e;
id o;
e = [otherSet objectEnumerator];
while ((o = [e nextObject])) // 1. pick a member from otherSet.
{
if (GSIMapNodeForKey(&map, (GSIMapKey)o) != 0)
{
return YES;
}
}
}
return NO;
}
- (BOOL) isSubsetOfSet: (NSSet*) otherSet
{
GSIMapNode node = map.firstNode;
// -1. members of this set(self) <= that of otherSet
if (map.nodeCount > [otherSet count])
return NO;
// 0. Loop for all members in this set(self).
while (node != 0)
{
// 1. check the member is in the otherSet.
if ([otherSet member: node->key.obj])
{
// 1.1 if true -> continue, try to check the next member.
node = node->nextInMap;
}
else
{
// 1.2 if false -> return NO;
return NO;
}
}
// 2. return YES; all members in this set are also in the otherSet.
return YES;
}
- (BOOL) isEqualToSet: (NSSet*)other
{
if (other == nil)
{
return NO;
}
else if (other == self)
{
return YES;
}
else
{
Class c = fastClass(other);
if (c == setClass || c == mutableSetClass)
{
if (map.nodeCount != ((NSGSet*)other)->map.nodeCount)
{
return NO;
}
else
{
GSIMapNode node = map.firstNode;
while (node != 0)
{
if (GSIMapNodeForKey(&(((NSGSet*)other)->map), node->key)
== 0)
{
return NO;
}
node = node->nextInMap;
}
}
}
else
{
if (map.nodeCount != [other count])
{
return NO;
}
else
{
GSIMapNode node = map.firstNode;
while (node != 0)
{
if ([other member: node->key.obj] == nil)
{
return NO;
}
node = node->nextInMap;
}
}
}
return YES;
}
}
- (void) makeObjectsPerform: (SEL)aSelector
{
GSIMapNode node = map.firstNode;
while (node != 0)
{
[node->key.obj performSelector: aSelector];
node = node->nextInMap;
}
}
- (void) makeObjectsPerformSelector: (SEL)aSelector
{
GSIMapNode node = map.firstNode;
while (node != 0)
{
[node->key.obj performSelector: aSelector];
node = node->nextInMap;
}
}
- (void) makeObjectsPerformSelector: (SEL)aSelector withObject: argument
{
GSIMapNode node = map.firstNode;
while (node != 0)
{
[node->key.obj performSelector: aSelector withObject: argument];
node = node->nextInMap;
}
}
- (void) makeObjectsPerform: (SEL)aSelector withObject: argument
{
GSIMapNode node = map.firstNode;
while (node != 0)
{
[node->key.obj performSelector: aSelector withObject: argument];
node = node->nextInMap;
}
}
@end
@implementation NSGMutableSet @implementation NSGMutableSet
+ (void) initialize + (void) initialize
@ -217,6 +430,34 @@
return self; return self;
} }
- (id) initWithObjects: (id*)objects
count: (unsigned)count
{
self = [self initWithCapacity: count];
while (count--)
{
id anObject = objects[count];
if (anObject == nil)
{
NSLog(@"Tried to init a set with a nil object");
continue;
}
else
{
GSIMapNode node;
node = GSIMapNodeForKey(&map, (GSIMapKey)anObject);
if (node == 0)
{
GSIMapAddKey(&map, (GSIMapKey)anObject);
}
}
}
return self;
}
- (void) addObject: (NSObject*)anObject - (void) addObject: (NSObject*)anObject
{ {
GSIMapNode node; GSIMapNode node;
@ -224,7 +465,7 @@
if (anObject == nil) if (anObject == nil)
{ {
[NSException raise: NSInvalidArgumentException [NSException raise: NSInvalidArgumentException
format: @"Tried to add nil to set"]; format: @"Tried to add nil to set"];
} }
node = GSIMapNodeForKey(&map, (GSIMapKey)anObject); node = GSIMapNodeForKey(&map, (GSIMapKey)anObject);
if (node == 0) if (node == 0)
@ -249,3 +490,95 @@
} }
@end @end
@implementation NSGMutableSet (NonCore)
- (void) addObjectsFromArray: (NSArray*)array
{
unsigned count = [array count];
while (count--)
{
id anObject = [array objectAtIndex: count];
if (anObject == nil)
{
[NSException raise: NSInvalidArgumentException
format: @"Tried to add nil to set"];
}
else
{
GSIMapNode node;
node = GSIMapNodeForKey(&map, (GSIMapKey)anObject);
if (node == 0)
{
GSIMapAddKey(&map, (GSIMapKey)anObject);
}
}
}
}
- (void) unionSet: (NSSet*) other
{
if (other != self)
{
NSEnumerator *e = [other objectEnumerator];
id anObject;
while ((anObject = [e nextObject]) != nil)
{
GSIMapNode node;
if (anObject == nil)
{
[NSException raise: NSInvalidArgumentException
format: @"Tried to add nil to set"];
}
node = GSIMapNodeForKey(&map, (GSIMapKey)anObject);
if (node == 0)
{
GSIMapAddKey(&map, (GSIMapKey)anObject);
}
}
}
}
- (void) intersectSet: (NSSet*) other
{
if (other != self)
{
GSIMapNode node = map.firstNode;
while (node != 0)
{
GSIMapNode next = node->nextInMap;
if ([other containsObject: node->key.obj] == NO)
{
GSIMapRemoveKey(&map, node->key);
}
node = next;
}
}
}
- (void) minusSet: (NSSet*) other
{
if (other == self)
{
GSIMapCleanMap(&map);
}
else
{
NSEnumerator *e = [other objectEnumerator];
id anObject;
while ((anObject = [e nextObject]) != nil)
{
GSIMapRemoveKey(&map, (GSIMapKey)anObject);
}
}
}
@end

View file

@ -306,7 +306,7 @@
char *r = (char*)_fastMallocBuffer(_count+1); char *r = (char*)_fastMallocBuffer(_count+1);
if (_count > 0) if (_count > 0)
ustrtostr(r,_contents_chars, _count); ustrtostr(r, _contents_chars, _count);
r[_count] = '\0'; r[_count] = '\0';
return r; return r;
} }
@ -498,6 +498,81 @@
return strRangeUsNs(self, aString, mask, aRange); return strRangeUsNs(self, aString, mask, aRange);
} }
- (BOOL) boolValue
{
if (_count == 0)
{
return 0;
}
else
{
char buf[_count+1];
ustrtostr(buf, _contents_chars, _count);
buf[_count] = '\0';
if (_count == 3
&& (_contents_chars[0] == 'Y' || _contents_chars[0] == 'y')
&& (_contents_chars[1] == 'E' || _contents_chars[1] == 'e')
&& (_contents_chars[2] == 'S' || _contents_chars[2] == 's'))
{
return YES;
}
else
{
return atoi(buf);
}
}
}
- (double) doubleValue
{
if (_count == 0)
{
return 0;
}
else
{
char buf[_count+1];
ustrtostr(buf, _contents_chars, _count);
buf[_count] = '\0';
return atof(buf);
}
}
- (float) floatValue
{
if (_count == 0)
{
return 0;
}
else
{
char buf[_count+1];
ustrtostr(buf, _contents_chars, _count);
buf[_count] = '\0';
return (float) atof(buf);
}
}
- (int) intValue
{
if (_count == 0)
{
return 0;
}
else
{
char buf[_count+1];
ustrtostr(buf, _contents_chars, _count);
buf[_count] = '\0';
return atoi(buf);
}
}
@end @end

View file

@ -29,6 +29,7 @@
#include <Foundation/NSHost.h> #include <Foundation/NSHost.h>
#include <Foundation/NSArray.h> #include <Foundation/NSArray.h>
#include <Foundation/NSDictionary.h> #include <Foundation/NSDictionary.h>
#include <Foundation/NSSet.h>
#include <Foundation/NSString.h> #include <Foundation/NSString.h>
#include <Foundation/NSCoder.h> #include <Foundation/NSCoder.h>
#include <netdb.h> #include <netdb.h>
@ -48,62 +49,153 @@
#define INADDR_NONE -1 #define INADDR_NONE -1
#endif #endif
static NSString *localHostName = @"GNUstep local host";
static Class hostClass;
static NSLock *_hostCacheLock = nil; static NSLock *_hostCacheLock = nil;
static BOOL _hostCacheEnabled = YES; static BOOL _hostCacheEnabled = YES;
static NSMutableDictionary *_hostCache = nil; static NSMutableDictionary *_hostCache = nil;
static NSString *myHostName = nil;
@interface NSHost (Private) @interface NSHost (Private)
+ (struct hostent*) _entryForAddress: (NSString*)address;
- (id) _initWithHostEntry: (struct hostent*)entry key: (NSString*)key; - (id) _initWithHostEntry: (struct hostent*)entry key: (NSString*)key;
+ (NSMutableSet*) _localAddresses;
@end @end
@implementation NSHost (Private) @implementation NSHost (Private)
+ (struct hostent*) _entryForAddress: (NSString*)address
{
struct hostent *h = 0;
struct in_addr hostaddr;
#ifndef HAVE_INET_ATON
hostaddr.s_addr = inet_addr([address cString]);
if (hostaddr.s_addr == INADDR_NONE)
{
NSLog(@"Attempt to lookup host entry for bad IP address (%@)", address);
}
#else
if (inet_aton([address cString], (struct in_addr*)&hostaddr.s_addr) == 0)
{
NSLog(@"Attempt to lookup host entry for bad IP address (%@)", address);
}
#endif
else
{
h = gethostbyaddr((char*)&hostaddr, sizeof(hostaddr), AF_INET);
if (h == 0)
{
NSLog(@"Host '%@' not found using 'gethostbyaddr()' - perhaps "
@"the address is wrong or networking is not set up on your "
@"machine", address);
}
}
return h;
}
- (id) _initWithHostEntry: (struct hostent*)entry key: (NSString*)name - (id) _initWithHostEntry: (struct hostent*)entry key: (NSString*)name
{ {
int i; int i;
char *ptr; char *ptr;
struct in_addr in; struct in_addr in;
NSString *h_name; NSString *h_name;
NSMutableSet *names;
NSMutableSet *addresses;
NSMutableSet *extra;
if ((self = [super init]) == nil) if ((self = [super init]) == nil)
{ {
return nil; return nil;
} }
if (name == nil || [name isEqual: @""] == YES) if (name != localHostName && entry == (struct hostent*)NULL)
{
NSLog(@"Host init failed - empty name/address supplied");
RELEASE(self);
return nil;
}
if (entry == (struct hostent*)NULL)
{ {
NSLog(@"Host '%@' init failed - perhaps the name/address is wrong or " NSLog(@"Host '%@' init failed - perhaps the name/address is wrong or "
@"networking is not set up on your machine", name); @"networking is not set up on your machine", name);
RELEASE(self); RELEASE(self);
return nil; return nil;
} }
else if (localHostName == nil && entry != (struct hostent*)NULL)
_names = [NSMutableArray new];
_addresses = [NSMutableArray new];
h_name = [NSString stringWithCString: entry->h_name];
[_names addObject: h_name];
i = 0;
while ((ptr = entry->h_aliases[i++]) != 0)
{ {
[_names addObject: [NSString stringWithCString: ptr]]; NSLog(@"Nil hostname supplied but network database entry is not empty");
RELEASE(self);
return nil;
} }
i = 0; names = [NSMutableSet new];
while ((ptr = entry->h_addr_list[i++]) != 0) addresses = [NSMutableSet new];
{
NSString *addr;
memcpy((void*)&in.s_addr, (const void*)ptr, entry->h_length); if (name == localHostName)
addr = [NSString stringWithCString: (char*)inet_ntoa(in)]; {
[_addresses addObject: addr]; extra = [hostClass _localAddresses];
} }
else
{
extra = nil;
}
for (;;)
{
/*
* We remove all the IP addresses that we have added to the host so
* far from the set of extra addresses available on the current host.
* Then we try to find a new network database entry for one of the
* remaining extra addresses, and loop round to add all the names
* and addresses for that entry.
*/
[extra minusSet: addresses];
while (entry == 0 && [extra count] > 0)
{
NSString *a = [extra anyObject];
entry = [hostClass _entryForAddress: a];
if (entry == 0)
{
/*
* Can't find a database entry for this IP address, but since
* we know the address is valid, we add it to the list of
* addresses for this host anyway.
*/
[addresses addObject: a];
[extra removeObject: a];
}
}
if (entry == 0)
{
break;
}
h_name = [NSString stringWithCString: entry->h_name];
[names addObject: h_name];
if (entry->h_aliases != 0)
{
i = 0;
while ((ptr = entry->h_aliases[i++]) != 0)
{
[names addObject: [NSString stringWithCString: ptr]];
}
}
if (entry->h_addr_list != 0)
{
i = 0;
while ((ptr = entry->h_addr_list[i++]) != 0)
{
NSString *addr;
memcpy((void*)&in.s_addr, (const void*)ptr, entry->h_length);
addr = [NSString stringWithCString: (char*)inet_ntoa(in)];
[addresses addObject: addr];
}
}
entry = 0;
}
_names = [names copy];
RELEASE(names);
_addresses = [addresses copy];
RELEASE(addresses);
if (_hostCacheEnabled == YES) if (_hostCacheEnabled == YES)
{ {
@ -113,6 +205,14 @@ static NSMutableDictionary *_hostCache = nil;
return self; return self;
} }
+ (NSMutableSet*) _localAddresses
{
NSMutableSet *set;
set = [[self currentHost]->_addresses mutableCopy];
[set addObject: @"127.0.0.1"];
return AUTORELEASE(set);
}
@end @end
@implementation NSHost @implementation NSHost
@ -122,8 +222,6 @@ static NSMutableDictionary *_hostCache = nil;
*/ */
#define GSMAXHOSTNAMELEN 255 #define GSMAXHOSTNAMELEN 255
static NSString *myHost = nil;
+ (void) initialize + (void) initialize
{ {
if (self == [NSHost class]) if (self == [NSHost class])
@ -131,24 +229,25 @@ static NSString *myHost = nil;
char buf[GSMAXHOSTNAMELEN+1]; char buf[GSMAXHOSTNAMELEN+1];
int res; int res;
hostClass = self;
res = gethostname(buf, GSMAXHOSTNAMELEN); res = gethostname(buf, GSMAXHOSTNAMELEN);
if (res < 0) if (res < 0 || *buf == '\0')
{ {
NSLog(@"Unable to get name of current host - using 'localhost'"); NSLog(@"Unable to get name of current host - using 'localhost'");
myHost = @"localhost"; myHostName = @"localhost";
} }
else else
{ {
myHost = [[NSString alloc] initWithCString: buf]; myHostName = [[NSString alloc] initWithCString: buf];
} }
_hostCacheLock = [[NSLock alloc] init]; _hostCacheLock = [[NSRecursiveLock alloc] init];
_hostCache = [NSMutableDictionary new]; _hostCache = [NSMutableDictionary new];
} }
} }
+ (NSHost*) currentHost + (NSHost*) currentHost
{ {
return [self hostWithName: myHost]; return [self hostWithName: myHostName];
} }
+ (NSHost*) hostWithName: (NSString*)name + (NSHost*) hostWithName: (NSString*)name
@ -160,6 +259,11 @@ static NSString *myHost = nil;
NSLog(@"Nil host name sent to [NSHost +hostWithName:]"); NSLog(@"Nil host name sent to [NSHost +hostWithName:]");
return nil; return nil;
} }
if ([name isEqual: @""] == YES)
{
NSLog(@"Empty host name sent to [NSHost +hostWithName:]");
return nil;
}
[_hostCacheLock lock]; [_hostCacheLock lock];
if (_hostCacheEnabled == YES) if (_hostCacheEnabled == YES)
@ -168,19 +272,31 @@ static NSString *myHost = nil;
} }
if (host == nil) if (host == nil)
{ {
struct hostent *h; if (name == localHostName)
h = gethostbyname((char*)[name cString]);
if (h == 0)
{ {
NSLog(@"Host '%@' not found using 'gethostbyname()' - perhaps " /*
@"the hostname is wrong or networking is not set up on your " * Special GNUstep extension host - we try to have a host entry
@"machine", name); * with ALL the IP addresses of any interfaaces on the local machine
*/
host = [[self alloc] _initWithHostEntry: 0 key: name];
AUTORELEASE(host);
} }
else else
{ {
host = [[self alloc] _initWithHostEntry: h key: name]; struct hostent *h = 0;
AUTORELEASE(host);
h = gethostbyname((char*)[name cString]);
if (h == 0)
{
NSLog(@"Host '%@' not found using 'gethostbyname()' - perhaps "
@"the hostname is wrong or networking is not set up on your "
@"machine", name);
}
else
{
host = [[self alloc] _initWithHostEntry: h key: name];
AUTORELEASE(host);
}
} }
} }
[_hostCacheLock unlock]; [_hostCacheLock unlock];
@ -196,6 +312,11 @@ static NSString *myHost = nil;
NSLog(@"Nil host address sent to [NSHost +hostWithName:]"); NSLog(@"Nil host address sent to [NSHost +hostWithName:]");
return nil; return nil;
} }
if ([address isEqual: @""] == YES)
{
NSLog(@"Empty host address sent to [NSHost +hostWithName:]");
return nil;
}
[_hostCacheLock lock]; [_hostCacheLock lock];
if (_hostCacheEnabled == YES) if (_hostCacheEnabled == YES)
@ -206,35 +327,12 @@ static NSString *myHost = nil;
if (host == nil) if (host == nil)
{ {
struct hostent *h; struct hostent *h;
struct in_addr hostaddr;
BOOL addrOk = YES;
#ifndef HAVE_INET_ATON h = [self _entryForAddress: address];
hostaddr.s_addr = inet_addr([address cString]); if (h != 0)
if (hostaddr.s_addr == INADDR_NONE)
{ {
addrOk = NO; host = [[self alloc] _initWithHostEntry: h key: address];
} AUTORELEASE(host);
#else
if (inet_aton([address cString], (struct in_addr*)&hostaddr.s_addr) == 0)
{
addrOk = NO;
}
#endif
if (addrOk == YES)
{
h = gethostbyaddr((char*)&hostaddr, sizeof(hostaddr), AF_INET);
if (h == 0)
{
NSLog(@"Host '%@' not found using 'gethostbyaddr()' - perhaps "
@"the address is wrong or networking is not set up on your "
@"machine", address);
}
else
{
host = [[self alloc] _initWithHostEntry: h key: address];
AUTORELEASE(host);
}
} }
} }
[_hostCacheLock unlock]; [_hostCacheLock unlock];
@ -250,13 +348,7 @@ static NSString *myHost = nil;
+ (BOOL) isHostCacheEnabled; + (BOOL) isHostCacheEnabled;
{ {
BOOL res; return _hostCacheEnabled;
[_hostCacheLock lock];
res = _hostCacheEnabled;
[_hostCacheLock unlock];
return res;
} }
+ (void) flushHostCache + (void) flushHostCache
@ -279,7 +371,21 @@ static NSString *myHost = nil;
- (void) encodeWithCoder: (NSCoder*)aCoder - (void) encodeWithCoder: (NSCoder*)aCoder
{ {
[aCoder encodeObject: [self address]]; NSString *address = [self address];
if ([address isEqual: @"127.0.0.1"] == YES)
{
NSEnumerator *e = [_addresses objectEnumerator];
while ((address = [e nextObject]) != nil)
{
if ([address isEqual: @"127.0.0.1"] == NO)
{
break;
}
}
}
[aCoder encodeObject: address];
} }
- (id) initWithCoder: (NSCoder*)aCoder - (id) initWithCoder: (NSCoder*)aCoder
@ -288,7 +394,15 @@ static NSString *myHost = nil;
NSHost *host; NSHost *host;
address = [aCoder decodeObject]; address = [aCoder decodeObject];
host = RETAIN([NSHost hostWithAddress: address]); if (address != nil)
{
host = [NSHost hostWithAddress: address];
}
else
{
host = [NSHost currentHost];
}
RETAIN(host);
RELEASE(self); RELEASE(self);
return host; return host;
} }
@ -324,52 +438,68 @@ static NSString *myHost = nil;
- (BOOL) isEqual: (id)other - (BOOL) isEqual: (id)other
{ {
if (other == self) if (other == self)
return YES; {
return YES;
}
if ([other isKindOfClass: [NSHost class]]) if ([other isKindOfClass: [NSHost class]])
return [self isEqualToHost: (NSHost*)other]; {
return [self isEqualToHost: (NSHost*)other];
}
return NO; return NO;
} }
- (BOOL) isEqualToHost: (NSHost*)aHost - (BOOL) isEqualToHost: (NSHost*)aHost
{ {
NSArray* a; NSEnumerator *e;
int i; NSString *a;
if (aHost == self) if (aHost == self)
return YES; {
a = [aHost addresses];
for (i = 0; i < [a count]; i++)
if ([_addresses containsObject: [a objectAtIndex: i]])
return YES; return YES;
}
e = [aHost->_addresses objectEnumerator];
while ((a = [e nextObject]) != nil)
{
if ([_addresses member: a] != nil)
{
return YES;
}
}
return NO; return NO;
} }
- (NSString*) name - (NSString*) name
{ {
return [_names objectAtIndex: 0]; return [_names anyObject];
} }
- (NSArray*) names - (NSArray*) names
{ {
return _names; return [_names allObjects];
} }
- (NSString*) address - (NSString*) address
{ {
return [_addresses objectAtIndex: 0]; return [_addresses anyObject];
} }
- (NSArray*) addresses - (NSArray*) addresses
{ {
return _addresses; return [_addresses allObjects];
} }
- (NSString*) description - (NSString*) description
{ {
return [NSString stringWithFormat: @"Host %@ (%@ %@)", return [NSString stringWithFormat: @"Host %@ (%@ %@)",
[self name], [self names], [self addresses]]; [self name], _names, _addresses];
} }
@end @end
@implementation NSHost (GNUstep)
+ (NSHost*) localHost
{
return [self hostWithName: localHostName];
}
@end

View file

@ -302,7 +302,7 @@ static Class doubleNumberClass;
} }
} }
+ (NSNumber*) numberWithChar: (char)value + (NSNumber*) numberWithChar: (signed char)value
{ {
NSNumber *theObj; NSNumber *theObj;
@ -336,7 +336,7 @@ static Class doubleNumberClass;
return AUTORELEASE(theObj); return AUTORELEASE(theObj);
} }
+ (NSNumber*) numberWithInt: (int)value + (NSNumber*) numberWithInt: (signed int)value
{ {
NSNumber *theObj; NSNumber *theObj;
@ -350,7 +350,7 @@ static Class doubleNumberClass;
return AUTORELEASE(theObj); return AUTORELEASE(theObj);
} }
+ (NSNumber*) numberWithLong: (long)value + (NSNumber*) numberWithLong: (signed long)value
{ {
NSNumber *theObj; NSNumber *theObj;
@ -364,7 +364,7 @@ static Class doubleNumberClass;
return AUTORELEASE(theObj); return AUTORELEASE(theObj);
} }
+ (NSNumber*) numberWithLongLong: (long long)value + (NSNumber*) numberWithLongLong: (signed long long)value
{ {
NSNumber *theObj; NSNumber *theObj;
@ -378,7 +378,7 @@ static Class doubleNumberClass;
return AUTORELEASE(theObj); return AUTORELEASE(theObj);
} }
+ (NSNumber*) numberWithShort: (short)value + (NSNumber*) numberWithShort: (signed short)value
{ {
NSNumber *theObj; NSNumber *theObj;
@ -500,7 +500,7 @@ static Class doubleNumberClass;
return RETAIN(self); return RETAIN(self);
} }
- (id) initWithChar: (char)value - (id) initWithChar: (signed char)value
{ {
NSDeallocateObject(self); NSDeallocateObject(self);
if (value <= GS_SMALL && value >= -GS_SMALL) if (value <= GS_SMALL && value >= -GS_SMALL)
@ -531,7 +531,7 @@ static Class doubleNumberClass;
return self; return self;
} }
- (id) initWithInt: (int)value - (id) initWithInt: (signed int)value
{ {
NSDeallocateObject(self); NSDeallocateObject(self);
if (value <= GS_SMALL && value >= -GS_SMALL) if (value <= GS_SMALL && value >= -GS_SMALL)
@ -544,7 +544,7 @@ static Class doubleNumberClass;
return self; return self;
} }
- (id) initWithLong: (long)value - (id) initWithLong: (signed long)value
{ {
NSDeallocateObject(self); NSDeallocateObject(self);
if (value <= GS_SMALL && value >= -GS_SMALL) if (value <= GS_SMALL && value >= -GS_SMALL)
@ -557,7 +557,7 @@ static Class doubleNumberClass;
return self; return self;
} }
- (id) initWithLongLong: (long long)value - (id) initWithLongLong: (signed long long)value
{ {
NSDeallocateObject(self); NSDeallocateObject(self);
if (value <= GS_SMALL && value >= -GS_SMALL) if (value <= GS_SMALL && value >= -GS_SMALL)
@ -570,7 +570,7 @@ static Class doubleNumberClass;
return self; return self;
} }
- (id) initWithShort: (short)value - (id) initWithShort: (signed short)value
{ {
NSDeallocateObject(self); NSDeallocateObject(self);
if (value <= GS_SMALL && value >= -GS_SMALL) if (value <= GS_SMALL && value >= -GS_SMALL)
@ -742,7 +742,7 @@ static Class doubleNumberClass;
} }
case 1: case 1:
{ {
char oData; signed char oData;
(*(info->getValue))(self, @selector(getValue:), &oData); (*(info->getValue))(self, @selector(getValue:), &oData);
return oData; return oData;
@ -756,7 +756,7 @@ static Class doubleNumberClass;
} }
case 3: case 3:
{ {
short oData; signed short oData;
(*(info->getValue))(self, @selector(getValue:), &oData); (*(info->getValue))(self, @selector(getValue:), &oData);
return oData; return oData;
@ -770,7 +770,7 @@ static Class doubleNumberClass;
} }
case 5: case 5:
{ {
int oData; signed int oData;
(*(info->getValue))(self, @selector(getValue:), &oData); (*(info->getValue))(self, @selector(getValue:), &oData);
return oData; return oData;
@ -784,7 +784,7 @@ static Class doubleNumberClass;
} }
case 7: case 7:
{ {
long oData; signed long oData;
(*(info->getValue))(self, @selector(getValue:), &oData); (*(info->getValue))(self, @selector(getValue:), &oData);
return oData; return oData;
@ -798,7 +798,7 @@ static Class doubleNumberClass;
} }
case 9: case 9:
{ {
long long oData; signed long long oData;
(*(info->getValue))(self, @selector(getValue:), &oData); (*(info->getValue))(self, @selector(getValue:), &oData);
return oData; return oData;
@ -832,7 +832,7 @@ static Class doubleNumberClass;
return 0; return 0;
} }
- (char) charValue - (signed char) charValue
{ {
if (fastClass(self) == abstractClass) if (fastClass(self) == abstractClass)
[NSException raise: NSInternalInconsistencyException [NSException raise: NSInternalInconsistencyException
@ -852,7 +852,7 @@ static Class doubleNumberClass;
} }
case 1: case 1:
{ {
char oData; signed char oData;
(*(info->getValue))(self, @selector(getValue:), &oData); (*(info->getValue))(self, @selector(getValue:), &oData);
return oData; return oData;
@ -866,7 +866,7 @@ static Class doubleNumberClass;
} }
case 3: case 3:
{ {
short oData; signed short oData;
(*(info->getValue))(self, @selector(getValue:), &oData); (*(info->getValue))(self, @selector(getValue:), &oData);
return oData; return oData;
@ -880,7 +880,7 @@ static Class doubleNumberClass;
} }
case 5: case 5:
{ {
int oData; signed int oData;
(*(info->getValue))(self, @selector(getValue:), &oData); (*(info->getValue))(self, @selector(getValue:), &oData);
return oData; return oData;
@ -894,7 +894,7 @@ static Class doubleNumberClass;
} }
case 7: case 7:
{ {
long oData; signed long oData;
(*(info->getValue))(self, @selector(getValue:), &oData); (*(info->getValue))(self, @selector(getValue:), &oData);
return oData; return oData;
@ -908,7 +908,7 @@ static Class doubleNumberClass;
} }
case 9: case 9:
{ {
long long oData; signed long long oData;
(*(info->getValue))(self, @selector(getValue:), &oData); (*(info->getValue))(self, @selector(getValue:), &oData);
return oData; return oData;
@ -962,7 +962,7 @@ static Class doubleNumberClass;
} }
case 1: case 1:
{ {
char oData; signed char oData;
(*(info->getValue))(self, @selector(getValue:), &oData); (*(info->getValue))(self, @selector(getValue:), &oData);
return oData; return oData;
@ -976,7 +976,7 @@ static Class doubleNumberClass;
} }
case 3: case 3:
{ {
short oData; signed short oData;
(*(info->getValue))(self, @selector(getValue:), &oData); (*(info->getValue))(self, @selector(getValue:), &oData);
return oData; return oData;
@ -990,7 +990,7 @@ static Class doubleNumberClass;
} }
case 5: case 5:
{ {
int oData; signed int oData;
(*(info->getValue))(self, @selector(getValue:), &oData); (*(info->getValue))(self, @selector(getValue:), &oData);
return oData; return oData;
@ -1004,7 +1004,7 @@ static Class doubleNumberClass;
} }
case 7: case 7:
{ {
long oData; signed long oData;
(*(info->getValue))(self, @selector(getValue:), &oData); (*(info->getValue))(self, @selector(getValue:), &oData);
return oData; return oData;
@ -1018,7 +1018,7 @@ static Class doubleNumberClass;
} }
case 9: case 9:
{ {
long long oData; signed long long oData;
(*(info->getValue))(self, @selector(getValue:), &oData); (*(info->getValue))(self, @selector(getValue:), &oData);
return oData; return oData;
@ -1072,7 +1072,7 @@ static Class doubleNumberClass;
} }
case 1: case 1:
{ {
char oData; signed char oData;
(*(info->getValue))(self, @selector(getValue:), &oData); (*(info->getValue))(self, @selector(getValue:), &oData);
return oData; return oData;
@ -1086,7 +1086,7 @@ static Class doubleNumberClass;
} }
case 3: case 3:
{ {
short oData; signed short oData;
(*(info->getValue))(self, @selector(getValue:), &oData); (*(info->getValue))(self, @selector(getValue:), &oData);
return oData; return oData;
@ -1100,7 +1100,7 @@ static Class doubleNumberClass;
} }
case 5: case 5:
{ {
int oData; signed int oData;
(*(info->getValue))(self, @selector(getValue:), &oData); (*(info->getValue))(self, @selector(getValue:), &oData);
return oData; return oData;
@ -1114,7 +1114,7 @@ static Class doubleNumberClass;
} }
case 7: case 7:
{ {
long oData; signed long oData;
(*(info->getValue))(self, @selector(getValue:), &oData); (*(info->getValue))(self, @selector(getValue:), &oData);
return oData; return oData;
@ -1128,7 +1128,7 @@ static Class doubleNumberClass;
} }
case 9: case 9:
{ {
long long oData; signed long long oData;
(*(info->getValue))(self, @selector(getValue:), &oData); (*(info->getValue))(self, @selector(getValue:), &oData);
return oData; return oData;
@ -1162,7 +1162,7 @@ static Class doubleNumberClass;
return 0; return 0;
} }
- (int) intValue - (signed int) intValue
{ {
if (fastClass(self) == abstractClass) if (fastClass(self) == abstractClass)
[NSException raise: NSInternalInconsistencyException [NSException raise: NSInternalInconsistencyException
@ -1182,7 +1182,7 @@ static Class doubleNumberClass;
} }
case 1: case 1:
{ {
char oData; signed char oData;
(*(info->getValue))(self, @selector(getValue:), &oData); (*(info->getValue))(self, @selector(getValue:), &oData);
return oData; return oData;
@ -1196,7 +1196,7 @@ static Class doubleNumberClass;
} }
case 3: case 3:
{ {
short oData; signed short oData;
(*(info->getValue))(self, @selector(getValue:), &oData); (*(info->getValue))(self, @selector(getValue:), &oData);
return oData; return oData;
@ -1210,7 +1210,7 @@ static Class doubleNumberClass;
} }
case 5: case 5:
{ {
int oData; signed int oData;
(*(info->getValue))(self, @selector(getValue:), &oData); (*(info->getValue))(self, @selector(getValue:), &oData);
return oData; return oData;
@ -1224,7 +1224,7 @@ static Class doubleNumberClass;
} }
case 7: case 7:
{ {
long oData; signed long oData;
(*(info->getValue))(self, @selector(getValue:), &oData); (*(info->getValue))(self, @selector(getValue:), &oData);
return oData; return oData;
@ -1238,7 +1238,7 @@ static Class doubleNumberClass;
} }
case 9: case 9:
{ {
long long oData; signed long long oData;
(*(info->getValue))(self, @selector(getValue:), &oData); (*(info->getValue))(self, @selector(getValue:), &oData);
return oData; return oData;
@ -1272,7 +1272,7 @@ static Class doubleNumberClass;
return 0; return 0;
} }
- (long long) longLongValue - (signed long long) longLongValue
{ {
if (fastClass(self) == abstractClass) if (fastClass(self) == abstractClass)
[NSException raise: NSInternalInconsistencyException [NSException raise: NSInternalInconsistencyException
@ -1292,7 +1292,7 @@ static Class doubleNumberClass;
} }
case 1: case 1:
{ {
char oData; signed char oData;
(*(info->getValue))(self, @selector(getValue:), &oData); (*(info->getValue))(self, @selector(getValue:), &oData);
return oData; return oData;
@ -1306,7 +1306,7 @@ static Class doubleNumberClass;
} }
case 3: case 3:
{ {
short oData; signed short oData;
(*(info->getValue))(self, @selector(getValue:), &oData); (*(info->getValue))(self, @selector(getValue:), &oData);
return oData; return oData;
@ -1320,7 +1320,7 @@ static Class doubleNumberClass;
} }
case 5: case 5:
{ {
int oData; signed int oData;
(*(info->getValue))(self, @selector(getValue:), &oData); (*(info->getValue))(self, @selector(getValue:), &oData);
return oData; return oData;
@ -1334,7 +1334,7 @@ static Class doubleNumberClass;
} }
case 7: case 7:
{ {
long oData; signed long oData;
(*(info->getValue))(self, @selector(getValue:), &oData); (*(info->getValue))(self, @selector(getValue:), &oData);
return oData; return oData;
@ -1348,7 +1348,7 @@ static Class doubleNumberClass;
} }
case 9: case 9:
{ {
long long oData; signed long long oData;
(*(info->getValue))(self, @selector(getValue:), &oData); (*(info->getValue))(self, @selector(getValue:), &oData);
return oData; return oData;
@ -1382,7 +1382,7 @@ static Class doubleNumberClass;
return 0; return 0;
} }
- (long) longValue - (signed long) longValue
{ {
if (fastClass(self) == abstractClass) if (fastClass(self) == abstractClass)
[NSException raise: NSInternalInconsistencyException [NSException raise: NSInternalInconsistencyException
@ -1402,7 +1402,7 @@ static Class doubleNumberClass;
} }
case 1: case 1:
{ {
char oData; signed char oData;
(*(info->getValue))(self, @selector(getValue:), &oData); (*(info->getValue))(self, @selector(getValue:), &oData);
return oData; return oData;
@ -1416,7 +1416,7 @@ static Class doubleNumberClass;
} }
case 3: case 3:
{ {
short oData; signed short oData;
(*(info->getValue))(self, @selector(getValue:), &oData); (*(info->getValue))(self, @selector(getValue:), &oData);
return oData; return oData;
@ -1430,7 +1430,7 @@ static Class doubleNumberClass;
} }
case 5: case 5:
{ {
int oData; signed int oData;
(*(info->getValue))(self, @selector(getValue:), &oData); (*(info->getValue))(self, @selector(getValue:), &oData);
return oData; return oData;
@ -1444,7 +1444,7 @@ static Class doubleNumberClass;
} }
case 7: case 7:
{ {
long oData; signed long oData;
(*(info->getValue))(self, @selector(getValue:), &oData); (*(info->getValue))(self, @selector(getValue:), &oData);
return oData; return oData;
@ -1458,7 +1458,7 @@ static Class doubleNumberClass;
} }
case 9: case 9:
{ {
long long oData; signed long long oData;
(*(info->getValue))(self, @selector(getValue:), &oData); (*(info->getValue))(self, @selector(getValue:), &oData);
return oData; return oData;
@ -1492,7 +1492,7 @@ static Class doubleNumberClass;
return 0; return 0;
} }
- (short) shortValue - (signed short) shortValue
{ {
if (fastClass(self) == abstractClass) if (fastClass(self) == abstractClass)
[NSException raise: NSInternalInconsistencyException [NSException raise: NSInternalInconsistencyException
@ -1512,7 +1512,7 @@ static Class doubleNumberClass;
} }
case 1: case 1:
{ {
char oData; signed char oData;
(*(info->getValue))(self, @selector(getValue:), &oData); (*(info->getValue))(self, @selector(getValue:), &oData);
return oData; return oData;
@ -1526,7 +1526,7 @@ static Class doubleNumberClass;
} }
case 3: case 3:
{ {
short oData; signed short oData;
(*(info->getValue))(self, @selector(getValue:), &oData); (*(info->getValue))(self, @selector(getValue:), &oData);
return oData; return oData;
@ -1540,7 +1540,7 @@ static Class doubleNumberClass;
} }
case 5: case 5:
{ {
int oData; signed int oData;
(*(info->getValue))(self, @selector(getValue:), &oData); (*(info->getValue))(self, @selector(getValue:), &oData);
return oData; return oData;
@ -1554,7 +1554,7 @@ static Class doubleNumberClass;
} }
case 7: case 7:
{ {
long oData; signed long oData;
(*(info->getValue))(self, @selector(getValue:), &oData); (*(info->getValue))(self, @selector(getValue:), &oData);
return oData; return oData;
@ -1568,7 +1568,7 @@ static Class doubleNumberClass;
} }
case 9: case 9:
{ {
long long oData; signed long long oData;
(*(info->getValue))(self, @selector(getValue:), &oData); (*(info->getValue))(self, @selector(getValue:), &oData);
return oData; return oData;
@ -1627,7 +1627,7 @@ static Class doubleNumberClass;
} }
case 1: case 1:
{ {
char oData; signed char oData;
(*(info->getValue))(self, @selector(getValue:), &oData); (*(info->getValue))(self, @selector(getValue:), &oData);
return oData; return oData;
@ -1641,7 +1641,7 @@ static Class doubleNumberClass;
} }
case 3: case 3:
{ {
short oData; signed short oData;
(*(info->getValue))(self, @selector(getValue:), &oData); (*(info->getValue))(self, @selector(getValue:), &oData);
return oData; return oData;
@ -1655,7 +1655,7 @@ static Class doubleNumberClass;
} }
case 5: case 5:
{ {
int oData; signed int oData;
(*(info->getValue))(self, @selector(getValue:), &oData); (*(info->getValue))(self, @selector(getValue:), &oData);
return oData; return oData;
@ -1669,7 +1669,7 @@ static Class doubleNumberClass;
} }
case 7: case 7:
{ {
long oData; signed long oData;
(*(info->getValue))(self, @selector(getValue:), &oData); (*(info->getValue))(self, @selector(getValue:), &oData);
return oData; return oData;
@ -1683,7 +1683,7 @@ static Class doubleNumberClass;
} }
case 9: case 9:
{ {
long long oData; signed long long oData;
(*(info->getValue))(self, @selector(getValue:), &oData); (*(info->getValue))(self, @selector(getValue:), &oData);
return oData; return oData;
@ -1737,7 +1737,7 @@ static Class doubleNumberClass;
} }
case 1: case 1:
{ {
char oData; signed char oData;
(*(info->getValue))(self, @selector(getValue:), &oData); (*(info->getValue))(self, @selector(getValue:), &oData);
return oData; return oData;
@ -1751,7 +1751,7 @@ static Class doubleNumberClass;
} }
case 3: case 3:
{ {
short oData; signed short oData;
(*(info->getValue))(self, @selector(getValue:), &oData); (*(info->getValue))(self, @selector(getValue:), &oData);
return oData; return oData;
@ -1765,7 +1765,7 @@ static Class doubleNumberClass;
} }
case 5: case 5:
{ {
int oData; signed int oData;
(*(info->getValue))(self, @selector(getValue:), &oData); (*(info->getValue))(self, @selector(getValue:), &oData);
return oData; return oData;
@ -1779,7 +1779,7 @@ static Class doubleNumberClass;
} }
case 7: case 7:
{ {
long oData; signed long oData;
(*(info->getValue))(self, @selector(getValue:), &oData); (*(info->getValue))(self, @selector(getValue:), &oData);
return oData; return oData;
@ -1793,7 +1793,7 @@ static Class doubleNumberClass;
} }
case 9: case 9:
{ {
long long oData; signed long long oData;
(*(info->getValue))(self, @selector(getValue:), &oData); (*(info->getValue))(self, @selector(getValue:), &oData);
return oData; return oData;
@ -1847,7 +1847,7 @@ static Class doubleNumberClass;
} }
case 1: case 1:
{ {
char oData; signed char oData;
(*(info->getValue))(self, @selector(getValue:), &oData); (*(info->getValue))(self, @selector(getValue:), &oData);
return oData; return oData;
@ -1861,7 +1861,7 @@ static Class doubleNumberClass;
} }
case 3: case 3:
{ {
short oData; signed short oData;
(*(info->getValue))(self, @selector(getValue:), &oData); (*(info->getValue))(self, @selector(getValue:), &oData);
return oData; return oData;
@ -1875,7 +1875,7 @@ static Class doubleNumberClass;
} }
case 5: case 5:
{ {
int oData; signed int oData;
(*(info->getValue))(self, @selector(getValue:), &oData); (*(info->getValue))(self, @selector(getValue:), &oData);
return oData; return oData;
@ -1889,7 +1889,7 @@ static Class doubleNumberClass;
} }
case 7: case 7:
{ {
long oData; signed long oData;
(*(info->getValue))(self, @selector(getValue:), &oData); (*(info->getValue))(self, @selector(getValue:), &oData);
return oData; return oData;
@ -1903,7 +1903,7 @@ static Class doubleNumberClass;
} }
case 9: case 9:
{ {
long long oData; signed long long oData;
(*(info->getValue))(self, @selector(getValue:), &oData); (*(info->getValue))(self, @selector(getValue:), &oData);
return oData; return oData;
@ -1957,7 +1957,7 @@ static Class doubleNumberClass;
} }
case 1: case 1:
{ {
char oData; signed char oData;
(*(info->getValue))(self, @selector(getValue:), &oData); (*(info->getValue))(self, @selector(getValue:), &oData);
return oData; return oData;
@ -1971,7 +1971,7 @@ static Class doubleNumberClass;
} }
case 3: case 3:
{ {
short oData; signed short oData;
(*(info->getValue))(self, @selector(getValue:), &oData); (*(info->getValue))(self, @selector(getValue:), &oData);
return oData; return oData;
@ -1985,7 +1985,7 @@ static Class doubleNumberClass;
} }
case 5: case 5:
{ {
int oData; signed int oData;
(*(info->getValue))(self, @selector(getValue:), &oData); (*(info->getValue))(self, @selector(getValue:), &oData);
return oData; return oData;
@ -1999,7 +1999,7 @@ static Class doubleNumberClass;
} }
case 7: case 7:
{ {
long oData; signed long oData;
(*(info->getValue))(self, @selector(getValue:), &oData); (*(info->getValue))(self, @selector(getValue:), &oData);
return oData; return oData;
@ -2013,7 +2013,7 @@ static Class doubleNumberClass;
} }
case 9: case 9:
{ {
long long oData; signed long long oData;
(*(info->getValue))(self, @selector(getValue:), &oData); (*(info->getValue))(self, @selector(getValue:), &oData);
return oData; return oData;
@ -2067,7 +2067,7 @@ static Class doubleNumberClass;
} }
case 1: case 1:
{ {
char oData; signed char oData;
(*(info->getValue))(self, @selector(getValue:), &oData); (*(info->getValue))(self, @selector(getValue:), &oData);
return oData; return oData;
@ -2081,7 +2081,7 @@ static Class doubleNumberClass;
} }
case 3: case 3:
{ {
short oData; signed short oData;
(*(info->getValue))(self, @selector(getValue:), &oData); (*(info->getValue))(self, @selector(getValue:), &oData);
return oData; return oData;
@ -2095,7 +2095,7 @@ static Class doubleNumberClass;
} }
case 5: case 5:
{ {
int oData; signed int oData;
(*(info->getValue))(self, @selector(getValue:), &oData); (*(info->getValue))(self, @selector(getValue:), &oData);
return oData; return oData;
@ -2109,7 +2109,7 @@ static Class doubleNumberClass;
} }
case 7: case 7:
{ {
long oData; signed long oData;
(*(info->getValue))(self, @selector(getValue:), &oData); (*(info->getValue))(self, @selector(getValue:), &oData);
return oData; return oData;
@ -2123,7 +2123,7 @@ static Class doubleNumberClass;
} }
case 9: case 9:
{ {
long long oData; signed long long oData;
(*(info->getValue))(self, @selector(getValue:), &oData); (*(info->getValue))(self, @selector(getValue:), &oData);
return oData; return oData;
@ -2159,23 +2159,35 @@ static Class doubleNumberClass;
- (NSComparisonResult) compare: (NSNumber*)other - (NSComparisonResult) compare: (NSNumber*)other
{ {
double otherValue; if (other == self)
double myValue;
myValue = [self doubleValue];
otherValue = [other doubleValue];
if (myValue == otherValue)
{ {
return NSOrderedSame; return NSOrderedSame;
} }
else if (myValue < otherValue) else if (other == nil)
{ {
return NSOrderedAscending; [NSException raise: NSInvalidArgumentException
format: @"nil argument for compare:"];
} }
else else
{ {
return NSOrderedDescending; double otherValue;
double myValue;
myValue = [self doubleValue];
otherValue = [other doubleValue];
if (myValue == otherValue)
{
return NSOrderedSame;
}
else if (myValue < otherValue)
{
return NSOrderedAscending;
}
else
{
return NSOrderedDescending;
}
} }
} }
@ -2203,18 +2215,24 @@ static Class doubleNumberClass;
return hash; return hash;
} }
- (BOOL) isEqual: o - (BOOL) isEqual: (id)o
{ {
if (o == self) if (o == self)
{ {
return YES; return YES;
} }
if (o != nil && fastIsInstance(o) else if (o == nil)
&& fastInstanceIsKindOfClass(o, abstractClass)) {
return NO;
}
else if (fastIsInstance(o) && fastInstanceIsKindOfClass(o, abstractClass))
{ {
return [self isEqualToNumber: (NSNumber*)o]; return [self isEqualToNumber: (NSNumber*)o];
} }
return [super isEqual: o]; else
{
return [super isEqual: o];
}
} }
- (BOOL) isEqualToNumber: (NSNumber*)o - (BOOL) isEqualToNumber: (NSNumber*)o
@ -2223,7 +2241,11 @@ static Class doubleNumberClass;
{ {
return YES; return YES;
} }
if ([self compare: o] == NSOrderedSame) else if (o == nil)
{
return NO;
}
else if ([self compare: o] == NSOrderedSame)
{ {
return YES; return YES;
} }

View file

@ -1332,16 +1332,31 @@ static BOOL deallocNotifications = NO;
double_release_check_enabled = enable; double_release_check_enabled = enable;
} }
- (int) compare: (id)anotherObject; - (int) compare: (id)anotherObject
{ {
if ([self isEqual:anotherObject]) if (anotherObject == self)
return 0; {
return NSOrderedSame;
}
if (anotherObject == nil)
{
[NSException raise: NSInvalidArgumentException
format: @"nil argument for compare:"];
}
if ([self isEqual: anotherObject])
{
return NSOrderedSame;
}
// Ordering objects by their address is pretty useless, // Ordering objects by their address is pretty useless,
// so subclasses should override this is some useful way. // so subclasses should override this is some useful way.
else if (self > anotherObject) if (self > anotherObject)
return 1; {
return NSOrderedDescending;
}
else else
return -1; {
return NSOrderedAscending;
}
} }
- (BOOL) isMetaClass - (BOOL) isMetaClass

View file

@ -35,29 +35,33 @@
@implementation NSPort @implementation NSPort
Class _abstractClass; Class NSPort_abstract_class;
Class _concreteClass; Class NSPort_concrete_class;
+ (id) allocWithZone: (NSZone*)aZone + (id) allocWithZone: (NSZone*)aZone
{ {
if (self == _abstractClass) if (self == NSPort_abstract_class)
return NSAllocateObject(_concreteClass, 0, aZone); {
return NSAllocateObject(NSPort_concrete_class, 0, aZone);
}
else else
return [super allocWithZone: aZone]; {
return NSAllocateObject(self, 0, aZone);
}
} }
+ (void) initialize + (void) initialize
{ {
if (self == [NSPort class]) if (self == [NSPort class])
{ {
_abstractClass = self; NSPort_abstract_class = self;
_concreteClass = [GSTcpPort class]; NSPort_concrete_class = [GSTcpPort class];
} }
} }
+ (NSPort*) port + (NSPort*) port
{ {
return AUTORELEASE([_concreteClass new]); return AUTORELEASE([NSPort_concrete_class new]);
} }
+ (NSPort*) portWithMachPort: (int)machPort + (NSPort*) portWithMachPort: (int)machPort
@ -110,11 +114,20 @@ Class _concreteClass;
*/ */
- (void) invalidate - (void) invalidate
{ {
NSAutoreleasePool *arp;
[[NSPortNameServer systemDefaultPortNameServer] removePort: self]; [[NSPortNameServer systemDefaultPortNameServer] removePort: self];
_is_valid = NO; _is_valid = NO;
/*
* Use a local autorelease pool when invalidating so that we know that
* anything refering to this port during the invalidation process is
* released immediately.
*/
arp = [NSAutoreleasePool new];
[[NSNotificationCenter defaultCenter] [[NSNotificationCenter defaultCenter]
postNotificationName: NSPortDidBecomeInvalidNotification postNotificationName: NSPortDidBecomeInvalidNotification
object: self]; object: self];
[arp release];
} }
- (BOOL) isValid - (BOOL) isValid
@ -128,23 +141,27 @@ Class _concreteClass;
return 0; return 0;
} }
- (id) retain
{
return [super retain];
}
- (id) autorelease
{
return [super autorelease];
}
- (void) release - (void) release
{ {
if (_is_valid && [self retainCount] == 1) if (_is_valid && [self retainCount] == 1)
{ {
NSAutoreleasePool *arp;
/* /*
* If the port is about to have a final release deallocate it * If the port is about to have a final release deallocate it
* we must invalidate it. Use a local autorelease pool when * we must invalidate it.
* invalidating so that we know that anything refering to this * Bracket with retain/release pair to prevent recursion.
* port during the invalidation process is released immediately.
* Also - bracket with retain/release pair to prevent recursion.
*/ */
[super retain]; [super retain];
arp = [NSAutoreleasePool new];
[self invalidate]; [self invalidate];
[arp release];
[super release]; [super release];
} }
[super release]; [super release];

View file

@ -1,4 +1,3 @@
#if GS_NEW_DO
/* Implementation of NSPortCoder object for remote messaging /* Implementation of NSPortCoder object for remote messaging
Copyright (C) 1997,2000 Free Software Foundation, Inc. Copyright (C) 1997,2000 Free Software Foundation, Inc.
@ -75,8 +74,6 @@
#include <Foundation/DistributedObjects.h> #include <Foundation/DistributedObjects.h>
static BOOL debug_port_coder = NO;
typedef unsigned char uchar; typedef unsigned char uchar;
#define PREFIX "GNUstep DO archive" #define PREFIX "GNUstep DO archive"
@ -141,6 +138,7 @@ typeToName2(char type)
{ {
switch (type & _GSC_MASK) switch (type & _GSC_MASK)
{ {
case _GSC_CID: return "class (encoded as id)";
case _GSC_CLASS: return "class"; case _GSC_CLASS: return "class";
case _GSC_ID: return "object"; case _GSC_ID: return "object";
case _GSC_SEL: return "selector"; case _GSC_SEL: return "selector";
@ -427,9 +425,12 @@ static IMP _xRefImp; /* Serialize a crossref. */
(*_dTagImp)(_src, dTagSel, &ainfo, 0, &_cursor); (*_dTagImp)(_src, dTagSel, &ainfo, 0, &_cursor);
if (info != (ainfo & _GSC_MASK)) if (info != (ainfo & _GSC_MASK))
{ {
[NSException raise: NSInternalInconsistencyException if (info != _GSC_ID || (ainfo & _GSC_MASK) != _GSC_CID)
format: @"expected %s and got %s", {
typeToName2(info), typeToName2(ainfo)]; [NSException raise: NSInternalInconsistencyException
format: @"expected %s and got %s",
typeToName2(info), typeToName2(ainfo)];
}
} }
for (i = 0; i < count; i++) for (i = 0; i < count; i++)
@ -473,84 +474,6 @@ static IMP _xRefImp; /* Serialize a crossref. */
return [_comp objectAtIndex: pos]; return [_comp objectAtIndex: pos];
} }
/*
* The [-decodeObject] method is implemented purely for performance -
* It duplicates the code for handling objects in the
* [-decodeValueOfObjCType:at:] method above, but differs in that the
* resulting object is autoreleased when it comes from this method.
*/
- (id) decodeObject
{
unsigned char info;
unsigned xref;
id obj;
(*_dTagImp)(_src, dTagSel, &info, &xref, &_cursor);
if ((info & _GSC_MASK) != _GSC_ID)
{
[NSException raise: NSInternalInconsistencyException
format: @"expected object and got %s", typeToName2(info)];
}
/*
* Special case - a zero crossref value is a nil pointer.
*/
if ((info & _GSC_SIZE) == 0)
{
return nil;
}
if (info & _GSC_XREF)
{
if (xref >= GSIArrayCount(_objAry))
{
[NSException raise: NSInternalInconsistencyException
format: @"object crossref missing - %d",
xref];
}
obj = GSIArrayItemAtIndex(_objAry, xref).obj;
/*
* If it's a cross-reference, we don't need to autorelease it
* since we didn't create it.
*/
return obj;
}
else
{
Class c;
id rep;
if (xref != GSIArrayCount(_objAry))
{
[NSException raise: NSInternalInconsistencyException
format: @"extra object crossref - %d",
xref];
}
(*_dValImp)(self, dValSel, @encode(Class), &c);
obj = [c allocWithZone: _zone];
GSIArrayAddItem(_objAry, (GSIArrayItem)obj);
rep = [obj initWithCoder: self];
if (rep != obj)
{
obj = rep;
GSIArraySetItemAtIndex(_objAry, (GSIArrayItem)obj, xref);
}
rep = [obj awakeAfterUsingCoder: self];
if (rep != obj)
{
obj = rep;
GSIArraySetItemAtIndex(_objAry, (GSIArrayItem)obj, xref);
}
/*
* A newly allocated object needs to be autoreleased.
*/
return AUTORELEASE(obj);
}
}
- (void) decodeValueOfObjCType: (const char*)type - (void) decodeValueOfObjCType: (const char*)type
at: (void*)address at: (void*)address
{ {
@ -635,13 +558,62 @@ static IMP _xRefImp; /* Serialize a crossref. */
return; return;
} }
case _GSC_CID:
{
id obj;
typeCheck(*type, _GSC_ID);
/*
* Special case - a zero crossref value size is a nil pointer.
*/
if ((info & _GSC_SIZE) == 0)
{
obj = nil;
}
else
{
if (info & _GSC_XREF)
{
if (xref >= GSIArrayCount(_objAry))
{
[NSException raise: NSInternalInconsistencyException
format: @"object crossref missing - %d",
xref];
}
obj = GSIArrayItemAtIndex(_objAry, xref).obj;
/*
* If it's a cross-reference, we need to retain it in
* order to give the appearance that it's actually a
* new object.
*/
IF_NO_GC(RETAIN(obj));
}
else
{
if (xref != GSIArrayCount(_objAry))
{
[NSException raise: NSInternalInconsistencyException
format: @"extra object crossref - %d",
xref];
}
(*_dValImp)(self, dValSel, @encode(Class), &obj);
GSIArrayAddItem(_objAry, (GSIArrayItem)obj);
}
}
*(id*)address = obj;
return;
}
case _GSC_CLASS: case _GSC_CLASS:
{ {
Class c; Class c;
GSClassInfo *classInfo; GSClassInfo *classInfo;
Class dummy; Class dummy;
typeCheck(*type, _GSC_CLASS); if (*type != _C_ID)
{
typeCheck(*type, _GSC_CLASS);
}
/* /*
* Special case - a zero crossref value size is a nil pointer. * Special case - a zero crossref value size is a nil pointer.
*/ */
@ -1209,14 +1181,6 @@ static IMP _xRefImp; /* Serialize a crossref. */
(*_eTagImp)(_dst, eTagSel, _GSC_ID | _GSC_XREF, _GSC_X_0); (*_eTagImp)(_dst, eTagSel, _GSC_ID | _GSC_XREF, _GSC_X_0);
} }
} }
else if (fastIsInstance(anObject) == NO)
{
/*
* If the object we have been given is actually a class,
* we encode it as a class instead.
*/
(*_eValImp)(self, eValSel, @encode(Class), &anObject);
}
else else
{ {
GSIMapNode node; GSIMapNode node;
@ -1257,11 +1221,22 @@ static IMP _xRefImp; /* Serialize a crossref. */
} }
obj = [anObject replacementObjectForPortCoder: self]; obj = [anObject replacementObjectForPortCoder: self];
cls = [obj classForPortCoder]; if (fastIsInstance(obj) == NO)
{
(*_xRefImp)(_dst, xRefSel, _GSC_ID, node->value.uint); /*
(*_eValImp)(self, eValSel, @encode(Class), &cls); * If the object we have been given is actually a class,
[obj encodeWithCoder: self]; * we encode it as a special case.
*/
(*_xRefImp)(_dst, xRefSel, _GSC_CID, node->value.uint);
(*_eValImp)(self, eValSel, @encode(Class), &obj);
}
else
{
cls = [obj classForPortCoder];
(*_xRefImp)(_dst, xRefSel, _GSC_ID, node->value.uint);
(*_eValImp)(self, eValSel, @encode(Class), &cls);
[obj encodeWithCoder: self];
}
} }
else else
{ {
@ -1949,491 +1924,3 @@ static IMP _xRefImp; /* Serialize a crossref. */
@end @end
#else
/* Implementation of NSPortCoder object for remote messaging
Copyright (C) 1997 Free Software Foundation, Inc.
This implementation for OPENSTEP conformance written by
Richard Frith-Macdonald <richard@brainstorm.co.u>
Created: August 1997
based on original code -
Copyright (C) 1994, 1995, 1996 Free Software Foundation, Inc.
Written by: Andrew Kachites McCallum <mccallum@gnu.ai.mit.edu>
Created: July 1994
This file is part of the GNUstep Base Library.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with this library; if not, write to the Free
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111 USA.
*/
#include <config.h>
#include <base/preface.h>
#include <base/Coder.h>
#include <base/CStream.h>
#include <base/Port.h>
#include <base/MemoryStream.h>
#include <Foundation/NSData.h>
#include <Foundation/NSException.h>
#include <Foundation/DistributedObjects.h>
#define DEFAULT_SIZE 256
#define PORT_CODER_FORMAT_VERSION ((((GNUSTEP_BASE_MAJOR_VERSION * 100) + \
GNUSTEP_BASE_MINOR_VERSION) * 100) + GNUSTEP_BASE_SUBMINOR_VERSION)
static BOOL debug_connected_coder = NO;
/*
* The PortEncoder class is essentially the old ConnectedEncoder class
* with a name change.
* It uses the OPENSTEP method [-classForPortCoder] to ask an object
* what class to encode.
*/
@interface PortEncoder : Encoder
{
NSConnection *connection;
unsigned sequence_number;
int identifier;
BOOL _is_by_copy;
BOOL _is_by_ref;
}
+ newForWritingWithConnection: (NSConnection*)c
sequenceNumber: (int)n
identifier: (int)i;
- (void) dismiss;
- (NSConnection*) connection;
- (unsigned) sequenceNumber;
- (int) identifier;
@end
@implementation PortEncoder
- _initForWritingWithConnection: (NSConnection*)c
sequenceNumber: (int)n
identifier: (int)i
{
OutPacket* packet = [[[(OutPort*)[c sendPort] outPacketClass] alloc]
initForSendingWithCapacity: DEFAULT_SIZE
replyInPort: [c receivePort]];
[super initForWritingToStream: packet];
[packet release];
connection = c;
sequence_number = n;
identifier = i;
[self encodeValueOfCType: @encode(typeof(sequence_number))
at: &sequence_number
withName: @"PortCoder sequence number"];
[self encodeValueOfCType: @encode(typeof(identifier))
at: &identifier
withName: @"PortCoder identifier"];
return self;
}
+ newForWritingWithConnection: (NSConnection*)c
sequenceNumber: (int)n
identifier: (int)i
{
/* Export this method and not the -init... method because eventually
we may do some caching of old PortEncoder's to speed things up. */
return [[self alloc] _initForWritingWithConnection: c
sequenceNumber: n
identifier: i];
}
- (void) dismiss
{
id packet = [cstream stream];
NS_DURING
{
[(OutPort*)[connection sendPort] sendPacket: packet
timeout: [connection requestTimeout]];
}
NS_HANDLER
{
if (debug_connected_coder)
fprintf(stderr, "dismiss 0x%x: #=%d i=%d write failed - %s\n",
(unsigned)self, sequence_number, identifier,
[[localException reason] cString]);
if ([[connection sendPort] isValid])
[[connection sendPort] invalidate];
}
NS_ENDHANDLER
if (debug_connected_coder)
fprintf(stderr, "dismiss 0x%x: #=%d i=%d %d\n",
(unsigned)self, sequence_number, identifier,
[packet streamEofPosition]);
[self release];
}
/* Access to ivars. */
- (int) identifier
{
return identifier;
}
- (NSConnection*) connection
{
return connection;
}
- (BOOL) isBycopy
{
return _is_by_copy;
}
- (BOOL) isByref
{
return _is_by_ref;
}
- (unsigned) sequenceNumber
{
return sequence_number;
}
/*
* These three methods are called by Coder's designated object encoder when
* an object is to be sent over the wire with/without bycopy/byref.
* We make sure that if the object asks us whether it is to be sent bycopy
* or byref it is told the right thing.
*/
- (void) _doEncodeObject: anObj
{
id obj;
Class cls;
obj = [anObj replacementObjectForPortCoder: (NSPortCoder*)self];
cls = [obj classForPortCoder];
[self encodeClass: cls];
[obj encodeWithCoder: (NSCoder*)self];
}
- (void) _doEncodeBycopyObject: anObj
{
BOOL oldBycopy = _is_by_copy;
BOOL oldByref = _is_by_ref;
id obj;
Class cls;
_is_by_copy = YES;
_is_by_ref = NO;
obj = [anObj replacementObjectForPortCoder: (NSPortCoder*)self];
cls = [obj classForPortCoder];
[self encodeClass: cls];
[obj encodeWithCoder: (NSCoder*)self];
_is_by_copy = oldBycopy;
_is_by_ref = oldByref;
}
- (void) _doEncodeByrefObject: anObj
{
BOOL oldBycopy = _is_by_copy;
BOOL oldByref = _is_by_ref;
id obj;
Class cls;
_is_by_copy = NO;
_is_by_ref = YES;
obj = [anObj replacementObjectForPortCoder: (NSPortCoder*)self];
cls = [obj classForPortCoder];
[self encodeClass: cls];
[obj encodeWithCoder: (NSCoder*)self];
_is_by_copy = oldBycopy;
_is_by_ref = oldByref;
}
- (void) writeSignature
{
return;
}
- (void) encodeDataObject: (NSData*)anObject
{
unsigned l = [anObject length];
[self encodeValueOfObjCType: @encode(unsigned) at: &l];
if (l)
{
const void *b = [anObject bytes];
[self encodeArrayOfObjCType: @encode(unsigned char)
count: l
at: b];
}
}
@end
/*
* The PortDecoder class is essentially the old ConnectedDecoder class
* with a name change.
*/
@interface PortDecoder : Decoder
{
NSConnection *connection;
unsigned sequence_number;
int identifier;
}
+ newDecodingWithPacket: (InPacket*)packet
connection: (NSConnection*)c;
+ newDecodingWithConnection: (NSConnection*)c
timeout: (int) timeout;
- (void) dismiss;
- (NSConnection*) connection;
- (unsigned) sequenceNumber;
- (int) identifier;
- (NSPort*) replyPort;
@end
@implementation PortDecoder
+ (void) readSignatureFromCStream: (id <CStreaming>) cs
getClassname: (char *) name
formatVersion: (int*) version
{
const char *classname = class_get_class_name (self);
strcpy (name, classname);
*version = PORT_CODER_FORMAT_VERSION;
}
+ newDecodingWithConnection: (NSConnection*)c
timeout: (int) timeout
{
PortDecoder *cd;
id in_port;
id packet;
id reply_port;
/* Try to get a packet. */
in_port = [c receivePort];
packet = [in_port receivePacketWithTimeout: timeout];
if (!packet)
return nil; /* timeout */
/* Create the new PortDecoder */
cd = [self newReadingFromStream: packet];
[packet release];
reply_port = [packet replyPort];
cd->connection = [NSConnection newForInPort: in_port
outPort: reply_port
ancestorConnection: c];
/* Decode the PortDecoder's ivars. */
[cd decodeValueOfCType: @encode(typeof(cd->sequence_number))
at: &(cd->sequence_number)
withName: NULL];
[cd decodeValueOfCType: @encode(typeof(cd->identifier))
at: &(cd->identifier)
withName: NULL];
if (debug_connected_coder)
fprintf(stderr, "newDecoding #=%d id=%d\n",
cd->sequence_number, cd->identifier);
return cd;
}
+ newDecodingWithPacket: (InPacket*)packet
connection: (NSConnection*)c
{
PortDecoder *cd;
id in_port;
id reply_port;
in_port = [c receivePort];
/* Create the new PortDecoder */
cd = [self newReadingFromStream: packet];
[packet release];
reply_port = [packet replyOutPort];
cd->connection = [NSConnection newForInPort: in_port
outPort: reply_port
ancestorConnection: c];
/* Decode the PortDecoder's ivars. */
[cd decodeValueOfCType: @encode(typeof(cd->sequence_number))
at: &(cd->sequence_number)
withName: NULL];
[cd decodeValueOfCType: @encode(typeof(cd->identifier))
at: &(cd->identifier)
withName: NULL];
if (debug_connected_coder)
fprintf(stderr, "newDecoding #=%d id=%d\n",
cd->sequence_number, cd->identifier);
return cd;
}
/* Access to ivars. */
- (int) identifier
{
return identifier;
}
- (NSConnection*) connection
{
return connection;
}
- (NSPort*) replyPort
{
return (NSPort*)[(id)[cstream stream] replyPort];
}
- (unsigned) sequenceNumber
{
return sequence_number;
}
- (void) dealloc
{
[connection release];
[super dealloc];
}
- (void) dismiss
{
[self release];
}
- (NSData*) decodeDataObject
{
unsigned l;
[self decodeValueOfObjCType: @encode(unsigned) at: &l];
if (l)
{
void *b;
NSData *d;
NSZone *z;
#if GS_WITH_GC
z = GSAtomicMallocZone();
#else
z = NSDefaultMallocZone();
#endif
b = NSZoneMalloc(z, l);
[self decodeArrayOfObjCType: @encode(unsigned char)
count: l
at: b];
d = [[NSData alloc] initWithBytesNoCopy: b length: l fromZone: z];
IF_NO_GC(AUTORELEASE(d));
return d;
}
return [NSData data];
}
@end
/*
* The NSPortCoder class is an abstract class which is used to create
* instances of PortEncoder or PortDecoder depending on what factory
* method is used.
*/
@implementation NSPortCoder
+ newDecodingWithConnection: (NSConnection*)c
timeout: (int) timeout
{
return [PortDecoder newDecodingWithConnection:c timeout:timeout];
}
+ newDecodingWithPacket: (InPacket*)packet
connection: (NSConnection*)c
{
return [PortDecoder newDecodingWithPacket:packet connection:c];
}
+ newForWritingWithConnection: (NSConnection*)c
sequenceNumber: (int)n
identifier: (int)i
{
return [[PortEncoder alloc] _initForWritingWithConnection: c
sequenceNumber: n
identifier: i];
}
- allocWithZone: (NSZone*)z
{
[self subclassResponsibility:_cmd];
return nil;
}
- (NSConnection*) connection
{
[self subclassResponsibility:_cmd];
return nil;
}
- (NSPort*) decodePortObject
{
[self subclassResponsibility:_cmd];
return nil;
}
- (void) dismiss
{
[self subclassResponsibility:_cmd];
}
- (void) encodePortObject: (NSPort*)aPort
{
[self subclassResponsibility:_cmd];
}
- (int) identifier
{
[self subclassResponsibility:_cmd];
return 0;
}
- (BOOL) isBycopy
{
[self subclassResponsibility:_cmd];
return NO;
}
- (BOOL) isByref
{
[self subclassResponsibility:_cmd];
return NO;
}
- (NSPort*) replyPort
{
[self subclassResponsibility:_cmd];
return nil;
}
- (unsigned) sequenceNumber
{
[self subclassResponsibility:_cmd];
return 0;
}
@end
#endif

View file

@ -39,7 +39,7 @@
#include <Foundation/NSTimer.h> #include <Foundation/NSTimer.h>
#include <Foundation/NSPortNameServer.h> #include <Foundation/NSPortNameServer.h>
#include <Foundation/NSDebug.h> #include <Foundation/NSDebug.h>
#include <base/TcpPort.h> #include <netinet/in.h>
#include <arpa/inet.h> #include <arpa/inet.h>
/* /*
@ -60,16 +60,12 @@
* to suppress warnings about using private methods. * to suppress warnings about using private methods.
*/ */
@class GSTcpPort; @class GSTcpPort;
@class TcpOutPort;
@interface NSPort (Hack) @interface NSPort (Hack)
+ newForSendingToSockaddr: (struct sockaddr_in*)sockaddr
withAcceptedSocket: (int)sock
pollingInPort: (id)ip;
+ (GSTcpPort*) portWithNumber: (gsu16)number + (GSTcpPort*) portWithNumber: (gsu16)number
onHost: (NSHost*)host onHost: (NSHost*)host
forceAddress: (NSString*)addr forceAddress: (NSString*)addr
listener: (BOOL)shouldListen; listener: (BOOL)shouldListen;
- (gsu16) portNumber;
@end @end
/* /*
@ -345,17 +341,26 @@ typedef enum {
} }
else else
{ {
NSHost *current = [NSHost currentHost]; NSHost *local = [NSHost localHost];
NSHost *host = [NSHost hostWithName: hostname]; NSHost *host = [NSHost hostWithName: hostname];
if (host == nil) if (host == nil)
{ {
host = [NSHost hostWithAddress: hostname]; host = [NSHost hostWithAddress: hostname];
} }
if ([current isEqual: host]) if ([local isEqual: host])
{ {
state = GSPC_LOPEN; state = GSPC_LOPEN;
} }
else
{
NSHost *loopback = [NSHost hostWithAddress: @"127.0.0.1"];
if ([loopback isEqual: host])
{
state = GSPC_LOPEN;
}
}
} }
} }
@ -525,11 +530,7 @@ typedef enum {
#endif #endif
launchCmd = [NSString stringWithCString: launchCmd = [NSString stringWithCString:
make_gdomap_cmd(GNUSTEP_INSTALL_PREFIX)]; make_gdomap_cmd(GNUSTEP_INSTALL_PREFIX)];
#if GS_NEW_DO
portClass = [GSTcpPort class]; portClass = [GSTcpPort class];
#else
portClass = [TcpOutPort class];
#endif
} }
} }
@ -774,34 +775,7 @@ typedef enum {
if (portNum) if (portNum)
{ {
if (portClass == [TcpOutPort class]) if (portClass == [GSTcpPort class])
{
struct sockaddr_in sin;
NSPort *p;
unsigned short n;
memset(&sin, '\0', sizeof(sin));
sin.sin_family = AF_INET;
/*
* The returned port is an unsigned int - so we have to
* convert to a short in network byte order (big endian).
*/
n = (unsigned short)portNum;
sin.sin_port = NSSwapHostShortToBig(n);
/*
* The host addresses are given to us in network byte order
* so we just copy the address into place.
*/
sin.sin_addr = singleServer;
p = [TcpOutPort newForSendingToSockaddr: &sin
withAcceptedSocket: 0
pollingInPort: nil];
return AUTORELEASE(p);
}
else if (portClass == [GSTcpPort class])
{ {
NSString *addr; NSString *addr;
NSHost *host; NSHost *host;
@ -886,7 +860,7 @@ typedef enum {
if ([known count] == 0) if ([known count] == 0)
{ {
com = [GSPortCom new]; com = [GSPortCom new];
[com startPortUnregistration: [(TcpInPort*)port portNumber] [com startPortUnregistration: [port portNumber]
withName: nil]; withName: nil];
while ([limit timeIntervalSinceNow] > 0 && [com isActive] == YES) while ([limit timeIntervalSinceNow] > 0 && [com isActive] == YES)
{ {
@ -905,7 +879,7 @@ typedef enum {
} }
com = [GSPortCom new]; com = [GSPortCom new];
[com startPortRegistration: [(TcpInPort*)port portNumber] [com startPortRegistration: [port portNumber]
withName: name]; withName: name];
while ([limit timeIntervalSinceNow] > 0 && [com isActive] == YES) while ([limit timeIntervalSinceNow] > 0 && [com isActive] == YES)
{ {

View file

@ -477,8 +477,8 @@ _gnu_noobjc_free_vars(void)
} }
#else /* !HAVE_PROC_FS || !HAVE_LOAD_METHOD */ #else /* !HAVE_PROC_FS || !HAVE_LOAD_METHOD */
#ifdef __MINGW32__ #ifdef __MINGW__
/* For Windows32API Library, we know the global variables */ /* For WindowsAPI Library, we know the global variables */
extern int __argc; extern int __argc;
extern char** __argv; extern char** __argv;
extern char** _environ; extern char** _environ;
@ -505,9 +505,9 @@ int main(int argc, char *argv[], char *env[])
} }
#endif /* __MINGW__ */ #endif /* __MINGW__ */
#ifdef __MS_WIN32__ #ifdef __MS_WIN__
_MB_init_runtime(); _MB_init_runtime();
#endif /* __MS_WIN32__ */ #endif /* __MS_WIN__ */
_gnu_process_args(argc, argv, env); _gnu_process_args(argc, argv, env);
@ -515,7 +515,7 @@ int main(int argc, char *argv[], char *env[])
return gnustep_base_user_main(argc, argv, env); return gnustep_base_user_main(argc, argv, env);
} }
#endif /* !GS_PASS_ARGUMENTS */ #endif /* !GS_PASS_ARGUMENTS */
#endif /* __MINGW32__ */ #endif /* __MINGW__ */
#endif /* HAS_LOAD_METHOD && HAS_PROC_FS */ #endif /* HAS_LOAD_METHOD && HAS_PROC_FS */

View file

@ -23,8 +23,10 @@
#include <config.h> #include <config.h>
#include <base/behavior.h> #include <base/behavior.h>
#include <base/fast.x>
#include <Foundation/NSSet.h> #include <Foundation/NSSet.h>
#include <Foundation/NSGSet.h> #include <Foundation/NSGSet.h>
#include <Foundation/NSCoder.h>
#include <Foundation/NSArray.h> #include <Foundation/NSArray.h>
#include <Foundation/NSUtilities.h> #include <Foundation/NSUtilities.h>
#include <Foundation/NSString.h> #include <Foundation/NSString.h>
@ -54,26 +56,6 @@ static Class NSMutableSet_concrete_class;
} }
} }
+ (void) _setConcreteClass: (Class)c
{
NSSet_concrete_class = c;
}
+ (void) _setMutableConcreteClass: (Class)c
{
NSMutableSet_concrete_class = c;
}
+ (Class) _concreteClass
{
return NSSet_concrete_class;
}
+ (Class) _mutableConcreteClass
{
return NSMutableSet_concrete_class;
}
+ (id) set + (id) set
{ {
return AUTORELEASE([[self allocWithZone: NSDefaultMallocZone()] init]); return AUTORELEASE([[self allocWithZone: NSDefaultMallocZone()] init]);
@ -118,8 +100,13 @@ static Class NSMutableSet_concrete_class;
+ (id) allocWithZone: (NSZone*)z + (id) allocWithZone: (NSZone*)z
{ {
if (self == NSSet_abstract_class) if (self == NSSet_abstract_class)
return NSAllocateObject(NSSet_concrete_class, 0, z); {
return [super allocWithZone: z]; return NSAllocateObject(NSSet_concrete_class, 0, z);
}
else
{
return NSAllocateObject(self, 0, z);
}
} }
/* This is the designated initializer */ /* This is the designated initializer */
@ -132,13 +119,37 @@ static Class NSMutableSet_concrete_class;
- (id) initWithCoder: (NSCoder*)aCoder - (id) initWithCoder: (NSCoder*)aCoder
{ {
[self subclassResponsibility: _cmd]; unsigned count;
return nil; Class c = fastClass(self);
if (c == NSSet_abstract_class)
{
RELEASE(self);
self = [NSSet_concrete_class allocWithZone: NSDefaultMallocZone()];
return [self initWithCoder: aCoder];
}
else if (c == NSMutableSet_abstract_class)
{
RELEASE(self);
self = [NSMutableSet_concrete_class allocWithZone: NSDefaultMallocZone()];
return [self initWithCoder: aCoder];
}
[aCoder decodeValueOfObjCType: @encode(unsigned) at: &count];
{
id objs[count];
unsigned i;
for (i = 0; i < count; i++)
{
[aCoder decodeValueOfObjCType: @encode(id) at: &objs[i]];
}
return [self initWithObjects: objs count: count];
}
} }
- (void) encodeWithCoder: (NSCoder*)aCoder - (Class) classForCoder
{ {
[self subclassResponsibility: _cmd]; return NSSet_abstract_class;
} }
- (unsigned) count - (unsigned) count
@ -147,7 +158,20 @@ static Class NSMutableSet_concrete_class;
return 0; return 0;
} }
- (id) member: anObject - (void) encodeWithCoder: (NSCoder*)aCoder
{
unsigned count = [self count];
NSEnumerator *e = [self objectEnumerator];
id o;
[aCoder encodeValueOfObjCType: @encode(unsigned) at: &count];
while ((o = [e nextObject]) != nil)
{
[aCoder encodeValueOfObjCType: @encode(id) at: &o];
}
}
- (id) member: (id)anObject
{ {
return [self subclassResponsibility: _cmd]; return [self subclassResponsibility: _cmd];
return 0; return 0;
@ -165,8 +189,7 @@ static Class NSMutableSet_concrete_class;
- (id) mutableCopyWithZone: (NSZone*)z - (id) mutableCopyWithZone: (NSZone*)z
{ {
return [[[[self class] _mutableConcreteClass] allocWithZone: z] return [[NSMutableSet_concrete_class allocWithZone: z] initWithSet: self];
initWithSet: self];
} }
@end @end
@ -307,7 +330,12 @@ static Class NSMutableSet_concrete_class;
} }
} }
- (BOOL) containsObject: anObject - (Class) classForCoder
{
return NSSet_abstract_class;
}
- (BOOL) containsObject: (id)anObject
{ {
return (([self member: anObject]) ? YES : NO); return (([self member: anObject]) ? YES : NO);
} }
@ -395,7 +423,7 @@ static Class NSMutableSet_concrete_class;
return YES; return YES;
} }
- (BOOL) isEqual: other - (BOOL) isEqual: (id)other
{ {
if ([other isKindOfClass: [NSSet class]]) if ([other isKindOfClass: [NSSet class]])
return [self isEqualToSet: other]; return [self isEqualToSet: other];
@ -450,13 +478,18 @@ static Class NSMutableSet_concrete_class;
+ (id) allocWithZone: (NSZone*)z + (id) allocWithZone: (NSZone*)z
{ {
if (self == NSMutableSet_abstract_class) if (self == NSMutableSet_abstract_class)
return NSAllocateObject(NSMutableSet_concrete_class, 0, z); {
return [super allocWithZone: z]; return NSAllocateObject(NSMutableSet_concrete_class, 0, z);
}
else
{
return NSAllocateObject(self, 0, z);
}
} }
- (id) copyWithZone: (NSZone*)z - (id) copyWithZone: (NSZone*)z
{ {
return [[[[self class] _concreteClass] allocWithZone: z] initWithSet: self]; return [[NSSet_concrete_class allocWithZone: z] initWithSet: self];
} }
/* This is the designated initializer */ /* This is the designated initializer */
@ -465,12 +498,12 @@ static Class NSMutableSet_concrete_class;
return [self subclassResponsibility: _cmd]; return [self subclassResponsibility: _cmd];
} }
- (void) addObject: anObject - (void) addObject: (id)anObject
{ {
[self subclassResponsibility: _cmd]; [self subclassResponsibility: _cmd];
} }
- (void) removeObject: anObject - (void) removeObject: (id)anObject
{ {
[self subclassResponsibility: _cmd]; [self subclassResponsibility: _cmd];
} }
@ -479,13 +512,14 @@ static Class NSMutableSet_concrete_class;
@implementation NSMutableSetNonCore @implementation NSMutableSetNonCore
/* Override superclass's designated initializer */ - (id) initWithObjects: (id*)objects
- initWithObjects: (id*)objects count: (unsigned)count
count: (unsigned)count
{ {
[self initWithCapacity: count]; [self initWithCapacity: count];
while (count--) while (count--)
[self addObject: objects[count]]; {
[self addObject: objects[count]];
}
return self; return self;
} }
@ -494,35 +528,58 @@ static Class NSMutableSet_concrete_class;
unsigned i, c = [array count]; unsigned i, c = [array count];
for (i = 0; i < c; i++) for (i = 0; i < c; i++)
[self addObject: [array objectAtIndex: i]]; {
[self addObject: [array objectAtIndex: i]];
}
} }
- (void) unionSet: (NSSet*) other - (void) unionSet: (NSSet*) other
{ {
id keys = [other objectEnumerator]; if (other != self)
id key; {
id keys = [other objectEnumerator];
id key;
while ((key = [keys nextObject])) while ((key = [keys nextObject]))
[self addObject: key]; {
[self addObject: key];
}
}
} }
- (void) intersectSet: (NSSet*) other - (void) intersectSet: (NSSet*) other
{ {
id keys = [self objectEnumerator]; if (other != self)
id key; {
id keys = [self objectEnumerator];
id key;
while ((key = [keys nextObject])) while ((key = [keys nextObject]))
if ([other containsObject: key] == NO) {
[self removeObject: key]; if ([other containsObject: key] == NO)
{
[self removeObject: key];
}
}
}
} }
- (void) minusSet: (NSSet*) other - (void) minusSet: (NSSet*) other
{ {
id keys = [other objectEnumerator]; if (other == self)
id key; {
[self removeAllObjects];
}
else
{
id keys = [other objectEnumerator];
id key;
while ((key = [keys nextObject])) while ((key = [keys nextObject]))
[self removeObject: key]; {
[self removeObject: key];
}
}
} }
- (void) removeAllObjects - (void) removeAllObjects

View file

@ -43,7 +43,6 @@
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>
#include <base/preface.h> #include <base/preface.h>
#include <base/Coding.h>
#include <Foundation/NSString.h> #include <Foundation/NSString.h>
#include <Foundation/NSArray.h> #include <Foundation/NSArray.h>
#include <Foundation/NSCharacterSet.h> #include <Foundation/NSCharacterSet.h>
@ -99,7 +98,12 @@ static NSStringEncoding _availableEncodings[] = {
0 0
}; };
static Class NSString_class; /* For speed */ /*
* Cache classes for speed.
*/
static Class NSData_class;
static Class NSString_class;
static Class NSMutableString_class;
/* /*
* Include sequence handling code with instructions to generate search * Include sequence handling code with instructions to generate search
@ -173,47 +177,6 @@ static Class NSMutableString_c_concrete_class;
static NSStringEncoding _DefaultStringEncoding; static NSStringEncoding _DefaultStringEncoding;
+ (void) _setConcreteClass: (Class)c
{
NSString_concrete_class = c;
}
+ (void) _setConcreteCClass: (Class)c
{
NSString_c_concrete_class = c;
}
+ (void) _setMutableConcreteClass: (Class)c
{
NSMutableString_concrete_class = c;
}
+ (void) _setMutableConcreteCClass: (Class)c
{
NSMutableString_c_concrete_class = c;
}
+ (Class) _concreteClass
{
return NSString_concrete_class;
}
+ (Class) _concreteCClass
{
return NSString_c_concrete_class;
}
+ (Class) _mutableConcreteClass
{
return NSMutableString_concrete_class;
}
+ (Class) _mutableConcreteCClass
{
return NSMutableString_c_concrete_class;
}
#if HAVE_REGISTER_PRINTF_FUNCTION #if HAVE_REGISTER_PRINTF_FUNCTION
#include <stdio.h> #include <stdio.h>
#include <printf.h> #include <printf.h>
@ -279,6 +242,8 @@ handle_printf_atsign (FILE *stream,
{ {
_DefaultStringEncoding = GetDefEncoding(); _DefaultStringEncoding = GetDefEncoding();
NSString_class = self; NSString_class = self;
NSMutableString_class = [NSMutableString class];
NSData_class = [NSData class];
NSString_concrete_class = [NSGString class]; NSString_concrete_class = [NSGString class];
NSString_c_concrete_class = [NSGCString class]; NSString_c_concrete_class = [NSGCString class];
NSMutableString_concrete_class = [NSGMutableString class]; NSMutableString_concrete_class = [NSGMutableString class];
@ -300,9 +265,14 @@ handle_printf_atsign (FILE *stream,
+ (id) allocWithZone: (NSZone*)z + (id) allocWithZone: (NSZone*)z
{ {
if ([self class] == [NSString class]) if (self == NSString_class)
return NSAllocateObject ([self _concreteClass], 0, z); {
return [super allocWithZone: z]; return NSAllocateObject (NSString_concrete_class, 0, z);
}
else
{
return NSAllocateObject (self, 0, z);
}
} }
// Creating Temporary Strings // Creating Temporary Strings
@ -861,9 +831,9 @@ handle_printf_atsign (FILE *stream,
- (id) initWithContentsOfFile: (NSString*)path - (id) initWithContentsOfFile: (NSString*)path
{ {
NSStringEncoding enc; NSStringEncoding enc;
id d = [NSData dataWithContentsOfFile: path]; NSData *d = [NSData_class dataWithContentsOfFile: path];
const unsigned char *test; const unsigned char *test;
if (d == nil) if (d == nil)
return nil; return nil;
@ -912,12 +882,14 @@ handle_printf_atsign (FILE *stream,
{ {
unsigned l = [self length]; unsigned l = [self length];
unsigned i; unsigned i;
unichar (*caiImp)(NSString*, SEL, unsigned);
GS_RANGE_CHECK(aRange, l); GS_RANGE_CHECK(aRange, l);
caiImp = (unichar (*)())[self methodForSelector: caiSel];
for (i = 0; i < aRange.length; i++) for (i = 0; i < aRange.length; i++)
{ {
buffer[i] = [self characterAtIndex: aRange.location+i]; buffer[i] = (*caiImp)(self, caiSel, aRange.location + i);
} }
} }
@ -1124,15 +1096,17 @@ handle_printf_atsign (FILE *stream,
unsigned start; unsigned start;
unsigned end; unsigned end;
unsigned length = [self length]; unsigned length = [self length];
unichar (*caiImp)(NSString*, SEL, unsigned);
if (anIndex >= length) if (anIndex >= length)
[NSException raise: NSRangeException format:@"Invalid location."]; [NSException raise: NSRangeException format:@"Invalid location."];
caiImp = (unichar (*)())[self methodForSelector: caiSel];
start = anIndex; start = anIndex;
while (uni_isnonsp([self characterAtIndex: start]) && start > 0) while (uni_isnonsp((*caiImp)(self, caiSel, start)) && start > 0)
start--; start--;
end=start+1; end=start+1;
if (end < length) if (end < length)
while ((end < length) && (uni_isnonsp([self characterAtIndex: end])) ) while ((end < length) && (uni_isnonsp((*caiImp)(self, caiSel, end))) )
end++; end++;
return NSMakeRange(start, end-start); return NSMakeRange(start, end-start);
} }
@ -1398,17 +1372,19 @@ handle_printf_atsign (FILE *stream,
{ {
unichar thischar; unichar thischar;
unsigned start, end, len; unsigned start, end, len;
unichar (*caiImp)(NSString*, SEL, unsigned);
len = [self length]; len = [self length];
GS_RANGE_CHECK(aRange, len); GS_RANGE_CHECK(aRange, len);
caiImp = (unichar (*)())[self methodForSelector: caiSel];
start = aRange.location; start = aRange.location;
if (startIndex) if (startIndex)
{ {
if (start==0) if (start == 0)
{ {
*startIndex=0; *startIndex = 0;
} }
else else
{ {
@ -1417,8 +1393,8 @@ handle_printf_atsign (FILE *stream,
{ {
BOOL done = NO; BOOL done = NO;
thischar = [self characterAtIndex: start]; thischar = (*caiImp)(self, caiSel, start);
switch(thischar) switch (thischar)
{ {
case (unichar)0x000A: case (unichar)0x000A:
case (unichar)0x000D: case (unichar)0x000D:
@ -1435,8 +1411,8 @@ handle_printf_atsign (FILE *stream,
}; };
if (start == 0) if (start == 0)
{ {
thischar = [self characterAtIndex: start]; thischar = (*caiImp)(self, caiSel, start);
switch(thischar) switch (thischar)
{ {
case (unichar)0x000A: case (unichar)0x000A:
case (unichar)0x000D: case (unichar)0x000D:
@ -1456,12 +1432,12 @@ handle_printf_atsign (FILE *stream,
if (lineEndIndex || contentsEndIndex) if (lineEndIndex || contentsEndIndex)
{ {
end=aRange.location+aRange.length; end = aRange.location + aRange.length;
while (end<len) while (end < len)
{ {
BOOL done = NO; BOOL done = NO;
thischar = [self characterAtIndex: end]; thischar = (*caiImp)(self, caiSel, end);
switch(thischar) switch (thischar)
{ {
case (unichar)0x000A: case (unichar)0x000A:
case (unichar)0x000D: case (unichar)0x000D:
@ -1476,11 +1452,11 @@ handle_printf_atsign (FILE *stream,
if (done) if (done)
break; break;
}; };
if (end<len) if (end < len)
{ {
if ([self characterAtIndex: end]==(unichar)0x000D) if ((*caiImp)(self, caiSel, end) == (unichar)0x000D)
{ {
if ([self characterAtIndex: end+1]==(unichar)0x000A) if ((*caiImp)(self, caiSel, end+1) == (unichar)0x000A)
*lineEndIndex = end+1; *lineEndIndex = end+1;
else else
*lineEndIndex = end; *lineEndIndex = end;
@ -1494,15 +1470,15 @@ handle_printf_atsign (FILE *stream,
if (contentsEndIndex) if (contentsEndIndex)
{ {
if (end<len) if (end < len)
{ {
*contentsEndIndex= end-1; *contentsEndIndex = end-1;
} }
else else
{ {
/* xxx OPENSTEP documentation does not say what to do if last /* xxx OPENSTEP documentation does not say what to do if last
line is not terminated. Assume this */ line is not terminated. Assume this */
*contentsEndIndex= end; *contentsEndIndex = end;
} }
} }
} }
@ -1568,13 +1544,19 @@ handle_printf_atsign (FILE *stream,
unichar *s; unichar *s;
unsigned count; unsigned count;
unsigned len = [self length]; unsigned len = [self length];
unichar (*caiImp)(NSString*, SEL, unsigned);
if (len == 0) if (len == 0)
return self; {
return self;
}
z = fastZone(self); z = fastZone(self);
s = NSZoneMalloc(z, sizeof(unichar)*len); s = NSZoneMalloc(z, sizeof(unichar)*len);
caiImp = (unichar (*)())[self methodForSelector: caiSel];
for (count = 0; count < len; count++) for (count = 0; count < len; count++)
s[count] = uni_tolower([self characterAtIndex: count]); {
s[count] = uni_tolower((*caiImp)(self, caiSel, count));
}
return AUTORELEASE([[NSString_concrete_class return AUTORELEASE([[NSString_concrete_class
allocWithZone: NSDefaultMallocZone()] allocWithZone: NSDefaultMallocZone()]
initWithCharactersNoCopy: s length: len fromZone: z]); initWithCharactersNoCopy: s length: len fromZone: z]);
@ -1586,13 +1568,19 @@ handle_printf_atsign (FILE *stream,
unichar *s; unichar *s;
unsigned count; unsigned count;
unsigned len = [self length]; unsigned len = [self length];
unichar (*caiImp)(NSString*, SEL, unsigned);
if (len == 0) if (len == 0)
return self; {
return self;
}
z = fastZone(self); z = fastZone(self);
s = NSZoneMalloc(z, sizeof(unichar)*len); s = NSZoneMalloc(z, sizeof(unichar)*len);
caiImp = (unichar (*)())[self methodForSelector: caiSel];
for (count = 0; count < len; count++) for (count = 0; count < len; count++)
s[count] = uni_toupper([self characterAtIndex: count]); {
s[count] = uni_toupper((*caiImp)(self, caiSel, count));
}
return AUTORELEASE([[NSString_concrete_class return AUTORELEASE([[NSString_concrete_class
allocWithZone: NSDefaultMallocZone()] allocWithZone: NSDefaultMallocZone()]
initWithCharactersNoCopy: s length: len fromZone: z]); initWithCharactersNoCopy: s length: len fromZone: z]);
@ -1610,8 +1598,10 @@ handle_printf_atsign (FILE *stream,
- (const char*) cString - (const char*) cString
{ {
NSData *d = [self dataUsingEncoding: _DefaultStringEncoding NSData *d;
allowLossyConversion: NO];
d = [self dataUsingEncoding: _DefaultStringEncoding
allowLossyConversion: NO];
if (d == nil) if (d == nil)
{ {
[NSException raise: NSCharacterConversionException [NSException raise: NSCharacterConversionException
@ -1622,30 +1612,35 @@ handle_printf_atsign (FILE *stream,
- (const char*) lossyCString - (const char*) lossyCString
{ {
NSData *d = [self dataUsingEncoding: _DefaultStringEncoding NSData *d;
allowLossyConversion: YES];
d = [self dataUsingEncoding: _DefaultStringEncoding
allowLossyConversion: YES];
return (const char*)[d bytes]; return (const char*)[d bytes];
} }
- (unsigned) cStringLength - (unsigned) cStringLength
{ {
[self subclassResponsibility: _cmd]; NSData *d;
return 0;
d = [self dataUsingEncoding: _DefaultStringEncoding
allowLossyConversion: YES];
return [d length];
} }
- (void) getCString: (char*)buffer - (void) getCString: (char*)buffer
{ {
[self getCString: buffer maxLength: NSMaximumStringLength [self getCString: buffer maxLength: NSMaximumStringLength
range: ((NSRange){0, [self length]}) range: ((NSRange){0, [self length]})
remainingRange: NULL]; remainingRange: NULL];
} }
- (void) getCString: (char*)buffer - (void) getCString: (char*)buffer
maxLength: (unsigned)maxLength maxLength: (unsigned)maxLength
{ {
[self getCString: buffer maxLength: maxLength [self getCString: buffer maxLength: maxLength
range: ((NSRange){0, [self length]}) range: ((NSRange){0, [self length]})
remainingRange: NULL]; remainingRange: NULL];
} }
// xxx FIXME adjust range for composite sequence // xxx FIXME adjust range for composite sequence
@ -1656,6 +1651,7 @@ handle_printf_atsign (FILE *stream,
{ {
unsigned len; unsigned len;
unsigned count; unsigned count;
unichar (*caiImp)(NSString*, SEL, unsigned);
len = [self cStringLength]; len = [self cStringLength];
GS_RANGE_CHECK(aRange, len); GS_RANGE_CHECK(aRange, len);
@ -1678,10 +1674,11 @@ handle_printf_atsign (FILE *stream,
leftoverRange->length = aRange.length - maxLength; leftoverRange->length = aRange.length - maxLength;
} }
} }
caiImp = (unichar (*)())[self methodForSelector: caiSel];
count = 0; count = 0;
while (count < len) while (count < len)
{ {
buffer[count]=unitochar([self characterAtIndex: aRange.location + count]); buffer[count]=unitochar((*caiImp)(self, caiSel, aRange.location + count));
count++; count++;
} }
buffer[len] = '\0'; buffer[len] = '\0';
@ -1739,10 +1736,9 @@ handle_printf_atsign (FILE *stream,
ourbundle = [NSBundle bundleWithPath: rootPath]; ourbundle = [NSBundle bundleWithPath: rootPath];
ourname = GetEncodingName(encoding); ourname = GetEncodingName(encoding);
return [ourbundle return [ourbundle localizedStringForKey: ourname
localizedStringForKey: ourname value: ourname
value: ourname table: nil];
table: nil];
} }
- (BOOL) canBeConvertedToEncoding: (NSStringEncoding)encoding - (BOOL) canBeConvertedToEncoding: (NSStringEncoding)encoding
@ -1760,29 +1756,33 @@ handle_printf_atsign (FILE *stream,
- (NSData*) dataUsingEncoding: (NSStringEncoding)encoding - (NSData*) dataUsingEncoding: (NSStringEncoding)encoding
allowLossyConversion: (BOOL)flag allowLossyConversion: (BOOL)flag
{ {
int count=0; unsigned int count = 0;
int len = [self length]; unsigned int len = [self length];
unichar (*caiImp)(NSString*, SEL, unsigned);
if (len == 0) if (len == 0)
return [NSData data];
if ((encoding==NSASCIIStringEncoding)
|| (encoding==NSISOLatin1StringEncoding)
|| (encoding==NSISOLatin2StringEncoding)
|| (encoding==NSNEXTSTEPStringEncoding)
|| (encoding==NSNonLossyASCIIStringEncoding)
|| (encoding==NSSymbolStringEncoding)
|| (encoding==NSCyrillicStringEncoding))
{ {
char t; return [NSData_class data];
unsigned char *buff; }
caiImp = (unichar (*)())[self methodForSelector: caiSel];
if ((encoding == NSASCIIStringEncoding)
|| (encoding == NSISOLatin1StringEncoding)
|| (encoding == NSISOLatin2StringEncoding)
|| (encoding == NSNEXTSTEPStringEncoding)
|| (encoding == NSNonLossyASCIIStringEncoding)
|| (encoding == NSSymbolStringEncoding)
|| (encoding == NSCyrillicStringEncoding))
{
char t;
unsigned char *buff;
buff = (unsigned char*)NSZoneMalloc(NSDefaultMallocZone(), len+1); buff = (unsigned char*)NSZoneMalloc(NSDefaultMallocZone(), len+1);
if (!flag) if (!flag)
{ {
for (count = 0; count < len; count++) for (count = 0; count < len; count++)
{ {
t = encode_unitochar([self characterAtIndex: count], encoding); t = encode_unitochar((*caiImp)(self, caiSel, count), encoding);
if (t) if (t)
{ {
buff[count] = t; buff[count] = t;
@ -1798,7 +1798,7 @@ handle_printf_atsign (FILE *stream,
{ {
for (count = 0; count < len; count++) for (count = 0; count < len; count++)
{ {
t = encode_unitochar([self characterAtIndex: count], encoding); t = encode_unitochar((*caiImp)(self, caiSel, count), encoding);
if (t) if (t)
{ {
buff[count] = t; buff[count] = t;
@ -1814,17 +1814,19 @@ handle_printf_atsign (FILE *stream,
} }
} }
buff[count] = '\0'; buff[count] = '\0';
return [NSData dataWithBytesNoCopy: buff length: count]; return [NSData_class dataWithBytesNoCopy: buff length: count];
} }
else if (encoding == NSUnicodeStringEncoding) else if (encoding == NSUnicodeStringEncoding)
{ {
unichar *buff; unichar *buff;
buff = (unichar*)NSZoneMalloc(NSDefaultMallocZone(), 2*len+2); buff = (unichar*)NSZoneMalloc(NSDefaultMallocZone(), 2*len+2);
buff[0]=0xFEFF; buff[0] = 0xFEFF;
for (count = 0; count < len; count++) for (count = 0; count < len; count++)
buff[count+1] = [self characterAtIndex: count]; {
return [NSData dataWithBytesNoCopy: buff length: 2*len+2]; buff[count+1] = (*caiImp)(self, caiSel, count);
}
return [NSData_class dataWithBytesNoCopy: buff length: 2*len+2];
} }
else /* UTF8 or EUC */ else /* UTF8 or EUC */
{ {
@ -1962,7 +1964,7 @@ handle_printf_atsign (FILE *stream,
else else
{ {
NSRange range2 = [self rangeOfCharacterFromSet: pathSeps() NSRange range2 = [self rangeOfCharacterFromSet: pathSeps()
options: NSBackwardsSearch]; options: NSBackwardsSearch];
if (range2.length > 0 && range.location < range2.location) if (range2.length > 0 && range.location < range2.location)
substring = nil; substring = nil;
else else
@ -2019,7 +2021,7 @@ handle_printf_atsign (FILE *stream,
aLength--; aLength--;
} }
} }
return [NSString stringWithCharacters: buf length: length]; return [NSString_class stringWithCharacters: buf length: length];
} }
/* Returns a new string with the path extension given in aString /* Returns a new string with the path extension given in aString
@ -2071,8 +2073,8 @@ handle_printf_atsign (FILE *stream,
- (NSString*) stringByExpandingTildeInPath - (NSString*) stringByExpandingTildeInPath
{ {
NSString *homedir; NSString *homedir;
NSRange first_slash_range; NSRange first_slash_range;
if ([self length] == 0) if ([self length] == 0)
return AUTORELEASE([self copy]); return AUTORELEASE([self copy]);
@ -2101,9 +2103,8 @@ handle_printf_atsign (FILE *stream,
homedir = NSHomeDirectory (); homedir = NSHomeDirectory ();
} }
return [NSString stringWithFormat: @"%@%@", return [NSString_class stringWithFormat: @"%@%@", homedir,
homedir, [self substringFromIndex: first_slash_range.location]];
[self substringFromIndex: first_slash_range.location]];
} }
- (NSString*) stringByAbbreviatingWithTildeInPath - (NSString*) stringByAbbreviatingWithTildeInPath
@ -2113,8 +2114,8 @@ handle_printf_atsign (FILE *stream,
if (![self hasPrefix: homedir]) if (![self hasPrefix: homedir])
return AUTORELEASE([self copy]); return AUTORELEASE([self copy]);
return [NSString stringWithFormat: @"~%c%@", (char)pathSepChar, return [NSString_class stringWithFormat: @"~%c%@", (char)pathSepChar,
[self substringFromIndex: [homedir length] + 1]]; [self substringFromIndex: [homedir length] + 1]];
} }
- (NSString*) stringByResolvingSymlinksInPath - (NSString*) stringByResolvingSymlinksInPath
@ -2275,9 +2276,11 @@ handle_printf_atsign (FILE *stream,
{ {
NSMutableString *s; NSMutableString *s;
NSRange r; NSRange r;
unichar (*caiImp)(NSString*, SEL, unsigned);
/* Expand `~' in the path */ /* Expand `~' in the path */
s = [[self stringByExpandingTildeInPath] mutableCopy]; s = [[self stringByExpandingTildeInPath] mutableCopy];
caiImp = (unichar (*)())[s methodForSelector: caiSel];
/* Remove `/private' */ /* Remove `/private' */
if ([s hasPrefix: @"/private"]) if ([s hasPrefix: @"/private"])
@ -2292,13 +2295,13 @@ handle_printf_atsign (FILE *stream,
unsigned length = [s length]; unsigned length = [s length];
if (r.location + r.length + 1 <= length if (r.location + r.length + 1 <= length
&& pathSepMember([s characterAtIndex: r.location + 1]) == YES) && pathSepMember((*caiImp)(s, caiSel, r.location + 1)) == YES)
{ {
[s deleteCharactersInRange: r]; [s deleteCharactersInRange: r];
} }
else if (r.location + r.length + 2 <= length else if (r.location + r.length + 2 <= length
&& [s characterAtIndex: r.location + 1] == (unichar)'.' && (*caiImp)(s, caiSel, r.location + 1) == (unichar)'.'
&& pathSepMember([s characterAtIndex: r.location + 2]) == YES) && pathSepMember((*caiImp)(s, caiSel, r.location + 2)) == YES)
{ {
r.length++; r.length++;
[s deleteCharactersInRange: r]; [s deleteCharactersInRange: r];
@ -2328,9 +2331,9 @@ handle_printf_atsign (FILE *stream,
range: r]).length) range: r]).length)
{ {
if (r.location + r.length + 3 <= [s length] if (r.location + r.length + 3 <= [s length]
&& [s characterAtIndex: r.location + 1] == (unichar)'.' && (*caiImp)(s, caiSel, r.location + 1) == (unichar)'.'
&& [s characterAtIndex: r.location + 2] == (unichar)'.' && (*caiImp)(s, caiSel, r.location + 2) == (unichar)'.'
&& pathSepMember([s characterAtIndex: r.location + 3]) == YES) && pathSepMember((*caiImp)(s, caiSel, r.location + 3)) == YES)
{ {
if (r.location > 0) if (r.location > 0)
{ {
@ -2367,11 +2370,16 @@ handle_printf_atsign (FILE *stream,
if (len > 0) if (len > 0)
{ {
int count = 0; int count = 0;
unichar (*caiImp)() = (unichar (*)())[self methodForSelector: caiSel]; unichar (*caiImp)(NSString*, SEL, unsigned);
caiImp = (unichar (*)())[self methodForSelector: caiSel];
while (count < len) while (count < len)
if (!uni_isnonsp((*caiImp)(self, caiSel, count++))) {
blen++; if (!uni_isnonsp((*caiImp)(self, caiSel, count++)))
{
blen++;
}
}
} }
return blen; return blen;
} }
@ -2577,7 +2585,7 @@ handle_printf_atsign (FILE *stream,
} }
*ptr++ = '"'; *ptr++ = '"';
*ptr = '\0'; *ptr = '\0';
[output appendString: [NSString stringWithCString: buf]]; [output appendString: [NSString_class stringWithCString: buf]];
} }
} }
else else
@ -2593,7 +2601,7 @@ handle_printf_atsign (FILE *stream,
{ {
if ([self isKindOfClass: [NSMutableString class]] || if ([self isKindOfClass: [NSMutableString class]] ||
NSShouldRetainWithZone(self, zone) == NO) NSShouldRetainWithZone(self, zone) == NO)
return [[[[self class] _concreteClass] allocWithZone: zone] return [[NSString_concrete_class allocWithZone: zone]
initWithString: self]; initWithString: self];
else else
return RETAIN(self); return RETAIN(self);
@ -2601,7 +2609,7 @@ handle_printf_atsign (FILE *stream,
- (id) mutableCopyWithZone: (NSZone*)zone - (id) mutableCopyWithZone: (NSZone*)zone
{ {
return [[[[self class] _mutableConcreteClass] allocWithZone: zone] return [[NSMutableString_concrete_class allocWithZone: zone]
initWithString: self]; initWithString: self];
} }
@ -2700,9 +2708,14 @@ handle_printf_atsign (FILE *stream,
+ (id) allocWithZone: (NSZone*)z + (id) allocWithZone: (NSZone*)z
{ {
if ([self class] == [NSMutableString class]) if (self == NSMutableString_class)
return NSAllocateObject([self _mutableConcreteClass], 0, z); {
return [super allocWithZone: z]; return NSAllocateObject(NSMutableString_concrete_class, 0, z);
}
else
{
return NSAllocateObject(self, 0, z);
}
} }
// Creating Temporary Strings // Creating Temporary Strings
@ -2893,29 +2906,41 @@ handle_printf_atsign (FILE *stream,
{ {
unsigned location = 0; unsigned location = 0;
unsigned length = [self length]; unsigned length = [self length];
unichar (*caiImp)(NSString*, SEL, unsigned);
while (location < length && isspace([self characterAtIndex: location])) caiImp = (unichar (*)())[self methodForSelector: caiSel];
location++; while (location < length && isspace((*caiImp)(self, caiSel, location)))
{
location++;
}
if (location > 0) if (location > 0)
[self deleteCharactersInRange: NSMakeRange(0,location)]; {
[self deleteCharactersInRange: NSMakeRange(0,location)];
}
} }
- (void) trimTailSpaces - (void) trimTailSpaces
{ {
unsigned length = [self length]; unsigned length = [self length];
if (length) if (length > 0)
{ {
unsigned location = length; unsigned location = length;
unichar (*caiImp)(NSString*, SEL, unsigned);
caiImp = (unichar (*)())[self methodForSelector: caiSel];
while (location > 0) while (location > 0)
if (!isspace([self characterAtIndex: --location])) {
break; if (!isspace((*caiImp)(self, caiSel, --location)))
{
break;
}
}
if (location < length-1) if (location < length-1)
[self deleteCharactersInRange: NSMakeRange((location == 0) ? 0 {
: location + 1, length - ((location == 0) ? 0 : location + 1))]; [self deleteCharactersInRange: NSMakeRange((location == 0) ? 0
: location + 1, length - ((location == 0) ? 0 : location + 1))];
}
} }
} }

View file

@ -123,7 +123,18 @@ gnustep_base_thread_callback()
*/ */
+ (NSThread*) currentThread + (NSThread*) currentThread
{ {
return GSCurrentThread(); if (entered_multi_threaded_state == NO)
{
/*
* The NSThread class has been initialized - so we will have a default
* thread set up.
*/
return defaultThread;
}
else
{
return (NSThread*)objc_thread_get_data();
}
} }
/* /*

View file

@ -49,7 +49,9 @@ static Class NSDate_class;
repeats: (BOOL)f repeats: (BOOL)f
{ {
if (seconds <= 0) if (seconds <= 0)
seconds = 0.001; {
seconds = 0.001;
}
_interval = seconds; _interval = seconds;
_date = [[NSDate_class allocWithZone: [self zone]] _date = [[NSDate_class allocWithZone: [self zone]]
initWithTimeIntervalSinceNow: seconds]; initWithTimeIntervalSinceNow: seconds];
@ -61,31 +63,31 @@ static Class NSDate_class;
} }
+ (NSTimer*) timerWithTimeInterval: (NSTimeInterval)ti + (NSTimer*) timerWithTimeInterval: (NSTimeInterval)ti
invocation: invocation invocation: (NSInvocation*)invocation
repeats: (BOOL)f repeats: (BOOL)f
{ {
return AUTORELEASE([[self alloc] initWithTimeInterval: ti return AUTORELEASE([[self alloc] initWithTimeInterval: ti
targetOrInvocation: invocation targetOrInvocation: invocation
selector: NULL selector: NULL
userInfo: nil userInfo: nil
repeats: f]); repeats: f]);
} }
+ (NSTimer*) timerWithTimeInterval: (NSTimeInterval)ti + (NSTimer*) timerWithTimeInterval: (NSTimeInterval)ti
target: object target: (id)object
selector: (SEL)selector selector: (SEL)selector
userInfo: info userInfo: (id)info
repeats: (BOOL)f repeats: (BOOL)f
{ {
return AUTORELEASE([[self alloc] initWithTimeInterval: ti return AUTORELEASE([[self alloc] initWithTimeInterval: ti
targetOrInvocation: object targetOrInvocation: object
selector: selector selector: selector
userInfo: info userInfo: info
repeats: f]); repeats: f]);
} }
+ (NSTimer*) scheduledTimerWithTimeInterval: (NSTimeInterval)ti + (NSTimer*) scheduledTimerWithTimeInterval: (NSTimeInterval)ti
invocation: invocation invocation: (NSInvocation*)invocation
repeats: (BOOL)f repeats: (BOOL)f
{ {
id t = [self timerWithTimeInterval: ti id t = [self timerWithTimeInterval: ti
@ -96,16 +98,16 @@ static Class NSDate_class;
} }
+ (NSTimer*) scheduledTimerWithTimeInterval: (NSTimeInterval)ti + (NSTimer*) scheduledTimerWithTimeInterval: (NSTimeInterval)ti
target: object target: (id)object
selector: (SEL)selector selector: (SEL)selector
userInfo: info userInfo: (id)info
repeats: (BOOL)f repeats: (BOOL)f
{ {
id t = [self timerWithTimeInterval: ti id t = [self timerWithTimeInterval: ti
target: object target: object
selector: selector selector: selector
userInfo: info userInfo: info
repeats: f]; repeats: f];
[[NSRunLoop currentRunLoop] addTimer: t forMode: NSDefaultRunLoopMode]; [[NSRunLoop currentRunLoop] addTimer: t forMode: NSDefaultRunLoopMode];
return t; return t;
} }
@ -118,14 +120,20 @@ static Class NSDate_class;
- (void) fire - (void) fire
{ {
if (_selector) if (_selector == 0)
[_target performSelector: _selector withObject: self]; {
[(NSInvocation*)_target invoke];
}
else else
[_target invoke]; {
[_target performSelector: _selector withObject: self];
}
if (!_repeats) if (_repeats == NO)
[self invalidate]; {
else if (!_invalidated) [self invalidate];
}
else if (_invalidated == NO)
{ {
NSTimeInterval now = GSTimeNow(); NSTimeInterval now = GSTimeNow();
NSTimeInterval nxt = [_date timeIntervalSinceReferenceDate]; NSTimeInterval nxt = [_date timeIntervalSinceReferenceDate];
@ -138,7 +146,9 @@ static Class NSDate_class;
} }
#ifdef LOG_MISSED #ifdef LOG_MISSED
if (inc > 0) if (inc > 0)
NSLog(@"Missed %d timeouts at %f second intervals", inc, _interval); {
NSLog(@"Missed %d timeouts at %f second intervals", inc, _interval);
}
#endif #endif
RELEASE(_date); RELEASE(_date);
_date = [[NSDate_class allocWithZone: [self zone]] _date = [[NSDate_class allocWithZone: [self zone]]
@ -155,7 +165,10 @@ static Class NSDate_class;
- (BOOL) isValid - (BOOL) isValid
{ {
return !_invalidated; if (_invalidated == NO)
return YES;
else
return NO;
} }
- (NSDate*) fireDate - (NSDate*) fireDate
@ -175,7 +188,20 @@ static Class NSDate_class;
- (NSComparisonResult) compare: (NSTimer*)anotherTimer - (NSComparisonResult) compare: (NSTimer*)anotherTimer
{ {
return [_date compare: anotherTimer->_date]; if (anotherTimer == self)
{
return NSOrderedSame;
}
else if (anotherTimer == nil)
{
[NSException raise: NSInvalidArgumentException
format: @"nil argument for compare:"];
}
else
{
return [_date compare: anotherTimer->_date];
}
return 0;
} }
@end @end

View file

@ -98,6 +98,7 @@ typeToName2(char type)
{ {
switch (type & _GSC_MASK) switch (type & _GSC_MASK)
{ {
case _GSC_CID: return "class (encoded as id)";
case _GSC_CLASS: return "class"; case _GSC_CLASS: return "class";
case _GSC_ID: return "object"; case _GSC_ID: return "object";
case _GSC_SEL: return "selector"; case _GSC_SEL: return "selector";
@ -455,9 +456,12 @@ mapClassName(NSUnarchiverObjectInfo *info)
(*tagImp)(src, tagSel, &ainfo, 0, &cursor); (*tagImp)(src, tagSel, &ainfo, 0, &cursor);
if (info != (ainfo & _GSC_MASK)) if (info != (ainfo & _GSC_MASK))
{ {
[NSException raise: NSInternalInconsistencyException if (info != _GSC_ID || (ainfo & _GSC_MASK) != _GSC_CID)
format: @"expected %s and got %s", {
typeToName2(info), typeToName2(ainfo)]; [NSException raise: NSInternalInconsistencyException
format: @"expected %s and got %s",
typeToName2(info), typeToName2(ainfo)];
}
} }
for (i = 0; i < count; i++) for (i = 0; i < count; i++)
@ -558,7 +562,10 @@ mapClassName(NSUnarchiverObjectInfo *info)
NSUnarchiverObjectInfo *classInfo; NSUnarchiverObjectInfo *classInfo;
Class dummy; Class dummy;
typeCheck(*type, _GSC_CLASS); if (*type != _C_ID)
{
typeCheck(*type, _GSC_CLASS);
}
/* /*
* Special case - a zero crossref value size is a nil pointer. * Special case - a zero crossref value size is a nil pointer.
*/ */
@ -982,84 +989,6 @@ mapClassName(NSUnarchiverObjectInfo *info)
return [NSData data]; return [NSData data];
} }
/*
* The [-decodeObject] method is implemented purely for performance -
* It duplicates the code for handling objects in the
* [-decodeValueOfObjCType:at:] method above, but differs in that the
* resulting object is autoreleased when it comes from this method.
*/
- (id) decodeObject
{
unsigned char info;
unsigned xref;
id obj;
(*tagImp)(src, tagSel, &info, &xref, &cursor);
if ((info & _GSC_MASK) != _GSC_ID)
{
[NSException raise: NSInternalInconsistencyException
format: @"expected object and got %s", typeToName2(info)];
}
/*
* Special case - a zero crossref value is a nil pointer.
*/
if ((info & _GSC_SIZE) == 0)
{
return nil;
}
if (info & _GSC_XREF)
{
if (xref >= GSIArrayCount(objMap))
{
[NSException raise: NSInternalInconsistencyException
format: @"object crossref missing - %d",
xref];
}
obj = GSIArrayItemAtIndex(objMap, xref).obj;
/*
* If it's a cross-reference, we don't need to autorelease it
* since we didn't create it.
*/
return obj;
}
else
{
Class c;
id rep;
if (xref != GSIArrayCount(objMap))
{
[NSException raise: NSInternalInconsistencyException
format: @"extra object crossref - %d",
xref];
}
(*dValImp)(self, dValSel, @encode(Class), &c);
obj = [c allocWithZone: zone];
GSIArrayAddItem(objMap, (GSIArrayItem)obj);
rep = [obj initWithCoder: self];
if (rep != obj)
{
obj = rep;
GSIArraySetItemAtIndex(objMap, (GSIArrayItem)obj, xref);
}
rep = [obj awakeAfterUsingCoder: self];
if (rep != obj)
{
obj = rep;
GSIArraySetItemAtIndex(objMap, (GSIArrayItem)obj, xref);
}
/*
* A newly allocated object needs to be autoreleased.
*/
return AUTORELEASE(obj);
}
}
- (BOOL) isAtEnd - (BOOL) isAtEnd
{ {
return (cursor >= [data length]); return (cursor >= [data length]);

View file

@ -106,7 +106,7 @@ static Class sizeValueClass;
// Allocating and Initializing // Allocating and Initializing
+ (NSValue *)value: (const void *)value + (NSValue*) value: (const void *)value
withObjCType: (const char *)type withObjCType: (const char *)type
{ {
Class theClass = [self valueClassWithObjCType: type]; Class theClass = [self valueClassWithObjCType: type];
@ -117,7 +117,7 @@ static Class sizeValueClass;
return AUTORELEASE(theObj); return AUTORELEASE(theObj);
} }
+ (NSValue *)valueWithBytes: (const void *)value + (NSValue*) valueWithBytes: (const void *)value
objCType: (const char *)type objCType: (const char *)type
{ {
Class theClass = [self valueClassWithObjCType: type]; Class theClass = [self valueClassWithObjCType: type];
@ -128,7 +128,7 @@ static Class sizeValueClass;
return AUTORELEASE(theObj); return AUTORELEASE(theObj);
} }
+ (NSValue *) valueWithNonretainedObject: (id)anObject + (NSValue*) valueWithNonretainedObject: (id)anObject
{ {
NSValue *theObj; NSValue *theObj;
@ -137,7 +137,7 @@ static Class sizeValueClass;
return AUTORELEASE(theObj); return AUTORELEASE(theObj);
} }
+ (NSValue *) valueWithPoint: (NSPoint)point + (NSValue*) valueWithPoint: (NSPoint)point
{ {
NSValue *theObj; NSValue *theObj;
@ -146,7 +146,7 @@ static Class sizeValueClass;
return AUTORELEASE(theObj); return AUTORELEASE(theObj);
} }
+ (NSValue *)valueWithPointer: (const void *)pointer + (NSValue*) valueWithPointer: (const void *)pointer
{ {
NSValue *theObj; NSValue *theObj;
@ -155,7 +155,7 @@ static Class sizeValueClass;
return AUTORELEASE(theObj); return AUTORELEASE(theObj);
} }
+ (NSValue *)valueWithRect: (NSRect)rect + (NSValue*) valueWithRect: (NSRect)rect
{ {
NSValue *theObj; NSValue *theObj;
@ -164,7 +164,7 @@ static Class sizeValueClass;
return AUTORELEASE(theObj); return AUTORELEASE(theObj);
} }
+ (NSValue *)valueWithSize: (NSSize)size + (NSValue*) valueWithSize: (NSSize)size
{ {
NSValue *theObj; NSValue *theObj;
@ -173,7 +173,7 @@ static Class sizeValueClass;
return AUTORELEASE(theObj); return AUTORELEASE(theObj);
} }
+ (NSValue*)valueFromString: (NSString *)string + (NSValue*) valueFromString: (NSString *)string
{ {
NSDictionary *dict = [string propertyList]; NSDictionary *dict = [string propertyList];
@ -214,57 +214,57 @@ static Class sizeValueClass;
// Accessing Data // Accessing Data
/* All the rest of these methods must be implemented by a subclass */ /* All the rest of these methods must be implemented by a subclass */
- (void)getValue: (void *)value - (void) getValue: (void *)value
{ {
[self subclassResponsibility: _cmd]; [self subclassResponsibility: _cmd];
} }
- (BOOL)isEqual: (id)other - (BOOL) isEqual: (id)other
{ {
if ([other isKindOfClass: [self class]]) if ([other isKindOfClass: [self class]])
{ {
return [self isEqualToValue: other]; return [self isEqualToValue: other];
} }
return NO; return NO;
} }
- (BOOL)isEqualToValue: (NSValue*)other - (BOOL) isEqualToValue: (NSValue*)other
{ {
[self subclassResponsibility: _cmd]; [self subclassResponsibility: _cmd];
return NO; return NO;
} }
- (const char *)objCType - (const char *) objCType
{ {
[self subclassResponsibility: _cmd]; [self subclassResponsibility: _cmd];
return 0; return 0;
} }
- (id)nonretainedObjectValue - (id) nonretainedObjectValue
{ {
[self subclassResponsibility: _cmd]; [self subclassResponsibility: _cmd];
return 0; return 0;
} }
- (void *)pointerValue - (void *) pointerValue
{ {
[self subclassResponsibility: _cmd]; [self subclassResponsibility: _cmd];
return 0; return 0;
} }
- (NSRect)rectValue - (NSRect) rectValue
{ {
[self subclassResponsibility: _cmd]; [self subclassResponsibility: _cmd];
return NSMakeRect(0,0,0,0); return NSMakeRect(0,0,0,0);
} }
- (NSSize)sizeValue - (NSSize) sizeValue
{ {
[self subclassResponsibility: _cmd]; [self subclassResponsibility: _cmd];
return NSMakeSize(0,0); return NSMakeSize(0,0);
} }
- (NSPoint)pointValue - (NSPoint) pointValue
{ {
[self subclassResponsibility: _cmd]; [self subclassResponsibility: _cmd];
return NSMakePoint(0,0); return NSMakePoint(0,0);

View file

@ -1736,89 +1736,6 @@ static NSZone atomic_zone =
}; };
NSZone* __nszone_private_hidden_atomic_zone = &atomic_zone; NSZone* __nszone_private_hidden_atomic_zone = &atomic_zone;
NSZone* NSCreateZone (size_t start, size_t gran, BOOL canFree)
{ return __nszone_private_hidden_default_zone; }
NSZone* NSDefaultMallocZone (void)
{ return __nszone_private_hidden_default_zone; }
NSZone* GSAtomicMallocZone (void)
{ return __nszone_private_hidden_atomic_zone; }
NSZone* NSZoneFromPointer (void *ptr)
{ return __nszone_private_hidden_default_zone; }
void* NSZoneMalloc (NSZone *zone, size_t size)
{
void *ptr;
if (zone == GSAtomicMallocZone())
ptr = (void*)GC_MALLOC_ATOMIC(size);
else
ptr = (void*)GC_MALLOC(size);
if (ptr == 0)
ptr = GSOutOfMemory(size, YES);
return ptr;
}
void* NSZoneCalloc (NSZone *zone, size_t elems, size_t bytes)
{
size_t size = elems * bytes;
void *ptr;
if (zone == __nszone_private_hidden_atomic_zone)
ptr = (void*)GC_MALLOC_ATOMIC(size);
else
ptr = (void*)GC_MALLOC(size);
if (ptr == 0)
ptr = GSOutOfMemory(size, NO);
memset(ptr, '\0', size);
return ptr;
}
void* NSZoneRealloc (NSZone *zone, void *ptr, size_t size)
{
ptr = GC_REALLOC(ptr, size);
if (ptr == 0)
GSOutOfMemory(size, NO);
return ptr;
}
void NSRecycleZone (NSZone *zone)
{
}
void NSZoneFree (NSZone *zone, void *ptr)
{
GC_FREE(ptr);
}
void NSSetZoneName (NSZone *zone, NSString *name)
{
}
NSString* NSZoneName (NSZone *zone)
{
return nil;
}
void* NSZoneMallocAtomic (NSZone *zone, size_t size)
{
return NSZoneMalloc(GSAtomicMallocZone(), size);
}
BOOL NSZoneCheck (NSZone *zone)
{
return YES;
}
struct NSZoneStats NSZoneStats (NSZone *zone)
{
struct NSZoneStats stats = { 0 };
return stats;
}
#endif /* GS_WITH_GC */ #endif /* GS_WITH_GC */

View file

@ -33,211 +33,203 @@ struct _ucc_ {unichar from; char to;};
#include "unicode/cop.h" #include "unicode/cop.h"
#include "unicode/decomp.h" #include "unicode/decomp.h"
#define FALSE 0
#define TRUE 1
typedef unsigned char unc; typedef unsigned char unc;
static NSStringEncoding defEnc = GSUndefinedEncoding;
unichar unichar
encode_chartouni(char c, NSStringEncoding enc) encode_chartouni(char c, NSStringEncoding enc)
{ {
/* All that I could find in Next documentation /* All that I could find in Next documentation
on NSNonLossyASCIIStringEncoding was << forthcoming >>. */ on NSNonLossyASCIIStringEncoding was << forthcoming >>. */
if ((enc == NSNonLossyASCIIStringEncoding) switch (enc)
|| (enc == NSASCIIStringEncoding)
|| (enc == NSISOLatin1StringEncoding))
{ {
return (unichar)((unc)c); case NSNonLossyASCIIStringEncoding:
} case NSASCIIStringEncoding:
if ((enc == NSNEXTSTEPStringEncoding)) case NSISOLatin1StringEncoding:
{
if ((unc)c < Next_conv_base)
return (unichar)((unc)c); return (unichar)((unc)c);
else
return(Next_char_to_uni_table[(unc)c - Next_conv_base]); case NSNEXTSTEPStringEncoding:
} if ((unc)c < Next_conv_base)
if ((enc == NSCyrillicStringEncoding)) return (unichar)((unc)c);
{ else
if ((unc)c < Cyrillic_conv_base) return(Next_char_to_uni_table[(unc)c - Next_conv_base]);
return (unichar)((unc)c);
else case NSCyrillicStringEncoding:
return(Cyrillic_char_to_uni_table[(unc)c - Cyrillic_conv_base]); if ((unc)c < Cyrillic_conv_base)
} return (unichar)((unc)c);
if ((enc == NSISOLatin2StringEncoding)) else
{ return(Cyrillic_char_to_uni_table[(unc)c - Cyrillic_conv_base]);
if ((unc)c < Latin2_conv_base)
return (unichar)((unc)c); case NSISOLatin2StringEncoding:
else if ((unc)c < Latin2_conv_base)
return(Latin2_char_to_uni_table[(unc)c - Latin2_conv_base]); return (unichar)((unc)c);
} else
return(Latin2_char_to_uni_table[(unc)c - Latin2_conv_base]);
#if 0 #if 0
if ((enc == NSSymbolStringEncoding)) case NSSymbolStringEncoding:
{ if ((unc)c < Symbol_conv_base)
if ((unc)c < Symbol_conv_base) return (unichar)((unc)c);
return (unichar)((unc)c); else
else return(Symbol_char_to_uni_table[(unc)c - Symbol_conv_base]);
return(Symbol_char_to_uni_table[(unc)c - Symbol_conv_base]);
}
#endif #endif
return 0; default:
return 0;
}
} }
char char
encode_unitochar(unichar u, NSStringEncoding enc) encode_unitochar(unichar u, NSStringEncoding enc)
{ {
int res; int res;
int i =0; int i = 0;
if ((enc == NSNonLossyASCIIStringEncoding) switch (enc)
|| (enc == NSASCIIStringEncoding))
{ {
if (u <128) case NSNonLossyASCIIStringEncoding:
return (char)u; case NSASCIIStringEncoding:
else if (u < 128)
return 0; return (char)u;
} else
return 0;
if ((enc == NSISOLatin1StringEncoding)) case NSISOLatin1StringEncoding:
{ if (u < 256)
if (u <256) return (char)u;
return (char)u; else
else return 0;
return 0;
}
if ((enc == NSNEXTSTEPStringEncoding)) case NSNEXTSTEPStringEncoding:
{ if (u < (unichar)Next_conv_base)
if (u <(unichar)Next_conv_base) return (char)u;
return (char)u; else
else {
{ while (((res = u - Next_uni_to_char_table[i++].from) > 0)
while (((res = u-Next_uni_to_char_table[i++].from) > 0) && (i < Next_uni_to_char_table_size));
&& (i < Next_uni_to_char_table_size)); return res ? 0 : Next_uni_to_char_table[--i].to;
return res?0:Next_uni_to_char_table[--i].to; }
}
}
if ((enc == NSCyrillicStringEncoding)) case NSCyrillicStringEncoding:
{ if (u < (unichar)Cyrillic_conv_base)
if (u <(unichar)Cyrillic_conv_base) return (char)u;
return (char)u; else
else {
{ while (((res = u - Cyrillic_uni_to_char_table[i++].from) > 0)
while (((res = u-Cyrillic_uni_to_char_table[i++].from) > 0) && (i < Cyrillic_uni_to_char_table_size));
&& (i < Cyrillic_uni_to_char_table_size)); return res ? 0 : Cyrillic_uni_to_char_table[--i].to;
return res ? 0 : Cyrillic_uni_to_char_table[--i].to; }
}
}
if ((enc == NSISOLatin2StringEncoding)) case NSISOLatin2StringEncoding:
{ if (u < (unichar)Latin2_conv_base)
if (u <(unichar)Latin2_conv_base) return (char)u;
return (char)u; else
else {
{ while (((res = u - Latin2_uni_to_char_table[i++].from) > 0)
while (((res = u-Latin2_uni_to_char_table[i++].from) > 0) && (i < Latin2_uni_to_char_table_size));
&& (i < Latin2_uni_to_char_table_size)); return res ? 0 : Latin2_uni_to_char_table[--i].to;
return res ? 0 : Latin2_uni_to_char_table[--i].to; }
}
}
#if 0 #if 0
if ((enc == NSSymbolStringEncoding)) case NSSymbolStringEncoding:
{ if (u < (unichar)Symbol_conv_base)
if (u <(unichar)Symbol_conv_base) return (char)u;
return (char)u; else
else {
{ while (((res = u - Symbol_uni_to_char_table[i++].from) > 0)
while (((res = u-Symbol_uni_to_char_table[i++].from) > 0) && (i < Symbol_uni_to_char_table_size));
&& (i < Symbol_uni_to_char_table_size)); return res ? '*' : Symbol_uni_to_char_table[--i].to;
return res ? '*' : Symbol_uni_to_char_table[--i].to; }
}
}
#endif #endif
return 0; default:
return 0;
}
} }
unichar unichar
chartouni(char c) chartouni(char c)
{ {
static NSStringEncoding enc = GSUndefinedEncoding; if (defEnc == GSUndefinedEncoding)
{
if (enc == 0) defEnc = [NSString defaultCStringEncoding];
enc = [NSString defaultCStringEncoding]; }
return encode_chartouni(c, enc); return encode_chartouni(c, defEnc);
} }
char char
unitochar(unichar u) unitochar(unichar u)
{ {
unc res; unc res;
static NSStringEncoding enc = GSUndefinedEncoding;
if (enc == 0) if (defEnc == GSUndefinedEncoding)
enc = [NSString defaultCStringEncoding];
if ((res = encode_unitochar(u, enc)))
return res;
else
return '*';
}
int
strtoustr(unichar * u1,const char *s1,int size)
{
int count;
for (count = 0; (count < size) && (s1[count] != 0); count++)
u1[count] = chartouni(s1[count]);
return count;
}
int
ustrtostr(char *s2,unichar *u1,int size)
{
int count;
for (count = 0; (count < size) && (u1[count] != (unichar)0); count++)
s2[count] = unitochar(u1[count]);
return(count);
}
int
encode_strtoustr(unichar * u1,const char *s1,int size, NSStringEncoding enc)
{
int count;
for (count = 0; (count < size) && (s1[count] != 0); count++)
u1[count] = encode_chartouni(s1[count], enc);
return count;
}
int
encode_ustrtostr(char *s2,unichar *u1,int size, NSStringEncoding enc)
{
int count;
for (count = 0; (count < size) && (u1[count] != (unichar)0); count++)
s2[count] = encode_unitochar(u1[count], enc);
return(count);
}
/* Be carefull if you use this. Unicode arrays returned by
-getCharacters methods are not zero terminated */
int
uslen (unichar *u)
{
int len = 0;
while (u[len] != 0)
{ {
if (u[++len] == 0) defEnc = [NSString defaultCStringEncoding];
return len;
++len;
} }
return len; if ((res = encode_unitochar(u, defEnc)))
{
return res;
}
else
{
return '*';
}
}
int
strtoustr(unichar *u1, const char *s1, int size)
{
int count;
if (defEnc == GSUndefinedEncoding)
{
defEnc = [NSString defaultCStringEncoding];
}
for (count = 0; (count < size) && (s1[count] != 0); count++)
{
u1[count] = encode_chartouni(s1[count], defEnc);
}
return count;
}
int
ustrtostr(char *s2, unichar *u1, int size)
{
int count;
if (defEnc == GSUndefinedEncoding)
{
defEnc = [NSString defaultCStringEncoding];
}
for (count = 0; (count < size) && (u1[count] != (unichar)0); count++)
{
s2[count] = encode_unitochar(u1[count], defEnc);
}
return count;
}
int
encode_strtoustr(unichar *u1, const char *s1, int size, NSStringEncoding enc)
{
int count;
for (count = 0; (count < size) && (s1[count] != 0); count++)
{
u1[count] = encode_chartouni(s1[count], enc);
}
return count;
}
int
encode_ustrtostr(char *s2, unichar *u1, int size, NSStringEncoding enc)
{
int count;
for (count = 0; (count < size) && (u1[count] != (unichar)0); count++)
{
s2[count] = encode_unitochar(u1[count], enc);
}
return count;
} }
unichar unichar
@ -263,29 +255,33 @@ uni_toupper(unichar ch)
unsigned char unsigned char
uni_cop(unichar u) uni_cop(unichar u)
{ {
unichar count,first,last,comp; unichar count, first, last, comp;
BOOL notfound; BOOL notfound;
first = 0; first = 0;
last = uni_cop_table_size; last = uni_cop_table_size;
notfound = TRUE; notfound = YES;
count =0; count = 0;
if (u > (unichar)0x0080) // no nonspacing in ascii if (u > (unichar)0x0080) // no nonspacing in ascii
{ {
while (notfound && (first <= last)) while (notfound && (first <= last))
{ {
if (!(first == last)) if (first != last)
{ {
count = (first + last) / 2; count = (first + last) / 2;
comp = uni_cop_table[count].code; comp = uni_cop_table[count].code;
if (comp < u) if (comp < u)
first = count+1; {
first = count+1;
}
else else
if (comp > u) {
last = count-1; if (comp > u)
else last = count-1;
notfound = FALSE; else
notfound = NO;
}
} }
else /* first == last */ else /* first == last */
{ {
@ -303,25 +299,23 @@ uni_cop(unichar u)
BOOL BOOL
uni_isnonsp(unichar u) uni_isnonsp(unichar u)
{ {
#define TRUE 1
#define FALSE 0
// check is uni_cop good for this // check is uni_cop good for this
if (uni_cop(u)) if (uni_cop(u))
return TRUE; return YES;
else else
return FALSE; return NO;
} }
unichar* unichar*
uni_is_decomp(unichar u) uni_is_decomp(unichar u)
{ {
unichar count,first,last,comp; unichar count, first, last, comp;
BOOL notfound; BOOL notfound;
first = 0; first = 0;
last = uni_dec_table_size; last = uni_dec_table_size;
notfound = TRUE; notfound = YES;
count =0; count = 0;
if (u > (unichar)0x0080) // no composites in ascii if (u > (unichar)0x0080) // no composites in ascii
{ {
@ -334,10 +328,12 @@ uni_is_decomp(unichar u)
if (comp < u) if (comp < u)
first = count+1; first = count+1;
else else
if (comp > u) {
last = count-1; if (comp > u)
else last = count-1;
notfound = FALSE; else
notfound = NO;
}
} }
else /* first == last */ else /* first == last */
{ {

View file

@ -204,7 +204,7 @@ GSBuildStrings()
= [[NSString alloc] initWithCString: "NSArgumentDomain"]; = [[NSString alloc] initWithCString: "NSArgumentDomain"];
NSBundleDidLoadNotification NSBundleDidLoadNotification
= [[NSString alloc] initWithCString: "NSBundleDidLoadNotification"]; = [[NSString alloc] initWithCString: "NSBundleDidLoadNotification"];
NSCharacterConversionException *(NSString**)&NSCharacterConversionException
= [[NSString alloc] initWithCString: "NSCharacterConversionException"]; = [[NSString alloc] initWithCString: "NSCharacterConversionException"];
NSConnectionDidDieNotification NSConnectionDidDieNotification
= [[NSString alloc] initWithCString: "NSConnectionDidDieNotification"]; = [[NSString alloc] initWithCString: "NSConnectionDidDieNotification"];
@ -293,7 +293,7 @@ GSBuildStrings()
= [[NSString alloc] initWithCString: "NSFileTypeUnknown"]; = [[NSString alloc] initWithCString: "NSFileTypeUnknown"];
NSFormalName NSFormalName
= [[NSString alloc] initWithCString: "NSFormalName"]; = [[NSString alloc] initWithCString: "NSFormalName"];
NSGenericException *(NSString**)&NSGenericException
= [[NSString alloc] initWithCString: "NSGenericException"]; = [[NSString alloc] initWithCString: "NSGenericException"];
NSGlobalDomain NSGlobalDomain
= [[NSString alloc] initWithCString: "NSGlobalDomain"]; = [[NSString alloc] initWithCString: "NSGlobalDomain"];
@ -301,12 +301,12 @@ GSBuildStrings()
= [[NSString alloc] initWithCString: "NSHourNameDesignations"]; = [[NSString alloc] initWithCString: "NSHourNameDesignations"];
NSInconsistentArchiveException NSInconsistentArchiveException
= [[NSString alloc] initWithCString: "NSInconsistentArchiveException"]; = [[NSString alloc] initWithCString: "NSInconsistentArchiveException"];
NSInternalInconsistencyException *(NSString**)&NSInternalInconsistencyException
= [[NSString alloc] initWithCString: = [[NSString alloc] initWithCString:
"NSInternalInconsistencyException"]; "NSInternalInconsistencyException"];
NSInternationalCurrencyString NSInternationalCurrencyString
= [[NSString alloc] initWithCString: "NSInternationalCurrencyString"]; = [[NSString alloc] initWithCString: "NSInternationalCurrencyString"];
NSInvalidArgumentException *(NSString**)&NSInvalidArgumentException
= [[NSString alloc] initWithCString: "NSInvalidArgumentException"]; = [[NSString alloc] initWithCString: "NSInvalidArgumentException"];
NSLanguageCode NSLanguageCode
= [[NSString alloc] initWithCString: "NSLanguageCode"]; = [[NSString alloc] initWithCString: "NSLanguageCode"];
@ -316,7 +316,7 @@ GSBuildStrings()
= [[NSString alloc] initWithCString: "NSLaterTimeDesignations"]; = [[NSString alloc] initWithCString: "NSLaterTimeDesignations"];
NSLoadedClasses NSLoadedClasses
= [[NSString alloc] initWithCString: "NSLoadedClasses"]; = [[NSString alloc] initWithCString: "NSLoadedClasses"];
NSMallocException *(NSString**)&NSMallocException
= [[NSString alloc] initWithCString: "NSMallocException"]; = [[NSString alloc] initWithCString: "NSMallocException"];
NSMonthNameArray NSMonthNameArray
= [[NSString alloc] initWithCString: "NSMonthNameArray"]; = [[NSString alloc] initWithCString: "NSMonthNameArray"];
@ -335,7 +335,7 @@ GSBuildStrings()
= [[NSString alloc] initWithCString: "NSPositiveCurrencyFormatString"]; = [[NSString alloc] initWithCString: "NSPositiveCurrencyFormatString"];
NSPriorDayDesignations NSPriorDayDesignations
= [[NSString alloc] initWithCString: "NSPriorDayDesignations"]; = [[NSString alloc] initWithCString: "NSPriorDayDesignations"];
NSRangeException *(NSString**)&NSRangeException
= [[NSString alloc] initWithCString: "NSRangeException"]; = [[NSString alloc] initWithCString: "NSRangeException"];
NSRegistrationDomain NSRegistrationDomain
= [[NSString alloc] initWithCString: "NSRegistrationDomain"]; = [[NSString alloc] initWithCString: "NSRegistrationDomain"];

View file

@ -27,16 +27,8 @@
; ;
LIBRARY libgnustep-base LIBRARY libgnustep-base
EXPORTS EXPORTS
__objc_class_name_BinaryCStream
__objc_class_name_CStream
__objc_class_name_Coder
__objc_class_name_Decoder
__objc_class_name_Encoder
__objc_class_name_GSClassInfo
__objc_class_name_GSPortCoder
__objc_class_name_GSTcpHandle __objc_class_name_GSTcpHandle
__objc_class_name_GSTcpPort __objc_class_name_GSTcpPort
__objc_class_name_MemoryStream
__objc_class_name_NSArchiver __objc_class_name_NSArchiver
__objc_class_name_NSArray __objc_class_name_NSArray
__objc_class_name_NSArrayEnumerator __objc_class_name_NSArrayEnumerator
@ -138,9 +130,8 @@ __objc_class_name_NSObject
__objc_class_name__FastMallocBuffer __objc_class_name__FastMallocBuffer
__objc_class_name_NSPipe __objc_class_name_NSPipe
__objc_class_name_NSPort __objc_class_name_NSPort
__objc_class_name_GSClassInfo
__objc_class_name_NSPortCoder __objc_class_name_NSPortCoder
__objc_class_name_PortDecoder
__objc_class_name_PortEncoder
__objc_class_name_NSPortMessage __objc_class_name_NSPortMessage
__objc_class_name_GSPortCom __objc_class_name_GSPortCom
__objc_class_name_NSPortNameServer __objc_class_name_NSPortNameServer
@ -187,21 +178,4 @@ __objc_class_name_NSPointValue
__objc_class_name_NSPointerValue __objc_class_name_NSPointerValue
__objc_class_name_NSRectValue __objc_class_name_NSRectValue
__objc_class_name_NSSizeValue __objc_class_name_NSSizeValue
__objc_class_name_InPacket
__objc_class_name_InPort
__objc_class_name_OutPacket
__objc_class_name_OutPort
__objc_class_name_Port
__objc_class_name_RawCStream
__objc_class_name_StdioStream
__objc_class_name_Stream
__objc_class_name_TcpInPacket
__objc_class_name_TcpInPort
__objc_class_name_TcpOutPacket
__objc_class_name_TcpOutPort
__objc_class_name_TcpPrefPacket
__objc_class_name_TextCStream
__objc_class_name_UdpInPacket
__objc_class_name_UdpInPort
__objc_class_name_UdpOutPort
__objc_class_name_UnixFileHandle __objc_class_name_UnixFileHandle

View file

@ -34,110 +34,87 @@ include ../config.mak
# The tools to be compiled # The tools to be compiled
TEST_TOOL_NAME = \ TEST_TOOL_NAME = \
awake \ awake \
basic \ basic \
benchmark \ benchmark \
containers \ containers \
cstream \ create-abbrevs \
client \ create-regions \
diningPhilosophers \ diningPhilosophers \
fref \ fref \
gstcpport-server \ gstcpport-client \
gstcpport-client \ gstcpport-server \
invocation \ nsarchiver \
invocation_int \ nsarray \
invocation_char \ nsattributedstring \
invocation_short \ nsbundle \
invocation_long \ nscharacterset \
nsarray \ nsconnection \
nsarchiver \ nsconnection_client \
nsattributedstring \ nsconnection_server \
nsbundle \ nsdata \
nscharacterset \ nsdate \
nsdata \ nsdictionary \
NSData-test \ nsfilehandle \
nsdate \ nshashtable \
nsdictionary \ nshost \
nsfilehandle \ nsinvocation \
nshashtable \ nsmaptable \
nshost \ nsnotification \
nsinvocation \ nsprocessinfo \
nsmaptable \ nsscanner \
nsnotification \ nsset \
nsprocessinfo \ nstask \
nsscanner \ nstimer \
nsset \ nstimezone \
nstask \ release \
nstimer \ string \
nstimezone \ thread-except \
pipes \ values \
release \
server \
string \
tcpport-server \
tcpport-client \
thread-except \
values \
create-abbrevs \
create-regions
# The tool Objective-C source files to be compiled # The tool Objective-C source files to be compiled
testtool_OBJC_FILES = testtool.m awake_OBJC_FILES = awake.m
gstcpport-client_OBJC_FILES = gstcpport-client.m basic_OBJC_FILES = basic.m
gstcpport-server_OBJC_FILES = gstcpport-server.m
benchmark_OBJC_FILES = benchmark.m benchmark_OBJC_FILES = benchmark.m
containers_OBJC_FILES = containers.m containers_OBJC_FILES = containers.m
test01_OBJC_FILES = test01.m create-abbrevs_OBJC_FILES = create-abbrevs.m
test02_OBJC_FILES = test02.m create-regions_OBJC_FILES = create-regions.m
heap_OBJC_FILES = heap.m diningPhilosophers_OBJC_FILES = diningPhilosophers.m
randoms_OBJC_FILES = randoms.m fref_OBJC_FILES = fref.m
prepend_OBJC_FILES = prepend.m gstcpport-client_OBJC_FILES = gstcpport-client.m
pipes_OBJC_FILES = pipes.m gstcpport-server_OBJC_FILES = gstcpport-server.m
server_OBJC_FILES = server.m nsarchiver_OBJC_FILES = nsarchiver.m
client_OBJC_FILES = client.m
string_OBJC_FILES = string.m
values_OBJC_FILES = values.m
nsarray_OBJC_FILES = nsarray.m nsarray_OBJC_FILES = nsarray.m
nsattributedstring_OBJC_FILES = nsattributedstring.m nsattributedstring_OBJC_FILES = nsattributedstring.m
nsbundle_OBJC_FILES = nsbundle.m nsbundle_OBJC_FILES = nsbundle.m
nscharacterset_OBJC_FILES = nscharacterset.m
nsconnection_OBJC_FILES = nsconnection.m
nsconnection_client_OBJC_FILES = nsconnection_client.m
nsconnection_server_OBJC_FILES = nsconnection_server.m
nsdata_OBJC_FILES = nsdata.m nsdata_OBJC_FILES = nsdata.m
nsdate_OBJC_FILES = nsdate.m
nsdictionary_OBJC_FILES = nsdictionary.m nsdictionary_OBJC_FILES = nsdictionary.m
nsfilehandle_OBJC_FILES = nsfilehandle.m nsfilehandle_OBJC_FILES = nsfilehandle.m
nshashtable_OBJC_FILES = nshashtable.m
nshost_OBJC_FILES = nshost.m nshost_OBJC_FILES = nshost.m
nsinvocation_OBJC_FILES = nsinvocation.m nsinvocation_OBJC_FILES = nsinvocation.m
nsset_OBJC_FILES = nsset.m
nsprocessinfo_OBJC_FILES = nsprocessinfo.m
nsarchiver_OBJC_FILES = nsarchiver.m
oldclient_OBJC_FILES = oldclient.m
oldserver_OBJC_FILES = oldserver.m
invocation_OBJC_FILES = invocation.m
invocation_int_OBJC_FILES = invocation_int.m
invocation_char_OBJC_FILES = invocation_char.m
invocation_short_OBJC_FILES = invocation_short.m
invocation_long_OBJC_FILES = invocation_long.m
invocation_float_OBJC_FILES = invocation_float.m
diningPhilosophers_OBJC_FILES = diningPhilosophers.m
nsmaptable_OBJC_FILES = nsmaptable.m nsmaptable_OBJC_FILES = nsmaptable.m
nshashtable_OBJC_FILES = nshashtable.m
tcpport-server_OBJC_FILES = tcpport-server.m
tcpport-client_OBJC_FILES = tcpport-client.m
nsnotification_OBJC_FILES = nsnotification.m nsnotification_OBJC_FILES = nsnotification.m
nsprocessinfo_OBJC_FILES = nsprocessinfo.m
nsscanner_OBJC_FILES = nsscanner.m
nsset_OBJC_FILES = nsset.m
nstask_OBJC_FILES = nstask.m nstask_OBJC_FILES = nstask.m
nstimer_OBJC_FILES = nstimer.m nstimer_OBJC_FILES = nstimer.m
coder_OBJC_FILES = coder.m
cstream_OBJC_FILES = cstream.m
fref_OBJC_FILES = fref.m
basic_OBJC_FILES = basic.m
release_OBJC_FILES = release.m
nsscanner_OBJC_FILES = nsscanner.m
nsdate_OBJC_FILES = nsdate.m
awake_OBJC_FILES = awake.m
thread-except_OBJC_FILES = thread-except.m
nscharacterset_OBJC_FILES = nscharacterset.m
NSData-test_OBJC_FILES = NSData-test.m
nstimezone_OBJC_FILES = nstimezone.m nstimezone_OBJC_FILES = nstimezone.m
create-abbrevs_OBJC_FILES = create-abbrevs.m prepend_OBJC_FILES = prepend.m
create-regions_OBJC_FILES = create-regions.m release_OBJC_FILES = release.m
string_OBJC_FILES = string.m
test01_OBJC_FILES = test01.m
test02_OBJC_FILES = test02.m
testtool_OBJC_FILES = testtool.m
thread-except_OBJC_FILES = thread-except.m
values_OBJC_FILES = values.m
# The bundles to be compiled # The bundles to be compiled
BUNDLE_NAME=LoadMe BUNDLE_NAME=LoadMe

View file

@ -1,52 +1,8 @@
/* Test NSArchiver on encoding of self-referential forward references. */ /* Test NSArchiver on encoding of self-referential forward references. */
/* This tests an obscure, but important feature of archiving. GNUstep
implements it correctly; NeXT does not. When running in
NeXT-compatibility mode, (i.e. setting TRY_GNU_ARCHIVING to 0, and
setting SELF_REF_DECODE_SUBSTITUTES to 1) libgnustep-base crashes
when trying to use this feature. When the identical test is
compiled on a NeXTSTEP machine, it also crashes! */
/* Beginning of some parameters to vary. */
/* Both 1 works; both 0 works. 0 and 1 crash, as does NeXT's */
/* Use GNU Archiving features, if they are available. */
#define TRY_GNU_ARCHIVING 0
/* In the forward self-reference test, -initWithCoder substitutes
another object for self. */
#define SELF_REF_DECODE_SUBSTITUTES 0
/* End of some parameters to vary. */
#define GNU_ARCHIVING \
(TRY_GNU_ARCHIVING && defined(GNUSTEP_BASE_MAJOR_VERSION))
#if GNU_ARCHIVING
#include <base/Archiver.h>
#endif /* GNU_ARCHIVING */
#ifdef NX_CURRENT_COMPILER_RELEASE
#include <foundation/NSArchiver.h>
#include <foundation/NSArray.h>
#include <foundation/NSAutoreleasePool.h>
#else
#include <Foundation/NSArchiver.h> #include <Foundation/NSArchiver.h>
#include <Foundation/NSArray.h> #include <Foundation/NSArray.h>
#include <Foundation/NSAutoreleasePool.h> #include <Foundation/NSAutoreleasePool.h>
#endif
/* Set to 1 to use text coding instead of binary coding */
#define TEXTCSTREAM 1
#if TEXTCSTREAM
#include <base/Archiver.h>
#include <base/TextCStream.h>
#endif
/* The -initWithCoder methods substitutes another object for self. */
static int decode_substitutes;
/* This object encodes an -encodeConditionalObject: reference to a Foo. */ /* This object encodes an -encodeConditionalObject: reference to a Foo. */
@interface SubFoo : NSObject @interface SubFoo : NSObject
@ -67,53 +23,39 @@ static int decode_substitutes;
@implementation SubFoo @implementation SubFoo
- initWithSuperFoo: o label: (int)l - (void) dealloc
{ {
[super init]; RELEASE(super_foo);
super_foo = o; [super dealloc];
}
- (id) initWithSuperFoo: (id)o label: (int)l
{
self = [super init];
super_foo = RETAIN(o);
label = l; label = l;
return self; return self;
} }
- superFoo - (id) superFoo
{ {
return super_foo; return super_foo;
} }
- (void) encodeWithCoder: coder - (void) encodeWithCoder: (NSCoder*)coder
{ {
printf ("In [SubFoo encodeWithCoder:]\n"); printf ("In [SubFoo encodeWithCoder:]\n");
[super encodeWithCoder: coder];
#if GNU_ARCHIVING
[coder encodeObjectReference: super_foo
withName: @"super foo"];
#else
[coder encodeConditionalObject: super_foo]; [coder encodeConditionalObject: super_foo];
#endif
[coder encodeValueOfObjCType: @encode(int) [coder encodeValueOfObjCType: @encode(int)
at: &label]; at: &label];
} }
- initWithCoder: coder - (id) initWithCoder: (NSCoder*)coder
{ {
if (decode_substitutes) [coder decodeValueOfObjCType: @encode(id)
{ at: &super_foo];
id o = self;
self = [[[self class] alloc] init];
[o release];
}
else
{
self = [super initWithCoder: coder];
}
#if GNU_ARCHIVING
[coder decodeObjectAt: &super_foo
withName: NULL];
#else
super_foo = [coder decodeObject];
#endif
[coder decodeValueOfObjCType: @encode(int) [coder decodeValueOfObjCType: @encode(int)
at: &label]; at: &label];
return self; return self;
} }
@ -127,9 +69,15 @@ static int decode_substitutes;
@implementation Foo @implementation Foo
- init - (void) dealloc
{ {
[super init]; RELEASE(sub_foo);
[super dealloc];
}
- (id) init
{
self = [super init];
sub_foo = nil; sub_foo = nil;
label = 0; label = 0;
return self; return self;
@ -137,38 +85,28 @@ static int decode_substitutes;
- (void) setSubFoo: o - (void) setSubFoo: o
{ {
sub_foo = o; ASSIGN(sub_foo, o);
} }
- subFoo - (id) subFoo
{ {
return sub_foo; return sub_foo;
} }
- (void) encodeWithCoder: coder - (void) encodeWithCoder: (NSCoder*)coder
{ {
printf ("In [Foo encodeWithCoder:]\n"); printf ("In [Foo encodeWithCoder:]\n");
[super encodeWithCoder: coder];
[coder encodeObject: sub_foo]; [coder encodeObject: sub_foo];
[coder encodeValueOfObjCType: @encode(int) [coder encodeValueOfObjCType: @encode(int)
at: &label]; at: &label];
} }
- initWithCoder: coder - (id) initWithCoder: (NSCoder*)coder
{ {
if (decode_substitutes) [coder decodeValueOfObjCType: @encode(id)
{ at: &sub_foo];
id o = self;
self = [[[self class] alloc] init];
[o release];
}
else
{
self = [super initWithCoder: coder];
}
sub_foo = [coder decodeObject];
[coder decodeValueOfObjCType: @encode(int) [coder decodeValueOfObjCType: @encode(int)
at: &label]; at: &label];
return self; return self;
} }
@ -192,7 +130,6 @@ test_fref ()
id array; id array;
id foo, sub_foo; id foo, sub_foo;
printf ("\nTest encoding of forward references\n"); printf ("\nTest encoding of forward references\n");
decode_substitutes = 0;
array = [[NSMutableArray alloc] init]; array = [[NSMutableArray alloc] init];
foo = [[Foo alloc] init]; foo = [[Foo alloc] init];
@ -202,22 +139,14 @@ test_fref ()
[array addObject: foo]; [array addObject: foo];
[array insertObject: sub_foo atIndex: 0]; [array insertObject: sub_foo atIndex: 0];
#if GNU_ARCHIVING
[Archiver archiveRootObject: array toFile: @"fref.dat"];
#else
[NSArchiver archiveRootObject: array toFile: @"fref.dat"]; [NSArchiver archiveRootObject: array toFile: @"fref.dat"];
#endif
printf ("Encoded: "); printf ("Encoded: ");
[sub_foo print]; [sub_foo print];
[foo release]; RELEASE(foo);
[sub_foo release]; RELEASE(sub_foo);
[array release]; RELEASE(array);
#if GNU_ARCHIVING
array = [Unarchiver unarchiveObjectWithFile: @"fref.dat"];
#else
array = [NSUnarchiver unarchiveObjectWithFile: @"fref.dat"]; array = [NSUnarchiver unarchiveObjectWithFile: @"fref.dat"];
#endif
foo = [array objectAtIndex: 1]; foo = [array objectAtIndex: 1];
sub_foo = [foo subFoo]; sub_foo = [foo subFoo];
printf ("Decoded: "); printf ("Decoded: ");
@ -230,28 +159,19 @@ test_self_fref ()
{ {
id foo, sub_foo; id foo, sub_foo;
printf ("\nTest encoding of self-referential forward references\n"); printf ("\nTest encoding of self-referential forward references\n");
decode_substitutes = SELF_REF_DECODE_SUBSTITUTES;
foo = [[Foo alloc] init]; foo = [[Foo alloc] init];
[foo setLabel: 4]; [foo setLabel: 4];
sub_foo = [[SubFoo alloc] initWithSuperFoo: foo label: 3]; sub_foo = [[SubFoo alloc] initWithSuperFoo: foo label: 3];
[foo setSubFoo: sub_foo]; [foo setSubFoo: sub_foo];
#if GNU_ARCHIVING
[Archiver archiveRootObject: foo toFile: @"fref.dat"];
#else
[NSArchiver archiveRootObject: foo toFile: @"fref.dat"]; [NSArchiver archiveRootObject: foo toFile: @"fref.dat"];
#endif
printf ("Encoded: "); printf ("Encoded: ");
[sub_foo print]; [sub_foo print];
[foo release]; RELEASE(foo);
[sub_foo release]; RELEASE(sub_foo);
#if GNU_ARCHIVING
foo = [Unarchiver unarchiveObjectWithFile: @"fref.dat"];
#else
foo = [NSUnarchiver unarchiveObjectWithFile: @"fref.dat"]; foo = [NSUnarchiver unarchiveObjectWithFile: @"fref.dat"];
#endif
sub_foo = [foo subFoo]; sub_foo = [foo subFoo];
printf ("Decoded: "); printf ("Decoded: ");
[sub_foo print]; [sub_foo print];
@ -260,16 +180,12 @@ test_self_fref ()
int int
main () main ()
{ {
id arp = [NSAutoreleasePool new]; CREATE_AUTORELEASE_POOL(arp);
#if TEXTCSTREAM
[Archiver setDefaultCStreamClass: [TextCStream class]];
#endif
test_fref (); test_fref ();
test_self_fref (); test_self_fref ();
[arp release]; RELEASE(arp);
exit (0); exit (0);
} }

83
Testing/nsconnection.m Normal file
View file

@ -0,0 +1,83 @@
#include <Foundation/Foundation.h>
id myServer;
@interface Tester : NSObject
{
}
+ (void) connectWithPorts: (NSArray*)portArray;
+ (void) setServer: (id)anObject;
+ (void) startup;
- (int) doIt;
@end
@implementation Tester
+ (void) connectWithPorts: (NSArray*)portArray
{
NSAutoreleasePool *pool;
NSConnection *serverConnection;
Tester *serverObject;
pool = [[NSAutoreleasePool alloc] init];
serverConnection = [NSConnection
connectionWithReceivePort: [portArray objectAtIndex: 0]
sendPort: [portArray objectAtIndex: 1]];
serverObject = [[self alloc] init];
[(id)[serverConnection rootProxy] setServer: serverObject];
[serverObject release];
[[NSRunLoop currentRunLoop] run];
[pool release];
[NSThread exit];
return;
}
+ (void) setServer: (id)anObject
{
myServer = [anObject retain];
NSLog(@"Got %d", [myServer doIt]);
exit(0);
}
+ (void) startup
{
NSPort *port1;
NSPort *port2;
NSArray *portArray;
NSConnection *conn;
port1 = [NSPort port];
port2 = [NSPort port];
conn = [[NSConnection alloc] initWithReceivePort: port1 sendPort: port2];
[conn setRootObject: self];
/* Ports switched here. */
portArray = [NSArray arrayWithObjects: port2, port1, nil];
[NSThread detachNewThreadSelector: @selector(connectWithPorts:)
toTarget: self
withObject: portArray];
return;
}
- (int) doIt
{
return 42;
}
@end
int
main()
{
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
[Tester startup];
[[NSRunLoop currentRunLoop] run];
[pool release];
return 0;
}

View file

@ -0,0 +1,451 @@
#include <stdio.h>
#include <Foundation/NSObject.h>
#include <Foundation/NSConnection.h>
#include <Foundation/NSDistantObject.h>
#include <Foundation/NSDictionary.h>
#include <Foundation/NSString.h>
#include <Foundation/NSRunLoop.h>
#include <Foundation/NSData.h>
#include <Foundation/NSDate.h>
#include <Foundation/NSAutoreleasePool.h>
#include <Foundation/NSDebug.h>
#include <Foundation/NSProcessInfo.h>
#include <assert.h>
#include "server.h"
@interface Auth : NSObject
@end
@implementation Auth
- (BOOL) authenticateComponents: (NSMutableArray*)components
withData: (NSData*)authData
{
unsigned count = [components count];
while (count-- > 0)
{
id obj = [components objectAtIndex: count];
if ([obj isKindOfClass: [NSData class]] == YES)
{
NSMutableData *d = [obj mutableCopy];
unsigned l = [d length];
char *p = (char*)[d mutableBytes];
while (l-- > 0)
p[l] ^= 42;
[components replaceObjectAtIndex: count withObject: d];
RELEASE(d);
}
}
return YES;
}
@end
int con_data (id prx)
{
BOOL b, br;
unsigned char uc, ucr;
char c, cr;
short s, sr;
int i, ir;
long l, lr;
float flt, fltr;
double dbl, dblr;
char *str;
id obj;
small_struct small = {12};
foo ffoo = {99, "cow", 9876543};
int a3[3] = {66,77,88};
struct myarray ma = {{55,66,77}};
printf("Testing data sending\n");
printf("Boolean:\n");
b = YES;
printf(" sending %d", b);
br = [prx sendBoolean: b];
printf(" got %d", br);
if (b == !br)
printf(" ...ok\n");
else
printf(" *** ERROR ***\n");
br = b = YES;
printf(" sending ptr to %d", br);
[prx getBoolean: &br];
printf(" got %d", br);
if (b == !br)
printf(" ...ok\n");
else
printf(" *** ERROR ***\n");
printf(" (should get error returning ptr)\n");
#define TEST_CALL(test, send, got, sendp, var, varr, val, msg1, msg2) \
printf(test); \
var = val; \
printf(send, var); \
varr = [prx msg1 var]; \
printf(got, varr); \
if (varr != var+ADD_CONST) \
printf(" *** ERROR ***\n"); \
else \
printf(" ...ok\n"); \
varr = var = val+1; \
printf(sendp, varr); \
[prx msg2 &varr]; \
printf(got, varr); \
if (varr != var+ADD_CONST) \
printf(" *** ERROR ***\n"); \
else \
printf(" ...ok\n");
TEST_CALL("UChar:\n", " sending %x", " got %x", " sending ptr to %x",
uc, ucr, 23, sendUChar:, getUChar:)
printf(" (should get error returning ptr)\n");
TEST_CALL("Char:\n", " sending %x", " got %x", " sending ptr to %x",
c, cr, 23, sendChar:, getChar:)
printf(" (should get error returning ptr)\n");
TEST_CALL("Short:\n", " sending %d", " got %d", " sending ptr to %d",
s, sr, 23, sendShort:, getShort:)
TEST_CALL("Int:\n", " sending %d", " got %d", " sending ptr to %d",
i, ir, 23, sendInt:, getInt:)
TEST_CALL("Long:\n", " sending %ld", " got %ld", " sending ptr to %ld",
l, lr, 23, sendLong:, getLong:)
TEST_CALL("Float:\n", " sending %f", " got %f", " sending ptr to %f",
flt, fltr, 23.2, sendFloat:, getFloat:)
TEST_CALL("Double:\n", " sending %g", " got %g", " sending ptr to %g",
dbl, dblr, 23.2, sendDouble:, getDouble:)
flt = 2.718;
dbl = 3.14159265358979323846264338327;
printf(" sending double %f, float %f\n", dbl, flt);
[prx sendDouble:dbl andFloat:flt];
printf("String:\n");
str = "My String 1";
printf(" sending (%s)", str);
str = [prx sendString: str];
printf(" got (%s)\n", str);
str = "My String 3";
printf(" sending ptr to (%s)", str);
[prx getString: &str];
printf(" got (%s)\n", str);
printf("Small Struct:\n");
//printf(" sending %x", small.z);
//small = [prx sendSmallStruct: small];
//printf(" got %x\n", small.z);
printf(" sending ptr to %x", small.z);
[prx getSmallStruct: &small];
printf(" got %x\n", small.z);
printf("Struct:\n");
printf(" sending i=%d,s=%s,l=%ld", ffoo.i, ffoo.s, ffoo.l);
ffoo = [prx sendStruct: ffoo];
printf(" got %d %s %ld\n", ffoo.i, ffoo.s, ffoo.l);
printf(" sending ptr to i=%d,s=%s,l=%ld", ffoo.i, ffoo.s, ffoo.l);
[prx getStruct: &ffoo];
printf(" got i=%d,s=%s,l=%ld\n", ffoo.i, ffoo.s, ffoo.l);
printf("Object:\n");
obj = [NSObject new];
[prx addObject: obj]; // FIXME: Why is this needed?
printf(" sending %s", [[obj description] cString]);
obj = [prx sendObject: obj];
printf(" got %s\n", [[obj description] cString]);
printf(" sending ptr to %s", [[obj description] cString]);
[prx getObject: &obj];
printf(" got %s\n", [[obj description] cString]);
printf("Many Arguments:\n");
[prx manyArgs:1 :2 :3 :4 :5 :6 :7 :8 :9 :10 :11 :12];
return 0;
}
int
con_messages (id prx)
{
id obj;
obj = [NSObject new];
printf("Oneway Void message:\n");
[prx shout];
printf(" ok\n");
/* this next line doesn't actually test callbacks, it tests
sending the same object twice in the same message. */
printf("Send same object twice in message\n");
[prx sendObject: prx];
printf(" ok\n");
printf("performSelector:\n");
if (prx != [prx performSelector:sel_get_any_uid("self")])
printf(" ERROR\n");
else
printf(" ok\n");
printf("Testing bycopy/byref:\n");
[prx sendBycopy: obj];
#ifdef _F_BYREF
[prx sendByref: obj];
[prx sendByref:@"hello"];
[prx sendByref:[NSDate date]];
#endif
printf(" ok\n");
return 0;
}
int
con_benchmark (id prx)
{
int i;
NSDate *d = [NSDate date];
NSMutableData *sen = [NSMutableData data];
id localObj;
id rep;
printf("Benchmarking\n");
[sen setLength: 100000];
rep = [prx sendObject: sen];
printf(" Sent: 0x%p, Reply: 0x%p, Length: %d\n", sen, rep, [rep length]);
[NSConnection setDebug: 0];
[NSDistantObject setDebug: 0];
//[NSPort setDebug: 0];
localObj = [[NSObject alloc] init];
[prx addObject: localObj]; // FIXME: Why is this needed?
for (i = 0; i < 10000; i++)
{
#if 0
k = [prx count];
for (j = 0; j < k; j++)
{
id remote_peer_obj = [prx objectAt: j];
}
#endif
[prx echoObject: localObj];
}
printf(" Delay is %f\n", [d timeIntervalSinceNow]);
return 0;
}
int
con_statistics (id prx)
{
int j;
id localObj, cobj, a, o;
printf("------------------------------------------------------------\n");
printf("Printing Statistics\n");
localObj = [[NSObject alloc] init];
[prx outputStats: localObj];
printf(" >>list proxy's hash is 0x%d\n", [prx hash]);
printf(" >>list proxy's self is 0x%p = 0x%p\n", [prx self], prx);
printf(" >>proxy's name is (%s)\n", [prx name]);
cobj = [prx connectionForProxy];
o = [cobj statistics];
a = [o allKeys];
for (j = 0; j < [a count]; j++)
{
id k = [a objectAtIndex:j];
id v = [o objectForKey:k];
printf(" %s - %s\n", [k cString], [[v description] cString]);
}
printf("------------------------------------------------------------\n");
return 0;
}
int
con_loop (id prx)
{
NSAutoreleasePool *arp;
id cobj;
arp = [NSAutoreleasePool new];
cobj = [prx connectionForProxy];
printf("%d\n", [cobj retainCount]);
printf("%s\n", [[[cobj statistics] description] cString]);
//printf("%s\n", GSDebugAllocationList(YES));
[NSRunLoop runUntilDate: [NSDate dateWithTimeIntervalSinceNow: 2 * 60]];
[cobj invalidate];
[arp release];
return 0;
}
int
con_objects (id prx)
{
int j, k;
id localObj;
localObj = [NSObject new];
[prx addObject:localObj];
k = [prx count];
for (j = 0; j < k; j++)
{
id remote_peer_obj = [prx objectAt:j];
printf("triangle %d object proxy's hash is 0x%x\n",
j, (unsigned)[remote_peer_obj hash]);
#if 0
/* xxx look at this again after we use release/retain everywhere */
if ([remote_peer_obj isProxy])
[remote_peer_obj release];
#endif
remote_peer_obj = [prx objectAt:j];
printf("repeated triangle %d object proxy's hash is 0x%x\n",
j, (unsigned)[remote_peer_obj hash]);
}
return 0;
}
void
usage(const char *program)
{
printf("Usage: %s [-ds] [t|b|m|l|o] [host] [server]\n", program);
printf(" -d - Debug connection\n");
printf(" -s - Print Statistics\n");
printf(" -t - Data type test [default]\n");
printf(" -b - Benchmark test\n");
printf(" -m - Messaging test\n");
printf(" -l - Loop test\n");
printf(" -o - Objects test\n");
}
typedef enum {
NO_TEST, TYPE_TEST, BENCHMARK_TEST, MESSAGE_TEST,
LOOP_TEST, OBJECT_TEST
} test_t;
int main (int argc, char *argv[], char **env)
{
int c, debug, stats;
test_t type_test;
id cobj, prx;
NSAutoreleasePool *arp;
Auth *auth;
extern int optind;
extern char *optarg;
[NSProcessInfo initializeWithArguments: argv count: argc environment: env];
arp = [NSAutoreleasePool new];
auth = [Auth new];
GSDebugAllocationActive(YES);
debug = 0;
type_test = 0;
stats = 0;
while ((c = getopt(argc, argv, "hdtbmslo")) != EOF)
switch (c)
{
case 'd':
debug = 1;
break;
case 't':
type_test = TYPE_TEST;
break;
case 'b':
type_test = BENCHMARK_TEST;
break;
case 'm':
type_test = MESSAGE_TEST;
break;
case 's':
stats = 1;
break;
case 'l':
type_test = LOOP_TEST;
break;
case 'o':
type_test = OBJECT_TEST;
break;
case 'h':
usage(argv[0]);
exit(0);
break;
default:
usage(argv[0]);
exit(1);
break;
}
if (type_test == NO_TEST)
type_test = TYPE_TEST;
if (debug)
{
[NSConnection setDebug: 10];
[NSDistantObject setDebug: 10];
//[NSPort setDebug: 10];
}
if (optind < argc)
{
if (optind+1 < argc)
prx = [NSConnection rootProxyForConnectionWithRegisteredName:
[NSString stringWithCString: argv[optind+1]]
host: [NSString stringWithCString:argv[optind]]];
else
prx = [NSConnection rootProxyForConnectionWithRegisteredName:
@"test2server"
host:[NSString stringWithCString:argv[optind]]];
}
else
prx = [NSConnection rootProxyForConnectionWithRegisteredName:@"test2server"
host:nil];
if (prx == nil)
{
printf("ERROR: Failed to connect to server\n");
return -1;
}
cobj = [prx connectionForProxy];
[cobj setDelegate:auth];
[cobj setRequestTimeout:180.0];
[cobj setReplyTimeout:180.0];
[prx print: "This is a message from the client. Starting Tests!"];
switch (type_test)
{
case TYPE_TEST:
con_data (prx);
break;
case BENCHMARK_TEST:
con_benchmark (prx);
break;
case MESSAGE_TEST:
con_messages (prx);
break;
case LOOP_TEST:
con_loop (prx);
break;
case OBJECT_TEST:
con_objects (prx);
break;
default:
break;
}
if (stats)
con_statistics (prx);
[arp release];
return 0;
}

View file

@ -0,0 +1,468 @@
#include <Foundation/NSDictionary.h>
#include <Foundation/NSConnection.h>
#include <Foundation/NSDistantObject.h>
#include <Foundation/NSString.h>
#include <Foundation/NSNotification.h>
#include <Foundation/NSData.h>
#include <Foundation/NSRunLoop.h>
#include <Foundation/NSProcessInfo.h>
#include <Foundation/NSAutoreleasePool.h>
#include "server.h"
@implementation Server
- (NSData*) authenticationDataForComponents: (NSMutableArray*)components
{
unsigned count = [components count];
while (count-- > 0)
{
id obj = [components objectAtIndex: count];
if ([obj isKindOfClass: [NSData class]] == YES)
{
NSMutableData *d = [obj mutableCopy];
unsigned l = [d length];
char *p = (char*)[d mutableBytes];
while (l-- > 0)
p[l] ^= 42;
[components replaceObjectAtIndex: count withObject: d];
RELEASE(d);
}
}
return [NSData data];
}
- init
{
the_array = [[NSMutableArray alloc] init];
return self;
}
- (unsigned) count
{
return [the_array count];
}
- (void) addObject: o
{
[the_array addObject:o];
}
- objectAt: (unsigned)i
{
if (i < [the_array count])
return [the_array objectAtIndex: i];
else
return nil;
}
- echoObject: obj
{
return obj;
}
- print: (const char *)msg
{
printf(">>%s<<\n", msg);
fflush(stdout);
return self;
}
- (BOOL) sendBoolean: (BOOL)b
{
printf("(%s) got %d, returning %d\n", sel_get_name(_cmd), b, !b);
fflush(stdout);
return !b;
}
/* This causes problems, because the runtime encodes this as "*", a string! */
- (void) getBoolean: (BOOL*)bp
{
printf("(%s) got %d, returning %d\n", sel_get_name(_cmd), *bp, !(*bp));
fflush(stdout);
*bp = !(*bp);
}
/* This causes problems, because the runtime encodes this as "*", a string! */
- (unsigned char) sendUChar: (unsigned char)num
{
unsigned char rnum = num + ADD_CONST;
printf("(%s) got %d, returning %d\n", sel_get_name(_cmd), num, rnum);
fflush(stdout);
return rnum;
}
/* This causes problems, because the runtime encodes this as "*", a string! */
- (void) getUChar: (unsigned char *)num
{
unsigned char rnum = *num + ADD_CONST;
printf("(%s) got %d, returning %d\n", sel_get_name(_cmd), *num, rnum);
*num = rnum;
fflush(stdout);
}
- (char) sendChar: (char)num
{
char rnum = num + ADD_CONST;
printf("(%s) got %d, returning %d\n", sel_get_name(_cmd), num, rnum);
fflush(stdout);
return rnum;
}
- (void) getChar: (char *)num
{
char rnum = *num + ADD_CONST;
printf("(%s) got %d, returning %d\n", sel_get_name(_cmd), *num, rnum);
*num = rnum;
fflush(stdout);
}
- (short) sendShort: (short)num
{
short rnum = num + ADD_CONST;
printf("(%s) got %d, returning %d\n", sel_get_name(_cmd), num, rnum);
fflush(stdout);
return rnum;
}
- (void) getShort: (short *)num
{
short rnum = *num + ADD_CONST;
printf("(%s) got %d, returning %d\n", sel_get_name(_cmd), *num, rnum);
*num = rnum;
fflush(stdout);
}
- (int) sendInt: (int)num
{
int rnum = num + ADD_CONST;
printf("(%s) got %d, returning %d\n", sel_get_name(_cmd), num, rnum);
fflush(stdout);
return rnum;
}
- (void) getInt: (int *)num
{
int rnum = *num + ADD_CONST;
printf("(%s) got %d, returning %d\n", sel_get_name(_cmd), *num, rnum);
*num = rnum;
fflush(stdout);
}
- (long) sendLong: (long)num
{
long rnum = num + ADD_CONST;
printf("(%s) got %ld, returning %ld\n", sel_get_name(_cmd), num, rnum);
fflush(stdout);
return rnum;
}
- (void) getLong: (long *)num
{
long rnum = *num + ADD_CONST;
printf("(%s) got %ld, returning %ld\n", sel_get_name(_cmd), *num, rnum);
*num = rnum;
fflush(stdout);
}
- (float) sendFloat: (float)num
{
float rnum = num + ADD_CONST;
printf("(%s) got %f, returning %f\n", sel_get_name(_cmd), num, rnum);
fflush(stdout);
return rnum;
}
- (void) getFloat: (float *)num
{
float rnum = *num + ADD_CONST;
printf("(%s) got %f, returning %f\n", sel_get_name(_cmd), *num, rnum);
*num = rnum;
fflush(stdout);
}
- (double) sendDouble: (double)num
{
double rnum = num + ADD_CONST;
printf("(%s) got %g, returning %g\n", sel_get_name(_cmd), num, rnum);
fflush(stdout);
return rnum;
}
- (void) getDouble: (double *)num
{
double rnum = *num + ADD_CONST;
printf("(%s) got %g, returning %g\n", sel_get_name(_cmd), *num, rnum);
*num = rnum;
fflush(stdout);
}
- (small_struct) sendSmallStruct: (small_struct)str
{
char rnum = str.z + ADD_CONST;
printf("(%s) got %d, returning %d\n", sel_get_name(_cmd), str.z, rnum);
fflush(stdout);
str.z = rnum;
return str;
}
- (void) getSmallStruct: (small_struct *)str
{
char rnum = str->z + ADD_CONST;
printf("(%s) got %d, returning %d\n", sel_get_name(_cmd), str->z, rnum);
fflush(stdout);
str->z = rnum;
}
- (foo) sendStruct: (foo)f
{
foo f2 = {1, "horse", 987654};
printf("(%s) got i=%d s=%s l=%lu", sel_get_name(_cmd), f.i, f.s, f.l);
fflush(stdout);
printf(" returning i=%d s=%s l=%lu\n", f2.i, f2.s, f2.l);
fflush(stdout);
return f2;
}
- (void) getStruct: (foo *)f
{
foo f2 = {1, "horse", 987654};
printf("(%s) got i=%d s=%s l=%lu,", sel_get_name(_cmd), f->i, f->s, f->l);
fflush(stdout);
printf(" returning i=%d s=%s l=%lu\n", f2.i, f2.s, f2.l);
fflush(stdout);
*f = f2;
}
- sendObject: (id)str
{
printf ("(%s) got object (%s)\n", sel_get_name(_cmd),
object_get_class_name (str));
fflush(stdout);
return str;
}
- (void) getObject: (id *)str
{
printf ("(%s) got object (%s)\n", sel_get_name(_cmd),
object_get_class_name (*str));
fflush(stdout);
}
- (char *) sendString: (char *)str
{
printf ("(%s) got string (%s)", sel_get_name(_cmd), str);
str[0] = 'N';
printf(" returning (%s)\n", str);
fflush(stdout);
return str;
}
- (void) getString: (char **)str
{
printf ("(%s) got string (%s)", sel_get_name(_cmd), *str);
(*str)[0] = 'N';
printf(" returning (%s)\n", *str);
fflush(stdout);
}
- (oneway void) shout
{
printf ("(%s) got it\n", sel_get_name(_cmd));
fflush(stdout);
}
/* sender must also respond to 'bounce:count:' */
- bounce: sender count: (int)c
{
printf ("(%s) got message %d, bouncing back %d", sel_get_name(_cmd), c, c-1);
fflush(stdout);
if (--c)
[sender bounce:self count:c];
return self;
}
- (void) outputStats:obj
{
id c = [obj connectionForProxy];
id o = [c statistics];
id a = [o allKeys];
int j;
printf("------------------------------------------------------------\n");
printf("Printing Statistics\n");
printf(" Number of connections - %d\n", [[NSConnection allConnections] count]);
printf(" This connection -\n");
for (j = 0; j < [a count]; j++)
{
id k = [a objectAtIndex:j];
id v = [o objectForKey:k];
printf(" %s - %s\n", [k cString], [[v description] cString]);
}
printf("------------------------------------------------------------\n");
fflush(stdout);
}
/* Doesn't work because GCC generates the wrong encoding: "@0@+8:+12^i+16" */
- sendArray: (int[3])a
{
printf(" >> array %d %d %d\n", a[0], a[1], a[2]);
fflush(stdout);
return self;
}
- sendStructArray: (struct myarray)ma
{
printf(" >>struct array %d %d %d\n", ma.a[0], ma.a[1], ma.a[2]);
fflush(stdout);
return self;
}
- sendDouble: (double)d andFloat: (float)f
{
printf("(%s) got double %f, float %f\n", sel_get_name(_cmd), d, f);
fflush(stdout);
return self;
}
- sendBycopy: (bycopy id)o
{
printf(" >> bycopy class is %s\n", object_get_class_name (o));
fflush(stdout);
return self;
}
#ifdef _F_BYREF
- sendByref: (byref id)o
{
printf(" >> byref class is %s\n", object_get_class_name (o));
fflush(stdout);
return self;
}
#endif
- manyArgs: (int)i1 : (int)i2 : (int)i3 : (int)i4 : (int)i5 : (int)i6
: (int)i7 : (int)i8 : (int)i9 : (int)i10 : (int)i11 : (int)i12
{
printf("manyArgs: got %d %d %d %d %d %d %d %d %d %d %d %d\n",
i1, i2, i3, i4, i5, i6, i7, i8, i9, i10, i11, i12);
fflush(stdout);
return self;
}
- connectionBecameInvalid: notification
{
id anObj = [notification object];
if ([anObj isKindOf:[NSConnection class]])
{
int i, count = [the_array count];
for (i = count-1; i >= 0; i--)
{
id o = [the_array objectAtIndex: i];
if ([o isProxy] && [o connectionForProxy] == anObj)
[the_array removeObjectAtIndex: i];
}
if (count != [the_array count])
printf("$$$$$ connectionBecameInvalid: removed from the_array\n");
}
else
{
[self error:"non Connection is invalid"];
}
return self;
}
- (NSConnection*) connection: ancestor didConnect: newConn
{
printf("%s\n", sel_get_name(_cmd));
[[NSNotificationCenter defaultCenter]
addObserver: self
selector: @selector(connectionBecameInvalid:)
name: NSConnectionDidDieNotification
object: newConn];
[newConn setDelegate: self];
return newConn;
}
@end
void
usage(const char *program)
{
printf("Usage: %s [-d -t#] [server_name]\n", program);
printf(" -d - Debug connection\n");
printf(" -t - Timeout after # seconds\n");
}
int main(int argc, char *argv[], char **env)
{
int i, debug, timeout;
id l = [[Server alloc] init];
id o = [[NSObject alloc] init];
NSConnection *c;
NSAutoreleasePool *arp = [NSAutoreleasePool new];
extern int optind;
extern char *optarg;
[NSProcessInfo initializeWithArguments: argv count: argc environment: env];
debug = 0;
timeout = 0;
while ((i = getopt(argc, argv, "hdt:")) != EOF)
switch (i)
{
case 'd':
debug = 1;
break;
case 't':
timeout = atoi(optarg);;
break;
case 'h':
usage(argv[0]);
exit(0);
break;
default:
usage(argv[0]);
exit(1);
break;
}
#if NeXT_runtime
[NSDistantObject setProtocolForProxies:@protocol(AllProxies)];
#endif
if (debug)
{
[NSConnection setDebug: 10];
[NSDistantObject setDebug: 10];
}
c = [NSConnection defaultConnection];
[c setRootObject: l];
if (optind < argc)
[c registerName: [NSString stringWithCString: argv[optind]]];
else
[c registerName: @"test2server"];
[[NSNotificationCenter defaultCenter]
addObserver: l
selector: @selector(connectionBecameInvalid:)
name: NSConnectionDidDieNotification
object: c];
[c setDelegate: l];
[l addObject: o];
printf(" list's hash is 0x%x\n", (unsigned)[l hash]);
printf(" object's hash is 0x%x\n", (unsigned)[o hash]);
printf("Running...\n");
if (timeout)
[NSRunLoop runUntilDate: [NSDate dateWithTimeIntervalSinceNow: timeout]];
else
[NSRunLoop run];
printf("Finished\n");
[arp release];
exit(0);
}

View file

@ -1,8 +1,385 @@
#include <stdio.h>
#include <Foundation/NSData.h> #include <Foundation/NSData.h>
#include <Foundation/NSException.h>
#include <Foundation/NSRange.h>
#include <Foundation/NSSerialization.h>
#include <Foundation/NSArchiver.h> #include <Foundation/NSArchiver.h>
#include <Foundation/NSAutoreleasePool.h> #include <Foundation/NSAutoreleasePool.h>
#include <Foundation/NSString.h> #include <Foundation/NSString.h>
/******************************************************************************
* Module : NSMutableData(NSData) --- Black Box test module for the
* *Data classes to make sure that methods that raise exceptions
* do so, and that the exceptions are raised properly.
*
* Author : John W. M. Stevens
...............................................................................
15 April 1997
******************************************************************************/
/* Data for stuffing into *Data objects. I like printable data, as it
* gives a quick visual check mechanism, but it has the disadvantage
* of not checking for 8 bit cleanliness.
*/
char *testString = "Test string for mutable data and archiver classes.";
char *subString = "Sub String";
/*-----------------------------------------------------------------------------
| Routine : TestNSMutableData() --- Create an instance of an NSMutableData
| class, initialize it with a C string (to have something
| printable for tests) and invoke the two methods that
| should raise NSRangeException exceptions using ranges that
| cross both edges of the buffer boundary.
|
| Notes : Please see work logs for discussion.
-----------------------------------------------------------------------------*/
void
TestNSMutableData(void)
{
auto NSMutableData *nsMutData;
auto char *str;
auto NSRange range;
/* Allocate and initialize an instance of an NSMutableData
* class.
*/
nsMutData = [NSMutableData dataWithLength: strlen( testString ) + 1];
str = (char *) [nsMutData mutableBytes];
strcpy(str, testString);
/* Get contents, display. */
str = NULL;
str = (char *) [nsMutData mutableBytes];
printf("NSMutableData Test ---------------------------------------------"
"---------------\n"
"1) String: (%s)\n", str);
/* Attempt to force Range exception by having range start before
* zero.
*/
NS_DURING
range = NSMakeRange(-2, strlen( subString ));
[nsMutData replaceBytesInRange: range
withBytes : subString ];
NS_HANDLER
fprintf(stderr,
"%s %d : Exception %s - %s\n",
__FILE__,
__LINE__,
[[localException name] cString],
[[localException reason] cString]);
NS_ENDHANDLER
/* Attempt to force another Range exception. */
NS_DURING
range = NSMakeRange(41, strlen( subString ));
[nsMutData replaceBytesInRange: range
withBytes : subString ];
NS_HANDLER
fprintf(stderr,
"%s %d : Exception %s - %s\n",
__FILE__,
__LINE__,
[[localException name] cString],
[[localException reason] cString]);
NS_ENDHANDLER
/* Attempt to force another Range exception. */
NS_DURING
range = NSMakeRange(42, strlen( subString ));
[nsMutData replaceBytesInRange: range
withBytes : subString ];
NS_HANDLER
fprintf(stderr,
"%s %d : Exception %s - %s\n",
__FILE__,
__LINE__,
[[localException name] cString],
[[localException reason] cString]);
NS_ENDHANDLER
/* How about a length that is less than zero? */
NS_DURING
range = NSMakeRange(6, -3.0);
[nsMutData replaceBytesInRange: range
withBytes : subString ];
NS_HANDLER
fprintf(stderr,
"%s %d : Exception %s - %s\n",
__FILE__,
__LINE__,
[[localException name] cString],
[[localException reason] cString]);
NS_ENDHANDLER
/* Attempt to force Range exception by having range start before
* zero.
*/
NS_DURING
range = NSMakeRange(-2, strlen( subString ));
[nsMutData resetBytesInRange: range];
NS_HANDLER
fprintf(stderr,
"%s %d : Exception %s - %s\n",
__FILE__,
__LINE__,
[[localException name] cString],
[[localException reason] cString]);
NS_ENDHANDLER
/* Attempt to force another Range exception. */
NS_DURING
range = NSMakeRange(41, strlen( subString ));
[nsMutData resetBytesInRange: range];
NS_HANDLER
fprintf(stderr,
"%s %d : Exception %s - %s\n",
__FILE__,
__LINE__,
[[localException name] cString],
[[localException reason] cString]);
NS_ENDHANDLER
/* Attempt to force another Range exception. */
NS_DURING
range = NSMakeRange(42, strlen( subString ));
[nsMutData resetBytesInRange: range];
NS_HANDLER
fprintf(stderr,
"%s %d : Exception %s - %s\n",
__FILE__,
__LINE__,
[[localException name] cString],
[[localException reason] cString]);
NS_ENDHANDLER
/* How about a length less than zero? */
NS_DURING
range = NSMakeRange(6.0, -3.0);
[nsMutData resetBytesInRange: range];
NS_HANDLER
fprintf(stderr,
"%s %d : Exception %s - %s\n",
__FILE__,
__LINE__,
[[localException name] cString],
[[localException reason] cString]);
NS_ENDHANDLER
/* Get contents, display. */
str = NULL;
str = (char *) [nsMutData mutableBytes];
printf("2) String: (%s)\n", str);
/* Attempt to force an out of memory exception. */
#if 0
for ( ; ; )
{
/* Append. */
[nsMutData appendBytes: testString
length : strlen( testString ) + 1];
/* Show current value. */
printf("%9u\r", [nsMutData length]);
}
#endif
}
/*-----------------------------------------------------------------------------
| Routine : TestNSData() --- Create an instance of an NSData
| class, initialize it with a C string (to have something
| printable for tests) and invoke the two methods that
| should raise NSRangeException exceptions using ranges that
| cross both edges of the buffer boundary.
|
| Notes : Please see work logs for discussion.
-----------------------------------------------------------------------------*/
void
TestNSData(void)
{
auto NSData *nsData;
auto NSData *newNsData;
auto char *str;
auto char bfr[128];
auto NSRange range;
/* Allocate and initialize an instance of an NSData
* class.
*/
nsData = [NSData dataWithBytes: testString
length : (unsigned int) strlen( testString ) + 1];
/* Get contents, display. */
str = (char *) [nsData bytes];
printf("NSData Test ----------------------------------------------------"
"---------------\n"
"1) String: (%s)\n", str);
/* Attempt to force Range exception by having range start before
* zero.
*/
NS_DURING
/* Get buffer piece. */
range = NSMakeRange(-2.0, 6.0);
[nsData getBytes: bfr
range : range];
/* Print buffer piece. */
bfr[6] = '\0';
printf(" A) Buffer: (%s)\n", bfr);
NS_HANDLER
fprintf(stderr,
"%s %d : Exception %s - %s\n",
__FILE__,
__LINE__,
[[localException name] cString],
[[localException reason] cString]);
NS_ENDHANDLER
/* Attempt to force another Range exception. */
NS_DURING
/* Get piece. */
range = NSMakeRange(41, strlen( subString ));
[nsData getBytes: bfr
range : range];
/* Print buffer piece. */
bfr[strlen( subString )] = '\0';
printf(" B) Buffer: (%s)\n", bfr);
NS_HANDLER
fprintf(stderr,
"%s %d : Exception %s - %s\n",
__FILE__,
__LINE__,
[[localException name] cString],
[[localException reason] cString]);
NS_ENDHANDLER
/* Attempt to force another Range exception. */
NS_DURING
range = NSMakeRange(42, strlen( subString ));
[nsData getBytes: bfr
range : range];
/* Print buffer piece. */
bfr[strlen( subString )] = '\0';
printf(" C) Buffer: (%s)\n", bfr);
NS_HANDLER
fprintf(stderr,
"%s %d : Exception %s - %s\n",
__FILE__,
__LINE__,
[[localException name] cString],
[[localException reason] cString]);
NS_ENDHANDLER
/* How about less than zero length? */
NS_DURING
range = NSMakeRange(5.0, -4.0);
[nsData getBytes: bfr
range : range];
/* Print buffer piece. */
bfr[strlen( subString )] = '\0';
printf(" C) Buffer: (%s)\n", bfr);
NS_HANDLER
fprintf(stderr,
"%s %d : Exception %s - %s\n",
__FILE__,
__LINE__,
[[localException name] cString],
[[localException reason] cString]);
NS_ENDHANDLER
/*=================== subDataWithRange ======================================*/
/* Attempt to force Range exception by having range start before
* zero.
*/
NS_DURING
/* Get buffer piece. */
range = NSMakeRange(-2.0, 6.0);
newNsData = [nsData subdataWithRange: range];
/* Print buffer piece. */
[newNsData getBytes: bfr];
bfr[6] = '\0';
printf(" D) Buffer: (%s)\n", bfr);
NS_HANDLER
fprintf(stderr,
"%s %d : Exception %s - %s\n",
__FILE__,
__LINE__,
[[localException name] cString],
[[localException reason] cString]);
NS_ENDHANDLER
/* Attempt to force another Range exception. */
NS_DURING
/* Get buffer piece. */
range = NSMakeRange(41, strlen( subString ));
newNsData = [nsData subdataWithRange: range];
/* Print buffer piece. */
[newNsData getBytes: bfr];
bfr[strlen( subString )] = '\0';
printf(" E) Buffer: (%s)\n", bfr);
NS_HANDLER
fprintf(stderr,
"%s %d : Exception %s - %s\n",
__FILE__,
__LINE__,
[[localException name] cString],
[[localException reason] cString]);
NS_ENDHANDLER
/* Attempt to force another Range exception. */
NS_DURING
/* Get buffer piece. */
range = NSMakeRange(42, strlen( subString ));
newNsData = [nsData subdataWithRange: range];
/* Print buffer piece. */
[newNsData getBytes: bfr];
bfr[strlen( subString )] = '\0';
printf(" F) Buffer: (%s)\n", bfr);
NS_HANDLER
fprintf(stderr,
"%s %d : Exception %s - %s\n",
__FILE__,
__LINE__,
[[localException name] cString],
[[localException reason] cString]);
NS_ENDHANDLER
/* How about a length less than zero? */
NS_DURING
/* Get buffer piece. */
range = NSMakeRange(9.0, -6.0);
newNsData = [nsData subdataWithRange: range];
/* Print buffer piece. */
[newNsData getBytes: bfr];
bfr[strlen( subString )] = '\0';
printf(" F) Buffer: (%s)\n", bfr);
NS_HANDLER
fprintf(stderr,
"%s %d : Exception %s - %s\n",
__FILE__,
__LINE__,
[[localException name] cString],
[[localException reason] cString]);
NS_ENDHANDLER
/* Get contents, display. */
str = NULL;
str = (char *) [nsData bytes];
printf("2) String: (%s)\n", str);
}
int int
main() main()
{ {
@ -86,6 +463,12 @@ main()
[d setCapacity: 2000000]; [d setCapacity: 2000000];
printf("Set capacity of shared memory item to %d\n", [d capacity]); printf("Set capacity of shared memory item to %d\n", [d capacity]);
/* Test NSMutableData. */
TestNSMutableData();
/* Test NSData. */
TestNSData();
[pool release]; [pool release];
exit(0); exit(0);

View file

@ -1,13 +1,18 @@
#include <Foundation/NSRunLoop.h> #include <Foundation/NSRunLoop.h>
#include <base/Invocation.h>
#include <Foundation/NSTimer.h> #include <Foundation/NSTimer.h>
#include <Foundation/NSAutoreleasePool.h> #include <Foundation/NSInvocation.h>
#include <Foundation/NSAutoreleasePool.h>
@interface TestDouble : NSObject @interface TestDouble : NSObject
+ (double) testDouble; + (double) testDouble;
- (double) testDoubleInstance; - (double) testDoubleInstance;
@end @end
@implementation TestDouble @implementation TestDouble
+ (void) sayCount
{
static int count = 0;
printf ("Timer fired %d times\n", ++count);
}
+ (double) testDouble + (double) testDouble
{ {
return 12345678912345.0; return 12345678912345.0;
@ -23,20 +28,20 @@ double test_double ()
return 92345678912345.0; return 92345678912345.0;
} }
void say_count ()
{
static int count = 0;
printf ("Timer fired %d times\n", ++count);
}
int main() int main()
{ {
NSAutoreleasePool *arp = [NSAutoreleasePool new]; NSAutoreleasePool *arp = [NSAutoreleasePool new];
volatile double foo, bar; volatile double foo, bar;
id inv = [[VoidFunctionInvocation alloc] initWithVoidFunction: say_count]; id inv;
id o; id o;
id d; id d;
inv = [NSInvocation invocationWithMethodSignature:
[TestDouble methodSignatureForSelector: @selector(sayCount)]];
[inv setSelector: @selector(sayCount)];
[inv setTarget: [TestDouble class]];
foo = [TestDouble testDouble]; foo = [TestDouble testDouble];
printf ("TestDouble is %f\n", foo); printf ("TestDouble is %f\n", foo);
foo = [TestDouble testDouble]; foo = [TestDouble testDouble];

View file

@ -17,51 +17,58 @@ typedef struct _foo {
struct myarray { struct myarray {
int a[3]; int a[3];
}; };
#define ADD_CONST 47
@protocol ServerProtocol @protocol ServerProtocol
- (void) addObject: o; - (BOOL) sendBoolean: (BOOL)b;
- (void) getBoolean: (BOOL*)bp;
- (unsigned char) sendUChar: (unsigned char)uc;
- (void) getUChar: (unsigned char *)ucp;
- (char) sendChar: (char)uc;
- (void) getChar: (char *)ucp;
- (short) sendShort: (short)num;
- (void) getShort: (short *)num;
- (int) sendInt: (int)num;
- (void) getInt: (int *)num;
- (long) sendLong: (long)num;
- (void) getLong: (long *)num;
- (float) sendFloat: (float)num;
- (void) getFloat: (float *)num;
- (double) sendDouble: (double)num;
- (void) getDouble: (double *)num;
- sendDouble: (double)dbl andFloat: (float)flt;
- (small_struct) sendSmallStruct: (small_struct)str;
- (void) getSmallStruct: (small_struct *)str;
- (foo) sendStruct: (foo)str;
- (void) getStruct: (foo *)str;
- (id) sendObject: (id)str;
- (void) getObject: (id *)str;
- (char *) sendString: (char *)str;
- (void) getString: (char **)str;
- print: (const char *)str;
- objectAt: (unsigned)i; - objectAt: (unsigned)i;
- (unsigned) count; - (unsigned) count;
- print: (const char *)msg; - echoObject: obj;
- getLong: (out unsigned long*)i;
- (oneway void) shout; - (oneway void) shout;
- callbackNameOn: obj;
- bounce: sender count: (int)c; - bounce: sender count: (int)c;
- (BOOL) doBoolean: (BOOL)b;
- getBoolean: (BOOL*)bp;
- getUCharPtr: (unsigned char *)ucp;
- (oneway void) outputStats:obj; - (oneway void) outputStats:obj;
- (foo*) sendStructPtr: (foo*)f;
- sendStruct: (foo)f;
- sendSmallStruct: (small_struct)small;
- (foo) returnStruct;
- (foo) returnSetStruct: (int)x;
- (small_struct) returnSmallStruct;
- (small_struct) returnSetSmallStruct: (int)x;
- sendArray: (int[3])a; - sendArray: (int[3])a;
- sendStructArray: (struct myarray)ma; - sendStructArray: (struct myarray)ma;
- sendDouble: (double)d andFloat: (float)f;
- (double*) doDoublePointer: (double*)d;
- sendCharPtrPtr: (char**)sp;
- sendBycopy: (bycopy id)o; - sendBycopy: (bycopy id)o;
#ifdef _F_BYREF #ifdef _F_BYREF
- sendByref: (byref id)o; - sendByref: (byref id)o;
#endif #endif
- manyArgs: (int)i1 : (int)i2 : (int)i3 : (int)i4 : (int)i5 : (int)i6 - manyArgs: (int)i1 : (int)i2 : (int)i3 : (int)i4 : (int)i5 : (int)i6
: (int)i7 : (int)i8 : (int)i9 : (int)i10 : (int)i11 : (int)i12; : (int)i7 : (int)i8 : (int)i9 : (int)i10 : (int)i11 : (int)i12;
- (float) returnFloat;
- (double) returnDouble;
- (id) echoObject: (id)obj;
@end @end
#if NeXT_runtime
@protocol AllProxies <ServerProtocol>
- (const char *)name;
- (unsigned) hash;
- self;
@end
#endif
@interface Server : NSObject <ServerProtocol> @interface Server : NSObject <ServerProtocol>
{ {
id the_array; id the_array;

View file

@ -1,6 +1,8 @@
/* Test whether each thread has their own exception handlers. */ /* Test whether each thread has their own exception handlers. */
#ifndef _REENTRANT
#define _REENTRANT #define _REENTRANT
#endif
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>

View file

@ -16,11 +16,15 @@ int main()
NSPoint p; NSPoint p;
NSRect rect; NSRect rect;
NSValue *v1, *v2; NSValue *v1, *v2;
NSNumber *n1, *n2, *n3, *n4, *n5; NSNumber *nc, *ns, *n1, *n2, *n3, *n4, *n5;
NSArray *a1, *a2; NSArray *a1, *a2;
NSAutoreleasePool *arp = [NSAutoreleasePool new]; NSAutoreleasePool *arp = [NSAutoreleasePool new];
// Numbers // Numbers
nc = [NSNumber numberWithChar:-100];
ns = [NSNumber numberWithShort:-100];
printf("try %d, %d", [nc charValue], [ns shortValue]);
printf("nc compare:ns is %d\n", [nc compare:ns]);
n1 = [NSNumber numberWithUnsignedShort:30]; n1 = [NSNumber numberWithUnsignedShort:30];
n2 = [NSNumber numberWithDouble:2.7]; n2 = [NSNumber numberWithDouble:2.7];
n3 = [NSNumber numberWithDouble:30]; n3 = [NSNumber numberWithDouble:30];

View file

@ -37,7 +37,7 @@ DTD_FILES = gsdoc-0_6_5.dtd gsdoc-0_6_6.dtd
# The application to be compiled # The application to be compiled
TOOL_NAME = gdnc gsdoc defaults plmerge \ TOOL_NAME = gdnc gsdoc defaults plmerge \
plparse sfparse pldes plser plparse sfparse pldes plser
OBJC_PROGRAM_NAME = gdomap CTOOL_NAME = gdomap
# The source files to be compiled # The source files to be compiled
gdomap_C_FILES = gdomap.c gdomap_C_FILES = gdomap.c
@ -64,7 +64,7 @@ include Makefile.preamble
-include GNUmakefile.local -include GNUmakefile.local
include $(GNUSTEP_MAKEFILES)/objc.make include $(GNUSTEP_MAKEFILES)/ctool.make
include $(GNUSTEP_MAKEFILES)/tool.make include $(GNUSTEP_MAKEFILES)/tool.make
include Makefile.postamble include Makefile.postamble

View file

@ -19,7 +19,7 @@ before-install::
# Things to do after installing # Things to do after installing
after-install:: after-install::
if [ ! -f $(dtddir) ]; then \ @if [ ! -f $(dtddir) ]; then \
$(MKDIRS) $(dtddir); \ $(MKDIRS) $(dtddir); \
fi; \ fi; \
for file in $(DTD_FILES); do \ for file in $(DTD_FILES); do \
@ -28,16 +28,17 @@ after-install::
if [ "`$(WHOAMI)`" != "root" ]; then \ if [ "`$(WHOAMI)`" != "root" ]; then \
echo ""; \ echo ""; \
echo "************************************************************"; \ echo "************************************************************"; \
echo "WARNING: gdomap MUST be installed owned by root and with"; \ echo "FAILED gdomap installation - please re-run this as root ..."; \
echo "NOTE: gdomap MUST be installed owned by root and with"; \
echo "the 's-bit' set unless you defined 'GDOMAP_PORT_OVERRIDE' in"; \ echo "the 's-bit' set unless you defined 'GDOMAP_PORT_OVERRIDE' in"; \
echo "gdomap.h before compiling gdomap.c and NSPortNameServer.m"; \ echo "gdomap.h before compiling gdomap.c and NSPortNameServer.m"; \
echo "in which case you should install it by hand."; \ echo "in which case you should install it by hand."; \
echo "If you have installed by hand, ignore this message."; \
echo "************************************************************"; \ echo "************************************************************"; \
echo ""; \ echo ""; \
else \ else \
echo "Installing gdomap and gdnc in $(GNUSTEP_INSTALLATION_DIR)/Tools/$(GNUSTEP_TARGET_DIR)"; \ echo "Making gdomap in $(GNUSTEP_INSTALLATION_DIR)/Tools/$(GNUSTEP_TARGET_DIR) setuid to root"; \
$(INSTALL) -m 05755 $(GNUSTEP_OBJ_DIR)/gdomap $(GNUSTEP_INSTALLATION_DIR)/Tools/$(GNUSTEP_TARGET_DIR); \ $(INSTALL) -m 05755 $(GNUSTEP_OBJ_DIR)/gdomap $(GNUSTEP_INSTALLATION_DIR)/Tools/$(GNUSTEP_TARGET_DIR); \
$(INSTALL) -m 0755 $(GNUSTEP_OBJ_DIR)/gdnc $(GNUSTEP_INSTALLATION_DIR)/Tools/$(GNUSTEP_TARGET_DIR); \
fi; \ fi; \
echo "************************************************************"; \ echo "************************************************************"; \
echo "WARNING: if gdomap is started automatically, it will probe"; \ echo "WARNING: if gdomap is started automatically, it will probe"; \

View file

@ -7,12 +7,12 @@ GCC_VERSION=2.8.0
# The version number of this release. # The version number of this release.
MAJOR_VERSION=0 MAJOR_VERSION=0
MINOR_VERSION=6 MINOR_VERSION=6
SUBMINOR_VERSION=5 SUBMINOR_VERSION=6
GNUSTEP_BASE_VERSION=${MAJOR_VERSION}.${MINOR_VERSION}.${SUBMINOR_VERSION} GNUSTEP_BASE_VERSION=${MAJOR_VERSION}.${MINOR_VERSION}.${SUBMINOR_VERSION}
VERSION=${GNUSTEP_BASE_VERSION} VERSION=${GNUSTEP_BASE_VERSION}
GNUSTEP_BASE_FTP_MACHINE=ftp.gnu.org GNUSTEP_BASE_FTP_MACHINE=ftp.gnustep.org
GNUSTEP_BASE_FTP_DIRECTORY=pub/gnu/gstep GNUSTEP_BASE_FTP_DIRECTORY=pub/gnustep/core
GNUSTEP_BASE_SNAP_FTP_MACHINE=alpha.gnu.org GNUSTEP_BASE_SNAP_FTP_MACHINE=alpha.gnu.org
GNUSTEP_BASE_SNAP_FTP_DIRECTORY=gnu/gnustep GNUSTEP_BASE_SNAP_FTP_DIRECTORY=gnu/gnustep

830
configure vendored

File diff suppressed because it is too large Load diff

View file

@ -306,6 +306,7 @@ AC_SUBST(ac_cv_sizeof_float)
AC_CHECK_SIZEOF(double) AC_CHECK_SIZEOF(double)
AC_SUBST(ac_cv_sizeof_double) AC_SUBST(ac_cv_sizeof_double)
AC_SUBST(ac_cv_sizeof_voidp)
if test $ac_cv_sizeof_voidp = $ac_cv_sizeof_int; then if test $ac_cv_sizeof_voidp = $ac_cv_sizeof_int; then
GS_ADDR="unsigned int" GS_ADDR="unsigned int"
else else