OSDN Git Service

2008-06-10 Kai Tietz <kai.tietz@onevision.com>
[pf3gnuchains/gcc-fork.git] / libobjc / archive.c
index aca648e..b3af32d 100644 (file)
@@ -1,5 +1,5 @@
  /* GNU Objective C Runtime archiving
-   Copyright (C) 1993, 1995, 1996, 1997, 2002 Free Software Foundation, Inc.
+   Copyright (C) 1993, 1995, 1996, 1997, 2002, 2004 Free Software Foundation, Inc.
    Contributed by Kresten Krab Thorup
 
 This file is part of GCC.
@@ -15,8 +15,8 @@ details.
 
 You should have received a copy of the GNU General Public License along with
 GCC; see the file COPYING.  If not, write to the Free Software
-Foundation, 59 Temple Place - Suite 330,
-Boston, MA 02111-1307, USA.  */
+Foundation, 51 Franklin Street, Fifth Floor,
+Boston, MA 02110-1301, 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
@@ -25,9 +25,9 @@ Boston, MA 02111-1307, USA.  */
    covered by the GNU General Public License.  */
 
 #include "tconfig.h"
-#include "runtime.h"
-#include "typedstream.h"
-#include "encoding.h"
+#include "objc/runtime.h"
+#include "objc/typedstream.h"
+#include "objc/encoding.h"
 #include <stdlib.h>
 
 extern int fflush (FILE *);
@@ -62,7 +62,7 @@ const char *objc_skip_type (const char *type);
 static void __objc_finish_write_root_object (struct objc_typed_stream *);
 static void __objc_finish_read_root_object (struct objc_typed_stream *);
 
