1998-09-21 03:22:07 +02:00
|
|
|
/* GNU Objective C Runtime initialization
|
2020-01-01 12:51:42 +01:00
|
|
|
Copyright (C) 1993-2020 Free Software Foundation, Inc.
|
1998-09-21 03:22:07 +02:00
|
|
|
Contributed by Kresten Krab Thorup
|
|
|
|
+load support contributed by Ovidiu Predescu <ovidiu@net-community.com>
|
|
|
|
|
hash.c, [...]: Replace "GNU CC" with "GCC".
* hash.c, init.c, libobjc.def, libobjc_entry.c, linking.m,
makefile.dos, misc.c, nil_method.c, objects.c, sarray.c,
selector.c, sendmsg.c, thr-dce.c, thr-decosf1.c, thr-irix.c,
thr-mach.c, thr-objc.c, thr-os2.c, thr-posix.c, thr-pthreads.c,
thr-rtems.c, thr-single.c, thr-solaris.c, thr-vxworks.c,
thr-win32.c, thr.c: Replace "GNU CC" with "GCC".
From-SVN: r67134
2003-05-23 22:25:39 +02:00
|
|
|
This file is part of GCC.
|
1998-09-21 03:22:07 +02:00
|
|
|
|
hash.c, [...]: Replace "GNU CC" with "GCC".
* hash.c, init.c, libobjc.def, libobjc_entry.c, linking.m,
makefile.dos, misc.c, nil_method.c, objects.c, sarray.c,
selector.c, sendmsg.c, thr-dce.c, thr-decosf1.c, thr-irix.c,
thr-mach.c, thr-objc.c, thr-os2.c, thr-posix.c, thr-pthreads.c,
thr-rtems.c, thr-single.c, thr-solaris.c, thr-vxworks.c,
thr-win32.c, thr.c: Replace "GNU CC" with "GCC".
From-SVN: r67134
2003-05-23 22:25:39 +02:00
|
|
|
GCC is free software; you can redistribute it and/or modify it under the
|
1998-09-21 03:22:07 +02:00
|
|
|
terms of the GNU General Public License as published by the Free Software
|
2009-04-09 17:00:19 +02:00
|
|
|
Foundation; either version 3, or (at your option) any later version.
|
1998-09-21 03:22:07 +02:00
|
|
|
|
hash.c, [...]: Replace "GNU CC" with "GCC".
* hash.c, init.c, libobjc.def, libobjc_entry.c, linking.m,
makefile.dos, misc.c, nil_method.c, objects.c, sarray.c,
selector.c, sendmsg.c, thr-dce.c, thr-decosf1.c, thr-irix.c,
thr-mach.c, thr-objc.c, thr-os2.c, thr-posix.c, thr-pthreads.c,
thr-rtems.c, thr-single.c, thr-solaris.c, thr-vxworks.c,
thr-win32.c, thr.c: Replace "GNU CC" with "GCC".
From-SVN: r67134
2003-05-23 22:25:39 +02:00
|
|
|
GCC is distributed in the hope that it will be useful, but WITHOUT ANY
|
1998-09-21 03:22:07 +02:00
|
|
|
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
|
|
|
FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
|
|
|
|
details.
|
|
|
|
|
2009-04-09 17:00:19 +02:00
|
|
|
Under Section 7 of GPL version 3, you are granted additional
|
|
|
|
permissions described in the GCC Runtime Library Exception, version
|
|
|
|
3.1, as published by the Free Software Foundation.
|
1998-09-21 03:22:07 +02:00
|
|
|
|
2009-04-09 17:00:19 +02:00
|
|
|
You should have received a copy of the GNU General Public License and
|
|
|
|
a copy of the GCC Runtime Library Exception along with this program;
|
|
|
|
see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
|
|
|
|
<http://www.gnu.org/licenses/>. */
|
1998-09-21 03:22:07 +02:00
|
|
|
|
2010-12-23 20:46:04 +01:00
|
|
|
/* Uncommented the following line to enable debug logging. Use this
|
|
|
|
only while debugging the runtime. */
|
|
|
|
/* #define DEBUG 1 */
|
|
|
|
|
2010-09-12 00:47:14 +02:00
|
|
|
#include "objc-private/common.h"
|
2010-09-12 02:43:15 +02:00
|
|
|
#include "objc-private/error.h"
|
2010-12-17 23:12:34 +01:00
|
|
|
#include "objc/runtime.h"
|
2010-09-11 14:58:27 +02:00
|
|
|
#include "objc/thr.h"
|
2010-09-17 18:35:15 +02:00
|
|
|
#include "objc-private/hash.h"
|
|
|
|
#include "objc-private/objc-list.h"
|
2010-12-17 23:12:34 +01:00
|
|
|
#include "objc-private/module-abi-8.h"
|
2010-12-19 18:30:30 +01:00
|
|
|
#include "objc-private/runtime.h" /* For __objc_resolve_class_links(). */
|
2010-12-19 01:28:52 +01:00
|
|
|
#include "objc-private/selector.h" /* For __sel_register_typed_name(). */
|
2010-09-14 12:23:37 +02:00
|
|
|
#include "objc-private/objc-sync.h" /* For __objc_sync_init() */
|
2010-10-15 12:35:00 +02:00
|
|
|
#include "objc-private/protocols.h" /* For __objc_protocols_init(),
|
|
|
|
__objc_protocols_add_protocol()
|
|
|
|
__objc_protocols_register_selectors() */
|
2010-10-24 19:23:19 +02:00
|
|
|
#include "objc-private/accessors.h" /* For __objc_accessors_init() */
|
1998-09-21 03:22:07 +02:00
|
|
|
|
2010-12-18 13:22:59 +01:00
|
|
|
/* The version number of this runtime. This must match the number
|
2002-07-02 21:43:03 +02:00
|
|
|
defined in gcc (objc-act.c). */
|
1998-09-21 03:22:07 +02:00
|
|
|
#define OBJC_VERSION 8
|
|
|
|
#define PROTOCOL_VERSION 2
|
|
|
|
|
2010-12-21 16:34:19 +01:00
|
|
|
/* This list contains modules currently loaded into the runtime and
|
2010-12-21 23:17:52 +01:00
|
|
|
for which the +load method (and the load callback, if any) has not
|
|
|
|
been called yet. */
|
2002-07-02 21:43:03 +02:00
|
|
|
static struct objc_list *__objc_module_list = 0; /* !T:MUTEX */
|
1998-09-21 03:22:07 +02:00
|
|
|
|
2010-12-18 13:22:59 +01:00
|
|
|
/* This list contains all proto_list's not yet assigned class
|
|
|
|
links. */
|
2002-07-02 21:43:03 +02:00
|
|
|
static struct objc_list *unclaimed_proto_list = 0; /* !T:MUTEX */
|
1998-09-21 03:22:07 +02:00
|
|
|
|
|
|
|
/* List of unresolved static instances. */
|
|
|
|
static struct objc_list *uninitialized_statics = 0; /* !T:MUTEX */
|
|
|
|
|
2010-12-23 00:05:13 +01:00
|
|
|
/* List of duplicated classes found while loading modules. If we find
|
|
|
|
a class twice, we ignore it the second time. On some platforms,
|
|
|
|
where the order in which modules are loaded is well defined, this
|
|
|
|
allows you to replace a class in a shared library by linking in a
|
|
|
|
new implementation which is loaded in in the right order, and which
|
|
|
|
overrides the existing one.
|
|
|
|
|
|
|
|
Protected by __objc_runtime_mutex. */
|
|
|
|
static cache_ptr duplicate_classes = NULL;
|
|
|
|
|
2010-10-12 04:43:25 +02:00
|
|
|
/* Global runtime "write" mutex. Having a single mutex prevents
|
|
|
|
deadlocks, but reduces concurrency. To improve concurrency, some
|
|
|
|
groups of functions in the runtime have their own separate mutex
|
|
|
|
(eg, __class_table_lock in class.c); to avoid deadlocks, these
|
|
|
|
routines must make sure that they never acquire any other lock
|
|
|
|
while holding their own local lock. Ie, they should lock, execute
|
|
|
|
some C code that does not perform any calls to other runtime
|
|
|
|
functions which may potentially lock different locks, then unlock.
|
|
|
|
If they need to perform any calls to other runtime functions that
|
|
|
|
may potentially lock other locks, then they should use the global
|
|
|
|
__objc_runtime_mutex. */
|
1998-09-21 03:22:07 +02:00
|
|
|
objc_mutex_t __objc_runtime_mutex = 0;
|
|
|
|
|
2002-07-02 21:43:03 +02:00
|
|
|
/* Number of threads that are alive. */
|
1998-09-21 03:22:07 +02:00
|
|
|
int __objc_runtime_threads_alive = 1; /* !T:MUTEX */
|
|
|
|
|
2002-07-02 21:43:03 +02:00
|
|
|
/* Check compiler vs runtime version. */
|
2010-12-17 23:12:34 +01:00
|
|
|
static void init_check_module_version (struct objc_module *);
|
1998-09-21 03:22:07 +02:00
|
|
|
|
2002-07-02 21:43:03 +02:00
|
|
|
/* Assign isa links to protos. */
|
|
|
|
static void __objc_init_protocols (struct objc_protocol_list *protos);
|
1998-09-21 03:22:07 +02:00
|
|
|
|
2010-10-15 12:35:00 +02:00
|
|
|
/* Assign isa link to a protocol, and register it. */
|
|
|
|
static void __objc_init_protocol (struct objc_protocol *protocol);
|
|
|
|
|
2002-07-02 21:43:03 +02:00
|
|
|
/* Add protocol to class. */
|
|
|
|
static void __objc_class_add_protocols (Class, struct objc_protocol_list *);
|
1998-09-21 03:22:07 +02:00
|
|
|
|
2010-12-19 03:12:42 +01:00
|
|
|
/* Load callback hook. */
|
2010-12-21 23:17:52 +01:00
|
|
|
void (*_objc_load_callback) (Class class, struct objc_category *category) = 0; /* !T:SAFE */
|
1998-09-21 03:22:07 +02:00
|
|
|
|
2010-12-23 00:05:13 +01:00
|
|
|
/* Are all categories/classes resolved ? */
|
1998-09-21 03:22:07 +02:00
|
|
|
BOOL __objc_dangling_categories = NO; /* !T:UNUSED */
|
|
|
|
|
2010-12-18 13:22:59 +01:00
|
|
|
/* Sends +load to all classes and categories in certain
|
|
|
|
situations. */
|
1998-09-21 03:22:07 +02:00
|
|
|
static void objc_send_load (void);
|
|
|
|
|
|
|
|
/* Inserts all the classes defined in module in a tree of classes that
|
2010-12-26 17:56:01 +01:00
|
|
|
resembles the class hierarchy. This tree is traversed in preorder
|
2002-07-02 21:43:03 +02:00
|
|
|
and the classes in its nodes receive the +load message if these
|
2010-12-26 17:56:01 +01:00
|
|
|
methods were not executed before. The algorithm ensures that when
|
2002-07-02 21:43:03 +02:00
|
|
|
the +load method of a class is executed all the superclasses have
|
|
|
|
been already received the +load message. */
|
2010-12-17 23:12:34 +01:00
|
|
|
static void __objc_create_classes_tree (struct objc_module *module);
|
1998-09-21 03:22:07 +02:00
|
|
|
|
2010-12-21 23:17:52 +01:00
|
|
|
/* Calls the _objc_load_callback for each class and category in the
|
|
|
|
module (if _objc_load_callback is not NULL). */
|
|
|
|
static void __objc_call_load_callback (struct objc_module *module);
|
1998-09-21 03:22:07 +02:00
|
|
|
|
|
|
|
/* A special version that works only before the classes are completely
|
2002-07-02 21:43:03 +02:00
|
|
|
installed in the runtime. */
|
1998-09-21 03:22:07 +02:00
|
|
|
static BOOL class_is_subclass_of_class (Class class, Class superclass);
|
|
|
|
|
2010-12-26 17:56:01 +01:00
|
|
|
/* This is a node in the class tree hierarchy used to send +load
|
|
|
|
messages. */
|
2010-12-23 00:05:13 +01:00
|
|
|
typedef struct objc_class_tree
|
|
|
|
{
|
2010-12-26 17:56:01 +01:00
|
|
|
/* The class corresponding to the node. */
|
1998-09-21 03:22:07 +02:00
|
|
|
Class class;
|
2010-12-26 17:56:01 +01:00
|
|
|
|
|
|
|
/* This is a linked list of all the direct subclasses of this class.
|
|
|
|
'head' points to a subclass node; 'tail' points to the next
|
|
|
|
objc_list node (whose 'head' points to another subclass node,
|
|
|
|
etc). */
|
|
|
|
struct objc_list *subclasses;
|
1998-09-21 03:22:07 +02:00
|
|
|
} objc_class_tree;
|
|
|
|
|
2010-12-26 17:56:01 +01:00
|
|
|
/* This is a linked list of objc_class_tree trees. The head of these
|
|
|
|
trees are root classes (their super class is Nil). These different
|
2002-07-02 21:43:03 +02:00
|
|
|
trees represent different class hierarchies. */
|
1998-09-21 03:22:07 +02:00
|
|
|
static struct objc_list *__objc_class_tree_list = NULL;
|
|
|
|
|
2002-07-02 21:43:03 +02:00
|
|
|
/* Keeps the +load methods who have been already executed. This hash
|
|
|
|
should not be destroyed during the execution of the program. */
|
1998-09-21 03:22:07 +02:00
|
|
|
static cache_ptr __objc_load_methods = NULL;
|
|
|
|
|
2003-05-15 11:34:32 +02:00
|
|
|
/* This function is used when building the class tree used to send
|
|
|
|
ordinately the +load message to all classes needing it. The tree
|
|
|
|
is really needed so that superclasses will get the message before
|
|
|
|
subclasses.
|
|
|
|
|
2010-12-26 17:56:01 +01:00
|
|
|
This tree may contain classes which are being loaded (or have just
|
2003-05-15 11:34:32 +02:00
|
|
|
being loaded), and whose super_class pointers have not yet been
|
|
|
|
resolved. This implies that their super_class pointers point to a
|
|
|
|
string with the name of the superclass; when the first message is
|
|
|
|
sent to the class (/an object of that class) the class links will
|
|
|
|
be resolved, which will replace the super_class pointers with
|
|
|
|
pointers to the actual superclasses.
|
|
|
|
|
|
|
|
Unfortunately, the tree might also contain classes which had been
|
|
|
|
loaded previously, and whose class links have already been
|
|
|
|
resolved.
|
|
|
|
|
|
|
|
This function returns the superclass of a class in both cases, and
|
|
|
|
can be used to build the determine the class relationships while
|
2010-12-18 13:22:59 +01:00
|
|
|
building the tree. */
|
2003-05-15 11:34:32 +02:00
|
|
|
static Class class_superclass_of_class (Class class)
|
|
|
|
{
|
|
|
|
char *super_class_name;
|
|
|
|
|
|
|
|
/* If the class links have been resolved, use the resolved
|
2010-12-18 13:22:59 +01:00
|
|
|
links. */
|
2003-05-15 11:34:32 +02:00
|
|
|
if (CLS_ISRESOLV (class))
|
|
|
|
return class->super_class;
|
|
|
|
|
|
|
|
/* Else, 'class' has not yet been resolved. This means that its
|
2010-12-18 13:22:59 +01:00
|
|
|
super_class pointer is really the name of the super class (rather
|
|
|
|
than a pointer to the actual superclass). */
|
2003-05-15 11:34:32 +02:00
|
|
|
super_class_name = (char *)class->super_class;
|
|
|
|
|
|
|
|
/* Return Nil for a root class. */
|
|
|
|
if (super_class_name == NULL)
|
|
|
|
return Nil;
|
|
|
|
|
|
|
|
/* Lookup the superclass of non-root classes. */
|
2010-12-17 23:12:34 +01:00
|
|
|
return objc_getClass (super_class_name);
|
2003-05-15 11:34:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-07-02 21:43:03 +02:00
|
|
|
/* Creates a tree of classes whose topmost class is directly inherited
|
2010-12-26 17:56:01 +01:00
|
|
|
from `upper' and the bottom class in this tree is `bottom_class'.
|
|
|
|
If `upper' is Nil, creates a class hierarchy up to a root class.
|
|
|
|
The classes in this tree are super classes of `bottom_class'. The
|
|
|
|
`subclasses' member of each tree node point to the list of
|
|
|
|
subclasses for the node. */
|
1998-09-21 03:22:07 +02:00
|
|
|
static objc_class_tree *
|
|
|
|
create_tree_of_subclasses_inherited_from (Class bottom_class, Class upper)
|
|
|
|
{
|
2010-12-17 23:12:34 +01:00
|
|
|
Class superclass;
|
1998-09-21 03:22:07 +02:00
|
|
|
objc_class_tree *tree, *prev;
|
|
|
|
|
|
|
|
DEBUG_PRINTF ("create_tree_of_subclasses_inherited_from:");
|
2010-12-23 20:46:04 +01:00
|
|
|
DEBUG_PRINTF (" bottom_class = %s, upper = %s\n",
|
1998-09-21 03:22:07 +02:00
|
|
|
(bottom_class ? bottom_class->name : NULL),
|
|
|
|
(upper ? upper->name : NULL));
|
|
|
|
|
2010-12-26 17:56:01 +01:00
|
|
|
superclass = class_superclass_of_class (bottom_class);
|
|
|
|
|
|
|
|
prev = objc_calloc (1, sizeof (objc_class_tree));
|
1998-09-21 03:22:07 +02:00
|
|
|
prev->class = bottom_class;
|
|
|
|
|
2010-12-26 17:56:01 +01:00
|
|
|
if (superclass == upper)
|
|
|
|
return prev;
|
|
|
|
|
1998-09-21 03:22:07 +02:00
|
|
|
while (superclass != upper)
|
|
|
|
{
|
|
|
|
tree = objc_calloc (1, sizeof (objc_class_tree));
|
|
|
|
tree->class = superclass;
|
|
|
|
tree->subclasses = list_cons (prev, tree->subclasses);
|
2003-05-15 11:34:32 +02:00
|
|
|
superclass = class_superclass_of_class (superclass);
|
1998-09-21 03:22:07 +02:00
|
|
|
prev = tree;
|
|
|
|
}
|
|
|
|
|
|
|
|
return tree;
|
|
|
|
}
|
|
|
|
|
2002-07-02 21:43:03 +02:00
|
|
|
/* Insert the `class' into the proper place in the `tree' class
|
2010-12-26 17:56:01 +01:00
|
|
|
hierarchy. This function returns a new tree if the class has been
|
2002-07-02 21:43:03 +02:00
|
|
|
successfully inserted into the tree or NULL if the class is not
|
2010-12-26 17:56:01 +01:00
|
|
|
part of the classes hierarchy described by `tree'. This function
|
|
|
|
is private to objc_tree_insert_class (), you should not call it
|
2002-07-02 21:43:03 +02:00
|
|
|
directly. */
|
1998-09-21 03:22:07 +02:00
|
|
|
static objc_class_tree *
|
|
|
|
__objc_tree_insert_class (objc_class_tree *tree, Class class)
|
|
|
|
{
|
2010-12-26 17:56:01 +01:00
|
|
|
DEBUG_PRINTF ("__objc_tree_insert_class: tree = %p (root: %s), class = %s\n",
|
|
|
|
tree, ((tree && tree->class) ? tree->class->name : "Nil"), class->name);
|
1998-09-21 03:22:07 +02:00
|
|
|
|
|
|
|
if (tree == NULL)
|
|
|
|
return create_tree_of_subclasses_inherited_from (class, NULL);
|
|
|
|
else if (class == tree->class)
|
|
|
|
{
|
2010-12-18 13:22:59 +01:00
|
|
|
/* `class' has been already inserted. */
|
2010-12-23 20:46:04 +01:00
|
|
|
DEBUG_PRINTF (" 1. class %s was previously inserted\n", class->name);
|
1998-09-21 03:22:07 +02:00
|
|
|
return tree;
|
|
|
|
}
|
2003-05-15 11:34:32 +02:00
|
|
|
else if (class_superclass_of_class (class) == tree->class)
|
1998-09-21 03:22:07 +02:00
|
|
|
{
|
2010-12-18 13:22:59 +01:00
|
|
|
/* If class is a direct subclass of tree->class then add class
|
|
|
|
to the list of subclasses. First check to see if it wasn't
|
|
|
|
already inserted. */
|
1998-09-21 03:22:07 +02:00
|
|
|
struct objc_list *list = tree->subclasses;
|
|
|
|
objc_class_tree *node;
|
|
|
|
|
|
|
|
while (list)
|
|
|
|
{
|
|
|
|
/* Class has been already inserted; do nothing just return
|
2002-07-02 21:43:03 +02:00
|
|
|
the tree. */
|
|
|
|
if (((objc_class_tree *) list->head)->class == class)
|
1998-09-21 03:22:07 +02:00
|
|
|
{
|
2010-12-23 20:46:04 +01:00
|
|
|
DEBUG_PRINTF (" 2. class %s was previously inserted\n",
|
1998-09-21 03:22:07 +02:00
|
|
|
class->name);
|
|
|
|
return tree;
|
|
|
|
}
|
|
|
|
list = list->tail;
|
|
|
|
}
|
|
|
|
|
2010-12-18 13:22:59 +01:00
|
|
|
/* Create a new node class and insert it into the list of
|
|
|
|
subclasses. */
|
1998-09-21 03:22:07 +02:00
|
|
|
node = objc_calloc (1, sizeof (objc_class_tree));
|
|
|
|
node->class = class;
|
|
|
|
tree->subclasses = list_cons (node, tree->subclasses);
|
2010-12-23 20:46:04 +01:00
|
|
|
DEBUG_PRINTF (" 3. class %s inserted\n", class->name);
|
1998-09-21 03:22:07 +02:00
|
|
|
return tree;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2010-12-18 13:22:59 +01:00
|
|
|
/* The class is not a direct subclass of tree->class. Search
|
|
|
|
for class's superclasses in the list of subclasses. */
|
1998-09-21 03:22:07 +02:00
|
|
|
struct objc_list *subclasses = tree->subclasses;
|
|
|
|
|
2002-07-02 21:43:03 +02:00
|
|
|
/* Precondition: the class must be a subclass of tree->class;
|
|
|
|
otherwise return NULL to indicate our caller that it must
|
|
|
|
take the next tree. */
|
|
|
|
if (! class_is_subclass_of_class (class, tree->class))
|
1998-09-21 03:22:07 +02:00
|
|
|
return NULL;
|
|
|
|
|
|
|
|
for (; subclasses != NULL; subclasses = subclasses->tail)
|
|
|
|
{
|
2002-07-02 21:43:03 +02:00
|
|
|
Class aClass = ((objc_class_tree *) (subclasses->head))->class;
|
1998-09-21 03:22:07 +02:00
|
|
|
|
|
|
|
if (class_is_subclass_of_class (class, aClass))
|
|
|
|
{
|
2002-07-02 21:43:03 +02:00
|
|
|
/* If we found one of class's superclasses we insert the
|
|
|
|
class into its subtree and return the original tree
|
|
|
|
since nothing has been changed. */
|
1998-09-21 03:22:07 +02:00
|
|
|
subclasses->head
|
|
|
|
= __objc_tree_insert_class (subclasses->head, class);
|
2010-12-23 20:46:04 +01:00
|
|
|
DEBUG_PRINTF (" 4. class %s inserted\n", class->name);
|
1998-09-21 03:22:07 +02:00
|
|
|
return tree;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-07-02 21:43:03 +02:00
|
|
|
/* We haven't found a subclass of `class' in the `subclasses'
|
|
|
|
list. Create a new tree of classes whose topmost class is a
|
|
|
|
direct subclass of tree->class. */
|
1998-09-21 03:22:07 +02:00
|
|
|
{
|
|
|
|
objc_class_tree *new_tree
|
2002-07-02 21:43:03 +02:00
|
|
|
= create_tree_of_subclasses_inherited_from (class, tree->class);
|
1998-09-21 03:22:07 +02:00
|
|
|
tree->subclasses = list_cons (new_tree, tree->subclasses);
|
2010-12-23 20:46:04 +01:00
|
|
|
DEBUG_PRINTF (" 5. class %s inserted\n", class->name);
|
1998-09-21 03:22:07 +02:00
|
|
|
return tree;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-07-02 21:43:03 +02:00
|
|
|
/* This function inserts `class' in the right tree hierarchy classes. */
|
1998-09-21 03:22:07 +02:00
|
|
|
static void
|
|
|
|
objc_tree_insert_class (Class class)
|
|
|
|
{
|
|
|
|
struct objc_list *list_node;
|
|
|
|
objc_class_tree *tree;
|
2010-12-26 17:56:01 +01:00
|
|
|
|
1998-09-21 03:22:07 +02:00
|
|
|
list_node = __objc_class_tree_list;
|
|
|
|
while (list_node)
|
|
|
|
{
|
2010-12-26 17:56:01 +01:00
|
|
|
/* Try to insert the class in this class hierarchy. */
|
1998-09-21 03:22:07 +02:00
|
|
|
tree = __objc_tree_insert_class (list_node->head, class);
|
|
|
|
if (tree)
|
|
|
|
{
|
|
|
|
list_node->head = tree;
|
2010-12-26 17:56:01 +01:00
|
|
|
return;
|
1998-09-21 03:22:07 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
list_node = list_node->tail;
|
|
|
|
}
|
2010-12-26 17:56:01 +01:00
|
|
|
|
|
|
|
/* If the list was finished but the class hasn't been inserted, we
|
2013-07-21 17:38:21 +02:00
|
|
|
don't have an existing class hierarchy that can accommodate it.
|
2010-12-26 17:56:01 +01:00
|
|
|
Create a new one. */
|
|
|
|
__objc_class_tree_list = list_cons (NULL, __objc_class_tree_list);
|
|
|
|
__objc_class_tree_list->head = __objc_tree_insert_class (NULL, class);
|
1998-09-21 03:22:07 +02:00
|
|
|
}
|
|
|
|
|
2002-07-02 21:43:03 +02:00
|
|
|
/* Traverse tree in preorder. Used to send +load. */
|
1998-09-21 03:22:07 +02:00
|
|
|
static void
|
|
|
|
objc_preorder_traverse (objc_class_tree *tree,
|
|
|
|
int level,
|
2002-07-02 21:43:03 +02:00
|
|
|
void (*function) (objc_class_tree *, int))
|
1998-09-21 03:22:07 +02:00
|
|
|
{
|
|
|
|
struct objc_list *node;
|
|
|
|
|
|
|
|
(*function) (tree, level);
|
|
|
|
for (node = tree->subclasses; node; node = node->tail)
|
|
|
|
objc_preorder_traverse (node->head, level + 1, function);
|
|
|
|
}
|
|
|
|
|
2002-07-02 21:43:03 +02:00
|
|
|
/* Traverse tree in postorder. Used to destroy a tree. */
|
1998-09-21 03:22:07 +02:00
|
|
|
static void
|
|
|
|
objc_postorder_traverse (objc_class_tree *tree,
|
2002-07-02 21:43:03 +02:00
|
|
|
int level,
|
|
|
|
void (*function) (objc_class_tree *, int))
|
1998-09-21 03:22:07 +02:00
|
|
|
{
|
|
|
|
struct objc_list *node;
|
|
|
|
|
|
|
|
for (node = tree->subclasses; node; node = node->tail)
|
|
|
|
objc_postorder_traverse (node->head, level + 1, function);
|
|
|
|
(*function) (tree, level);
|
|
|
|
}
|
|
|
|
|
2002-07-02 21:43:03 +02:00
|
|
|
/* Used to print a tree class hierarchy. */
|
1998-09-21 03:22:07 +02:00
|
|
|
#ifdef DEBUG
|
|
|
|
static void
|
|
|
|
__objc_tree_print (objc_class_tree *tree, int level)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < level; i++)
|
|
|
|
printf (" ");
|
|
|
|
printf ("%s\n", tree->class->name);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2002-07-02 21:43:03 +02:00
|
|
|
/* Walks on a linked list of methods in the reverse order and executes
|
2010-12-21 16:34:19 +01:00
|
|
|
all the methods corresponding to the `+load' selector. Walking in
|
|
|
|
the reverse order assures the +load of class is executed first and
|
|
|
|
then +load of categories because of the way in which categories are
|
|
|
|
added to the class methods. This function needs to be called with
|
|
|
|
the objc_runtime_mutex locked. */
|
1998-09-21 03:22:07 +02:00
|
|
|
static void
|
2010-12-21 16:34:19 +01:00
|
|
|
__objc_send_load_using_method_list (struct objc_method_list *method_list, Class class)
|
1998-09-21 03:22:07 +02:00
|
|
|
{
|
2010-12-21 16:34:19 +01:00
|
|
|
static SEL load_selector = 0;
|
1998-09-21 03:22:07 +02:00
|
|
|
int i;
|
|
|
|
|
2010-12-21 16:34:19 +01:00
|
|
|
if (!method_list)
|
1998-09-21 03:22:07 +02:00
|
|
|
return;
|
|
|
|
|
2010-12-21 16:34:19 +01:00
|
|
|
/* This needs no lock protection because we are called with the
|
|
|
|
objc_runtime_mutex locked. */
|
|
|
|
if (!load_selector)
|
|
|
|
load_selector = sel_registerName ("load");
|
|
|
|
|
|
|
|
/* method_list is a linked list of method lists; since we're
|
|
|
|
executing in reverse order, we need to do the next list before we
|
|
|
|
do this one. */
|
|
|
|
__objc_send_load_using_method_list (method_list->method_next, class);
|
1998-09-21 03:22:07 +02:00
|
|
|
|
2002-07-02 21:43:03 +02:00
|
|
|
/* Search the method list. */
|
1998-09-21 03:22:07 +02:00
|
|
|
for (i = 0; i < method_list->method_count; i++)
|
|
|
|
{
|
2010-12-17 23:12:34 +01:00
|
|
|
struct objc_method *mth = &method_list->method_list[i];
|
1998-09-21 03:22:07 +02:00
|
|
|
|
2010-12-21 16:34:19 +01:00
|
|
|
/* We are searching for +load methods that we haven't executed
|
|
|
|
yet. */
|
|
|
|
if (mth->method_name && sel_eq (mth->method_name, load_selector)
|
re PR libobjc/19024 (name collisions libobjc/libmysqlclient)
2005-03-02 David Ayers <d.ayers@inode.at>
PR libobjc/19024
* Makefile.in (OBJS): Add hash_compat.lo.
(OBJS_GC): Add hash_compat_gc.lo.
(hash_compat_gc.lo): New target and rule.
* objc/hash.h (hash_new, hash_delete, hash_add, hash_remove)
(hash_next, hash_value_for_key, hash_is_key_in_hash)
(hash_ptr, hash_string, compare_ptrs, compare_strings): Prefix
with objc_. Add deprecated non prefixed inlined versions.
(OBJC_IGNORE_DEPRECATED_API): New macro to hide deprecated
declarations.
* hash.c (hash_new, hash_delete, hash_add, hash_remove, hash_next)
(hash_value_for_key, hash_is_key_in_hash): Prefix with objc_ and
update callers.
* hash_compat.c: New file.
* archive.c: Update callers.
* init.c: Likewise.
* selector.c: Likewise.
* libobjc.def: Add objc_ versions of hash functions.
From-SVN: r95793
2005-03-02 20:37:03 +01:00
|
|
|
&& ! objc_hash_is_key_in_hash (__objc_load_methods, mth->method_imp))
|
1998-09-21 03:22:07 +02:00
|
|
|
{
|
2010-12-21 16:34:19 +01:00
|
|
|
/* Add this method into the +load hash table, so we won't
|
|
|
|
execute it again next time. */
|
re PR libobjc/19024 (name collisions libobjc/libmysqlclient)
2005-03-02 David Ayers <d.ayers@inode.at>
PR libobjc/19024
* Makefile.in (OBJS): Add hash_compat.lo.
(OBJS_GC): Add hash_compat_gc.lo.
(hash_compat_gc.lo): New target and rule.
* objc/hash.h (hash_new, hash_delete, hash_add, hash_remove)
(hash_next, hash_value_for_key, hash_is_key_in_hash)
(hash_ptr, hash_string, compare_ptrs, compare_strings): Prefix
with objc_. Add deprecated non prefixed inlined versions.
(OBJC_IGNORE_DEPRECATED_API): New macro to hide deprecated
declarations.
* hash.c (hash_new, hash_delete, hash_add, hash_remove, hash_next)
(hash_value_for_key, hash_is_key_in_hash): Prefix with objc_ and
update callers.
* hash_compat.c: New file.
* archive.c: Update callers.
* init.c: Likewise.
* selector.c: Likewise.
* libobjc.def: Add objc_ versions of hash functions.
From-SVN: r95793
2005-03-02 20:37:03 +01:00
|
|
|
objc_hash_add (&__objc_load_methods,
|
|
|
|
mth->method_imp,
|
|
|
|
mth->method_imp);
|
2010-12-18 13:22:59 +01:00
|
|
|
|
2010-12-21 16:34:19 +01:00
|
|
|
/* Call +load. */
|
2010-12-23 20:46:04 +01:00
|
|
|
DEBUG_PRINTF (" begin of [%s +load]\n", class->name);
|
2001-06-09 00:19:47 +02:00
|
|
|
(*mth->method_imp) ((id)class, mth->method_name);
|
2010-12-23 20:46:04 +01:00
|
|
|
DEBUG_PRINTF (" end of [%s +load]\n", class->name);
|
2001-06-09 00:19:47 +02:00
|
|
|
|
1998-09-21 03:22:07 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-12-21 16:34:19 +01:00
|
|
|
/* This function needs to be called with the objc_runtime_mutex
|
|
|
|
locked. */
|
1998-09-21 03:22:07 +02:00
|
|
|
static void
|
Object.m: Fix signed/unsigned warning.
* Object.m: Fix signed/unsigned warning.
* Protocol.m: Likewise.
* archive.c: Always include stdlib.h.
(objc_read_short, objc_read_unsigned_short, objc_read_int,
objc_read_long, __objc_read_nbyte_uint, __objc_read_nbyte_ulong):
Fix signed/unsigned warning.
(objc_write_type, objc_read_type, objc_write_types,
objc_read_types): Ensure ctype 8-bit safety.
(__objc_no_write, __objc_no_read): Mark unused parameters.
* class.c (class_table_setup): Specify void arg.
* encoding.c (atoi, objc_sizeof_type, objc_alignof_type,
objc_skip_typespec, objc_skip_offset,
objc_layout_structure_next_member): Ensure ctype 8-bit safety.
(objc_layout_structure_next_member): Ensure variables are
initialized.
* gc.c (__objc_generate_gc_type_description,
class_ivar_set_gcinvisible): Mark unused parameters.
* init.c (__objc_send_load, __objc_destroy_class_tree_node): Mark
unused parameters.
(__objc_init_protocols) Fix signed/unsigned warning.
* nil_method.c (nil_method): Mark unused parameters.
* thr.h (objc_thread_callback): Specify void arg.
* sarray.c (sarray_new, sarray_realloc, sarray_free): Fix
signed/unsigned warning.
(sarray_free): Fix formatting.
* selector.c (sel_types_match): Ensure ctype 8-bit safety.
* sendmsg.c (__objc_init_install_dtable) Mark unused parameters.
From-SVN: r54649
2002-06-15 19:50:14 +02:00
|
|
|
__objc_send_load (objc_class_tree *tree,
|
|
|
|
int level __attribute__ ((__unused__)))
|
1998-09-21 03:22:07 +02:00
|
|
|
{
|
|
|
|
Class class = tree->class;
|
2010-12-17 23:12:34 +01:00
|
|
|
struct objc_method_list *method_list = class->class_pointer->methods;
|
1998-09-21 03:22:07 +02:00
|
|
|
|
2010-12-23 20:46:04 +01:00
|
|
|
DEBUG_PRINTF ("+load: need to send load to class '%s'\n", class->name);
|
2010-12-21 16:34:19 +01:00
|
|
|
__objc_send_load_using_method_list (method_list, class);
|
1998-09-21 03:22:07 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
Object.m: Fix signed/unsigned warning.
* Object.m: Fix signed/unsigned warning.
* Protocol.m: Likewise.
* archive.c: Always include stdlib.h.
(objc_read_short, objc_read_unsigned_short, objc_read_int,
objc_read_long, __objc_read_nbyte_uint, __objc_read_nbyte_ulong):
Fix signed/unsigned warning.
(objc_write_type, objc_read_type, objc_write_types,
objc_read_types): Ensure ctype 8-bit safety.
(__objc_no_write, __objc_no_read): Mark unused parameters.
* class.c (class_table_setup): Specify void arg.
* encoding.c (atoi, objc_sizeof_type, objc_alignof_type,
objc_skip_typespec, objc_skip_offset,
objc_layout_structure_next_member): Ensure ctype 8-bit safety.
(objc_layout_structure_next_member): Ensure variables are
initialized.
* gc.c (__objc_generate_gc_type_description,
class_ivar_set_gcinvisible): Mark unused parameters.
* init.c (__objc_send_load, __objc_destroy_class_tree_node): Mark
unused parameters.
(__objc_init_protocols) Fix signed/unsigned warning.
* nil_method.c (nil_method): Mark unused parameters.
* thr.h (objc_thread_callback): Specify void arg.
* sarray.c (sarray_new, sarray_realloc, sarray_free): Fix
signed/unsigned warning.
(sarray_free): Fix formatting.
* selector.c (sel_types_match): Ensure ctype 8-bit safety.
* sendmsg.c (__objc_init_install_dtable) Mark unused parameters.
From-SVN: r54649
2002-06-15 19:50:14 +02:00
|
|
|
__objc_destroy_class_tree_node (objc_class_tree *tree,
|
|
|
|
int level __attribute__ ((__unused__)))
|
1998-09-21 03:22:07 +02:00
|
|
|
{
|
|
|
|
objc_free (tree);
|
|
|
|
}
|
|
|
|
|
2002-07-02 21:43:03 +02:00
|
|
|
/* This is used to check if the relationship between two classes
|
|
|
|
before the runtime completely installs the classes. */
|
1998-09-21 03:22:07 +02:00
|
|
|
static BOOL
|
|
|
|
class_is_subclass_of_class (Class class, Class superclass)
|
|
|
|
{
|
|
|
|
for (; class != Nil;)
|
|
|
|
{
|
|
|
|
if (class == superclass)
|
|
|
|
return YES;
|
2003-05-15 11:34:32 +02:00
|
|
|
class = class_superclass_of_class (class);
|
1998-09-21 03:22:07 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return NO;
|
|
|
|
}
|
|
|
|
|
2002-07-02 21:43:03 +02:00
|
|
|
/* This list contains all the classes in the runtime system for whom
|
|
|
|
their superclasses are not yet known to the runtime. */
|
|
|
|
static struct objc_list *unresolved_classes = 0;
|
1998-09-21 03:22:07 +02:00
|
|
|
|
2010-10-17 13:01:31 +02:00
|
|
|
/* Extern function used to reference the Object class. */
|
1999-06-21 06:41:41 +02:00
|
|
|
extern void __objc_force_linking (void);
|
|
|
|
|
|
|
|
void
|
1998-09-21 03:22:07 +02:00
|
|
|
__objc_force_linking (void)
|
|
|
|
{
|
|
|
|
extern void __objc_linking (void);
|
|
|
|
__objc_linking ();
|
|
|
|
}
|
|
|
|
|
2002-07-02 21:43:03 +02:00
|
|
|
/* Run through the statics list, removing modules as soon as all its
|
|
|
|
statics have been initialized. */
|
1998-09-21 03:22:07 +02:00
|
|
|
static void
|
|
|
|
objc_init_statics (void)
|
|
|
|
{
|
|
|
|
struct objc_list **cell = &uninitialized_statics;
|
|
|
|
struct objc_static_instances **statics_in_module;
|
|
|
|
|
2002-07-02 21:43:03 +02:00
|
|
|
objc_mutex_lock (__objc_runtime_mutex);
|
1998-09-21 03:22:07 +02:00
|
|
|
|
|
|
|
while (*cell)
|
|
|
|
{
|
|
|
|
int module_initialized = 1;
|
|
|
|
|
|
|
|
for (statics_in_module = (*cell)->head;
|
|
|
|
*statics_in_module; statics_in_module++)
|
|
|
|
{
|
|
|
|
struct objc_static_instances *statics = *statics_in_module;
|
2010-12-17 23:12:34 +01:00
|
|
|
Class class = objc_getClass (statics->class_name);
|
1998-09-21 03:22:07 +02:00
|
|
|
|
2002-07-02 21:43:03 +02:00
|
|
|
if (! class)
|
1998-09-21 03:22:07 +02:00
|
|
|
{
|
2010-10-13 10:16:42 +02:00
|
|
|
/* It is unfortunate that this will cause all the
|
|
|
|
statics initialization to be done again (eg, if we
|
|
|
|
already initialized constant strings, and are now
|
|
|
|
initializing protocols, setting module_initialized to
|
|
|
|
0 would cause constant strings to be initialized
|
|
|
|
again). It would be good to be able to track if we
|
|
|
|
have already initialized some of them. */
|
|
|
|
module_initialized = 0;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* Note that if this is a list of Protocol objects, some
|
|
|
|
of them may have been initialized already (because
|
|
|
|
they were attached to classes or categories, and the
|
|
|
|
class/category loading code automatically fixes them
|
|
|
|
up), and some of them may not. We really need to go
|
2010-10-15 12:35:00 +02:00
|
|
|
through the whole list to be sure! Protocols are
|
|
|
|
also special because we want to register them and
|
|
|
|
register all their selectors. */
|
1998-09-21 03:22:07 +02:00
|
|
|
id *inst;
|
|
|
|
|
2010-10-15 12:35:00 +02:00
|
|
|
if (strcmp (statics->class_name, "Protocol") == 0)
|
|
|
|
{
|
|
|
|
/* Protocols are special, because not only we want
|
|
|
|
to fix up their class pointers, but we also want
|
|
|
|
to register them and their selectors with the
|
|
|
|
runtime. */
|
|
|
|
for (inst = &statics->instances[0]; *inst; inst++)
|
|
|
|
__objc_init_protocol ((struct objc_protocol *)*inst);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2010-12-18 13:22:59 +01:00
|
|
|
/* Other static instances (typically constant
|
|
|
|
strings) are easier as we just fix up their class
|
|
|
|
pointers. */
|
2010-10-15 12:35:00 +02:00
|
|
|
for (inst = &statics->instances[0]; *inst; inst++)
|
|
|
|
(*inst)->class_pointer = class;
|
|
|
|
}
|
1998-09-21 03:22:07 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if (module_initialized)
|
|
|
|
{
|
|
|
|
/* Remove this module from the uninitialized list. */
|
|
|
|
struct objc_list *this = *cell;
|
|
|
|
*cell = this->tail;
|
2002-07-02 21:43:03 +02:00
|
|
|
objc_free (this);
|
1998-09-21 03:22:07 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
cell = &(*cell)->tail;
|
|
|
|
}
|
|
|
|
|
2002-07-02 21:43:03 +02:00
|
|
|
objc_mutex_unlock (__objc_runtime_mutex);
|
2010-12-18 13:22:59 +01:00
|
|
|
}
|
1998-09-21 03:22:07 +02:00
|
|
|
|
|
|
|
/* This function is called by constructor functions generated for each
|
2002-07-02 21:43:03 +02:00
|
|
|
module compiled. (_GLOBAL_$I$...) The purpose of this function is
|
|
|
|
to gather the module pointers so that they may be processed by the
|
|
|
|
initialization routines as soon as possible. */
|
1998-09-21 03:22:07 +02:00
|
|
|
void
|
2010-12-17 23:12:34 +01:00
|
|
|
__objc_exec_class (struct objc_module *module)
|
1998-09-21 03:22:07 +02:00
|
|
|
{
|
2010-12-17 23:12:34 +01:00
|
|
|
/* Have we processed any constructors previously? This flag is used
|
|
|
|
to indicate that some global data structures need to be
|
|
|
|
built. */
|
1998-09-21 03:22:07 +02:00
|
|
|
static BOOL previous_constructors = 0;
|
|
|
|
|
2002-07-02 21:43:03 +02:00
|
|
|
static struct objc_list *unclaimed_categories = 0;
|
1998-09-21 03:22:07 +02:00
|
|
|
|
2010-12-17 23:12:34 +01:00
|
|
|
/* The symbol table (defined in objc-private/module-abi-8.h)
|
|
|
|
generated by gcc. */
|
|
|
|
struct objc_symtab *symtab = module->symtab;
|
1998-09-21 03:22:07 +02:00
|
|
|
|
2010-12-17 23:12:34 +01:00
|
|
|
/* The statics in this module. */
|
1998-09-21 03:22:07 +02:00
|
|
|
struct objc_static_instances **statics
|
|
|
|
= symtab->defs[symtab->cls_def_cnt + symtab->cat_def_cnt];
|
|
|
|
|
2010-12-17 23:12:34 +01:00
|
|
|
/* Entry used to traverse hash lists. */
|
2002-07-02 21:43:03 +02:00
|
|
|
struct objc_list **cell;
|
1998-09-21 03:22:07 +02:00
|
|
|
|
2010-12-17 23:12:34 +01:00
|
|
|
/* The table of selector references for this module. */
|
2010-12-21 13:49:26 +01:00
|
|
|
struct objc_selector *selectors = symtab->refs;
|
1998-09-21 03:22:07 +02:00
|
|
|
|
|
|
|
int i;
|
|
|
|
|
2010-12-23 20:46:04 +01:00
|
|
|
DEBUG_PRINTF ("\n__objc_exec_class (%p) - start processing module...\n", module);
|
1998-09-21 03:22:07 +02:00
|
|
|
|
2010-12-18 13:22:59 +01:00
|
|
|
/* Check gcc version. */
|
2002-07-02 21:43:03 +02:00
|
|
|
init_check_module_version (module);
|
1998-09-21 03:22:07 +02:00
|
|
|
|
2010-12-18 13:22:59 +01:00
|
|
|
/* On the first call of this routine, initialize some data
|
|
|
|
structures. */
|
2002-07-02 21:43:03 +02:00
|
|
|
if (! previous_constructors)
|
1998-09-21 03:22:07 +02:00
|
|
|
{
|
2010-12-18 13:22:59 +01:00
|
|
|
/* Initialize thread-safe system. */
|
2002-07-02 21:43:03 +02:00
|
|
|
__objc_init_thread_system ();
|
1998-09-21 03:22:07 +02:00
|
|
|
__objc_runtime_threads_alive = 1;
|
2002-07-02 21:43:03 +02:00
|
|
|
__objc_runtime_mutex = objc_mutex_allocate ();
|
1998-09-21 03:22:07 +02:00
|
|
|
|
2002-07-02 21:43:03 +02:00
|
|
|
__objc_init_selector_tables ();
|
|
|
|
__objc_init_class_tables ();
|
|
|
|
__objc_init_dispatch_tables ();
|
2010-12-23 00:05:13 +01:00
|
|
|
duplicate_classes = objc_hash_new (8,
|
|
|
|
(hash_func_type)objc_hash_ptr,
|
|
|
|
objc_compare_ptrs);
|
re PR libobjc/19024 (name collisions libobjc/libmysqlclient)
2005-03-02 David Ayers <d.ayers@inode.at>
PR libobjc/19024
* Makefile.in (OBJS): Add hash_compat.lo.
(OBJS_GC): Add hash_compat_gc.lo.
(hash_compat_gc.lo): New target and rule.
* objc/hash.h (hash_new, hash_delete, hash_add, hash_remove)
(hash_next, hash_value_for_key, hash_is_key_in_hash)
(hash_ptr, hash_string, compare_ptrs, compare_strings): Prefix
with objc_. Add deprecated non prefixed inlined versions.
(OBJC_IGNORE_DEPRECATED_API): New macro to hide deprecated
declarations.
* hash.c (hash_new, hash_delete, hash_add, hash_remove, hash_next)
(hash_value_for_key, hash_is_key_in_hash): Prefix with objc_ and
update callers.
* hash_compat.c: New file.
* archive.c: Update callers.
* init.c: Likewise.
* selector.c: Likewise.
* libobjc.def: Add objc_ versions of hash functions.
From-SVN: r95793
2005-03-02 20:37:03 +01:00
|
|
|
__objc_load_methods = objc_hash_new (128,
|
|
|
|
(hash_func_type)objc_hash_ptr,
|
|
|
|
objc_compare_ptrs);
|
2010-10-12 04:43:25 +02:00
|
|
|
__objc_protocols_init ();
|
2010-10-24 19:23:19 +02:00
|
|
|
__objc_accessors_init ();
|
2010-09-14 12:23:37 +02:00
|
|
|
__objc_sync_init ();
|
1998-09-21 03:22:07 +02:00
|
|
|
previous_constructors = 1;
|
|
|
|
}
|
|
|
|
|
2010-12-21 16:34:19 +01:00
|
|
|
/* Save the module pointer so that later we remember to call +load
|
|
|
|
on all classes and categories on it. */
|
2002-07-02 21:43:03 +02:00
|
|
|
objc_mutex_lock (__objc_runtime_mutex);
|
|
|
|
__objc_module_list = list_cons (module, __objc_module_list);
|
1998-09-21 03:22:07 +02:00
|
|
|
|
2010-12-21 13:49:26 +01:00
|
|
|
/* Replace referenced selectors from names to SELs. */
|
1998-09-21 03:22:07 +02:00
|
|
|
if (selectors)
|
2010-12-23 20:46:04 +01:00
|
|
|
{
|
|
|
|
DEBUG_PRINTF (" registering selectors\n");
|
|
|
|
__objc_register_selectors_from_module (selectors);
|
|
|
|
}
|
1998-09-21 03:22:07 +02:00
|
|
|
|
2010-12-18 13:22:59 +01:00
|
|
|
/* Parse the classes in the load module and gather selector
|
|
|
|
information. */
|
1998-09-21 03:22:07 +02:00
|
|
|
for (i = 0; i < symtab->cls_def_cnt; ++i)
|
|
|
|
{
|
|
|
|
Class class = (Class) symtab->defs[i];
|
2002-07-02 21:43:03 +02:00
|
|
|
const char *superclass = (char *) class->super_class;
|
1998-09-21 03:22:07 +02:00
|
|
|
|
|
|
|
/* Make sure we have what we think. */
|
2002-07-02 21:43:03 +02:00
|
|
|
assert (CLS_ISCLASS (class));
|
|
|
|
assert (CLS_ISMETA (class->class_pointer));
|
2010-12-23 20:46:04 +01:00
|
|
|
DEBUG_PRINTF (" installing class '%s'\n", class->name);
|
1998-09-21 03:22:07 +02:00
|
|
|
|
2011-10-09 12:29:50 +02:00
|
|
|
/* Workaround for a bug in clang: Clang may set flags other than
|
|
|
|
_CLS_CLASS and _CLS_META even when compiling for the
|
|
|
|
traditional ABI (version 8), confusing our runtime. Try to
|
|
|
|
wipe these flags out. */
|
|
|
|
if (CLS_ISCLASS (class))
|
|
|
|
__CLS_INFO (class) = _CLS_CLASS;
|
|
|
|
else
|
|
|
|
__CLS_INFO (class) = _CLS_META;
|
|
|
|
|
2010-12-18 13:22:59 +01:00
|
|
|
/* Initialize the subclass list to be NULL. In some cases it
|
|
|
|
isn't and this crashes the program. */
|
1998-09-21 03:22:07 +02:00
|
|
|
class->subclass_list = NULL;
|
|
|
|
|
2010-12-23 00:05:13 +01:00
|
|
|
if (__objc_init_class (class))
|
|
|
|
{
|
|
|
|
/* Check to see if the superclass is known in this point. If
|
|
|
|
it's not add the class to the unresolved_classes list. */
|
|
|
|
if (superclass && ! objc_getClass (superclass))
|
|
|
|
unresolved_classes = list_cons (class, unresolved_classes);
|
|
|
|
}
|
|
|
|
}
|
1998-09-21 03:22:07 +02:00
|
|
|
|
|
|
|
/* Process category information from the module. */
|
|
|
|
for (i = 0; i < symtab->cat_def_cnt; ++i)
|
|
|
|
{
|
2010-12-17 23:12:34 +01:00
|
|
|
struct objc_category *category = symtab->defs[i + symtab->cls_def_cnt];
|
|
|
|
Class class = objc_getClass (category->class_name);
|
1998-09-21 03:22:07 +02:00
|
|
|
|
2010-12-18 13:22:59 +01:00
|
|
|
/* If the class for the category exists then append its
|
|
|
|
methods. */
|
1998-09-21 03:22:07 +02:00
|
|
|
if (class)
|
|
|
|
{
|
2010-12-23 20:46:04 +01:00
|
|
|
DEBUG_PRINTF (" installing category '%s (%s)'\n", category->class_name, category->category_name);
|
1998-09-21 03:22:07 +02:00
|
|
|
/* Do instance methods. */
|
|
|
|
if (category->instance_methods)
|
|
|
|
class_add_method_list (class, category->instance_methods);
|
|
|
|
|
|
|
|
/* Do class methods. */
|
|
|
|
if (category->class_methods)
|
|
|
|
class_add_method_list ((Class) class->class_pointer,
|
|
|
|
category->class_methods);
|
|
|
|
|
|
|
|
if (category->protocols)
|
|
|
|
{
|
|
|
|
__objc_init_protocols (category->protocols);
|
|
|
|
__objc_class_add_protocols (class, category->protocols);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Register the instance methods as class methods, this is
|
2002-07-02 21:43:03 +02:00
|
|
|
only done for root classes. */
|
|
|
|
__objc_register_instance_methods_to_class (class);
|
1998-09-21 03:22:07 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2010-12-23 20:46:04 +01:00
|
|
|
DEBUG_PRINTF (" delaying installation of category '%s (%s)'\n", category->class_name, category->category_name);
|
2010-12-18 13:22:59 +01:00
|
|
|
/* The object to which the category methods belong can't be
|
|
|
|
found. Save the information. */
|
2002-07-02 21:43:03 +02:00
|
|
|
unclaimed_categories = list_cons (category, unclaimed_categories);
|
1998-09-21 03:22:07 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (statics)
|
|
|
|
uninitialized_statics = list_cons (statics, uninitialized_statics);
|
|
|
|
if (uninitialized_statics)
|
|
|
|
objc_init_statics ();
|
|
|
|
|
2010-12-18 13:22:59 +01:00
|
|
|
/* Scan the unclaimed category hash. Attempt to attach any
|
|
|
|
unclaimed categories to objects. */
|
2001-12-17 18:23:09 +01:00
|
|
|
for (cell = &unclaimed_categories; *cell; )
|
1998-09-21 03:22:07 +02:00
|
|
|
{
|
2010-12-17 23:12:34 +01:00
|
|
|
struct objc_category *category = (*cell)->head;
|
|
|
|
Class class = objc_getClass (category->class_name);
|
1998-09-21 03:22:07 +02:00
|
|
|
|
|
|
|
if (class)
|
|
|
|
{
|
2010-12-23 20:46:04 +01:00
|
|
|
DEBUG_PRINTF (" installing (delayed) category '%s (%s)'\n", category->class_name, category->category_name);
|
1998-09-21 03:22:07 +02:00
|
|
|
list_remove_head (cell);
|
|
|
|
|
|
|
|
if (category->instance_methods)
|
|
|
|
class_add_method_list (class, category->instance_methods);
|
|
|
|
|
|
|
|
if (category->class_methods)
|
|
|
|
class_add_method_list ((Class) class->class_pointer,
|
|
|
|
category->class_methods);
|
|
|
|
|
|
|
|
if (category->protocols)
|
|
|
|
{
|
|
|
|
__objc_init_protocols (category->protocols);
|
|
|
|
__objc_class_add_protocols (class, category->protocols);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Register the instance methods as class methods, this is
|
2002-07-02 21:43:03 +02:00
|
|
|
only done for root classes. */
|
|
|
|
__objc_register_instance_methods_to_class (class);
|
1998-09-21 03:22:07 +02:00
|
|
|
}
|
2001-12-17 18:23:09 +01:00
|
|
|
else
|
|
|
|
cell = &(*cell)->tail;
|
1998-09-21 03:22:07 +02:00
|
|
|
}
|
|
|
|
|
2010-12-17 23:12:34 +01:00
|
|
|
if (unclaimed_proto_list && objc_getClass ("Protocol"))
|
1998-09-21 03:22:07 +02:00
|
|
|
{
|
2002-07-02 21:43:03 +02:00
|
|
|
list_mapcar (unclaimed_proto_list,
|
|
|
|
(void (*) (void *))__objc_init_protocols);
|
1998-09-21 03:22:07 +02:00
|
|
|
list_free (unclaimed_proto_list);
|
|
|
|
unclaimed_proto_list = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
objc_send_load ();
|
|
|
|
|
2010-12-19 18:30:30 +01:00
|
|
|
/* Check if there are no unresolved classes (ie, classes whose
|
|
|
|
superclass has not been loaded yet) and that the 'Object' class,
|
|
|
|
used as the class of classes, exist. If so, it is worth
|
|
|
|
"resolving the class links" at this point, which will setup all
|
|
|
|
the class/superclass pointers. */
|
|
|
|
if (!unresolved_classes && objc_getClass ("Object"))
|
2010-12-23 20:46:04 +01:00
|
|
|
{
|
|
|
|
DEBUG_PRINTF (" resolving class links\n");
|
|
|
|
__objc_resolve_class_links ();
|
|
|
|
}
|
2010-12-19 03:12:42 +01:00
|
|
|
|
2010-12-19 18:30:30 +01:00
|
|
|
objc_mutex_unlock (__objc_runtime_mutex);
|
2010-12-23 20:46:04 +01:00
|
|
|
|
|
|
|
DEBUG_PRINTF ("__objc_exec_class (%p) - finished processing module...\n\n", module);
|
1998-09-21 03:22:07 +02:00
|
|
|
}
|
|
|
|
|
2010-12-21 16:34:19 +01:00
|
|
|
/* This function needs to be called with the objc_runtime_mutex
|
|
|
|
locked. */
|
2002-07-02 21:43:03 +02:00
|
|
|
static void
|
|
|
|
objc_send_load (void)
|
1998-09-21 03:22:07 +02:00
|
|
|
{
|
2010-12-21 16:34:19 +01:00
|
|
|
if (!__objc_module_list)
|
1998-09-21 03:22:07 +02:00
|
|
|
return;
|
|
|
|
|
|
|
|
/* Try to find out if all the classes loaded so far also have their
|
2010-12-21 16:34:19 +01:00
|
|
|
superclasses known to the runtime. We suppose that the objects
|
2002-07-02 21:43:03 +02:00
|
|
|
that are allocated in the +load method are in general of a class
|
|
|
|
declared in the same module. */
|
1998-09-21 03:22:07 +02:00
|
|
|
if (unresolved_classes)
|
|
|
|
{
|
|
|
|
Class class = unresolved_classes->head;
|
|
|
|
|
2010-12-17 23:12:34 +01:00
|
|
|
while (objc_getClass ((char *) class->super_class))
|
1998-09-21 03:22:07 +02:00
|
|
|
{
|
|
|
|
list_remove_head (&unresolved_classes);
|
|
|
|
if (unresolved_classes)
|
|
|
|
class = unresolved_classes->head;
|
|
|
|
else
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2002-07-02 21:43:03 +02:00
|
|
|
/* If we still have classes for whom we don't have yet their
|
|
|
|
super classes known to the runtime we don't send the +load
|
2010-12-21 23:17:52 +01:00
|
|
|
messages (and call the load callback) yet. */
|
1998-09-21 03:22:07 +02:00
|
|
|
if (unresolved_classes)
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2010-10-17 13:01:31 +02:00
|
|
|
/* Special check. If 'Object', which is used by meta-classes, has
|
|
|
|
not been loaded yet, delay sending of +load. */
|
2010-12-17 23:12:34 +01:00
|
|
|
if (! objc_getClass ("Object"))
|
1998-09-21 03:22:07 +02:00
|
|
|
return;
|
|
|
|
|
2002-07-02 21:43:03 +02:00
|
|
|
/* Iterate over all modules in the __objc_module_list and call on
|
2010-12-21 23:17:52 +01:00
|
|
|
them the __objc_create_classes_tree function. This function
|
2002-07-02 21:43:03 +02:00
|
|
|
creates a tree of classes that resembles the class hierarchy. */
|
|
|
|
list_mapcar (__objc_module_list,
|
|
|
|
(void (*) (void *)) __objc_create_classes_tree);
|
1998-09-21 03:22:07 +02:00
|
|
|
|
|
|
|
while (__objc_class_tree_list)
|
|
|
|
{
|
|
|
|
#ifdef DEBUG
|
|
|
|
objc_preorder_traverse (__objc_class_tree_list->head,
|
|
|
|
0, __objc_tree_print);
|
|
|
|
#endif
|
|
|
|
objc_preorder_traverse (__objc_class_tree_list->head,
|
|
|
|
0, __objc_send_load);
|
|
|
|
objc_postorder_traverse (__objc_class_tree_list->head,
|
|
|
|
0, __objc_destroy_class_tree_node);
|
|
|
|
list_remove_head (&__objc_class_tree_list);
|
|
|
|
}
|
|
|
|
|
2010-12-21 23:17:52 +01:00
|
|
|
/* For each module, call the _objc_load_callback if any is
|
|
|
|
defined. */
|
|
|
|
list_mapcar (__objc_module_list, (void (*) (void *)) __objc_call_load_callback);
|
|
|
|
|
|
|
|
/* Empty the list of modules. */
|
1998-09-21 03:22:07 +02:00
|
|
|
list_free (__objc_module_list);
|
|
|
|
__objc_module_list = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2010-12-17 23:12:34 +01:00
|
|
|
__objc_create_classes_tree (struct objc_module *module)
|
1998-09-21 03:22:07 +02:00
|
|
|
{
|
2010-12-18 13:22:59 +01:00
|
|
|
/* The runtime mutex is locked at this point */
|
2010-12-17 23:12:34 +01:00
|
|
|
struct objc_symtab *symtab = module->symtab;
|
1998-09-21 03:22:07 +02:00
|
|
|
int i;
|
|
|
|
|
2013-07-21 17:38:21 +02:00
|
|
|
/* Iterate through classes defined in this module and insert them in
|
2002-07-02 21:43:03 +02:00
|
|
|
the classes tree hierarchy. */
|
1998-09-21 03:22:07 +02:00
|
|
|
for (i = 0; i < symtab->cls_def_cnt; i++)
|
|
|
|
{
|
|
|
|
Class class = (Class) symtab->defs[i];
|
|
|
|
|
2010-12-23 00:05:13 +01:00
|
|
|
if (!objc_hash_is_key_in_hash (duplicate_classes, class))
|
|
|
|
objc_tree_insert_class (class);
|
1998-09-21 03:22:07 +02:00
|
|
|
}
|
2010-12-21 16:34:19 +01:00
|
|
|
|
|
|
|
/* Now iterate over "claimed" categories too (ie, categories that
|
|
|
|
extend a class that has already been loaded by the runtime), and
|
|
|
|
insert them in the classes tree hiearchy too. Otherwise, if you
|
|
|
|
add a category, its +load method would not be called if the class
|
|
|
|
is already loaded in the runtime. It the category is
|
|
|
|
"unclaimed", ie, we haven't loaded the main class yet, postpone
|
|
|
|
sending +load as we want to execute +load from the class before
|
|
|
|
we execute the one from the category. */
|
|
|
|
for (i = 0; i < symtab->cat_def_cnt; ++i)
|
|
|
|
{
|
|
|
|
struct objc_category *category = symtab->defs[i + symtab->cls_def_cnt];
|
|
|
|
Class class = objc_getClass (category->class_name);
|
|
|
|
|
|
|
|
/* If the class for the category exists then append its
|
|
|
|
methods. */
|
|
|
|
if (class)
|
|
|
|
objc_tree_insert_class (class);
|
|
|
|
}
|
1998-09-21 03:22:07 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2010-12-21 23:17:52 +01:00
|
|
|
__objc_call_load_callback (struct objc_module *module)
|
1998-09-21 03:22:07 +02:00
|
|
|
{
|
2010-12-21 23:17:52 +01:00
|
|
|
if (_objc_load_callback)
|
1998-09-21 03:22:07 +02:00
|
|
|
{
|
2010-12-21 23:17:52 +01:00
|
|
|
/* The runtime mutex is locked at this point. */
|
|
|
|
struct objc_symtab *symtab = module->symtab;
|
|
|
|
int i;
|
|
|
|
|
2013-07-21 17:38:21 +02:00
|
|
|
/* Iterate through classes defined in this module and call the callback
|
2010-12-21 23:17:52 +01:00
|
|
|
for each one. */
|
|
|
|
for (i = 0; i < symtab->cls_def_cnt; i++)
|
|
|
|
{
|
|
|
|
Class class = (Class) symtab->defs[i];
|
2010-12-23 00:05:13 +01:00
|
|
|
|
|
|
|
if (!objc_hash_is_key_in_hash (duplicate_classes, class))
|
|
|
|
{
|
|
|
|
/* Call the _objc_load_callback for this class. */
|
2010-12-23 20:46:04 +01:00
|
|
|
DEBUG_PRINTF (" calling the load callback for class '%s'\n", class->name);
|
2010-12-23 00:05:13 +01:00
|
|
|
_objc_load_callback (class, 0);
|
|
|
|
}
|
2010-12-21 23:17:52 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Call the _objc_load_callback for categories. Don't register
|
|
|
|
the instance methods as class methods for categories to root
|
|
|
|
classes since they were already added in the class. */
|
|
|
|
for (i = 0; i < symtab->cat_def_cnt; i++)
|
|
|
|
{
|
|
|
|
struct objc_category *category = symtab->defs[i + symtab->cls_def_cnt];
|
|
|
|
Class class = objc_getClass (category->class_name);
|
|
|
|
|
2010-12-23 20:46:04 +01:00
|
|
|
DEBUG_PRINTF (" calling the load callback for category '%s (%s)'\n",
|
|
|
|
category->class_name, category->category_name);
|
2010-12-21 23:17:52 +01:00
|
|
|
_objc_load_callback (class, category);
|
|
|
|
}
|
1998-09-21 03:22:07 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-07-02 21:43:03 +02:00
|
|
|
/* Sanity check the version of gcc used to compile `module'. */
|
|
|
|
static void
|
2010-12-17 23:12:34 +01:00
|
|
|
init_check_module_version (struct objc_module *module)
|
1998-09-21 03:22:07 +02:00
|
|
|
{
|
2010-12-17 23:12:34 +01:00
|
|
|
if ((module->version != OBJC_VERSION) || (module->size != sizeof (struct objc_module)))
|
1998-09-21 03:22:07 +02:00
|
|
|
{
|
2010-09-12 02:43:15 +02:00
|
|
|
_objc_abort ("Module %s version %d doesn't match runtime %d\n",
|
|
|
|
module->name, (int)module->version, OBJC_VERSION);
|
1998-09-21 03:22:07 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-12-23 00:05:13 +01:00
|
|
|
/* __objc_init_class must be called with __objc_runtime_mutex already
|
|
|
|
locked. Return YES if the class could be setup; return NO if the
|
|
|
|
class could not be setup because a class with the same name already
|
|
|
|
exists. */
|
|
|
|
BOOL
|
2010-10-16 23:26:59 +02:00
|
|
|
__objc_init_class (Class class)
|
|
|
|
{
|
|
|
|
/* Store the class in the class table and assign class numbers. */
|
2010-12-21 23:49:37 +01:00
|
|
|
if (__objc_add_class_to_hash (class))
|
|
|
|
{
|
|
|
|
/* Register all of the selectors in the class and meta class. */
|
|
|
|
__objc_register_selectors_from_class (class);
|
|
|
|
__objc_register_selectors_from_class ((Class) class->class_pointer);
|
|
|
|
|
|
|
|
/* Install the fake dispatch tables. */
|
|
|
|
__objc_install_premature_dtable (class);
|
|
|
|
__objc_install_premature_dtable (class->class_pointer);
|
|
|
|
|
|
|
|
/* Register the instance methods as class methods, this is only
|
|
|
|
done for root classes. */
|
|
|
|
__objc_register_instance_methods_to_class (class);
|
|
|
|
|
|
|
|
if (class->protocols)
|
|
|
|
__objc_init_protocols (class->protocols);
|
2010-12-23 00:05:13 +01:00
|
|
|
|
|
|
|
return YES;
|
2010-12-21 23:49:37 +01:00
|
|
|
}
|
|
|
|
else
|
2010-12-23 00:05:13 +01:00
|
|
|
{
|
|
|
|
/* The module contains a duplicate class. Remember it so that
|
|
|
|
we will ignore it later. */
|
2010-12-23 20:46:04 +01:00
|
|
|
DEBUG_PRINTF (" duplicate class '%s' - will be ignored\n", class->name);
|
2010-12-23 00:05:13 +01:00
|
|
|
objc_hash_add (&duplicate_classes, class, class);
|
|
|
|
return NO;
|
|
|
|
}
|
2010-10-16 23:26:59 +02:00
|
|
|
}
|
|
|
|
|
2010-10-15 12:35:00 +02:00
|
|
|
/* __objc_init_protocol must be called with __objc_runtime_mutex
|
|
|
|
already locked, and the "Protocol" class already registered. */
|
|
|
|
static void
|
|
|
|
__objc_init_protocol (struct objc_protocol *protocol)
|
|
|
|
{
|
|
|
|
static Class proto_class = 0;
|
|
|
|
|
|
|
|
if (! proto_class)
|
2010-12-17 23:12:34 +01:00
|
|
|
proto_class = objc_getClass ("Protocol");
|
2010-10-15 12:35:00 +02:00
|
|
|
|
|
|
|
if (((size_t)protocol->class_pointer) == PROTOCOL_VERSION)
|
|
|
|
{
|
2010-12-18 13:22:59 +01:00
|
|
|
/* Assign class pointer. */
|
2010-10-15 12:35:00 +02:00
|
|
|
protocol->class_pointer = proto_class;
|
|
|
|
|
|
|
|
/* Register all the selectors in the protocol with the runtime.
|
|
|
|
This both registers the selectors with the right types, and
|
|
|
|
it also fixes up the 'struct objc_method' structures inside
|
|
|
|
the protocol so that each method_name (a char * as compiled
|
|
|
|
by the compiler) is replaced with the appropriate runtime
|
|
|
|
SEL. */
|
|
|
|
if (protocol->class_methods)
|
|
|
|
__objc_register_selectors_from_description_list (protocol->class_methods);
|
|
|
|
|
|
|
|
if (protocol->instance_methods)
|
|
|
|
__objc_register_selectors_from_description_list (protocol->instance_methods);
|
|
|
|
|
|
|
|
/* Register the protocol in the hashtable or protocols by
|
|
|
|
name. */
|
|
|
|
__objc_protocols_add_protocol (protocol->protocol_name, protocol);
|
|
|
|
|
2010-12-18 13:22:59 +01:00
|
|
|
/* Init super protocols. */
|
2010-10-15 12:35:00 +02:00
|
|
|
__objc_init_protocols (protocol->protocol_list);
|
|
|
|
}
|
|
|
|
else if (protocol->class_pointer != proto_class)
|
|
|
|
{
|
|
|
|
_objc_abort ("Version %d doesn't match runtime protocol version %d\n",
|
|
|
|
(int) ((char *) protocol->class_pointer
|
|
|
|
- (char *) 0),
|
|
|
|
PROTOCOL_VERSION);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1998-09-21 03:22:07 +02:00
|
|
|
static void
|
2002-07-02 21:43:03 +02:00
|
|
|
__objc_init_protocols (struct objc_protocol_list *protos)
|
1998-09-21 03:22:07 +02:00
|
|
|
{
|
Object.m: Fix signed/unsigned warning.
* Object.m: Fix signed/unsigned warning.
* Protocol.m: Likewise.
* archive.c: Always include stdlib.h.
(objc_read_short, objc_read_unsigned_short, objc_read_int,
objc_read_long, __objc_read_nbyte_uint, __objc_read_nbyte_ulong):
Fix signed/unsigned warning.
(objc_write_type, objc_read_type, objc_write_types,
objc_read_types): Ensure ctype 8-bit safety.
(__objc_no_write, __objc_no_read): Mark unused parameters.
* class.c (class_table_setup): Specify void arg.
* encoding.c (atoi, objc_sizeof_type, objc_alignof_type,
objc_skip_typespec, objc_skip_offset,
objc_layout_structure_next_member): Ensure ctype 8-bit safety.
(objc_layout_structure_next_member): Ensure variables are
initialized.
* gc.c (__objc_generate_gc_type_description,
class_ivar_set_gcinvisible): Mark unused parameters.
* init.c (__objc_send_load, __objc_destroy_class_tree_node): Mark
unused parameters.
(__objc_init_protocols) Fix signed/unsigned warning.
* nil_method.c (nil_method): Mark unused parameters.
* thr.h (objc_thread_callback): Specify void arg.
* sarray.c (sarray_new, sarray_realloc, sarray_free): Fix
signed/unsigned warning.
(sarray_free): Fix formatting.
* selector.c (sel_types_match): Ensure ctype 8-bit safety.
* sendmsg.c (__objc_init_install_dtable) Mark unused parameters.
From-SVN: r54649
2002-06-15 19:50:14 +02:00
|
|
|
size_t i;
|
1998-09-21 03:22:07 +02:00
|
|
|
static Class proto_class = 0;
|
|
|
|
|
|
|
|
if (! protos)
|
|
|
|
return;
|
|
|
|
|
2002-07-02 21:43:03 +02:00
|
|
|
objc_mutex_lock (__objc_runtime_mutex);
|
1998-09-21 03:22:07 +02:00
|
|
|
|
2002-07-02 21:43:03 +02:00
|
|
|
if (! proto_class)
|
2010-12-17 23:12:34 +01:00
|
|
|
proto_class = objc_getClass ("Protocol");
|
1998-09-21 03:22:07 +02:00
|
|
|
|
2002-07-02 21:43:03 +02:00
|
|
|
if (! proto_class)
|
1998-09-21 03:22:07 +02:00
|
|
|
{
|
|
|
|
unclaimed_proto_list = list_cons (protos, unclaimed_proto_list);
|
2002-07-02 21:43:03 +02:00
|
|
|
objc_mutex_unlock (__objc_runtime_mutex);
|
1998-09-21 03:22:07 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
#if 0
|
2010-12-18 13:22:59 +01:00
|
|
|
assert (protos->next == 0); /* Only single ones allowed. */
|
1998-09-21 03:22:07 +02:00
|
|
|
#endif
|
|
|
|
|
2002-07-02 21:43:03 +02:00
|
|
|
for (i = 0; i < protos->count; i++)
|
1998-09-21 03:22:07 +02:00
|
|
|
{
|
2002-07-02 21:43:03 +02:00
|
|
|
struct objc_protocol *aProto = protos->list[i];
|
2010-10-15 12:35:00 +02:00
|
|
|
__objc_init_protocol (aProto);
|
1998-09-21 03:22:07 +02:00
|
|
|
}
|
|
|
|
|
2002-07-02 21:43:03 +02:00
|
|
|
objc_mutex_unlock (__objc_runtime_mutex);
|
1998-09-21 03:22:07 +02:00
|
|
|
}
|
|
|
|
|
2002-07-02 21:43:03 +02:00
|
|
|
static void
|
|
|
|
__objc_class_add_protocols (Class class, struct objc_protocol_list *protos)
|
1998-09-21 03:22:07 +02:00
|
|
|
{
|
|
|
|
if (! protos)
|
|
|
|
return;
|
|
|
|
|
|
|
|
protos->next = class->protocols;
|
|
|
|
class->protocols = protos;
|
|
|
|
}
|