Runtime portability cleanup
authorKresten Krab Thorup <krab@gcc.gnu.org>
Mon, 26 Apr 1993 16:06:37 +0000 (16:06 +0000)
committerKresten Krab Thorup <krab@gcc.gnu.org>
Mon, 26 Apr 1993 16:06:37 +0000 (16:06 +0000)
From-SVN: r4235

15 files changed:
gcc/objc/Makefile.in
gcc/objc/Object.m
gcc/objc/archive.c
gcc/objc/class.c
gcc/objc/hash.c
gcc/objc/hash.h
gcc/objc/init.c
gcc/objc/misc.c
gcc/objc/objc-api.h
gcc/objc/objc.h
gcc/objc/objects.c
gcc/objc/runtime.h
gcc/objc/sarray.c
gcc/objc/sarray.h
gcc/objc/sendmsg.c

index 656fcddcad4a41f89e4ac2a68ea0e44f9b72ad53..2f38a256f230da1abac01ecb1460aa7dff528eec 100644 (file)
@@ -29,7 +29,7 @@
 .SUFFIXES: .m
 
 OPTIMIZE= -O
-CFLAGS = $(GCC_CFLAGS) -DIN_OBJC
+CFLAGS = $(GCC_CFLAGS) 
 
 VPATH = $(srcdir)/objc
 
index f08350accf88586696175216af06360f4caed173..dd27f2d8316fe4a41456d4cc12fcb84acecb841e 100644 (file)
@@ -105,7 +105,7 @@ extern int errno;
 
 - (unsigned int)hash
 {
-  return (unsigned int)self;
+  return (size_t)self;
 }
 
 - (BOOL)isEqual:anObject
@@ -290,8 +290,8 @@ extern int errno;
 - error:(const char *)aString, ...
 {
 #define FMT "error: %s (%s)\n%s\n"
-  char fmt[(strlen(FMT)+strlen(object_get_class_name(self))
-            +((aString!=NULL)?strlen(aString):0)+8)];
+  char fmt[(strlen((char*)FMT)+strlen((char*)object_get_class_name(self))
+            +((aString!=NULL)?strlen((char*)aString):0)+8)];
   va_list ap;
 
   sprintf(fmt, FMT, object_get_class_name(self),
index 17836e76933574f61ad46ad2997df45bdbb13ceb..77cc4f0e23963f629df5710bdf8824d2206fd4f7 100644 (file)
@@ -369,8 +369,8 @@ __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,
-                          strlen(class->name));
-  objc_write_unsigned_int (stream, CLS_GETNUMBER(class));
+                          strlen((char*)class->name));
+  return objc_write_unsigned_int (stream, CLS_GETNUMBER(class));
 }
 
 
@@ -397,7 +397,7 @@ __objc_write_selector (struct objc_typed_stream* stream, SEL selector)
 {
   const char* sel_name = sel_get_name (selector);
   __objc_write_extension (stream, _BX_SEL);
-  return objc_write_string (stream, sel_name, strlen(sel_name));
+  return objc_write_string (stream, sel_name, strlen ((char*)sel_name));
 }
 
 int 
@@ -1303,6 +1303,7 @@ __objc_read_typed_stream_signature (TypedStream* stream)
   sscanf (buffer, "GNU TypedStream %d", &stream->version);
   if (stream->version != OBJC_TYPED_STREAM_VERSION)
     __objc_fatal ("cannot handle TypedStream version %d", stream->version);
+  return 1;
 }
 
 static int
@@ -1312,6 +1313,7 @@ __objc_write_typed_stream_signature (TypedStream* stream)
   sprintf(buffer, "GNU TypedStream %d", OBJC_TYPED_STREAM_VERSION);
   stream->version = OBJC_TYPED_STREAM_VERSION;
   (*stream->write)(stream->physical, buffer, strlen(buffer)+1);
+  return 1;
 }
 
 static void __objc_finish_write_root_object(struct objc_typed_stream* stream)
