#ifndef __hash_INCLUDE_GNU
#define __hash_INCLUDE_GNU
-
+#ifdef IN_OBJC
+#include "gstddef.h"
+#else
+#include <stddef.h>
+#endif
/*
* This data structure is used to hold items
manipulation of the key pointer. (Use the lowest bits
except for those likely to be 0 due to alignment.) */
-static inline unsigned int
+static inline unsigned int
hash_ptr (cache_ptr cache, const void *key)
{
- return ((unsigned int)key / sizeof (void *)) & cache->mask;
+ return ((size_t)key / sizeof (void *)) & cache->mask;
}
for(i = 0; i < protos->count; i++)
{
- if (((int)((id)protos->list[i])->class_pointer) == PROTOCOL_VERSION)
+ if (((size_t)((id)protos->list[i])->class_pointer) == PROTOCOL_VERSION)
((id)protos->list[i])->class_pointer = proto_class;
else
{
objc_msg_lookup(id receiver, SEL op)
{
if(receiver)
- return sarray_get(receiver->class_pointer->dtable, (unsigned int) op);
+ return sarray_get(receiver->class_pointer->dtable, (size_t) op);
else
return nil_method;
}
struct sindex** the_index;
struct sbucket** the_bucket;
#ifdef OBJC_SPARSE3
- unsigned int ioffset;
+ size_t ioffset;
#endif
- unsigned int boffset;
- unsigned int eoffset;
+ size_t boffset;
+ size_t eoffset;
#ifdef PRECOMPUTE_SELECTORS
union sofftype xx;
xx.idx = index;
sarray_new (int size, void* default_element)
{
#ifdef OBJC_SPARSE3
- unsigned num_indices = ((size-1)/(INDEX_CAPACITY))+1;
+ size_t num_indices = ((size-1)/(INDEX_CAPACITY))+1;
#else /* OBJC_SPARSE2 */
- unsigned num_indices = ((size-1)/BUCKET_SIZE)+1;
+ size_t num_indices = ((size-1)/BUCKET_SIZE)+1;
#endif
int counter;
struct sarray* arr;
void
sarray_free(struct sarray* array) {
#ifdef OBJC_SPARSE3
- unsigned int old_max_index = (array->capacity-1)/INDEX_CAPACITY;
+ size_t old_max_index = (array->capacity-1)/INDEX_CAPACITY;
#else
- unsigned int old_max_index = (array->capacity-1)/BUCKET_SIZE;
+ size_t old_max_index = (array->capacity-1)/BUCKET_SIZE;
#endif
int counter = 0;
sarray_lazy_copy(struct sarray* oarr)
{
#ifdef OBJC_SPARSE3
- unsigned num_indices = ((oarr->capacity-1)/INDEX_CAPACITY)+1;
+ size_t num_indices = ((oarr->capacity-1)/INDEX_CAPACITY)+1;
#else /* OBJC_SPARSE2 */
- unsigned num_indices = ((oarr->capacity-1)/BUCKET_SIZE)+1;
+ size_t num_indices = ((oarr->capacity-1)/BUCKET_SIZE)+1;
#endif
struct sarray* arr;
#include <assert.h>
+/* An unsigned integer of same size as a pointer */
+#define SIZET_BITS (sizeof(size_t)*8)
+
#if defined(sparc) || defined(OBJC_SPARSE2)
#define PRECOMPUTE_SELECTORS
#endif
#endif /* OBJC_SPARSE2 */
-typedef unsigned int sidx;
+typedef size_t sidx;
#ifdef PRECOMPUTE_SELECTORS
struct soffset {
#ifdef OBJC_SPARSE3
- unsigned char unused;
- unsigned char eoffset;
- unsigned char boffset;
- unsigned char ioffset;
+ unsigned int unused : SIZET_BITS/4;
+ unsigned int eoffset : SIZET_BITS/4;
+ unsigned int boffset : SIZET_BITS/4;
+ unsigned int ioffset : SIZET_BITS/4;
#else /* OBJC_SPARSE2 */
#ifdef sparc
- unsigned int boffset : 30 - BUCKET_BITS;
+ unsigned int boffset : (SIZET_BITS - 2) - BUCKET_BITS;
unsigned int eoffset : BUCKET_BITS;
unsigned int unused : 2;
#else
- unsigned short boffset;
- unsigned short eoffset;
+ unsigned int boffset : SIZET_BITS/2;
+ unsigned int eoffset : SIZET_BITS/2;
#endif
#endif /* OBJC_SPARSE2 */
};
}
static inline sidx
-soffset_encode(unsigned int offset)
+soffset_encode(size_t offset)
{
union sofftype x;
x.off.eoffset = offset%BUCKET_SIZE;
#else /* not PRECOMPUTE_SELECTORS */
-static inline unsigned int
+static inline size_t
soffset_decode(sidx index)
{
return index;
}
static inline sidx
-soffset_encode(unsigned int offset)
+soffset_encode(size_t offset)
{
return offset;
}
const char*
sel_get_name (SEL selector)
{
- if ((soffset_decode((unsigned)selector) > 0)
- && (soffset_decode((unsigned)selector) <= __objc_selector_max_index))
+ if ((soffset_decode((sidx)selector) > 0)
+ && (soffset_decode((sidx)selector) <= __objc_selector_max_index))
return sarray_get (__objc_selector_array, (sidx) selector);
else
return NULL;
get_imp (Class_t class, SEL sel)
{
#ifdef OBJC_SPARSE_LOOKUP
- void* res = sarray_get (class->dtable, (unsigned int) sel);
+ void* res = sarray_get (class->dtable, (size_t) sel);
if(res == __objc_init_install_dtable)
__objc_install_dispatch_table_for_class (class);
- return sarray_get (class->dtable, (unsigned int) sel);
+ return sarray_get (class->dtable, (size_t) sel);
#else
return cache_get (class, sel);
#endif
static Cache_t
__objc_cache_insert(Cache_t cache, SEL op, IMP imp)
{
- int index = ((unsigned int)op)&(cache)->mask;
+ int index = ((size_t)op)&(cache)->mask;
if(op == 0)
return cache;