mirror of
https://github.com/gnustep/libs-base.git
synced 2025-04-25 17:51:01 +00:00
Rewrite of NSData from Richard Frith-Macdonald <richard@brainstorm.co.uk>
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@2459 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
parent
7b704b0ec4
commit
f88a65db7e
32 changed files with 1576 additions and 2603 deletions
90
ChangeLog
90
ChangeLog
|
@ -1,3 +1,93 @@
|
||||||
|
Sun Sep 28 21:15:00 1997 Richard Frith-Macdonald <richard@brainstorm.co.uk>
|
||||||
|
|
||||||
|
* checks/nsdata.m: Added a whole lot of trivial checks.
|
||||||
|
|
||||||
|
* checks/oldserver.h: Added include file for oldserver.m, oldclient.m
|
||||||
|
|
||||||
|
* src/Coder.m: ([-initForWritingWithMutableData:]) added code to
|
||||||
|
wrap the NSMutableData object inside a MemoryStream since
|
||||||
|
NSMutableData no longer conforms to the MemoryStreaming protocol.
|
||||||
|
([-initForReadingWithData:]) added code to wrap the NSData object
|
||||||
|
inside a MemoryStream.
|
||||||
|
([+unarchiveObjectWithData:]) added code to wrap the NSData object
|
||||||
|
inside a MemoryStream.
|
||||||
|
([-classForPortCoder:]) changed to [-classForPortCoder] to conform
|
||||||
|
to OpenStep spec.
|
||||||
|
|
||||||
|
* src/Makefile.in: Removed NSGData.[hm] and NSHData.[hm]
|
||||||
|
|
||||||
|
* src/MemoryStream.m: Rewritten to use NSData and NSMutableData
|
||||||
|
objects to hold the memory.
|
||||||
|
|
||||||
|
* src/NSAttributedString.m: ([-classForPortCoder:]) changed to
|
||||||
|
[-classForPortCoder] to conform to OpenStep spec.
|
||||||
|
|
||||||
|
* src/NSData.m: Extensively rewritten to have the OPENSTEP class
|
||||||
|
cluster architecture. Should support the full OPENSTEP api and
|
||||||
|
have shared memory support and static buffer support as extensions.
|
||||||
|
|
||||||
|
* src/NSDate.m: ([-classForPortCoder:]) changed to [-classForPortCoder]
|
||||||
|
to conform to OpenStep spec.
|
||||||
|
|
||||||
|
* src/NSDistantObject.m: ([-classForPortCoder:]) changed to
|
||||||
|
[-classForPortCoder] to conform to OpenStep spec.
|
||||||
|
|
||||||
|
* src/NSGArchiver.m: ([-archiverData]) modified to cope with changes
|
||||||
|
to NSData and NSMutableData.
|
||||||
|
|
||||||
|
* src/NSGAttributedString.m: ([-classForPortCoder:]) changed to
|
||||||
|
[-classForPortCoder] to conform to OpenStep spec.
|
||||||
|
|
||||||
|
* src/NSGCString.m: ([-classForPortCoder:]) changed to
|
||||||
|
[-classForPortCoder] to conform to OpenStep spec.
|
||||||
|
|
||||||
|
* src/NSGString.m: ([-classForPortCoder:]) changed to
|
||||||
|
[-classForPortCoder] to conform to OpenStep spec.
|
||||||
|
|
||||||
|
* src/NSPortCoder.m: ([-classForPortCoder:]) changed to
|
||||||
|
[-classForPortCoder] to conform to OpenStep spec.
|
||||||
|
([-isByCopy]) changed to [-isBycopy] to conform to OpenStep.
|
||||||
|
|
||||||
|
* src/NSString.m: ([-classForPortCoder:]) changed to
|
||||||
|
[-classForPortCoder] to conform to OpenStep spec.
|
||||||
|
|
||||||
|
* src/Port.m: ([-classForPortCoder:]) changed to
|
||||||
|
[-classForPortCoder] to conform to OpenStep spec.
|
||||||
|
|
||||||
|
* src/StdioStream.m: ([-initWithFilename:fmode:]) fixed excessive
|
||||||
|
releases of string. ([-initWithFileDescriptor:fmode:]) fixed
|
||||||
|
excessive releases of string. ([-close]) clear file pointer when
|
||||||
|
it is closed to prevent attempted operations on bad pointer.
|
||||||
|
|
||||||
|
* src/TcpPort.m: ([-classForPortCoder:]) changed to
|
||||||
|
[-classForPortCoder] to conform to OpenStep spec. Also multiple
|
||||||
|
changes to deal with the rewrite of MemoryStream.
|
||||||
|
|
||||||
|
* src/UdpPort.m: ([-classForPortCoder:]) changed to
|
||||||
|
[-classForPortCoder] to conform to OpenStep spec.
|
||||||
|
|
||||||
|
* src/UnixFileHandle.m: Numerous changes improving logging and
|
||||||
|
tidying stuff. failed initialisers should now all return nil
|
||||||
|
rather than raising exceptions.
|
||||||
|
|
||||||
|
* src/include/MemoryStream.h: Changed this class to use NSData and
|
||||||
|
NSMutableData to hold its contents. Added methods to initialise
|
||||||
|
with a data object so we can wrap an NSData or NSMutableData inside
|
||||||
|
a MemoryStream to give it Streaming behaviour.
|
||||||
|
|
||||||
|
* src/include/NSData.h: Added some extension methods for creating
|
||||||
|
data objects with static buffers or shared memory buffers.
|
||||||
|
|
||||||
|
* src/include/NSDistantObject.m: ([-classForPortCoder:]) changed to
|
||||||
|
[-classForPortCoder] to conform to OpenStep spec.
|
||||||
|
|
||||||
|
* src/include/NSObject.m: ([-classForPortCoder:]) changed to
|
||||||
|
[-classForPortCoder] to conform to OpenStep spec.
|
||||||
|
|
||||||
|
* src/include/NSPortCoder.m: ([-classForPortCoder:]) changed to
|
||||||
|
[-classForPortCoder], and ([-isByCopy]) changed to [-isBycopy] to
|
||||||
|
conform to OpenStep spec.
|
||||||
|
|
||||||
Fri Sep 26 20:43:12 1997 Adam Fedor <fedor@doc.com>
|
Fri Sep 26 20:43:12 1997 Adam Fedor <fedor@doc.com>
|
||||||
|
|
||||||
* Fix Makefiles so snapshots and releases work again
|
* Fix Makefiles so snapshots and releases work again
|
||||||
|
|
|
@ -21,6 +21,13 @@
|
||||||
Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
Modified by: Richard Frith-Macdonald <richard@brainstorm.co.uk>
|
||||||
|
Date: September 1997
|
||||||
|
|
||||||
|
Modifications to use NSData and NSMutable data objects to hold data.
|
||||||
|
*/
|
||||||
|
|
||||||
#ifndef __MemoryStream_h_GNUSTEP_BASE_INCLUDE
|
#ifndef __MemoryStream_h_GNUSTEP_BASE_INCLUDE
|
||||||
#define __MemoryStream_h_GNUSTEP_BASE_INCLUDE
|
#define __MemoryStream_h_GNUSTEP_BASE_INCLUDE
|
||||||
|
|
||||||
|
@ -45,21 +52,23 @@
|
||||||
|
|
||||||
@interface MemoryStream : Stream <MemoryStreaming>
|
@interface MemoryStream : Stream <MemoryStreaming>
|
||||||
{
|
{
|
||||||
int type;
|
id data;
|
||||||
char *buffer;
|
|
||||||
int size;
|
|
||||||
int eof_position;
|
|
||||||
int prefix;
|
int prefix;
|
||||||
int position;
|
int position;
|
||||||
BOOL free_when_done;
|
int eof_position;
|
||||||
|
BOOL isMutable;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
+ (MemoryStream*)streamWithData: (id)anObject;
|
||||||
|
|
||||||
- initWithCapacity: (unsigned)capacity
|
- initWithCapacity: (unsigned)capacity
|
||||||
prefix: (unsigned)prefix;
|
prefix: (unsigned)prefix;
|
||||||
|
- initWithData: (id)anObject;
|
||||||
|
|
||||||
- initWithSize: (unsigned)s; /* For backwards compatibility, depricated */
|
- initWithSize: (unsigned)s; /* For backwards compatibility, depricated */
|
||||||
|
|
||||||
- (void) setFreeWhenDone: (BOOL)f;
|
- (id) data;
|
||||||
|
- (id) mutableData;
|
||||||
- (unsigned) streamBufferPrefix;
|
- (unsigned) streamBufferPrefix;
|
||||||
- (unsigned) streamBufferLength; /* prefix + eofPosition */
|
- (unsigned) streamBufferLength; /* prefix + eofPosition */
|
||||||
|
|
||||||
|
|
|
@ -258,7 +258,7 @@ extern NSString *ConnectionBecameInvalidNotification;
|
||||||
@end
|
@end
|
||||||
|
|
||||||
@interface Object (NSPortCoder)
|
@interface Object (NSPortCoder)
|
||||||
- (Class) classForPortCoder: (NSPortCoder*)aCoder;
|
- (Class) classForPortCoder;
|
||||||
/*
|
/*
|
||||||
* Must return the class that will be created on the remote side
|
* 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
|
* of the connection. If the class to be created is not the same
|
||||||
|
|
|
@ -34,13 +34,13 @@
|
||||||
|
|
||||||
+ (id)data;
|
+ (id)data;
|
||||||
+ (id)dataWithBytes: (const void*)bytes
|
+ (id)dataWithBytes: (const void*)bytes
|
||||||
length: (unsigned int)length;
|
length: (unsigned int)length;
|
||||||
+ (id)dataWithBytesNoCopy: (void*)bytes
|
+ (id)dataWithBytesNoCopy: (void*)bytes
|
||||||
length: (unsigned int)length;
|
length: (unsigned int)length;
|
||||||
+ (id)dataWithContentsOfFile: (NSString*)path;
|
+ (id)dataWithContentsOfFile: (NSString*)path;
|
||||||
+ (id)dataWithContentsOfMappedFile: (NSString*)path;
|
+ (id)dataWithContentsOfMappedFile: (NSString*)path;
|
||||||
- (id)initWithBytes: (const void*)bytes
|
- (id)initWithBytes: (const void*)bytes
|
||||||
length: (unsigned int)length;
|
length: (unsigned int)length;
|
||||||
- (id)initWithBytesNoCopy: (void*)bytes
|
- (id)initWithBytesNoCopy: (void*)bytes
|
||||||
length: (unsigned int)length;
|
length: (unsigned int)length;
|
||||||
- (id)initWithContentsOfFile: (NSString*)path;
|
- (id)initWithContentsOfFile: (NSString*)path;
|
||||||
|
@ -53,9 +53,9 @@
|
||||||
- (NSString*)description;
|
- (NSString*)description;
|
||||||
- (void)getBytes: (void*)buffer;
|
- (void)getBytes: (void*)buffer;
|
||||||
- (void)getBytes: (void*)buffer
|
- (void)getBytes: (void*)buffer
|
||||||
length: (unsigned int)length;
|
length: (unsigned int)length;
|
||||||
- (void)getBytes: (void*)buffer
|
- (void)getBytes: (void*)buffer
|
||||||
range: (NSRange)aRange;
|
range: (NSRange)aRange;
|
||||||
- (NSData*)subdataWithRange: (NSRange)aRange;
|
- (NSData*)subdataWithRange: (NSRange)aRange;
|
||||||
|
|
||||||
// Querying a Data Object
|
// Querying a Data Object
|
||||||
|
@ -72,23 +72,29 @@
|
||||||
|
|
||||||
- (unsigned int)deserializeAlignedBytesLengthAtCursor: (unsigned int*)cursor;
|
- (unsigned int)deserializeAlignedBytesLengthAtCursor: (unsigned int*)cursor;
|
||||||
- (void)deserializeBytes: (void*)buffer
|
- (void)deserializeBytes: (void*)buffer
|
||||||
length: (unsigned int)bytes
|
length: (unsigned int)bytes
|
||||||
atCursor: (unsigned int*)cursor;
|
atCursor: (unsigned int*)cursor;
|
||||||
- (void)deserializeDataAt: (void*)data
|
- (void)deserializeDataAt: (void*)data
|
||||||
ofObjCType: (const char*)type
|
ofObjCType: (const char*)type
|
||||||
atCursor: (unsigned int*)cursor
|
atCursor: (unsigned int*)cursor
|
||||||
context: (id <NSObjCTypeSerializationCallBack>)callback;
|
context: (id <NSObjCTypeSerializationCallBack>)callback;
|
||||||
- (int)deserializeIntAtCursor: (unsigned int*)cursor;
|
- (int)deserializeIntAtCursor: (unsigned int*)cursor;
|
||||||
- (int)deserializeIntAtIndex: (unsigned int)location;
|
- (int)deserializeIntAtIndex: (unsigned int)location;
|
||||||
- (void)deserializeInts: (int*)intBuffer
|
- (void)deserializeInts: (int*)intBuffer
|
||||||
count: (unsigned int)numInts
|
count: (unsigned int)numInts
|
||||||
atCursor: (unsigned int*)cursor;
|
atCursor: (unsigned int*)cursor;
|
||||||
- (void)deserializeInts: (int*)intBuffer
|
- (void)deserializeInts: (int*)intBuffer
|
||||||
count: (unsigned int)numInts
|
count: (unsigned int)numInts
|
||||||
atIndex: (unsigned int)index;
|
atIndex: (unsigned int)index;
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
||||||
|
@interface NSData (GNUstepExtensions)
|
||||||
|
+ (id) dataWithShmID: (int)anID length: (unsigned) length;
|
||||||
|
+ (id) dataWithSharedBytes: (const void*)bytes length: (unsigned) length;
|
||||||
|
+ (id) dataWithStaticBytes: (const void*)bytes length: (unsigned) length;
|
||||||
|
@end
|
||||||
|
|
||||||
|
|
||||||
@interface NSMutableData : NSData
|
@interface NSMutableData : NSData
|
||||||
|
|
||||||
|
@ -132,6 +138,12 @@
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
||||||
|
@interface NSMutableData (GNUstepExtensions)
|
||||||
|
- (unsigned int) capacity;
|
||||||
|
- (id) setCapacity: (unsigned int)newCapacity;
|
||||||
|
- (int) shmID;
|
||||||
|
@end
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Local Variables:
|
Local Variables:
|
||||||
mode: ObjC
|
mode: ObjC
|
||||||
|
|
|
@ -55,7 +55,7 @@
|
||||||
+ newForRemoteTarget: (unsigned)target connection: (NSConnection*)conn;
|
+ newForRemoteTarget: (unsigned)target connection: (NSConnection*)conn;
|
||||||
|
|
||||||
- awakeAfterUsingCoder: aDecoder;
|
- awakeAfterUsingCoder: aDecoder;
|
||||||
- classForPortCoder: aRmc;
|
- classForPortCoder;
|
||||||
+ newWithCoder: aRmc;
|
+ newWithCoder: aRmc;
|
||||||
- (const char *) selectorTypeForProxy: (SEL)selector;
|
- (const char *) selectorTypeForProxy: (SEL)selector;
|
||||||
- forward: (SEL)aSel :(arglist_t)frame;
|
- forward: (SEL)aSel :(arglist_t)frame;
|
||||||
|
|
|
@ -1,67 +0,0 @@
|
||||||
/* Interface to concrete implementation of NSData based on MemoryStream class
|
|
||||||
Copyright (C) 1995 Free Software Foundation, Inc.
|
|
||||||
|
|
||||||
Written by: Andrew Kachites McCallum <mccallum@gnu.ai.mit.edu>
|
|
||||||
Date: April 1995
|
|
||||||
|
|
||||||
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., 675 Mass Ave, Cambridge, MA 02139, USA.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef __NSGData_h_GNUSTEP_BASE_INCLUDE
|
|
||||||
#define __NSGData_h_GNUSTEP_BASE_INCLUDE
|
|
||||||
|
|
||||||
#include <gnustep/base/preface.h>
|
|
||||||
#include <Foundation/NSData.h>
|
|
||||||
#include <gnustep/base/MemoryStream.h>
|
|
||||||
|
|
||||||
@interface NSGData : NSData
|
|
||||||
{
|
|
||||||
/* For now, these must match the instance variables in
|
|
||||||
gnustep/base/MemoryStream.h.
|
|
||||||
This will change. */
|
|
||||||
int type;
|
|
||||||
char *buffer;
|
|
||||||
int size;
|
|
||||||
int eofPosition;
|
|
||||||
int prefix;
|
|
||||||
int position;
|
|
||||||
}
|
|
||||||
|
|
||||||
@end
|
|
||||||
|
|
||||||
@interface NSGData (GNU) <MemoryStreaming>
|
|
||||||
@end
|
|
||||||
|
|
||||||
@interface NSGMutableData : NSMutableData
|
|
||||||
{
|
|
||||||
/* For now, these must match the instance variables in
|
|
||||||
gnustep/base/MemoryStream.h.
|
|
||||||
This will change. */
|
|
||||||
int type;
|
|
||||||
char *buffer;
|
|
||||||
int size;
|
|
||||||
int eofPosition;
|
|
||||||
int prefix;
|
|
||||||
int position;
|
|
||||||
}
|
|
||||||
|
|
||||||
@end
|
|
||||||
|
|
||||||
@interface NSGMutableData (GNU) <MemoryStreaming>
|
|
||||||
@end
|
|
||||||
|
|
||||||
#endif /* __NSGData_h_GNUSTEP_BASE_INCLUDE */
|
|
|
@ -1,227 +0,0 @@
|
||||||
/* Interface for GNU Objective C NSData classes
|
|
||||||
Copyright (C) 1997 Free Software Foundation, Inc.
|
|
||||||
|
|
||||||
Written by: Richard Frith-Macdonald <richard@brainstorm.co.uk>
|
|
||||||
Date: July 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., 675 Mass Ave, Cambridge, MA 02139, USA.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef __NSHData_h
|
|
||||||
#define __NSHData_h
|
|
||||||
|
|
||||||
#include <gnustep/base/preface.h>
|
|
||||||
#include <gnustep/base/Streaming.h>
|
|
||||||
#include <gnustep/base/MemoryStream.h>
|
|
||||||
#include <Foundation/NSObject.h>
|
|
||||||
#include <Foundation/NSRange.h>
|
|
||||||
#include <Foundation/NSData.h>
|
|
||||||
#include <Foundation/NSSerialization.h>
|
|
||||||
|
|
||||||
typedef enum {
|
|
||||||
MALLOC_DATA = 0, // This is data allocated by malloc.
|
|
||||||
STATIC_DATA, // This is data from somewhere else.
|
|
||||||
SHARED_DATA, // This is data allocated by shmget.
|
|
||||||
MAPPED_DATA // This is a memory mapped file.
|
|
||||||
} NSDataType;
|
|
||||||
|
|
||||||
@interface NSHData : NSData <MemoryStreaming,SeekableStreaming>
|
|
||||||
{
|
|
||||||
NSDataType type;
|
|
||||||
char* buffer;
|
|
||||||
int shm_id;
|
|
||||||
unsigned int size;
|
|
||||||
unsigned int eof_position;
|
|
||||||
unsigned int position;
|
|
||||||
}
|
|
||||||
|
|
||||||
+ (id) data;
|
|
||||||
+ (id) dataWithBytes: (const void*)bytes
|
|
||||||
length: (unsigned int)length;
|
|
||||||
+ (id) dataWithBytesNoCopy: (void*)bytes
|
|
||||||
length: (unsigned int)length;
|
|
||||||
+ (id) dataWithContentsOfFile: (NSString*)path;
|
|
||||||
+ (id) dataWithContentsOfMappedFile: (NSString*)path;
|
|
||||||
+ (id) dataWithData: (NSData*)other;
|
|
||||||
|
|
||||||
- (const void*)bytes;
|
|
||||||
- (NSString*) description;
|
|
||||||
- (void) getBytes: (void*)buffer;
|
|
||||||
- (void) getBytes: (void*)buffer
|
|
||||||
length: (unsigned int)length;
|
|
||||||
- (void) getBytes: (void*)buffer
|
|
||||||
range: (NSRange)aRange;
|
|
||||||
|
|
||||||
- (id) initWithBytes: (const void*)bytes
|
|
||||||
length: (unsigned int)length;
|
|
||||||
- (id) initWithBytesNoCopy: (void*)bytes
|
|
||||||
length: (unsigned int)length;
|
|
||||||
- (id) initWithContentsOfFile: (NSString*)path;
|
|
||||||
- (id) initWithContentsOfMappedFile: (NSString*)path;
|
|
||||||
- (id) initWithData: (NSData*)data;
|
|
||||||
|
|
||||||
- (BOOL) isEqualToData: (NSData*)other;
|
|
||||||
- (unsigned int) length;
|
|
||||||
- (NSData*)subdataWithRange: (NSRange)aRange;
|
|
||||||
- (BOOL) writeToFile: (NSString*)path
|
|
||||||
atomically: (BOOL)useAuxiliaryFile;
|
|
||||||
|
|
||||||
|
|
||||||
- (unsigned int) deserializeAlignedBytesLengthAtCursor: (unsigned int*)cursor;
|
|
||||||
- (void) deserializeBytes: (void*)buffer
|
|
||||||
length: (unsigned int)bytes
|
|
||||||
atCursor: (unsigned int*)cursor;
|
|
||||||
- (void) deserializeDataAt: (void*)data
|
|
||||||
ofObjCType: (const char*)type
|
|
||||||
atCursor: (unsigned int*)cursor
|
|
||||||
context: (id <NSObjCTypeSerializationCallBack>)callback;
|
|
||||||
- (int) deserializeIntAtCursor: (unsigned int*)cursor;
|
|
||||||
- (int) deserializeIntAtIndex: (unsigned int)location;
|
|
||||||
- (void) deserializeInts: (int*)intBuffer
|
|
||||||
count: (unsigned int)numInts
|
|
||||||
atCursor: (unsigned int*)cursor;
|
|
||||||
- (void) deserializeInts: (int*)intBuffer
|
|
||||||
count: (unsigned int)numInts
|
|
||||||
atIndex: (unsigned int)index;
|
|
||||||
|
|
||||||
|
|
||||||
/* GNUstep extensions to NSData primarily for the Streaming prototcol.
|
|
||||||
The write operations have no effect on an NSData but work as expected
|
|
||||||
for NSMutableData objects.
|
|
||||||
*/
|
|
||||||
+ (void) setVMChunk:(int)size;
|
|
||||||
+ (void) setVMThreshold:(int)size;
|
|
||||||
+ (int) vmChunk;
|
|
||||||
+ (int) vmThreshold;
|
|
||||||
- (void) close;
|
|
||||||
- (void) flushStream;
|
|
||||||
|
|
||||||
/* How the internal designated initialiser works -
|
|
||||||
if 't' is MALLOC_DATA
|
|
||||||
if 'f' is YES
|
|
||||||
We set 'buffer' to 'b'
|
|
||||||
else
|
|
||||||
We set 'buffer' to point to memory allocated of the size
|
|
||||||
specified in 's', and copy 'l' bytes from 'b' or clear
|
|
||||||
'l' bytes if 'b' is nul. We set 'f' to YES.
|
|
||||||
|
|
||||||
if 't' is STATIC_DATA
|
|
||||||
If 'b' is zero
|
|
||||||
We set 'buffer' to "" and set 'size' to zero.
|
|
||||||
else
|
|
||||||
We set 'buffer' to 'b'
|
|
||||||
|
|
||||||
if 't' is SHARED_DATA
|
|
||||||
If 'm' is non-zero
|
|
||||||
We attach to the specified chunk of shared memory and set
|
|
||||||
'buffer' to point to it. We set 'size' to the size of the
|
|
||||||
shared memory. We either clear the first 'l' bytes or we
|
|
||||||
copy them from 'b' if 'b' is not nul.
|
|
||||||
else
|
|
||||||
We create a chunk of shared memory of at least 'size' bytes,
|
|
||||||
set 'buffer' to point to it, and set 'size' to the size of
|
|
||||||
the shared memory.
|
|
||||||
We either clear the first 'l' bytes or we copy them from 'b'
|
|
||||||
if 'b' is not nul.
|
|
||||||
|
|
||||||
if 't' is MAPPED_DATA
|
|
||||||
We map the file 'n' into memory and set 'buffer' to point to it.
|
|
||||||
|
|
||||||
*/
|
|
||||||
- initOnBuffer: (void*)b /* data area or nul pointer */
|
|
||||||
size: (unsigned)s /* size of the data area */
|
|
||||||
type: (NSDataType)t /* type of storage to use */
|
|
||||||
sharedMem: (int)m /* ID of shared memory segment */
|
|
||||||
fileName: (NSString*)n /* name of mmap file. */
|
|
||||||
eofPosition: (unsigned)l /* length of data for reading */
|
|
||||||
position: (unsigned)i /* current pos for read/write */
|
|
||||||
noCopy: (BOOL)f;
|
|
||||||
|
|
||||||
- initWithCapacity: (unsigned int)capacity;
|
|
||||||
- (BOOL) isAtEof;
|
|
||||||
- (BOOL) isClosed;
|
|
||||||
- (BOOL) isWritable;
|
|
||||||
|
|
||||||
- (int) readByte: (unsigned char*)b;
|
|
||||||
- (int) readBytes: (void*)b length: (int)l;
|
|
||||||
- (int) readFormat: (NSString*)format, ...;
|
|
||||||
- (int) readFormat: (NSString*)format arguments: (va_list)arg;
|
|
||||||
- (NSString*) readLine;
|
|
||||||
|
|
||||||
- (void) rewindStream;
|
|
||||||
|
|
||||||
- (void) setFreeWhenDone: (BOOL)f;
|
|
||||||
- (void) setStreamBufferCapacity: (unsigned)s;
|
|
||||||
- (void) setStreamEofPosition: (unsigned)i;
|
|
||||||
- (void) setStreamPosition: (unsigned)i;
|
|
||||||
- (void) setStreamPosition: (unsigned)i seekMode: (seek_mode_t)mode;
|
|
||||||
- (void) setVMThreshold:(int)size;
|
|
||||||
|
|
||||||
- (char*) streamBuffer; /* Returns null for an NSData object. */
|
|
||||||
- (unsigned) streamBufferLength;
|
|
||||||
- (unsigned) streamEofPosition;
|
|
||||||
- (unsigned) streamPosition;
|
|
||||||
|
|
||||||
/* The following write operations have no effect on an NSData object. */
|
|
||||||
- (int) writeByte: (unsigned char)b;
|
|
||||||
- (int) writeBytes: (const void*)b length: (int)l;
|
|
||||||
- (int) writeFormat: (NSString*)format, ...;
|
|
||||||
- (int) writeFormat: (NSString*)format arguments: (va_list)arg;
|
|
||||||
- (void) writeLine: (NSString*)l;
|
|
||||||
|
|
||||||
- (int) vmThreshold;
|
|
||||||
@end
|
|
||||||
|
|
||||||
@interface NSHMutableData : NSHData
|
|
||||||
{
|
|
||||||
int vm_threshold;
|
|
||||||
}
|
|
||||||
|
|
||||||
+ (id) dataWithCapacity: (unsigned int)numBytes;
|
|
||||||
+ (id) dataWithLength: (unsigned int)length;
|
|
||||||
|
|
||||||
- (void) appendBytes:(const void*)bytes
|
|
||||||
length:(unsigned int)length;
|
|
||||||
- (void) appendData:(NSData*)other;
|
|
||||||
- (void) increaseLengthBy:(unsigned int)length;
|
|
||||||
- (id) initWithLength: (unsigned int)length;
|
|
||||||
- (void*) mutableBytes;
|
|
||||||
- (void) replaceBytesInRange: (NSRange)aRange
|
|
||||||
withBytes: (const void*)bytes;
|
|
||||||
- (void) resetBytesInRange: (NSRange)aRange;
|
|
||||||
- (void) setData:(NSData*)other;
|
|
||||||
- (void) setLength:(unsigned int)length;
|
|
||||||
- (void) setVMThreshold:(int)size;
|
|
||||||
|
|
||||||
- (void) serializeAlignedBytesLength: (unsigned int)length;
|
|
||||||
- (void) serializeDataAt: (const void*)data
|
|
||||||
ofObjCType: (const char*)type
|
|
||||||
context: (id <NSObjCTypeSerializationCallBack>)callback;
|
|
||||||
- (void) serializeInt: (int)value;
|
|
||||||
- (void) serializeInt: (int)value
|
|
||||||
atIndex: (unsigned int)location;
|
|
||||||
- (void) serializeInts: (int*)intBuffer
|
|
||||||
count: (unsigned int)numInts;
|
|
||||||
- (void) serializeInts: (int*)intBuffer
|
|
||||||
count: (unsigned int)numInts
|
|
||||||
atIndex: (unsigned int)location;
|
|
||||||
|
|
||||||
- (int) vmThreshold;
|
|
||||||
- (void) increaseCapacityBy:(unsigned int)length;
|
|
||||||
@end
|
|
||||||
|
|
||||||
#endif /* __NSHData_h */
|
|
|
@ -114,7 +114,7 @@
|
||||||
@end
|
@end
|
||||||
|
|
||||||
@interface NSObject (NSPortCoder)
|
@interface NSObject (NSPortCoder)
|
||||||
- (Class) classForPortCoder: (NSPortCoder*)anEncoder;
|
- (Class) classForPortCoder;
|
||||||
- (id) replacementObjectForPortCoder: (NSPortCoder*)anEncoder;
|
- (id) replacementObjectForPortCoder: (NSPortCoder*)anEncoder;
|
||||||
@end
|
@end
|
||||||
|
|
||||||
|
|
|
@ -39,7 +39,7 @@
|
||||||
- (NSConnection*) connection;
|
- (NSConnection*) connection;
|
||||||
- (NSPort*) decodePortObject;
|
- (NSPort*) decodePortObject;
|
||||||
- (void) encodePortObject: (NSPort*)aPort;
|
- (void) encodePortObject: (NSPort*)aPort;
|
||||||
- (BOOL) isByCopy;
|
- (BOOL) isBycopy;
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
||||||
|
|
|
@ -252,20 +252,16 @@ static BOOL debug_coder = NO;
|
||||||
|
|
||||||
/* Initializing an archiver */
|
/* Initializing an archiver */
|
||||||
|
|
||||||
@interface NSData (Streaming) <Streaming>
|
|
||||||
@end
|
|
||||||
|
|
||||||
- (id) initForWritingWithMutableData: (NSMutableData*)mdata
|
- (id) initForWritingWithMutableData: (NSMutableData*)mdata
|
||||||
{
|
{
|
||||||
/* This relies on the fact that GNU extentions to NSMutableData
|
[(id)self initForWritingToStream: [MemoryStream streamWithData: mdata]];
|
||||||
cause it to conform to <Streaming>. */
|
|
||||||
[(id)self initForWritingToStream: mdata];
|
|
||||||
return self;
|
return self;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (id) initForReadingWithData: (NSData*)data
|
- (id) initForReadingWithData: (NSData*)data
|
||||||
{
|
{
|
||||||
id ret = [[self class] newReadingFromStream: data];
|
id ret = [[self class] newReadingFromStream:
|
||||||
|
[MemoryStream streamWithData:data]];
|
||||||
if ([self retainCount] == 0)
|
if ([self retainCount] == 0)
|
||||||
[ret autorelease];
|
[ret autorelease];
|
||||||
else
|
else
|
||||||
|
@ -295,7 +291,8 @@ static BOOL debug_coder = NO;
|
||||||
|
|
||||||
+ unarchiveObjectWithData: (NSData*) data
|
+ unarchiveObjectWithData: (NSData*) data
|
||||||
{
|
{
|
||||||
return [self decodeObjectWithName: NULL fromStream: data];
|
return [self decodeObjectWithName: NULL
|
||||||
|
fromStream: [MemoryStream streamWithData:data]];
|
||||||
}
|
}
|
||||||
|
|
||||||
+ unarchiveObjectWithFile: (NSString*) path
|
+ unarchiveObjectWithFile: (NSString*) path
|
||||||
|
|
|
@ -118,7 +118,7 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Next two methods for OPENSTEP */
|
/* Next two methods for OPENSTEP */
|
||||||
- (Class) classForPortCoder: coder
|
- (Class) classForPortCoder
|
||||||
{
|
{
|
||||||
return [self class];
|
return [self class];
|
||||||
}
|
}
|
||||||
|
@ -753,9 +753,9 @@ my_method_get_next_argument (arglist_t argframe,
|
||||||
|
|
||||||
/* Encode ourself as a proxies across Connection's; we can't encode
|
/* Encode ourself as a proxies across Connection's; we can't encode
|
||||||
a function across the wire. */
|
a function across the wire. */
|
||||||
- classForPortCoder: coder
|
- classForPortCoder
|
||||||
{
|
{
|
||||||
return [[coder connection] proxyClass];
|
return [NSDistantObject class];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void) encodeWithCoder: (id <Encoding>)coder
|
- (void) encodeWithCoder: (id <Encoding>)coder
|
||||||
|
@ -786,9 +786,9 @@ my_method_get_next_argument (arglist_t argframe,
|
||||||
|
|
||||||
/* Encode ourself as a proxies across Connection's; we can't encode
|
/* Encode ourself as a proxies across Connection's; we can't encode
|
||||||
a function across the wire. */
|
a function across the wire. */
|
||||||
- classForPortCoder: coder
|
- classForPortCoder
|
||||||
{
|
{
|
||||||
return [[coder connection] proxyClass];
|
return [NSDistantObject class];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void) encodeWithCoder: (id <Encoding>)coder
|
- (void) encodeWithCoder: (id <Encoding>)coder
|
||||||
|
|
|
@ -315,8 +315,6 @@ NSGArray.m \
|
||||||
NSGAttributedString.m \
|
NSGAttributedString.m \
|
||||||
NSGCountedSet.m \
|
NSGCountedSet.m \
|
||||||
NSGCString.m \
|
NSGCString.m \
|
||||||
NSGData.m \
|
|
||||||
NSHData.m \
|
|
||||||
NSGDictionary.m \
|
NSGDictionary.m \
|
||||||
NSGSet.m \
|
NSGSet.m \
|
||||||
NSGSequence.m \
|
NSGSequence.m \
|
||||||
|
@ -406,8 +404,6 @@ Foundation/NSGArchiver.h \
|
||||||
Foundation/NSGArray.h \
|
Foundation/NSGArray.h \
|
||||||
Foundation/NSGAttributedString.h \
|
Foundation/NSGAttributedString.h \
|
||||||
Foundation/NSGCString.h \
|
Foundation/NSGCString.h \
|
||||||
Foundation/NSGData.h \
|
|
||||||
Foundation/NSHData.h \
|
|
||||||
Foundation/NSGDictionary.h \
|
Foundation/NSGDictionary.h \
|
||||||
Foundation/NSGSet.h \
|
Foundation/NSGSet.h \
|
||||||
Foundation/NSGSequence.h \
|
Foundation/NSGSequence.h \
|
||||||
|
|
|
@ -24,6 +24,7 @@
|
||||||
#include <gnustep/base/preface.h>
|
#include <gnustep/base/preface.h>
|
||||||
#include <gnustep/base/MemoryStream.h>
|
#include <gnustep/base/MemoryStream.h>
|
||||||
#include <gnustep/base/Coder.h>
|
#include <gnustep/base/Coder.h>
|
||||||
|
#include <Foundation/NSData.h>
|
||||||
#include <Foundation/NSException.h>
|
#include <Foundation/NSException.h>
|
||||||
#include <stdarg.h>
|
#include <stdarg.h>
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
|
@ -44,15 +45,6 @@
|
||||||
/* memory.h and strings.h conflict on some systems. */
|
/* memory.h and strings.h conflict on some systems. */
|
||||||
#endif /* not STDC_HEADERS and not HAVE_STRING_H */
|
#endif /* not STDC_HEADERS and not HAVE_STRING_H */
|
||||||
|
|
||||||
/* This could be done with a set of classes instead. */
|
|
||||||
enum {MALLOC_MEMORY_STREAM = 0, OBSTACK_MEMORY_STREAM, VM_MEMORY_STREAM};
|
|
||||||
|
|
||||||
enum {
|
|
||||||
STREAM_READONLY = 0,
|
|
||||||
STREAM_READWRITE,
|
|
||||||
STREAM_WRITEONLY
|
|
||||||
};
|
|
||||||
|
|
||||||
#define DEFAULT_MEMORY_STREAM_SIZE 64
|
#define DEFAULT_MEMORY_STREAM_SIZE 64
|
||||||
|
|
||||||
extern int
|
extern int
|
||||||
|
@ -67,6 +59,16 @@ static BOOL debug_memory_stream = NO;
|
||||||
|
|
||||||
@implementation MemoryStream
|
@implementation MemoryStream
|
||||||
|
|
||||||
|
+ (MemoryStream*)streamWithData: (id)anObject
|
||||||
|
{
|
||||||
|
return [[[MemoryStream alloc] initWithData:anObject] autorelease];
|
||||||
|
}
|
||||||
|
|
||||||
|
- (id) data
|
||||||
|
{
|
||||||
|
return data;
|
||||||
|
}
|
||||||
|
|
||||||
/* xxx This interface will change */
|
/* xxx This interface will change */
|
||||||
- _initOnMallocBuffer: (char*)b
|
- _initOnMallocBuffer: (char*)b
|
||||||
freeWhenDone: (BOOL)f
|
freeWhenDone: (BOOL)f
|
||||||
|
@ -75,14 +77,37 @@ static BOOL debug_memory_stream = NO;
|
||||||
prefix: (unsigned)p /* never read/write before this position */
|
prefix: (unsigned)p /* never read/write before this position */
|
||||||
position: (unsigned)i /* current position for reading/writing */
|
position: (unsigned)i /* current position for reading/writing */
|
||||||
{
|
{
|
||||||
[super init];
|
self = [super init];
|
||||||
buffer = b;
|
if (self)
|
||||||
size = s;
|
{
|
||||||
prefix = p;
|
if (b)
|
||||||
position = i;
|
if (f)
|
||||||
eof_position = l;
|
data = [NSMutableData dataWithBytesNoCopy: b length: s];
|
||||||
free_when_done = f;
|
else
|
||||||
type = MALLOC_MEMORY_STREAM;
|
data = [NSMutableData dataWithBytes: b length: s];
|
||||||
|
else
|
||||||
|
{
|
||||||
|
data = [NSMutableData dataWithCapacity: s];
|
||||||
|
if (data)
|
||||||
|
[data setLength: s];
|
||||||
|
}
|
||||||
|
|
||||||
|
if (data)
|
||||||
|
{
|
||||||
|
[data retain];
|
||||||
|
prefix = p;
|
||||||
|
position = i;
|
||||||
|
eof_position = l;
|
||||||
|
isMutable = YES;
|
||||||
|
if ([data length] < prefix + MAX(position, eof_position))
|
||||||
|
[data setLength: prefix + MAX(position, eof_position)];
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
[self release];
|
||||||
|
self = nil;
|
||||||
|
}
|
||||||
|
}
|
||||||
return self;
|
return self;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -105,9 +130,7 @@ static BOOL debug_memory_stream = NO;
|
||||||
prefix: (unsigned)p
|
prefix: (unsigned)p
|
||||||
position: (unsigned)i
|
position: (unsigned)i
|
||||||
{
|
{
|
||||||
char *b;
|
return [self _initOnMallocBuffer: 0
|
||||||
OBJC_MALLOC(b, char, s);
|
|
||||||
return [self _initOnMallocBuffer:b
|
|
||||||
freeWhenDone: YES
|
freeWhenDone: YES
|
||||||
size: s
|
size: s
|
||||||
eofPosition: i
|
eofPosition: i
|
||||||
|
@ -128,6 +151,29 @@ static BOOL debug_memory_stream = NO;
|
||||||
return [self initWithSize:capacity prefix:0 position:0];
|
return [self initWithSize:capacity prefix:0 position:0];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
- initWithData: (id)anObject
|
||||||
|
{
|
||||||
|
self = [super init];
|
||||||
|
if (self)
|
||||||
|
{
|
||||||
|
if (anObject && [anObject isKindOfClass:[NSData class]])
|
||||||
|
{
|
||||||
|
data = [anObject retain];
|
||||||
|
if ([data isKindOfClass:[NSMutableData class]])
|
||||||
|
isMutable = YES;
|
||||||
|
eof_position = [data length];
|
||||||
|
position = 0;
|
||||||
|
prefix = 0;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
[self dealloc];
|
||||||
|
self = nil;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return self;
|
||||||
|
}
|
||||||
|
|
||||||
- initWithSize: (unsigned)s
|
- initWithSize: (unsigned)s
|
||||||
{
|
{
|
||||||
return [self initWithCapacity:s];
|
return [self initWithCapacity:s];
|
||||||
|
@ -138,14 +184,9 @@ static BOOL debug_memory_stream = NO;
|
||||||
return [self initWithCapacity: DEFAULT_MEMORY_STREAM_SIZE];
|
return [self initWithCapacity: DEFAULT_MEMORY_STREAM_SIZE];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void) setFreeWhenDone: (BOOL)f
|
|
||||||
{
|
|
||||||
free_when_done = f;
|
|
||||||
}
|
|
||||||
|
|
||||||
- (BOOL) isWritable
|
- (BOOL) isWritable
|
||||||
{
|
{
|
||||||
return YES;
|
return isMutable;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void) encodeWithCoder: anEncoder
|
- (void) encodeWithCoder: anEncoder
|
||||||
|
@ -159,38 +200,54 @@ static BOOL debug_memory_stream = NO;
|
||||||
return self;
|
return self;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
- (id) mutableData
|
||||||
|
{
|
||||||
|
if (isMutable)
|
||||||
|
return data;
|
||||||
|
return nil;
|
||||||
|
}
|
||||||
|
|
||||||
- (int) writeBytes: (const void*)b length: (int)l
|
- (int) writeBytes: (const void*)b length: (int)l
|
||||||
{
|
{
|
||||||
if (prefix+position+l > size)
|
unsigned size;
|
||||||
|
|
||||||
|
if (isMutable)
|
||||||
{
|
{
|
||||||
size = MAX(prefix+position+l, size*2);
|
size = [data capacity];
|
||||||
buffer = objc_realloc (buffer, size);
|
if (prefix+position+l > size)
|
||||||
|
{
|
||||||
|
size = MAX(prefix+position+l, size*2);
|
||||||
|
[data setCapacity: size];
|
||||||
|
}
|
||||||
|
if (position+prefix+l > [data length])
|
||||||
|
[data setLength: position+prefix+l];
|
||||||
|
memcpy([data mutableBytes]+prefix+position, b, l);
|
||||||
|
position += l;
|
||||||
|
if (position > eof_position)
|
||||||
|
eof_position = position;
|
||||||
|
return l;
|
||||||
}
|
}
|
||||||
memcpy(buffer+prefix+position, b, l);
|
return 0;
|
||||||
position += l;
|
|
||||||
if (position > eof_position)
|
|
||||||
eof_position = position;
|
|
||||||
return l;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
- (int) readBytes: (void*)b length: (int)l
|
- (int) readBytes: (void*)b length: (int)l
|
||||||
{
|
{
|
||||||
if (position+l > eof_position)
|
if (position+l > eof_position)
|
||||||
l = eof_position-position;
|
l = eof_position-position;
|
||||||
memcpy(b, buffer+prefix+position, l);
|
memcpy(b, [data bytes]+prefix+position, l);
|
||||||
position += l;
|
position += l;
|
||||||
return l;
|
return l;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (NSString*) readLine
|
- (NSString*) readLine
|
||||||
{
|
{
|
||||||
char *nl = memchr(buffer+prefix+position, '\n', eof_position-position);
|
char *nl = memchr([data bytes]+prefix+position, '\n', eof_position-position);
|
||||||
char *ret = NULL;
|
char *ret = NULL;
|
||||||
if (nl)
|
if (nl)
|
||||||
{
|
{
|
||||||
int len = nl-buffer-prefix-position;
|
int len = nl-((char*)[data bytes])-prefix-position;
|
||||||
ret = objc_malloc (len+1);
|
ret = objc_malloc (len+1);
|
||||||
strncpy(ret, buffer+prefix+position, len);
|
strncpy(ret, ((char*)[data bytes])+prefix+position, len);
|
||||||
ret[len] = '\0';
|
ret[len] = '\0';
|
||||||
position += len+1;
|
position += len+1;
|
||||||
}
|
}
|
||||||
|
@ -206,54 +263,65 @@ static BOOL debug_memory_stream = NO;
|
||||||
|
|
||||||
int outchar_func(void *s, int c)
|
int outchar_func(void *s, int c)
|
||||||
{
|
{
|
||||||
if (MS->prefix + MS->position >= MS->size)
|
if (MS->isMutable)
|
||||||
return EOF;
|
{
|
||||||
MS->buffer[MS->prefix + MS->position++] = (char)c;
|
if (MS->prefix + MS->position >= [MS->data capacity])
|
||||||
return 1;
|
return EOF;
|
||||||
|
((char*)[MS->data mutableBytes])[MS->prefix + MS->position++] = (char)c;
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
return EOF;
|
||||||
}
|
}
|
||||||
|
|
||||||
int inchar_func(void *s)
|
int inchar_func(void *s)
|
||||||
{
|
{
|
||||||
if (MS->prefix + MS->position >= MS->size)
|
if (MS->prefix + MS->position >= [MS->data length])
|
||||||
return EOF;
|
return EOF;
|
||||||
return (int) MS->buffer[MS->prefix + MS->position++];
|
return (int) ((char*)[MS->data bytes])[MS->prefix + MS->position++];
|
||||||
}
|
}
|
||||||
|
|
||||||
void unchar_func(void *s, int c)
|
void unchar_func(void *s, int c)
|
||||||
{
|
{
|
||||||
if (MS->position > 0)
|
if (MS->position > 0)
|
||||||
MS->position--;
|
MS->position--;
|
||||||
MS->buffer[MS->prefix + MS->position] = (char)c;
|
if (MS->isMutable)
|
||||||
|
((char*)[MS->data mutableBytes])[MS->prefix + MS->position] = (char)c;
|
||||||
}
|
}
|
||||||
|
|
||||||
#if HAVE_VSPRINTF
|
#if HAVE_VSPRINTF
|
||||||
- (int) writeFormat: (NSString*)format
|
- (int) writeFormat: (NSString*)format
|
||||||
arguments: (va_list)arg
|
arguments: (va_list)arg
|
||||||
{
|
{
|
||||||
|
unsigned size;
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
|
if (!isMutable)
|
||||||
|
return 0;
|
||||||
/* xxx Using this ugliness we at least let ourselves safely print
|
/* xxx Using this ugliness we at least let ourselves safely print
|
||||||
formatted strings up to 128 bytes long.
|
formatted strings up to 128 bytes long.
|
||||||
It's digusting, though, and we need to fix it.
|
It's digusting, though, and we need to fix it.
|
||||||
Using GNU stdio streams would do the trick.
|
Using GNU stdio streams would do the trick.
|
||||||
*/
|
*/
|
||||||
|
size = [data capacity];
|
||||||
if (size - (prefix + position) < 128)
|
if (size - (prefix + position) < 128)
|
||||||
[self setStreamBufferCapacity: MAX(128, size*2)];
|
size = MAX(size+128, size*2);
|
||||||
|
[data setLength: size];
|
||||||
ret = VSPRINTF_LENGTH (vsprintf(buffer+prefix+position,
|
|
||||||
[format cStringNoCopy], arg));
|
ret = VSPRINTF_LENGTH (vsprintf([data mutableBytes]+prefix+position,
|
||||||
|
[format cStringNoCopy], arg));
|
||||||
position += ret;
|
position += ret;
|
||||||
/* xxx Make sure we didn't overrun our buffer.
|
/* xxx Make sure we didn't overrun our buffer.
|
||||||
As per above kludge, this would happen if we happen to have more than
|
As per above kludge, this would happen if we happen to have more than
|
||||||
128 bytes left in the buffer and we try to write a string longer than
|
128 bytes left in the buffer and we try to write a string longer than
|
||||||
the num bytes left in the buffer. */
|
the num bytes left in the buffer. */
|
||||||
assert(prefix + position <= size);
|
assert(prefix + position <= [data capacity]);
|
||||||
if (position > eof_position)
|
if (position > eof_position)
|
||||||
eof_position = position;
|
eof_position = position;
|
||||||
|
[data setLength:eof_position + prefix];
|
||||||
if (debug_memory_stream)
|
if (debug_memory_stream)
|
||||||
{
|
{
|
||||||
*(buffer+prefix+position) = '\0';
|
*(char*)([data mutableBytes]+prefix+position) = '\0';
|
||||||
fprintf(stderr, "%s\n", buffer+prefix);
|
fprintf(stderr, "%s\n", (char*)[data mutableBytes]+prefix);
|
||||||
}
|
}
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
@ -299,8 +367,7 @@ void unchar_func(void *s, int c)
|
||||||
|
|
||||||
- (void) dealloc
|
- (void) dealloc
|
||||||
{
|
{
|
||||||
if (free_when_done)
|
[data release];
|
||||||
OBJC_FREE(buffer);
|
|
||||||
[super dealloc];
|
[super dealloc];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -314,21 +381,23 @@ void unchar_func(void *s, int c)
|
||||||
|
|
||||||
- (unsigned) streamBufferCapacity
|
- (unsigned) streamBufferCapacity
|
||||||
{
|
{
|
||||||
return size;
|
if (isMutable)
|
||||||
|
return [data capacity];
|
||||||
|
return [data length];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (char*) streamBuffer
|
- (char*) streamBuffer
|
||||||
{
|
{
|
||||||
return buffer;
|
if (isMutable)
|
||||||
|
return (char*)[data mutableBytes];
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void) setStreamBufferCapacity: (unsigned)s
|
- (void) setStreamBufferCapacity: (unsigned)s
|
||||||
{
|
{
|
||||||
if (s > prefix + eof_position)
|
if (isMutable)
|
||||||
{
|
if (s > prefix + eof_position)
|
||||||
buffer = objc_realloc (buffer, s);
|
[data setCapacity:s];
|
||||||
size = s;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
- (unsigned) streamEofPosition
|
- (unsigned) streamEofPosition
|
||||||
|
@ -338,7 +407,7 @@ void unchar_func(void *s, int c)
|
||||||
|
|
||||||
- (void) setStreamEofPosition: (unsigned)i
|
- (void) setStreamEofPosition: (unsigned)i
|
||||||
{
|
{
|
||||||
if (i < size)
|
if (i < [data length] - prefix)
|
||||||
eof_position = i;
|
eof_position = i;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -102,7 +102,7 @@ static Class NSMutableAttributedString_concrete_class;
|
||||||
return [super initWithCoder:aDecoder];
|
return [super initWithCoder:aDecoder];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (Class) classForPortCoder: (NSPortCoder*)aCoder
|
- (Class) classForPortCoder
|
||||||
{
|
{
|
||||||
return [self class];
|
return [self class];
|
||||||
}
|
}
|
||||||
|
|
1358
Source/NSData.m
1358
Source/NSData.m
File diff suppressed because it is too large
Load diff
|
@ -159,7 +159,7 @@
|
||||||
return [self class];
|
return [self class];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (Class) classForPortCoder: aRmc
|
- (Class) classForPortCoder
|
||||||
{
|
{
|
||||||
return [self class];
|
return [self class];
|
||||||
}
|
}
|
||||||
|
|
|
@ -570,12 +570,12 @@ format: @"NSDistantObject objects only encode with PortEncoder class"];
|
||||||
argFrame: frame];
|
argFrame: frame];
|
||||||
}
|
}
|
||||||
|
|
||||||
- classForCoder: (NSCoder*)aCoder;
|
- classForCoder
|
||||||
{
|
{
|
||||||
return object_get_class (self);
|
return object_get_class (self);
|
||||||
}
|
}
|
||||||
|
|
||||||
- classForPortCoder: (NSPortCoder*)aCoder
|
- classForPortCoder
|
||||||
{
|
{
|
||||||
return object_get_class (self);
|
return object_get_class (self);
|
||||||
}
|
}
|
||||||
|
@ -612,15 +612,18 @@ format: @"NSDistantObject objects only encode with PortEncoder class"];
|
||||||
|
|
||||||
@implementation Protocol (DistributedObjectsCoding)
|
@implementation Protocol (DistributedObjectsCoding)
|
||||||
|
|
||||||
- (Class) classForPortCoder: (NSPortCoder*)aRmc;
|
- (Class) classForPortCoder
|
||||||
{
|
{
|
||||||
return [NSDistantObject class];
|
return [self classForCoder];
|
||||||
}
|
}
|
||||||
|
|
||||||
- replacementObjectForPortCoder: (NSPortCoder*)aRmc;
|
- replacementObjectForPortCoder: (NSPortCoder*)aRmc;
|
||||||
{
|
{
|
||||||
return [NSDistantObject proxyWithLocal: self
|
if ([aRmc isBycopy])
|
||||||
connection: [aRmc connection]];
|
return self;
|
||||||
|
else
|
||||||
|
return [NSDistantObject proxyWithLocal: self
|
||||||
|
connection: [aRmc connection]];
|
||||||
}
|
}
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
|
@ -27,6 +27,7 @@
|
||||||
#include <gnustep/base/CStream.h>
|
#include <gnustep/base/CStream.h>
|
||||||
#include <gnustep/base/behavior.h>
|
#include <gnustep/base/behavior.h>
|
||||||
#include <gnustep/base/CoderPrivate.h>
|
#include <gnustep/base/CoderPrivate.h>
|
||||||
|
#include <gnustep/base/MemoryStream.h>
|
||||||
#include <Foundation/NSException.h>
|
#include <Foundation/NSException.h>
|
||||||
|
|
||||||
#define USE_OPENSTEP_STYLE_FORWARD_REFERENCES 1
|
#define USE_OPENSTEP_STYLE_FORWARD_REFERENCES 1
|
||||||
|
@ -200,20 +201,19 @@
|
||||||
return "NSGUnarchiver";
|
return "NSGUnarchiver";
|
||||||
}
|
}
|
||||||
|
|
||||||
/* if anyone asks for an archivers data we assume that they have finished
|
/* Attempting to use the archiver after this will
|
||||||
archiving and want to read from the data area, so we rewind the stream
|
|
||||||
and give it to them. Attempting to use the archiver after this will
|
|
||||||
mess up in a big way. NB. If the archiver was not writing to an
|
mess up in a big way. NB. If the archiver was not writing to an
|
||||||
NSData object, we can't give one out, so we return nil. */
|
NSData object, we can't give one out, so we return nil. */
|
||||||
- (NSMutableData*) archiverData
|
- (NSMutableData*) archiverData
|
||||||
{
|
{
|
||||||
id s = [cstream stream];
|
id s = [cstream stream];
|
||||||
if ([s isKindOfClass:[NSData class]])
|
if ([s isKindOfClass:[MemoryStream class]])
|
||||||
|
{
|
||||||
|
[s rewindStream];
|
||||||
|
return [s mutableData];
|
||||||
|
}
|
||||||
|
if ([s isKindOfClass:[NSMutableData class]])
|
||||||
{
|
{
|
||||||
if ([s respondsTo:@selector(rewindStream)])
|
|
||||||
{
|
|
||||||
[s rewindStream];
|
|
||||||
}
|
|
||||||
return (NSMutableData*)s;
|
return (NSMutableData*)s;
|
||||||
}
|
}
|
||||||
return nil;
|
return nil;
|
||||||
|
|
|
@ -139,7 +139,7 @@ NSDictionary *_attributesAtIndexEffectiveRange(
|
||||||
return nil;
|
return nil;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (Class) classForPortCoder: (NSPortCoder*)aCoder
|
- (Class) classForPortCoder
|
||||||
{
|
{
|
||||||
return [self class];
|
return [self class];
|
||||||
}
|
}
|
||||||
|
@ -203,7 +203,7 @@ NSDictionary *_attributesAtIndexEffectiveRange(
|
||||||
|
|
||||||
@implementation NSGMutableAttributedString
|
@implementation NSGMutableAttributedString
|
||||||
|
|
||||||
- (Class) classForPortCoder: (NSPortCoder*)aCoder
|
- (Class) classForPortCoder
|
||||||
{
|
{
|
||||||
return [self class];
|
return [self class];
|
||||||
}
|
}
|
||||||
|
|
|
@ -83,7 +83,7 @@
|
||||||
return [self class];
|
return [self class];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (Class) classForPortCoder: (NSPortCoder*)aCoder
|
- (Class) classForPortCoder
|
||||||
{
|
{
|
||||||
return [self class];
|
return [self class];
|
||||||
}
|
}
|
||||||
|
|
166
Source/NSGData.m
166
Source/NSGData.m
|
@ -1,166 +0,0 @@
|
||||||
/* Concrete NSData for GNUStep based on GNU MemoryStream class
|
|
||||||
Copyright (C) 1995, 1996 Free Software Foundation, Inc.
|
|
||||||
|
|
||||||
Written by: Andrew Kachites McCallum <mccallum@gnu.ai.mit.edu>
|
|
||||||
Date: April 1995
|
|
||||||
|
|
||||||
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., 675 Mass Ave, Cambridge, MA 02139, USA.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include <gnustep/base/preface.h>
|
|
||||||
#include <Foundation/NSGData.h>
|
|
||||||
#include <gnustep/base/NSCoder.h>
|
|
||||||
#include <gnustep/base/behavior.h>
|
|
||||||
#include <gnustep/base/MemoryStream.h>
|
|
||||||
#include <gnustep/base/NSString.h>
|
|
||||||
|
|
||||||
/* This from gnustep/base/MemoryStream.h */
|
|
||||||
@interface NSGData (MemoryStream)
|
|
||||||
- _initOnMallocBuffer: (char*)b
|
|
||||||
size: (unsigned)s /* size of malloc'ed buffer */
|
|
||||||
eofPosition: (unsigned)l /* length of buffer with data for reading */
|
|
||||||
prefix: (unsigned)p /* reset for this position */
|
|
||||||
position: (unsigned)i; /* current position for reading/writing */
|
|
||||||
@end
|
|
||||||
|
|
||||||
@implementation NSGData
|
|
||||||
|
|
||||||
+ (void) initialize
|
|
||||||
{
|
|
||||||
static int done = 0;
|
|
||||||
if (!done)
|
|
||||||
{
|
|
||||||
done = 1;
|
|
||||||
class_add_behavior([NSGData class], [MemoryStream class]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/* This is the (internal) designated initializer */
|
|
||||||
- (id) _initWithBytesNoCopy: (void*)bytes
|
|
||||||
length: (unsigned int)length
|
|
||||||
{
|
|
||||||
/* xxxFIXME: should we call [super _initWithBytesNoCopy:length:]? */
|
|
||||||
[self _initOnMallocBuffer:bytes
|
|
||||||
size:length
|
|
||||||
eofPosition:length
|
|
||||||
prefix:0
|
|
||||||
position:0];
|
|
||||||
return self;
|
|
||||||
}
|
|
||||||
|
|
||||||
- (id) initWithBytesNoCopy: (void*)bytes
|
|
||||||
length: (unsigned int)length
|
|
||||||
{
|
|
||||||
return [self _initWithBytesNoCopy:bytes length:length];
|
|
||||||
}
|
|
||||||
|
|
||||||
- (const void*) bytes
|
|
||||||
{
|
|
||||||
return buffer;
|
|
||||||
}
|
|
||||||
|
|
||||||
- (unsigned int) length
|
|
||||||
{
|
|
||||||
return eofPosition;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Storing Data
|
|
||||||
|
|
||||||
- (BOOL) writeToFile: (NSString*)path
|
|
||||||
atomically: (BOOL)useAuxiliaryFile
|
|
||||||
{
|
|
||||||
/* xxx This currently ignores useAuxiliaryFile. */
|
|
||||||
int written;
|
|
||||||
FILE* fp = fopen([path cStringNoCopy], "w");
|
|
||||||
assert (fp); /* This should raise NSException instead. */
|
|
||||||
written = fwrite(buffer+prefix, 1, eofPosition, fp);
|
|
||||||
assert (eofPosition == written);
|
|
||||||
fclose(fp);
|
|
||||||
return YES;
|
|
||||||
}
|
|
||||||
|
|
||||||
- copyWithZone: (NSZone *)zone
|
|
||||||
{
|
|
||||||
if (NSShouldRetainWithZone(self, zone))
|
|
||||||
return [self retain];
|
|
||||||
else {
|
|
||||||
return [[NSData allocWithZone:zone]
|
|
||||||
initWithBytes:[self bytes] length:[self length]];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
- mutableCopyWithZone: (NSZone *)zone
|
|
||||||
{
|
|
||||||
return [[NSMutableData allocWithZone:zone]
|
|
||||||
initWithBytes:[self bytes] length:[self length]];
|
|
||||||
}
|
|
||||||
|
|
||||||
@end
|
|
||||||
|
|
||||||
|
|
||||||
@implementation NSGMutableData
|
|
||||||
|
|
||||||
+ (void) initialize
|
|
||||||
{
|
|
||||||
static int done = 0;
|
|
||||||
if (!done)
|
|
||||||
{
|
|
||||||
done = 1;
|
|
||||||
class_add_behavior([NSGMutableData class], [NSGData class]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Make sure we do this, and not what MemoryStream says. */
|
|
||||||
- (id) initWithCapacity: (unsigned int)capacity
|
|
||||||
{
|
|
||||||
return [self initWithBytesNoCopy: objc_malloc (capacity)
|
|
||||||
length:capacity];
|
|
||||||
}
|
|
||||||
|
|
||||||
/* This is the designated initializer. The behavior comes from NSGData.
|
|
||||||
- (id) initWithBytesNoCopy: (void*)bytes
|
|
||||||
length: (unsigned int)length */
|
|
||||||
|
|
||||||
- (unsigned) capacity
|
|
||||||
{
|
|
||||||
return size;
|
|
||||||
}
|
|
||||||
|
|
||||||
- (void) setLength: (unsigned int)length
|
|
||||||
{
|
|
||||||
[self setStreamBufferCapacity:length];
|
|
||||||
eofPosition = size;
|
|
||||||
}
|
|
||||||
|
|
||||||
- (void*) mutableBytes
|
|
||||||
{
|
|
||||||
return buffer;
|
|
||||||
}
|
|
||||||
|
|
||||||
- (void) appendBytes: (const void*)bytes
|
|
||||||
length: (unsigned int)length
|
|
||||||
{
|
|
||||||
[self writeBytes:bytes length:length];
|
|
||||||
}
|
|
||||||
|
|
||||||
- copyWithZone: (NSZone *)zone
|
|
||||||
{
|
|
||||||
return [[NSData allocWithZone:zone]
|
|
||||||
initWithBytes:[self bytes] length:[self length]];
|
|
||||||
}
|
|
||||||
|
|
||||||
@end
|
|
|
@ -225,7 +225,7 @@
|
||||||
return [self class];
|
return [self class];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (Class) classForPortCoder: (NSPortCoder*)aCoder
|
- (Class) classForPortCoder
|
||||||
{
|
{
|
||||||
return [self class];
|
return [self class];
|
||||||
}
|
}
|
||||||
|
|
1684
Source/NSHData.m
1684
Source/NSHData.m
File diff suppressed because it is too large
Load diff
|
@ -137,7 +137,7 @@ static BOOL debug_connected_coder = NO;
|
||||||
return connection;
|
return connection;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (BOOL) isByCopy
|
- (BOOL) isBycopy
|
||||||
{
|
{
|
||||||
return _is_by_copy;
|
return _is_by_copy;
|
||||||
}
|
}
|
||||||
|
@ -172,12 +172,12 @@ static BOOL debug_connected_coder = NO;
|
||||||
{
|
{
|
||||||
BOOL old = _is_by_copy;
|
BOOL old = _is_by_copy;
|
||||||
id obj;
|
id obj;
|
||||||
|
Class cls;
|
||||||
|
|
||||||
_is_by_copy = NO;
|
_is_by_copy = NO;
|
||||||
obj = [anObj classForPortCoder: (NSPortCoder*)self];
|
|
||||||
/* xxx Should I also do classname substition here? */
|
|
||||||
[self encodeClass: obj];
|
|
||||||
obj = [anObj replacementObjectForPortCoder: (NSPortCoder*)self];
|
obj = [anObj replacementObjectForPortCoder: (NSPortCoder*)self];
|
||||||
|
cls = [obj classForPortCoder];
|
||||||
|
[self encodeClass: cls];
|
||||||
[obj encodeWithCoder: (NSCoder*)self];
|
[obj encodeWithCoder: (NSCoder*)self];
|
||||||
_is_by_copy = old;
|
_is_by_copy = old;
|
||||||
}
|
}
|
||||||
|
@ -188,7 +188,7 @@ static BOOL debug_connected_coder = NO;
|
||||||
id obj;
|
id obj;
|
||||||
|
|
||||||
_is_by_copy = YES;
|
_is_by_copy = YES;
|
||||||
obj = [anObj classForPortCoder: (NSPortCoder*)self];
|
obj = [anObj classForPortCoder];
|
||||||
[self encodeClass: obj];
|
[self encodeClass: obj];
|
||||||
obj = [anObj replacementObjectForPortCoder: (NSPortCoder*)self];
|
obj = [anObj replacementObjectForPortCoder: (NSPortCoder*)self];
|
||||||
[obj encodeWithCoder: (NSCoder*)self];
|
[obj encodeWithCoder: (NSCoder*)self];
|
||||||
|
@ -422,7 +422,7 @@ static BOOL debug_connected_coder = NO;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (BOOL) isByCopy
|
- (BOOL) isBycopy
|
||||||
{
|
{
|
||||||
[self subclassResponsibility:_cmd];
|
[self subclassResponsibility:_cmd];
|
||||||
return NO;
|
return NO;
|
||||||
|
@ -446,12 +446,9 @@ static BOOL debug_connected_coder = NO;
|
||||||
@implementation NSObject (NSPortCoder)
|
@implementation NSObject (NSPortCoder)
|
||||||
|
|
||||||
/* By default, Object's encode themselves as proxies across Connection's */
|
/* By default, Object's encode themselves as proxies across Connection's */
|
||||||
- (Class) classForPortCoder: (NSPortCoder*)aRmc
|
- (Class) classForPortCoder
|
||||||
{
|
{
|
||||||
if ([aRmc isByCopy]) {
|
return [self classForCoder];
|
||||||
return [self class];
|
|
||||||
}
|
|
||||||
return [[aRmc connection] proxyClass];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline BOOL class_is_kind_of (Class self, Class aClassObject)
|
static inline BOOL class_is_kind_of (Class self, Class aClassObject)
|
||||||
|
@ -466,7 +463,7 @@ static inline BOOL class_is_kind_of (Class self, Class aClassObject)
|
||||||
|
|
||||||
- replacementObjectForPortCoder: (NSPortCoder*)aRmc
|
- replacementObjectForPortCoder: (NSPortCoder*)aRmc
|
||||||
{
|
{
|
||||||
if ([aRmc isByCopy]) {
|
if ([aRmc isBycopy]) {
|
||||||
return self;
|
return self;
|
||||||
}
|
}
|
||||||
else if (class_is_kind_of(object_get_class(self->isa),
|
else if (class_is_kind_of(object_get_class(self->isa),
|
||||||
|
|
|
@ -2315,7 +2315,7 @@ else
|
||||||
* deallocated in the other process - causing a memory leak. So we tell
|
* deallocated in the other process - causing a memory leak. So we tell
|
||||||
* the DO system to use the super class instead.
|
* the DO system to use the super class instead.
|
||||||
*/
|
*/
|
||||||
- (Class)classForPortCoder: (NSPortCoder*)aCoder
|
- (Class)classForPortCoder
|
||||||
{
|
{
|
||||||
return [self superclass];
|
return [self superclass];
|
||||||
}
|
}
|
||||||
|
|
|
@ -69,7 +69,7 @@
|
||||||
return [self class];
|
return [self class];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (Class) classForPortCoder: aRmc
|
- (Class) classForPortCoder
|
||||||
{
|
{
|
||||||
return [self class];
|
return [self class];
|
||||||
}
|
}
|
||||||
|
|
|
@ -115,7 +115,8 @@ o_vscanf (void *stream,
|
||||||
{
|
{
|
||||||
id message;
|
id message;
|
||||||
|
|
||||||
message = [NSString stringWithFormat: @"Stream: %s", strerror(errno)];
|
message = [[NSString alloc] initWithFormat: @"Stream: %s",
|
||||||
|
strerror(errno)];
|
||||||
NSLog(message);
|
NSLog(message);
|
||||||
[message release];
|
[message release];
|
||||||
[super dealloc];
|
[super dealloc];
|
||||||
|
@ -131,7 +132,8 @@ o_vscanf (void *stream,
|
||||||
{
|
{
|
||||||
id message;
|
id message;
|
||||||
|
|
||||||
message = [NSString stringWithFormat: @"Stream: %s", strerror(errno)];
|
message = [[NSString alloc] initWithFormat: @"Stream: %s",
|
||||||
|
strerror(errno)];
|
||||||
NSLog(message);
|
NSLog(message);
|
||||||
[message release];
|
[message release];
|
||||||
[super dealloc];
|
[super dealloc];
|
||||||
|
@ -243,6 +245,7 @@ stdio_unchar_func(void *s, int c)
|
||||||
- (void) close
|
- (void) close
|
||||||
{
|
{
|
||||||
fclose(fp);
|
fclose(fp);
|
||||||
|
fp = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (BOOL) isClosed
|
- (BOOL) isClosed
|
||||||
|
|
|
@ -40,6 +40,7 @@
|
||||||
#include <gnustep/base/NSException.h>
|
#include <gnustep/base/NSException.h>
|
||||||
#include <Foundation/NSRunLoop.h>
|
#include <Foundation/NSRunLoop.h>
|
||||||
#include <gnustep/base/Invocation.h>
|
#include <gnustep/base/Invocation.h>
|
||||||
|
#include <Foundation/NSData.h>
|
||||||
#include <Foundation/NSDate.h>
|
#include <Foundation/NSDate.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
@ -1238,7 +1239,7 @@ assert(type == ET_RPORT);
|
||||||
return [TcpOutPort class];
|
return [TcpOutPort class];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (Class) classForPortCoder: aRmc
|
- (Class) classForPortCoder
|
||||||
{
|
{
|
||||||
return [TcpOutPort class];
|
return [TcpOutPort class];
|
||||||
}
|
}
|
||||||
|
@ -1686,7 +1687,7 @@ static NSMapTable *out_port_bag = NULL;
|
||||||
[super dealloc];
|
[super dealloc];
|
||||||
}
|
}
|
||||||
|
|
||||||
- classForPortCoder: aRmc
|
- classForPortCoder
|
||||||
{
|
{
|
||||||
/* Make sure that Connection's always send us bycopy,
|
/* Make sure that Connection's always send us bycopy,
|
||||||
i.e. as our own class, not a Proxy class. */
|
i.e. as our own class, not a Proxy class. */
|
||||||
|
@ -1840,15 +1841,15 @@ static NSMapTable *out_port_bag = NULL;
|
||||||
int c;
|
int c;
|
||||||
int remaining;
|
int remaining;
|
||||||
|
|
||||||
remaining = size - eof_position;
|
remaining = [data length] - prefix - eof_position;
|
||||||
#ifdef GDOMAP
|
#ifdef GDOMAP
|
||||||
c = tryRead(s, 1, buffer + prefix + eof_position, -remaining);
|
c = tryRead(s, 1, [data mutableBytes] + prefix + eof_position, -remaining);
|
||||||
#else
|
#else
|
||||||
/* xxx We need to make sure this read() is non-blocking. */
|
/* xxx We need to make sure this read() is non-blocking. */
|
||||||
#ifdef __WIN32__
|
#ifdef __WIN32__
|
||||||
c = recv (s, buffer + prefix + eof_position, remaining, 0);
|
c = recv (s, [data mutableBytes] + prefix + eof_position, remaining, 0);
|
||||||
#else
|
#else
|
||||||
c = read (s, buffer + prefix + eof_position, remaining);
|
c = read (s, [data mutableBytes] + prefix + eof_position, remaining);
|
||||||
#endif /* __WIN32 */
|
#endif /* __WIN32 */
|
||||||
#endif /* GDOMAP */
|
#endif /* GDOMAP */
|
||||||
if (c <= 0) {
|
if (c <= 0) {
|
||||||
|
@ -1875,25 +1876,25 @@ static NSMapTable *out_port_bag = NULL;
|
||||||
|
|
||||||
/* Put the packet size in the first two bytes of the packet. */
|
/* Put the packet size in the first two bytes of the packet. */
|
||||||
assert (prefix == PREFIX_SIZE);
|
assert (prefix == PREFIX_SIZE);
|
||||||
*(PREFIX_LENGTH_TYPE*)buffer = htons (eof_position);
|
*(PREFIX_LENGTH_TYPE*)[data mutableBytes] = htons (eof_position);
|
||||||
|
|
||||||
/* Put the sockaddr_in for replies in the next bytes of the prefix
|
/* Put the sockaddr_in for replies in the next bytes of the prefix
|
||||||
region. If there is no reply address specified, fill it with zeros. */
|
region. If there is no reply address specified, fill it with zeros. */
|
||||||
if (addr)
|
if (addr)
|
||||||
/* Do this memcpy instead of simply casting the pointer because
|
/* Do this memcpy instead of simply casting the pointer because
|
||||||
some systems fail to do the cast correctly (due to alignment issues?) */
|
some systems fail to do the cast correctly (due to alignment issues?) */
|
||||||
memcpy (buffer + PREFIX_LENGTH_SIZE, addr, PREFIX_ADDRESS_SIZE);
|
memcpy ([data mutableBytes]+PREFIX_LENGTH_SIZE, addr, PREFIX_ADDRESS_SIZE);
|
||||||
else
|
else
|
||||||
memset (buffer + PREFIX_LENGTH_SIZE, 0, PREFIX_ADDRESS_SIZE);
|
memset ([data mutableBytes]+PREFIX_LENGTH_SIZE, 0, PREFIX_ADDRESS_SIZE);
|
||||||
|
|
||||||
/* Write the packet on the socket. */
|
/* Write the packet on the socket. */
|
||||||
#ifdef GDOMAP
|
#ifdef GDOMAP
|
||||||
c = tryWrite (s, (int)timeout, buffer, prefix + eof_position);
|
c = tryWrite (s, (int)timeout, [data bytes], prefix + eof_position);
|
||||||
#else
|
#else
|
||||||
#ifdef __WIN32__
|
#ifdef __WIN32__
|
||||||
c = send (s, buffer, prefix + eof_position, 0);
|
c = send (s, [data bytes], prefix + eof_position, 0);
|
||||||
#else
|
#else
|
||||||
c = write (s, buffer, prefix + eof_position);
|
c = write (s, [data bytes], prefix + eof_position);
|
||||||
#endif /* __WIN32__ */
|
#endif /* __WIN32__ */
|
||||||
#endif /* GDOMAP */
|
#endif /* GDOMAP */
|
||||||
if (c == -2) {
|
if (c == -2) {
|
||||||
|
|
|
@ -291,7 +291,7 @@ static NSMapTable *port_number_2_in_port = NULL;
|
||||||
return [UdpOutPort class];
|
return [UdpOutPort class];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (Class) classForPortCoder: aRmc
|
- (Class) classForPortCoder
|
||||||
{
|
{
|
||||||
return [UdpOutPort class];
|
return [UdpOutPort class];
|
||||||
}
|
}
|
||||||
|
|
|
@ -69,7 +69,7 @@ getAddr(NSString* name, NSString* svc, NSString* pcl, struct sockaddr_in *sin)
|
||||||
struct servent* sp;
|
struct servent* sp;
|
||||||
|
|
||||||
if (svc == nil)
|
if (svc == nil)
|
||||||
return NO;
|
svc = @"localhost";
|
||||||
|
|
||||||
if (pcl)
|
if (pcl)
|
||||||
proto = [pcl cStringNoCopy];
|
proto = [pcl cStringNoCopy];
|
||||||
|
@ -174,21 +174,17 @@ getAddr(NSString* name, NSString* svc, NSString* pcl, struct sockaddr_in *sin)
|
||||||
int net;
|
int net;
|
||||||
struct sockaddr_in sin;
|
struct sockaddr_in sin;
|
||||||
|
|
||||||
if (address == nil)
|
|
||||||
{
|
|
||||||
[self release];
|
|
||||||
return nil;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (getAddr(address, service, protocol, &sin) == NO)
|
if (getAddr(address, service, protocol, &sin) == NO)
|
||||||
{
|
{
|
||||||
[self release];
|
[self dealloc];
|
||||||
|
NSLog(@"bad address-service-protocol combination");
|
||||||
return nil;
|
return nil;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((net = socket(AF_INET, SOCK_STREAM, PF_UNSPEC)) < 0)
|
if ((net = socket(AF_INET, SOCK_STREAM, PF_UNSPEC)) < 0)
|
||||||
{
|
{
|
||||||
[self release];
|
[self dealloc];
|
||||||
|
NSLog(@"unable to create socket - %s", strerror(errno));
|
||||||
return nil;
|
return nil;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -201,7 +197,8 @@ getAddr(NSString* name, NSString* svc, NSString* pcl, struct sockaddr_in *sin)
|
||||||
if (connect(net, (struct sockaddr*)&sin, sizeof(sin)) < 0)
|
if (connect(net, (struct sockaddr*)&sin, sizeof(sin)) < 0)
|
||||||
if (errno != EINPROGRESS)
|
if (errno != EINPROGRESS)
|
||||||
{
|
{
|
||||||
[self release];
|
[self dealloc];
|
||||||
|
NSLog(@"unable to make connection - %s", strerror(errno));
|
||||||
return nil;
|
return nil;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -214,10 +211,10 @@ getAddr(NSString* name, NSString* svc, NSString* pcl, struct sockaddr_in *sin)
|
||||||
[writeInfo addObject:info];
|
[writeInfo addObject:info];
|
||||||
[info release];
|
[info release];
|
||||||
[self watchWriteDescriptor];
|
[self watchWriteDescriptor];
|
||||||
|
connectOK = YES;
|
||||||
|
readOK = NO;
|
||||||
|
writeOK = NO;
|
||||||
}
|
}
|
||||||
connectOK = YES;
|
|
||||||
readOK = NO;
|
|
||||||
writeOK = NO;
|
|
||||||
return self;
|
return self;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -231,13 +228,15 @@ getAddr(NSString* name, NSString* svc, NSString* pcl, struct sockaddr_in *sin)
|
||||||
|
|
||||||
if (getAddr(address, service, protocol, &sin) == NO)
|
if (getAddr(address, service, protocol, &sin) == NO)
|
||||||
{
|
{
|
||||||
[self release];
|
[self dealloc];
|
||||||
return nil;
|
NSLog(@"bad address-service-protocol combination");
|
||||||
|
return nil;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((net = socket(AF_INET, SOCK_STREAM, PF_UNSPEC)) < 0)
|
if ((net = socket(AF_INET, SOCK_STREAM, PF_UNSPEC)) < 0)
|
||||||
{
|
{
|
||||||
[self release];
|
[self dealloc];
|
||||||
|
NSLog(@"unable to create socket - %s", strerror(errno));
|
||||||
return nil;
|
return nil;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -246,21 +245,26 @@ getAddr(NSString* name, NSString* svc, NSString* pcl, struct sockaddr_in *sin)
|
||||||
if (bind(net, (struct sockaddr *)&sin, sizeof(sin)) < 0)
|
if (bind(net, (struct sockaddr *)&sin, sizeof(sin)) < 0)
|
||||||
{
|
{
|
||||||
(void) close(net);
|
(void) close(net);
|
||||||
[self release];
|
[self dealloc];
|
||||||
|
NSLog(@"unable to bind to port - %s", strerror(errno));
|
||||||
return nil;
|
return nil;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (listen(net, 5) < 0)
|
if (listen(net, 5) < 0)
|
||||||
{
|
{
|
||||||
(void) close(net);
|
(void) close(net);
|
||||||
[self release];
|
[self dealloc];
|
||||||
|
NSLog(@"unable to listen on port - %s", strerror(errno));
|
||||||
return nil;
|
return nil;
|
||||||
}
|
}
|
||||||
|
|
||||||
self = [self initWithFileDescriptor:net closeOnDealloc:YES];
|
self = [self initWithFileDescriptor:net closeOnDealloc:YES];
|
||||||
acceptOK = YES;
|
if (self)
|
||||||
readOK = NO;
|
{
|
||||||
writeOK = NO;
|
acceptOK = YES;
|
||||||
|
readOK = NO;
|
||||||
|
writeOK = NO;
|
||||||
|
}
|
||||||
return self;
|
return self;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -270,13 +274,14 @@ getAddr(NSString* name, NSString* svc, NSString* pcl, struct sockaddr_in *sin)
|
||||||
|
|
||||||
if (d < 0)
|
if (d < 0)
|
||||||
{
|
{
|
||||||
[self release];
|
[self dealloc];
|
||||||
return nil;
|
return nil;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
self = [self initWithFileDescriptor:d closeOnDealloc:YES];
|
self = [self initWithFileDescriptor:d closeOnDealloc:YES];
|
||||||
writeOK = NO;
|
if (self)
|
||||||
|
writeOK = NO;
|
||||||
return self;
|
return self;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -287,13 +292,14 @@ getAddr(NSString* name, NSString* svc, NSString* pcl, struct sockaddr_in *sin)
|
||||||
|
|
||||||
if (d < 0)
|
if (d < 0)
|
||||||
{
|
{
|
||||||
[self release];
|
[self dealloc];
|
||||||
return nil;
|
return nil;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
self = [self initWithFileDescriptor:d closeOnDealloc:YES];
|
self = [self initWithFileDescriptor:d closeOnDealloc:YES];
|
||||||
readOK = NO;
|
if (self)
|
||||||
|
readOK = NO;
|
||||||
return self;
|
return self;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -304,7 +310,7 @@ getAddr(NSString* name, NSString* svc, NSString* pcl, struct sockaddr_in *sin)
|
||||||
|
|
||||||
if (d < 0)
|
if (d < 0)
|
||||||
{
|
{
|
||||||
[self release];
|
[self dealloc];
|
||||||
return nil;
|
return nil;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@ -318,7 +324,7 @@ getAddr(NSString* name, NSString* svc, NSString* pcl, struct sockaddr_in *sin)
|
||||||
if (fh_stderr)
|
if (fh_stderr)
|
||||||
{
|
{
|
||||||
[fh_stderr retain];
|
[fh_stderr retain];
|
||||||
[self release];
|
[self dealloc];
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -326,8 +332,8 @@ getAddr(NSString* name, NSString* svc, NSString* pcl, struct sockaddr_in *sin)
|
||||||
fh_stderr = self;
|
fh_stderr = self;
|
||||||
}
|
}
|
||||||
self = fh_stderr;
|
self = fh_stderr;
|
||||||
readOK = NO;
|
if (self)
|
||||||
return self;
|
readOK = NO;
|
||||||
return self;
|
return self;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -336,7 +342,7 @@ getAddr(NSString* name, NSString* svc, NSString* pcl, struct sockaddr_in *sin)
|
||||||
if (fh_stdin)
|
if (fh_stdin)
|
||||||
{
|
{
|
||||||
[fh_stdin retain];
|
[fh_stdin retain];
|
||||||
[self release];
|
[self dealloc];
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -344,7 +350,8 @@ getAddr(NSString* name, NSString* svc, NSString* pcl, struct sockaddr_in *sin)
|
||||||
fh_stdin = self;
|
fh_stdin = self;
|
||||||
}
|
}
|
||||||
self = fh_stdin;
|
self = fh_stdin;
|
||||||
writeOK = NO;
|
if (self)
|
||||||
|
writeOK = NO;
|
||||||
return self;
|
return self;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -353,7 +360,7 @@ getAddr(NSString* name, NSString* svc, NSString* pcl, struct sockaddr_in *sin)
|
||||||
if (fh_stdout)
|
if (fh_stdout)
|
||||||
{
|
{
|
||||||
[fh_stdout retain];
|
[fh_stdout retain];
|
||||||
[self release];
|
[self dealloc];
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -361,7 +368,8 @@ getAddr(NSString* name, NSString* svc, NSString* pcl, struct sockaddr_in *sin)
|
||||||
fh_stdout = self;
|
fh_stdout = self;
|
||||||
}
|
}
|
||||||
self = fh_stdout;
|
self = fh_stdout;
|
||||||
readOK = NO;
|
if (self)
|
||||||
|
readOK = NO;
|
||||||
return self;
|
return self;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -384,9 +392,11 @@ getAddr(NSString* name, NSString* svc, NSString* pcl, struct sockaddr_in *sin)
|
||||||
int e;
|
int e;
|
||||||
|
|
||||||
if (fstat(desc, &sbuf) < 0)
|
if (fstat(desc, &sbuf) < 0)
|
||||||
[NSException raise: NSFileHandleOperationException
|
{
|
||||||
format: @"unable to get status of descriptor - %s",
|
[self dealloc];
|
||||||
strerror(errno)];
|
NSLog(@"unable to get status of descriptor - %s", strerror(errno));
|
||||||
|
return nil;
|
||||||
|
}
|
||||||
if (S_ISREG(sbuf.st_mode))
|
if (S_ISREG(sbuf.st_mode))
|
||||||
isStandardFile = YES;
|
isStandardFile = YES;
|
||||||
else
|
else
|
||||||
|
@ -732,12 +742,9 @@ getAddr(NSString* name, NSString* svc, NSString* pcl, struct sockaddr_in *sin)
|
||||||
|
|
||||||
- (void)closeFile
|
- (void)closeFile
|
||||||
{
|
{
|
||||||
NSNotification* n;
|
if (descriptor < 0)
|
||||||
|
[NSException raise: NSFileHandleOperationException
|
||||||
/* Ensure that any notifications we queued are destroyed with us. */
|
format: @"attempt to close closed file"];
|
||||||
n = [NSNotification notificationWithName:@"any" object:self userInfo:nil];
|
|
||||||
[[NSNotificationQueue defaultQueue] dequeueNotificationsMatching:n
|
|
||||||
coalesceMask:NSNotificationCoalescingOnSender];
|
|
||||||
|
|
||||||
[self ignoreReadDescriptor];
|
[self ignoreReadDescriptor];
|
||||||
[self ignoreWriteDescriptor];
|
[self ignoreWriteDescriptor];
|
||||||
|
@ -851,12 +858,15 @@ getAddr(NSString* name, NSString* svc, NSString* pcl, struct sockaddr_in *sin)
|
||||||
|
|
||||||
- (void)ignoreReadDescriptor
|
- (void)ignoreReadDescriptor
|
||||||
{
|
{
|
||||||
NSRunLoop* l = [NSRunLoop currentRunLoop];
|
NSRunLoop *l;
|
||||||
NSArray* modes = nil;
|
NSArray *modes;
|
||||||
|
|
||||||
if (descriptor < 0)
|
if (descriptor < 0)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
l = [NSRunLoop currentRunLoop];
|
||||||
|
modes = nil;
|
||||||
|
|
||||||
if (readInfo)
|
if (readInfo)
|
||||||
modes = (NSArray*)[readInfo objectForKey:NSFileHandleNotificationMonitorModes];
|
modes = (NSArray*)[readInfo objectForKey:NSFileHandleNotificationMonitorModes];
|
||||||
|
|
||||||
|
@ -881,12 +891,15 @@ getAddr(NSString* name, NSString* svc, NSString* pcl, struct sockaddr_in *sin)
|
||||||
|
|
||||||
- (void)ignoreWriteDescriptor
|
- (void)ignoreWriteDescriptor
|
||||||
{
|
{
|
||||||
NSRunLoop* l = [NSRunLoop currentRunLoop];
|
NSRunLoop *l;
|
||||||
NSArray* modes = nil;
|
NSArray *modes;
|
||||||
|
|
||||||
if (descriptor < 0)
|
if (descriptor < 0)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
l = [NSRunLoop currentRunLoop];
|
||||||
|
modes = nil;
|
||||||
|
|
||||||
if ([writeInfo count] > 0)
|
if ([writeInfo count] > 0)
|
||||||
{
|
{
|
||||||
NSMutableDictionary* info = [writeInfo objectAtIndex:0];
|
NSMutableDictionary* info = [writeInfo objectAtIndex:0];
|
||||||
|
@ -915,7 +928,7 @@ getAddr(NSString* name, NSString* svc, NSString* pcl, struct sockaddr_in *sin)
|
||||||
|
|
||||||
- (void)watchReadDescriptorForModes:(NSArray*)modes;
|
- (void)watchReadDescriptorForModes:(NSArray*)modes;
|
||||||
{
|
{
|
||||||
NSRunLoop* l;
|
NSRunLoop *l;
|
||||||
|
|
||||||
if (descriptor < 0)
|
if (descriptor < 0)
|
||||||
return;
|
return;
|
||||||
|
@ -986,7 +999,7 @@ getAddr(NSString* name, NSString* svc, NSString* pcl, struct sockaddr_in *sin)
|
||||||
extra: (void*)extra
|
extra: (void*)extra
|
||||||
forMode: (NSString*)mode
|
forMode: (NSString*)mode
|
||||||
{
|
{
|
||||||
NSString* operation;
|
NSString *operation;
|
||||||
|
|
||||||
if (type == ET_RDESC) {
|
if (type == ET_RDESC) {
|
||||||
operation = [readInfo objectForKey:NotificationKey];
|
operation = [readInfo objectForKey:NotificationKey];
|
||||||
|
@ -1115,13 +1128,12 @@ getAddr(NSString* name, NSString* svc, NSString* pcl, struct sockaddr_in *sin)
|
||||||
e &= ~NBLK_OPT;
|
e &= ~NBLK_OPT;
|
||||||
|
|
||||||
if (fcntl(descriptor, F_SETFL, e) < 0)
|
if (fcntl(descriptor, F_SETFL, e) < 0)
|
||||||
[NSException raise: NSFileHandleOperationException
|
NSLog(@"unable to set non-blocking mode - %s", strerror(errno));
|
||||||
format: @"could not change non-blocking mode"];
|
else
|
||||||
isNonBlocking = flag;
|
isNonBlocking = flag;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
[NSException raise: NSFileHandleOperationException
|
NSLog(@"unable to get non-blocking mode - %s", strerror(errno));
|
||||||
format: @"could not change non-blocking mode"];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
|
@ -1,11 +1,14 @@
|
||||||
#include <Foundation/NSData.h>
|
#include <Foundation/NSData.h>
|
||||||
|
#include <Foundation/NSArchiver.h>
|
||||||
#include <Foundation/NSAutoreleasePool.h>
|
#include <Foundation/NSAutoreleasePool.h>
|
||||||
#include <Foundation/NSString.h>
|
#include <Foundation/NSString.h>
|
||||||
|
|
||||||
int
|
int
|
||||||
main()
|
main()
|
||||||
{
|
{
|
||||||
|
id a;
|
||||||
id d;
|
id d;
|
||||||
|
id o;
|
||||||
id pool;
|
id pool;
|
||||||
|
|
||||||
pool = [[NSAutoreleasePool alloc] init];
|
pool = [[NSAutoreleasePool alloc] init];
|
||||||
|
@ -14,7 +17,76 @@ main()
|
||||||
if (d == nil)
|
if (d == nil)
|
||||||
printf("Unable to map file");
|
printf("Unable to map file");
|
||||||
printf("Mapped %d bytes\n", [d length]);
|
printf("Mapped %d bytes\n", [d length]);
|
||||||
|
|
||||||
|
o = [d copy];
|
||||||
|
printf("Copied %d bytes\n", [o length]);
|
||||||
|
[o release];
|
||||||
|
|
||||||
|
o = [d mutableCopy];
|
||||||
|
printf("Copied %d bytes\n", [o length]);
|
||||||
|
[o release];
|
||||||
|
|
||||||
|
d = [NSData dataWithContentsOfFile:@"nsdata.m"];
|
||||||
|
if (d == nil)
|
||||||
|
printf("Unable to read file");
|
||||||
|
printf("Read %d bytes\n", [d length]);
|
||||||
|
|
||||||
|
o = [d copy];
|
||||||
|
printf("Copied %d bytes\n", [o length]);
|
||||||
|
[o release];
|
||||||
|
|
||||||
|
o = [d mutableCopy];
|
||||||
|
printf("Copied %d bytes\n", [o length]);
|
||||||
|
[o release];
|
||||||
|
|
||||||
|
d = [NSData dataWithSharedBytes: [d bytes] length: [d length]];
|
||||||
|
if (d == nil)
|
||||||
|
printf("Unable to make shared data");
|
||||||
|
printf("Shared data of %d bytes\n", [d length]);
|
||||||
|
|
||||||
|
o = [d copy];
|
||||||
|
printf("Copied %d bytes\n", [o length]);
|
||||||
|
[o release];
|
||||||
|
|
||||||
|
o = [d mutableCopy];
|
||||||
|
printf("Copied %d bytes\n", [o length]);
|
||||||
|
[o release];
|
||||||
|
|
||||||
|
d = [NSMutableData dataWithSharedBytes: [d bytes] length: [d length]];
|
||||||
|
if (d == nil)
|
||||||
|
printf("Unable to make mutable shared data");
|
||||||
|
printf("Mutable shared data of %d bytes\n", [d length]);
|
||||||
|
|
||||||
|
o = [d copy];
|
||||||
|
printf("Copied %d bytes\n", [o length]);
|
||||||
|
[o release];
|
||||||
|
|
||||||
|
o = [d mutableCopy];
|
||||||
|
printf("Copied %d bytes\n", [o length]);
|
||||||
|
[o release];
|
||||||
|
|
||||||
|
[d appendBytes: "Hello world" length: 11];
|
||||||
|
printf("Extended by 11 bytes to %d bytes\n", [d length]);
|
||||||
|
|
||||||
|
d = [NSMutableData dataWithShmID: [d shmID] length: [d length]];
|
||||||
|
if (d == nil)
|
||||||
|
printf("Unable to make mutable data with old ID\n");
|
||||||
|
printf("data with shmID gives data length %d\n", [d length]);
|
||||||
|
|
||||||
|
a = [[NSArchiver new] autorelease];
|
||||||
|
[a encodeRootObject: d];
|
||||||
|
printf("Encoded data into archive\n");
|
||||||
|
a = [[NSUnarchiver alloc] initForReadingWithData: [a archiverData]];
|
||||||
|
o = [a decodeObject];
|
||||||
|
printf("Decoded data from archive - length %d\n", [o length]);
|
||||||
|
[a release];
|
||||||
|
[o release];
|
||||||
|
|
||||||
|
[d setCapacity: 2000000];
|
||||||
|
printf("Set capacity of shared memory item to %d\n", [d capacity]);
|
||||||
|
|
||||||
[pool release];
|
[pool release];
|
||||||
|
|
||||||
exit(0);
|
exit(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -5,10 +5,10 @@
|
||||||
#include <gnustep/base/Connection.h>
|
#include <gnustep/base/Connection.h>
|
||||||
#include <gnustep/base/Array.h>
|
#include <gnustep/base/Array.h>
|
||||||
|
|
||||||
typedef struct _small_struct {
|
typedef struct _small_struct {
|
||||||
unsigned char z;
|
unsigned char z;
|
||||||
} small_struct;
|
} small_struct;
|
||||||
|
|
||||||
typedef struct _foo {
|
typedef struct _foo {
|
||||||
int i;
|
int i;
|
||||||
char *s;
|
char *s;
|
||||||
|
|
Loading…
Reference in a new issue