Initial revision
[official-gcc.git] / gcc / objc / init.c
blob5e56146c42341c9b6eb2be22505737698e3fcc0a
1 /* GNU Objective C Runtime initialization
2 Copyright (C) 1993, 1995, 1996, 1997 Free Software Foundation, Inc.
3 Contributed by Kresten Krab Thorup
4 +load support contributed by Ovidiu Predescu <ovidiu@net-community.com>
6 This file is part of GNU CC.
8 GNU CC 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 2, or (at your option) any later version.
12 GNU CC 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.
17 You should have received a copy of the GNU General Public License along with
18 GNU CC; see the file COPYING. If not, write to the Free Software
19 Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
21 /* As a special exception, if you link this library with files compiled with
22 GCC to produce an executable, this does not cause the resulting executable
23 to be covered by the GNU General Public License. This exception does not
24 however invalidate any other reasons why the executable file might be
25 covered by the GNU General Public License. */
27 #include "runtime.h"
29 /* The version number of this runtime. This must match the number
30 defined in gcc (objc-act.c) */
31 #define OBJC_VERSION 8
32 #define PROTOCOL_VERSION 2
34 /* This list contains all modules currently loaded into the runtime */
35 static struct objc_list* __objc_module_list = 0; /* !T:MUTEX */
37 /* This list contains all proto_list's not yet assigned class links */
38 static struct objc_list* unclaimed_proto_list = 0; /* !T:MUTEX */
40 /* List of unresolved static instances. */
41 static struct objc_list *uninitialized_statics = 0; /* !T:MUTEX */
43 /* Global runtime "write" mutex. */
44 objc_mutex_t __objc_runtime_mutex = 0;
46 /* Number of threads that are alive. */
47 int __objc_runtime_threads_alive = 1; /* !T:MUTEX */
49 /* Check compiler vs runtime version */
50 static void init_check_module_version (Module_t);
52 /* Assign isa links to protos */
53 static void __objc_init_protocols (struct objc_protocol_list* protos);
55 /* Add protocol to class */
56 static void __objc_class_add_protocols (Class, struct objc_protocol_list*);
58 /* This is a hook which is called by __objc_exec_class every time a class
59 or a category is loaded into the runtime. This may e.g. help a
60 dynamic loader determine the classes that have been loaded when
61 an object file is dynamically linked in */
62 void (*_objc_load_callback)(Class class, Category* category) = 0; /* !T:SAFE */
64 /* Is all categories/classes resolved? */
65 BOOL __objc_dangling_categories = NO; /* !T:UNUSED */
67 extern SEL
68 __sel_register_typed_name (const char *name, const char *types,
69 struct objc_selector *orig, BOOL is_const);
71 /* Sends +load to all classes and categories in certain situations. */
72 static void objc_send_load (void);
74 /* Inserts all the classes defined in module in a tree of classes that
75 resembles the class hierarchy. This tree is traversed in preorder and the
76 classes in its nodes receive the +load message if these methods were not
77 executed before. The algorithm ensures that when the +load method of a class
78 is executed all the superclasses have been already received the +load
79 message. */
80 static void __objc_create_classes_tree (Module_t module);
82 static void __objc_call_callback (Module_t module);
84 /* A special version that works only before the classes are completely
85 installed in the runtime. */
86 static BOOL class_is_subclass_of_class (Class class, Class superclass);
88 typedef struct objc_class_tree {
89 Class class;
90 struct objc_list *subclasses; /* `head' is pointer to an objc_class_tree */
91 } objc_class_tree;
93 /* This is a linked list of objc_class_tree trees. The head of these trees
94 are root classes (their super class is Nil). These different trees
95 represent different class hierarchies. */
96 static struct objc_list *__objc_class_tree_list = NULL;
98 /* Keeps the +load methods who have been already executed. This hash should
99 not be destroyed during the execution of the program. */
100 static cache_ptr __objc_load_methods = NULL;
102 /* Creates a tree of classes whose topmost class is directly inherited from
103 `upper' and the bottom class in this tree is `bottom_class'. The classes
104 in this tree are super classes of `bottom_class'. `subclasses' member
105 of each tree node point to the next subclass tree node. */
106 static objc_class_tree *
107 create_tree_of_subclasses_inherited_from (Class bottom_class, Class upper)
109 Class superclass = bottom_class->super_class ?
110 objc_lookup_class ((char*)bottom_class->super_class)
111 : Nil;
113 objc_class_tree *tree, *prev;
115 DEBUG_PRINTF ("create_tree_of_subclasses_inherited_from:");
116 DEBUG_PRINTF ("bottom_class = %s, upper = %s\n",
117 (bottom_class ? bottom_class->name : NULL),
118 (upper ? upper->name : NULL));
120 tree = prev = objc_calloc (1, sizeof (objc_class_tree));
121 prev->class = bottom_class;
123 while (superclass != upper)
125 tree = objc_calloc (1, sizeof (objc_class_tree));
126 tree->class = superclass;
127 tree->subclasses = list_cons (prev, tree->subclasses);
128 superclass = (superclass->super_class ?
129 objc_lookup_class ((char*)superclass->super_class)
130 : Nil);
131 prev = tree;
134 return tree;
137 /* Insert the `class' into the proper place in the `tree' class hierarchy. This
138 function returns a new tree if the class has been successfully inserted into
139 the tree or NULL if the class is not part of the classes hierarchy described
140 by `tree'. This function is private to objc_tree_insert_class(), you should
141 not call it directly. */
142 static objc_class_tree *
143 __objc_tree_insert_class (objc_class_tree *tree, Class class)
145 DEBUG_PRINTF ("__objc_tree_insert_class: tree = %x, class = %s\n",
146 tree, class->name);
148 if (tree == NULL)
149 return create_tree_of_subclasses_inherited_from (class, NULL);
150 else if (class == tree->class)
152 /* `class' has been already inserted */
153 DEBUG_PRINTF ("1. class %s was previously inserted\n", class->name);
154 return tree;
156 else if ((class->super_class ?
157 objc_lookup_class ((char*)class->super_class)
158 : Nil)
159 == tree->class)
161 /* If class is a direct subclass of tree->class then add class to the
162 list of subclasses. First check to see if it wasn't already
163 inserted. */
164 struct objc_list *list = tree->subclasses;
165 objc_class_tree *node;
167 while (list)
169 /* Class has been already inserted; do nothing just return
170 the tree. */
171 if (((objc_class_tree*)list->head)->class == class)
173 DEBUG_PRINTF ("2. class %s was previously inserted\n",
174 class->name);
175 return tree;
177 list = list->tail;
180 /* Create a new node class and insert it into the list of subclasses */
181 node = objc_calloc (1, sizeof (objc_class_tree));
182 node->class = class;
183 tree->subclasses = list_cons (node, tree->subclasses);
184 DEBUG_PRINTF ("3. class %s inserted\n", class->name);
185 return tree;
187 else
189 /* The class is not a direct subclass of tree->class. Search for class's
190 superclasses in the list of subclasses. */
191 struct objc_list *subclasses = tree->subclasses;
193 /* Precondition: the class must be a subclass of tree->class; otherwise
194 return NULL to indicate our caller that it must take the next tree. */
195 if (!class_is_subclass_of_class (class, tree->class))
196 return NULL;
198 for (; subclasses != NULL; subclasses = subclasses->tail)
200 Class aClass = ((objc_class_tree*)(subclasses->head))->class;
202 if (class_is_subclass_of_class (class, aClass))
204 /* If we found one of class's superclasses we insert the class
205 into its subtree and return the original tree since nothing
206 has been changed. */
207 subclasses->head
208 = __objc_tree_insert_class (subclasses->head, class);
209 DEBUG_PRINTF ("4. class %s inserted\n", class->name);
210 return tree;
214 /* We haven't found a subclass of `class' in the `subclasses' list.
215 Create a new tree of classes whose topmost class is a direct subclass
216 of tree->class. */
218 objc_class_tree *new_tree
219 = create_tree_of_subclasses_inherited_from (class, tree->class);
220 tree->subclasses = list_cons (new_tree, tree->subclasses);
221 DEBUG_PRINTF ("5. class %s inserted\n", class->name);
222 return tree;
227 /* This function inserts `class' in the right tree hierarchy classes. */
228 static void
229 objc_tree_insert_class (Class class)
231 struct objc_list *list_node;
232 objc_class_tree *tree;
234 list_node = __objc_class_tree_list;
235 while (list_node)
237 tree = __objc_tree_insert_class (list_node->head, class);
238 if (tree)
240 list_node->head = tree;
241 break;
243 else
244 list_node = list_node->tail;
247 /* If the list was finished but the class hasn't been inserted, insert it
248 here. */
249 if (!list_node)
251 __objc_class_tree_list = list_cons (NULL, __objc_class_tree_list);
252 __objc_class_tree_list->head = __objc_tree_insert_class (NULL, class);
256 /* Traverse tree in preorder. Used to send +load. */
257 static void
258 objc_preorder_traverse (objc_class_tree *tree,
259 int level,
260 void (*function)(objc_class_tree*, int))
262 struct objc_list *node;
264 (*function) (tree, level);
265 for (node = tree->subclasses; node; node = node->tail)
266 objc_preorder_traverse (node->head, level + 1, function);
269 /* Traverse tree in postorder. Used to destroy a tree. */
270 static void
271 objc_postorder_traverse (objc_class_tree *tree,
272 int level,
273 void (*function)(objc_class_tree*, int))
275 struct objc_list *node;
277 for (node = tree->subclasses; node; node = node->tail)
278 objc_postorder_traverse (node->head, level + 1, function);
279 (*function) (tree, level);
282 /* Used to print a tree class hierarchy. */
283 static void
284 __objc_tree_print (objc_class_tree *tree, int level)
286 int i;
288 for (i = 0; i < level; i++)
289 printf (" ");
290 printf ("%s\n", tree->class->name);
293 /* Walks on a linked list of methods in the reverse order and executes all
294 the methods corresponding to `op' selector. Walking in the reverse order
295 assures the +load of class is executed first and then +load of categories
296 because of the way in which categories are added to the class methods. */
297 static void
298 __objc_send_message_in_list (MethodList_t method_list, Class class, SEL op)
300 int i;
302 if (!method_list)
303 return;
305 /* First execute the `op' message in the following method lists */
306 __objc_send_message_in_list (method_list->method_next, class, op);
308 /* Search the method list. */
309 for (i = 0; i < method_list->method_count; i++)
311 Method_t mth = &method_list->method_list[i];
313 if (mth->method_name && sel_eq (mth->method_name, op)
314 && !hash_is_key_in_hash (__objc_load_methods, mth->method_name))
316 /* The method was found and wasn't previously executed. */
317 (*mth->method_imp) ((id)class, mth->method_name);
319 /* Add this method into the +load hash table */
320 hash_add (&__objc_load_methods, mth->method_imp, mth->method_imp);
322 DEBUG_PRINTF ("sending +load in class: %s\n", class->name);
324 break;
329 static void
330 __objc_send_load (objc_class_tree *tree, int level)
332 static SEL load_sel = 0;
333 Class class = tree->class;
334 MethodList_t method_list = class->class_pointer->methods;
336 if (!load_sel)
337 load_sel = sel_register_name ("load");
339 __objc_send_message_in_list (method_list, class, load_sel);
342 static void
343 __objc_destroy_class_tree_node (objc_class_tree *tree, int level)
345 objc_free (tree);
348 /* This is used to check if the relationship between two classes before the
349 runtime completely installs the classes. */
350 static BOOL
351 class_is_subclass_of_class (Class class, Class superclass)
353 for (; class != Nil;)
355 if (class == superclass)
356 return YES;
357 class = (class->super_class ?
358 objc_lookup_class ((char*)class->super_class)
359 : Nil);
362 return NO;
365 /* This list contains all the classes in the runtime system for whom their
366 superclasses are not yet know to the runtime. */
367 static struct objc_list* unresolved_classes = 0;
369 /* Static function used to reference the Object and NXConstantString classes.
371 static void
372 __objc_force_linking (void)
374 extern void __objc_linking (void);
375 __objc_linking ();
377 /* Call the function to avoid compiler warning */
378 __objc_force_linking ();
381 /* Run through the statics list, removing modules as soon as all its statics
382 have been initialized. */
383 static void
384 objc_init_statics ()
386 struct objc_list **cell = &uninitialized_statics;
387 struct objc_static_instances **statics_in_module;
389 objc_mutex_lock(__objc_runtime_mutex);
391 while (*cell)
393 int module_initialized = 1;
395 for (statics_in_module = (*cell)->head;
396 *statics_in_module; statics_in_module++)
398 struct objc_static_instances *statics = *statics_in_module;
399 Class class = objc_lookup_class (statics->class_name);
401 if (!class)
402 module_initialized = 0;
403 /* Actually, the static's class_pointer will be NULL when we
404 haven't been here before. However, the comparison is to be
405 reminded of taking into account class posing and to think about
406 possible semantics... */
407 else if (class != statics->instances[0]->class_pointer)
409 id *inst;
411 for (inst = &statics->instances[0]; *inst; inst++)
413 (*inst)->class_pointer = class;
415 /* ??? Make sure the object will not be freed. With
416 refcounting, invoke `-retain'. Without refcounting, do
417 nothing and hope that `-free' will never be invoked. */
419 /* ??? Send the object an `-initStatic' or something to
420 that effect now or later on? What are the semantics of
421 statically allocated instances, besides the trivial
422 NXConstantString, anyway? */
426 if (module_initialized)
428 /* Remove this module from the uninitialized list. */
429 struct objc_list *this = *cell;
430 *cell = this->tail;
431 objc_free(this);
433 else
434 cell = &(*cell)->tail;
437 objc_mutex_unlock(__objc_runtime_mutex);
438 } /* objc_init_statics */
440 /* This function is called by constructor functions generated for each
441 module compiled. (_GLOBAL_$I$...) The purpose of this function is to
442 gather the module pointers so that they may be processed by the
443 initialization routines as soon as possible */
445 void
446 __objc_exec_class (Module_t module)
448 /* Have we processed any constructors previously? This flag is used to
449 indicate that some global data structures need to be built. */
450 static BOOL previous_constructors = 0;
452 static struct objc_list* unclaimed_categories = 0;
454 /* The symbol table (defined in objc-api.h) generated by gcc */
455 Symtab_t symtab = module->symtab;
457 /* The statics in this module */
458 struct objc_static_instances **statics
459 = symtab->defs[symtab->cls_def_cnt + symtab->cat_def_cnt];
461 /* Entry used to traverse hash lists */
462 struct objc_list** cell;
464 /* The table of selector references for this module */
465 SEL selectors = symtab->refs;
467 /* dummy counter */
468 int i;
470 DEBUG_PRINTF ("received module: %s\n", module->name);
472 /* check gcc version */
473 init_check_module_version(module);
475 /* On the first call of this routine, initialize some data structures. */
476 if (!previous_constructors)
478 /* Initialize thread-safe system */
479 __objc_init_thread_system();
480 __objc_runtime_threads_alive = 1;
481 __objc_runtime_mutex = objc_mutex_allocate();
483 __objc_init_selector_tables();
484 __objc_init_class_tables();
485 __objc_init_dispatch_tables();
486 __objc_class_tree_list = list_cons (NULL, __objc_class_tree_list);
487 __objc_load_methods
488 = hash_new (128, (hash_func_type)hash_ptr, compare_ptrs);
489 previous_constructors = 1;
492 /* Save the module pointer for later processing. (not currently used) */
493 objc_mutex_lock(__objc_runtime_mutex);
494 __objc_module_list = list_cons(module, __objc_module_list);
496 /* Replace referenced selectors from names to SEL's. */
497 if (selectors)
499 for (i = 0; selectors[i].sel_id; ++i)
501 const char *name, *type;
502 name = (char*)selectors[i].sel_id;
503 type = (char*)selectors[i].sel_types;
504 /* Constructors are constant static data so we can safely store
505 pointers to them in the runtime structures. is_const == YES */
506 __sel_register_typed_name (name, type,
507 (struct objc_selector*)&(selectors[i]),
508 YES);
512 /* Parse the classes in the load module and gather selector information. */
513 DEBUG_PRINTF ("gathering selectors from module: %s\n", module->name);
514 for (i = 0; i < symtab->cls_def_cnt; ++i)
516 Class class = (Class) symtab->defs[i];
517 const char* superclass = (char*)class->super_class;
519 /* Make sure we have what we think. */
520 assert (CLS_ISCLASS(class));
521 assert (CLS_ISMETA(class->class_pointer));
522 DEBUG_PRINTF ("phase 1, processing class: %s\n", class->name);
524 /* Initialize the subclass list to be NULL.
525 In some cases it isn't and this crashes the program. */
526 class->subclass_list = NULL;
528 /* Store the class in the class table and assign class numbers. */
529 __objc_add_class_to_hash (class);
531 /* Register all of the selectors in the class and meta class. */
532 __objc_register_selectors_from_class (class);
533 __objc_register_selectors_from_class ((Class) class->class_pointer);
535 /* Install the fake dispatch tables */
536 __objc_install_premature_dtable(class);
537 __objc_install_premature_dtable(class->class_pointer);
539 /* Register the instance methods as class methods, this is
540 only done for root classes. */
541 __objc_register_instance_methods_to_class(class);
543 if (class->protocols)
544 __objc_init_protocols (class->protocols);
546 /* Check to see if the superclass is known in this point. If it's not
547 add the class to the unresolved_classes list. */
548 if (superclass && !objc_lookup_class (superclass))
549 unresolved_classes = list_cons (class, unresolved_classes);
552 /* Process category information from the module. */
553 for (i = 0; i < symtab->cat_def_cnt; ++i)
555 Category_t category = symtab->defs[i + symtab->cls_def_cnt];
556 Class class = objc_lookup_class (category->class_name);
558 /* If the class for the category exists then append its methods. */
559 if (class)
562 DEBUG_PRINTF ("processing categories from (module,object): %s, %s\n",
563 module->name,
564 class->name);
566 /* Do instance methods. */
567 if (category->instance_methods)
568 class_add_method_list (class, category->instance_methods);
570 /* Do class methods. */
571 if (category->class_methods)
572 class_add_method_list ((Class) class->class_pointer,
573 category->class_methods);
575 if (category->protocols)
577 __objc_init_protocols (category->protocols);
578 __objc_class_add_protocols (class, category->protocols);
581 /* Register the instance methods as class methods, this is
582 only done for root classes. */
583 __objc_register_instance_methods_to_class(class);
585 else
587 /* The object to which the category methods belong can't be found.
588 Save the information. */
589 unclaimed_categories = list_cons(category, unclaimed_categories);
593 if (statics)
594 uninitialized_statics = list_cons (statics, uninitialized_statics);
595 if (uninitialized_statics)
596 objc_init_statics ();
598 /* Scan the unclaimed category hash. Attempt to attach any unclaimed
599 categories to objects. */
600 for (cell = &unclaimed_categories;
601 *cell;
602 ({ if (*cell) cell = &(*cell)->tail; }))
604 Category_t category = (*cell)->head;
605 Class class = objc_lookup_class (category->class_name);
607 if (class)
609 DEBUG_PRINTF ("attaching stored categories to object: %s\n",
610 class->name);
612 list_remove_head (cell);
614 if (category->instance_methods)
615 class_add_method_list (class, category->instance_methods);
617 if (category->class_methods)
618 class_add_method_list ((Class) class->class_pointer,
619 category->class_methods);
621 if (category->protocols)
623 __objc_init_protocols (category->protocols);
624 __objc_class_add_protocols (class, category->protocols);
627 /* Register the instance methods as class methods, this is
628 only done for root classes. */
629 __objc_register_instance_methods_to_class(class);
633 if (unclaimed_proto_list && objc_lookup_class ("Protocol"))
635 list_mapcar (unclaimed_proto_list,(void(*)(void*))__objc_init_protocols);
636 list_free (unclaimed_proto_list);
637 unclaimed_proto_list = 0;
640 objc_send_load ();
642 objc_mutex_unlock(__objc_runtime_mutex);
645 static void objc_send_load (void)
647 if (!__objc_module_list)
648 return;
650 /* Try to find out if all the classes loaded so far also have their
651 superclasses known to the runtime. We suppose that the objects that are
652 allocated in the +load method are in general of a class declared in the
653 same module. */
654 if (unresolved_classes)
656 Class class = unresolved_classes->head;
658 while (objc_lookup_class ((char*)class->super_class))
660 list_remove_head (&unresolved_classes);
661 if (unresolved_classes)
662 class = unresolved_classes->head;
663 else
664 break;
668 * If we still have classes for whom we don't have yet their super
669 * classes known to the runtime we don't send the +load messages.
671 if (unresolved_classes)
672 return;
675 /* Special check to allow creating and sending messages to constant strings
676 in +load methods. If these classes are not yet known, even if all the
677 other classes are known, delay sending of +load. */
678 if (!objc_lookup_class ("NXConstantString") ||
679 !objc_lookup_class ("Object"))
680 return;
682 /* Iterate over all modules in the __objc_module_list and call on them the
683 __objc_create_classes_tree function. This function creates a tree of
684 classes that resembles the class hierarchy. */
685 list_mapcar (__objc_module_list, (void(*)(void*))__objc_create_classes_tree);
687 while (__objc_class_tree_list)
689 #ifdef DEBUG
690 objc_preorder_traverse (__objc_class_tree_list->head,
691 0, __objc_tree_print);
692 #endif
693 objc_preorder_traverse (__objc_class_tree_list->head,
694 0, __objc_send_load);
695 objc_postorder_traverse (__objc_class_tree_list->head,
696 0, __objc_destroy_class_tree_node);
697 list_remove_head (&__objc_class_tree_list);
700 list_mapcar (__objc_module_list, (void(*)(void*))__objc_call_callback);
701 list_free (__objc_module_list);
702 __objc_module_list = NULL;
705 static void
706 __objc_create_classes_tree (Module_t module)
708 /* The runtime mutex is locked in this point */
710 Symtab_t symtab = module->symtab;
711 int i;
713 /* Iterate thru classes defined in this module and insert them in the classes
714 tree hierarchy. */
715 for (i = 0; i < symtab->cls_def_cnt; i++)
717 Class class = (Class) symtab->defs[i];
719 objc_tree_insert_class (class);
723 static void
724 __objc_call_callback (Module_t module)
726 /* The runtime mutex is locked in this point */
728 Symtab_t symtab = module->symtab;
729 int i;
731 /* Iterate thru classes defined in this module and call the callback for
732 each one. */
733 for (i = 0; i < symtab->cls_def_cnt; i++)
735 Class class = (Class) symtab->defs[i];
737 /* Call the _objc_load_callback for this class. */
738 if (_objc_load_callback)
739 _objc_load_callback(class, 0);
742 /* Call the _objc_load_callback for categories. Don't register the instance
743 methods as class methods for categories to root classes since they were
744 already added in the class. */
745 for (i = 0; i < symtab->cat_def_cnt; i++)
747 Category_t category = symtab->defs[i + symtab->cls_def_cnt];
748 Class class = objc_lookup_class (category->class_name);
750 if (_objc_load_callback)
751 _objc_load_callback(class, category);
755 /* Sanity check the version of gcc used to compile `module'*/
756 static void init_check_module_version(Module_t module)
758 if ((module->version != OBJC_VERSION) || (module->size != sizeof (Module)))
760 int code;
762 if(module->version > OBJC_VERSION)
763 code = OBJC_ERR_OBJC_VERSION;
764 else if (module->version < OBJC_VERSION)
765 code = OBJC_ERR_GCC_VERSION;
766 else
767 code = OBJC_ERR_MODULE_SIZE;
769 objc_error(nil, code, "Module %s version %d doesn't match runtime %d\n",
770 module->name, (int)module->version, OBJC_VERSION);
774 static void
775 __objc_init_protocols (struct objc_protocol_list* protos)
777 int i;
778 static Class proto_class = 0;
780 if (! protos)
781 return;
783 objc_mutex_lock(__objc_runtime_mutex);
785 if (!proto_class)
786 proto_class = objc_lookup_class("Protocol");
788 if (!proto_class)
790 unclaimed_proto_list = list_cons (protos, unclaimed_proto_list);
791 objc_mutex_unlock(__objc_runtime_mutex);
792 return;
795 #if 0
796 assert (protos->next == 0); /* only single ones allowed */
797 #endif
799 for(i = 0; i < protos->count; i++)
801 struct objc_protocol* aProto = protos->list[i];
802 if (((size_t)aProto->class_pointer) == PROTOCOL_VERSION)
804 /* assign class pointer */
805 aProto->class_pointer = proto_class;
807 /* init super protocols */
808 __objc_init_protocols (aProto->protocol_list);
810 else if (protos->list[i]->class_pointer != proto_class)
812 objc_error(nil, OBJC_ERR_PROTOCOL_VERSION,
813 "Version %d doesn't match runtime protocol version %d\n",
814 (int)((char*)protos->list[i]->class_pointer-(char*)0),
815 PROTOCOL_VERSION);
819 objc_mutex_unlock(__objc_runtime_mutex);
822 static void __objc_class_add_protocols (Class class,
823 struct objc_protocol_list* protos)
825 /* Well... */
826 if (! protos)
827 return;
829 /* Add it... */
830 protos->next = class->protocols;
831 class->protocols = protos;