1 /* GNU Objective C Runtime message lookup
2 Copyright (C) 1993, 1995, 1996, 1997, 1998,
3 2001, 2002, 2004, 2009, 2010 Free Software Foundation, Inc.
4 Contributed by Kresten Krab Thorup
6 This file is part of GCC.
8 GCC is free software; you can redistribute it and/or modify it under the
9 terms of the GNU General Public License as published by the Free Software
10 Foundation; either version 3, or (at your option) any later version.
12 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
13 WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
14 FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
17 Under Section 7 of GPL version 3, you are granted additional
18 permissions described in the GCC Runtime Library Exception, version
19 3.1, as published by the Free Software Foundation.
21 You should have received a copy of the GNU General Public License and
22 a copy of the GCC Runtime Library Exception along with this program;
23 see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
24 <http://www.gnu.org/licenses/>. */
27 /* FIXME: This file has no business including tm.h. */
28 /* FIXME: This should be using libffi instead of __builtin_apply
31 #include "objc-private/common.h"
32 #include "objc-private/error.h"
34 #include "coretypes.h"
36 #include "objc/runtime.h"
37 #include "objc/message.h" /* For objc_msg_lookup(), objc_msg_lookup_super(). */
39 #include "objc-private/module-abi-8.h"
40 #include "objc-private/runtime.h"
41 #include "objc-private/sarray.h"
42 #include "objc-private/selector.h" /* For sel_is_mapped() */
43 #include "runtime-info.h"
44 #include <assert.h> /* For assert */
45 #include <string.h> /* For strlen */
47 /* This is how we hack STRUCT_VALUE to be 1 or 0. */
48 #define gen_rtx(args...) 1
49 #define gen_rtx_MEM(args...) 1
50 #define gen_rtx_REG(args...) 1
51 /* Already defined in gcc/coretypes.h. So prevent double definition warning. */
55 #if ! defined (STRUCT_VALUE) || STRUCT_VALUE == 0
56 #define INVISIBLE_STRUCT_RETURN 1
58 #define INVISIBLE_STRUCT_RETURN 0
61 /* The uninstalled dispatch table. */
62 struct sarray *__objc_uninstalled_dtable = 0; /* !T:MUTEX */
64 /* Two hooks for method forwarding. If either is set, it is invoked to
65 * return a function that performs the real forwarding. If both are
66 * set, the result of __objc_msg_forward2 will be preferred over that
67 * of __objc_msg_forward. If both return NULL or are unset, the
68 * libgcc based functions (__builtin_apply and friends) are used. */
69 IMP (*__objc_msg_forward) (SEL) = NULL;
70 IMP (*__objc_msg_forward2) (id, SEL) = NULL;
72 /* Send +initialize to class. */
73 static void __objc_send_initialize (Class);
75 static void __objc_install_dispatch_table_for_class (Class);
77 /* Forward declare some functions. */
78 static void __objc_init_install_dtable (id, SEL);
80 /* Various forwarding functions that are used based upon the
81 return type for the selector.
82 __objc_block_forward for structures.
83 __objc_double_forward for floats/doubles.
84 __objc_word_forward for pointers or types that fit in registers. */
85 static double __objc_double_forward (id, SEL, ...);
86 static id __objc_word_forward (id, SEL, ...);
87 typedef struct { id many[8]; } __big;
88 #if INVISIBLE_STRUCT_RETURN
93 __objc_block_forward (id, SEL, ...);
94 static struct objc_method * search_for_method_in_hierarchy (Class class, SEL sel);
95 struct objc_method * search_for_method_in_list (struct objc_method_list * list, SEL op);
96 id nil_method (id, SEL);
98 /* Given a selector, return the proper forwarding implementation. */
101 __objc_get_forward_imp (id rcv, SEL sel)
103 /* If a custom forwarding hook was registered, try getting a
104 forwarding function from it. There are two forward routine hooks,
105 one that takes the receiver as an argument and one that does
107 if (__objc_msg_forward2)
110 if ((result = __objc_msg_forward2 (rcv, sel)) != NULL)
113 if (__objc_msg_forward)
116 if ((result = __objc_msg_forward (sel)) != NULL)
120 /* In all other cases, use the default forwarding functions built
121 using __builtin_apply and friends. */
123 const char *t = sel->sel_types;
125 if (t && (*t == '[' || *t == '(' || *t == '{')
126 #ifdef OBJC_MAX_STRUCT_BY_VALUE
127 && objc_sizeof_type (t) > OBJC_MAX_STRUCT_BY_VALUE
130 return (IMP)__objc_block_forward;
131 else if (t && (*t == 'f' || *t == 'd'))
132 return (IMP)__objc_double_forward;
134 return (IMP)__objc_word_forward;
138 /* Selectors for +resolveClassMethod: and +resolveInstanceMethod:.
139 These are set up at startup. */
140 static SEL selector_resolveClassMethod = NULL;
141 static SEL selector_resolveInstanceMethod = NULL;
143 /* Internal routines use to resolve a class method using
144 +resolveClassMethod:. 'class' is always a non-Nil class (*not* a
145 meta-class), and 'sel' is the selector that we are trying to
146 resolve. This must be called when class is not Nil, and the
147 dispatch table for class methods has already been installed.
149 This routine tries to call +resolveClassMethod: to give an
150 opportunity to resolve the method. If +resolveClassMethod: returns
151 YES, it tries looking up the method again, and if found, it returns
152 it. Else, it returns NULL. */
155 __objc_resolve_class_method (Class class, SEL sel)
157 /* We need to lookup +resolveClassMethod:. */
158 BOOL (*resolveMethodIMP) (id, SEL, SEL);
160 /* The dispatch table for class methods is already installed and we
161 don't want any forwarding to happen when looking up this method,
162 so we just look it up directly. Note that if 'sel' is precisely
163 +resolveClassMethod:, this would look it up yet again and find
164 nothing. That's no problem and there's no recursion. */
165 resolveMethodIMP = (BOOL (*) (id, SEL, SEL))sarray_get_safe
166 (class->class_pointer->dtable, (size_t) selector_resolveClassMethod->sel_id);
168 if (resolveMethodIMP && resolveMethodIMP ((id)class, selector_resolveClassMethod, sel))
170 /* +resolveClassMethod: returned YES. Look the method up again.
171 We already know the dtable is installed. */
173 /* TODO: There is the case where +resolveClassMethod: is buggy
174 and returned YES without actually adding the method. We
175 could maybe print an error message. */
176 return sarray_get_safe (class->class_pointer->dtable, (size_t) sel->sel_id);
182 /* Internal routines use to resolve a instance method using
183 +resolveInstanceMethod:. 'class' is always a non-Nil class, and
184 'sel' is the selector that we are trying to resolve. This must be
185 called when class is not Nil, and the dispatch table for instance
186 methods has already been installed.
188 This routine tries to call +resolveInstanceMethod: to give an
189 opportunity to resolve the method. If +resolveInstanceMethod:
190 returns YES, it tries looking up the method again, and if found, it
191 returns it. Else, it returns NULL. */
194 __objc_resolve_instance_method (Class class, SEL sel)
196 /* We need to lookup +resolveInstanceMethod:. */
197 BOOL (*resolveMethodIMP) (id, SEL, SEL);
199 /* The dispatch table for class methods may not be already installed
200 so we have to install it if needed. */
201 resolveMethodIMP = sarray_get_safe (class->class_pointer->dtable,
202 (size_t) selector_resolveInstanceMethod->sel_id);
203 if (resolveMethodIMP == 0)
205 /* Try again after installing the dtable. */
206 if (class->class_pointer->dtable == __objc_uninstalled_dtable)
208 objc_mutex_lock (__objc_runtime_mutex);
209 if (class->class_pointer->dtable == __objc_uninstalled_dtable)
210 __objc_install_dispatch_table_for_class (class->class_pointer);
211 objc_mutex_unlock (__objc_runtime_mutex);
213 resolveMethodIMP = sarray_get_safe (class->class_pointer->dtable,
214 (size_t) selector_resolveInstanceMethod->sel_id);
217 if (resolveMethodIMP && resolveMethodIMP ((id)class, selector_resolveInstanceMethod, sel))
219 /* +resolveInstanceMethod: returned YES. Look the method up
220 again. We already know the dtable is installed. */
222 /* TODO: There is the case where +resolveInstanceMethod: is
223 buggy and returned YES without actually adding the method.
224 We could maybe print an error message. */
225 return sarray_get_safe (class->dtable, (size_t) sel->sel_id);
231 /* Given a class and selector, return the selector's
235 get_imp (Class class, SEL sel)
237 /* In a vanilla implementation we would first check if the dispatch
238 table is installed. Here instead, to get more speed in the
239 standard case (that the dispatch table is installed) we first try
240 to get the imp using brute force. Only if that fails, we do what
241 we should have been doing from the very beginning, that is, check
242 if the dispatch table needs to be installed, install it if it's
243 not installed, and retrieve the imp from the table if it's
245 void *res = sarray_get_safe (class->dtable, (size_t) sel->sel_id);
248 /* Not a valid method. */
249 if (class->dtable == __objc_uninstalled_dtable)
251 /* The dispatch table needs to be installed. */
252 objc_mutex_lock (__objc_runtime_mutex);
254 /* Double-checked locking pattern: Check
255 __objc_uninstalled_dtable again in case another thread
256 installed the dtable while we were waiting for the lock
258 if (class->dtable == __objc_uninstalled_dtable)
260 __objc_install_dispatch_table_for_class (class);
263 objc_mutex_unlock (__objc_runtime_mutex);
264 /* Call ourselves with the installed dispatch table and get
266 res = get_imp (class, sel);
270 /* The dispatch table has been installed. */
272 /* Get the method from the dispatch table (we try to get it
273 again in case another thread has installed the dtable just
274 after we invoked sarray_get_safe, but before we checked
275 class->dtable == __objc_uninstalled_dtable). */
276 res = sarray_get_safe (class->dtable, (size_t) sel->sel_id);
279 /* The dispatch table has been installed, and the method
280 is not in the dispatch table. So the method just
281 doesn't exist for the class. */
283 /* Try going through the +resolveClassMethod: or
284 +resolveInstanceMethod: process. */
285 if (CLS_ISMETA (class))
287 /* We have the meta class, but we need to invoke the
288 +resolveClassMethod: method on the class. So, we
289 need to obtain the class from the meta class,
290 which we do using the fact that both the class
291 and the meta-class have the same name. */
292 Class realClass = objc_lookUpClass (class->name);
294 res = __objc_resolve_class_method (realClass, sel);
297 res = __objc_resolve_instance_method (class, sel);
301 /* If that fails, then return the forwarding
302 implementation. We don't know the receiver (only
303 its class), so we have to pass 'nil' as the first
304 argument. Passing the class as first argument is
305 wrong because the class is not the receiver; it
306 can result in us calling a class method when we
307 want an instance method of the same name. */
308 res = __objc_get_forward_imp (nil, sel);
316 /* The new name of get_imp(). */
318 class_getMethodImplementation (Class class_, SEL selector)
320 if (class_ == Nil || selector == NULL)
323 /* get_imp is inlined, so we're good. */
324 return get_imp (class_, selector);
327 /* Given a method, return its implementation. This has been replaced
328 by method_getImplementation() in the modern API. */
330 method_get_imp (struct objc_method * method)
332 return (method != (struct objc_method *)0) ? method->method_imp : (IMP)0;
335 /* Query if an object can respond to a selector, returns YES if the
336 object implements the selector otherwise NO. Does not check if the
337 method can be forwarded. */
340 __objc_responds_to (id object, SEL sel)
344 /* Install dispatch table if need be. */
345 if (object->class_pointer->dtable == __objc_uninstalled_dtable)
347 objc_mutex_lock (__objc_runtime_mutex);
348 if (object->class_pointer->dtable == __objc_uninstalled_dtable)
350 __objc_install_dispatch_table_for_class (object->class_pointer);
352 objc_mutex_unlock (__objc_runtime_mutex);
355 /* Get the method from the dispatch table. */
356 res = sarray_get_safe (object->class_pointer->dtable, (size_t) sel->sel_id);
361 class_respondsToSelector (Class class_, SEL selector)
365 if (class_ == Nil || selector == NULL)
368 /* Install dispatch table if need be. */
369 if (class_->dtable == __objc_uninstalled_dtable)
371 objc_mutex_lock (__objc_runtime_mutex);
372 if (class_->dtable == __objc_uninstalled_dtable)
374 __objc_install_dispatch_table_for_class (class_);
376 objc_mutex_unlock (__objc_runtime_mutex);
379 /* Get the method from the dispatch table. */
380 res = sarray_get_safe (class_->dtable, (size_t) selector->sel_id);
384 /* This is the lookup function. All entries in the table are either a
385 valid method *or* zero. If zero then either the dispatch table
386 needs to be installed or it doesn't exist and forwarding is
389 objc_msg_lookup (id receiver, SEL op)
394 result = sarray_get_safe (receiver->class_pointer->dtable,
398 /* Not a valid method. */
399 if (receiver->class_pointer->dtable == __objc_uninstalled_dtable)
401 /* The dispatch table needs to be installed. This
402 happens on the very first method call to the
404 __objc_init_install_dtable (receiver, op);
406 /* Get real method for this in newly installed
408 result = get_imp (receiver->class_pointer, op);
412 /* The dispatch table has been installed. Check again
413 if the method exists (just in case the dispatch table
414 has been installed by another thread after we did the
415 previous check that the method exists). */
416 result = sarray_get_safe (receiver->class_pointer->dtable,
420 /* Try going through the +resolveClassMethod: or
421 +resolveInstanceMethod: process. */
422 if (CLS_ISMETA (receiver->class_pointer))
423 result = __objc_resolve_class_method ((Class)receiver, op);
425 result = __objc_resolve_instance_method (receiver->class_pointer,
430 /* If the method still just doesn't exist for
431 the class, attempt to forward the method. */
432 result = __objc_get_forward_imp (receiver, op);
440 return (IMP)nil_method;
444 objc_msg_lookup_super (struct objc_super *super, SEL sel)
447 return get_imp (super->super_class, sel);
449 return (IMP)nil_method;
452 /* Temporarily defined here until objc_msg_sendv() goes away. */
453 char *method_get_first_argument (struct objc_method *,
456 char *method_get_next_argument (arglist_t argframe,
458 int method_get_sizeof_arguments (struct objc_method *);
461 class_get_instance_method (Class class, SEL op);
464 objc_msg_sendv (id object, SEL op, arglist_t arg_frame)
466 struct objc_method *m = class_get_instance_method (object->class_pointer, op);
468 *((id *) method_get_first_argument (m, arg_frame, &type)) = object;
469 *((SEL *) method_get_next_argument (arg_frame, &type)) = op;
470 return __builtin_apply ((apply_t) m->method_imp,
472 method_get_sizeof_arguments (m));
476 __objc_init_dispatch_tables ()
478 __objc_uninstalled_dtable = sarray_new (200, 0);
480 /* TODO: It would be cool to register typed selectors here. */
481 selector_resolveClassMethod = sel_registerName ("resolveClassMethod:");
482 selector_resolveInstanceMethod =sel_registerName ("resolveInstanceMethod:");
485 /* This function is called by objc_msg_lookup when the dispatch table
486 needs to be installed; thus it is called once for each class,
487 namely when the very first message is sent to it. */
489 __objc_init_install_dtable (id receiver, SEL op __attribute__ ((__unused__)))
491 objc_mutex_lock (__objc_runtime_mutex);
493 /* This may happen, if the programmer has taken the address of a
494 method before the dtable was initialized... too bad for him! */
495 if (receiver->class_pointer->dtable != __objc_uninstalled_dtable)
497 objc_mutex_unlock (__objc_runtime_mutex);
501 if (CLS_ISCLASS (receiver->class_pointer))
503 /* receiver is an ordinary object. */
504 assert (CLS_ISCLASS (receiver->class_pointer));
506 /* Install instance methods table. */
507 __objc_install_dispatch_table_for_class (receiver->class_pointer);
509 /* Call +initialize -- this will in turn install the factory
510 dispatch table if not already done. :-) */
511 __objc_send_initialize (receiver->class_pointer);
515 /* receiver is a class object. */
516 assert (CLS_ISCLASS ((Class)receiver));
517 assert (CLS_ISMETA (receiver->class_pointer));
519 /* Install real dtable for factory methods. */
520 __objc_install_dispatch_table_for_class (receiver->class_pointer);
522 __objc_send_initialize ((Class)receiver);
524 objc_mutex_unlock (__objc_runtime_mutex);
527 /* Install dummy table for class which causes the first message to
528 that class (or instances hereof) to be initialized properly. */
530 __objc_install_premature_dtable (Class class)
532 assert (__objc_uninstalled_dtable);
533 class->dtable = __objc_uninstalled_dtable;
536 /* Send +initialize to class if not already done. */
538 __objc_send_initialize (Class class)
540 /* This *must* be a class object. */
541 assert (CLS_ISCLASS (class));
542 assert (! CLS_ISMETA (class));
544 if (! CLS_ISINITIALIZED (class))
546 CLS_SETINITIALIZED (class);
547 CLS_SETINITIALIZED (class->class_pointer);
549 /* Create the garbage collector type memory description. */
550 __objc_generate_gc_type_description (class);
552 if (class->super_class)
553 __objc_send_initialize (class->super_class);
556 SEL op = sel_registerName ("initialize");
558 struct objc_method_list * method_list = class->class_pointer->methods;
563 struct objc_method * method;
565 for (i = 0; i < method_list->method_count; i++)
567 method = &(method_list->method_list[i]);
568 if (method->method_name
569 && method->method_name->sel_id == op->sel_id)
571 imp = method->method_imp;
579 method_list = method_list->method_next;
582 (*imp) ((id) class, op);
587 /* Walk on the methods list of class and install the methods in the
588 reverse order of the lists. Since methods added by categories are
589 before the methods of class in the methods list, this allows
590 categories to substitute methods declared in class. However if
591 more than one category replaces the same method nothing is
592 guaranteed about what method will be used. Assumes that
593 __objc_runtime_mutex is locked down. */
595 __objc_install_methods_in_dtable (Class class, struct objc_method_list * method_list)
602 if (method_list->method_next)
603 __objc_install_methods_in_dtable (class, method_list->method_next);
605 for (i = 0; i < method_list->method_count; i++)
607 struct objc_method * method = &(method_list->method_list[i]);
608 sarray_at_put_safe (class->dtable,
609 (sidx) method->method_name->sel_id,
614 /* Assumes that __objc_runtime_mutex is locked down. */
616 __objc_install_dispatch_table_for_class (Class class)
620 /* If the class has not yet had its class links resolved, we must
621 re-compute all class links. */
622 if (! CLS_ISRESOLV (class))
623 __objc_resolve_class_links ();
625 super = class->super_class;
627 if (super != 0 && (super->dtable == __objc_uninstalled_dtable))
628 __objc_install_dispatch_table_for_class (super);
630 /* Allocate dtable if necessary. */
633 objc_mutex_lock (__objc_runtime_mutex);
634 class->dtable = sarray_new (__objc_selector_max_index, 0);
635 objc_mutex_unlock (__objc_runtime_mutex);
638 class->dtable = sarray_lazy_copy (super->dtable);
640 __objc_install_methods_in_dtable (class, class->methods);
644 __objc_update_dispatch_table_for_class (Class class)
649 /* Not yet installed -- skip it. */
650 if (class->dtable == __objc_uninstalled_dtable)
653 objc_mutex_lock (__objc_runtime_mutex);
656 __objc_install_premature_dtable (class); /* someone might require it... */
657 sarray_free (arr); /* release memory */
659 /* Could have been lazy... */
660 __objc_install_dispatch_table_for_class (class);
662 if (class->subclass_list) /* Traverse subclasses. */
663 for (next = class->subclass_list; next; next = next->sibling_class)
664 __objc_update_dispatch_table_for_class (next);
666 objc_mutex_unlock (__objc_runtime_mutex);
669 /* This function adds a method list to a class. This function is
670 typically called by another function specific to the run-time. As
671 such this function does not worry about thread safe issues.
673 This one is only called for categories. Class objects have their
674 methods installed right away, and their selectors are made into
675 SEL's by the function __objc_register_selectors_from_class. */
677 class_add_method_list (Class class, struct objc_method_list * list)
679 /* Passing of a linked list is not allowed. Do multiple calls. */
680 assert (! list->method_next);
682 __objc_register_selectors_from_list(list);
684 /* Add the methods to the class's method list. */
685 list->method_next = class->methods;
686 class->methods = list;
688 /* Update the dispatch table of class. */
689 __objc_update_dispatch_table_for_class (class);
693 class_get_instance_method (Class class, SEL op)
695 return search_for_method_in_hierarchy (class, op);
699 class_get_class_method (MetaClass class, SEL op)
701 return search_for_method_in_hierarchy (class, op);
705 class_getInstanceMethod (Class class_, SEL selector)
707 struct objc_method *m;
709 if (class_ == Nil || selector == NULL)
712 m = search_for_method_in_hierarchy (class_, selector);
716 /* Try going through +resolveInstanceMethod:, and do the search
717 again if successful. */
718 if (__objc_resolve_instance_method (class_, selector))
719 return search_for_method_in_hierarchy (class_, selector);
725 class_getClassMethod (Class class_, SEL selector)
727 struct objc_method *m;
729 if (class_ == Nil || selector == NULL)
732 m = search_for_method_in_hierarchy (class_->class_pointer,
737 /* Try going through +resolveClassMethod:, and do the search again
739 if (__objc_resolve_class_method (class_, selector))
740 return search_for_method_in_hierarchy (class_->class_pointer,
747 class_addMethod (Class class_, SEL selector, IMP implementation,
748 const char *method_types)
750 struct objc_method_list *method_list;
751 struct objc_method *method;
752 const char *method_name;
754 if (class_ == Nil || selector == NULL || implementation == NULL
755 || method_types == NULL || (strcmp (method_types, "") == 0))
758 method_name = sel_getName (selector);
759 if (method_name == NULL)
762 method_list = (struct objc_method_list *)objc_calloc (1, sizeof (struct objc_method_list));
763 method_list->method_count = 1;
765 method = &(method_list->method_list[0]);
766 method->method_name = objc_malloc (strlen (method_name) + 1);
767 strcpy ((char *)method->method_name, method_name);
769 method->method_types = objc_malloc (strlen (method_types) + 1);
770 strcpy ((char *)method->method_types, method_types);
772 method->method_imp = implementation;
774 if (CLS_IS_IN_CONSTRUCTION (class_))
776 /* We only need to add the method to the list. It will be
777 registered with the runtime when the class pair is registered
779 method_list->method_next = class_->methods;
780 class_->methods = method_list;
784 /* Add the method to a live class. */
785 objc_mutex_lock (__objc_runtime_mutex);
786 class_add_method_list (class_, method_list);
787 objc_mutex_unlock (__objc_runtime_mutex);
793 /* Temporarily, until we include objc/runtime.h. */
795 method_setImplementation (struct objc_method * method, IMP implementation);
798 class_replaceMethod (Class class_, SEL selector, IMP implementation,
799 const char *method_types)
801 struct objc_method * method;
803 if (class_ == Nil || selector == NULL || implementation == NULL
804 || method_types == NULL)
807 method = search_for_method_in_hierarchy (class_, selector);
811 return method_setImplementation (method, implementation);
815 class_addMethod (class_, selector, implementation, method_types);
820 /* Search for a method starting from the current class up its
821 hierarchy. Return a pointer to the method's method structure if
822 found. NULL otherwise. */
823 static struct objc_method *
824 search_for_method_in_hierarchy (Class cls, SEL sel)
826 struct objc_method * method = NULL;
829 if (! sel_is_mapped (sel))
832 /* Scan the method list of the class. If the method isn't found in
833 the list then step to its super class. */
834 for (class = cls; ((! method) && class); class = class->super_class)
835 method = search_for_method_in_list (class->methods, sel);
842 /* Given a linked list of method and a method's name. Search for the
843 named method's method structure. Return a pointer to the method's
844 method structure if found. NULL otherwise. */
846 search_for_method_in_list (struct objc_method_list * list, SEL op)
848 struct objc_method_list * method_list = list;
850 if (! sel_is_mapped (op))
853 /* If not found then we'll search the list. */
858 /* Search the method list. */
859 for (i = 0; i < method_list->method_count; ++i)
861 struct objc_method * method = &method_list->method_list[i];
863 if (method->method_name)
864 if (method->method_name->sel_id == op->sel_id)
868 /* The method wasn't found. Follow the link to the next list of
870 method_list = method_list->method_next;
876 static retval_t __objc_forward (id object, SEL sel, arglist_t args);
878 /* Forwarding pointers/integers through the normal registers. */
880 __objc_word_forward (id rcv, SEL op, ...)
884 args = __builtin_apply_args ();
885 res = __objc_forward (rcv, op, args);
887 __builtin_return (res);
892 /* Specific routine for forwarding floats/double because of
893 architectural differences on some processors. i386s for example
894 which uses a floating point stack versus general registers for
895 floating point numbers. This forward routine makes sure that GCC
896 restores the proper return values. */
898 __objc_double_forward (id rcv, SEL op, ...)
902 args = __builtin_apply_args ();
903 res = __objc_forward (rcv, op, args);
904 __builtin_return (res);
907 #if INVISIBLE_STRUCT_RETURN
912 __objc_block_forward (id rcv, SEL op, ...)
916 args = __builtin_apply_args ();
917 res = __objc_forward (rcv, op, args);
919 __builtin_return (res);
921 #if INVISIBLE_STRUCT_RETURN
922 return (__big) {{0, 0, 0, 0, 0, 0, 0, 0}};
929 /* This function is installed in the dispatch table for all methods
930 which are not implemented. Thus, it is called when a selector is
933 __objc_forward (id object, SEL sel, arglist_t args)
936 static SEL frwd_sel = 0; /* !T:SAFE2 */
939 /* First try if the object understands forward::. */
941 frwd_sel = sel_get_any_uid ("forward::");
943 if (__objc_responds_to (object, frwd_sel))
945 imp = get_imp (object->class_pointer, frwd_sel);
946 return (*imp) (object, frwd_sel, sel, args);
949 /* If the object recognizes the doesNotRecognize: method then we're
951 err_sel = sel_get_any_uid ("doesNotRecognize:");
952 if (__objc_responds_to (object, err_sel))
954 imp = get_imp (object->class_pointer, err_sel);
955 return (*imp) (object, err_sel, sel);
958 /* The object doesn't recognize the method. Check for responding to
959 error:. If it does then sent it. */
961 char msg[256 + strlen ((const char *) sel_getName (sel))
962 + strlen ((const char *) object->class_pointer->name)];
964 sprintf (msg, "(%s) %s does not recognize %s",
965 (CLS_ISMETA (object->class_pointer)
968 object->class_pointer->name, sel_getName (sel));
970 /* TODO: support for error: is surely deprecated ? */
971 err_sel = sel_get_any_uid ("error:");
972 if (__objc_responds_to (object, err_sel))
974 imp = get_imp (object->class_pointer, err_sel);
975 return (*imp) (object, sel_get_any_uid ("error:"), msg);
978 /* The object doesn't respond to doesNotRecognize: or error:;
979 Therefore, a default action is taken. */
980 _objc_abort ("%s\n", msg);
987 __objc_print_dtable_stats ()
991 objc_mutex_lock (__objc_runtime_mutex);
994 printf ("memory usage: (%s)\n", "2-level sparse arrays");
996 printf ("memory usage: (%s)\n", "3-level sparse arrays");
999 printf ("arrays: %d = %ld bytes\n", narrays,
1000 (long) ((size_t) narrays * sizeof (struct sarray)));
1001 total += narrays * sizeof (struct sarray);
1002 printf ("buckets: %d = %ld bytes\n", nbuckets,
1003 (long) ((size_t) nbuckets * sizeof (struct sbucket)));
1004 total += nbuckets * sizeof (struct sbucket);
1006 printf ("idxtables: %d = %ld bytes\n",
1007 idxsize, (long) ((size_t) idxsize * sizeof (void *)));
1008 total += idxsize * sizeof (void *);
1009 printf ("-----------------------------------\n");
1010 printf ("total: %d bytes\n", total);
1011 printf ("===================================\n");
1013 objc_mutex_unlock (__objc_runtime_mutex);
1016 /* Returns the uninstalled dispatch table indicator. If a class'
1017 dispatch table points to __objc_uninstalled_dtable then that means
1018 it needs its dispatch table to be installed. */
1020 objc_get_uninstalled_dtable (void)
1022 return __objc_uninstalled_dtable;