Runtime portability cleanup

From-SVN: r4235
This commit is contained in:
Kresten Krab Thorup 1993-04-26 16:06:37 +00:00
parent 0cd02cbbfb
commit a7ab3794a9
15 changed files with 53 additions and 45 deletions

View File

@ -29,7 +29,7 @@
.SUFFIXES: .m
OPTIMIZE= -O
CFLAGS = $(GCC_CFLAGS) -DIN_OBJC
CFLAGS = $(GCC_CFLAGS)
VPATH = $(srcdir)/objc

View 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),

View 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)

View 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))

View 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. */

View 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>

View 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;

View 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();
}

View 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;

View 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

View 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;
}

View 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;

View 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

View 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>

View 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);