Tidy use of sized datatypes. Check for invalid asumption of interchangability

of int/long in encoder/decoder methods.


git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@22291 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
CaS 2006-01-11 08:37:16 +00:00
parent 7d11eb6607
commit bb1ce663a4
19 changed files with 283 additions and 285 deletions

View file

@ -1,3 +1,27 @@
2006-01-11 Richard Frith-Macdonald <rfm@gnu.org>
* Headers/Additions/GNUstepBase/GSUnion.h:
* Headers/Foundation/NSByteOrder.h:
* Headers/Foundation/NSPort.h:
* Source/GSFileHandle.m:
* Source/GSFormat.m:
* Source/NSData.m:
* Source/NSDistantObject.m:
* Source/NSMessagePort.m:
* Source/NSPortCoder.m:
* Source/NSSerializer.m:
* Source/NSSocketPort.m:
* Source/NSSocketPortNameServer.m:
* Source/NSString.m:
* Source/NSTimeZone.m:
* Source/NSUnarchiver.m:
* Source/win32/GSFileHandleWin32.m:
* Source/win32/NSMessagePortWin32.m:
Update to use sized datatypes from stdint.h now that almost all
operating systems support it. Changes not complete yet though.
* Source/NSCalendarDate.m:
Support '%T' and '%t' as supplied by unix date/time locale info.
2006-01-10 Richard Frith-Macdonald <rfm@gnu.org> 2006-01-10 Richard Frith-Macdonald <rfm@gnu.org>
* Source/mframe.m: * Source/mframe.m:

View file