-static __inline__ int
+static inline int
 __objc_code_unsigned_char (unsigned char *buf, unsigned char val)
 {
   if ((val&_B_VALUE) == val)
@@ -84,10 +84,10 @@ objc_write_unsigned_char (struct objc_typed_stream *stream,
 {
   unsigned char buf[sizeof (unsigned char) + 1];
   int len = __objc_code_unsigned_char (buf, value);
-  return (*stream->write) (stream->physical, buf, len);
+  return (*stream->write) (stream->physical, (char*)buf, len);
 }
 
-static __inline__ int
+static inline int
 __objc_code_char (unsigned char *buf, signed char val)
 {
   if (val >= 0)
@@ -105,10 +105,10 @@ objc_write_char (struct objc_typed_stream *stream, signed char value)
 {
   unsigned char buf[sizeof (char) + 1];
   int len = __objc_code_char (buf, value);
-  return (*stream->write) (stream->physical, buf, len);
+  return (*stream->write) (stream->physical, (char*)buf, len);
 }
 
-static __inline__ int
+static inline int
 __objc_code_unsigned_short (unsigned char *buf, unsigned short val)
 {
   if ((val&_B_VALUE) == val)
@@ -143,10 +143,10 @@ objc_write_unsigned_short (struct objc_typed_stream *stream,
 {
   unsigned char buf[sizeof (unsigned short) + 1];
   int len = __objc_code_unsigned_short (buf, value);
-  return (*stream->write) (stream->physical, buf, len);
+  return (*stream->write) (stream->physical, (char*)buf, len);
 }
       
-static __inline__ int
+static inline int
 __objc_code_short (unsigned char *buf, short val)
 {
   int sign = (val < 0);
@@ -161,11 +161,11 @@ objc_write_short (struct objc_typed_stream *stream, short value)
 {
   unsigned char buf[sizeof (short) + 1];
   int len = __objc_code_short (buf, value);
-  return (*stream->write) (stream->physical, buf, len);
+  return (*stream->write) (stream->physical, (char*)buf, len);
 }
       
 
-static __inline__ int
+static inline int
 __objc_code_unsigned_int (unsigned char *buf, unsigned int val)
 {
   if ((val&_B_VALUE) == val)
@@ -199,10 +199,10 @@ objc_write_unsigned_int (struct objc_typed_stream *stream, unsigned int value)
 {
   unsigned char buf[sizeof (unsigned int) + 1];
   int len = __objc_code_unsigned_int (buf, value);
-  return (*stream->write) (stream->physical, buf, len);
+  return (*stream->write) (stream->physical, (char*)buf, len);
 }
 
-static __inline__ int
+static inline int
 __objc_code_int (unsigned char *buf, int val)
 {
   int sign = (val < 0);
@@ -217,10 +217,10 @@ objc_write_int (struct objc_typed_stream *stream, int value)
 {
   unsigned char buf[sizeof (int) + 1];
   int len = __objc_code_int (buf, value);
-  return (*stream->write) (stream->physical, buf, len);
+  return (*stream->write) (stream->physical, (char*)buf, len);
 }
 
-static __inline__ int
+static inline int
 __objc_code_unsigned_long (unsigned char *buf, unsigned long val)
 {
   if ((val&_B_VALUE) == val)
@@ -255,10 +255,10 @@ objc_write_unsigned_long (struct objc_typed_stream *stream,
 {
   unsigned char buf[sizeof (unsigned long) + 1];
   int len = __objc_code_unsigned_long (buf, value);
-  return (*stream->write) (stream->physical, buf, len);
+  return (*stream->write) (stream->physical, (char*)buf, len);
 }
 
-static __inline__ int
+static inline int
 __objc_code_long (unsigned char *buf, long val)
 {
   int sign = (val < 0);
@@ -273,7 +273,7 @@ objc_write_long (struct objc_typed_stream *stream, long value)
 {
   unsigned char buf[sizeof (long) + 1];
   int len = __objc_code_long (buf, value);
-  return (*stream->write) (stream->physical, buf, len);
+  return (*stream->write) (stream->physical, (char*)buf, len);
 }
 
 
@@ -290,8 +290,8 @@ objc_write_string (struct objc_typed_stream *stream,
   else /* _B_NINT */
     buf[0] = (buf[0]&_B_VALUE)|_B_NSTR;
 
-  if ((*stream->write) (stream->physical, buf, len) != 0)
-    return (*stream->write) (stream->physical, string, nbytes);
+  if ((*stream->write) (stream->physical, (char*)buf, len) != 0)
+    return (*stream->write) (stream->physical, (char*)string, nbytes);
   else
     return 0;
 }
@@ -301,12 +301,13 @@ objc_write_string_atomic (struct objc_typed_stream *stream,
                          unsigned char *string, unsigned int nbytes)
 {
   unsigned long key;
-  if ((key = PTR2LONG(hash_value_for_key (stream->stream_table, string))))
+  if ((key = PTR2LONG(objc_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);
+      objc_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;
@@ -323,12 +324,12 @@ objc_write_register_common (struct objc_typed_stream *stream,
     {
       buf[0] = _B_RCOMM|0x01;
       buf[1] &= _B_VALUE;
-      return (*stream->write) (stream->physical, buf, len + 1);
+      return (*stream->write) (stream->physical, (char*)buf, len + 1);
     }
   else
     {
       buf[1] = (buf[1]&_B_VALUE)|_B_RCOMM;
-      return (*stream->write) (stream->physical, buf + 1, len);
+      return (*stream->write) (stream->physical, (char*)buf + 1, len);
     }
 }
 
@@ -341,22 +342,22 @@ objc_write_use_common (struct objc_typed_stream *stream, unsigned long key)
     {
       buf[0] = _B_UCOMM|0x01;
       buf[1] &= _B_VALUE;
-      return (*stream->write) (stream->physical, buf, 2);
+      return (*stream->write) (stream->physical, (char*)buf, 2);
     }
   else
     {
       buf[1] = (buf[1]&_B_VALUE)|_B_UCOMM;
-      return (*stream->write) (stream->physical, buf + 1, len);
+      return (*stream->write) (stream->physical, (char*)buf + 1, len);
     }
 }
 
-static __inline__ int
+static inline int
 __objc_write_extension (struct objc_typed_stream *stream, unsigned char code)
 {
   if (code <= _B_VALUE)
     {
       unsigned char buf = code|_B_EXT;
-      return (*stream->write) (stream->physical, &buf, 1);
+      return (*stream->write) (stream->physical, (char*)&buf, 1);
     }
   else 
     {
@@ -366,7 +367,7 @@ __objc_write_extension (struct objc_typed_stream *stream, unsigned char code)
     }
 }
 
-__inline__ int
+inline int
 __objc_write_object (struct objc_typed_stream *stream, id object)
 {
   unsigned char buf = '\0';
@@ -376,7 +377,7 @@ __objc_write_object (struct objc_typed_stream *stream, id object)
       __objc_write_extension (stream, _BX_OBJECT);
       objc_write_class (stream, object->class_pointer);
       (*objc_msg_lookup (object, write_sel)) (object, write_sel, stream);
-      return (*stream->write) (stream->physical, &buf, 1);
+      return (*stream->write) (stream->physical, (char*)&buf, 1);
     }
   else
     return objc_write_use_common (stream, 0);
@@ -386,7 +387,7 @@ int
 objc_write_object_reference (struct objc_typed_stream *stream, id object)
 {
   unsigned long key;
-  if ((key = PTR2LONG(hash_value_for_key (stream->object_table, object))))
+  if ((key = PTR2LONG(objc_hash_value_for_key (stream->object_table, object))))
     return objc_write_use_common (stream, key);
 
   __objc_write_extension (stream, _BX_OBJREF);
@@ -415,7 +416,7 @@ int
 objc_write_object (struct objc_typed_stream *stream, id object)
 {
   unsigned long key;
-  if ((key = PTR2LONG(hash_value_for_key (stream->object_table, object))))
+  if ((key = PTR2LONG(objc_hash_value_for_key (stream->object_table, object))))
     return objc_write_use_common (stream, key);
 
   else if (object == nil)
@@ -424,18 +425,19 @@ objc_write_object (struct objc_typed_stream *stream, id object)
   else
     {
       int length;
-      hash_add (&stream->object_table, LONG2PTR(key=PTR2LONG(object)), object);
+      objc_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
+inline int
 __objc_write_class (struct objc_typed_stream *stream, struct objc_class *class)
 {
   __objc_write_extension (stream, _BX_CLASS);
-  objc_write_string_atomic (stream, (char *) class->name,
+  objc_write_string_atomic (stream, (unsigned char *) class->name,
                           strlen ((char *) class->name));
   return objc_write_unsigned_long (stream, class->version);
 }
@@ -446,12 +448,13 @@ objc_write_class (struct objc_typed_stream *stream,
                         struct objc_class *class)
 {
   unsigned long key;
-  if ((key = PTR2LONG(hash_value_for_key (stream->stream_table, class))))
+  if ((key = PTR2LONG(objc_hash_value_for_key (stream->stream_table, class))))
     return objc_write_use_common (stream, key);
   else
     {
       int length;
-      hash_add (&stream->stream_table, LONG2PTR(key = PTR2LONG(class)), class);
+      objc_hash_add (&stream->stream_table,
+                    LONG2PTR(key = PTR2LONG(class)), class);
       if ((length = objc_write_register_common (stream, key)))
        return __objc_write_class (stream, class);
       return length;
@@ -459,16 +462,16 @@ objc_write_class (struct objc_typed_stream *stream,
 }
 
 
-__inline__ int 
+inline int 
 __objc_write_selector (struct objc_typed_stream *stream, SEL selector)
 {
   const char *sel_name;
   __objc_write_extension (stream, _BX_SEL);
   /* to handle NULL selectors */
   if ((SEL)0 == selector)
-    return objc_write_string (stream, "", 0);
+    return objc_write_string (stream, (unsigned char*)"", 0);
   sel_name = sel_get_name (selector);
-  return objc_write_string (stream, sel_name, strlen ((char*)sel_name));
+  return objc_write_string (stream, (unsigned char*)sel_name, strlen ((char*)sel_name));
 }
 
 int 
@@ -482,12 +485,13 @@ objc_write_selector (struct objc_typed_stream *stream, SEL 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))))
+  if ((key = PTR2LONG(objc_hash_value_for_key (stream->stream_table,
+                                              sel_name))))
     return objc_write_use_common (stream, key);
   else
     {
       int length;
-      hash_add (&stream->stream_table, 
+      objc_hash_add (&stream->stream_table, 
                LONG2PTR(key = PTR2LONG(sel_name)), (char *) sel_name);
       if ((length = objc_write_register_common (stream, key)))
        return __objc_write_selector (stream, selector);
@@ -501,12 +505,12 @@ objc_write_selector (struct objc_typed_stream *stream, SEL selector)
 ** Read operations 
 */
 
-__inline__ int
+inline int
 objc_read_char (struct objc_typed_stream *stream, char *val)
 {
   unsigned char buf;
   int len;
-  len = (*stream->read) (stream->physical, &buf, 1);
+  len = (*stream->read) (stream->physical, (char*)&buf, 1);
   if (len != 0)
     {
       if ((buf & _B_CODE) == _B_SINT)
@@ -528,18 +532,18 @@ objc_read_char (struct objc_typed_stream *stream, char *val)
 }
 
 
-__inline__ int
+inline int
 objc_read_unsigned_char (struct objc_typed_stream *stream, unsigned char *val)
 {
   unsigned char buf;
   int len;
-  if ((len = (*stream->read) (stream->physical, &buf, 1)))
+  if ((len = (*stream->read) (stream->physical, (char*)&buf, 1)))
     {
       if ((buf & _B_CODE) == _B_SINT)
        (*val) = (buf & _B_VALUE);
 
       else if ((buf & _B_NUMBER) == 1)
-       len = (*stream->read) (stream->physical, val, 1);
+       len = (*stream->read) (stream->physical, (char*)val, 1);
 
       else
        objc_error (nil, OBJC_ERR_BAD_DATA,
@@ -549,12 +553,12 @@ objc_read_unsigned_char (struct objc_typed_stream *stream, unsigned char *val)
   return len;
 }
 
-__inline__ int
+inline int
 objc_read_short (struct objc_typed_stream *stream, short *value)
 {
   unsigned char buf[sizeof (short) + 1];
   int len;
-  if ((len = (*stream->read) (stream->physical, buf, 1)))
+  if ((len = (*stream->read) (stream->physical, (char*)buf, 1)))
     {
       if ((buf[0] & _B_CODE) == _B_SINT)
        (*value) = (buf[0] & _B_VALUE);
@@ -566,7 +570,7 @@ objc_read_short (struct objc_typed_stream *stream, short *value)
          if (nbytes > (int) sizeof (short))
            objc_error (nil, OBJC_ERR_BAD_DATA,
                        "expected short, got bigger (%dbits)", nbytes*8);
-         len = (*stream->read) (stream->physical, buf + 1, nbytes);
+         len = (*stream->read) (stream->physical, (char*)buf + 1, nbytes);
          (*value) = 0;
          while (pos <= nbytes)
            (*value) = ((*value)*0x100) + buf[pos++];
@@ -577,13 +581,13 @@ objc_read_short (struct objc_typed_stream *stream, short *value)
   return len;
 }
 
-__inline__ int
+inline int
 objc_read_unsigned_short (struct objc_typed_stream *stream,
                          unsigned short *value)
 {
   unsigned char buf[sizeof (unsigned short) + 1];
   int len;
-  if ((len = (*stream->read) (stream->physical, buf, 1)))
+  if ((len = (*stream->read) (stream->physical, (char*)buf, 1)))
     {
       if ((buf[0] & _B_CODE) == _B_SINT)
        (*value) = (buf[0] & _B_VALUE);
@@ -595,7 +599,7 @@ objc_read_unsigned_short (struct objc_typed_stream *stream,
          if (nbytes > (int) sizeof (short))
            objc_error (nil, OBJC_ERR_BAD_DATA,
                        "expected short, got int or bigger");
-         len = (*stream->read) (stream->physical, buf + 1, nbytes);
+         len = (*stream->read) (stream->physical, (char*)buf + 1, nbytes);
          (*value) = 0;
          while (pos <= nbytes)
            (*value) = ((*value)*0x100) + buf[pos++];
@@ -605,12 +609,12 @@ objc_read_unsigned_short (struct objc_typed_stream *stream,
 }
 
 
-__inline__ int
+inline int
 objc_read_int (struct objc_typed_stream *stream, int *value)
 {
   unsigned char buf[sizeof (int) + 1];
   int len;
-  if ((len = (*stream->read) (stream->physical, buf, 1)))
+  if ((len = (*stream->read) (stream->physical, (char*)buf, 1)))
     {
       if ((buf[0] & _B_CODE) == _B_SINT)
        (*value) = (buf[0] & _B_VALUE);
@@ -621,7 +625,7 @@ objc_read_int (struct objc_typed_stream *stream, int *value)
          int nbytes = buf[0] & _B_NUMBER;
          if (nbytes > (int) sizeof (int))
            objc_error (nil, OBJC_ERR_BAD_DATA, "expected int, got bigger");
-         len = (*stream->read) (stream->physical, buf + 1, nbytes);
+         len = (*stream->read) (stream->physical, (char*)buf + 1, nbytes);
          (*value) = 0;
          while (pos <= nbytes)
            (*value) = ((*value)*0x100) + buf[pos++];
@@ -632,12 +636,12 @@ objc_read_int (struct objc_typed_stream *stream, int *value)
   return len;
 }
 
-__inline__ int
+inline int
 objc_read_long (struct objc_typed_stream *stream, long *value)
 {
   unsigned char buf[sizeof (long) + 1];
   int len;
-  if ((len = (*stream->read) (stream->physical, buf, 1)))
+  if ((len = (*stream->read) (stream->physical, (char*)buf, 1)))
     {
       if ((buf[0] & _B_CODE) == _B_SINT)
        (*value) = (buf[0] & _B_VALUE);
@@ -648,7 +652,7 @@ objc_read_long (struct objc_typed_stream *stream, long *value)
          int nbytes = buf[0] & _B_NUMBER;
          if (nbytes > (int) sizeof (long))
            objc_error (nil, OBJC_ERR_BAD_DATA, "expected long, got bigger");
-         len = (*stream->read) (stream->physical, buf + 1, nbytes);
+         len = (*stream->read) (stream->physical, (char*)buf + 1, nbytes);
          (*value) = 0;
          while (pos <= nbytes)
            (*value) = ((*value)*0x100) + buf[pos++];
@@ -659,7 +663,7 @@ objc_read_long (struct objc_typed_stream *stream, long *value)
   return len;
 }
 
-__inline__ int
+inline int
 __objc_read_nbyte_uint (struct objc_typed_stream *stream,
                        unsigned int nbytes, unsigned int *val)
 {
@@ -670,7 +674,7 @@ __objc_read_nbyte_uint (struct objc_typed_stream *stream,
   if (nbytes > sizeof (int))
     objc_error (nil, OBJC_ERR_BAD_DATA, "expected int, got bigger");
 
-  len = (*stream->read) (stream->physical, buf, nbytes);
+  len = (*stream->read) (stream->physical, (char*)buf, nbytes);
   (*val) = 0;
   while (pos < nbytes)
     (*val) = ((*val)*0x100) + buf[pos++];
@@ -678,13 +682,13 @@ __objc_read_nbyte_uint (struct objc_typed_stream *stream,
 }
   
 
-__inline__ int
+inline int
 objc_read_unsigned_int (struct objc_typed_stream *stream,
                        unsigned int *value)
 {
   unsigned char buf[sizeof (unsigned int) + 1];
   int len;
-  if ((len = (*stream->read) (stream->physical, buf, 1)))
+  if ((len = (*stream->read) (stream->physical, (char*)buf, 1)))
     {
       if ((buf[0] & _B_CODE) == _B_SINT)
        (*value) = (buf[0] & _B_VALUE);
@@ -707,7 +711,7 @@ __objc_read_nbyte_ulong (struct objc_typed_stream *stream,
   if (nbytes > sizeof (long))
     objc_error (nil, OBJC_ERR_BAD_DATA, "expected long, got bigger");
 
-  len = (*stream->read) (stream->physical, buf, nbytes);
+  len = (*stream->read) (stream->physical, (char*)buf, nbytes);
   (*val) = 0;
   while (pos < nbytes)
     (*val) = ((*val)*0x100) + buf[pos++];
@@ -715,13 +719,13 @@ __objc_read_nbyte_ulong (struct objc_typed_stream *stream,
 }
   
 
-__inline__ int
+inline int
 objc_read_unsigned_long (struct objc_typed_stream *stream,
                         unsigned long *value)
 {
   unsigned char buf[sizeof (unsigned long) + 1];
   int len;
-  if ((len = (*stream->read) (stream->physical, buf, 1)))
+  if ((len = (*stream->read) (stream->physical, (char*)buf, 1)))
     {
       if ((buf[0] & _B_CODE) == _B_SINT)
        (*value) = (buf[0] & _B_VALUE);
@@ -733,20 +737,20 @@ objc_read_unsigned_long (struct objc_typed_stream *stream,
   return len;
 }
 
-__inline__ int
+inline int
 objc_read_string (struct objc_typed_stream *stream,
                  char **string)
 {
   unsigned char buf[sizeof (unsigned int) + 1];
   int len;
-  if ((len = (*stream->read) (stream->physical, buf, 1)))
+  if ((len = (*stream->read) (stream->physical, (char*)buf, 1)))
     {
       unsigned long key = 0;
 
       if ((buf[0]&_B_CODE) == _B_RCOMM)        /* register following */
        {
          len = __objc_read_nbyte_ulong (stream, (buf[0] & _B_VALUE), &key);
-         len = (*stream->read) (stream->physical, buf, 1);
+         len = (*stream->read) (stream->physical, (char*)buf, 1);
        }
 
       switch (buf[0]&_B_CODE) {
@@ -755,7 +759,7 @@ objc_read_string (struct objc_typed_stream *stream,
          int length = buf[0]&_B_VALUE;
          (*string) = (char*)objc_malloc (length + 1);
          if (key)
-           hash_add (&stream->stream_table, LONG2PTR(key), *string);
+           objc_hash_add (&stream->stream_table, LONG2PTR(key), *string);
          len = (*stream->read) (stream->physical, *string, length);
          (*string)[length] = '\0';
        }
@@ -765,7 +769,7 @@ objc_read_string (struct objc_typed_stream *stream,
        {
          char *tmp;
          len = __objc_read_nbyte_ulong (stream, (buf[0] & _B_VALUE), &key);
-         tmp = hash_value_for_key (stream->stream_table, LONG2PTR (key));
+         tmp = objc_hash_value_for_key (stream->stream_table, LONG2PTR (key));
          *string = objc_malloc (strlen (tmp) + 1);
          strcpy (*string, tmp);
        }
@@ -778,7 +782,7 @@ objc_read_string (struct objc_typed_stream *stream,
          if (len) {
            (*string) = (char*)objc_malloc (nbytes + 1);
            if (key)
-             hash_add (&stream->stream_table, LONG2PTR(key), *string);
+             objc_hash_add (&stream->stream_table, LONG2PTR(key), *string);
            len = (*stream->read) (stream->physical, *string, nbytes);
            (*string)[nbytes] = '\0';
          }
@@ -800,7 +804,7 @@ objc_read_object (struct objc_typed_stream *stream, id *object)
 {
   unsigned char buf[sizeof (unsigned int)];
   int len;
-  if ((len = (*stream->read) (stream->physical, buf, 1)))
+  if ((len = (*stream->read) (stream->physical, (char*)buf, 1)))
     {
       SEL read_sel = sel_get_any_uid ("read:");
       unsigned long key = 0;
@@ -808,7 +812,7 @@ objc_read_object (struct objc_typed_stream *stream, id *object)
       if ((buf[0]&_B_CODE) == _B_RCOMM)        /* register common */
        {
          len = __objc_read_nbyte_ulong (stream, (buf[0] & _B_VALUE), &key);
-         len = (*stream->read) (stream->physical, buf, 1);
+         len = (*stream->read) (stream->physical, (char*)buf, 1);
        }
 
       if (buf[0] == (_B_EXT | _BX_OBJECT))
@@ -823,14 +827,14 @@ objc_read_object (struct objc_typed_stream *stream, id *object)
 
          /* register? */
          if (key)
-           hash_add (&stream->object_table, LONG2PTR(key), *object);
+           objc_hash_add (&stream->object_table, LONG2PTR(key), *object);
 
          /* send -read: */
          if (__objc_responds_to (*object, read_sel))
            (*get_imp (class, read_sel)) (*object, read_sel, stream);
 
          /* check null-byte */
-         len = (*stream->read) (stream->physical, buf, 1);
+         len = (*stream->read) (stream->physical, (char*)buf, 1);
          if (buf[0] != '\0')
            objc_error (nil, OBJC_ERR_BAD_DATA,
                        "expected null-byte, got opcode %c", buf[0]);
@@ -841,17 +845,19 @@ objc_read_object (struct objc_typed_stream *stream, id *object)
          if (key)
            objc_error (nil, OBJC_ERR_BAD_KEY, "cannot register use upcode...");
          len = __objc_read_nbyte_ulong (stream, (buf[0] & _B_VALUE), &key);
-         (*object) = hash_value_for_key (stream->object_table, LONG2PTR(key));
+         (*object) = objc_hash_value_for_key (stream->object_table,
+                                              LONG2PTR(key));
        }
 
       else if (buf[0] == (_B_EXT | _BX_OBJREF))        /* a forward reference */
        {
          struct objc_list *other;
          len = objc_read_unsigned_long (stream, &key);
-         other = (struct objc_list *) hash_value_for_key (stream->object_refs, 
+         other 
+           = (struct objc_list *) objc_hash_value_for_key (stream->object_refs, 
                                                           LONG2PTR(key));
-         hash_add (&stream->object_refs, LONG2PTR(key), 
-                   (void *)list_cons (object, other));
+         objc_hash_add (&stream->object_refs, LONG2PTR(key), 
+                        (void *)list_cons (object, other));
        }
 
       else if (buf[0] == (_B_EXT | _BX_OBJROOT)) /* a root object */
@@ -875,19 +881,20 @@ objc_read_class (struct objc_typed_stream *stream, Class *class)
 {
   unsigned char buf[sizeof (unsigned int)];
   int len;
-  if ((len = (*stream->read) (stream->physical, buf, 1)))
+  if ((len = (*stream->read) (stream->physical, (char*)buf, 1)))
     {
       unsigned long key = 0;
 
       if ((buf[0]&_B_CODE) == _B_RCOMM)        /* register following */
        {
          len = __objc_read_nbyte_ulong (stream, (buf[0] & _B_VALUE), &key);
-         len = (*stream->read) (stream->physical, buf, 1);
+         len = (*stream->read) (stream->physical, (char*)buf, 1);
        }
 
       if (buf[0] == (_B_EXT | _BX_CLASS))
        {
-         char *class_name;
+         char temp[1] = "";
+         char *class_name = temp;
          unsigned long version;
 
          /* get class */
@@ -897,10 +904,11 @@ objc_read_class (struct objc_typed_stream *stream, Class *class)
 
          /* register */
          if (key)
-           hash_add (&stream->stream_table, LONG2PTR(key), *class);
+           objc_hash_add (&stream->stream_table, LONG2PTR(key), *class);
 
          objc_read_unsigned_long (stream, &version);
-         hash_add (&stream->class_table, (*class)->name, (void *)version);
+         objc_hash_add (&stream->class_table,
+                        (*class)->name, (void *) ((size_t) version));
        }
 
       else if ((buf[0]&_B_CODE) == _B_UCOMM)
@@ -908,7 +916,8 @@ objc_read_class (struct objc_typed_stream *stream, Class *class)
          if (key)
            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));
+         *class = objc_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);
@@ -926,19 +935,20 @@ objc_read_selector (struct objc_typed_stream *stream, SEL* selector)
 {
   unsigned char buf[sizeof (unsigned int)];
   int len;
-  if ((len = (*stream->read) (stream->physical, buf, 1)))
+  if ((len = (*stream->read) (stream->physical, (char*)buf, 1)))
     {
       unsigned long key = 0;
 
       if ((buf[0]&_B_CODE) == _B_RCOMM)        /* register following */
        {
          len = __objc_read_nbyte_ulong (stream, (buf[0] & _B_VALUE), &key);
-         len = (*stream->read) (stream->physical, buf, 1);
+         len = (*stream->read) (stream->physical, (char*)buf, 1);
        }
 
       if (buf[0] == (_B_EXT|_BX_SEL)) /* selector! */
        {
-         char *selector_name;
+         char temp[1] = "";
+         char *selector_name = temp;
 
          /* get selector */
          len = objc_read_string (stream, &selector_name);
@@ -954,7 +964,8 @@ objc_read_selector (struct objc_typed_stream *stream, SEL* selector)
 
          /* register */
          if (key)
-           hash_add (&stream->stream_table, LONG2PTR(key), (void *) *selector);
+           objc_hash_add (&stream->stream_table,
+                          LONG2PTR(key), (void *) *selector);
        }
 
       else if ((buf[0]&_B_CODE) == _B_UCOMM)
@@ -962,8 +973,8 @@ objc_read_selector (struct objc_typed_stream *stream, SEL* selector)
          if (key)
            objc_error (nil, OBJC_ERR_BAD_KEY, "cannot register use upcode...");
          len = __objc_read_nbyte_ulong (stream, (buf[0] & _B_VALUE), &key);
-         (*selector) = hash_value_for_key (stream->stream_table, 
-                                           LONG2PTR(key));
+         (*selector) = objc_hash_value_for_key (stream->stream_table, 
+                                                LONG2PTR(key));
        }
 
       else
@@ -1032,11 +1043,11 @@ objc_write_type (TypedStream *stream, const char *type, const void *data)
 
   case _C_CHARPTR:
     return objc_write_string (stream,
-                             *(char **) data, strlen (*(char **) data));
+                             *(unsigned char **) data, strlen (*(char **) data));
     break;
 
   case _C_ATOM:
-    return objc_write_string_atomic (stream, *(char **) data, 
+    return objc_write_string_atomic (stream, *(unsigned char **) data, 
                                     strlen (*(char **) data));
     break;
 
@@ -1058,7 +1069,7 @@ objc_write_type (TypedStream *stream, const char *type, const void *data)
       while (*type != _C_STRUCT_E)
        {
          align = objc_alignof_type (type);       /* padd to alignment */
-         acc_size += ROUND (acc_size, align);
+         acc_size = ROUND (acc_size, align);
          objc_write_type (stream, type, ((char *) data) + acc_size);
          acc_size += objc_sizeof_type (type);   /* add component size */
          type = objc_skip_typespec (type);      /* skip component */
@@ -1154,7 +1165,7 @@ objc_read_type(TypedStream *stream, const char *type, void *data)
       while (*type != _C_STRUCT_E)
        {
          align = objc_alignof_type (type);       /* padd to alignment */
-         acc_size += ROUND (acc_size, align);
+         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 */
@@ -1241,15 +1252,15 @@ objc_write_types (TypedStream *stream, const char *type, ...)
 
       case _C_CHARPTR:
        {
-         char **str = va_arg (args, char **);
-         res = objc_write_string (stream, *str, strlen (*str));
+         unsigned char **str = va_arg (args, unsigned char **);
+         res = objc_write_string (stream, *str, strlen ((char*)*str));
        }
        break;
 
       case _C_ATOM:
        {
-         char **str = va_arg (args, char **);
-         res = objc_write_string_atomic (stream, *str, strlen (*str));
+         unsigned char **str = va_arg (args, unsigned char **);
+         res = objc_write_string_atomic (stream, *str, strlen ((char*)*str));
        }
        break;
 
@@ -1473,54 +1484,54 @@ __objc_write_typed_stream_signature (TypedStream *stream)
 
 static void __objc_finish_write_root_object(struct objc_typed_stream *stream)
 {
-  hash_delete (stream->object_table);
-  stream->object_table = hash_new(64,
-                                 (hash_func_type)hash_ptr,
-                                 (compare_func_type)compare_ptrs);
+  objc_hash_delete (stream->object_table);
+  stream->object_table = objc_hash_new (64,
+                                       (hash_func_type) objc_hash_ptr,
+                                       (compare_func_type) objc_compare_ptrs);
 }
 
 static void __objc_finish_read_root_object(struct objc_typed_stream *stream)
 {
   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);
+  cache_ptr free_list = objc_hash_new (64,
+                                      (hash_func_type) objc_hash_ptr,
+                                      (compare_func_type) objc_compare_ptrs);
 
   /* resolve object forward references */
-  for (node = hash_next (stream->object_refs, NULL); node;
-       node = hash_next (stream->object_refs, node))
+  for (node = objc_hash_next (stream->object_refs, NULL); node;
+       node = objc_hash_next (stream->object_refs, node))
     {
       struct objc_list *reflist = node->value;
       const void *key = node->key;
-      id object = hash_value_for_key (stream->object_table, key);
+      id object = objc_hash_value_for_key (stream->object_table, key);
       while (reflist)
        {
          *((id*) reflist->head) = object;
-         if (hash_value_for_key (free_list,reflist) == NULL)
-           hash_add (&free_list,reflist,reflist);
+         if (objc_hash_value_for_key (free_list,reflist) == NULL)
+           objc_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))
+  for (node = objc_hash_next (free_list, NULL); node;
+       node = objc_hash_next (free_list, node))
     objc_free ((void *) node->key);
 
-  hash_delete (free_list);
+  objc_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);
+  objc_hash_delete (stream->object_refs);
+  stream->object_refs = objc_hash_new (8, (hash_func_type) objc_hash_ptr,
+                                      (compare_func_type) objc_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))
+      for (node = objc_hash_next (stream->object_table, NULL); node;
+          node = objc_hash_next (stream->object_table, node))
        {
          id object = node->value;
          if (__objc_responds_to (object, awake_sel))
@@ -1529,10 +1540,10 @@ static void __objc_finish_read_root_object(struct objc_typed_stream *stream)
     }
 
   /* empty object table */
-  hash_delete (stream->object_table);
-  stream->object_table = hash_new(64,
-                                 (hash_func_type)hash_ptr,
-                                 (compare_func_type)compare_ptrs);
+  objc_hash_delete (stream->object_table);
+  stream->object_table = objc_hash_new(64,
+                                      (hash_func_type)objc_hash_ptr,
+                                      (compare_func_type)objc_compare_ptrs);
 }
 
 /*
@@ -1546,21 +1557,22 @@ objc_open_typed_stream (FILE *physical, int mode)
 
   s->mode = mode;
   s->physical = physical;
-  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->stream_table = objc_hash_new (64,
+                                  (hash_func_type) objc_hash_ptr,
+                                  (compare_func_type) objc_compare_ptrs);
+  s->object_table = objc_hash_new (64,
+                                  (hash_func_type) objc_hash_ptr,
+                                  (compare_func_type) objc_compare_ptrs);
   s->eof = (objc_typed_eof_func) __objc_feof;
   s->flush = (objc_typed_flush_func) fflush;
   s->writing_root_p = 0;
   if (mode == OBJC_READONLY)
     {
-      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->class_table 
+       = objc_hash_new (8, (hash_func_type) objc_hash_string,
+                        (compare_func_type) objc_compare_strings);
+      s->object_refs = objc_hash_new (8, (hash_func_type) objc_hash_ptr,
+                                     (compare_func_type) objc_compare_ptrs);
       s->read = (objc_typed_read_func) __objc_fread;
       s->write = (objc_typed_write_func) __objc_no_write;
       __objc_read_typed_stream_signature (s);
@@ -1619,12 +1631,12 @@ objc_close_typed_stream (TypedStream *stream)
   if (stream->mode == OBJC_READONLY)
     {
       __objc_finish_read_root_object (stream); /* Just in case... */
-      hash_delete (stream->class_table);
-      hash_delete (stream->object_refs);
+      objc_hash_delete (stream->class_table);
+      objc_hash_delete (stream->object_refs);
     }
 
-  hash_delete (stream->stream_table);
-  hash_delete (stream->object_table);
+  objc_hash_delete (stream->stream_table);
+  objc_hash_delete (stream->object_table);
 
   if (stream->type == (OBJC_MANAGED_STREAM | OBJC_FILE_STREAM))
     fclose ((FILE *)stream->physical);
@@ -1648,7 +1660,8 @@ long
 objc_get_stream_class_version (TypedStream *stream, Class class)
 {
   if (stream->class_table)
-    return PTR2LONG(hash_value_for_key (stream->class_table, class->name));
+    return PTR2LONG(objc_hash_value_for_key (stream->class_table,
+                                            class->name));
   else
     return class_get_version (class);
 }