2002-07-02 21:43:03 +02:00
|
|
|
/* GNU Objective C Runtime archiving
|
|
|
|
Copyright (C) 1993, 1995, 1996, 1997, 2002 Free Software Foundation, Inc.
|
1998-09-21 03:22:07 +02:00
|
|
|
Contributed by Kresten Krab Thorup
|
|
|
|
|
Makefile.in, [...]: Replace "GNU CC" with "GCC".
2003-05-23 Nathanael Nerode <neroden@gcc.gnu.org>
* Makefile.in, NXConstStr.m, Object.m, Protocol.m, archive.c,
class.c, encoding.c, gc.c, objc/NXConstStr.h, objc/Object.h,
objc/Protocol.h, objc/encoding.h, objc/hash.h, objc/objc-api.h,
objc/objc-list.h, objc/objc.h, ocjc/runtime.h, objc/sarray.h,
objc/thr.h, objc/typedstream.h: Replace "GNU CC" with "GCC".
From-SVN: r67131
2003-05-23 22:04:58 +02:00
|
|
|
This file is part of GCC.
|
1998-09-21 03:22:07 +02:00
|
|
|
|
Makefile.in, [...]: Replace "GNU CC" with "GCC".
2003-05-23 Nathanael Nerode <neroden@gcc.gnu.org>
* Makefile.in, NXConstStr.m, Object.m, Protocol.m, archive.c,
class.c, encoding.c, gc.c, objc/NXConstStr.h, objc/Object.h,
objc/Protocol.h, objc/encoding.h, objc/hash.h, objc/objc-api.h,
objc/objc-list.h, objc/objc.h, ocjc/runtime.h, objc/sarray.h,
objc/thr.h, objc/typedstream.h: Replace "GNU CC" with "GCC".
From-SVN: r67131
2003-05-23 22:04:58 +02:00
|
|
|
GCC is free software; you can redistribute it and/or modify it under the
|
1998-09-21 03:22:07 +02:00
|
|
|
terms of the GNU General Public License as published by the Free Software
|
|
|
|
Foundation; either version 2, or (at your option) any later version.
|
|
|
|
|
Makefile.in, [...]: Replace "GNU CC" with "GCC".
2003-05-23 Nathanael Nerode <neroden@gcc.gnu.org>
* Makefile.in, NXConstStr.m, Object.m, Protocol.m, archive.c,
class.c, encoding.c, gc.c, objc/NXConstStr.h, objc/Object.h,
objc/Protocol.h, objc/encoding.h, objc/hash.h, objc/objc-api.h,
objc/objc-list.h, objc/objc.h, ocjc/runtime.h, objc/sarray.h,
objc/thr.h, objc/typedstream.h: Replace "GNU CC" with "GCC".
From-SVN: r67131
2003-05-23 22:04:58 +02:00
|
|
|
GCC is distributed in the hope that it will be useful, but WITHOUT ANY
|
1998-09-21 03:22:07 +02:00
|
|
|
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
|
|
|
FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
|
|
|
|
details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License along with
|
Makefile.in, [...]: Replace "GNU CC" with "GCC".
2003-05-23 Nathanael Nerode <neroden@gcc.gnu.org>
* Makefile.in, NXConstStr.m, Object.m, Protocol.m, archive.c,
class.c, encoding.c, gc.c, objc/NXConstStr.h, objc/Object.h,
objc/Protocol.h, objc/encoding.h, objc/hash.h, objc/objc-api.h,
objc/objc-list.h, objc/objc.h, ocjc/runtime.h, objc/sarray.h,
objc/thr.h, objc/typedstream.h: Replace "GNU CC" with "GCC".
From-SVN: r67131
2003-05-23 22:04:58 +02:00
|
|
|
GCC; see the file COPYING. If not, write to the Free Software
|
1998-09-21 03:22:07 +02:00
|
|
|
Foundation, 59 Temple Place - Suite 330,
|
|
|
|
Boston, MA 02111-1307, USA. */
|
|
|
|
|
|
|
|
/* As a special exception, if you link this library with files compiled with
|
|
|
|
GCC to produce an executable, this does not cause the resulting executable
|
|
|
|
to be covered by the GNU General Public License. This exception does not
|
|
|
|
however invalidate any other reasons why the executable file might be
|
|
|
|
covered by the GNU General Public License. */
|
|
|
|
|
1998-10-01 23:35:22 +02:00
|
|
|
#include "tconfig.h"
|
1998-09-21 03:22:07 +02:00
|
|
|
#include "runtime.h"
|
|
|
|
#include "typedstream.h"
|
|
|
|
#include "encoding.h"
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
2002-07-02 21:43:03 +02:00
|
|
|
extern int fflush (FILE *);
|
1998-09-21 03:22:07 +02:00
|
|
|
|
|
|
|
#define ROUND(V, A) \
|
2002-07-02 21:43:03 +02:00
|
|
|
({ typeof (V) __v = (V); typeof (A) __a = (A); \
|
|
|
|
__a * ((__v + __a - 1)/__a); })
|
1998-09-21 03:22:07 +02:00
|
|
|
|
2002-07-02 21:43:03 +02:00
|
|
|
#define PTR2LONG(P) (((char *) (P))-(char *) 0)
|
|
|
|
#define LONG2PTR(L) (((char *) 0) + (L))
|
1998-09-21 03:22:07 +02:00
|
|
|
|
|
|
|
/* Declare some functions... */
|
|
|
|
|
|
|
|
static int
|
2002-07-02 21:43:03 +02:00
|
|
|
objc_read_class (struct objc_typed_stream *stream, Class *class);
|
1998-09-21 03:22:07 +02:00
|
|
|
|
2002-07-02 21:43:03 +02:00
|
|
|
int objc_sizeof_type (const char *type);
|
1998-09-21 03:22:07 +02:00
|
|
|
|
|
|
|
static int
|
2002-07-02 21:43:03 +02:00
|
|
|
objc_write_use_common (struct objc_typed_stream *stream, unsigned long key);
|
1998-09-21 03:22:07 +02:00
|
|
|
|
|
|
|
static int
|
2002-07-02 21:43:03 +02:00
|
|
|
objc_write_register_common (struct objc_typed_stream *stream,
|
1998-09-21 03:22:07 +02:00
|
|
|
unsigned long key);
|
|
|
|
|
|
|
|
static int
|
2002-07-02 21:43:03 +02:00
|
|
|
objc_write_class (struct objc_typed_stream *stream,
|
|
|
|
struct objc_class *class);
|
1998-09-21 03:22:07 +02:00
|
|
|
|
2002-07-02 21:43:03 +02:00
|
|
|
const char *objc_skip_type (const char *type);
|
1998-09-21 03:22:07 +02:00
|
|
|
|
2002-07-02 21:43:03 +02:00
|
|
|
static void __objc_finish_write_root_object (struct objc_typed_stream *);
|
|
|
|
static void __objc_finish_read_root_object (struct objc_typed_stream *);
|
1998-09-21 03:22:07 +02:00
|
|
|
|
|
|
|
static __inline__ int
|
2002-07-02 21:43:03 +02:00
|
|
|
__objc_code_unsigned_char (unsigned char *buf, unsigned char val)
|
1998-09-21 03:22:07 +02:00
|
|
|
{
|
|
|
|
if ((val&_B_VALUE) == val)
|
|
|
|
{
|
|
|
|
buf[0] = val|_B_SINT;
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
buf[0] = _B_NINT|0x01;
|
|
|
|
buf[1] = val;
|
|
|
|
return 2;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2002-07-02 21:43:03 +02:00
|
|
|
objc_write_unsigned_char (struct objc_typed_stream *stream,
|
1998-09-21 03:22:07 +02:00
|
|
|
unsigned char value)
|
|
|
|
{
|
2002-07-02 21:43:03 +02:00
|
|
|
unsigned char buf[sizeof (unsigned char) + 1];
|
1998-09-21 03:22:07 +02:00
|
|
|
int len = __objc_code_unsigned_char (buf, value);
|
2002-07-02 21:43:03 +02:00
|
|
|
return (*stream->write) (stream->physical, buf, len);
|
1998-09-21 03:22:07 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static __inline__ int
|
2002-07-02 21:43:03 +02:00
|
|
|
__objc_code_char (unsigned char *buf, signed char val)
|
1998-09-21 03:22:07 +02:00
|
|
|
{
|
|
|
|
if (val >= 0)
|
|
|
|
return __objc_code_unsigned_char (buf, val);
|
|
|
|
else
|
|
|
|
{
|
|
|
|
buf[0] = _B_NINT|_B_SIGN|0x01;
|
|
|
|
buf[1] = -val;
|
|
|
|
return 2;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2002-07-02 21:43:03 +02:00
|
|
|
objc_write_char (struct objc_typed_stream *stream, signed char value)
|
1998-09-21 03:22:07 +02:00
|
|
|
{
|
2002-07-02 21:43:03 +02:00
|
|
|
unsigned char buf[sizeof (char) + 1];
|
1998-09-21 03:22:07 +02:00
|
|
|
int len = __objc_code_char (buf, value);
|
2002-07-02 21:43:03 +02:00
|
|
|
return (*stream->write) (stream->physical, buf, len);
|
1998-09-21 03:22:07 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static __inline__ int
|
2002-07-02 21:43:03 +02:00
|
|
|
__objc_code_unsigned_short (unsigned char *buf, unsigned short val)
|
1998-09-21 03:22:07 +02:00
|
|
|
{
|
|
|
|
if ((val&_B_VALUE) == val)
|
|
|
|
{
|
|
|
|
buf[0] = val|_B_SINT;
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
int c, b;
|
|
|
|
|
|
|
|
buf[0] = _B_NINT;
|
|
|
|
|
2002-07-02 21:43:03 +02:00
|
|
|
for (c = sizeof (short); c != 0; c -= 1)
|
|
|
|
if (((val >> (8*(c - 1)))%0x100) != 0)
|
1998-09-21 03:22:07 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
buf[0] |= c;
|
|
|
|
|
|
|
|
for (b = 1; c != 0; c--, b++)
|
|
|
|
{
|
2002-07-02 21:43:03 +02:00
|
|
|
buf[b] = (val >> (8*(c - 1)))%0x100;
|
1998-09-21 03:22:07 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return b;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2002-07-02 21:43:03 +02:00
|
|
|
objc_write_unsigned_short (struct objc_typed_stream *stream,
|
1998-09-21 03:22:07 +02:00
|
|
|
unsigned short value)
|
|
|
|
{
|
2002-07-02 21:43:03 +02:00
|
|
|
unsigned char buf[sizeof (unsigned short) + 1];
|
1998-09-21 03:22:07 +02:00
|
|
|
int len = __objc_code_unsigned_short (buf, value);
|
2002-07-02 21:43:03 +02:00
|
|
|
return (*stream->write) (stream->physical, buf, len);
|
1998-09-21 03:22:07 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static __inline__ int
|
2002-07-02 21:43:03 +02:00
|
|
|
__objc_code_short (unsigned char *buf, short val)
|
1998-09-21 03:22:07 +02:00
|
|
|
{
|
|
|
|
int sign = (val < 0);
|
|
|
|
int size = __objc_code_unsigned_short (buf, sign ? -val : val);
|
|
|
|
if (sign)
|
|
|
|
buf[0] |= _B_SIGN;
|
|
|
|
return size;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2002-07-02 21:43:03 +02:00
|
|
|
objc_write_short (struct objc_typed_stream *stream, short value)
|
1998-09-21 03:22:07 +02:00
|
|
|
{
|
2002-07-02 21:43:03 +02:00
|
|
|
unsigned char buf[sizeof (short) + 1];
|
1998-09-21 03:22:07 +02:00
|
|
|
int len = __objc_code_short (buf, value);
|
2002-07-02 21:43:03 +02:00
|
|
|
return (*stream->write) (stream->physical, buf, len);
|
1998-09-21 03:22:07 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static __inline__ int
|
2002-07-02 21:43:03 +02:00
|
|
|
__objc_code_unsigned_int (unsigned char *buf, unsigned int val)
|
1998-09-21 03:22:07 +02:00
|
|
|
{
|
|
|
|
if ((val&_B_VALUE) == val)
|
|
|
|
{
|
|
|
|
buf[0] = val|_B_SINT;
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
int c, b;
|
|
|
|
|
|
|
|
buf[0] = _B_NINT;
|
|
|
|
|
2002-07-02 21:43:03 +02:00
|
|
|
for (c = sizeof (int); c != 0; c -= 1)
|
|
|
|
if (((val >> (8*(c - 1)))%0x100) != 0)
|
1998-09-21 03:22:07 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
buf[0] |= c;
|
|
|
|
|
|
|
|
for (b = 1; c != 0; c--, b++)
|
|
|
|
{
|
|
|
|
buf[b] = (val >> (8*(c-1)))%0x100;
|
|
|
|
}
|
|
|
|
|
|
|
|
return b;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2002-07-02 21:43:03 +02:00
|
|
|
objc_write_unsigned_int (struct objc_typed_stream *stream, unsigned int value)
|
1998-09-21 03:22:07 +02:00
|
|
|
{
|
2002-07-02 21:43:03 +02:00
|
|
|
unsigned char buf[sizeof (unsigned int) + 1];
|
1998-09-21 03:22:07 +02:00
|
|
|
int len = __objc_code_unsigned_int (buf, value);
|
2002-07-02 21:43:03 +02:00
|
|
|
return (*stream->write) (stream->physical, buf, len);
|
1998-09-21 03:22:07 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static __inline__ int
|
2002-07-02 21:43:03 +02:00
|
|
|
__objc_code_int (unsigned char *buf, int val)
|
1998-09-21 03:22:07 +02:00
|
|
|
{
|
|
|
|
int sign = (val < 0);
|
|
|
|
int size = __objc_code_unsigned_int (buf, sign ? -val : val);
|
|
|
|
if (sign)
|
|
|
|
buf[0] |= _B_SIGN;
|
|
|
|
return size;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2002-07-02 21:43:03 +02:00
|
|
|
objc_write_int (struct objc_typed_stream *stream, int value)
|
1998-09-21 03:22:07 +02:00
|
|
|
{
|
2002-07-02 21:43:03 +02:00
|
|
|
unsigned char buf[sizeof (int) + 1];
|
1998-09-21 03:22:07 +02:00
|
|
|
int len = __objc_code_int (buf, value);
|
2002-07-02 21:43:03 +02:00
|
|
|
return (*stream->write) (stream->physical, buf, len);
|
1998-09-21 03:22:07 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static __inline__ int
|
2002-07-02 21:43:03 +02:00
|
|
|
__objc_code_unsigned_long (unsigned char *buf, unsigned long val)
|
1998-09-21 03:22:07 +02:00
|
|
|
{
|
|
|
|
if ((val&_B_VALUE) == val)
|
|
|
|
{
|
|
|
|
buf[0] = val|_B_SINT;
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
int c, b;
|
|
|
|
|
|
|
|
buf[0] = _B_NINT;
|
|
|
|
|
2002-07-02 21:43:03 +02:00
|
|
|
for (c = sizeof (long); c != 0; c -= 1)
|
|
|
|
if (((val >> (8*(c - 1)))%0x100) != 0)
|
1998-09-21 03:22:07 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
buf[0] |= c;
|
|
|
|
|
|
|
|
for (b = 1; c != 0; c--, b++)
|
|
|
|
{
|
2002-07-02 21:43:03 +02:00
|
|
|
buf[b] = (val >> (8*(c - 1)))%0x100;
|
1998-09-21 03:22:07 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return b;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2002-07-02 21:43:03 +02:00
|
|
|
objc_write_unsigned_long (struct objc_typed_stream *stream,
|
1998-09-21 03:22:07 +02:00
|
|
|
unsigned long value)
|
|
|
|
{
|
2002-07-02 21:43:03 +02:00
|
|
|
unsigned char buf[sizeof (unsigned long) + 1];
|
1998-09-21 03:22:07 +02:00
|
|
|
int len = __objc_code_unsigned_long (buf, value);
|
2002-07-02 21:43:03 +02:00
|
|
|
return (*stream->write) (stream->physical, buf, len);
|
1998-09-21 03:22:07 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static __inline__ int
|
2002-07-02 21:43:03 +02:00
|
|
|
__objc_code_long (unsigned char *buf, long val)
|
1998-09-21 03:22:07 +02:00
|
|
|
{
|
|
|
|
int sign = (val < 0);
|
|
|
|
int size = __objc_code_unsigned_long (buf, sign ? -val : val);
|
|
|
|
if (sign)
|
|
|
|
buf[0] |= _B_SIGN;
|
|
|
|
return size;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2002-07-02 21:43:03 +02:00
|
|
|
objc_write_long (struct objc_typed_stream *stream, long value)
|
1998-09-21 03:22:07 +02:00
|
|
|
{
|
2002-07-02 21:43:03 +02:00
|
|
|
unsigned char buf[sizeof (long) + 1];
|
1998-09-21 03:22:07 +02:00
|
|
|
int len = __objc_code_long (buf, value);
|
2002-07-02 21:43:03 +02:00
|
|
|
return (*stream->write) (stream->physical, buf, len);
|
1998-09-21 03:22:07 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int
|
2002-07-02 21:43:03 +02:00
|
|
|
objc_write_string (struct objc_typed_stream *stream,
|
|
|
|
const unsigned char *string, unsigned int nbytes)
|
1998-09-21 03:22:07 +02:00
|
|
|
{
|
2002-07-02 21:43:03 +02:00
|
|
|
unsigned char buf[sizeof (unsigned int) + 1];
|
1998-09-21 03:22:07 +02:00
|
|
|
int len = __objc_code_unsigned_int (buf, nbytes);
|
|
|
|
|
|
|
|
if ((buf[0]&_B_CODE) == _B_SINT)
|
|
|
|
buf[0] = (buf[0]&_B_VALUE)|_B_SSTR;
|
|
|
|
|
|
|
|
else /* _B_NINT */
|
|
|
|
buf[0] = (buf[0]&_B_VALUE)|_B_NSTR;
|
|
|
|
|
2002-07-02 21:43:03 +02:00
|
|
|
if ((*stream->write) (stream->physical, buf, len) != 0)
|
|
|
|
return (*stream->write) (stream->physical, string, nbytes);
|
1998-09-21 03:22:07 +02:00
|
|
|
else
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2002-07-02 21:43:03 +02:00
|
|
|
objc_write_string_atomic (struct objc_typed_stream *stream,
|
|
|
|
unsigned char *string, unsigned int nbytes)
|
1998-09-21 03:22:07 +02:00
|
|
|
{
|
|
|
|
unsigned long key;
|
|
|
|
if ((key = PTR2LONG(hash_value_for_key (stream->stream_table, string))))
|
|
|
|
return objc_write_use_common (stream, key);
|
|
|
|
else
|
|
|
|
{
|
|
|
|
int length;
|
|
|
|
hash_add (&stream->stream_table, LONG2PTR(key=PTR2LONG(string)), string);
|
|
|
|
if ((length = objc_write_register_common (stream, key)))
|
|
|
|
return objc_write_string (stream, string, nbytes);
|
|
|
|
return length;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2002-07-02 21:43:03 +02:00
|
|
|
objc_write_register_common (struct objc_typed_stream *stream,
|
1998-09-21 03:22:07 +02:00
|
|
|
unsigned long key)
|
|
|
|
{
|
|
|
|
unsigned char buf[sizeof (unsigned long)+2];
|
2002-07-02 21:43:03 +02:00
|
|
|
int len = __objc_code_unsigned_long (buf + 1, key);
|
1998-09-21 03:22:07 +02:00
|
|
|
if (len == 1)
|
|
|
|
{
|
|
|
|
buf[0] = _B_RCOMM|0x01;
|
|
|
|
buf[1] &= _B_VALUE;
|
2002-07-02 21:43:03 +02:00
|
|
|
return (*stream->write) (stream->physical, buf, len + 1);
|
1998-09-21 03:22:07 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
buf[1] = (buf[1]&_B_VALUE)|_B_RCOMM;
|
2002-07-02 21:43:03 +02:00
|
|
|
return (*stream->write) (stream->physical, buf + 1, len);
|
1998-09-21 03:22:07 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2002-07-02 21:43:03 +02:00
|
|
|
objc_write_use_common (struct objc_typed_stream *stream, unsigned long key)
|
1998-09-21 03:22:07 +02:00
|
|
|
{
|
|
|
|
unsigned char buf[sizeof (unsigned long)+2];
|
2002-07-02 21:43:03 +02:00
|
|
|
int len = __objc_code_unsigned_long (buf + 1, key);
|
1998-09-21 03:22:07 +02:00
|
|
|
if (len == 1)
|
|
|
|
{
|
|
|
|
buf[0] = _B_UCOMM|0x01;
|
|
|
|
buf[1] &= _B_VALUE;
|
2002-07-02 21:43:03 +02:00
|
|
|
return (*stream->write) (stream->physical, buf, 2);
|
1998-09-21 03:22:07 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
buf[1] = (buf[1]&_B_VALUE)|_B_UCOMM;
|
2002-07-02 21:43:03 +02:00
|
|
|
return (*stream->write) (stream->physical, buf + 1, len);
|
1998-09-21 03:22:07 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static __inline__ int
|
2002-07-02 21:43:03 +02:00
|
|
|
__objc_write_extension (struct objc_typed_stream *stream, unsigned char code)
|
1998-09-21 03:22:07 +02:00
|
|
|
{
|
|
|
|
if (code <= _B_VALUE)
|
|
|
|
{
|
|
|
|
unsigned char buf = code|_B_EXT;
|
2002-07-02 21:43:03 +02:00
|
|
|
return (*stream->write) (stream->physical, &buf, 1);
|
1998-09-21 03:22:07 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2002-07-02 21:43:03 +02:00
|
|
|
objc_error (nil, OBJC_ERR_BAD_OPCODE,
|
|
|
|
"__objc_write_extension: bad opcode %c\n", code);
|
1998-09-21 03:22:07 +02:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
__inline__ int
|
2002-07-02 21:43:03 +02:00
|
|
|
__objc_write_object (struct objc_typed_stream *stream, id object)
|
1998-09-21 03:22:07 +02:00
|
|
|
{
|
|
|
|
unsigned char buf = '\0';
|
|
|
|
SEL write_sel = sel_get_any_uid ("write:");
|
|
|
|
if (object)
|
|
|
|
{
|
|
|
|
__objc_write_extension (stream, _BX_OBJECT);
|
|
|
|
objc_write_class (stream, object->class_pointer);
|
2002-07-02 21:43:03 +02:00
|
|
|
(*objc_msg_lookup (object, write_sel)) (object, write_sel, stream);
|
|
|
|
return (*stream->write) (stream->physical, &buf, 1);
|
1998-09-21 03:22:07 +02:00
|
|
|
}
|
|
|
|
else
|
2002-07-02 21:43:03 +02:00
|
|
|
return objc_write_use_common (stream, 0);
|
1998-09-21 03:22:07 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2002-07-02 21:43:03 +02:00
|
|
|
objc_write_object_reference (struct objc_typed_stream *stream, id object)
|
1998-09-21 03:22:07 +02:00
|
|
|
{
|
|
|
|
unsigned long key;
|
|
|
|
if ((key = PTR2LONG(hash_value_for_key (stream->object_table, object))))
|
|
|
|
return objc_write_use_common (stream, key);
|
|
|
|
|
|
|
|
__objc_write_extension (stream, _BX_OBJREF);
|
|
|
|
return objc_write_unsigned_long (stream, PTR2LONG (object));
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2002-07-02 21:43:03 +02:00
|
|
|
objc_write_root_object (struct objc_typed_stream *stream, id object)
|
1998-09-21 03:22:07 +02:00
|
|
|
{
|
|
|
|
int len = 0;
|
|
|
|
if (stream->writing_root_p)
|
|
|
|
objc_error (nil, OBJC_ERR_RECURSE_ROOT,
|
|
|
|
"objc_write_root_object called recursively");
|
|
|
|
else
|
|
|
|
{
|
|
|
|
stream->writing_root_p = 1;
|
|
|
|
__objc_write_extension (stream, _BX_OBJROOT);
|
2002-07-02 21:43:03 +02:00
|
|
|
if ((len = objc_write_object (stream, object)))
|
|
|
|
__objc_finish_write_root_object (stream);
|
1998-09-21 03:22:07 +02:00
|
|
|
stream->writing_root_p = 0;
|
|
|
|
}
|
|
|
|
return len;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2002-07-02 21:43:03 +02:00
|
|
|
objc_write_object (struct objc_typed_stream *stream, id object)
|
1998-09-21 03:22:07 +02:00
|
|
|
{
|
|
|
|
unsigned long key;
|
|
|
|
if ((key = PTR2LONG(hash_value_for_key (stream->object_table, object))))
|
|
|
|
return objc_write_use_common (stream, key);
|
|
|
|
|
|
|
|
else if (object == nil)
|
2002-07-02 21:43:03 +02:00
|
|
|
return objc_write_use_common (stream, 0);
|
1998-09-21 03:22:07 +02:00
|
|
|
|
|
|
|
else
|
|
|
|
{
|
|
|
|
int length;
|
|
|
|
hash_add (&stream->object_table, LONG2PTR(key=PTR2LONG(object)), object);
|
|
|
|
if ((length = objc_write_register_common (stream, key)))
|
|
|
|
return __objc_write_object (stream, object);
|
|
|
|
return length;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
__inline__ int
|
2002-07-02 21:43:03 +02:00
|
|
|
__objc_write_class (struct objc_typed_stream *stream, struct objc_class *class)
|
1998-09-21 03:22:07 +02:00
|
|
|
{
|
|
|
|
__objc_write_extension (stream, _BX_CLASS);
|
2002-07-02 21:43:03 +02:00
|
|
|
objc_write_string_atomic (stream, (char *) class->name,
|
|
|
|
strlen ((char *) class->name));
|
1998-09-21 03:22:07 +02:00
|
|
|
return objc_write_unsigned_long (stream, class->version);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static int
|
2002-07-02 21:43:03 +02:00
|
|
|
objc_write_class (struct objc_typed_stream *stream,
|
|
|
|
struct objc_class *class)
|
1998-09-21 03:22:07 +02:00
|
|
|
{
|
|
|
|
unsigned long key;
|
|
|
|
if ((key = PTR2LONG(hash_value_for_key (stream->stream_table, class))))
|
|
|
|
return objc_write_use_common (stream, key);
|
|
|
|
else
|
|
|
|
{
|
|
|
|
int length;
|
2002-07-02 21:43:03 +02:00
|
|
|
hash_add (&stream->stream_table, LONG2PTR(key = PTR2LONG(class)), class);
|
1998-09-21 03:22:07 +02:00
|
|
|
if ((length = objc_write_register_common (stream, key)))
|
|
|
|
return __objc_write_class (stream, class);
|
|
|
|
return length;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
__inline__ int
|
2002-07-02 21:43:03 +02:00
|
|
|
__objc_write_selector (struct objc_typed_stream *stream, SEL selector)
|
1998-09-21 03:22:07 +02:00
|
|
|
{
|
2002-07-02 21:43:03 +02:00
|
|
|
const char *sel_name;
|
1998-09-21 03:22:07 +02:00
|
|
|
__objc_write_extension (stream, _BX_SEL);
|
|
|
|
/* to handle NULL selectors */
|
|
|
|
if ((SEL)0 == selector)
|
|
|
|
return objc_write_string (stream, "", 0);
|
|
|
|
sel_name = sel_get_name (selector);
|
|
|
|
return objc_write_string (stream, sel_name, strlen ((char*)sel_name));
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2002-07-02 21:43:03 +02:00
|
|
|
objc_write_selector (struct objc_typed_stream *stream, SEL selector)
|
1998-09-21 03:22:07 +02:00
|
|
|
{
|
2002-07-02 21:43:03 +02:00
|
|
|
const char *sel_name;
|
1998-09-21 03:22:07 +02:00
|
|
|
unsigned long key;
|
|
|
|
|
|
|
|
/* to handle NULL selectors */
|
|
|
|
if ((SEL)0 == selector)
|
|
|
|
return __objc_write_selector (stream, selector);
|
|
|
|
|
|
|
|
sel_name = sel_get_name (selector);
|
|
|
|
if ((key = PTR2LONG(hash_value_for_key (stream->stream_table, sel_name))))
|
|
|
|
return objc_write_use_common (stream, key);
|
|
|
|
else
|
|
|
|
{
|
|
|
|
int length;
|
|
|
|
hash_add (&stream->stream_table,
|
2002-07-02 21:43:03 +02:00
|
|
|
LONG2PTR(key = PTR2LONG(sel_name)), (char *) sel_name);
|
1998-09-21 03:22:07 +02:00
|
|
|
if ((length = objc_write_register_common (stream, key)))
|
|
|
|
return __objc_write_selector (stream, selector);
|
|
|
|
return length;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
** Read operations
|
|
|
|
*/
|
|
|
|
|
|
|
|
__inline__ int
|
2002-07-02 21:43:03 +02:00
|
|
|
objc_read_char (struct objc_typed_stream *stream, char *val)
|
1998-09-21 03:22:07 +02:00
|
|
|
{
|
|
|
|
unsigned char buf;
|
|
|
|
int len;
|
2002-07-02 21:43:03 +02:00
|
|
|
len = (*stream->read) (stream->physical, &buf, 1);
|
1998-09-21 03:22:07 +02:00
|
|
|
if (len != 0)
|
|
|
|
{
|
|
|
|
if ((buf & _B_CODE) == _B_SINT)
|
|
|
|
(*val) = (buf & _B_VALUE);
|
|
|
|
|
|
|
|
else if ((buf & _B_NUMBER) == 1)
|
|
|
|
{
|
2002-07-02 21:43:03 +02:00
|
|
|
len = (*stream->read) (stream->physical, val, 1);
|
1998-09-21 03:22:07 +02:00
|
|
|
if (buf&_B_SIGN)
|
2002-07-02 21:43:03 +02:00
|
|
|
(*val) = -1 * (*val);
|
1998-09-21 03:22:07 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
else
|
2002-07-02 21:43:03 +02:00
|
|
|
objc_error (nil, OBJC_ERR_BAD_DATA,
|
|
|
|
"expected 8bit signed int, got %dbit int",
|
|
|
|
(int) (buf&_B_NUMBER)*8);
|
1998-09-21 03:22:07 +02:00
|
|
|
}
|
|
|
|
return len;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
__inline__ int
|
2002-07-02 21:43:03 +02:00
|
|
|
objc_read_unsigned_char (struct objc_typed_stream *stream, unsigned char *val)
|
1998-09-21 03:22:07 +02:00
|
|
|
{
|
|
|
|
unsigned char buf;
|
|
|
|
int len;
|
2002-07-02 21:43:03 +02:00
|
|
|
if ((len = (*stream->read) (stream->physical, &buf, 1)))
|
1998-09-21 03:22:07 +02:00
|
|
|
{
|
|
|
|
if ((buf & _B_CODE) == _B_SINT)
|
|
|
|
(*val) = (buf & _B_VALUE);
|
|
|
|
|
|
|
|
else if ((buf & _B_NUMBER) == 1)
|
2002-07-02 21:43:03 +02:00
|
|
|
len = (*stream->read) (stream->physical, val, 1);
|
1998-09-21 03:22:07 +02:00
|
|
|
|
|
|
|
else
|
2002-07-02 21:43:03 +02:00
|
|
|
objc_error (nil, OBJC_ERR_BAD_DATA,
|
|
|
|
"expected 8bit unsigned int, got %dbit int",
|
|
|
|
(int) (buf&_B_NUMBER)*8);
|
1998-09-21 03:22:07 +02:00
|
|
|
}
|
|
|
|
return len;
|
|
|
|
}
|
|
|
|
|
|
|
|
__inline__ int
|
2002-07-02 21:43:03 +02:00
|
|
|
objc_read_short (struct objc_typed_stream *stream, short *value)
|
1998-09-21 03:22:07 +02:00
|
|
|
{
|
2002-07-02 21:43:03 +02:00
|
|
|
unsigned char buf[sizeof (short) + 1];
|
1998-09-21 03:22:07 +02:00
|
|
|
int len;
|
2002-07-02 21:43:03 +02:00
|
|
|
if ((len = (*stream->read) (stream->physical, buf, 1)))
|
1998-09-21 03:22:07 +02:00
|
|
|
{
|
|
|
|
if ((buf[0] & _B_CODE) == _B_SINT)
|
|
|
|
(*value) = (buf[0] & _B_VALUE);
|
|
|
|
|
|
|
|
else
|
|
|
|
{
|
|
|
|
int pos = 1;
|
|
|
|
int nbytes = buf[0] & _B_NUMBER;
|
Object.m: Fix signed/unsigned warning.
* Object.m: Fix signed/unsigned warning.
* Protocol.m: Likewise.
* archive.c: Always include stdlib.h.
(objc_read_short, objc_read_unsigned_short, objc_read_int,
objc_read_long, __objc_read_nbyte_uint, __objc_read_nbyte_ulong):
Fix signed/unsigned warning.
(objc_write_type, objc_read_type, objc_write_types,
objc_read_types): Ensure ctype 8-bit safety.
(__objc_no_write, __objc_no_read): Mark unused parameters.
* class.c (class_table_setup): Specify void arg.
* encoding.c (atoi, objc_sizeof_type, objc_alignof_type,
objc_skip_typespec, objc_skip_offset,
objc_layout_structure_next_member): Ensure ctype 8-bit safety.
(objc_layout_structure_next_member): Ensure variables are
initialized.
* gc.c (__objc_generate_gc_type_description,
class_ivar_set_gcinvisible): Mark unused parameters.
* init.c (__objc_send_load, __objc_destroy_class_tree_node): Mark
unused parameters.
(__objc_init_protocols) Fix signed/unsigned warning.
* nil_method.c (nil_method): Mark unused parameters.
* thr.h (objc_thread_callback): Specify void arg.
* sarray.c (sarray_new, sarray_realloc, sarray_free): Fix
signed/unsigned warning.
(sarray_free): Fix formatting.
* selector.c (sel_types_match): Ensure ctype 8-bit safety.
* sendmsg.c (__objc_init_install_dtable) Mark unused parameters.
From-SVN: r54649
2002-06-15 19:50:14 +02:00
|
|
|
if (nbytes > (int) sizeof (short))
|
2002-07-02 21:43:03 +02:00
|
|
|
objc_error (nil, OBJC_ERR_BAD_DATA,
|
|
|
|
"expected short, got bigger (%dbits)", nbytes*8);
|
|
|
|
len = (*stream->read) (stream->physical, buf + 1, nbytes);
|
1998-09-21 03:22:07 +02:00
|
|
|
(*value) = 0;
|
|
|
|
while (pos <= nbytes)
|
|
|
|
(*value) = ((*value)*0x100) + buf[pos++];
|
|
|
|
if (buf[0] & _B_SIGN)
|
|
|
|
(*value) = -(*value);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return len;
|
|
|
|
}
|
|
|
|
|
|
|
|
__inline__ int
|
2002-07-02 21:43:03 +02:00
|
|
|
objc_read_unsigned_short (struct objc_typed_stream *stream,
|
|
|
|
unsigned short *value)
|
1998-09-21 03:22:07 +02:00
|
|
|
{
|
2002-07-02 21:43:03 +02:00
|
|
|
unsigned char buf[sizeof (unsigned short) + 1];
|
1998-09-21 03:22:07 +02:00
|
|
|
int len;
|
2002-07-02 21:43:03 +02:00
|
|
|
if ((len = (*stream->read) (stream->physical, buf, 1)))
|
1998-09-21 03:22:07 +02:00
|
|
|
{
|
|
|
|
if ((buf[0] & _B_CODE) == _B_SINT)
|
|
|
|
(*value) = (buf[0] & _B_VALUE);
|
|
|
|
|
|
|
|
else
|
|
|
|
{
|
|
|
|
int pos = 1;
|
|
|
|
int nbytes = buf[0] & _B_NUMBER;
|
Object.m: Fix signed/unsigned warning.
* Object.m: Fix signed/unsigned warning.
* Protocol.m: Likewise.
* archive.c: Always include stdlib.h.
(objc_read_short, objc_read_unsigned_short, objc_read_int,
objc_read_long, __objc_read_nbyte_uint, __objc_read_nbyte_ulong):
Fix signed/unsigned warning.
(objc_write_type, objc_read_type, objc_write_types,
objc_read_types): Ensure ctype 8-bit safety.
(__objc_no_write, __objc_no_read): Mark unused parameters.
* class.c (class_table_setup): Specify void arg.
* encoding.c (atoi, objc_sizeof_type, objc_alignof_type,
objc_skip_typespec, objc_skip_offset,
objc_layout_structure_next_member): Ensure ctype 8-bit safety.
(objc_layout_structure_next_member): Ensure variables are
initialized.
* gc.c (__objc_generate_gc_type_description,
class_ivar_set_gcinvisible): Mark unused parameters.
* init.c (__objc_send_load, __objc_destroy_class_tree_node): Mark
unused parameters.
(__objc_init_protocols) Fix signed/unsigned warning.
* nil_method.c (nil_method): Mark unused parameters.
* thr.h (objc_thread_callback): Specify void arg.
* sarray.c (sarray_new, sarray_realloc, sarray_free): Fix
signed/unsigned warning.
(sarray_free): Fix formatting.
* selector.c (sel_types_match): Ensure ctype 8-bit safety.
* sendmsg.c (__objc_init_install_dtable) Mark unused parameters.
From-SVN: r54649
2002-06-15 19:50:14 +02:00
|
|
|
if (nbytes > (int) sizeof (short))
|
2002-07-02 21:43:03 +02:00
|
|
|
objc_error (nil, OBJC_ERR_BAD_DATA,
|
|
|
|
"expected short, got int or bigger");
|
|
|
|
len = (*stream->read) (stream->physical, buf + 1, nbytes);
|
1998-09-21 03:22:07 +02:00
|
|
|
(*value) = 0;
|
|
|
|
while (pos <= nbytes)
|
|
|
|
(*value) = ((*value)*0x100) + buf[pos++];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return len;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
__inline__ int
|
2002-07-02 21:43:03 +02:00
|
|
|
objc_read_int (struct objc_typed_stream *stream, int *value)
|
1998-09-21 03:22:07 +02:00
|
|
|
{
|
2002-07-02 21:43:03 +02:00
|
|
|
unsigned char buf[sizeof (int) + 1];
|
1998-09-21 03:22:07 +02:00
|
|
|
int len;
|
2002-07-02 21:43:03 +02:00
|
|
|
if ((len = (*stream->read) (stream->physical, buf, 1)))
|
1998-09-21 03:22:07 +02:00
|
|
|
{
|
|
|
|
if ((buf[0] & _B_CODE) == _B_SINT)
|
|
|
|
(*value) = (buf[0] & _B_VALUE);
|
|
|
|
|
|
|
|
else
|
|
|
|
{
|
|
|
|
int pos = 1;
|
|
|
|
int nbytes = buf[0] & _B_NUMBER;
|
Object.m: Fix signed/unsigned warning.
* Object.m: Fix signed/unsigned warning.
* Protocol.m: Likewise.
* archive.c: Always include stdlib.h.
(objc_read_short, objc_read_unsigned_short, objc_read_int,
objc_read_long, __objc_read_nbyte_uint, __objc_read_nbyte_ulong):
Fix signed/unsigned warning.
(objc_write_type, objc_read_type, objc_write_types,
objc_read_types): Ensure ctype 8-bit safety.
(__objc_no_write, __objc_no_read): Mark unused parameters.
* class.c (class_table_setup): Specify void arg.
* encoding.c (atoi, objc_sizeof_type, objc_alignof_type,
objc_skip_typespec, objc_skip_offset,
objc_layout_structure_next_member): Ensure ctype 8-bit safety.
(objc_layout_structure_next_member): Ensure variables are
initialized.
* gc.c (__objc_generate_gc_type_description,
class_ivar_set_gcinvisible): Mark unused parameters.
* init.c (__objc_send_load, __objc_destroy_class_tree_node): Mark
unused parameters.
(__objc_init_protocols) Fix signed/unsigned warning.
* nil_method.c (nil_method): Mark unused parameters.
* thr.h (objc_thread_callback): Specify void arg.
* sarray.c (sarray_new, sarray_realloc, sarray_free): Fix
signed/unsigned warning.
(sarray_free): Fix formatting.
* selector.c (sel_types_match): Ensure ctype 8-bit safety.
* sendmsg.c (__objc_init_install_dtable) Mark unused parameters.
From-SVN: r54649
2002-06-15 19:50:14 +02:00
|
|
|
if (nbytes > (int) sizeof (int))
|
2002-07-02 21:43:03 +02:00
|
|
|
objc_error (nil, OBJC_ERR_BAD_DATA, "expected int, got bigger");
|
|
|
|
len = (*stream->read) (stream->physical, buf + 1, nbytes);
|
1998-09-21 03:22:07 +02:00
|
|
|
(*value) = 0;
|
|
|
|
while (pos <= nbytes)
|
|
|
|
(*value) = ((*value)*0x100) + buf[pos++];
|
|
|
|
if (buf[0] & _B_SIGN)
|
|
|
|
(*value) = -(*value);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return len;
|
|
|
|
}
|
|
|
|
|
|
|
|
__inline__ int
|
2002-07-02 21:43:03 +02:00
|
|
|
objc_read_long (struct objc_typed_stream *stream, long *value)
|
1998-09-21 03:22:07 +02:00
|
|
|
{
|
2002-07-02 21:43:03 +02:00
|
|
|
unsigned char buf[sizeof (long) + 1];
|
1998-09-21 03:22:07 +02:00
|
|
|
int len;
|
2002-07-02 21:43:03 +02:00
|
|
|
if ((len = (*stream->read) (stream->physical, buf, 1)))
|
1998-09-21 03:22:07 +02:00
|
|
|
{
|
|
|
|
if ((buf[0] & _B_CODE) == _B_SINT)
|
|
|
|
(*value) = (buf[0] & _B_VALUE);
|
|
|
|
|
|
|
|
else
|
|
|
|
{
|
|
|
|
int pos = 1;
|
|
|
|
int nbytes = buf[0] & _B_NUMBER;
|
Object.m: Fix signed/unsigned warning.
* Object.m: Fix signed/unsigned warning.
* Protocol.m: Likewise.
* archive.c: Always include stdlib.h.
(objc_read_short, objc_read_unsigned_short, objc_read_int,
objc_read_long, __objc_read_nbyte_uint, __objc_read_nbyte_ulong):
Fix signed/unsigned warning.
(objc_write_type, objc_read_type, objc_write_types,
objc_read_types): Ensure ctype 8-bit safety.
(__objc_no_write, __objc_no_read): Mark unused parameters.
* class.c (class_table_setup): Specify void arg.
* encoding.c (atoi, objc_sizeof_type, objc_alignof_type,
objc_skip_typespec, objc_skip_offset,
objc_layout_structure_next_member): Ensure ctype 8-bit safety.
(objc_layout_structure_next_member): Ensure variables are
initialized.
* gc.c (__objc_generate_gc_type_description,
class_ivar_set_gcinvisible): Mark unused parameters.
* init.c (__objc_send_load, __objc_destroy_class_tree_node): Mark
unused parameters.
(__objc_init_protocols) Fix signed/unsigned warning.
* nil_method.c (nil_method): Mark unused parameters.
* thr.h (objc_thread_callback): Specify void arg.
* sarray.c (sarray_new, sarray_realloc, sarray_free): Fix
signed/unsigned warning.
(sarray_free): Fix formatting.
* selector.c (sel_types_match): Ensure ctype 8-bit safety.
* sendmsg.c (__objc_init_install_dtable) Mark unused parameters.
From-SVN: r54649
2002-06-15 19:50:14 +02:00
|
|
|
if (nbytes > (int) sizeof (long))
|
2002-07-02 21:43:03 +02:00
|
|
|
objc_error (nil, OBJC_ERR_BAD_DATA, "expected long, got bigger");
|
|
|
|
len = (*stream->read) (stream->physical, buf + 1, nbytes);
|
1998-09-21 03:22:07 +02:00
|
|
|
(*value) = 0;
|
|
|
|
while (pos <= nbytes)
|
|
|
|
(*value) = ((*value)*0x100) + buf[pos++];
|
|
|
|
if (buf[0] & _B_SIGN)
|
|
|
|
(*value) = -(*value);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return len;
|
|
|
|
}
|
|
|
|
|
|
|
|
__inline__ int
|
2002-07-02 21:43:03 +02:00
|
|
|
__objc_read_nbyte_uint (struct objc_typed_stream *stream,
|
|
|
|
unsigned int nbytes, unsigned int *val)
|
1998-09-21 03:22:07 +02:00
|
|
|
{
|
Object.m: Fix signed/unsigned warning.
* Object.m: Fix signed/unsigned warning.
* Protocol.m: Likewise.
* archive.c: Always include stdlib.h.
(objc_read_short, objc_read_unsigned_short, objc_read_int,
objc_read_long, __objc_read_nbyte_uint, __objc_read_nbyte_ulong):
Fix signed/unsigned warning.
(objc_write_type, objc_read_type, objc_write_types,
objc_read_types): Ensure ctype 8-bit safety.
(__objc_no_write, __objc_no_read): Mark unused parameters.
* class.c (class_table_setup): Specify void arg.
* encoding.c (atoi, objc_sizeof_type, objc_alignof_type,
objc_skip_typespec, objc_skip_offset,
objc_layout_structure_next_member): Ensure ctype 8-bit safety.
(objc_layout_structure_next_member): Ensure variables are
initialized.
* gc.c (__objc_generate_gc_type_description,
class_ivar_set_gcinvisible): Mark unused parameters.
* init.c (__objc_send_load, __objc_destroy_class_tree_node): Mark
unused parameters.
(__objc_init_protocols) Fix signed/unsigned warning.
* nil_method.c (nil_method): Mark unused parameters.
* thr.h (objc_thread_callback): Specify void arg.
* sarray.c (sarray_new, sarray_realloc, sarray_free): Fix
signed/unsigned warning.
(sarray_free): Fix formatting.
* selector.c (sel_types_match): Ensure ctype 8-bit safety.
* sendmsg.c (__objc_init_install_dtable) Mark unused parameters.
From-SVN: r54649
2002-06-15 19:50:14 +02:00
|
|
|
int len;
|
|
|
|
unsigned int pos = 0;
|
2002-07-02 21:43:03 +02:00
|
|
|
unsigned char buf[sizeof (unsigned int) + 1];
|
1998-09-21 03:22:07 +02:00
|
|
|
|
|
|
|
if (nbytes > sizeof (int))
|
2002-07-02 21:43:03 +02:00
|
|
|
objc_error (nil, OBJC_ERR_BAD_DATA, "expected int, got bigger");
|
1998-09-21 03:22:07 +02:00
|
|
|
|
2002-07-02 21:43:03 +02:00
|
|
|
len = (*stream->read) (stream->physical, buf, nbytes);
|
1998-09-21 03:22:07 +02:00
|
|
|
(*val) = 0;
|
|
|
|
while (pos < nbytes)
|
|
|
|
(*val) = ((*val)*0x100) + buf[pos++];
|
|
|
|
return len;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
__inline__ int
|
2002-07-02 21:43:03 +02:00
|
|
|
objc_read_unsigned_int (struct objc_typed_stream *stream,
|
|
|
|
unsigned int *value)
|
1998-09-21 03:22:07 +02:00
|
|
|
{
|
2002-07-02 21:43:03 +02:00
|
|
|
unsigned char buf[sizeof (unsigned int) + 1];
|
1998-09-21 03:22:07 +02:00
|
|
|
int len;
|
2002-07-02 21:43:03 +02:00
|
|
|
if ((len = (*stream->read) (stream->physical, buf, 1)))
|
1998-09-21 03:22:07 +02:00
|
|
|
{
|
|
|
|
if ((buf[0] & _B_CODE) == _B_SINT)
|
|
|
|
(*value) = (buf[0] & _B_VALUE);
|
|
|
|
|
|
|
|
else
|
|
|
|
len = __objc_read_nbyte_uint (stream, (buf[0] & _B_VALUE), value);
|
|
|
|
|
|
|
|
}
|
|
|
|
return len;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2002-07-02 21:43:03 +02:00
|
|
|
__objc_read_nbyte_ulong (struct objc_typed_stream *stream,
|
|
|
|
unsigned int nbytes, unsigned long *val)
|
1998-09-21 03:22:07 +02:00
|
|
|
{
|
Object.m: Fix signed/unsigned warning.
* Object.m: Fix signed/unsigned warning.
* Protocol.m: Likewise.
* archive.c: Always include stdlib.h.
(objc_read_short, objc_read_unsigned_short, objc_read_int,
objc_read_long, __objc_read_nbyte_uint, __objc_read_nbyte_ulong):
Fix signed/unsigned warning.
(objc_write_type, objc_read_type, objc_write_types,
objc_read_types): Ensure ctype 8-bit safety.
(__objc_no_write, __objc_no_read): Mark unused parameters.
* class.c (class_table_setup): Specify void arg.
* encoding.c (atoi, objc_sizeof_type, objc_alignof_type,
objc_skip_typespec, objc_skip_offset,
objc_layout_structure_next_member): Ensure ctype 8-bit safety.
(objc_layout_structure_next_member): Ensure variables are
initialized.
* gc.c (__objc_generate_gc_type_description,
class_ivar_set_gcinvisible): Mark unused parameters.
* init.c (__objc_send_load, __objc_destroy_class_tree_node): Mark
unused parameters.
(__objc_init_protocols) Fix signed/unsigned warning.
* nil_method.c (nil_method): Mark unused parameters.
* thr.h (objc_thread_callback): Specify void arg.
* sarray.c (sarray_new, sarray_realloc, sarray_free): Fix
signed/unsigned warning.
(sarray_free): Fix formatting.
* selector.c (sel_types_match): Ensure ctype 8-bit safety.
* sendmsg.c (__objc_init_install_dtable) Mark unused parameters.
From-SVN: r54649
2002-06-15 19:50:14 +02:00
|
|
|
int len;
|
|
|
|
unsigned int pos = 0;
|
2002-07-02 21:43:03 +02:00
|
|
|
unsigned char buf[sizeof (unsigned long) + 1];
|
1998-09-21 03:22:07 +02:00
|
|
|
|
|
|
|
if (nbytes > sizeof (long))
|
2002-07-02 21:43:03 +02:00
|
|
|
objc_error (nil, OBJC_ERR_BAD_DATA, "expected long, got bigger");
|
1998-09-21 03:22:07 +02:00
|
|
|
|
2002-07-02 21:43:03 +02:00
|
|
|
len = (*stream->read) (stream->physical, buf, nbytes);
|
1998-09-21 03:22:07 +02:00
|
|
|
(*val) = 0;
|
|
|
|
while (pos < nbytes)
|
|
|
|
(*val) = ((*val)*0x100) + buf[pos++];
|
|
|
|
return len;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
__inline__ int
|
2002-07-02 21:43:03 +02:00
|
|
|
objc_read_unsigned_long (struct objc_typed_stream *stream,
|
|
|
|
unsigned long *value)
|
1998-09-21 03:22:07 +02:00
|
|
|
{
|
2002-07-02 21:43:03 +02:00
|
|
|
unsigned char buf[sizeof (unsigned long) + 1];
|
1998-09-21 03:22:07 +02:00
|
|
|
int len;
|
2002-07-02 21:43:03 +02:00
|
|
|
if ((len = (*stream->read) (stream->physical, buf, 1)))
|
1998-09-21 03:22:07 +02:00
|
|
|
{
|
|
|
|
if ((buf[0] & _B_CODE) == _B_SINT)
|
|
|
|
(*value) = (buf[0] & _B_VALUE);
|
|
|
|
|
|
|
|
else
|
|
|
|
len = __objc_read_nbyte_ulong (stream, (buf[0] & _B_VALUE), value);
|
|
|
|
|
|
|
|
}
|
|
|
|
return len;
|
|
|
|
}
|
|
|
|
|
|
|
|
__inline__ int
|
2002-07-02 21:43:03 +02:00
|
|
|
objc_read_string (struct objc_typed_stream *stream,
|
|
|
|
char **string)
|
1998-09-21 03:22:07 +02:00
|
|
|
{
|
2002-07-02 21:43:03 +02:00
|
|
|
unsigned char buf[sizeof (unsigned int) + 1];
|
1998-09-21 03:22:07 +02:00
|
|
|
int len;
|
2002-07-02 21:43:03 +02:00
|
|
|
if ((len = (*stream->read) (stream->physical, buf, 1)))
|
1998-09-21 03:22:07 +02:00
|
|
|
{
|
|
|
|
unsigned long key = 0;
|
|
|
|
|
|
|
|
if ((buf[0]&_B_CODE) == _B_RCOMM) /* register following */
|
|
|
|
{
|
2002-07-02 21:43:03 +02:00
|
|
|
len = __objc_read_nbyte_ulong (stream, (buf[0] & _B_VALUE), &key);
|
|
|
|
len = (*stream->read) (stream->physical, buf, 1);
|
1998-09-21 03:22:07 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
switch (buf[0]&_B_CODE) {
|
|
|
|
case _B_SSTR:
|
|
|
|
{
|
|
|
|
int length = buf[0]&_B_VALUE;
|
2002-07-02 21:43:03 +02:00
|
|
|
(*string) = (char*)objc_malloc (length + 1);
|
1998-09-21 03:22:07 +02:00
|
|
|
if (key)
|
|
|
|
hash_add (&stream->stream_table, LONG2PTR(key), *string);
|
2002-07-02 21:43:03 +02:00
|
|
|
len = (*stream->read) (stream->physical, *string, length);
|
1998-09-21 03:22:07 +02:00
|
|
|
(*string)[length] = '\0';
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case _B_UCOMM:
|
|
|
|
{
|
|
|
|
char *tmp;
|
2002-07-02 21:43:03 +02:00
|
|
|
len = __objc_read_nbyte_ulong (stream, (buf[0] & _B_VALUE), &key);
|
1998-09-21 03:22:07 +02:00
|
|
|
tmp = hash_value_for_key (stream->stream_table, LONG2PTR (key));
|
2002-07-02 21:43:03 +02:00
|
|
|
*string = objc_malloc (strlen (tmp) + 1);
|
1998-09-21 03:22:07 +02:00
|
|
|
strcpy (*string, tmp);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case _B_NSTR:
|
|
|
|
{
|
|
|
|
unsigned int nbytes = buf[0]&_B_VALUE;
|
2002-07-02 21:43:03 +02:00
|
|
|
len = __objc_read_nbyte_uint (stream, nbytes, &nbytes);
|
1998-09-21 03:22:07 +02:00
|
|
|
if (len) {
|
2002-07-02 21:43:03 +02:00
|
|
|
(*string) = (char*)objc_malloc (nbytes + 1);
|
1998-09-21 03:22:07 +02:00
|
|
|
if (key)
|
|
|
|
hash_add (&stream->stream_table, LONG2PTR(key), *string);
|
2002-07-02 21:43:03 +02:00
|
|
|
len = (*stream->read) (stream->physical, *string, nbytes);
|
1998-09-21 03:22:07 +02:00
|
|
|
(*string)[nbytes] = '\0';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2002-07-02 21:43:03 +02:00
|
|
|
objc_error (nil, OBJC_ERR_BAD_DATA,
|
|
|
|
"expected string, got opcode %c\n", (buf[0]&_B_CODE));
|
1998-09-21 03:22:07 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return len;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int
|
2002-07-02 21:43:03 +02:00
|
|
|
objc_read_object (struct objc_typed_stream *stream, id *object)
|
1998-09-21 03:22:07 +02:00
|
|
|
{
|
|
|
|
unsigned char buf[sizeof (unsigned int)];
|
|
|
|
int len;
|
2002-07-02 21:43:03 +02:00
|
|
|
if ((len = (*stream->read) (stream->physical, buf, 1)))
|
1998-09-21 03:22:07 +02:00
|
|
|
{
|
|
|
|
SEL read_sel = sel_get_any_uid ("read:");
|
|
|
|
unsigned long key = 0;
|
|
|
|
|
|
|
|
if ((buf[0]&_B_CODE) == _B_RCOMM) /* register common */
|
|
|
|
{
|
2002-07-02 21:43:03 +02:00
|
|
|
len = __objc_read_nbyte_ulong (stream, (buf[0] & _B_VALUE), &key);
|
|
|
|
len = (*stream->read) (stream->physical, buf, 1);
|
1998-09-21 03:22:07 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (buf[0] == (_B_EXT | _BX_OBJECT))
|
|
|
|
{
|
|
|
|
Class class;
|
|
|
|
|
|
|
|
/* get class */
|
|
|
|
len = objc_read_class (stream, &class);
|
|
|
|
|
|
|
|
/* create instance */
|
2002-07-02 21:43:03 +02:00
|
|
|
(*object) = class_create_instance (class);
|
1998-09-21 03:22:07 +02:00
|
|
|
|
|
|
|
/* register? */
|
|
|
|
if (key)
|
|
|
|
hash_add (&stream->object_table, LONG2PTR(key), *object);
|
|
|
|
|
|
|
|
/* send -read: */
|
|
|
|
if (__objc_responds_to (*object, read_sel))
|
2002-07-02 21:43:03 +02:00
|
|
|
(*get_imp (class, read_sel)) (*object, read_sel, stream);
|
1998-09-21 03:22:07 +02:00
|
|
|
|
|
|
|
/* check null-byte */
|
2002-07-02 21:43:03 +02:00
|
|
|
len = (*stream->read) (stream->physical, buf, 1);
|
1998-09-21 03:22:07 +02:00
|
|
|
if (buf[0] != '\0')
|
2002-07-02 21:43:03 +02:00
|
|
|
objc_error (nil, OBJC_ERR_BAD_DATA,
|
|
|
|
"expected null-byte, got opcode %c", buf[0]);
|
1998-09-21 03:22:07 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
else if ((buf[0]&_B_CODE) == _B_UCOMM)
|
|
|
|
{
|
|
|
|
if (key)
|
2002-07-02 21:43:03 +02:00
|
|
|
objc_error (nil, OBJC_ERR_BAD_KEY, "cannot register use upcode...");
|
|
|
|
len = __objc_read_nbyte_ulong (stream, (buf[0] & _B_VALUE), &key);
|
1998-09-21 03:22:07 +02:00
|
|
|
(*object) = hash_value_for_key (stream->object_table, LONG2PTR(key));
|
|
|
|
}
|
|
|
|
|
|
|
|
else if (buf[0] == (_B_EXT | _BX_OBJREF)) /* a forward reference */
|
|
|
|
{
|
2002-07-02 21:43:03 +02:00
|
|
|
struct objc_list *other;
|
1998-09-21 03:22:07 +02:00
|
|
|
len = objc_read_unsigned_long (stream, &key);
|
2002-07-02 21:43:03 +02:00
|
|
|
other = (struct objc_list *) hash_value_for_key (stream->object_refs,
|
|
|
|
LONG2PTR(key));
|
1998-09-21 03:22:07 +02:00
|
|
|
hash_add (&stream->object_refs, LONG2PTR(key),
|
2002-07-02 21:43:03 +02:00
|
|
|
(void *)list_cons (object, other));
|
1998-09-21 03:22:07 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
else if (buf[0] == (_B_EXT | _BX_OBJROOT)) /* a root object */
|
|
|
|
{
|
|
|
|
if (key)
|
2002-07-02 21:43:03 +02:00
|
|
|
objc_error (nil, OBJC_ERR_BAD_KEY,
|
|
|
|
"cannot register root object...");
|
1998-09-21 03:22:07 +02:00
|
|
|
len = objc_read_object (stream, object);
|
|
|
|
__objc_finish_read_root_object (stream);
|
|
|
|
}
|
|
|
|
|
|
|
|
else
|
2002-07-02 21:43:03 +02:00
|
|
|
objc_error (nil, OBJC_ERR_BAD_DATA,
|
|
|
|
"expected object, got opcode %c", buf[0]);
|
1998-09-21 03:22:07 +02:00
|
|
|
}
|
|
|
|
return len;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2002-07-02 21:43:03 +02:00
|
|
|
objc_read_class (struct objc_typed_stream *stream, Class *class)
|
1998-09-21 03:22:07 +02:00
|
|
|
{
|
|
|
|
unsigned char buf[sizeof (unsigned int)];
|
|
|
|
int len;
|
2002-07-02 21:43:03 +02:00
|
|
|
if ((len = (*stream->read) (stream->physical, buf, 1)))
|
1998-09-21 03:22:07 +02:00
|
|
|
{
|
|
|
|
unsigned long key = 0;
|
|
|
|
|
|
|
|
if ((buf[0]&_B_CODE) == _B_RCOMM) /* register following */
|
|
|
|
{
|
2002-07-02 21:43:03 +02:00
|
|
|
len = __objc_read_nbyte_ulong (stream, (buf[0] & _B_VALUE), &key);
|
|
|
|
len = (*stream->read) (stream->physical, buf, 1);
|
1998-09-21 03:22:07 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (buf[0] == (_B_EXT | _BX_CLASS))
|
|
|
|
{
|
2004-05-13 21:01:04 +02:00
|
|
|
char *class_name = "";
|
1998-09-21 03:22:07 +02:00
|
|
|
unsigned long version;
|
|
|
|
|
|
|
|
/* get class */
|
|
|
|
len = objc_read_string (stream, &class_name);
|
2002-07-02 21:43:03 +02:00
|
|
|
(*class) = objc_get_class (class_name);
|
|
|
|
objc_free (class_name);
|
1998-09-21 03:22:07 +02:00
|
|
|
|
|
|
|
/* register */
|
|
|
|
if (key)
|
|
|
|
hash_add (&stream->stream_table, LONG2PTR(key), *class);
|
|
|
|
|
2002-07-02 21:43:03 +02:00
|
|
|
objc_read_unsigned_long (stream, &version);
|
|
|
|
hash_add (&stream->class_table, (*class)->name, (void *)version);
|
1998-09-21 03:22:07 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
else if ((buf[0]&_B_CODE) == _B_UCOMM)
|
|
|
|
{
|
|
|
|
if (key)
|
2002-07-02 21:43:03 +02:00
|
|
|
objc_error (nil, OBJC_ERR_BAD_KEY, "cannot register use upcode...");
|
|
|
|
len = __objc_read_nbyte_ulong (stream, (buf[0] & _B_VALUE), &key);
|
|
|
|
*class = hash_value_for_key (stream->stream_table, LONG2PTR(key));
|
|
|
|
if (! *class)
|
|
|
|
objc_error (nil, OBJC_ERR_BAD_CLASS,
|
|
|
|
"cannot find class for key %lu", key);
|
1998-09-21 03:22:07 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
else
|
2002-07-02 21:43:03 +02:00
|
|
|
objc_error (nil, OBJC_ERR_BAD_DATA,
|
|
|
|
"expected class, got opcode %c", buf[0]);
|
1998-09-21 03:22:07 +02:00
|
|
|
}
|
|
|
|
return len;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2002-07-02 21:43:03 +02:00
|
|
|
objc_read_selector (struct objc_typed_stream *stream, SEL* selector)
|
1998-09-21 03:22:07 +02:00
|
|
|
{
|
|
|
|
unsigned char buf[sizeof (unsigned int)];
|
|
|
|
int len;
|
2002-07-02 21:43:03 +02:00
|
|
|
if ((len = (*stream->read) (stream->physical, buf, 1)))
|
1998-09-21 03:22:07 +02:00
|
|
|
{
|
|
|
|
unsigned long key = 0;
|
|
|
|
|
|
|
|
if ((buf[0]&_B_CODE) == _B_RCOMM) /* register following */
|
|
|
|
{
|
2002-07-02 21:43:03 +02:00
|
|
|
len = __objc_read_nbyte_ulong (stream, (buf[0] & _B_VALUE), &key);
|
|
|
|
len = (*stream->read) (stream->physical, buf, 1);
|
1998-09-21 03:22:07 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (buf[0] == (_B_EXT|_BX_SEL)) /* selector! */
|
|
|
|
{
|
2004-05-13 21:01:04 +02:00
|
|
|
char *selector_name = "";
|
1998-09-21 03:22:07 +02:00
|
|
|
|
|
|
|
/* get selector */
|
|
|
|
len = objc_read_string (stream, &selector_name);
|
|
|
|
/* To handle NULL selectors */
|
2002-07-02 21:43:03 +02:00
|
|
|
if (0 == strlen (selector_name))
|
1998-09-21 03:22:07 +02:00
|
|
|
{
|
|
|
|
(*selector) = (SEL)0;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
else
|
2002-07-02 21:43:03 +02:00
|
|
|
(*selector) = sel_get_any_uid (selector_name);
|
|
|
|
objc_free (selector_name);
|
1998-09-21 03:22:07 +02:00
|
|
|
|
|
|
|
/* register */
|
|
|
|
if (key)
|
2002-07-02 21:43:03 +02:00
|
|
|
hash_add (&stream->stream_table, LONG2PTR(key), (void *) *selector);
|
1998-09-21 03:22:07 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
else if ((buf[0]&_B_CODE) == _B_UCOMM)
|
|
|
|
{
|
|
|
|
if (key)
|
2002-07-02 21:43:03 +02:00
|
|
|
objc_error (nil, OBJC_ERR_BAD_KEY, "cannot register use upcode...");
|
|
|
|
len = __objc_read_nbyte_ulong (stream, (buf[0] & _B_VALUE), &key);
|
1998-09-21 03:22:07 +02:00
|
|
|
(*selector) = hash_value_for_key (stream->stream_table,
|
|
|
|
LONG2PTR(key));
|
|
|
|
}
|
|
|
|
|
|
|
|
else
|
2002-07-02 21:43:03 +02:00
|
|
|
objc_error (nil, OBJC_ERR_BAD_DATA,
|
|
|
|
"expected selector, got opcode %c", buf[0]);
|
1998-09-21 03:22:07 +02:00
|
|
|
}
|
|
|
|
return len;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
** USER LEVEL FUNCTIONS
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
** Write one object, encoded in TYPE and pointed to by DATA to the
|
|
|
|
** typed stream STREAM.
|
|
|
|
*/
|
|
|
|
|
|
|
|
int
|
2002-07-02 21:43:03 +02:00
|
|
|
objc_write_type (TypedStream *stream, const char *type, const void *data)
|
1998-09-21 03:22:07 +02:00
|
|
|
{
|
2002-07-02 21:43:03 +02:00
|
|
|
switch (*type) {
|
1998-09-21 03:22:07 +02:00
|
|
|
case _C_ID:
|
2002-07-02 21:43:03 +02:00
|
|
|
return objc_write_object (stream, *(id *) data);
|
1998-09-21 03:22:07 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
case _C_CLASS:
|
2002-07-02 21:43:03 +02:00
|
|
|
return objc_write_class (stream, *(Class *) data);
|
1998-09-21 03:22:07 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
case _C_SEL:
|
2002-07-02 21:43:03 +02:00
|
|
|
return objc_write_selector (stream, *(SEL *) data);
|
1998-09-21 03:22:07 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
case _C_CHR:
|
2002-07-02 21:43:03 +02:00
|
|
|
return objc_write_char (stream, *(signed char *) data);
|
1998-09-21 03:22:07 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
case _C_UCHR:
|
2002-07-02 21:43:03 +02:00
|
|
|
return objc_write_unsigned_char (stream, *(unsigned char *) data);
|
1998-09-21 03:22:07 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
case _C_SHT:
|
2002-07-02 21:43:03 +02:00
|
|
|
return objc_write_short (stream, *(short *) data);
|
1998-09-21 03:22:07 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
case _C_USHT:
|
2002-07-02 21:43:03 +02:00
|
|
|
return objc_write_unsigned_short (stream, *(unsigned short *) data);
|
1998-09-21 03:22:07 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
case _C_INT:
|
2002-07-02 21:43:03 +02:00
|
|
|
return objc_write_int (stream, *(int *) data);
|
1998-09-21 03:22:07 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
case _C_UINT:
|
2002-07-02 21:43:03 +02:00
|
|
|
return objc_write_unsigned_int (stream, *(unsigned int *) data);
|
1998-09-21 03:22:07 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
case _C_LNG:
|
2002-07-02 21:43:03 +02:00
|
|
|
return objc_write_long (stream, *(long *) data);
|
1998-09-21 03:22:07 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
case _C_ULNG:
|
2002-07-02 21:43:03 +02:00
|
|
|
return objc_write_unsigned_long (stream, *(unsigned long *) data);
|
1998-09-21 03:22:07 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
case _C_CHARPTR:
|
2002-07-02 21:43:03 +02:00
|
|
|
return objc_write_string (stream,
|
|
|
|
*(char **) data, strlen (*(char **) data));
|
1998-09-21 03:22:07 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
case _C_ATOM:
|
2002-07-02 21:43:03 +02:00
|
|
|
return objc_write_string_atomic (stream, *(char **) data,
|
|
|
|
strlen (*(char **) data));
|
1998-09-21 03:22:07 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
case _C_ARY_B:
|
|
|
|
{
|
2002-07-02 21:43:03 +02:00
|
|
|
int len = atoi (type + 1);
|
|
|
|
while (isdigit ((unsigned char) *++type))
|
1998-09-21 03:22:07 +02:00
|
|
|
;
|
|
|
|
return objc_write_array (stream, type, len, data);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case _C_STRUCT_B:
|
|
|
|
{
|
|
|
|
int acc_size = 0;
|
|
|
|
int align;
|
|
|
|
while (*type != _C_STRUCT_E && *type++ != '=')
|
|
|
|
; /* skip "<name>=" */
|
|
|
|
while (*type != _C_STRUCT_E)
|
|
|
|
{
|
|
|
|
align = objc_alignof_type (type); /* padd to alignment */
|
|
|
|
acc_size += ROUND (acc_size, align);
|
2002-07-02 21:43:03 +02:00
|
|
|
objc_write_type (stream, type, ((char *) data) + acc_size);
|
1998-09-21 03:22:07 +02:00
|
|
|
acc_size += objc_sizeof_type (type); /* add component size */
|
|
|
|
type = objc_skip_typespec (type); /* skip component */
|
|
|
|
}
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
default:
|
|
|
|
{
|
2002-07-02 21:43:03 +02:00
|
|
|
objc_error (nil, OBJC_ERR_BAD_TYPE,
|
|
|
|
"objc_write_type: cannot parse typespec: %s\n", type);
|
1998-09-21 03:22:07 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
** Read one object, encoded in TYPE and pointed to by DATA to the
|
|
|
|
** typed stream STREAM. DATA specifies the address of the types to
|
|
|
|
** read. Expected type is checked against the type actually present
|
|
|
|
** on the stream.
|
|
|
|
*/
|
|
|
|
|
|
|
|
int
|
2002-07-02 21:43:03 +02:00
|
|
|
objc_read_type(TypedStream *stream, const char *type, void *data)
|
1998-09-21 03:22:07 +02:00
|
|
|
{
|
|
|
|
char c;
|
2002-07-02 21:43:03 +02:00
|
|
|
switch (c = *type) {
|
1998-09-21 03:22:07 +02:00
|
|
|
case _C_ID:
|
|
|
|
return objc_read_object (stream, (id*)data);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case _C_CLASS:
|
|
|
|
return objc_read_class (stream, (Class*)data);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case _C_SEL:
|
|
|
|
return objc_read_selector (stream, (SEL*)data);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case _C_CHR:
|
|
|
|
return objc_read_char (stream, (char*)data);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case _C_UCHR:
|
|
|
|
return objc_read_unsigned_char (stream, (unsigned char*)data);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case _C_SHT:
|
|
|
|
return objc_read_short (stream, (short*)data);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case _C_USHT:
|
|
|
|
return objc_read_unsigned_short (stream, (unsigned short*)data);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case _C_INT:
|
|
|
|
return objc_read_int (stream, (int*)data);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case _C_UINT:
|
|
|
|
return objc_read_unsigned_int (stream, (unsigned int*)data);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case _C_LNG:
|
|
|
|
return objc_read_long (stream, (long*)data);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case _C_ULNG:
|
|
|
|
return objc_read_unsigned_long (stream, (unsigned long*)data);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case _C_CHARPTR:
|
|
|
|
case _C_ATOM:
|
|
|
|
return objc_read_string (stream, (char**)data);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case _C_ARY_B:
|
|
|
|
{
|
2002-07-02 21:43:03 +02:00
|
|
|
int len = atoi (type + 1);
|
|
|
|
while (isdigit ((unsigned char) *++type))
|
1998-09-21 03:22:07 +02:00
|
|
|
;
|
|
|
|
return objc_read_array (stream, type, len, data);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case _C_STRUCT_B:
|
|
|
|
{
|
|
|
|
int acc_size = 0;
|
|
|
|
int align;
|
|
|
|
while (*type != _C_STRUCT_E && *type++ != '=')
|
|
|
|
; /* skip "<name>=" */
|
|
|
|
while (*type != _C_STRUCT_E)
|
|
|
|
{
|
|
|
|
align = objc_alignof_type (type); /* padd to alignment */
|
|
|
|
acc_size += ROUND (acc_size, align);
|
|
|
|
objc_read_type (stream, type, ((char*)data)+acc_size);
|
|
|
|
acc_size += objc_sizeof_type (type); /* add component size */
|
|
|
|
type = objc_skip_typespec (type); /* skip component */
|
|
|
|
}
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
default:
|
|
|
|
{
|
2002-07-02 21:43:03 +02:00
|
|
|
objc_error (nil, OBJC_ERR_BAD_TYPE,
|
|
|
|
"objc_read_type: cannot parse typespec: %s\n", type);
|
1998-09-21 03:22:07 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
** Write the object specified by the template TYPE to STREAM. Last
|
|
|
|
** arguments specify addresses of values to be written. It might
|
|
|
|
** seem surprising to specify values by address, but this is extremely
|
|
|
|
** convenient for copy-paste with objc_read_types calls. A more
|
|
|
|
** down-to-the-earth cause for this passing of addresses is that values
|
|
|
|
** of arbitrary size is not well supported in ANSI C for functions with
|
|
|
|
** variable number of arguments.
|
|
|
|
*/
|
|
|
|
|
|
|
|
int
|
2002-07-02 21:43:03 +02:00
|
|
|
objc_write_types (TypedStream *stream, const char *type, ...)
|
1998-09-21 03:22:07 +02:00
|
|
|
{
|
|
|
|
va_list args;
|
|
|
|
const char *c;
|
|
|
|
int res = 0;
|
|
|
|
|
|
|
|
va_start(args, type);
|
|
|
|
|
|
|
|
for (c = type; *c; c = objc_skip_typespec (c))
|
|
|
|
{
|
2002-07-02 21:43:03 +02:00
|
|
|
switch (*c) {
|
1998-09-21 03:22:07 +02:00
|
|
|
case _C_ID:
|
|
|
|
res = objc_write_object (stream, *va_arg (args, id*));
|
|
|
|
break;
|
|
|
|
|
|
|
|
case _C_CLASS:
|
2002-07-02 21:43:03 +02:00
|
|
|
res = objc_write_class (stream, *va_arg (args, Class*));
|
1998-09-21 03:22:07 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
case _C_SEL:
|
2002-07-02 21:43:03 +02:00
|
|
|
res = objc_write_selector (stream, *va_arg (args, SEL*));
|
1998-09-21 03:22:07 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
case _C_CHR:
|
|
|
|
res = objc_write_char (stream, *va_arg (args, char*));
|
|
|
|
break;
|
|
|
|
|
|
|
|
case _C_UCHR:
|
|
|
|
res = objc_write_unsigned_char (stream,
|
|
|
|
*va_arg (args, unsigned char*));
|
|
|
|
break;
|
|
|
|
|
|
|
|
case _C_SHT:
|
2002-07-02 21:43:03 +02:00
|
|
|
res = objc_write_short (stream, *va_arg (args, short*));
|
1998-09-21 03:22:07 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
case _C_USHT:
|
|
|
|
res = objc_write_unsigned_short (stream,
|
2002-07-02 21:43:03 +02:00
|
|
|
*va_arg (args, unsigned short*));
|
1998-09-21 03:22:07 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
case _C_INT:
|
2002-07-02 21:43:03 +02:00
|
|
|
res = objc_write_int(stream, *va_arg (args, int*));
|
1998-09-21 03:22:07 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
case _C_UINT:
|
2002-07-02 21:43:03 +02:00
|
|
|
res = objc_write_unsigned_int(stream, *va_arg (args, unsigned int*));
|
1998-09-21 03:22:07 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
case _C_LNG:
|
2002-07-02 21:43:03 +02:00
|
|
|
res = objc_write_long(stream, *va_arg (args, long*));
|
1998-09-21 03:22:07 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
case _C_ULNG:
|
2002-07-02 21:43:03 +02:00
|
|
|
res = objc_write_unsigned_long(stream, *va_arg (args, unsigned long*));
|
1998-09-21 03:22:07 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
case _C_CHARPTR:
|
|
|
|
{
|
2002-07-02 21:43:03 +02:00
|
|
|
char **str = va_arg (args, char **);
|
|
|
|
res = objc_write_string (stream, *str, strlen (*str));
|
1998-09-21 03:22:07 +02:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case _C_ATOM:
|
|
|
|
{
|
2002-07-02 21:43:03 +02:00
|
|
|
char **str = va_arg (args, char **);
|
|
|
|
res = objc_write_string_atomic (stream, *str, strlen (*str));
|
1998-09-21 03:22:07 +02:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case _C_ARY_B:
|
|
|
|
{
|
2002-07-02 21:43:03 +02:00
|
|
|
int len = atoi (c + 1);
|
|
|
|
const char *t = c;
|
|
|
|
while (isdigit ((unsigned char) *++t))
|
1998-09-21 03:22:07 +02:00
|
|
|
;
|
2002-07-02 21:43:03 +02:00
|
|
|
res = objc_write_array (stream, t, len, va_arg (args, void *));
|
1998-09-21 03:22:07 +02:00
|
|
|
t = objc_skip_typespec (t);
|
|
|
|
if (*t != _C_ARY_E)
|
2002-07-02 21:43:03 +02:00
|
|
|
objc_error (nil, OBJC_ERR_BAD_TYPE, "expected `]', got: %s", t);
|
1998-09-21 03:22:07 +02:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2002-07-02 21:43:03 +02:00
|
|
|
objc_error (nil, OBJC_ERR_BAD_TYPE,
|
|
|
|
"objc_write_types: cannot parse typespec: %s\n", type);
|
1998-09-21 03:22:07 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
va_end(args);
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
** Last arguments specify addresses of values to be read. Expected
|
|
|
|
** type is checked against the type actually present on the stream.
|
|
|
|
*/
|
|
|
|
|
|
|
|
int
|
2002-07-02 21:43:03 +02:00
|
|
|
objc_read_types(TypedStream *stream, const char *type, ...)
|
1998-09-21 03:22:07 +02:00
|
|
|
{
|
|
|
|
va_list args;
|
|
|
|
const char *c;
|
|
|
|
int res = 0;
|
|
|
|
|
2002-07-02 21:43:03 +02:00
|
|
|
va_start (args, type);
|
1998-09-21 03:22:07 +02:00
|
|
|
|
|
|
|
for (c = type; *c; c = objc_skip_typespec(c))
|
|
|
|
{
|
2002-07-02 21:43:03 +02:00
|
|
|
switch (*c) {
|
1998-09-21 03:22:07 +02:00
|
|
|
case _C_ID:
|
2002-07-02 21:43:03 +02:00
|
|
|
res = objc_read_object(stream, va_arg (args, id*));
|
1998-09-21 03:22:07 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
case _C_CLASS:
|
2002-07-02 21:43:03 +02:00
|
|
|
res = objc_read_class(stream, va_arg (args, Class*));
|
1998-09-21 03:22:07 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
case _C_SEL:
|
2002-07-02 21:43:03 +02:00
|
|
|
res = objc_read_selector(stream, va_arg (args, SEL*));
|
1998-09-21 03:22:07 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
case _C_CHR:
|
2002-07-02 21:43:03 +02:00
|
|
|
res = objc_read_char(stream, va_arg (args, char*));
|
1998-09-21 03:22:07 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
case _C_UCHR:
|
2002-07-02 21:43:03 +02:00
|
|
|
res = objc_read_unsigned_char(stream, va_arg (args, unsigned char*));
|
1998-09-21 03:22:07 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
case _C_SHT:
|
2002-07-02 21:43:03 +02:00
|
|
|
res = objc_read_short(stream, va_arg (args, short*));
|
1998-09-21 03:22:07 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
case _C_USHT:
|
2002-07-02 21:43:03 +02:00
|
|
|
res = objc_read_unsigned_short(stream, va_arg (args, unsigned short*));
|
1998-09-21 03:22:07 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
case _C_INT:
|
2002-07-02 21:43:03 +02:00
|
|
|
res = objc_read_int(stream, va_arg (args, int*));
|
1998-09-21 03:22:07 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
case _C_UINT:
|
2002-07-02 21:43:03 +02:00
|
|
|
res = objc_read_unsigned_int(stream, va_arg (args, unsigned int*));
|
1998-09-21 03:22:07 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
case _C_LNG:
|
2002-07-02 21:43:03 +02:00
|
|
|
res = objc_read_long(stream, va_arg (args, long*));
|
1998-09-21 03:22:07 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
case _C_ULNG:
|
2002-07-02 21:43:03 +02:00
|
|
|
res = objc_read_unsigned_long(stream, va_arg (args, unsigned long*));
|
1998-09-21 03:22:07 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
case _C_CHARPTR:
|
|
|
|
case _C_ATOM:
|
|
|
|
{
|
2002-07-02 21:43:03 +02:00
|
|
|
char **str = va_arg (args, char **);
|
1998-09-21 03:22:07 +02:00
|
|
|
res = objc_read_string (stream, str);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case _C_ARY_B:
|
|
|
|
{
|
2002-07-02 21:43:03 +02:00
|
|
|
int len = atoi (c + 1);
|
|
|
|
const char *t = c;
|
|
|
|
while (isdigit ((unsigned char) *++t))
|
1998-09-21 03:22:07 +02:00
|
|
|
;
|
2002-07-02 21:43:03 +02:00
|
|
|
res = objc_read_array (stream, t, len, va_arg (args, void *));
|
1998-09-21 03:22:07 +02:00
|
|
|
t = objc_skip_typespec (t);
|
|
|
|
if (*t != _C_ARY_E)
|
2002-07-02 21:43:03 +02:00
|
|
|
objc_error (nil, OBJC_ERR_BAD_TYPE, "expected `]', got: %s", t);
|
1998-09-21 03:22:07 +02:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2002-07-02 21:43:03 +02:00
|
|
|
objc_error (nil, OBJC_ERR_BAD_TYPE,
|
|
|
|
"objc_read_types: cannot parse typespec: %s\n", type);
|
1998-09-21 03:22:07 +02:00
|
|
|
}
|
|
|
|
}
|
2002-07-02 21:43:03 +02:00
|
|
|
va_end (args);
|
1998-09-21 03:22:07 +02:00
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
** Write an array of COUNT elements of TYPE from the memory address DATA.
|
|
|
|
** This is equivalent of objc_write_type (stream, "[N<type>]", data)
|
|
|
|
*/
|
|
|
|
|
|
|
|
int
|
2002-07-02 21:43:03 +02:00
|
|
|
objc_write_array (TypedStream *stream, const char *type,
|
|
|
|
int count, const void *data)
|
1998-09-21 03:22:07 +02:00
|
|
|
{
|
|
|
|
int off = objc_sizeof_type(type);
|
2002-07-02 21:43:03 +02:00
|
|
|
const char *where = data;
|
1998-09-21 03:22:07 +02:00
|
|
|
|
|
|
|
while (count-- > 0)
|
|
|
|
{
|
|
|
|
objc_write_type(stream, type, where);
|
|
|
|
where += off;
|
|
|
|
}
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
** Read an array of COUNT elements of TYPE into the memory address
|
|
|
|
** DATA. The memory pointed to by data is supposed to be allocated
|
|
|
|
** by the callee. This is equivalent of
|
|
|
|
** objc_read_type (stream, "[N<type>]", data)
|
|
|
|
*/
|
|
|
|
|
|
|
|
int
|
2002-07-02 21:43:03 +02:00
|
|
|
objc_read_array (TypedStream *stream, const char *type,
|
|
|
|
int count, void *data)
|
1998-09-21 03:22:07 +02:00
|
|
|
{
|
|
|
|
int off = objc_sizeof_type(type);
|
2002-07-02 21:43:03 +02:00
|
|
|
char *where = (char*)data;
|
1998-09-21 03:22:07 +02:00
|
|
|
|
|
|
|
while (count-- > 0)
|
|
|
|
{
|
|
|
|
objc_read_type(stream, type, where);
|
|
|
|
where += off;
|
|
|
|
}
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2002-07-02 21:43:03 +02:00
|
|
|
__objc_fread (FILE *file, char *data, int len)
|
1998-09-21 03:22:07 +02:00
|
|
|
{
|
|
|
|
return fread(data, len, 1, file);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2002-07-02 21:43:03 +02:00
|
|
|
__objc_fwrite (FILE *file, char *data, int len)
|
1998-09-21 03:22:07 +02:00
|
|
|
{
|
|
|
|
return fwrite(data, len, 1, file);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2002-07-02 21:43:03 +02:00
|
|
|
__objc_feof (FILE *file)
|
1998-09-21 03:22:07 +02:00
|
|
|
{
|
|
|
|
return feof(file);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2002-07-02 21:43:03 +02:00
|
|
|
__objc_no_write (FILE *file __attribute__ ((__unused__)),
|
|
|
|
const char *data __attribute__ ((__unused__)),
|
|
|
|
int len __attribute__ ((__unused__)))
|
1998-09-21 03:22:07 +02:00
|
|
|
{
|
|
|
|
objc_error (nil, OBJC_ERR_NO_WRITE, "TypedStream not open for writing");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2002-07-02 21:43:03 +02:00
|
|
|
__objc_no_read (FILE *file __attribute__ ((__unused__)),
|
|
|
|
const char *data __attribute__ ((__unused__)),
|
|
|
|
int len __attribute__ ((__unused__)))
|
1998-09-21 03:22:07 +02:00
|
|
|
{
|
|
|
|
objc_error (nil, OBJC_ERR_NO_READ, "TypedStream not open for reading");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2002-07-02 21:43:03 +02:00
|
|
|
__objc_read_typed_stream_signature (TypedStream *stream)
|
1998-09-21 03:22:07 +02:00
|
|
|
{
|
|
|
|
char buffer[80];
|
|
|
|
int pos = 0;
|
|
|
|
do
|
2002-07-02 21:43:03 +02:00
|
|
|
(*stream->read) (stream->physical, buffer+pos, 1);
|
1998-09-21 03:22:07 +02:00
|
|
|
while (buffer[pos++] != '\0')
|
|
|
|
;
|
|
|
|
sscanf (buffer, "GNU TypedStream %d", &stream->version);
|
|
|
|
if (stream->version != OBJC_TYPED_STREAM_VERSION)
|
|
|
|
objc_error (nil, OBJC_ERR_STREAM_VERSION,
|
|
|
|
"cannot handle TypedStream version %d", stream->version);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2002-07-02 21:43:03 +02:00
|
|
|
__objc_write_typed_stream_signature (TypedStream *stream)
|
1998-09-21 03:22:07 +02:00
|
|
|
{
|
|
|
|
char buffer[80];
|
|
|
|
sprintf(buffer, "GNU TypedStream %d", OBJC_TYPED_STREAM_VERSION);
|
|
|
|
stream->version = OBJC_TYPED_STREAM_VERSION;
|
2002-07-02 21:43:03 +02:00
|
|
|
(*stream->write) (stream->physical, buffer, strlen (buffer) + 1);
|
1998-09-21 03:22:07 +02:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2002-07-02 21:43:03 +02:00
|
|
|
static void __objc_finish_write_root_object(struct objc_typed_stream *stream)
|
1998-09-21 03:22:07 +02:00
|
|
|
{
|
|
|
|
hash_delete (stream->object_table);
|
|
|
|
stream->object_table = hash_new(64,
|
|
|
|
(hash_func_type)hash_ptr,
|
|
|
|
(compare_func_type)compare_ptrs);
|
|
|
|
}
|
|
|
|
|
2002-07-02 21:43:03 +02:00
|
|
|
static void __objc_finish_read_root_object(struct objc_typed_stream *stream)
|
1998-09-21 03:22:07 +02:00
|
|
|
{
|
|
|
|
node_ptr node;
|
|
|
|
SEL awake_sel = sel_get_any_uid ("awake");
|
|
|
|
cache_ptr free_list = hash_new (64,
|
|
|
|
(hash_func_type) hash_ptr,
|
|
|
|
(compare_func_type) compare_ptrs);
|
|
|
|
|
|
|
|
/* resolve object forward references */
|
|
|
|
for (node = hash_next (stream->object_refs, NULL); node;
|
|
|
|
node = hash_next (stream->object_refs, node))
|
|
|
|
{
|
2002-07-02 21:43:03 +02:00
|
|
|
struct objc_list *reflist = node->value;
|
|
|
|
const void *key = node->key;
|
1998-09-21 03:22:07 +02:00
|
|
|
id object = hash_value_for_key (stream->object_table, key);
|
2002-07-02 21:43:03 +02:00
|
|
|
while (reflist)
|
1998-09-21 03:22:07 +02:00
|
|
|
{
|
2002-07-02 21:43:03 +02:00
|
|
|
*((id*) reflist->head) = object;
|
1998-09-21 03:22:07 +02:00
|
|
|
if (hash_value_for_key (free_list,reflist) == NULL)
|
|
|
|
hash_add (&free_list,reflist,reflist);
|
|
|
|
|
|
|
|
reflist = reflist->tail;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* apply __objc_free to all objects stored in free_list */
|
|
|
|
for (node = hash_next (free_list, NULL); node;
|
|
|
|
node = hash_next (free_list, node))
|
|
|
|
objc_free ((void *) node->key);
|
|
|
|
|
|
|
|
hash_delete (free_list);
|
|
|
|
|
|
|
|
/* empty object reference table */
|
|
|
|
hash_delete (stream->object_refs);
|
|
|
|
stream->object_refs = hash_new(8, (hash_func_type)hash_ptr,
|
|
|
|
(compare_func_type)compare_ptrs);
|
|
|
|
|
|
|
|
/* call -awake for all objects read */
|
|
|
|
if (awake_sel)
|
|
|
|
{
|
|
|
|
for (node = hash_next (stream->object_table, NULL); node;
|
|
|
|
node = hash_next (stream->object_table, node))
|
|
|
|
{
|
|
|
|
id object = node->value;
|
|
|
|
if (__objc_responds_to (object, awake_sel))
|
2002-07-02 21:43:03 +02:00
|
|
|
(*objc_msg_lookup (object, awake_sel)) (object, awake_sel);
|
1998-09-21 03:22:07 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* empty object table */
|
|
|
|
hash_delete (stream->object_table);
|
|
|
|
stream->object_table = hash_new(64,
|
|
|
|
(hash_func_type)hash_ptr,
|
|
|
|
(compare_func_type)compare_ptrs);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
** Open the stream PHYSICAL in MODE
|
|
|
|
*/
|
|
|
|
|
2002-07-02 21:43:03 +02:00
|
|
|
TypedStream *
|
|
|
|
objc_open_typed_stream (FILE *physical, int mode)
|
1998-09-21 03:22:07 +02:00
|
|
|
{
|
2002-07-02 21:43:03 +02:00
|
|
|
TypedStream *s = (TypedStream *) objc_malloc (sizeof (TypedStream));
|
1998-09-21 03:22:07 +02:00
|
|
|
|
|
|
|
s->mode = mode;
|
|
|
|
s->physical = physical;
|
2002-07-02 21:43:03 +02:00
|
|
|
s->stream_table = hash_new (64,
|
|
|
|
(hash_func_type) hash_ptr,
|
|
|
|
(compare_func_type) compare_ptrs);
|
|
|
|
s->object_table = hash_new (64,
|
|
|
|
(hash_func_type) hash_ptr,
|
|
|
|
(compare_func_type) compare_ptrs);
|
|
|
|
s->eof = (objc_typed_eof_func) __objc_feof;
|
|
|
|
s->flush = (objc_typed_flush_func) fflush;
|
1998-09-21 03:22:07 +02:00
|
|
|
s->writing_root_p = 0;
|
|
|
|
if (mode == OBJC_READONLY)
|
|
|
|
{
|
2002-07-02 21:43:03 +02:00
|
|
|
s->class_table = hash_new (8, (hash_func_type) hash_string,
|
|
|
|
(compare_func_type) compare_strings);
|
|
|
|
s->object_refs = hash_new (8, (hash_func_type) hash_ptr,
|
|
|
|
(compare_func_type) compare_ptrs);
|
|
|
|
s->read = (objc_typed_read_func) __objc_fread;
|
|
|
|
s->write = (objc_typed_write_func) __objc_no_write;
|
1998-09-21 03:22:07 +02:00
|
|
|
__objc_read_typed_stream_signature (s);
|
|
|
|
}
|
|
|
|
else if (mode == OBJC_WRITEONLY)
|
|
|
|
{
|
|
|
|
s->class_table = 0;
|
|
|
|
s->object_refs = 0;
|
2002-07-02 21:43:03 +02:00
|
|
|
s->read = (objc_typed_read_func) __objc_no_read;
|
|
|
|
s->write = (objc_typed_write_func) __objc_fwrite;
|
1998-09-21 03:22:07 +02:00
|
|
|
__objc_write_typed_stream_signature (s);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
objc_close_typed_stream (s);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
s->type = OBJC_FILE_STREAM;
|
|
|
|
return s;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
** Open the file named by FILE_NAME in MODE
|
|
|
|
*/
|
|
|
|
|
|
|
|
TypedStream*
|
2002-07-02 21:43:03 +02:00
|
|
|
objc_open_typed_stream_for_file (const char *file_name, int mode)
|
1998-09-21 03:22:07 +02:00
|
|
|
{
|
2002-07-02 21:43:03 +02:00
|
|
|
FILE *file = NULL;
|
|
|
|
TypedStream *s;
|
1998-09-21 03:22:07 +02:00
|
|
|
|
|
|
|
if (mode == OBJC_READONLY)
|
|
|
|
file = fopen (file_name, "r");
|
|
|
|
else
|
|
|
|
file = fopen (file_name, "w");
|
|
|
|
|
|
|
|
if (file)
|
|
|
|
{
|
|
|
|
s = objc_open_typed_stream (file, mode);
|
|
|
|
if (s)
|
|
|
|
s->type |= OBJC_MANAGED_STREAM;
|
|
|
|
return s;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
** Close STREAM freeing the structure it self. If it was opened with
|
|
|
|
** objc_open_typed_stream_for_file, the file will also be closed.
|
|
|
|
*/
|
|
|
|
|
|
|
|
void
|
2002-07-02 21:43:03 +02:00
|
|
|
objc_close_typed_stream (TypedStream *stream)
|
1998-09-21 03:22:07 +02:00
|
|
|
{
|
|
|
|
if (stream->mode == OBJC_READONLY)
|
|
|
|
{
|
|
|
|
__objc_finish_read_root_object (stream); /* Just in case... */
|
|
|
|
hash_delete (stream->class_table);
|
|
|
|
hash_delete (stream->object_refs);
|
|
|
|
}
|
|
|
|
|
|
|
|
hash_delete (stream->stream_table);
|
|
|
|
hash_delete (stream->object_table);
|
|
|
|
|
|
|
|
if (stream->type == (OBJC_MANAGED_STREAM | OBJC_FILE_STREAM))
|
2002-07-02 21:43:03 +02:00
|
|
|
fclose ((FILE *)stream->physical);
|
1998-09-21 03:22:07 +02:00
|
|
|
|
|
|
|
objc_free(stream);
|
|
|
|
}
|
|
|
|
|
|
|
|
BOOL
|
2002-07-02 21:43:03 +02:00
|
|
|
objc_end_of_typed_stream (TypedStream *stream)
|
1998-09-21 03:22:07 +02:00
|
|
|
{
|
2002-07-02 21:43:03 +02:00
|
|
|
return (*stream->eof) (stream->physical);
|
1998-09-21 03:22:07 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2002-07-02 21:43:03 +02:00
|
|
|
objc_flush_typed_stream (TypedStream *stream)
|
1998-09-21 03:22:07 +02:00
|
|
|
{
|
2002-07-02 21:43:03 +02:00
|
|
|
(*stream->flush) (stream->physical);
|
1998-09-21 03:22:07 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
long
|
2002-07-02 21:43:03 +02:00
|
|
|
objc_get_stream_class_version (TypedStream *stream, Class class)
|
1998-09-21 03:22:07 +02:00
|
|
|
{
|
|
|
|
if (stream->class_table)
|
|
|
|
return PTR2LONG(hash_value_for_key (stream->class_table, class->name));
|
|
|
|
else
|
|
|
|
return class_get_version (class);
|
|
|
|
}
|
|
|
|
|