+2004-05-25 Andrew Pinski <pinskia@physics.uc.edu>
+
+ Merge from the libobjc-branch
+ 2004-02-09 Andrew Pinski <pinskia@physics.uc.edu>
+
+ * Makefile.in (OBJC_H): Change objc-deps.h to objc-decls.h.
+
+ 2004-02-03 Andrew Pinski <pinskia@physics.uc.edu>
+
+ * Makefile.in (OBJC_H): Add objc-deps.h.
+
+ 2004-01-27 Nicola Pero <n.pero@mi.flashnet.it>
+
+ * Protocol.m ([-conformsTo:]): If the argument is nil, return NO.
+ ([-hash], [-isEqual:]): New methods.
+
+ 2004-01-27 Richard Frith-Macdonald <rfm@gnu.org>
+
+ * sarray.c (sarray_free): Add a better comment.
+
+ 2004-01-27 Adam Fedor <fedor@gnu.org>
+
+ * hash.c (hash_add): Cast cachep to int.
+ * selector.c (__sel_register_typed_name): Cast
+ soffset_decode to int.
+
+ 2004-01-27 Alexander Malmberg <alexander@malmberg.org>
+
+ * selector.c: Rename register_selectors_from_list to
+ __objc_register_selectors_from_list. Update caller.
+ (__objc_register_selectors_from_list): Lock __objc_runtime_mutex
+ while registering selectors. Use __sel_register_typed_name instead
+ of sel_register_typed_name. Check for NULL method_name:s.
+ (pool_alloc_selector): New function.
+ (__sel_register_typed_name): Use pool_alloc_selector to allocate
+ selector structures.
+ * sendmsg.c (class_add_method_list): Use
+ __objc_register_selectors_from_list.
+ * objc/runtime.h: Add __objc_register_selectors_from_list.
+
+ 2004-01-25 Adam Fedor <fedor@gnu.org>
+ Nicola Pero <n.pero@mi.flashnet.it>
+ Andrew Pinski <pinskia@physics.uc.edu>
+
+ * objc/objc-decls.h: New file.
+ * objc/objc-api.h (_objc_lookup_class): Mark as export.
+ (_objc_load_callback): Likewise.
+ (_objc_object_alloc): Likewise.
+ (_objc_object_copy): Likewise.
+ (_objc_object_dispose): Likewise.
+
+ 2004-01-25 Andrew Pinski <pinskia@physics.uc.edu>
+
+ * archive.c: s/__inline__/inline
+ * sendmsg.c: Likewise.
+
+ * encoding.c: Remove FIXME about the warning
+ about unused variable.
+ * sendmsg.c: Add a FIXME comment saying that
+ this should be using libffi.
+
+ * Makefile.in (LIBTOOL): Use @LIBTOOL@ now as it works.
+
+
2004-05-13 Andrew Pinski <pinskia@physics.uc.edu>
* archive.c (objc_read_class): Initialize class_name.
# numbers.
LIBOBJC_VERSION = @VERSION@
LIBOBJC_GC_VERSION = @VERSION@
-# @LIBTOOL@ does not get it right, so we hack it in - FIXME
-LIBTOOL = ./libtool
+LIBTOOL = @LIBTOOL@
LIBTOOL_COMPILE = $(LIBTOOL) --mode=compile
LIBTOOL_LINK = $(LIBTOOL) --mode=link
LIBTOOL_INSTALL = $(LIBTOOL) --mode=install
OBJC_H = hash.h objc-list.h sarray.h objc.h objc-api.h \
NXConstStr.h Object.h Protocol.h encoding.h typedstream.h \
- thr.h
+ thr.h objc-decls.h
# Modules that comprise the runtime library.
/* This file contains the implementation of class Protocol.
- Copyright (C) 1993 Free Software Foundation, Inc.
+ Copyright (C) 1993, 2004 Free Software Foundation, Inc.
This file is part of GCC.
size_t i;
struct objc_protocol_list* proto_list;
+ if (aProtocolObject == nil)
+ return NO;
+
if (!strcmp(aProtocolObject->protocol_name, self->protocol_name))
return YES;
return NULL;
}
+- (unsigned) hash
+{
+ /* Compute a hash of the protocol_name; use the same hash algorithm
+ * that we use for class names; protocol names and class names are
+ * somewhat similar types of string spaces.
+ */
+ int hash = 0, index;
+
+ for (index = 0; protocol_name[index] != '\0'; index++)
+ {
+ hash = (hash << 4) ^ (hash >> 28) ^ protocol_name[index];
+ }
+
+ hash = (hash ^ (hash >> 10) ^ (hash >> 20));
+
+ return hash;
+}
+
+- (BOOL) isEqual: (id)obj
+{
+ if (strcmp (protocol_name, [obj name]) == 0)
+ return YES;
+
+ return NO;
+}
@end
/* 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.
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)
return (*stream->write) (stream->physical, buf, len);
}
-static __inline__ int
+static inline int
__objc_code_char (unsigned char *buf, signed char val)
{
if (val >= 0)
return (*stream->write) (stream->physical, buf, len);
}
-static __inline__ int
+static inline int
__objc_code_unsigned_short (unsigned char *buf, unsigned short val)
{
if ((val&_B_VALUE) == val)
return (*stream->write) (stream->physical, buf, len);
}
-static __inline__ int
+static inline int
__objc_code_short (unsigned char *buf, short val)
{
int sign = (val < 0);
}
-static __inline__ int
+static inline int
__objc_code_unsigned_int (unsigned char *buf, unsigned int val)
{
if ((val&_B_VALUE) == val)
return (*stream->write) (stream->physical, buf, len);
}
-static __inline__ int
+static inline int
__objc_code_int (unsigned char *buf, int val)
{
int sign = (val < 0);
return (*stream->write) (stream->physical, buf, len);
}
-static __inline__ int
+static inline int
__objc_code_unsigned_long (unsigned char *buf, unsigned long val)
{
if ((val&_B_VALUE) == val)
return (*stream->write) (stream->physical, buf, len);
}
-static __inline__ int
+static inline int
__objc_code_long (unsigned char *buf, long val)
{
int sign = (val < 0);
}
}
-static __inline__ int
+static inline int
__objc_write_extension (struct objc_typed_stream *stream, unsigned char code)
{
if (code <= _B_VALUE)
}
}
-__inline__ int
+inline int
__objc_write_object (struct objc_typed_stream *stream, id object)
{
unsigned char buf = '\0';
}
}
-__inline__ int
+inline int
__objc_write_class (struct objc_typed_stream *stream, struct objc_class *class)
{
__objc_write_extension (stream, _BX_CLASS);
}
-__inline__ int
+inline int
__objc_write_selector (struct objc_typed_stream *stream, SEL selector)
{
const char *sel_name;
** Read operations
*/
-__inline__ int
+inline int
objc_read_char (struct objc_typed_stream *stream, char *val)
{
unsigned char buf;
}
-__inline__ int
+inline int
objc_read_unsigned_char (struct objc_typed_stream *stream, unsigned char *val)
{
unsigned char buf;
return len;
}
-__inline__ int
+inline int
objc_read_short (struct objc_typed_stream *stream, short *value)
{
unsigned char buf[sizeof (short) + 1];
return len;
}
-__inline__ int
+inline int
objc_read_unsigned_short (struct objc_typed_stream *stream,
unsigned short *value)
{
}
-__inline__ int
+inline int
objc_read_int (struct objc_typed_stream *stream, int *value)
{
unsigned char buf[sizeof (int) + 1];
return len;
}
-__inline__ int
+inline int
objc_read_long (struct objc_typed_stream *stream, long *value)
{
unsigned char buf[sizeof (long) + 1];
return len;
}
-__inline__ int
+inline int
__objc_read_nbyte_uint (struct objc_typed_stream *stream,
unsigned int nbytes, unsigned int *val)
{
}
-__inline__ int
+inline int
objc_read_unsigned_int (struct objc_typed_stream *stream,
unsigned int *value)
{
}
-__inline__ int
+inline int
objc_read_unsigned_long (struct objc_typed_stream *stream,
unsigned long *value)
{
return len;
}
-__inline__ int
+inline int
objc_read_string (struct objc_typed_stream *stream,
char **string)
{
/* Encoding of types for Objective C.
- Copyright (C) 1993, 1995, 1996, 1997, 1998, 2000, 2002
+ Copyright (C) 1993, 1995, 1996, 1997, 1998, 2000, 2002, 2004
Free Software Foundation, Inc.
Contributed by Kresten Krab Thorup
Bitfield support by Ovidiu Predescu
/* Some ROUND_TYPE_ALIGN macros use TARGET_foo, and consequently
target_flags. Define a dummy entry here to so we don't die. */
-/* ??? FIXME: As of 2002-06-21, the attribute `unused' doesn't seem to
- eliminate the warning. */
static int __attribute__ ((__unused__)) target_flags = 0;
/* Hash tables for Objective C internal structures
- Copyright (C) 1993, 1996, 1997 Free Software Foundation, Inc.
+ Copyright (C) 1993, 1996, 1997, 2004 Free Software Foundation, Inc.
This file is part of GCC.
(*cachep)->compare_func);
DEBUG_PRINTF ("Expanding cache %#x from %d to %d\n",
- *cachep, (*cachep)->size, new->size);
+ (int) *cachep, (*cachep)->size, new->size);
/* Copy the nodes from the first hash table to the new one. */
while ((node1 = hash_next (*cachep, node1)))
/* GNU Objective-C Runtime API.
- Copyright (C) 1993, 1995, 1996, 1997, 2002 Free Software Foundation, Inc.
+ Copyright (C) 1993, 1995, 1996, 1997, 2002, 2004 Free Software Foundation, Inc.
This file is part of GCC.
#include "objc/objc.h"
#include "objc/hash.h"
#include "objc/thr.h"
+#include "objc/objc-decls.h"
#include <stdio.h>
#include <stdarg.h>
extern void objc_error(id object, int code, const char* fmt, ...);
extern void objc_verror(id object, int code, const char* fmt, va_list ap);
typedef BOOL (*objc_error_handler)(id, int code, const char *fmt, va_list ap);
-objc_error_handler objc_set_error_handler(objc_error_handler func);
+extern objc_error_handler objc_set_error_handler(objc_error_handler func);
/*
** Error codes
** This may e.g. try to load in the class using dynamic loading.
** The function is guaranteed to be passed a non-NULL name string.
*/
-extern Class (*_objc_lookup_class)(const char *name);
+objc_EXPORT Class (*_objc_lookup_class)(const char *name);
/*
** This is a hook which is called by __objc_exec_class every time a class
** dynamic loader determine the classes that have been loaded when
** an object file is dynamically linked in.
*/
-extern void (*_objc_load_callback)(Class class, Category* category);
+objc_EXPORT void (*_objc_load_callback)(Class class, Category* category);
/*
** Hook functions for allocating, copying and disposing of instances
*/
-extern id (*_objc_object_alloc)(Class class);
-extern id (*_objc_object_copy)(id object);
-extern id (*_objc_object_dispose)(id object);
+objc_EXPORT id (*_objc_object_alloc)(Class class);
+objc_EXPORT id (*_objc_object_copy)(id object);
+objc_EXPORT id (*_objc_object_dispose)(id object);
/*
** Standard functions for memory allocation and disposal.
** Users should call the normal objc routines above for
** memory allocation and disposal within their programs.
*/
-extern void *(*_objc_malloc)(size_t);
-extern void *(*_objc_atomic_malloc)(size_t);
-extern void *(*_objc_valloc)(size_t);
-extern void *(*_objc_realloc)(void *, size_t);
-extern void *(*_objc_calloc)(size_t, size_t);
-extern void (*_objc_free)(void *);
+objc_EXPORT void *(*_objc_malloc)(size_t);
+objc_EXPORT void *(*_objc_atomic_malloc)(size_t);
+objc_EXPORT void *(*_objc_valloc)(size_t);
+objc_EXPORT void *(*_objc_realloc)(void *, size_t);
+objc_EXPORT void *(*_objc_calloc)(size_t, size_t);
+objc_EXPORT void (*_objc_free)(void *);
/*
** Hook for method forwarding. This makes it easy to substitute a
** library, such as ffcall, that implements closures, thereby avoiding
** gcc's __builtin_apply problems.
*/
-extern IMP (*__objc_msg_forward)(SEL);
+objc_EXPORT IMP (*__objc_msg_forward)(SEL);
Method_t class_get_class_method(MetaClass class, SEL aSel);
--- /dev/null
+/* GNU Objective-C Extern helpers for Win32.
+ Copyright (C) 2004 Free Software Foundation, Inc.
+
+This file is part of GCC.
+
+GCC is free software; you can redistribute it and/or modify it
+under the terms of the GNU General Public License as published by the
+Free Software Foundation; either version 2, or (at your option) any
+later version.
+
+GCC is distributed in the hope that it will be useful, but WITHOUT
+ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
+License for more 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. */
+
+/* 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 to be covered by the GNU General Public License. This
+ exception does not however invalidate any other reasons why the
+ executable file might be covered by the GNU General Public License. */
+
+#ifndef __objc_decls_INCLUDE_GNU
+#define __objc_decls_INCLUDE_GNU
+
+#if defined (_WIN32) || defined (__WIN32__) || defined (WIN32)
+
+# ifdef DLL_EXPORT /* defined by libtool (if required) */
+# define objc_EXPORT __declspec(dllexport)
+# define objc_DECLARE __declspec(dllexport)
+#else
+# define objc_EXPORT extern __declspec(dllimport)
+# define objc_DECLARE extern __declspec(dllimport)
+#endif
+
+#else
+
+# define objc_EXPORT extern
+# define objc_DECLARE
+
+#endif
+
+#endif /* __objc_decls_INCLUDE_GNU */
/* GNU Objective C Runtime internal declarations
- 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.
extern void __objc_install_premature_dtable(Class); /* (objc-dispatch.c) */
extern void __objc_resolve_class_links(void); /* (objc-class.c) */
extern void __objc_register_selectors_from_class(Class); /* (objc-sel.c) */
+extern void __objc_register_selectors_from_list (MethodList_t); /* (selector.c) */
extern void __objc_update_dispatch_table_for_class (Class);/* (objc-msg.c) */
extern int __objc_init_thread_system(void); /* thread.c */
/* Sparse Arrays for Objective C dispatch tables
- Copyright (C) 1993, 1995, 1996, 2002 Free Software Foundation, Inc.
+ Copyright (C) 1993, 1995, 1996, 2002, 2004 Free Software Foundation, Inc.
This file is part of GCC.
#endif
- /* If this is a copy, go ahead and decrement/deallocate the original */
+ /* If this is a copy of another array, we free it (which might just
+ * decrement its reference count so it will be freed when no longer in use).
+ */
if (array->is_copy_of)
sarray_free (array->is_copy_of);
/* GNU Objective C Runtime selector related functions
- 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.
static struct sarray *__objc_selector_names = 0; /* uid -> name !T:MUTEX */
static cache_ptr __objc_selector_hash = 0; /* name -> uid !T:MUTEX */
-static void register_selectors_from_list (MethodList_t);
-
/* Number of selectors stored in each of the above tables */
unsigned int __objc_selector_max_index = 0; /* !T:MUTEX */
method_list = class->methods;
while (method_list)
{
- register_selectors_from_list (method_list);
+ __objc_register_selectors_from_list (method_list);
method_list = method_list->method_next;
}
}
the record table. This is the routine that does the actual recording
work.
- This one is only called for Class objects. For categories,
- class_add_method_list is called.
+ The name and type pointers in the method list must be permanent and
+ immutable.
*/
-static void
-register_selectors_from_list (MethodList_t method_list)
+void
+__objc_register_selectors_from_list (MethodList_t method_list)
{
int i = 0;
+
+ objc_mutex_lock (__objc_runtime_mutex);
while (i < method_list->method_count)
{
Method_t method = &method_list->method_list[i];
- method->method_name
- = sel_register_typed_name ((const char *) method->method_name,
- method->method_types);
+ if (method->method_name)
+ {
+ method->method_name
+ = __sel_register_typed_name ((const char *) method->method_name,
+ method->method_types, 0, YES);
+ }
i += 1;
}
+ objc_mutex_unlock (__objc_runtime_mutex);
}
/* The uninstalled dispatch table */
extern struct sarray *__objc_uninstalled_dtable;
+/* __sel_register_typed_name allocates lots of struct objc_selector:s
+ of 8 (16, if pointers are 64 bits) bytes at startup. To reduce the number
+ of malloc calls and memory lost to malloc overhead, we allocate
+ objc_selector:s in blocks here. This is only called from
+ __sel_register_typed_name, and __sel_register_typed_name may only be
+ called when __objc_runtime_mutex is locked.
+
+ Note that the objc_selector:s allocated from __sel_register_typed_name
+ are never freed.
+
+ 62 because 62 * sizeof (struct objc_selector) = 496 (992). This should
+ let malloc add some overhead and use a nice, round 512 (1024) byte chunk.
+ */
+#define SELECTOR_POOL_SIZE 62
+static struct objc_selector *selector_pool;
+static int selector_pool_left;
+
+static struct objc_selector *
+pool_alloc_selector(void)
+{
+ if (!selector_pool_left)
+ {
+ selector_pool = objc_malloc (sizeof (struct objc_selector)
+ * SELECTOR_POOL_SIZE);
+ selector_pool_left = SELECTOR_POOL_SIZE;
+ }
+ return &selector_pool[--selector_pool_left];
+}
+
/* Store the passed selector name in the selector record and return its
selector value (value returned by sel_get_uid).
Assumes that the calling function has locked down __objc_runtime_mutex. */
if (orig)
j = orig;
else
- j = objc_malloc (sizeof (struct objc_selector));
+ j = pool_alloc_selector ();
j->sel_id = (void *) i;
/* Can we use the pointer or must copy types? Don't copy if NULL */
if (orig)
j = orig;
else
- j = objc_malloc (sizeof (struct objc_selector));
+ j = pool_alloc_selector ();
j->sel_id = (void *) i;
/* Can we use the pointer or must copy types? Don't copy if NULL */
}
DEBUG_PRINTF ("Record selector %s[%s] as: %ld\n", name, types,
- soffset_decode (i));
+ (long) soffset_decode (i));
{
int is_new = (l == 0);
sel_register_typed_name (const char *name, const char *type)
{
SEL ret;
-
+
objc_mutex_lock (__objc_runtime_mutex);
/* Assume that name and type are not constant static memory and need to
be copied before put into a runtime structure. is_const == NO */
/* GNU Objective C Runtime message lookup
Copyright (C) 1993, 1995, 1996, 1997, 1998,
- 2001, 2002 Free Software Foundation, Inc.
+ 2001, 2002, 2004 Free Software Foundation, Inc.
Contributed by Kresten Krab Thorup
This file is part of GCC.
covered by the GNU General Public License. */
/* FIXME: This file has no business including tm.h. */
+/* FIXME: This should be using libffi instead of __builtin_apply
+ and friends. */
#include "tconfig.h"
#include "coretypes.h"
#include "encoding.h"
#include "runtime-info.h"
-/* this is how we hack STRUCT_VALUE to be 1 or 0 */
+/* This is how we hack STRUCT_VALUE to be 1 or 0. */
#define gen_rtx(args...) 1
#define gen_rtx_MEM(args...) 1
#define gen_rtx_REG(args...) 1
id nil_method (id, SEL);
/* Given a selector, return the proper forwarding implementation. */
-__inline__
+inline
IMP
__objc_get_forward_imp (SEL sel)
{
}
/* Given a class and selector, return the selector's implementation. */
-__inline__
+inline
IMP
get_imp (Class class, SEL sel)
{
/* Query if an object can respond to a selector, returns YES if the
object implements the selector otherwise NO. Does not check if the
method can be forwarded. */
-__inline__
+inline
BOOL
__objc_responds_to (id object, SEL sel)
{
/* This is the lookup function. All entries in the table are either a
valid method *or* zero. If zero then either the dispatch table
needs to be installed or it doesn't exist and forwarding is attempted. */
-__inline__
+inline
IMP
objc_msg_lookup (id receiver, SEL op)
{
This one is only called for categories. Class objects have their
methods installed right away, and their selectors are made into
- SEL's by the function __objc_register_selectors_from_class. */
+ SEL's by the function __objc_register_selectors_from_class. */
void
class_add_method_list (Class class, MethodList_t list)
{
- int i;
-
/* Passing of a linked list is not allowed. Do multiple calls. */
assert (! list->method_next);
- /* Check for duplicates. */
- for (i = 0; i < list->method_count; ++i)
- {
- Method_t method = &list->method_list[i];
-
- if (method->method_name) /* Sometimes these are NULL */
- {
- /* This is where selector names are transmogrified to SEL's */
- method->method_name =
- sel_register_typed_name ((const char *) method->method_name,
- method->method_types);
- }
- }
+ __objc_register_selectors_from_list(list);
/* Add the methods to the class's method list. */
list->method_next = class->methods;
/* Returns the uninstalled dispatch table indicator.
If a class' dispatch table points to __objc_uninstalled_dtable
then that means it needs its dispatch table to be installed. */
-__inline__
+inline
struct sarray *
objc_get_uninstalled_dtable ()
{