]> git.ipfire.org Git - thirdparty/gcc.git/blob - libobjc/sendmsg.c
In libobjc/:
[thirdparty/gcc.git] / libobjc / sendmsg.c
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
5
6 This file is part of GCC.
7
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.
11
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
15 details.
16
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.
20
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/>. */
25
26
27 /* FIXME: This file has no business including tm.h. */
28 /* FIXME: This should be using libffi instead of __builtin_apply
29 and friends. */
30
31 #include "objc-private/common.h"
32 #include "objc-private/error.h"
33 #include "tconfig.h"
34 #include "coretypes.h"
35 #include "tm.h"
36 #include "objc/objc-api.h"
37 #include "objc/thr.h"
38 #include "objc-private/runtime.h"
39 #include "objc-private/sarray.h"
40 #include "objc/encoding.h"
41 #include "runtime-info.h"
42 #include <assert.h> /* For assert */
43 #include <string.h> /* For strlen */
44
45 /* Temporarily while we include objc/objc-api.h instead of objc-private/module-abi-8.h. */
46 #define _CLS_IN_CONSTRUCTION 0x10L
47 #define CLS_IS_IN_CONSTRUCTION(cls) __CLS_ISINFO(cls, _CLS_IN_CONSTRUCTION)
48
49 /* This is how we hack STRUCT_VALUE to be 1 or 0. */
50 #define gen_rtx(args...) 1
51 #define gen_rtx_MEM(args...) 1
52 #define gen_rtx_REG(args...) 1
53 /* Alread defined in gcc/coretypes.h. So prevent double definition warning. */
54 #undef rtx
55 #define rtx int
56
57 #if ! defined (STRUCT_VALUE) || STRUCT_VALUE == 0
58 #define INVISIBLE_STRUCT_RETURN 1
59 #else
60 #define INVISIBLE_STRUCT_RETURN 0
61 #endif
62
63 /* The uninstalled dispatch table */
64 struct sarray *__objc_uninstalled_dtable = 0; /* !T:MUTEX */
65
66 /* Two hooks for method forwarding. If either is set, it is invoked
67 * to return a function that performs the real forwarding. If both
68 * are set, the result of __objc_msg_forward2 will be preferred over
69 * that of __objc_msg_forward. If both return NULL or are unset,
70 * the libgcc based functions (__builtin_apply and friends) are
71 * used.
72 */
73 IMP (*__objc_msg_forward) (SEL) = NULL;
74 IMP (*__objc_msg_forward2) (id, SEL) = NULL;
75
76 /* Send +initialize to class */
77 static void __objc_send_initialize (Class);
78
79 static void __objc_install_dispatch_table_for_class (Class);
80
81 /* Forward declare some functions */
82 static void __objc_init_install_dtable (id, SEL);
83
84 /* Various forwarding functions that are used based upon the
85 return type for the selector.
86 __objc_block_forward for structures.
87 __objc_double_forward for floats/doubles.
88 __objc_word_forward for pointers or types that fit in registers. */
89 static double __objc_double_forward (id, SEL, ...);
90 static id __objc_word_forward (id, SEL, ...);
91 typedef struct { id many[8]; } __big;
92 #if INVISIBLE_STRUCT_RETURN
93 static __big
94 #else
95 static id
96 #endif
97 __objc_block_forward (id, SEL, ...);
98 static struct objc_method * search_for_method_in_hierarchy (Class class, SEL sel);
99 struct objc_method * search_for_method_in_list (struct objc_method_list * list, SEL op);
100 id nil_method (id, SEL);
101
102 /* Given a selector, return the proper forwarding implementation. */
103 inline
104 IMP
105 __objc_get_forward_imp (id rcv, SEL sel)
106 {
107 /* If a custom forwarding hook was registered, try getting a forwarding
108 function from it. There are two forward routine hooks, one that
109 takes the receiver as an argument and one that does not. */
110 if (__objc_msg_forward2)
111 {
112 IMP result;
113 if ((result = __objc_msg_forward2 (rcv, sel)) != NULL)
114 return result;
115 }
116 if (__objc_msg_forward)
117 {
118 IMP result;
119 if ((result = __objc_msg_forward (sel)) != NULL)
120 return result;
121 }
122
123 /* In all other cases, use the default forwarding functions built using
124 __builtin_apply and friends. */
125 {
126 const char *t = sel->sel_types;
127
128 if (t && (*t == '[' || *t == '(' || *t == '{')
129 #ifdef OBJC_MAX_STRUCT_BY_VALUE
130 && objc_sizeof_type (t) > OBJC_MAX_STRUCT_BY_VALUE
131 #endif
132 )
133 return (IMP)__objc_block_forward;
134 else if (t && (*t == 'f' || *t == 'd'))
135 return (IMP)__objc_double_forward;
136 else
137 return (IMP)__objc_word_forward;
138 }
139 }
140
141 /* Given a class and selector, return the selector's implementation. */
142 inline
143 IMP
144 get_imp (Class class, SEL sel)
145 {
146 /* In a vanilla implementation we would first check if the dispatch
147 table is installed. Here instead, to get more speed in the
148 standard case (that the dispatch table is installed) we first try
149 to get the imp using brute force. Only if that fails, we do what
150 we should have been doing from the very beginning, that is, check
151 if the dispatch table needs to be installed, install it if it's
152 not installed, and retrieve the imp from the table if it's
153 installed. */
154 void *res = sarray_get_safe (class->dtable, (size_t) sel->sel_id);
155 if (res == 0)
156 {
157 /* Not a valid method */
158 if (class->dtable == __objc_uninstalled_dtable)
159 {
160 /* The dispatch table needs to be installed. */
161 objc_mutex_lock (__objc_runtime_mutex);
162
163 /* Double-checked locking pattern: Check
164 __objc_uninstalled_dtable again in case another thread
165 installed the dtable while we were waiting for the lock
166 to be released. */
167 if (class->dtable == __objc_uninstalled_dtable)
168 {
169 __objc_install_dispatch_table_for_class (class);
170 }
171
172 objc_mutex_unlock (__objc_runtime_mutex);
173 /* Call ourselves with the installed dispatch table
174 and get the real method */
175 res = get_imp (class, sel);
176 }
177 else
178 {
179 /* The dispatch table has been installed. */
180
181 /* Get the method from the dispatch table (we try to get it
182 again in case another thread has installed the dtable just
183 after we invoked sarray_get_safe, but before we checked
184 class->dtable == __objc_uninstalled_dtable).
185 */
186 res = sarray_get_safe (class->dtable, (size_t) sel->sel_id);
187 if (res == 0)
188 {
189 /* The dispatch table has been installed, and the method
190 is not in the dispatch table. So the method just
191 doesn't exist for the class. Return the forwarding
192 implementation. */
193 res = __objc_get_forward_imp ((id)class, sel);
194 }
195 }
196 }
197 return res;
198 }
199
200 /* The new name of get_imp(). */
201 IMP
202 class_getMethodImplementation (Class class_, SEL selector)
203 {
204 if (class_ == Nil || selector == NULL)
205 return NULL;
206
207 /* get_imp is inlined, so we're good. */
208 return get_imp (class_, selector);
209 }
210
211 /* Given a method, return its implementation. */
212 IMP
213 method_get_imp (struct objc_method * method)
214 {
215 return (method != (struct objc_method *)0) ? method->method_imp : (IMP)0;
216 }
217
218 /* Query if an object can respond to a selector, returns YES if the
219 object implements the selector otherwise NO. Does not check if the
220 method can be forwarded. */
221 inline
222 BOOL
223 __objc_responds_to (id object, SEL sel)
224 {
225 void *res;
226
227 /* Install dispatch table if need be */
228 if (object->class_pointer->dtable == __objc_uninstalled_dtable)
229 {
230 objc_mutex_lock (__objc_runtime_mutex);
231 if (object->class_pointer->dtable == __objc_uninstalled_dtable)
232 {
233 __objc_install_dispatch_table_for_class (object->class_pointer);
234 }
235 objc_mutex_unlock (__objc_runtime_mutex);
236 }
237
238 /* Get the method from the dispatch table */
239 res = sarray_get_safe (object->class_pointer->dtable, (size_t) sel->sel_id);
240 return (res != 0);
241 }
242
243 BOOL
244 class_respondsToSelector (Class class_, SEL selector)
245 {
246 void *res;
247
248 if (class_ == Nil || selector == NULL)
249 return NO;
250
251 /* Install dispatch table if need be */
252 if (class_->dtable == __objc_uninstalled_dtable)
253 {
254 objc_mutex_lock (__objc_runtime_mutex);
255 if (class_->dtable == __objc_uninstalled_dtable)
256 {
257 __objc_install_dispatch_table_for_class (class_);
258 }
259 objc_mutex_unlock (__objc_runtime_mutex);
260 }
261
262 /* Get the method from the dispatch table */
263 res = sarray_get_safe (class_->dtable, (size_t) selector->sel_id);
264 return (res != 0);
265 }
266
267 /* This is the lookup function. All entries in the table are either a
268 valid method *or* zero. If zero then either the dispatch table
269 needs to be installed or it doesn't exist and forwarding is attempted. */
270
271 IMP
272 objc_msg_lookup (id receiver, SEL op)
273 {
274 IMP result;
275 if (receiver)
276 {
277 result = sarray_get_safe (receiver->class_pointer->dtable,
278 (sidx)op->sel_id);
279 if (result == 0)
280 {
281 /* Not a valid method */
282 if (receiver->class_pointer->dtable == __objc_uninstalled_dtable)
283 {
284 /* The dispatch table needs to be installed.
285 This happens on the very first method call to the class. */
286 __objc_init_install_dtable (receiver, op);
287
288 /* Get real method for this in newly installed dtable */
289 result = get_imp (receiver->class_pointer, op);
290 }
291 else
292 {
293 /* The dispatch table has been installed. Check again
294 if the method exists (just in case the dispatch table
295 has been installed by another thread after we did the
296 previous check that the method exists).
297 */
298 result = sarray_get_safe (receiver->class_pointer->dtable,
299 (sidx)op->sel_id);
300 if (result == 0)
301 {
302 /* If the method still just doesn't exist for the
303 class, attempt to forward the method. */
304 result = __objc_get_forward_imp (receiver, op);
305 }
306 }
307 }
308 return result;
309 }
310 else
311 return (IMP)nil_method;
312 }
313
314 IMP
315 objc_msg_lookup_super (Super_t super, SEL sel)
316 {
317 if (super->self)
318 return get_imp (super->class, sel);
319 else
320 return (IMP)nil_method;
321 }
322
323 int method_get_sizeof_arguments (Method *);
324
325 retval_t
326 objc_msg_sendv (id object, SEL op, arglist_t arg_frame)
327 {
328 Method *m = class_get_instance_method (object->class_pointer, op);
329 const char *type;
330 *((id *) method_get_first_argument (m, arg_frame, &type)) = object;
331 *((SEL *) method_get_next_argument (arg_frame, &type)) = op;
332 return __builtin_apply ((apply_t) m->method_imp,
333 arg_frame,
334 method_get_sizeof_arguments (m));
335 }
336
337 void
338 __objc_init_dispatch_tables ()
339 {
340 __objc_uninstalled_dtable = sarray_new (200, 0);
341 }
342
343 /* This function is called by objc_msg_lookup when the
344 dispatch table needs to be installed; thus it is called once
345 for each class, namely when the very first message is sent to it. */
346 static void
347 __objc_init_install_dtable (id receiver, SEL op __attribute__ ((__unused__)))
348 {
349 objc_mutex_lock (__objc_runtime_mutex);
350
351 /* This may happen, if the programmer has taken the address of a
352 method before the dtable was initialized... too bad for him! */
353 if (receiver->class_pointer->dtable != __objc_uninstalled_dtable)
354 {
355 objc_mutex_unlock (__objc_runtime_mutex);
356 return;
357 }
358
359 if (CLS_ISCLASS (receiver->class_pointer))
360 {
361 /* receiver is an ordinary object */
362 assert (CLS_ISCLASS (receiver->class_pointer));
363
364 /* install instance methods table */
365 __objc_install_dispatch_table_for_class (receiver->class_pointer);
366
367 /* call +initialize -- this will in turn install the factory
368 dispatch table if not already done :-) */
369 __objc_send_initialize (receiver->class_pointer);
370 }
371 else
372 {
373 /* receiver is a class object */
374 assert (CLS_ISCLASS ((Class)receiver));
375 assert (CLS_ISMETA (receiver->class_pointer));
376
377 /* Install real dtable for factory methods */
378 __objc_install_dispatch_table_for_class (receiver->class_pointer);
379
380 __objc_send_initialize ((Class)receiver);
381 }
382 objc_mutex_unlock (__objc_runtime_mutex);
383 }
384
385 /* Install dummy table for class which causes the first message to
386 that class (or instances hereof) to be initialized properly */
387 void
388 __objc_install_premature_dtable (Class class)
389 {
390 assert (__objc_uninstalled_dtable);
391 class->dtable = __objc_uninstalled_dtable;
392 }
393
394 /* Send +initialize to class if not already done */
395 static void
396 __objc_send_initialize (Class class)
397 {
398 /* This *must* be a class object */
399 assert (CLS_ISCLASS (class));
400 assert (! CLS_ISMETA (class));
401
402 if (! CLS_ISINITIALIZED (class))
403 {
404 CLS_SETINITIALIZED (class);
405 CLS_SETINITIALIZED (class->class_pointer);
406
407 /* Create the garbage collector type memory description */
408 __objc_generate_gc_type_description (class);
409
410 if (class->super_class)
411 __objc_send_initialize (class->super_class);
412
413 {
414 SEL op = sel_register_name ("initialize");
415 IMP imp = 0;
416 struct objc_method_list * method_list = class->class_pointer->methods;
417
418 while (method_list) {
419 int i;
420 struct objc_method * method;
421
422 for (i = 0; i < method_list->method_count; i++) {
423 method = &(method_list->method_list[i]);
424 if (method->method_name
425 && method->method_name->sel_id == op->sel_id) {
426 imp = method->method_imp;
427 break;
428 }
429 }
430
431 if (imp)
432 break;
433
434 method_list = method_list->method_next;
435
436 }
437 if (imp)
438 (*imp) ((id) class, op);
439
440 }
441 }
442 }
443
444 /* Walk on the methods list of class and install the methods in the reverse
445 order of the lists. Since methods added by categories are before the methods
446 of class in the methods list, this allows categories to substitute methods
447 declared in class. However if more than one category replaces the same
448 method nothing is guaranteed about what method will be used.
449 Assumes that __objc_runtime_mutex is locked down. */
450 static void
451 __objc_install_methods_in_dtable (Class class, struct objc_method_list * method_list)
452 {
453 int i;
454
455 if (! method_list)
456 return;
457
458 if (method_list->method_next)
459 __objc_install_methods_in_dtable (class, method_list->method_next);
460
461 for (i = 0; i < method_list->method_count; i++)
462 {
463 struct objc_method * method = &(method_list->method_list[i]);
464 sarray_at_put_safe (class->dtable,
465 (sidx) method->method_name->sel_id,
466 method->method_imp);
467 }
468 }
469
470 /* Assumes that __objc_runtime_mutex is locked down. */
471 static void
472 __objc_install_dispatch_table_for_class (Class class)
473 {
474 Class super;
475
476 /* If the class has not yet had its class links resolved, we must
477 re-compute all class links */
478 if (! CLS_ISRESOLV (class))
479 __objc_resolve_class_links ();
480
481 super = class->super_class;
482
483 if (super != 0 && (super->dtable == __objc_uninstalled_dtable))
484 __objc_install_dispatch_table_for_class (super);
485
486 /* Allocate dtable if necessary */
487 if (super == 0)
488 {
489 objc_mutex_lock (__objc_runtime_mutex);
490 class->dtable = sarray_new (__objc_selector_max_index, 0);
491 objc_mutex_unlock (__objc_runtime_mutex);
492 }
493 else
494 class->dtable = sarray_lazy_copy (super->dtable);
495
496 __objc_install_methods_in_dtable (class, class->methods);
497 }
498
499 void
500 __objc_update_dispatch_table_for_class (Class class)
501 {
502 Class next;
503 struct sarray *arr;
504
505 /* not yet installed -- skip it */
506 if (class->dtable == __objc_uninstalled_dtable)
507 return;
508
509 objc_mutex_lock (__objc_runtime_mutex);
510
511 arr = class->dtable;
512 __objc_install_premature_dtable (class); /* someone might require it... */
513 sarray_free (arr); /* release memory */
514
515 /* could have been lazy... */
516 __objc_install_dispatch_table_for_class (class);
517
518 if (class->subclass_list) /* Traverse subclasses */
519 for (next = class->subclass_list; next; next = next->sibling_class)
520 __objc_update_dispatch_table_for_class (next);
521
522 objc_mutex_unlock (__objc_runtime_mutex);
523 }
524
525
526 /* This function adds a method list to a class. This function is
527 typically called by another function specific to the run-time. As
528 such this function does not worry about thread safe issues.
529
530 This one is only called for categories. Class objects have their
531 methods installed right away, and their selectors are made into
532 SEL's by the function __objc_register_selectors_from_class. */
533 void
534 class_add_method_list (Class class, struct objc_method_list * list)
535 {
536 /* Passing of a linked list is not allowed. Do multiple calls. */
537 assert (! list->method_next);
538
539 __objc_register_selectors_from_list(list);
540
541 /* Add the methods to the class's method list. */
542 list->method_next = class->methods;
543 class->methods = list;
544
545 /* Update the dispatch table of class */
546 __objc_update_dispatch_table_for_class (class);
547 }
548
549 struct objc_method *
550 class_get_instance_method (Class class, SEL op)
551 {
552 return search_for_method_in_hierarchy (class, op);
553 }
554
555 struct objc_method *
556 class_get_class_method (MetaClass class, SEL op)
557 {
558 return search_for_method_in_hierarchy (class, op);
559 }
560
561 struct objc_method *
562 class_getInstanceMethod (Class class_, SEL selector)
563 {
564 if (class_ == Nil || selector == NULL)
565 return NULL;
566
567 return search_for_method_in_hierarchy (class_, selector);
568 }
569
570 struct objc_method *
571 class_getClassMethod (Class class_, SEL selector)
572 {
573 if (class_ == Nil || selector == NULL)
574 return NULL;
575
576 return search_for_method_in_hierarchy (class_->class_pointer,
577 selector);
578 }
579
580 BOOL
581 class_addMethod (Class class_, SEL selector, IMP implementation,
582 const char *method_types)
583 {
584 struct objc_method_list *method_list;
585 struct objc_method *method;
586 const char *method_name;
587
588 if (class_ == Nil || selector == NULL || implementation == NULL
589 || method_types == NULL || (strcmp (method_types, "") == 0))
590 return NO;
591
592 method_name = sel_get_name (selector);
593 if (method_name == NULL)
594 return NO;
595
596 method_list = (struct objc_method_list *)objc_calloc (1, sizeof (struct objc_method_list));
597 method_list->method_count = 1;
598
599 method = &(method_list->method_list[0]);
600 method->method_name = objc_malloc (strlen (method_name) + 1);
601 strcpy ((char *)method->method_name, method_name);
602
603 method->method_types = objc_malloc (strlen (method_types) + 1);
604 strcpy ((char *)method->method_types, method_types);
605
606 method->method_imp = implementation;
607
608 if (CLS_IS_IN_CONSTRUCTION (class_))
609 {
610 /* We only need to add the method to the list. It will be
611 registered with the runtime when the class pair is registered
612 (if ever). */
613 method_list->method_next = class_->methods;
614 class_->methods = method_list;
615 }
616 else
617 {
618 /* Add the method to a live class. */
619 objc_mutex_lock (__objc_runtime_mutex);
620 class_add_method_list (class_, method_list);
621 objc_mutex_unlock (__objc_runtime_mutex);
622 }
623
624 return YES;
625 }
626
627 /* Temporarily, until we include objc/runtime.h. */
628 extern IMP
629 method_setImplementation (struct objc_method * method, IMP implementation);
630
631 IMP
632 class_replaceMethod (Class class_, SEL selector, IMP implementation,
633 const char *method_types)
634 {
635 struct objc_method * method;
636
637 if (class_ == Nil || selector == NULL || implementation == NULL
638 || method_types == NULL)
639 return NULL;
640
641 method = search_for_method_in_hierarchy (class_, selector);
642
643 if (method)
644 {
645 return method_setImplementation (method, implementation);
646 }
647 else
648 {
649 class_addMethod (class_, selector, implementation, method_types);
650 return NULL;
651 }
652 }
653
654 /* Search for a method starting from the current class up its hierarchy.
655 Return a pointer to the method's method structure if found. NULL
656 otherwise. */
657 static struct objc_method *
658 search_for_method_in_hierarchy (Class cls, SEL sel)
659 {
660 struct objc_method * method = NULL;
661 Class class;
662
663 if (! sel_is_mapped (sel))
664 return NULL;
665
666 /* Scan the method list of the class. If the method isn't found in the
667 list then step to its super class. */
668 for (class = cls; ((! method) && class); class = class->super_class)
669 method = search_for_method_in_list (class->methods, sel);
670
671 return method;
672 }
673
674
675
676 /* Given a linked list of method and a method's name. Search for the named
677 method's method structure. Return a pointer to the method's method
678 structure if found. NULL otherwise. */
679 struct objc_method *
680 search_for_method_in_list (struct objc_method_list * list, SEL op)
681 {
682 struct objc_method_list * method_list = list;
683
684 if (! sel_is_mapped (op))
685 return NULL;
686
687 /* If not found then we'll search the list. */
688 while (method_list)
689 {
690 int i;
691
692 /* Search the method list. */
693 for (i = 0; i < method_list->method_count; ++i)
694 {
695 struct objc_method * method = &method_list->method_list[i];
696
697 if (method->method_name)
698 if (method->method_name->sel_id == op->sel_id)
699 return method;
700 }
701
702 /* The method wasn't found. Follow the link to the next list of
703 methods. */
704 method_list = method_list->method_next;
705 }
706
707 return NULL;
708 }
709
710 static retval_t __objc_forward (id object, SEL sel, arglist_t args);
711
712 /* Forwarding pointers/integers through the normal registers */
713 static id
714 __objc_word_forward (id rcv, SEL op, ...)
715 {
716 void *args, *res;
717
718 args = __builtin_apply_args ();
719 res = __objc_forward (rcv, op, args);
720 if (res)
721 __builtin_return (res);
722 else
723 return res;
724 }
725
726 /* Specific routine for forwarding floats/double because of
727 architectural differences on some processors. i386s for
728 example which uses a floating point stack versus general
729 registers for floating point numbers. This forward routine
730 makes sure that GCC restores the proper return values */
731 static double
732 __objc_double_forward (id rcv, SEL op, ...)
733 {
734 void *args, *res;
735
736 args = __builtin_apply_args ();
737 res = __objc_forward (rcv, op, args);
738 __builtin_return (res);
739 }
740
741 #if INVISIBLE_STRUCT_RETURN
742 static __big
743 #else
744 static id
745 #endif
746 __objc_block_forward (id rcv, SEL op, ...)
747 {
748 void *args, *res;
749
750 args = __builtin_apply_args ();
751 res = __objc_forward (rcv, op, args);
752 if (res)
753 __builtin_return (res);
754 else
755 #if INVISIBLE_STRUCT_RETURN
756 return (__big) {{0, 0, 0, 0, 0, 0, 0, 0}};
757 #else
758 return nil;
759 #endif
760 }
761
762
763 /* This function is installed in the dispatch table for all methods which are
764 not implemented. Thus, it is called when a selector is not recognized. */
765 static retval_t
766 __objc_forward (id object, SEL sel, arglist_t args)
767 {
768 IMP imp;
769 static SEL frwd_sel = 0; /* !T:SAFE2 */
770 SEL err_sel;
771
772 /* first try if the object understands forward:: */
773 if (! frwd_sel)
774 frwd_sel = sel_get_any_uid ("forward::");
775
776 if (__objc_responds_to (object, frwd_sel))
777 {
778 imp = get_imp (object->class_pointer, frwd_sel);
779 return (*imp) (object, frwd_sel, sel, args);
780 }
781
782 /* If the object recognizes the doesNotRecognize: method then we're going
783 to send it. */
784 err_sel = sel_get_any_uid ("doesNotRecognize:");
785 if (__objc_responds_to (object, err_sel))
786 {
787 imp = get_imp (object->class_pointer, err_sel);
788 return (*imp) (object, err_sel, sel);
789 }
790
791 /* The object doesn't recognize the method. Check for responding to
792 error:. If it does then sent it. */
793 {
794 char msg[256 + strlen ((const char *) sel_get_name (sel))
795 + strlen ((const char *) object->class_pointer->name)];
796
797 sprintf (msg, "(%s) %s does not recognize %s",
798 (CLS_ISMETA (object->class_pointer)
799 ? "class"
800 : "instance" ),
801 object->class_pointer->name, sel_get_name (sel));
802
803 /* TODO: support for error: is surely deprecated ? */
804 err_sel = sel_get_any_uid ("error:");
805 if (__objc_responds_to (object, err_sel))
806 {
807 imp = get_imp (object->class_pointer, err_sel);
808 return (*imp) (object, sel_get_any_uid ("error:"), msg);
809 }
810
811 /* The object doesn't respond to doesNotRecognize: or error:; Therefore,
812 a default action is taken. */
813 _objc_abort ("%s\n", msg);
814
815 return 0;
816 }
817 }
818
819 void
820 __objc_print_dtable_stats ()
821 {
822 int total = 0;
823
824 objc_mutex_lock (__objc_runtime_mutex);
825
826 #ifdef OBJC_SPARSE2
827 printf ("memory usage: (%s)\n", "2-level sparse arrays");
828 #else
829 printf ("memory usage: (%s)\n", "3-level sparse arrays");
830 #endif
831
832 printf ("arrays: %d = %ld bytes\n", narrays,
833 (long) ((size_t) narrays * sizeof (struct sarray)));
834 total += narrays * sizeof (struct sarray);
835 printf ("buckets: %d = %ld bytes\n", nbuckets,
836 (long) ((size_t) nbuckets * sizeof (struct sbucket)));
837 total += nbuckets * sizeof (struct sbucket);
838
839 printf ("idxtables: %d = %ld bytes\n",
840 idxsize, (long) ((size_t) idxsize * sizeof (void *)));
841 total += idxsize * sizeof (void *);
842 printf ("-----------------------------------\n");
843 printf ("total: %d bytes\n", total);
844 printf ("===================================\n");
845
846 objc_mutex_unlock (__objc_runtime_mutex);
847 }
848
849 /* Returns the uninstalled dispatch table indicator.
850 If a class' dispatch table points to __objc_uninstalled_dtable
851 then that means it needs its dispatch table to be installed. */
852
853 struct sarray *
854 objc_get_uninstalled_dtable ()
855 {
856 return __objc_uninstalled_dtable;
857 }