index a5feef57b97731643069917c57b914fb8001b250..87ebf258bec9dbded22edae1d62af687577626db 100644 (file)
@@ -139,7 +139,6 @@ objc_get_class (const char *name)
 void __objc_resolve_class_links()
 {
   node_ptr node;
-  Class_t class1;
   Class_t object_class = objc_get_class ("Object");
 
   assert(object_class);
@@ -230,8 +229,7 @@ class_pose_as (Class_t impostor, Class_t super_class)
   Class_t new_class = (Class_t) calloc (1, sizeof (Class));
   MetaClass_t new_meta_class =
     (MetaClass_t) __objc_xmalloc(sizeof (MetaClass));
-  node_ptr node;
-  char *new_name = (char *)__objc_xmalloc (strlen (super_class->name) + 12);
+  char *new_name = (char *)__objc_xmalloc ((size_t)strlen ((char*)super_class->name) + 12);
 
   /* We must know the state of the hierachy.  Do initial setup if needed */
   if(!CLS_ISRESOLV(impostor))
index 7189c1d5bc86602626717a1f9b5d0691d84abff0..294d87bfdf6ef5c7a3ef5faaf2e06a1866a1ced8 100644 (file)
@@ -45,7 +45,6 @@ hash_new (unsigned int size, hash_func_type hash_func,
 {
   cache_ptr cache;
 
-
   /* Pass me a value greater than 0 and a power of 2.  */
   assert (size);
   assert (!(size & (size - 1)));
@@ -84,7 +83,7 @@ hash_delete (cache_ptr cache)
 
 
   /* Purge all key/value pairs from the table.  */
-  while (node = hash_next (cache, NULL))
+  while ((node = hash_next (cache, NULL)))
     hash_remove (cache, node->key);
 
   /* Release the array of nodes and the cache itself.  */
@@ -145,7 +144,7 @@ hash_add (cache_ptr *cachep, const void *key, void *value)
                  *cachep, (*cachep)->size, new->size);
 
     /* Copy the nodes from the first hash table to the new one.  */
-    while (node1 = hash_next (*cachep, node1))
+    while ((node1 = hash_next (*cachep, node1)))
       hash_add (&new, node1->key, node1->value);
 
     /* Trash the old cache.  */
index 6516b8a407c8444425dfa9aa83c30049975e2c92..2c6ff126268504ada5817458258a075f9f5dede4 100644 (file)
@@ -27,7 +27,7 @@ the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  */
 #ifndef __hash_INCLUDE_GNU
 #define __hash_INCLUDE_GNU
 
-#ifdef IN_OBJC
+#ifdef IN_GCC
 #include "gstddef.h"
 #else
 #include <stddef.h>
index 453f166ef1c6940fdae27ef1257e360db0b3cc40..c42715cdebf779093775479ae5fad8038f8c4798 100644 (file)
@@ -66,9 +66,6 @@ __objc_exec_class (Module_t module)
   /* The symbol table (defined in objc.h) generated by gcc */
   Symtab_t symtab = module->symtab;
 
-  /* Pointer to the class Object class object */
-  Class_t object_class;
-
   /* Entry used to traverse hash lists */
   struct objc_list** cell;
 
@@ -166,7 +163,7 @@ __objc_exec_class (Module_t module)
      categories to objects.  */
   for (cell = &unclaimed_categories;
        *cell;
-       *cell && (cell = &(*cell)->tail))
+       *cell && ((cell = &(*cell)->tail)))
     {
       Category_t category = (*cell)->head;
       Class_t class = objc_lookup_class (category->class_name);
@@ -247,7 +244,7 @@ __objc_init_protocols (struct objc_protocol_list* protos)
        {
          fprintf (stderr,
                   "Version %d doesn't protocol version %d\n",
-                  ((int)((id)protos->list[i])->class_pointer),
+                  ((size_t)((id)protos->list[i])->class_pointer),
                   PROTOCOL_VERSION);
          abort ();
        }
@@ -257,11 +254,6 @@ __objc_init_protocols (struct objc_protocol_list* protos)
 static void __objc_class_add_protocols (Class_t class,
                                        struct objc_protocol_list* protos)
 {
-#ifndef NeXT_OBJC              /* force class Protocol to be linked in */
-  extern char* __objc_class_name_Protocol;
-  char* x = __objc_class_name_Protocol;
-#endif
-
   /* Well... */
   if (! protos)
     return;
index b4e08a50bb0c54a9457607c0fb2eee26acb9fd5f..54bd6a29ce9eb9a5968fe97d0275e937a6773b58 100644 (file)
@@ -43,7 +43,7 @@ objc_error(id object, const char* fmt, va_list ap)
 volatile void
 objc_fatal(const char* msg)
 {
-  write(2, msg, strlen(msg));
+  write(2, msg, (size_t)strlen((char*)msg));
   abort();
 }
 
index f407be03c74ea31cead112e7f3a2f74a8c52423d..8a0370f0491c52a2ed31c170f9b6c2fb8a30f45b 100644 (file)
@@ -28,7 +28,7 @@ the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  */
 
 #include "objc/objc.h"
 #include "objc/hash.h"
-
+#include <memory.h>
 
 static const ARGSIZE = 96;             /* for `method_get_argsize()' */
 
@@ -154,7 +154,7 @@ object_copy(id object)
         {
           id copy = class_create_instance(object->class_pointer);
           if (copy!=nil)
-            bcopy(object, copy, object->class_pointer->instance_size);
+            memcpy(copy, object, (size_t)object->class_pointer->instance_size);
           return copy;
         }
       return nil;
index 8d7b0594a833b6146c7c1865160b880f6eef44bc..c06a0135962ebe1c6c8356490319bef279c9a5fc 100644 (file)
@@ -26,6 +26,18 @@ the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  */
 #ifndef __objc_INCLUDE_GNU
 #define __objc_INCLUDE_GNU
 
+#ifdef IN_GCC
+#include "config.h"
+#include "gstddef.h"
+#else
+#include <stddef.h>
+#endif
+
+extern size_t strlen(char*);
+extern void* malloc(size_t);
+extern void* calloc(size_t, size_t);
+extern void* realloc(const void*, size_t);
+extern void free(const void*);
 
 /*
 ** Hash-cache or sparse arrays?
@@ -43,7 +55,7 @@ extern const char* __objc_hash_lookup_id;
 
 
 #include <stdio.h>
-#ifdef IN_OBJC
+#ifdef IN_GCC
 #include <gstdarg.h>
 #else
 #include <stdarg.h>
@@ -290,7 +302,7 @@ struct objc_class {
                                                 Object. */
   const char*         name;                   /* Name of the class. */
   long                version;                /* Unknown. */
-  long                info;                   /* Bit mask.  See class masks 
+  unsigned long       info;                   /* Bit mask.  See class masks 
                                                 defined above. */
   long                instance_size;          /* Size in bytes of the class.  
                                                 The sum of the class definition 
@@ -388,7 +400,7 @@ struct objc_protocol_list {
 #define CLS_GETNUMBER(cls) (__CLS_INFO(cls) >> (HOST_BITS_PER_LONG/2))
 #define CLS_SETNUMBER(cls, num) \
   ({ assert(CLS_GETNUMBER(cls)==0); \
-     __CLS_SETINFO(cls, ((num) << (HOST_BITS_PER_LONG/2))); })
+     __CLS_SETINFO(cls, (((unsigned long)num) << (HOST_BITS_PER_LONG/2))); })
 
 /*
 ** The compiler generates one of these structures for each category.  A class
index a8f1a3be94fe765fd1f417f02589f741340ea6a9..5463f6eeb1915215d295438bba4ed5c873d590d0 100644 (file)
@@ -68,7 +68,7 @@ id __objc_object_dispose(id object)
 id __objc_object_copy(id object)
 {
   id copy = class_create_instance(object->class_pointer);
-  bcopy(object, copy, object->class_pointer->instance_size);
+  memcpy(copy, object, object->class_pointer->instance_size);
   return copy;
 }
 
index 1d9924f58705b010441cc837f9b3d564dbb818a6..e61d4d230b9b2368d29d3d7c3fe68c9f30d4d7e7 100644 (file)
@@ -27,7 +27,9 @@ You should have received a copy of the GNU General Public License along with
 #ifndef __objc_runtime_INCLUDE_GNU
 #define __objc_runtime_INCLUDE_GNU
 
-#include <stdio.h>             /* argh! I hate this */
+#include <stdio.h>
+#include <memory.h>
+#include <ctype.h>
 
 #include "gstdarg.h"           /* for varargs and va_list's */
 #include "gstddef.h"           /* so noone else will get system versions */
@@ -47,6 +49,7 @@ extern void __objc_install_premature_dtable(Class_t); /* (objc-dispatch.c) */
 extern void __objc_resolve_class_links(); /* (objc-class.c) */
 extern void __objc_register_selectors_from_class(Class_t); /* (objc-sel.c) */
 extern void __objc_update_dispatch_table_for_class (Class_t);/* (objc-msg.c) */
+extern void class_add_method_list(Class_t, MethodList_t);
 
 /* True when class links has been resolved */     
 extern BOOL __objc_class_links_resolved;
index 50deeb0cf390bfebcee0be165cfd9eb47365b503..0dd584a50b752e6ce29bc8133779137be04f6e6c 100644 (file)
@@ -26,6 +26,7 @@ the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  */
 #include "objc/sarray.h"
 #include <stdio.h>
 #include "assert.h"
+#include <memory.h>
 
 int nbuckets = 0;
 int nindices = 0;
@@ -43,7 +44,9 @@ const char* __objc_sparse3_id = "3 level sparse indices";
 void
 sarray_at_put(struct sarray* array, sidx index, void* element)
 {
+#ifdef OBJC_SPARSE3
   struct sindex** the_index;
+#endif
   struct sbucket** the_bucket;
 #ifdef OBJC_SPARSE3
   size_t ioffset;
@@ -84,7 +87,7 @@ sarray_at_put(struct sarray* array, sidx index, void* element)
 
     /* The index was previously empty, allocate a new */
     *the_index = (struct sindex*)__objc_xmalloc(sizeof(struct sindex));
-    bcopy(array->empty_index, *the_index, sizeof(struct sindex));
+    memcpy(*the_index, array->empty_index, sizeof(struct sindex));
     (*the_index)->version = array->version;
     the_bucket = &((*the_index)->buckets[boffset]);
     nindices += 1;
@@ -94,7 +97,7 @@ sarray_at_put(struct sarray* array, sidx index, void* element)
     /* This index must be lazy copied */
     struct sindex* old_index = *the_index;
     *the_index = (struct sindex*)__objc_xmalloc(sizeof(struct sindex));
-    bcopy(old_index, *the_index, sizeof(struct sindex));
+    memcpy( *the_index,old_index, sizeof(struct sindex));
     (*the_index)->version = array->version;
     the_bucket = &((*the_index)->buckets[boffset]);
     nindices += 1;
@@ -110,7 +113,7 @@ sarray_at_put(struct sarray* array, sidx index, void* element)
     /* The bucket was previously empty (or something like that), */
     /* allocate a new.  This is the effect of `lazy' allocation */  
     *the_bucket = (struct sbucket*)__objc_xmalloc(sizeof(struct sbucket));
-    bcopy(array->empty_bucket, *the_bucket, sizeof(struct sbucket));
+    memcpy( *the_bucket,array->empty_bucket, sizeof(struct sbucket));
     (*the_bucket)->version = array->version;
     nbuckets += 1;
 
@@ -119,7 +122,7 @@ sarray_at_put(struct sarray* array, sidx index, void* element)
     /* Perform lazy copy. */
     struct sbucket* old_bucket = *the_bucket;
     *the_bucket = (struct sbucket*)__objc_xmalloc(sizeof(struct sbucket));
-    bcopy(old_bucket, *the_bucket, sizeof(struct sbucket));
+    memcpy( *the_bucket,old_bucket, sizeof(struct sbucket));
     (*the_bucket)->version = array->version;
     nbuckets += 1;
 
@@ -401,7 +404,7 @@ sarray_lazy_copy(struct sarray* oarr)
 
   /* Allocate core array */
   arr = (struct sarray*) __objc_xmalloc(sizeof(struct sarray));
-  bcopy(oarr, arr, sizeof(struct sarray));
+  memcpy( arr,oarr, sizeof(struct sarray));
   arr->version = oarr->version + 1;
   arr->is_copy_of = oarr;
   oarr->ref_count += 1;
@@ -411,13 +414,13 @@ sarray_lazy_copy(struct sarray* oarr)
   /* Copy bucket table */
   arr->indices = (struct sindex**) 
     __objc_xmalloc(sizeof(struct sindex*)*num_indices);
-  bcopy(oarr->indices, arr->indices, 
+  memcpy( arr->indices,oarr->indices, 
        sizeof(struct sindex*)*num_indices);
 #else 
   /* Copy bucket table */
   arr->buckets = (struct sbucket**) 
     __objc_xmalloc(sizeof(struct sbucket*)*num_indices);
-  bcopy(oarr->buckets, arr->buckets, 
+  memcpy( arr->buckets,oarr->buckets, 
        sizeof(struct sbucket*)*num_indices);
 #endif
 
index 1d96078dc74ca34224af8a5e4e1de1952c0165a8..7ef2f1cc2e8e498f3e3d461ce518fe852212794a 100644 (file)
@@ -39,7 +39,7 @@ extern const char* __objc_sparse2_id;
 extern const char* __objc_sparse3_id;
 #endif
 
-#ifdef IN_OBJC
+#ifdef IN_GCC
 #include "gstddef.h"
 #else
 #include <stddef.h>
index 1e14470cab697ded764277a2af3f2b62fd119903..bf38b67ef6ac23f088046a5a918b9d77cabc95b6 100644 (file)
@@ -205,7 +205,6 @@ void __objc_install_premature_dtable(Class_t class)
 static void __objc_send_initialize(Class_t class)
 {
   Method_t m;
-  IMP imp;
 
   /* This *must* be a class object */
   assert(CLS_ISCLASS(class));
@@ -450,8 +449,8 @@ __objc_missing_method (id object, SEL sel, ...)
   /* The object doesn't recognize the method.  Check for responding to
      error:.  If it does then sent it. */
   {
-    char msg[256 + strlen (sel_get_name (sel))
-             + strlen (object->class_pointer->name)];
+    char msg[256 + strlen ((char*)sel_get_name (sel))
+             + strlen ((char*)object->class_pointer->name)];
 
     sprintf (msg, "(%s) %s does not recognize %s",
             (CLS_ISMETA(object->class_pointer)
@@ -471,7 +470,7 @@ __objc_missing_method (id object, SEL sel, ...)
   }
 }
 
-int __objc_print_dtable_stats()
+void __objc_print_dtable_stats()
 {
   int total = 0;
   printf("memory usage: (%s)\n",
@@ -504,7 +503,7 @@ int __objc_print_dtable_stats()
   printf("-----------------------------------\n");
   printf("total: %d bytes\n", total);
   printf("===================================\n");
-  }
+}
 
 #ifdef OBJC_HASH_LOOKUP
 static Cache_t __objc_cache_insert(Cache_t cache, SEL op, IMP imp);