mirror of
https://github.com/gnustep/libs-base.git
synced 2025-04-23 09:04:13 +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
5367a9100f
commit
0060d4a2a4
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>
|
||||
|
||||
* Fix Makefiles so snapshots and releases work again
|
||||
|
|
|
@ -21,6 +21,13 @@
|
|||
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
|
||||
#define __MemoryStream_h_GNUSTEP_BASE_INCLUDE
|
||||
|
||||
|
@ -45,21 +52,23 @@
|
|||
|
||||
@interface MemoryStream : Stream <MemoryStreaming>
|
||||
{
|
||||
int type;
|
||||
char *buffer;
|
||||
int size;
|
||||
int eof_position;
|
||||
id data;
|
||||
int prefix;
|
||||
int position;
|
||||
BOOL free_when_done;
|
||||
int eof_position;
|
||||
BOOL isMutable;
|
||||
}
|
||||
|
||||
+ (MemoryStream*)streamWithData: (id)anObject;
|
||||
|
||||
- initWithCapacity: (unsigned)capacity
|
||||
prefix: (unsigned)prefix;
|
||||
- initWithData: (id)anObject;
|
||||
|
||||
- initWithSize: (unsigned)s; /* For backwards compatibility, depricated */
|
||||
|
||||
- (void) setFreeWhenDone: (BOOL)f;
|
||||
- (id) data;
|
||||
- (id) mutableData;
|
||||
- (unsigned) streamBufferPrefix;
|
||||
- (unsigned) streamBufferLength; /* prefix + eofPosition */
|
||||
|
||||
|
|
|
@ -258,7 +258,7 @@ extern NSString *ConnectionBecameInvalidNotification;
|
|||
@end
|
||||
|
||||
@interface Object (NSPortCoder)
|
||||
- (Class) classForPortCoder: (NSPortCoder*)aCoder;
|
||||
- (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
|
||||
|
|
|
@ -34,13 +34,13 @@
|
|||
|
||||
+ (id)data;
|
||||
+ (id)dataWithBytes: (const void*)bytes
|
||||
length: (unsigned int)length;
|
||||
length: (unsigned int)length;
|
||||
+ (id)dataWithBytesNoCopy: (void*)bytes
|
||||
length: (unsigned int)length;
|
||||
length: (unsigned int)length;
|
||||
+ (id)dataWithContentsOfFile: (NSString*)path;
|
||||
+ (id)dataWithContentsOfMappedFile: (NSString*)path;
|
||||
- (id)initWithBytes: (const void*)bytes
|
||||
length: (unsigned int)length;
|
||||
length: (unsigned int)length;
|
||||
- (id)initWithBytesNoCopy: (void*)bytes
|
||||
length: (unsigned int)length;
|
||||
- (id)initWithContentsOfFile: (NSString*)path;
|
||||
|
@ -53,9 +53,9 @@
|
|||
- (NSString*)description;
|
||||
- (void)getBytes: (void*)buffer;
|
||||
- (void)getBytes: (void*)buffer
|
||||
length: (unsigned int)length;
|
||||
length: (unsigned int)length;
|
||||
- (void)getBytes: (void*)buffer
|
||||
range: (NSRange)aRange;
|
||||
range: (NSRange)aRange;
|
||||
- (NSData*)subdataWithRange: (NSRange)aRange;
|
||||
|
||||
// Querying a Data Object
|
||||
|
@ -72,23 +72,29 @@
|
|||
|
||||
- (unsigned int)deserializeAlignedBytesLengthAtCursor: (unsigned int*)cursor;
|
||||
- (void)deserializeBytes: (void*)buffer
|
||||
length: (unsigned int)bytes
|
||||
atCursor: (unsigned int*)cursor;
|
||||
length: (unsigned int)bytes
|
||||
atCursor: (unsigned int*)cursor;
|
||||
- (void)deserializeDataAt: (void*)data
|
||||
ofObjCType: (const char*)type
|
||||
atCursor: (unsigned int*)cursor
|
||||
context: (id <NSObjCTypeSerializationCallBack>)callback;
|
||||
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;
|
||||
count: (unsigned int)numInts
|
||||
atCursor: (unsigned int*)cursor;
|
||||
- (void)deserializeInts: (int*)intBuffer
|
||||
count: (unsigned int)numInts
|
||||
atIndex: (unsigned int)index;
|
||||
count: (unsigned int)numInts
|
||||
atIndex: (unsigned int)index;
|
||||
|
||||
@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
|
||||
|
||||
|
@ -132,6 +138,12 @@
|
|||
|
||||
@end
|
||||
|
||||
@interface NSMutableData (GNUstepExtensions)
|
||||
- (unsigned int) capacity;
|
||||
- (id) setCapacity: (unsigned int)newCapacity;
|
||||
- (int) shmID;
|
||||
@end
|
||||
|
||||
/*
|
||||
Local Variables:
|
||||
mode: ObjC
|
||||
|
|
|
@ -55,7 +55,7 @@
|
|||
+ newForRemoteTarget: (unsigned)target connection: (NSConnection*)conn;
|
||||
|
||||
- awakeAfterUsingCoder: aDecoder;
|
||||
- classForPortCoder: aRmc;
|
||||
- classForPortCoder;
|
||||
+ newWithCoder: aRmc;
|
||||
- (const char *) selectorTypeForProxy: (SEL)selector;
|
||||
- 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
|
||||
|
||||
@interface NSObject (NSPortCoder)
|
||||
- (Class) classForPortCoder: (NSPortCoder*)anEncoder;
|
||||
- (Class) classForPortCoder;
|
||||
- (id) replacementObjectForPortCoder: (NSPortCoder*)anEncoder;
|
||||
@end
|
||||
|
||||
|
|
|
@ -39,7 +39,7 @@
|
|||
- (NSConnection*) connection;
|
||||
- (NSPort*) decodePortObject;
|
||||
- (void) encodePortObject: (NSPort*)aPort;
|
||||
- (BOOL) isByCopy;
|
||||
- (BOOL) isBycopy;
|
||||
|
||||
@end
|
||||
|
||||
|
|
|
@ -252,20 +252,16 @@ static BOOL debug_coder = NO;
|
|||
|
||||
/* Initializing an archiver */
|
||||
|
||||
@interface NSData (Streaming) <Streaming>
|
||||
@end
|
||||
|
||||
- (id) initForWritingWithMutableData: (NSMutableData*)mdata
|
||||
{
|
||||
/* This relies on the fact that GNU extentions to NSMutableData
|
||||
cause it to conform to <Streaming>. */
|
||||
[(id)self initForWritingToStream: mdata];
|
||||
[(id)self initForWritingToStream: [MemoryStream streamWithData: mdata]];
|
||||
return self;
|
||||
}
|
||||
|
||||
- (id) initForReadingWithData: (NSData*)data
|
||||
{
|
||||
id ret = [[self class] newReadingFromStream: data];
|
||||
id ret = [[self class] newReadingFromStream:
|
||||
[MemoryStream streamWithData:data]];
|
||||
if ([self retainCount] == 0)
|
||||
[ret autorelease];
|
||||
else
|
||||
|
@ -295,7 +291,8 @@ static BOOL debug_coder = NO;
|
|||
|
||||
+ unarchiveObjectWithData: (NSData*) data
|
||||
{
|
||||
return [self decodeObjectWithName: NULL fromStream: data];
|
||||
return [self decodeObjectWithName: NULL
|
||||
fromStream: [MemoryStream streamWithData:data]];
|
||||
}
|
||||
|
||||
+ unarchiveObjectWithFile: (NSString*) path
|
||||
|
|
|
@ -118,7 +118,7 @@
|
|||
}
|
||||
|
||||
/* Next two methods for OPENSTEP */
|
||||
- (Class) classForPortCoder: coder
|
||||
- (Class) classForPortCoder
|
||||
{
|
||||
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
|
||||
a function across the wire. */
|
||||
- classForPortCoder: coder
|
||||
- classForPortCoder
|
||||
{
|
||||
return [[coder connection] proxyClass];
|
||||
return [NSDistantObject class];
|
||||
}
|
||||
|
||||
- (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
|
||||
a function across the wire. */
|
||||
- classForPortCoder: coder
|
||||
- classForPortCoder
|
||||
{
|
||||
return [[coder connection] proxyClass];
|
||||
return [NSDistantObject class];
|
||||
}
|
||||
|
||||
- (void) encodeWithCoder: (id <Encoding>)coder
|
||||
|
|
|
@ -315,8 +315,6 @@ NSGArray.m \
|
|||
NSGAttributedString.m \
|
||||
NSGCountedSet.m \
|
||||
NSGCString.m \
|
||||
NSGData.m \
|
||||
NSHData.m \
|
||||
NSGDictionary.m \
|
||||
NSGSet.m \
|
||||
NSGSequence.m \
|
||||
|
@ -406,8 +404,6 @@ Foundation/NSGArchiver.h \
|
|||
Foundation/NSGArray.h \
|
||||
Foundation/NSGAttributedString.h \
|
||||
Foundation/NSGCString.h \
|
||||
Foundation/NSGData.h \
|
||||
Foundation/NSHData.h \
|
||||
Foundation/NSGDictionary.h \
|
||||
Foundation/NSGSet.h \
|
||||
Foundation/NSGSequence.h \
|
||||
|
|
|
@ -24,6 +24,7 @@
|
|||
#include <gnustep/base/preface.h>
|
||||
#include <gnustep/base/MemoryStream.h>
|
||||
#include <gnustep/base/Coder.h>
|
||||
#include <Foundation/NSData.h>
|
||||
#include <Foundation/NSException.h>
|
||||
#include <stdarg.h>
|
||||
#include <assert.h>
|
||||
|
@ -44,15 +45,6 @@
|
|||
/* memory.h and strings.h conflict on some systems. */
|
||||
#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
|
||||
|
||||
extern int
|
||||
|
@ -67,6 +59,16 @@ static BOOL debug_memory_stream = NO;
|
|||
|
||||
@implementation MemoryStream
|
||||
|
||||
+ (MemoryStream*)streamWithData: (id)anObject
|
||||
{
|
||||
return [[[MemoryStream alloc] initWithData:anObject] autorelease];
|
||||
}
|
||||
|
||||
- (id) data
|
||||
{
|
||||
return data;
|
||||
}
|
||||
|
||||
/* xxx This interface will change */
|
||||
- _initOnMallocBuffer: (char*)b
|
||||
freeWhenDone: (BOOL)f
|
||||
|
@ -75,14 +77,37 @@ static BOOL debug_memory_stream = NO;
|
|||
prefix: (unsigned)p /* never read/write before this position */
|
||||
position: (unsigned)i /* current position for reading/writing */
|
||||
{
|
||||
[super init];
|
||||
buffer = b;
|
||||
size = s;
|
||||
prefix = p;
|
||||
position = i;
|
||||
eof_position = l;
|
||||
free_when_done = f;
|
||||
type = MALLOC_MEMORY_STREAM;
|
||||
self = [super init];
|
||||
if (self)
|
||||
{
|
||||
if (b)
|
||||
if (f)
|
||||
data = [NSMutableData dataWithBytesNoCopy: b length: s];
|
||||
else
|
||||
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;
|
||||
}
|
||||
|
||||
|
@ -105,9 +130,7 @@ static BOOL debug_memory_stream = NO;
|
|||
prefix: (unsigned)p
|
||||
position: (unsigned)i
|
||||
{
|
||||
char *b;
|
||||
OBJC_MALLOC(b, char, s);
|
||||
return [self _initOnMallocBuffer:b
|
||||
return [self _initOnMallocBuffer: 0
|
||||
freeWhenDone: YES
|
||||
size: s
|
||||
eofPosition: i
|
||||
|
@ -128,6 +151,29 @@ static BOOL debug_memory_stream = NO;
|
|||
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
|
||||
{
|
||||
return [self initWithCapacity:s];
|
||||
|
@ -138,14 +184,9 @@ static BOOL debug_memory_stream = NO;
|
|||
return [self initWithCapacity: DEFAULT_MEMORY_STREAM_SIZE];
|
||||
}
|
||||
|
||||
- (void) setFreeWhenDone: (BOOL)f
|
||||
{
|
||||
free_when_done = f;
|
||||
}
|
||||
|
||||
- (BOOL) isWritable
|
||||
{
|
||||
return YES;
|
||||
return isMutable;
|
||||
}
|
||||
|
||||
- (void) encodeWithCoder: anEncoder
|
||||
|
@ -159,38 +200,54 @@ static BOOL debug_memory_stream = NO;
|
|||
return self;
|
||||
}
|
||||
|
||||
- (id) mutableData
|
||||
{
|
||||
if (isMutable)
|
||||
return data;
|
||||
return nil;
|
||||
}
|
||||
|
||||
- (int) writeBytes: (const void*)b length: (int)l
|
||||
{
|
||||
if (prefix+position+l > size)
|
||||
unsigned size;
|
||||
|
||||
if (isMutable)
|
||||
{
|
||||
size = MAX(prefix+position+l, size*2);
|
||||
buffer = objc_realloc (buffer, size);
|
||||
size = [data capacity];
|
||||
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);
|
||||
position += l;
|
||||
if (position > eof_position)
|
||||
eof_position = position;
|
||||
return l;
|
||||
return 0;
|
||||
}
|
||||
|
||||
- (int) readBytes: (void*)b length: (int)l
|
||||
{
|
||||
if (position+l > eof_position)
|
||||
l = eof_position-position;
|
||||
memcpy(b, buffer+prefix+position, l);
|
||||
memcpy(b, [data bytes]+prefix+position, l);
|
||||
position += l;
|
||||
return l;
|
||||
}
|
||||
|
||||
- (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;
|
||||
if (nl)
|
||||
{
|
||||
int len = nl-buffer-prefix-position;
|
||||
int len = nl-((char*)[data bytes])-prefix-position;
|
||||
ret = objc_malloc (len+1);
|
||||
strncpy(ret, buffer+prefix+position, len);
|
||||
strncpy(ret, ((char*)[data bytes])+prefix+position, len);
|
||||
ret[len] = '\0';
|
||||
position += len+1;
|
||||
}
|
||||
|
@ -206,54 +263,65 @@ static BOOL debug_memory_stream = NO;
|
|||
|
||||
int outchar_func(void *s, int c)
|
||||
{
|
||||
if (MS->prefix + MS->position >= MS->size)
|
||||
return EOF;
|
||||
MS->buffer[MS->prefix + MS->position++] = (char)c;
|
||||
return 1;
|
||||
if (MS->isMutable)
|
||||
{
|
||||
if (MS->prefix + MS->position >= [MS->data capacity])
|
||||
return EOF;
|
||||
((char*)[MS->data mutableBytes])[MS->prefix + MS->position++] = (char)c;
|
||||
return 1;
|
||||
}
|
||||
return EOF;
|
||||
}
|
||||
|
||||
int inchar_func(void *s)
|
||||
{
|
||||
if (MS->prefix + MS->position >= MS->size)
|
||||
if (MS->prefix + MS->position >= [MS->data length])
|
||||
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)
|
||||
{
|
||||
if (MS->position > 0)
|
||||
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
|
||||
- (int) writeFormat: (NSString*)format
|
||||
arguments: (va_list)arg
|
||||
{
|
||||
{
|
||||
unsigned size;
|
||||
int ret;
|
||||
|
||||
if (!isMutable)
|
||||
return 0;
|
||||
/* xxx Using this ugliness we at least let ourselves safely print
|
||||
formatted strings up to 128 bytes long.
|
||||
It's digusting, though, and we need to fix it.
|
||||
Using GNU stdio streams would do the trick.
|
||||
*/
|
||||
size = [data capacity];
|
||||
if (size - (prefix + position) < 128)
|
||||
[self setStreamBufferCapacity: MAX(128, size*2)];
|
||||
|
||||
ret = VSPRINTF_LENGTH (vsprintf(buffer+prefix+position,
|
||||
[format cStringNoCopy], arg));
|
||||
size = MAX(size+128, size*2);
|
||||
[data setLength: size];
|
||||
|
||||
ret = VSPRINTF_LENGTH (vsprintf([data mutableBytes]+prefix+position,
|
||||
[format cStringNoCopy], arg));
|
||||
position += ret;
|
||||
/* xxx Make sure we didn't overrun our buffer.
|
||||
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
|
||||
the num bytes left in the buffer. */
|
||||
assert(prefix + position <= size);
|
||||
assert(prefix + position <= [data capacity]);
|
||||
if (position > eof_position)
|
||||
eof_position = position;
|
||||
[data setLength:eof_position + prefix];
|
||||
if (debug_memory_stream)
|
||||
{
|
||||
*(buffer+prefix+position) = '\0';
|
||||
fprintf(stderr, "%s\n", buffer+prefix);
|
||||
*(char*)([data mutableBytes]+prefix+position) = '\0';
|
||||
fprintf(stderr, "%s\n", (char*)[data mutableBytes]+prefix);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
@ -299,8 +367,7 @@ void unchar_func(void *s, int c)
|
|||
|
||||
- (void) dealloc
|
||||
{
|
||||
if (free_when_done)
|
||||
OBJC_FREE(buffer);
|
||||
[data release];
|
||||
[super dealloc];
|
||||
}
|
||||
|
||||
|
@ -314,21 +381,23 @@ void unchar_func(void *s, int c)
|
|||
|
||||
- (unsigned) streamBufferCapacity
|
||||
{
|
||||
return size;
|
||||
if (isMutable)
|
||||
return [data capacity];
|
||||
return [data length];
|
||||
}
|
||||
|
||||
- (char*) streamBuffer
|
||||
{
|
||||
return buffer;
|
||||
if (isMutable)
|
||||
return (char*)[data mutableBytes];
|
||||
return 0;
|
||||
}
|
||||
|
||||
- (void) setStreamBufferCapacity: (unsigned)s
|
||||
{
|
||||
if (s > prefix + eof_position)
|
||||
{
|
||||
buffer = objc_realloc (buffer, s);
|
||||
size = s;
|
||||
}
|
||||
if (isMutable)
|
||||
if (s > prefix + eof_position)
|
||||
[data setCapacity:s];
|
||||
}
|
||||
|
||||
- (unsigned) streamEofPosition
|
||||
|
@ -338,7 +407,7 @@ void unchar_func(void *s, int c)
|
|||
|
||||
- (void) setStreamEofPosition: (unsigned)i
|
||||
{
|
||||
if (i < size)
|
||||
if (i < [data length] - prefix)
|
||||
eof_position = i;
|
||||
}
|
||||
|
||||
|
|
|
@ -102,7 +102,7 @@ static Class NSMutableAttributedString_concrete_class;
|
|||
return [super initWithCoder:aDecoder];
|
||||
}
|
||||
|
||||
- (Class) classForPortCoder: (NSPortCoder*)aCoder
|
||||
- (Class) classForPortCoder
|
||||
{
|
||||
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];
|
||||
}
|
||||
|
||||
- (Class) classForPortCoder: aRmc
|
||||
- (Class) classForPortCoder
|
||||
{
|
||||
return [self class];
|
||||
}
|
||||
|
|
|
@ -570,12 +570,12 @@ format: @"NSDistantObject objects only encode with PortEncoder class"];
|
|||
argFrame: frame];
|
||||
}
|
||||
|
||||
- classForCoder: (NSCoder*)aCoder;
|
||||
- classForCoder
|
||||
{
|
||||
return object_get_class (self);
|
||||
}
|
||||
|
||||
- classForPortCoder: (NSPortCoder*)aCoder
|
||||
- classForPortCoder
|
||||
{
|
||||
return object_get_class (self);
|
||||
}
|
||||
|
@ -612,15 +612,18 @@ format: @"NSDistantObject objects only encode with PortEncoder class"];
|
|||
|
||||
@implementation Protocol (DistributedObjectsCoding)
|
||||
|
||||
- (Class) classForPortCoder: (NSPortCoder*)aRmc;
|
||||
- (Class) classForPortCoder
|
||||
{
|
||||
return [NSDistantObject class];
|
||||
return [self classForCoder];
|
||||
}
|
||||
|
||||
- replacementObjectForPortCoder: (NSPortCoder*)aRmc;
|
||||
{
|
||||
return [NSDistantObject proxyWithLocal: self
|
||||
connection: [aRmc connection]];
|
||||
if ([aRmc isBycopy])
|
||||
return self;
|
||||
else
|
||||
return [NSDistantObject proxyWithLocal: self
|
||||
connection: [aRmc connection]];
|
||||
}
|
||||
|
||||
@end
|
||||
|
|
|
@ -27,6 +27,7 @@
|
|||
#include <gnustep/base/CStream.h>
|
||||
#include <gnustep/base/behavior.h>
|
||||
#include <gnustep/base/CoderPrivate.h>
|
||||
#include <gnustep/base/MemoryStream.h>
|
||||
#include <Foundation/NSException.h>
|
||||
|
||||
#define USE_OPENSTEP_STYLE_FORWARD_REFERENCES 1
|
||||
|
@ -200,20 +201,19 @@
|
|||
return "NSGUnarchiver";
|
||||
}
|
||||
|
||||
/* if anyone asks for an archivers data we assume that they have finished
|
||||
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
|
||||
/* Attempting to use the archiver after this will
|
||||
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. */
|
||||
- (NSMutableData*) archiverData
|
||||
{
|
||||
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 nil;
|
||||
|
|
|
@ -139,7 +139,7 @@ NSDictionary *_attributesAtIndexEffectiveRange(
|
|||
return nil;
|
||||
}
|
||||
|
||||
- (Class) classForPortCoder: (NSPortCoder*)aCoder
|
||||
- (Class) classForPortCoder
|
||||
{
|
||||
return [self class];
|
||||
}
|
||||
|
@ -203,7 +203,7 @@ NSDictionary *_attributesAtIndexEffectiveRange(
|
|||
|
||||
@implementation NSGMutableAttributedString
|
||||
|
||||
- (Class) classForPortCoder: (NSPortCoder*)aCoder
|
||||
- (Class) classForPortCoder
|
||||
{
|
||||
return [self class];
|
||||
}
|
||||
|
|
|
@ -83,7 +83,7 @@
|
|||
return [self class];
|
||||
}
|
||||
|
||||
- (Class) classForPortCoder: (NSPortCoder*)aCoder
|
||||
- (Class) classForPortCoder
|
||||
{
|
||||
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];
|
||||
}
|
||||
|
||||
- (Class) classForPortCoder: (NSPortCoder*)aCoder
|
||||
- (Class) classForPortCoder
|
||||
{
|
||||
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;
|
||||
}
|
||||
|
||||
- (BOOL) isByCopy
|
||||
- (BOOL) isBycopy
|
||||
{
|
||||
return _is_by_copy;
|
||||
}
|
||||
|
@ -172,12 +172,12 @@ static BOOL debug_connected_coder = NO;
|
|||
{
|
||||
BOOL old = _is_by_copy;
|
||||
id obj;
|
||||
Class cls;
|
||||
|
||||
_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];
|
||||
cls = [obj classForPortCoder];
|
||||
[self encodeClass: cls];
|
||||
[obj encodeWithCoder: (NSCoder*)self];
|
||||
_is_by_copy = old;
|
||||
}
|
||||
|
@ -188,7 +188,7 @@ static BOOL debug_connected_coder = NO;
|
|||
id obj;
|
||||
|
||||
_is_by_copy = YES;
|
||||
obj = [anObj classForPortCoder: (NSPortCoder*)self];
|
||||
obj = [anObj classForPortCoder];
|
||||
[self encodeClass: obj];
|
||||
obj = [anObj replacementObjectForPortCoder: (NSPortCoder*)self];
|
||||
[obj encodeWithCoder: (NSCoder*)self];
|
||||
|
@ -422,7 +422,7 @@ static BOOL debug_connected_coder = NO;
|
|||
return 0;
|
||||
}
|
||||
|
||||
- (BOOL) isByCopy
|
||||
- (BOOL) isBycopy
|
||||
{
|
||||
[self subclassResponsibility:_cmd];
|
||||
return NO;
|
||||
|
@ -446,12 +446,9 @@ static BOOL debug_connected_coder = NO;
|
|||
@implementation NSObject (NSPortCoder)
|
||||
|
||||
/* By default, Object's encode themselves as proxies across Connection's */
|
||||
- (Class) classForPortCoder: (NSPortCoder*)aRmc
|
||||
- (Class) classForPortCoder
|
||||
{
|
||||
if ([aRmc isByCopy]) {
|
||||
return [self class];
|
||||
}
|
||||
return [[aRmc connection] proxyClass];
|
||||
return [self classForCoder];
|
||||
}
|
||||
|
||||
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
|
||||
{
|
||||
if ([aRmc isByCopy]) {
|
||||
if ([aRmc isBycopy]) {
|
||||
return self;
|
||||
}
|
||||
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
|
||||
* the DO system to use the super class instead.
|
||||
*/
|
||||
- (Class)classForPortCoder: (NSPortCoder*)aCoder
|
||||
- (Class)classForPortCoder
|
||||
{
|
||||
return [self superclass];
|
||||
}
|
||||
|
|
|
@ -69,7 +69,7 @@
|
|||
return [self class];
|
||||
}
|
||||
|
||||
- (Class) classForPortCoder: aRmc
|
||||
- (Class) classForPortCoder
|
||||
{
|
||||
return [self class];
|
||||
}
|
||||
|
|
|
@ -115,7 +115,8 @@ o_vscanf (void *stream,
|
|||
{
|
||||
id message;
|
||||
|
||||
message = [NSString stringWithFormat: @"Stream: %s", strerror(errno)];
|
||||
message = [[NSString alloc] initWithFormat: @"Stream: %s",
|
||||
strerror(errno)];
|
||||
NSLog(message);
|
||||
[message release];
|
||||
[super dealloc];
|
||||
|
@ -131,7 +132,8 @@ o_vscanf (void *stream,
|
|||
{
|
||||
id message;
|
||||
|
||||
message = [NSString stringWithFormat: @"Stream: %s", strerror(errno)];
|
||||
message = [[NSString alloc] initWithFormat: @"Stream: %s",
|
||||
strerror(errno)];
|
||||
NSLog(message);
|
||||
[message release];
|
||||
[super dealloc];
|
||||
|
@ -243,6 +245,7 @@ stdio_unchar_func(void *s, int c)
|
|||
- (void) close
|
||||
{
|
||||
fclose(fp);
|
||||
fp = 0;
|
||||
}
|
||||
|
||||
- (BOOL) isClosed
|
||||
|
|
|
@ -40,6 +40,7 @@
|
|||
#include <gnustep/base/NSException.h>
|
||||
#include <Foundation/NSRunLoop.h>
|
||||
#include <gnustep/base/Invocation.h>
|
||||
#include <Foundation/NSData.h>
|
||||
#include <Foundation/NSDate.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
@ -1238,7 +1239,7 @@ assert(type == ET_RPORT);
|
|||
return [TcpOutPort class];
|
||||
}
|
||||
|
||||
- (Class) classForPortCoder: aRmc
|
||||
- (Class) classForPortCoder
|
||||
{
|
||||
return [TcpOutPort class];
|
||||
}
|
||||
|
@ -1686,7 +1687,7 @@ static NSMapTable *out_port_bag = NULL;
|
|||
[super dealloc];
|
||||
}
|
||||
|
||||
- classForPortCoder: aRmc
|
||||
- classForPortCoder
|
||||
{
|
||||
/* Make sure that Connection's always send us bycopy,
|
||||
i.e. as our own class, not a Proxy class. */
|
||||
|
@ -1840,15 +1841,15 @@ static NSMapTable *out_port_bag = NULL;
|
|||
int c;
|
||||
int remaining;
|
||||
|
||||
remaining = size - eof_position;
|
||||
remaining = [data length] - prefix - eof_position;
|
||||
#ifdef GDOMAP
|
||||
c = tryRead(s, 1, buffer + prefix + eof_position, -remaining);
|
||||
c = tryRead(s, 1, [data mutableBytes] + prefix + eof_position, -remaining);
|
||||
#else
|
||||
/* xxx We need to make sure this read() is non-blocking. */
|
||||
#ifdef __WIN32__
|
||||
c = recv (s, buffer + prefix + eof_position, remaining, 0);
|
||||
c = recv (s, [data mutableBytes] + prefix + eof_position, remaining, 0);
|
||||
#else
|
||||
c = read (s, buffer + prefix + eof_position, remaining);
|
||||
c = read (s, [data mutableBytes] + prefix + eof_position, remaining);
|
||||
#endif /* __WIN32 */
|
||||
#endif /* GDOMAP */
|
||||
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. */
|
||||
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
|
||||
region. If there is no reply address specified, fill it with zeros. */
|
||||
if (addr)
|
||||
/* Do this memcpy instead of simply casting the pointer because
|
||||
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
|
||||
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. */
|
||||
#ifdef GDOMAP
|
||||
c = tryWrite (s, (int)timeout, buffer, prefix + eof_position);
|
||||
c = tryWrite (s, (int)timeout, [data bytes], prefix + eof_position);
|
||||
#else
|
||||
#ifdef __WIN32__
|
||||
c = send (s, buffer, prefix + eof_position, 0);
|
||||
c = send (s, [data bytes], prefix + eof_position, 0);
|
||||
#else
|
||||
c = write (s, buffer, prefix + eof_position);
|
||||
c = write (s, [data bytes], prefix + eof_position);
|
||||
#endif /* __WIN32__ */
|
||||
#endif /* GDOMAP */
|
||||
if (c == -2) {
|
||||
|
|
|
@ -291,7 +291,7 @@ static NSMapTable *port_number_2_in_port = NULL;
|
|||
return [UdpOutPort class];
|
||||
}
|
||||
|
||||
- (Class) classForPortCoder: aRmc
|
||||
- (Class) classForPortCoder
|
||||
{
|
||||
return [UdpOutPort class];
|
||||
}
|
||||
|
|
|
@ -69,7 +69,7 @@ getAddr(NSString* name, NSString* svc, NSString* pcl, struct sockaddr_in *sin)
|
|||
struct servent* sp;
|
||||
|
||||
if (svc == nil)
|
||||
return NO;
|
||||
svc = @"localhost";
|
||||
|
||||
if (pcl)
|
||||
proto = [pcl cStringNoCopy];
|
||||
|
@ -174,21 +174,17 @@ getAddr(NSString* name, NSString* svc, NSString* pcl, struct sockaddr_in *sin)
|
|||
int net;
|
||||
struct sockaddr_in sin;
|
||||
|
||||
if (address == nil)
|
||||
{
|
||||
[self release];
|
||||
return nil;
|
||||
}
|
||||
|
||||
if (getAddr(address, service, protocol, &sin) == NO)
|
||||
{
|
||||
[self release];
|
||||
[self dealloc];
|
||||
NSLog(@"bad address-service-protocol combination");
|
||||
return nil;
|
||||
}
|
||||
|
||||
if ((net = socket(AF_INET, SOCK_STREAM, PF_UNSPEC)) < 0)
|
||||
{
|
||||
[self release];
|
||||
[self dealloc];
|
||||
NSLog(@"unable to create socket - %s", strerror(errno));
|
||||
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 (errno != EINPROGRESS)
|
||||
{
|
||||
[self release];
|
||||
[self dealloc];
|
||||
NSLog(@"unable to make connection - %s", strerror(errno));
|
||||
return nil;
|
||||
}
|
||||
|
||||
|
@ -214,10 +211,10 @@ getAddr(NSString* name, NSString* svc, NSString* pcl, struct sockaddr_in *sin)
|
|||
[writeInfo addObject:info];
|
||||
[info release];
|
||||
[self watchWriteDescriptor];
|
||||
connectOK = YES;
|
||||
readOK = NO;
|
||||
writeOK = NO;
|
||||
}
|
||||
connectOK = YES;
|
||||
readOK = NO;
|
||||
writeOK = NO;
|
||||
return self;
|
||||
}
|
||||
|
||||
|
@ -231,13 +228,15 @@ getAddr(NSString* name, NSString* svc, NSString* pcl, struct sockaddr_in *sin)
|
|||
|
||||
if (getAddr(address, service, protocol, &sin) == NO)
|
||||
{
|
||||
[self release];
|
||||
return nil;
|
||||
[self dealloc];
|
||||
NSLog(@"bad address-service-protocol combination");
|
||||
return nil;
|
||||
}
|
||||
|
||||
if ((net = socket(AF_INET, SOCK_STREAM, PF_UNSPEC)) < 0)
|
||||
{
|
||||
[self release];
|
||||
[self dealloc];
|
||||
NSLog(@"unable to create socket - %s", strerror(errno));
|
||||
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)
|
||||
{
|
||||
(void) close(net);
|
||||
[self release];
|
||||
[self dealloc];
|
||||
NSLog(@"unable to bind to port - %s", strerror(errno));
|
||||
return nil;
|
||||
}
|
||||
|
||||
if (listen(net, 5) < 0)
|
||||
{
|
||||
(void) close(net);
|
||||
[self release];
|
||||
[self dealloc];
|
||||
NSLog(@"unable to listen on port - %s", strerror(errno));
|
||||
return nil;
|
||||
}
|
||||
|
||||
self = [self initWithFileDescriptor:net closeOnDealloc:YES];
|
||||
acceptOK = YES;
|
||||
readOK = NO;
|
||||
writeOK = NO;
|
||||
if (self)
|
||||
{
|
||||
acceptOK = YES;
|
||||
readOK = NO;
|
||||
writeOK = NO;
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
|
@ -270,13 +274,14 @@ getAddr(NSString* name, NSString* svc, NSString* pcl, struct sockaddr_in *sin)
|
|||
|
||||
if (d < 0)
|
||||
{
|
||||
[self release];
|
||||
[self dealloc];
|
||||
return nil;
|
||||
}
|
||||
else
|
||||
{
|
||||
self = [self initWithFileDescriptor:d closeOnDealloc:YES];
|
||||
writeOK = NO;
|
||||
if (self)
|
||||
writeOK = NO;
|
||||
return self;
|
||||
}
|
||||
}
|
||||
|
@ -287,13 +292,14 @@ getAddr(NSString* name, NSString* svc, NSString* pcl, struct sockaddr_in *sin)
|
|||
|
||||
if (d < 0)
|
||||
{
|
||||
[self release];
|
||||
[self dealloc];
|
||||
return nil;
|
||||
}
|
||||
else
|
||||
{
|
||||
self = [self initWithFileDescriptor:d closeOnDealloc:YES];
|
||||
readOK = NO;
|
||||
if (self)
|
||||
readOK = NO;
|
||||
return self;
|
||||
}
|
||||
}
|
||||
|
@ -304,7 +310,7 @@ getAddr(NSString* name, NSString* svc, NSString* pcl, struct sockaddr_in *sin)
|
|||
|
||||
if (d < 0)
|
||||
{
|
||||
[self release];
|
||||
[self dealloc];
|
||||
return nil;
|
||||
}
|
||||
else
|
||||
|
@ -318,7 +324,7 @@ getAddr(NSString* name, NSString* svc, NSString* pcl, struct sockaddr_in *sin)
|
|||
if (fh_stderr)
|
||||
{
|
||||
[fh_stderr retain];
|
||||
[self release];
|
||||
[self dealloc];
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -326,8 +332,8 @@ getAddr(NSString* name, NSString* svc, NSString* pcl, struct sockaddr_in *sin)
|
|||
fh_stderr = self;
|
||||
}
|
||||
self = fh_stderr;
|
||||
readOK = NO;
|
||||
return self;
|
||||
if (self)
|
||||
readOK = NO;
|
||||
return self;
|
||||
}
|
||||
|
||||
|
@ -336,7 +342,7 @@ getAddr(NSString* name, NSString* svc, NSString* pcl, struct sockaddr_in *sin)
|
|||
if (fh_stdin)
|
||||
{
|
||||
[fh_stdin retain];
|
||||
[self release];
|
||||
[self dealloc];
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -344,7 +350,8 @@ getAddr(NSString* name, NSString* svc, NSString* pcl, struct sockaddr_in *sin)
|
|||
fh_stdin = self;
|
||||
}
|
||||
self = fh_stdin;
|
||||
writeOK = NO;
|
||||
if (self)
|
||||
writeOK = NO;
|
||||
return self;
|
||||
}
|
||||
|
||||
|
@ -353,7 +360,7 @@ getAddr(NSString* name, NSString* svc, NSString* pcl, struct sockaddr_in *sin)
|
|||
if (fh_stdout)
|
||||
{
|
||||
[fh_stdout retain];
|
||||
[self release];
|
||||
[self dealloc];
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -361,7 +368,8 @@ getAddr(NSString* name, NSString* svc, NSString* pcl, struct sockaddr_in *sin)
|
|||
fh_stdout = self;
|
||||
}
|
||||
self = fh_stdout;
|
||||
readOK = NO;
|
||||
if (self)
|
||||
readOK = NO;
|
||||
return self;
|
||||
}
|
||||
|
||||
|
@ -384,9 +392,11 @@ getAddr(NSString* name, NSString* svc, NSString* pcl, struct sockaddr_in *sin)
|
|||
int e;
|
||||
|
||||
if (fstat(desc, &sbuf) < 0)
|
||||
[NSException raise: NSFileHandleOperationException
|
||||
format: @"unable to get status of descriptor - %s",
|
||||
strerror(errno)];
|
||||
{
|
||||
[self dealloc];
|
||||
NSLog(@"unable to get status of descriptor - %s", strerror(errno));
|
||||
return nil;
|
||||
}
|
||||
if (S_ISREG(sbuf.st_mode))
|
||||
isStandardFile = YES;
|
||||
else
|
||||
|
@ -732,12 +742,9 @@ getAddr(NSString* name, NSString* svc, NSString* pcl, struct sockaddr_in *sin)
|
|||
|
||||
- (void)closeFile
|
||||
{
|
||||
NSNotification* n;
|
||||
|
||||
/* Ensure that any notifications we queued are destroyed with us. */
|
||||
n = [NSNotification notificationWithName:@"any" object:self userInfo:nil];
|
||||
[[NSNotificationQueue defaultQueue] dequeueNotificationsMatching:n
|
||||
coalesceMask:NSNotificationCoalescingOnSender];
|
||||
if (descriptor < 0)
|
||||
[NSException raise: NSFileHandleOperationException
|
||||
format: @"attempt to close closed file"];
|
||||
|
||||
[self ignoreReadDescriptor];
|
||||
[self ignoreWriteDescriptor];
|
||||
|
@ -851,12 +858,15 @@ getAddr(NSString* name, NSString* svc, NSString* pcl, struct sockaddr_in *sin)
|
|||
|
||||
- (void)ignoreReadDescriptor
|
||||
{
|
||||
NSRunLoop* l = [NSRunLoop currentRunLoop];
|
||||
NSArray* modes = nil;
|
||||
NSRunLoop *l;
|
||||
NSArray *modes;
|
||||
|
||||
if (descriptor < 0)
|
||||
return;
|
||||
|
||||
l = [NSRunLoop currentRunLoop];
|
||||
modes = nil;
|
||||
|
||||
if (readInfo)
|
||||
modes = (NSArray*)[readInfo objectForKey:NSFileHandleNotificationMonitorModes];
|
||||
|
||||
|
@ -881,12 +891,15 @@ getAddr(NSString* name, NSString* svc, NSString* pcl, struct sockaddr_in *sin)
|
|||
|
||||
- (void)ignoreWriteDescriptor
|
||||
{
|
||||
NSRunLoop* l = [NSRunLoop currentRunLoop];
|
||||
NSArray* modes = nil;
|
||||
NSRunLoop *l;
|
||||
NSArray *modes;
|
||||
|
||||
if (descriptor < 0)
|
||||
return;
|
||||
|
||||
l = [NSRunLoop currentRunLoop];
|
||||
modes = nil;
|
||||
|
||||
if ([writeInfo count] > 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;
|
||||
{
|
||||
NSRunLoop* l;
|
||||
NSRunLoop *l;
|
||||
|
||||
if (descriptor < 0)
|
||||
return;
|
||||
|
@ -986,7 +999,7 @@ getAddr(NSString* name, NSString* svc, NSString* pcl, struct sockaddr_in *sin)
|
|||
extra: (void*)extra
|
||||
forMode: (NSString*)mode
|
||||
{
|
||||
NSString* operation;
|
||||
NSString *operation;
|
||||
|
||||
if (type == ET_RDESC) {
|
||||
operation = [readInfo objectForKey:NotificationKey];
|
||||
|
@ -1115,13 +1128,12 @@ getAddr(NSString* name, NSString* svc, NSString* pcl, struct sockaddr_in *sin)
|
|||
e &= ~NBLK_OPT;
|
||||
|
||||
if (fcntl(descriptor, F_SETFL, e) < 0)
|
||||
[NSException raise: NSFileHandleOperationException
|
||||
format: @"could not change non-blocking mode"];
|
||||
isNonBlocking = flag;
|
||||
NSLog(@"unable to set non-blocking mode - %s", strerror(errno));
|
||||
else
|
||||
isNonBlocking = flag;
|
||||
}
|
||||
else
|
||||
[NSException raise: NSFileHandleOperationException
|
||||
format: @"could not change non-blocking mode"];
|
||||
NSLog(@"unable to get non-blocking mode - %s", strerror(errno));
|
||||
}
|
||||
|
||||
@end
|
||||
|
|
|
@ -1,11 +1,14 @@
|
|||
#include <Foundation/NSData.h>
|
||||
#include <Foundation/NSArchiver.h>
|
||||
#include <Foundation/NSAutoreleasePool.h>
|
||||
#include <Foundation/NSString.h>
|
||||
|
||||
int
|
||||
main()
|
||||
{
|
||||
id a;
|
||||
id d;
|
||||
id o;
|
||||
id pool;
|
||||
|
||||
pool = [[NSAutoreleasePool alloc] init];
|
||||
|
@ -14,7 +17,76 @@ main()
|
|||
if (d == nil)
|
||||
printf("Unable to map file");
|
||||
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];
|
||||
|
||||
exit(0);
|
||||
}
|
||||
|
||||
|
|
|
@ -5,10 +5,10 @@
|
|||
#include <gnustep/base/Connection.h>
|
||||
#include <gnustep/base/Array.h>
|
||||
|
||||
typedef struct _small_struct {
|
||||
typedef struct _small_struct {
|
||||
unsigned char z;
|
||||
} small_struct;
|
||||
|
||||
|
||||
typedef struct _foo {
|
||||
int i;
|
||||
char *s;
|
||||
|
|
Loading…
Reference in a new issue