@ -90,20 +90,20 @@ typedef union {
const char *cstr; const char *cstr;
#endif #endif
#if ((GSUNION_TYPES) & GSUNION_8B) #if ((GSUNION_TYPES) & GSUNION_8B)
gss8 s8; int8_t s8;
gsu8 u8; uint8_t u8;
#endif #endif
#if ((GSUNION_TYPES) & GSUNION_16B) #if ((GSUNION_TYPES) & GSUNION_16B)
gss16 s16; int16_t s16;
gsu16 u16; uint16_t u16;
#endif #endif
#if ((GSUNION_TYPES) & GSUNION_32B) #if ((GSUNION_TYPES) & GSUNION_32B)
gss32 s32; int32_t s32;
gsu32 u32; uint32_t u32;
#endif #endif
#if ((GSUNION_TYPES) & GSUNION_64B) #if ((GSUNION_TYPES) & GSUNION_64B)
gss64 s64; int64_t s64;
gsu64 u64; uint64_t u64;
#endif #endif
#if defined(GSUNION_EXTRA) #if defined(GSUNION_EXTRA)
GSUNION_EXTRA ext; GSUNION_EXTRA ext;

View file

@ -29,8 +29,8 @@
/* /*
* OPENSTEP type definitions for Byte ordering. * OPENSTEP type definitions for Byte ordering.
*/ */
typedef gsu32 NSSwappedFloat; typedef uint32_t NSSwappedFloat;
typedef gsu64 NSSwappedDouble; typedef uint64_t NSSwappedDouble;
typedef enum { typedef enum {
NS_UnknownByteOrder, NS_UnknownByteOrder,
@ -49,48 +49,48 @@ typedef enum {
/* /*
* First the GNUstep functions for byte swapping * First the GNUstep functions for byte swapping
*/ */
static inline gsu16 static inline uint16_t
GSSwapI16(gsu16 in) __attribute__((unused)); GSSwapI16(uint16_t in) __attribute__((unused));
static inline gsu32 static inline uint32_t
GSSwapI32(gsu32 in) __attribute__((unused)); GSSwapI32(uint32_t in) __attribute__((unused));
static inline gsu64 static inline uint64_t
GSSwapI64(gsu64 in) __attribute__((unused)); GSSwapI64(uint64_t in) __attribute__((unused));
static inline gsu128 static inline gsu128
GSSwapI128(gsu128 in) __attribute__((unused)); GSSwapI128(gsu128 in) __attribute__((unused));
static inline gsu16 static inline uint16_t
GSSwapBigI16ToHost(gsu16 in) __attribute__((unused)); GSSwapBigI16ToHost(uint16_t in) __attribute__((unused));
static inline gsu32 static inline uint32_t
GSSwapBigI32ToHost(gsu32 in) __attribute__((unused)); GSSwapBigI32ToHost(uint32_t in) __attribute__((unused));
static inline gsu64 static inline uint64_t
GSSwapBigI64ToHost(gsu64 in) __attribute__((unused)); GSSwapBigI64ToHost(uint64_t in) __attribute__((unused));
static inline gsu128 static inline gsu128
GSSwapBigI128ToHost(gsu128 in) __attribute__((unused)); GSSwapBigI128ToHost(gsu128 in) __attribute__((unused));
static inline gsu16 static inline uint16_t
GSSwapHostI16ToBig(gsu16 in) __attribute__((unused)); GSSwapHostI16ToBig(uint16_t in) __attribute__((unused));
static inline gsu32 static inline uint32_t
GSSwapHostI32ToBig(gsu32 in) __attribute__((unused)); GSSwapHostI32ToBig(uint32_t in) __attribute__((unused));
static inline gsu64 static inline uint64_t
GSSwapHostI64ToBig(gsu64 in) __attribute__((unused)); GSSwapHostI64ToBig(uint64_t in) __attribute__((unused));
static inline gsu128 static inline gsu128
GSSwapHostI128ToBig(gsu128 in) __attribute__((unused)); GSSwapHostI128ToBig(gsu128 in) __attribute__((unused));
static inline gsu16 static inline uint16_t
GSSwapLittleI16ToHost(gsu16 in) __attribute__((unused)); GSSwapLittleI16ToHost(uint16_t in) __attribute__((unused));
static inline gsu32 static inline uint32_t
GSSwapLittleI32ToHost(gsu32 in) __attribute__((unused)); GSSwapLittleI32ToHost(uint32_t in) __attribute__((unused));
static inline gsu64 static inline uint64_t
GSSwapLittleI64ToHost(gsu64 in) __attribute__((unused)); GSSwapLittleI64ToHost(uint64_t in) __attribute__((unused));
static inline gsu128 static inline gsu128
GSSwapLittleI128ToHost(gsu128 in) __attribute__((unused)); GSSwapLittleI128ToHost(gsu128 in) __attribute__((unused));
static inline gsu16 static inline uint16_t
GSSwapHostI16ToLittle(gsu16 in) __attribute__((unused)); GSSwapHostI16ToLittle(uint16_t in) __attribute__((unused));
static inline gsu32 static inline uint32_t
GSSwapHostI32ToLittle(gsu32 in) __attribute__((unused)); GSSwapHostI32ToLittle(uint32_t in) __attribute__((unused));
static inline gsu64 static inline uint64_t
GSSwapHostI64ToLittle(gsu64 in) __attribute__((unused)); GSSwapHostI64ToLittle(uint64_t in) __attribute__((unused));
static inline gsu128 static inline gsu128
GSSwapHostI128ToLittle(gsu128 in) __attribute__((unused)); GSSwapHostI128ToLittle(gsu128 in) __attribute__((unused));
@ -101,12 +101,12 @@ GSSwapHostI128ToLittle(gsu128 in) __attribute__((unused));
extern void _gcc3_1_hack(void); extern void _gcc3_1_hack(void);
#endif #endif
static inline gsu16 static inline uint16_t
GSSwapI16(gsu16 in) GSSwapI16(uint16_t in)
{ {
union swap { union swap {
gsu16 num; uint16_t num;
gsu8 byt[2]; uint8_t byt[2];
} dst; } dst;
union swap *src = (union swap*)&in; union swap *src = (union swap*)&in;
#if (__GNUC__ == 3) && (__GNUC_MINOR__ == 1) #if (__GNUC__ == 3) && (__GNUC_MINOR__ == 1)
@ -117,12 +117,12 @@ GSSwapI16(gsu16 in)
return dst.num; return dst.num;
} }
static inline gsu32 static inline uint32_t
GSSwapI32(gsu32 in) GSSwapI32(uint32_t in)
{ {
union swap { union swap {
gsu32 num; uint32_t num;
gsu8 byt[4]; uint8_t byt[4];
} dst; } dst;
union swap *src = (union swap*)&in; union swap *src = (union swap*)&in;
#if (__GNUC__ == 3) && (__GNUC_MINOR__ == 1) #if (__GNUC__ == 3) && (__GNUC_MINOR__ == 1)
@ -135,12 +135,12 @@ GSSwapI32(gsu32 in)
return dst.num; return dst.num;
} }
static inline gsu64 static inline uint64_t
GSSwapI64(gsu64 in) GSSwapI64(uint64_t in)
{ {
union swap { union swap {
gsu64 num; uint64_t num;
gsu8 byt[8]; uint8_t byt[8];
} dst; } dst;
union swap *src = (union swap*)&in; union swap *src = (union swap*)&in;
#if (__GNUC__ == 3) && (__GNUC_MINOR__ == 1) #if (__GNUC__ == 3) && (__GNUC_MINOR__ == 1)
@ -162,7 +162,7 @@ GSSwapI128(gsu128 in)
{ {
union swap { union swap {
gsu128 num; gsu128 num;
gsu8 byt[16]; uint8_t byt[16];
} dst; } dst;
union swap *src = (union swap*)&in; union swap *src = (union swap*)&in;
#if (__GNUC__ == 3) && (__GNUC_MINOR__ == 1) #if (__GNUC__ == 3) && (__GNUC_MINOR__ == 1)
@ -399,18 +399,18 @@ NSHostByteOrder(void)
/* /*
* Swap Big endian to host * Swap Big endian to host
*/ */
static inline gsu16 static inline uint16_t
GSSwapBigI16ToHost(gsu16 in) GSSwapBigI16ToHost(uint16_t in)
{ {
return in; return in;
} }
static inline gsu32 static inline uint32_t
GSSwapBigI32ToHost(gsu32 in) GSSwapBigI32ToHost(uint32_t in)
{ {
return in; return in;
} }
static inline gsu64 static inline uint64_t
GSSwapBigI64ToHost(gsu64 in) GSSwapBigI64ToHost(uint64_t in)
{ {
return in; return in;
} }
@ -459,18 +459,18 @@ NSSwapBigShortToHost(unsigned short num)
/* /*
* Swap Host to Big endian * Swap Host to Big endian
*/ */
static inline gsu16 static inline uint16_t
GSSwapHostI16ToBig(gsu16 in) GSSwapHostI16ToBig(uint16_t in)
{ {
return in; return in;
} }
static inline gsu32 static inline uint32_t
GSSwapHostI32ToBig(gsu32 in) GSSwapHostI32ToBig(uint32_t in)
{ {
return in; return in;
} }
static inline gsu64 static inline uint64_t
GSSwapHostI64ToBig(gsu64 in) GSSwapHostI64ToBig(uint64_t in)
{ {
return in; return in;
} }
@ -519,18 +519,18 @@ NSSwapHostShortToBig(unsigned short num)
/* /*
* Swap Little endian to Host * Swap Little endian to Host
*/ */
static inline gsu16 static inline uint16_t
GSSwapLittleI16ToHost(gsu16 in) GSSwapLittleI16ToHost(uint16_t in)
{ {
return GSSwapI16(in); return GSSwapI16(in);
} }
static inline gsu32 static inline uint32_t
GSSwapLittleI32ToHost(gsu32 in) GSSwapLittleI32ToHost(uint32_t in)
{ {
return GSSwapI32(in); return GSSwapI32(in);
} }
static inline gsu64 static inline uint64_t
GSSwapLittleI64ToHost(gsu64 in) GSSwapLittleI64ToHost(uint64_t in)
{ {
return GSSwapI64(in); return GSSwapI64(in);
} }
@ -579,18 +579,18 @@ NSSwapLittleShortToHost(unsigned short num)
/* /*
* Swap Host to Little endian * Swap Host to Little endian
*/ */
static inline gsu16 static inline uint16_t
GSSwapHostI16ToLittle(gsu16 in) GSSwapHostI16ToLittle(uint16_t in)
{ {
return GSSwapI16(in); return GSSwapI16(in);
} }
static inline gsu32 static inline uint32_t
GSSwapHostI32ToLittle(gsu32 in) GSSwapHostI32ToLittle(uint32_t in)
{ {
return GSSwapI32(in); return GSSwapI32(in);
} }
static inline gsu64 static inline uint64_t
GSSwapHostI64ToLittle(gsu64 in) GSSwapHostI64ToLittle(uint64_t in)
{ {
return GSSwapI64(in); return GSSwapI64(in);
} }
@ -649,18 +649,18 @@ NSHostByteOrder(void)
/* /*
* Swap Big endian to host * Swap Big endian to host
*/ */
static inline gsu16 static inline uint16_t
GSSwapBigI16ToHost(gsu16 in) GSSwapBigI16ToHost(uint16_t in)
{ {
return GSSwapI16(in); return GSSwapI16(in);
} }
static inline gsu32 static inline uint32_t
GSSwapBigI32ToHost(gsu32 in) GSSwapBigI32ToHost(uint32_t in)
{ {
return GSSwapI32(in); return GSSwapI32(in);
} }
static inline gsu64 static inline uint64_t
GSSwapBigI64ToHost(gsu64 in) GSSwapBigI64ToHost(uint64_t in)
{ {
return GSSwapI64(in); return GSSwapI64(in);
} }
@ -708,18 +708,18 @@ NSSwapBigShortToHost(unsigned short num)
/* /*
* Swap Host to Big endian * Swap Host to Big endian
*/ */
static inline gsu16 static inline uint16_t
GSSwapHostI16ToBig(gsu16 in) GSSwapHostI16ToBig(uint16_t in)
{ {
return GSSwapI16(in); return GSSwapI16(in);
} }
static inline gsu32 static inline uint32_t
GSSwapHostI32ToBig(gsu32 in) GSSwapHostI32ToBig(uint32_t in)
{ {
return GSSwapI32(in); return GSSwapI32(in);
} }
static inline gsu64 static inline uint64_t
GSSwapHostI64ToBig(gsu64 in) GSSwapHostI64ToBig(uint64_t in)
{ {
return GSSwapI64(in); return GSSwapI64(in);
} }
@ -767,18 +767,18 @@ NSSwapHostShortToBig(unsigned short num)
/* /*
* Swap Little endian to Host * Swap Little endian to Host
*/ */
static inline gsu16 static inline uint16_t
GSSwapLittleI16ToHost(gsu16 in) GSSwapLittleI16ToHost(uint16_t in)
{ {
return in; return in;
} }
static inline gsu32 static inline uint32_t
GSSwapLittleI32ToHost(gsu32 in) GSSwapLittleI32ToHost(uint32_t in)
{ {
return in; return in;
} }
static inline gsu64 static inline uint64_t
GSSwapLittleI64ToHost(gsu64 in) GSSwapLittleI64ToHost(uint64_t in)
{ {
return in; return in;
} }
@ -827,18 +827,18 @@ NSSwapLittleShortToHost(unsigned short num)
/* /*
* Swap Host to Little endian * Swap Host to Little endian
*/ */
static inline gsu16 static inline uint16_t
GSSwapHostI16ToLittle(gsu16 in) GSSwapHostI16ToLittle(uint16_t in)
{ {
return in; return in;
} }
static inline gsu32 static inline uint32_t
GSSwapHostI32ToLittle(gsu32 in) GSSwapHostI32ToLittle(uint32_t in)
{ {
return in; return in;
} }
static inline gsu64 static inline uint64_t
GSSwapHostI64ToLittle(gsu64 in) GSSwapHostI64ToLittle(uint64_t in)
{ {
return in; return in;
} }

View file

@ -202,7 +202,7 @@ typedef SOCKET NSSocketNativeHandle;
NSRecursiveLock *myLock; NSRecursiveLock *myLock;
NSHost *host; /* OpenStep host for this port. */ NSHost *host; /* OpenStep host for this port. */
NSString *address; /* Forced internet address. */ NSString *address; /* Forced internet address. */
gsu16 portNum; /* TCP port in host byte order. */ uint16_t portNum; /* TCP port in host byte order. */
SOCKET listener; SOCKET listener;
NSMapTable *handles; /* Handles indexed by socket. */ NSMapTable *handles; /* Handles indexed by socket. */
#if defined(__MINGW32__) #if defined(__MINGW32__)
@ -215,7 +215,7 @@ typedef SOCKET NSSocketNativeHandle;
* Look up and return an existing <code>NSSocketPort</code> given a host and * Look up and return an existing <code>NSSocketPort</code> given a host and
* number, or return nil if one has not been created. * number, or return nil if one has not been created.
*/ */
+ (NSSocketPort*) existingPortWithNumber: (gsu16)number + (NSSocketPort*) existingPortWithNumber: (uint16_t)number
onHost: (NSHost*)aHost; onHost: (NSHost*)aHost;
/** /**
@ -230,7 +230,7 @@ typedef SOCKET NSSocketNativeHandle;
* remote host, the port will use the first address that works.<br/> * remote host, the port will use the first address that works.<br/>
* shouldListen specifies whether to listen on the port initially. * shouldListen specifies whether to listen on the port initially.
*/ */
+ (NSSocketPort*) portWithNumber: (gsu16)number + (NSSocketPort*) portWithNumber: (uint16_t)number
onHost: (NSHost*)aHost onHost: (NSHost*)aHost
forceAddress: (NSString*)addr forceAddress: (NSString*)addr
listener: (BOOL)shouldListen; listener: (BOOL)shouldListen;
@ -259,7 +259,7 @@ typedef SOCKET NSSocketNativeHandle;
/** /**
* Returns port number of underlying socket. * Returns port number of underlying socket.
*/ */
- (gsu16) portNumber; - (uint16_t) portNumber;
// This is the OS X interface // This is the OS X interface
/* /*

View file

@ -208,14 +208,14 @@ getAddr(NSString* name, NSString* svc, NSString* pcl, struct sockaddr_in *sin)
} }
if (*ptr == '\0' && val <= 0xffff) if (*ptr == '\0' && val <= 0xffff)
{ {
gsu16 v = val; uint16_t v = val;
sin->sin_port = GSSwapHostI16ToBig(v); sin->sin_port = GSSwapHostI16ToBig(v);
return YES; return YES;
} }
else if (strcmp(ptr, "gdomap") == 0) else if (strcmp(ptr, "gdomap") == 0)
{ {
gsu16 v; uint16_t v;
#ifdef GDOMAP_PORT_OVERRIDE #ifdef GDOMAP_PORT_OVERRIDE
v = GDOMAP_PORT_OVERRIDE; v = GDOMAP_PORT_OVERRIDE;
#else #else

View file

@ -85,7 +85,7 @@
#ifdef HAVE_WCHAR_H #ifdef HAVE_WCHAR_H
#include <wchar.h> #include <wchar.h>
#else #else
typedef gsu32 wint_t; typedef uint32_t wint_t;
#endif #endif
#ifdef HAVE_SYS_INTTYPES_H #ifdef HAVE_SYS_INTTYPES_H
#include <sys/inttypes.h> #include <sys/inttypes.h>

View file

@ -690,6 +690,14 @@ static inline int getDigits(const char *from, char *to, int limit)
{ {
sub = @"%I:%M:%S %p"; sub = @"%I:%M:%S %p";
} }
else if (c == 'T')
{
sub = @"%H:%M:%S";
}
else if (c == 't')
{
sub = @"\t";
}
else if (c == 'X') else if (c == 'X')
{ {
sub = [locale objectForKey: NSTimeFormatString]; sub = [locale objectForKey: NSTimeFormatString];

View file

@ -335,19 +335,10 @@ failure:
*/ */
@implementation NSData @implementation NSData
#if NEED_WORD_ALIGNMENT
static unsigned gsu16Align;
static unsigned gsu32Align;
#endif
+ (void) initialize + (void) initialize
{ {
if (self == [NSData class]) if (self == [NSData class])
{ {
#if NEED_WORD_ALIGNMENT
gsu16Align = objc_alignof_type(@encode(gsu16));
gsu32Align = objc_alignof_type(@encode(gsu32));
#endif
NSDataAbstract = self; NSDataAbstract = self;
NSMutableDataAbstract = [NSMutableData class]; NSMutableDataAbstract = [NSMutableData class];
dataMalloc = [NSDataMalloc class]; dataMalloc = [NSDataMalloc class];
@ -1170,7 +1161,7 @@ failure:
} }
case _C_CHARPTR: case _C_CHARPTR:
{ {
gss32 length; int32_t length;
[self deserializeBytes: &length [self deserializeBytes: &length
length: sizeof(length) length: sizeof(length)
@ -1340,7 +1331,7 @@ failure:
} }
case _C_CLASS: case _C_CLASS:
{ {
gsu16 ni; uint16_t ni;
[self deserializeBytes: &ni [self deserializeBytes: &ni
length: sizeof(ni) length: sizeof(ni)
@ -1372,8 +1363,8 @@ failure:
} }
case _C_SEL: case _C_SEL:
{ {
gsu16 ln; uint16_t ln;
gsu16 lt; uint16_t lt;
[self deserializeBytes: &ln [self deserializeBytes: &ln
length: sizeof(ln) length: sizeof(ln)
@ -1588,7 +1579,7 @@ failure:
atCursor: (unsigned int*)cursor atCursor: (unsigned int*)cursor
{ {
[self deserializeDataAt: (void*)tag [self deserializeDataAt: (void*)tag
ofObjCType: @encode(gsu8) ofObjCType: @encode(uint8_t)
atCursor: cursor atCursor: cursor
context: nil]; context: nil];
if (*tag & _GSC_MAYX) if (*tag & _GSC_MAYX)
@ -1601,10 +1592,10 @@ failure:
} }
case _GSC_X_1: case _GSC_X_1:
{ {
gsu8 x; uint8_t x;
[self deserializeDataAt: (void*)&x [self deserializeDataAt: (void*)&x
ofObjCType: @encode(gsu8) ofObjCType: @encode(uint8_t)
atCursor: cursor atCursor: cursor
context: nil]; context: nil];
*ref = (unsigned int)x; *ref = (unsigned int)x;
@ -1612,10 +1603,10 @@ failure:
} }
case _GSC_X_2: case _GSC_X_2:
{ {
gsu16 x; uint16_t x;
[self deserializeDataAt: (void*)&x [self deserializeDataAt: (void*)&x
ofObjCType: @encode(gsu16) ofObjCType: @encode(uint16_t)
atCursor: cursor atCursor: cursor
context: nil]; context: nil];
*ref = (unsigned int)x; *ref = (unsigned int)x;
@ -1623,10 +1614,10 @@ failure:
} }
default: default:
{ {
gsu32 x; uint32_t x;
[self deserializeDataAt: (void*)&x [self deserializeDataAt: (void*)&x
ofObjCType: @encode(gsu32) ofObjCType: @encode(uint32_t)
atCursor: cursor atCursor: cursor
context: nil]; context: nil];
*ref = (unsigned int)x; *ref = (unsigned int)x;
@ -2045,17 +2036,17 @@ failure:
case _C_CHARPTR: case _C_CHARPTR:
{ {
gsu32 len; uint32_t len;
gsu32 ni; uint32_t ni;
if (!*(void**)data) if (!*(void**)data)
{ {
ni = (gsu32)-1; ni = (uint32_t)-1;
ni = GSSwapHostI32ToBig(ni); ni = GSSwapHostI32ToBig(ni);
[self appendBytes: (void*)&ni length: sizeof(ni)]; [self appendBytes: (void*)&ni length: sizeof(ni)];
return; return;
} }
len = (gsu32)strlen(*(void**)data); len = (uint32_t)strlen(*(void**)data);
ni = GSSwapHostI32ToBig(len); ni = GSSwapHostI32ToBig(len);
[self appendBytes: (void*)&ni length: sizeof(ni)]; [self appendBytes: (void*)&ni length: sizeof(ni)];
[self appendBytes: *(void**)data length: len]; [self appendBytes: *(void**)data length: len];
@ -2158,8 +2149,8 @@ failure:
case _C_CLASS: case _C_CLASS:
{ {
const char *name = *(Class*)data?GSNameFromClass(*(Class*)data):""; const char *name = *(Class*)data?GSNameFromClass(*(Class*)data):"";
gsu16 ln = (gsu16)strlen(name); uint16_t ln = (uint16_t)strlen(name);
gsu16 ni; uint16_t ni;
ni = GSSwapHostI16ToBig(ln); ni = GSSwapHostI16ToBig(ln);
[self appendBytes: &ni length: sizeof(ni)]; [self appendBytes: &ni length: sizeof(ni)];
@ -2172,10 +2163,10 @@ failure:
case _C_SEL: case _C_SEL:
{ {
const char *name = *(SEL*)data?GSNameFromSelector(*(SEL*)data):""; const char *name = *(SEL*)data?GSNameFromSelector(*(SEL*)data):"";
gsu16 ln = (name == 0) ? 0 : (gsu16)strlen(name); uint16_t ln = (name == 0) ? 0 : (uint16_t)strlen(name);
const char *types = *(SEL*)data?GSTypesFromSelector(*(SEL*)data):""; const char *types = *(SEL*)data?GSTypesFromSelector(*(SEL*)data):"";
gsu16 lt = (types == 0) ? 0 : (gsu16)strlen(types); uint16_t lt = (types == 0) ? 0 : (uint16_t)strlen(types);
gsu16 ni; uint16_t ni;
ni = GSSwapHostI16ToBig(ln); ni = GSSwapHostI16ToBig(ln);
[self appendBytes: &ni length: sizeof(ni)]; [self appendBytes: &ni length: sizeof(ni)];
@ -2337,38 +2328,38 @@ failure:
{ {
if (xref <= 0xff) if (xref <= 0xff)
{ {
gsu8 x = (gsu8)xref; uint8_t x = (uint8_t)xref;
tag = (tag & ~_GSC_SIZE) | _GSC_X_1; tag = (tag & ~_GSC_SIZE) | _GSC_X_1;
[self serializeDataAt: (void*)&tag [self serializeDataAt: (void*)&tag
ofObjCType: @encode(unsigned char) ofObjCType: @encode(unsigned char)
context: nil]; context: nil];
[self serializeDataAt: (void*)&x [self serializeDataAt: (void*)&x
ofObjCType: @encode(gsu8) ofObjCType: @encode(uint8_t)
context: nil]; context: nil];
} }
else if (xref <= 0xffff) else if (xref <= 0xffff)
{ {
gsu16 x = (gsu16)xref; uint16_t x = (uint16_t)xref;
tag = (tag & ~_GSC_SIZE) | _GSC_X_2; tag = (tag & ~_GSC_SIZE) | _GSC_X_2;
[self serializeDataAt: (void*)&tag [self serializeDataAt: (void*)&tag
ofObjCType: @encode(unsigned char) ofObjCType: @encode(unsigned char)
context: nil]; context: nil];
[self serializeDataAt: (void*)&x [self serializeDataAt: (void*)&x
ofObjCType: @encode(gsu16) ofObjCType: @encode(uint16_t)
context: nil]; context: nil];
} }
else else
{ {
gsu32 x = (gsu32)xref; uint32_t x = (uint32_t)xref;
tag = (tag & ~_GSC_SIZE) | _GSC_X_4; tag = (tag & ~_GSC_SIZE) | _GSC_X_4;
[self serializeDataAt: (void*)&tag [self serializeDataAt: (void*)&tag
ofObjCType: @encode(unsigned char) ofObjCType: @encode(unsigned char)
context: nil]; context: nil];
[self serializeDataAt: (void*)&x [self serializeDataAt: (void*)&x
ofObjCType: @encode(gsu32) ofObjCType: @encode(uint32_t)
context: nil]; context: nil];
} }
} }
@ -2493,7 +2484,7 @@ getBytes(void* dst, void* src, unsigned len, unsigned limit, unsigned *pos)
} }
case _C_CHARPTR: case _C_CHARPTR:
{ {
gss32 len; int32_t len;
[self deserializeBytes: &len [self deserializeBytes: &len
length: sizeof(len) length: sizeof(len)
@ -2644,7 +2635,7 @@ getBytes(void* dst, void* src, unsigned len, unsigned limit, unsigned *pos)
} }
case _C_CLASS: case _C_CLASS:
{ {
gsu16 ni; uint16_t ni;
getBytes((void*)&ni, bytes, sizeof(ni), length, cursor); getBytes((void*)&ni, bytes, sizeof(ni), length, cursor);
ni = GSSwapBigI16ToHost(ni); ni = GSSwapBigI16ToHost(ni);
@ -2672,8 +2663,8 @@ getBytes(void* dst, void* src, unsigned len, unsigned limit, unsigned *pos)
} }
case _C_SEL: case _C_SEL:
{ {
gsu16 ln; uint16_t ln;
gsu16 lt; uint16_t lt;
getBytes((void*)&ln, bytes, sizeof(ln), length, cursor); getBytes((void*)&ln, bytes, sizeof(ln), length, cursor);
ln = GSSwapBigI16ToHost(ln); ln = GSSwapBigI16ToHost(ln);
@ -2760,7 +2751,7 @@ getBytes(void* dst, void* src, unsigned len, unsigned limit, unsigned *pos)
} }
case _GSC_X_2: case _GSC_X_2:
{ {
gsu16 x; uint16_t x;
if (*cursor >= length-1) if (*cursor >= length-1)
{ {
@ -2769,18 +2760,18 @@ getBytes(void* dst, void* src, unsigned len, unsigned limit, unsigned *pos)
*cursor, length]; *cursor, length];
} }
#if NEED_WORD_ALIGNMENT #if NEED_WORD_ALIGNMENT
if ((*cursor % gsu16Align) != 0) if ((*cursor % __alignof__(uint16_t)) != 0)
memcpy(&x, (bytes + *cursor), 2); memcpy(&x, (bytes + *cursor), 2);
else else
#endif #endif
x = *(gsu16*)(bytes + *cursor); x = *(uint16_t*)(bytes + *cursor);
*cursor += 2; *cursor += 2;
*ref = (unsigned int)GSSwapBigI16ToHost(x); *ref = (unsigned int)GSSwapBigI16ToHost(x);
return; return;
} }
default: default:
{ {
gsu32 x; uint32_t x;
if (*cursor >= length-3) if (*cursor >= length-3)
{ {
@ -2789,11 +2780,11 @@ getBytes(void* dst, void* src, unsigned len, unsigned limit, unsigned *pos)
*cursor, length]; *cursor, length];
} }
#if NEED_WORD_ALIGNMENT #if NEED_WORD_ALIGNMENT
if ((*cursor % gsu32Align) != 0) if ((*cursor % __alignof__(uint32_t)) != 0)
memcpy(&x, (bytes + *cursor), 4); memcpy(&x, (bytes + *cursor), 4);
else else
#endif #endif
x = *(gsu32*)(bytes + *cursor); x = *(uint32_t*)(bytes + *cursor);
*cursor += 4; *cursor += 4;
*ref = (unsigned int)GSSwapBigI32ToHost(x); *ref = (unsigned int)GSSwapBigI32ToHost(x);
return; return;
@ -3288,8 +3279,8 @@ getBytes(void* dst, void* src, unsigned len, unsigned limit, unsigned *pos)
case _C_CHARPTR: case _C_CHARPTR:
{ {
unsigned len; unsigned len;
gss32 ni; int32_t ni;
gsu32 minimum; uint32_t minimum;
if (!*(void**)data) if (!*(void**)data)
{ {
@ -3320,7 +3311,7 @@ getBytes(void* dst, void* src, unsigned len, unsigned limit, unsigned *pos)
unsigned size; unsigned size;
unsigned count = atoi(++type); unsigned count = atoi(++type);
unsigned i; unsigned i;
gsu32 minimum; uint32_t minimum;
while (isdigit(*type)) while (isdigit(*type))
{ {
@ -3421,9 +3412,9 @@ getBytes(void* dst, void* src, unsigned len, unsigned limit, unsigned *pos)
case _C_CLASS: case _C_CLASS:
{ {
const char *name = *(Class*)data?GSNameFromClass(*(Class*)data):""; const char *name = *(Class*)data?GSNameFromClass(*(Class*)data):"";
gsu16 ln = (gsu16)strlen(name); uint16_t ln = (uint16_t)strlen(name);
gsu32 minimum = length + ln + sizeof(gsu16); uint32_t minimum = length + ln + sizeof(uint16_t);
gsu16 ni; uint16_t ni;
if (minimum > capacity) if (minimum > capacity)
{ {
@ -3442,11 +3433,11 @@ getBytes(void* dst, void* src, unsigned len, unsigned limit, unsigned *pos)
case _C_SEL: case _C_SEL:
{ {
const char *name = *(SEL*)data?GSNameFromSelector(*(SEL*)data):""; const char *name = *(SEL*)data?GSNameFromSelector(*(SEL*)data):"";
gsu16 ln = (name == 0) ? 0 : (gsu16)strlen(name); uint16_t ln = (name == 0) ? 0 : (uint16_t)strlen(name);
const char *types = *(SEL*)data?GSTypesFromSelector(*(SEL*)data):""; const char *types = *(SEL*)data?GSTypesFromSelector(*(SEL*)data):"";
gsu16 lt = (types == 0) ? 0 : (gsu16)strlen(types); uint16_t lt = (types == 0) ? 0 : (uint16_t)strlen(types);
gsu32 minimum = length + ln + lt + 2*sizeof(gsu16); uint32_t minimum = length + ln + lt + 2*sizeof(uint16_t);
gsu16 ni; uint16_t ni;
if (minimum > capacity) if (minimum > capacity)
{ {
@ -3495,49 +3486,49 @@ getBytes(void* dst, void* src, unsigned len, unsigned limit, unsigned *pos)
{ {
[self _grow: length + 2]; [self _grow: length + 2];
} }
*(gsu8*)(bytes + length++) = tag; *(uint8_t*)(bytes + length++) = tag;
*(gsu8*)(bytes + length++) = xref; *(uint8_t*)(bytes + length++) = xref;
} }
else if (xref <= 0xffff) else if (xref <= 0xffff)
{ {
gsu16 x = (gsu16)xref; uint16_t x = (uint16_t)xref;
tag = (tag & ~_GSC_SIZE) | _GSC_X_2; tag = (tag & ~_GSC_SIZE) | _GSC_X_2;
if (length + 3 >= capacity) if (length + 3 >= capacity)
{ {
[self _grow: length + 3]; [self _grow: length + 3];
} }
*(gsu8*)(bytes + length++) = tag; *(uint8_t*)(bytes + length++) = tag;
#if NEED_WORD_ALIGNMENT #if NEED_WORD_ALIGNMENT
if ((length % gsu16Align) != 0) if ((length % __alignof__(uint16_t)) != 0)
{ {
x = GSSwapHostI16ToBig(x); x = GSSwapHostI16ToBig(x);
memcpy((bytes + length), &x, 2); memcpy((bytes + length), &x, 2);
} }
else else
#endif #endif
*(gsu16*)(bytes + length) = GSSwapHostI16ToBig(x); *(uint16_t*)(bytes + length) = GSSwapHostI16ToBig(x);
length += 2; length += 2;
} }
else else
{ {
gsu32 x = (gsu32)xref; uint32_t x = (uint32_t)xref;
tag = (tag & ~_GSC_SIZE) | _GSC_X_4; tag = (tag & ~_GSC_SIZE) | _GSC_X_4;
if (length + 5 >= capacity) if (length + 5 >= capacity)
{ {
[self _grow: length + 5]; [self _grow: length + 5];
} }
*(gsu8*)(bytes + length++) = tag; *(uint8_t*)(bytes + length++) = tag;
#if NEED_WORD_ALIGNMENT #if NEED_WORD_ALIGNMENT
if ((length % gsu32Align) != 0) if ((length % __alignof__(uint32_t)) != 0)
{ {
x = GSSwapHostI32ToBig(x); x = GSSwapHostI32ToBig(x);
memcpy((bytes + length), &x, 4); memcpy((bytes + length), &x, 4);
} }
else else
#endif #endif
*(gsu32*)(bytes + length) = GSSwapHostI32ToBig(x); *(uint32_t*)(bytes + length) = GSSwapHostI32ToBig(x);
length += 4; length += 4;
} }
} }

View file

@ -163,7 +163,7 @@ enum proxyLocation
+ (id) initWithCoder: (NSCoder*)aCoder + (id) initWithCoder: (NSCoder*)aCoder
{ {
gsu8 proxy_tag; uint8_t proxy_tag;
unsigned target; unsigned target;
id decoder_connection; id decoder_connection;
NSDistantObject *o; NSDistantObject *o;
@ -444,7 +444,7 @@ enum proxyLocation
- (void) encodeWithCoder: (NSCoder*)aRmc - (void) encodeWithCoder: (NSCoder*)aRmc
{ {
unsigned proxy_target; unsigned proxy_target;
gsu8 proxy_tag; uint8_t proxy_tag;
NSConnection *encoder_connection; NSConnection *encoder_connection;
/* /*

View file

@ -93,7 +93,7 @@
/* /*
* Largest chunk of data possible in DO * Largest chunk of data possible in DO
*/ */
static gsu32 maxDataLength = 32 * 1024 * 1024; static uint32_t maxDataLength = 32 * 1024 * 1024;
#if 0 #if 0
#define M_LOCK(X) {NSDebugMLLog(@"NSMessagePort",@"lock %@",X); [X lock];} #define M_LOCK(X) {NSDebugMLLog(@"NSMessagePort",@"lock %@",X); [X lock];}
@ -121,8 +121,8 @@ typedef enum {
* Its contents are transmitted in network byte order. * Its contents are transmitted in network byte order.
*/ */
typedef struct { typedef struct {
gsu32 type; /* A GSPortItemType as a 4-byte number. */ uint32_t type; /* A GSPortItemType as a 4-byte number. */
gsu32 length; /* The length of the item (excluding header). */ uint32_t length; /* The length of the item (excluding header). */
} GSPortItemHeader; } GSPortItemHeader;
/* /*
@ -132,8 +132,8 @@ typedef struct {
* NB. additional data counts as part of the same item. * NB. additional data counts as part of the same item.
*/ */
typedef struct { typedef struct {
gsu32 mId; /* The ID for the message starting with this. */ uint32_t mId; /* The ID for the message starting with this. */
gsu32 nItems; /* Number of items (including this one). */ uint32_t nItems; /* Number of items (including this one). */
} GSPortMsgHeader; } GSPortMsgHeader;
typedef struct { typedef struct {
@ -237,11 +237,11 @@ typedef enum {
unsigned wLength; /* Ammount written so far. */ unsigned wLength; /* Ammount written so far. */
NSMutableArray *wMsgs; /* Message in progress. */ NSMutableArray *wMsgs; /* Message in progress. */
NSMutableData *rData; /* Buffer for incoming data */ NSMutableData *rData; /* Buffer for incoming data */
gsu32 rLength; /* Amount read so far. */ uint32_t rLength; /* Amount read so far. */
gsu32 rWant; /* Amount desired. */ uint32_t rWant; /* Amount desired. */
NSMutableArray *rItems; /* Message in progress. */ NSMutableArray *rItems; /* Message in progress. */
GSPortItemType rType; /* Type of data being read. */ GSPortItemType rType; /* Type of data being read. */
gsu32 rId; /* Id of incoming message. */ uint32_t rId; /* Id of incoming message. */
unsigned nItems; /* Number of items to be read. */ unsigned nItems; /* Number of items to be read. */
GSHandleState state; /* State of the handle. */ GSHandleState state; /* State of the handle. */
unsigned int addrNum; /* Address number within host. */ unsigned int addrNum; /* Address number within host. */
@ -1164,17 +1164,10 @@ typedef struct {
#define lDesc ((internal*)_internal)->_listener #define lDesc ((internal*)_internal)->_listener
#if NEED_WORD_ALIGNMENT
static unsigned wordAlign;
#endif
+ (void) initialize + (void) initialize
{ {
if (self == [NSMessagePort class]) if (self == [NSMessagePort class])
{ {
#if NEED_WORD_ALIGNMENT
wordAlign = objc_alignof_type(@encode(gsu32));
#endif
messagePortClass = self; messagePortClass = self;
messagePortMap = NSCreateMapTable(NSNonRetainedObjectMapKeyCallBacks, messagePortMap = NSCreateMapTable(NSNonRetainedObjectMapKeyCallBacks,
NSNonOwnedPointerMapValueCallBacks, 0); NSNonOwnedPointerMapValueCallBacks, 0);
@ -1862,7 +1855,7 @@ static unsigned wordAlign;
* word boundary, so we work with an aligned buffer * word boundary, so we work with an aligned buffer
* and use memcmpy() * and use memcmpy()
*/ */
if ((hLength % wordAlign) != 0) if ((hLength % __alignof__(uint32_t)) != 0)
{ {
GSPortItemHeader itemHeader; GSPortItemHeader itemHeader;

View file

@ -521,9 +521,9 @@ static IMP _xRefImp; /* Serialize a crossref. */
gsu128 bigval; gsu128 bigval;
#else #else
#if GS_HAVE_I64 #if GS_HAVE_I64
gsu64 bigval; uint64_t bigval;
#else #else
gsu32 bigval; uint32_t bigval;
#endif #endif
#endif #endif
@ -949,27 +949,27 @@ static IMP _xRefImp; /* Serialize a crossref. */
{ {
case _GSC_I16: /* Encoded as 16-bit */ case _GSC_I16: /* Encoded as 16-bit */
{ {
gsu16 val; uint16_t val;
(*_dDesImp)(_src, dDesSel, &val, @encode(gsu16), &_cursor, nil); (*_dDesImp)(_src, dDesSel, &val, @encode(uint16_t), &_cursor, nil);
bigval = val; bigval = val;
break; break;
} }
case _GSC_I32: /* Encoded as 32-bit */ case _GSC_I32: /* Encoded as 32-bit */
{ {
gsu32 val; uint32_t val;
(*_dDesImp)(_src, dDesSel, &val, @encode(gsu32), &_cursor, nil); (*_dDesImp)(_src, dDesSel, &val, @encode(uint32_t), &_cursor, nil);
bigval = val; bigval = val;
break; break;
} }
case _GSC_I64: /* Encoded as 64-bit */ case _GSC_I64: /* Encoded as 64-bit */
{ {
gsu64 val; uint64_t val;
(*_dDesImp)(_src, dDesSel, &val, @encode(gsu64), &_cursor, nil); (*_dDesImp)(_src, dDesSel, &val, @encode(uint64_t), &_cursor, nil);
#if GS_HAVE_I64 #if GS_HAVE_I64
bigval = val; bigval = val;
#else #else
@ -988,9 +988,9 @@ static IMP _xRefImp; /* Serialize a crossref. */
#else #else
val = GSSwapBigI128ToHost(val); val = GSSwapBigI128ToHost(val);
#if GS_HAVE_I64 #if GS_HAVE_I64
bigval = *(gsu64*)&val; bigval = *(uint64_t*)&val;
#else #else
bigval = *(gsu32*)&val; bigval = *(uint32_t*)&val;
#endif #endif
#endif #endif
break; break;

View file

@ -128,10 +128,6 @@ static Class MStringClass = 0;
static Class StringClass = 0; static Class StringClass = 0;
static Class NumberClass = 0; static Class NumberClass = 0;
#if NEED_WORD_ALIGNMENT
static unsigned gsu32Align;
#endif
typedef struct { typedef struct {
@defs(GSString) @defs(GSString)
} *ivars; } *ivars;
@ -260,7 +256,7 @@ serializeToInfo(id object, _NSSerializerInfo* info)
* word boundary, so we work with an aligned buffer * word boundary, so we work with an aligned buffer
* and use memcmpy() * and use memcmpy()
*/ */
if ((dlen % gsu32Align) != 0) if ((dlen % __alignof__(uint32_t)) != 0)
{ {
unichar buffer[slen]; unichar buffer[slen];
[object getCharacters: buffer]; [object getCharacters: buffer];
@ -370,9 +366,6 @@ static BOOL shouldBeCompact = NO;
{ {
if (self == [NSSerializer class]) if (self == [NSSerializer class])
{ {
#if NEED_WORD_ALIGNMENT
gsu32Align = objc_alignof_type(@encode(gsu32));
#endif
appSel = @selector(appendBytes:length:); appSel = @selector(appendBytes:length:);
datSel = @selector(mutableBytes); datSel = @selector(mutableBytes);
lenSel = @selector(length); lenSel = @selector(length);

View file

@ -105,7 +105,7 @@
/* /*
* Largest chunk of data possible in DO * Largest chunk of data possible in DO
*/ */
static gsu32 maxDataLength = 32 * 1024 * 1024; static uint32_t maxDataLength = 32 * 1024 * 1024;
#if 0 #if 0
#define M_LOCK(X) {NSDebugMLLog(@"GSTcpHandleLock",@"lock %@ in %@",X,[NSThread currentThread]); [X lock];} #define M_LOCK(X) {NSDebugMLLog(@"GSTcpHandleLock",@"lock %@ in %@",X,[NSThread currentThread]); [X lock];}
@ -148,8 +148,8 @@ typedef enum {
* Its contents are transmitted in network byte order. * Its contents are transmitted in network byte order.
*/ */
typedef struct { typedef struct {
gsu32 type; /* A GSPortItemType as a 4-byte number. */ uint32_t type; /* A GSPortItemType as a 4-byte number. */
gsu32 length; /* The length of the item (excluding header). */ uint32_t length; /* The length of the item (excluding header). */
} GSPortItemHeader; } GSPortItemHeader;
/* /*
@ -159,12 +159,12 @@ typedef struct {
* NB. additional data counts as part of the same item. * NB. additional data counts as part of the same item.
*/ */
typedef struct { typedef struct {
gsu32 mId; /* The ID for the message starting with this. */ uint32_t mId; /* The ID for the message starting with this. */
gsu32 nItems; /* Number of items (including this one). */ uint32_t nItems; /* Number of items (including this one). */
} GSPortMsgHeader; } GSPortMsgHeader;
typedef struct { typedef struct {
gsu16 num; /* TCP port num */ uint16_t num; /* TCP port num */
char addr[0]; /* host address */ char addr[0]; /* host address */
} GSPortInfo; } GSPortInfo;
@ -193,11 +193,11 @@ typedef enum {
unsigned wLength; /* Ammount written so far. */ unsigned wLength; /* Ammount written so far. */
NSMutableArray *wMsgs; /* Message in progress. */ NSMutableArray *wMsgs; /* Message in progress. */
NSMutableData *rData; /* Buffer for incoming data */ NSMutableData *rData; /* Buffer for incoming data */
gsu32 rLength; /* Amount read so far. */ uint32_t rLength; /* Amount read so far. */
gsu32 rWant; /* Amount desired. */ uint32_t rWant; /* Amount desired. */
NSMutableArray *rItems; /* Message in progress. */ NSMutableArray *rItems; /* Message in progress. */
GSPortItemType rType; /* Type of data being read. */ GSPortItemType rType; /* Type of data being read. */
gsu32 rId; /* Id of incoming message. */ uint32_t rId; /* Id of incoming message. */
unsigned nItems; /* Number of items to be read. */ unsigned nItems; /* Number of items to be read. */
GSHandleState state; /* State of the handle. */ GSHandleState state; /* State of the handle. */
unsigned int addrNum; /* Address number within host. */ unsigned int addrNum; /* Address number within host. */
@ -253,8 +253,8 @@ decodePort(NSData *data, NSString *defaultAddress)
GSPortItemHeader *pih; GSPortItemHeader *pih;
GSPortInfo *pi; GSPortInfo *pi;
NSString *addr; NSString *addr;
gsu16 pnum; uint16_t pnum;
gsu32 length; uint32_t length;
NSHost *host; NSHost *host;
unichar c; unichar c;
@ -306,7 +306,7 @@ newDataWithEncodedPort(NSSocketPort *port)
NSMutableData *data; NSMutableData *data;
unsigned plen; unsigned plen;
NSString *addr; NSString *addr;
gsu16 pnum; uint16_t pnum;
pnum = [port portNumber]; pnum = [port portNumber];
addr = [port address]; addr = [port address];
@ -1488,17 +1488,10 @@ static NSRecursiveLock *tcpPortLock = nil;
static NSMapTable *tcpPortMap = 0; static NSMapTable *tcpPortMap = 0;
static Class tcpPortClass; static Class tcpPortClass;
#if NEED_WORD_ALIGNMENT
static unsigned wordAlign;
#endif
+ (void) initialize + (void) initialize
{ {
if (self == [NSSocketPort class]) if (self == [NSSocketPort class])
{ {
#if NEED_WORD_ALIGNMENT
wordAlign = objc_alignof_type(@encode(gsu32));
#endif
tcpPortClass = self; tcpPortClass = self;
tcpPortMap = NSCreateMapTable(NSIntMapKeyCallBacks, tcpPortMap = NSCreateMapTable(NSIntMapKeyCallBacks,
NSNonOwnedPointerMapValueCallBacks, 0); NSNonOwnedPointerMapValueCallBacks, 0);
@ -1518,7 +1511,7 @@ static unsigned wordAlign;
/* /*
* Look up an existing NSSocketPort given a host and number * Look up an existing NSSocketPort given a host and number
*/ */
+ (NSSocketPort*) existingPortWithNumber: (gsu16)number + (NSSocketPort*) existingPortWithNumber: (uint16_t)number
onHost: (NSHost*)aHost onHost: (NSHost*)aHost
{ {
NSSocketPort *port = nil; NSSocketPort *port = nil;
@ -1550,7 +1543,7 @@ static unsigned wordAlign;
* then, for the local host, the port uses ALL IP addresses, and for a * then, for the local host, the port uses ALL IP addresses, and for a
* remote host, the port will use the first address that works. * remote host, the port will use the first address that works.
*/ */
+ (NSSocketPort*) portWithNumber: (gsu16)number + (NSSocketPort*) portWithNumber: (uint16_t)number
onHost: (NSHost*)aHost onHost: (NSHost*)aHost
forceAddress: (NSString*)addr forceAddress: (NSString*)addr
listener: (BOOL)shouldListen listener: (BOOL)shouldListen
@ -2141,7 +2134,7 @@ static unsigned wordAlign;
return NO; return NO;
} }
- (gsu16) portNumber - (uint16_t) portNumber
{ {
return portNum; return portNum;
} }
@ -2394,7 +2387,7 @@ static unsigned wordAlign;
* word boundary, so we work with an aligned buffer * word boundary, so we work with an aligned buffer
* and use memcmpy() * and use memcmpy()
*/ */
if ((hLength % wordAlign) != 0) if ((hLength % __alignof__(uint32_t)) != 0)
{ {
GSPortItemHeader itemHeader; GSPortItemHeader itemHeader;

View file

@ -63,11 +63,11 @@
*/ */
@class NSSocketPort; @class NSSocketPort;
@interface NSSocketPort (Hack) @interface NSSocketPort (Hack)
+ (NSSocketPort*) portWithNumber: (gsu16)number + (NSSocketPort*) portWithNumber: (uint16_t)number
onHost: (NSHost*)host onHost: (NSHost*)host
forceAddress: (NSString*)addr forceAddress: (NSString*)addr
listener: (BOOL)shouldListen; listener: (BOOL)shouldListen;
- (gsu16) portNumber; - (uint16_t) portNumber;
@end @end
/* /*
@ -119,8 +119,9 @@ typedef enum {
- (GSPortComState) state; - (GSPortComState) state;
- (void) startListNameServers; - (void) startListNameServers;
- (void) startPortLookup: (NSString*)name onHost: (NSString*)addr; - (void) startPortLookup: (NSString*)name onHost: (NSString*)addr;
- (void) startPortRegistration: (gsu32)portNumber withName: (NSString*)name; - (void) startPortRegistration: (uint32_t)portNumber withName: (NSString*)name;
- (void) startPortUnregistration: (gsu32)portNumber withName: (NSString*)name; - (void) startPortUnregistration: (uint32_t)portNumber
withName: (NSString*)name;
@end @end
@implementation GSPortCom @implementation GSPortCom
@ -259,7 +260,7 @@ typedef enum {
} }
else if (state == GSPC_READ1 && msg.rtype == GDO_SERVERS) else if (state == GSPC_READ1 && msg.rtype == GDO_SERVERS)
{ {
gsu32 numSvrs = GSSwapBigI32ToHost(*(gsu32*)[data bytes]); uint32_t numSvrs = GSSwapBigI32ToHost(*(uint32_t*)[data bytes]);
if (numSvrs == 0) if (numSvrs == 0)
{ {
@ -490,7 +491,7 @@ typedef enum {
[self open: host]; [self open: host];
} }
- (void) startPortRegistration: (gsu32)portNumber withName: (NSString*)name - (void) startPortRegistration: (uint32_t)portNumber withName: (NSString*)name
{ {
msg.rtype = GDO_REGISTER; /* Register a port. */ msg.rtype = GDO_REGISTER; /* Register a port. */
msg.ptype = GDO_TCP_GDO; /* Port is TCP port for GNU DO */ msg.ptype = GDO_TCP_GDO; /* Port is TCP port for GNU DO */
@ -503,7 +504,7 @@ typedef enum {
[self open: nil]; [self open: nil];
} }
- (void) startPortUnregistration: (gsu32)portNumber withName: (NSString*)name - (void) startPortUnregistration: (uint32_t)portNumber withName: (NSString*)name
{ {
msg.rtype = GDO_UNREG; msg.rtype = GDO_UNREG;
msg.ptype = GDO_TCP_GDO; msg.ptype = GDO_TCP_GDO;
@ -666,7 +667,7 @@ typedef enum {
*/ */
dat = AUTORELEASE(RETAIN([com data])); dat = AUTORELEASE(RETAIN([com data]));
svrs = (struct in_addr*)([dat bytes] + 4); svrs = (struct in_addr*)([dat bytes] + 4);
numSvrs = GSSwapBigI32ToHost(*(gsu32*)[dat bytes]); numSvrs = GSSwapBigI32ToHost(*(uint32_t*)[dat bytes]);
if (numSvrs == 0) if (numSvrs == 0)
{ {
[NSException raise: NSInternalInconsistencyException [NSException raise: NSInternalInconsistencyException
@ -759,7 +760,8 @@ typedef enum {
[com close]; [com close];
if ([com state] == GSPC_DONE) if ([com state] == GSPC_DONE)
{ {
*port = GSSwapBigI32ToHost(*(gsu32*)[[com data] bytes]); *port
= GSSwapBigI32ToHost(*(uint32_t*)[[com data] bytes]);
if (*port != 0) if (*port != 0)
{ {
singleServer = [com addr]; singleServer = [com addr];
@ -953,7 +955,7 @@ typedef enum {
{ {
unsigned result; unsigned result;
result = GSSwapBigI32ToHost(*(gsu32*)[[com data] bytes]); result = GSSwapBigI32ToHost(*(uint32_t*)[[com data] bytes]);
if (result == 0) if (result == 0)
{ {
unsigned int portNum; unsigned int portNum;
@ -1091,7 +1093,7 @@ typedef enum {
NSPort *port; NSPort *port;
unsigned result; unsigned result;
result = GSSwapBigI32ToHost(*(gsu32*)[[com data] bytes]); result = GSSwapBigI32ToHost(*(uint32_t*)[[com data] bytes]);
if (result == 0) if (result == 0)
{ {
NSLog(@"NSSocketPortNameServer unable to unregister '%@'", name); NSLog(@"NSSocketPortNameServer unable to unregister '%@'", name);

View file

@ -336,7 +336,7 @@ static unsigned rootOf(NSString *s, unsigned l)
/* Convert a high-low surrogate pair into Unicode scalar code-point */ /* Convert a high-low surrogate pair into Unicode scalar code-point */
static inline gsu32 static inline uint32_t
surrogatePairValue(unichar high, unichar low) surrogatePairValue(unichar high, unichar low)
{ {
return ((high - (unichar)0xD800) * (unichar)400) return ((high - (unichar)0xD800) * (unichar)400)
@ -3285,7 +3285,7 @@ handle_printf_atsign (FILE *stream,
unsigned char *buff; unsigned char *buff;
unsigned i, j; unsigned i, j;
unichar ch, ch2; unichar ch, ch2;
gsu32 cp; uint32_t cp;
buff = (unsigned char *)NSZoneMalloc(NSDefaultMallocZone(), len*3); buff = (unsigned char *)NSZoneMalloc(NSDefaultMallocZone(), len*3);
@ -3311,10 +3311,10 @@ handle_printf_atsign (FILE *stream,
i++; i++;
} }
else else
cp = (gsu32)ch; cp = (uint32_t)ch;
} }
else else
cp = (gsu32)ch; cp = (uint32_t)ch;
if (cp < 0x80) if (cp < 0x80)
{ {

View file

@ -176,7 +176,7 @@ struct ttinfo
* And this is the structure used in the time zone instances. * And this is the structure used in the time zone instances.
*/ */
typedef struct { typedef struct {
gss32 offset; int32_t offset;
BOOL isdst; BOOL isdst;
unsigned char abbr_idx; unsigned char abbr_idx;
char pad[2]; char pad[2];
@ -190,7 +190,7 @@ typedef struct {
NSData *timeZoneData; NSData *timeZoneData;
unsigned int n_trans; unsigned int n_trans;
unsigned int n_types; unsigned int n_types;
gss32 *trans; int32_t *trans;
TypeInfo *types; TypeInfo *types;
unsigned char *idxs; unsigned char *idxs;
} }
@ -2145,8 +2145,8 @@ int dayOfCommonEra(NSTimeInterval when);
static TypeInfo* static TypeInfo*
chop(NSTimeInterval since, GSTimeZone *zone) chop(NSTimeInterval since, GSTimeZone *zone)
{ {
gss32 when = (gss32)since; int32_t when = (int32_t)since;
gss32 *trans = zone->trans; int32_t *trans = zone->trans;
unsigned hi = zone->n_trans; unsigned hi = zone->n_trans;
unsigned lo = 0; unsigned lo = 0;
unsigned int i; unsigned int i;
@ -2271,12 +2271,12 @@ newDetailInZoneForType(GSTimeZone *zone, TypeInfo *type)
format: @"TZ_MAGIC is incorrect"]; format: @"TZ_MAGIC is incorrect"];
} }
#endif #endif
n_trans = GSSwapBigI32ToHost(*(gss32*)header->tzh_timecnt); n_trans = GSSwapBigI32ToHost(*(int32_t*)header->tzh_timecnt);
n_types = GSSwapBigI32ToHost(*(gss32*)header->tzh_typecnt); n_types = GSSwapBigI32ToHost(*(int32_t*)header->tzh_typecnt);
charcnt = GSSwapBigI32ToHost(*(gss32*)header->tzh_charcnt); charcnt = GSSwapBigI32ToHost(*(int32_t*)header->tzh_charcnt);
i = pos; i = pos;
i += sizeof(gss32)*n_trans; i += sizeof(int32_t)*n_trans;
if (i > length) if (i > length)
{ {
[NSException raise: fileException [NSException raise: fileException
@ -2305,19 +2305,19 @@ newDetailInZoneForType(GSTimeZone *zone, TypeInfo *type)
* for efficient access ... not the same saze as the data * for efficient access ... not the same saze as the data
* we received. * we received.
*/ */
i = n_trans * (sizeof(gss32)+1) + n_types * sizeof(TypeInfo); i = n_trans * (sizeof(int32_t)+1) + n_types * sizeof(TypeInfo);
buf = NSZoneMalloc(NSDefaultMallocZone(), i); buf = NSZoneMalloc(NSDefaultMallocZone(), i);
types = (TypeInfo*)buf; types = (TypeInfo*)buf;
buf += (n_types * sizeof(TypeInfo)); buf += (n_types * sizeof(TypeInfo));
trans = (gss32*)buf; trans = (int32_t*)buf;
buf += (n_trans * sizeof(gss32)); buf += (n_trans * sizeof(int32_t));
idxs = (unsigned char*)buf; idxs = (unsigned char*)buf;
/* Read in transitions. */ /* Read in transitions. */
for (i = 0; i < n_trans; i++) for (i = 0; i < n_trans; i++)
{ {
trans[i] = GSSwapBigI32ToHost(*(gss32*)(bytes + pos)); trans[i] = GSSwapBigI32ToHost(*(int32_t*)(bytes + pos));
pos += sizeof(gss32); pos += sizeof(int32_t);
} }
for (i = 0; i < n_trans; i++) for (i = 0; i < n_trans; i++)
{ {

View file

@ -583,9 +583,9 @@ static Class NSDataMallocClass;
gsu128 bigval; gsu128 bigval;
#else #else
#if GS_HAVE_I64 #if GS_HAVE_I64
gsu64 bigval; uint64_t bigval;
#else #else
gsu32 bigval; uint32_t bigval;
#endif #endif
#endif #endif
@ -707,7 +707,7 @@ static Class NSDataMallocClass;
{ {
unsigned cver; unsigned cver;
NSString *className; NSString *className;
gsu16 nameLength; uint16_t nameLength;
if (xref != GSIArrayCount(clsMap)) if (xref != GSIArrayCount(clsMap))
{ {
@ -719,7 +719,8 @@ static Class NSDataMallocClass;
* A class is encoded as a 16-bit length, a sequence of * A class is encoded as a 16-bit length, a sequence of
* characters providing its name, then a version number. * characters providing its name, then a version number.
*/ */
(*desImp)(src, desSel, &nameLength, @encode(gsu16), &cursor, nil); (*desImp)(src, desSel, &nameLength, @encode(uint16_t),
&cursor, nil);
if (nameLength == 0) if (nameLength == 0)
{ {
className = nil; className = nil;
@ -1006,27 +1007,27 @@ static Class NSDataMallocClass;
{ {
case _GSC_I16: /* Encoded as 16-bit */ case _GSC_I16: /* Encoded as 16-bit */
{ {
gsu16 val; uint16_t val;
(*desImp)(src, desSel, &val, @encode(gsu16), &cursor, nil); (*desImp)(src, desSel, &val, @encode(uint16_t), &cursor, nil);
bigval = val; bigval = val;
break; break;
} }
case _GSC_I32: /* Encoded as 32-bit */ case _GSC_I32: /* Encoded as 32-bit */
{ {
gsu32 val; uint32_t val;
(*desImp)(src, desSel, &val, @encode(gsu32), &cursor, nil); (*desImp)(src, desSel, &val, @encode(uint32_t), &cursor, nil);
bigval = val; bigval = val;
break; break;
} }
case _GSC_I64: /* Encoded as 64-bit */ case _GSC_I64: /* Encoded as 64-bit */
{ {
gsu64 val; uint64_t val;
(*desImp)(src, desSel, &val, @encode(gsu64), &cursor, nil); (*desImp)(src, desSel, &val, @encode(uint64_t), &cursor, nil);
#if GS_HAVE_I64 #if GS_HAVE_I64
bigval = val; bigval = val;
#else #else
@ -1045,9 +1046,9 @@ static Class NSDataMallocClass;
#else #else
val = GSSwapBigI128ToHost(val); val = GSSwapBigI128ToHost(val);
#if GS_HAVE_I64 #if GS_HAVE_I64
bigval = *(gsu64*)&val; bigval = *(uint64_t*)&val;
#else #else
bigval = *(gsu32*)&val; bigval = *(uint32_t*)&val;
#endif #endif
#endif #endif
break; break;

View file

@ -192,14 +192,14 @@ getAddr(NSString* name, NSString* svc, NSString* pcl, struct sockaddr_in *sin)
} }
if (*ptr == '\0' && val <= 0xffff) if (*ptr == '\0' && val <= 0xffff)
{ {
gsu16 v = val; uint16_t v = val;
sin->sin_port = GSSwapHostI16ToBig(v); sin->sin_port = GSSwapHostI16ToBig(v);
return YES; return YES;
} }
else if (strcmp(ptr, "gdomap") == 0) else if (strcmp(ptr, "gdomap") == 0)
{ {
gsu16 v; uint16_t v;
#ifdef GDOMAP_PORT_OVERRIDE #ifdef GDOMAP_PORT_OVERRIDE
v = GDOMAP_PORT_OVERRIDE; v = GDOMAP_PORT_OVERRIDE;
#else #else

View file

@ -79,8 +79,8 @@ typedef enum {
* Its contents are transmitted in network byte order. * Its contents are transmitted in network byte order.
*/ */
typedef struct { typedef struct {
gsu32 type; /* A GSPortItemType as a 4-byte number. */ uint32_t type; /* A GSPortItemType as a 4-byte number. */
gsu32 length; /* The length of the item (excluding header). */ uint32_t length; /* The length of the item (excluding header). */
} GSPortItemHeader; } GSPortItemHeader;
/* /*
@ -90,8 +90,8 @@ typedef struct {
* NB. additional data counts as part of the same item. * NB. additional data counts as part of the same item.
*/ */
typedef struct { typedef struct {
gsu32 mId; /* The ID for the message starting with this. */ uint32_t mId; /* The ID for the message starting with this. */
gsu32 nItems; /* Number of items (including this one). */ uint32_t nItems; /* Number of items (including this one). */
unsigned char version; unsigned char version;
unsigned char port[16]; unsigned char port[16];
} GSPortMsgHeader; } GSPortMsgHeader;
@ -135,10 +135,6 @@ static NSRecursiveLock *messagePortLock = nil;
static NSMapTable *ports = 0; static NSMapTable *ports = 0;
static Class messagePortClass = 0; static Class messagePortClass = 0;
#if NEED_WORD_ALIGNMENT
static unsigned wordAlign;
#endif
- (BOOL) _setupSendPort - (BOOL) _setupSendPort
{ {
internal *this = (internal*)self->_internal; internal *this = (internal*)self->_internal;
@ -183,9 +179,6 @@ static unsigned wordAlign;
{ {
if (self == [NSMessagePort class]) if (self == [NSMessagePort class])
{ {
#if NEED_WORD_ALIGNMENT
wordAlign = objc_alignof_type(@encode(gsu32));
#endif
messagePortClass = self; messagePortClass = self;
ports = NSCreateMapTable(NSNonRetainedObjectMapKeyCallBacks, ports = NSCreateMapTable(NSNonRetainedObjectMapKeyCallBacks,
NSNonOwnedPointerMapValueCallBacks, 0); NSNonOwnedPointerMapValueCallBacks, 0);