OSDN Git Service

PR preprocessor/16323
[pf3gnuchains/gcc-fork.git] / libobjc / archive.c
index f424504..096ca69 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.
@@ -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;
 }
@@ -323,12 +323,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 +341,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 +366,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 +376,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);
@@ -431,11 +431,11 @@ objc_write_object (struct objc_typed_stream *stream, id object)
     }
 }
 
-__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);
 }
@@ -459,16 +459,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 
@@ -501,12 +501,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 +528,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 +549,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 +566,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 +577,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 +595,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 +605,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 +621,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 +632,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 +648,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 +659,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 +670,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 +678,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 +707,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 +715,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 +733,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) {
@@ -800,7 +800,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 +808,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))
@@ -830,7 +830,7 @@ objc_read_object (struct objc_typed_stream *stream, id *object)
            (*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]);
@@ -875,19 +875,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 */
@@ -926,19 +927,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);
@@ -1032,11 +1034,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;
 
@@ -1241,15 +1243,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;