]> git.ipfire.org Git - thirdparty/gcc.git/blobdiff - libobjc/sendmsg.c
Update copyright years.
[thirdparty/gcc.git] / libobjc / sendmsg.c
index c84e90f5b6e35111ff82ad59ea0e18daa3101a9c..892f55b945a8be07725a02d1591b6867d86c88ce 100644 (file)
@@ -1,6 +1,5 @@
 /* GNU Objective C Runtime message lookup 
-   Copyright (C) 1993, 1995, 1996, 1997, 1998,
-   2001, 2002, 2004, 2009, 2010 Free Software Foundation, Inc.
+   Copyright (C) 1993-2021 Free Software Foundation, Inc.
    Contributed by Kresten Krab Thorup
 
 This file is part of GCC.
@@ -27,7 +26,6 @@ see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
    only while debugging the runtime.  */
 /* #define DEBUG 1 */
 
-/* FIXME: This file has no business including tm.h.  */
 /* FIXME: This should be using libffi instead of __builtin_apply
    and friends.  */
 
@@ -35,7 +33,6 @@ see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
 #include "objc-private/error.h"
 #include "tconfig.h"
 #include "coretypes.h"
-#include "tm.h"
 #include "objc/runtime.h"
 #include "objc/message.h"          /* For objc_msg_lookup(), objc_msg_lookup_super().  */
 #include "objc/thr.h"
@@ -48,21 +45,11 @@ see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
 #include <assert.h> /* For assert */
 #include <string.h> /* For strlen */
 
-/* This is how we hack STRUCT_VALUE to be 1 or 0.   */
-#define gen_rtx(args...) 1
-#define gen_rtx_MEM(args...) 1
-#define gen_rtx_REG(args...) 1
-/* Already defined in gcc/coretypes.h. So prevent double definition warning.  */
-#undef rtx
-#define rtx int
-
-#if ! defined (STRUCT_VALUE) || STRUCT_VALUE == 0
 #define INVISIBLE_STRUCT_RETURN 1
-#else
-#define INVISIBLE_STRUCT_RETURN 0
-#endif
 
-/* The uninstalled dispatch table.  */
+/* The uninstalled dispatch table.  If a class' dispatch table points
+   to __objc_uninstalled_dtable then that means it needs its dispatch
+   table to be installed.  */
 struct sarray *__objc_uninstalled_dtable = 0;   /* !T:MUTEX */
 
 /* Two hooks for method forwarding. If either is set, it is invoked to
@@ -103,6 +90,10 @@ static struct objc_method * search_for_method_in_hierarchy (Class class, SEL sel
 struct objc_method * search_for_method_in_list (struct objc_method_list * list, SEL op);
 id nil_method (id, SEL);
 
+/* Make sure this inline function is exported regardless of GNU89 or C99
+   inlining semantics as it is part of the libobjc ABI.  */
+extern IMP __objc_get_forward_imp (id, SEL);
+
 /* Given a selector, return the proper forwarding implementation.  */
 inline
 IMP
@@ -319,6 +310,10 @@ get_implementation (id receiver, Class class, SEL sel)
   return res;
 }
 
+/* Make sure this inline function is exported regardless of GNU89 or C99
+   inlining semantics as it is part of the libobjc ABI.  */
+extern IMP get_imp (Class, SEL);
+
 inline
 IMP
 get_imp (Class class, SEL sel)
@@ -469,29 +464,6 @@ objc_msg_lookup_super (struct objc_super *super, SEL sel)
     return (IMP)nil_method;
 }
 
-/* Temporarily defined here until objc_msg_sendv() goes away.  */
-char *method_get_first_argument (struct objc_method *,
-                                arglist_t argframe, 
-                                const char **type);
-char *method_get_next_argument (arglist_t argframe, 
-                               const char **type);
-int method_get_sizeof_arguments (struct objc_method *);
-
-struct objc_method *
-class_get_instance_method (Class class, SEL op);
-
-retval_t
-objc_msg_sendv (id object, SEL op, arglist_t arg_frame)
-{
-  struct objc_method *m = class_get_instance_method (object->class_pointer, op);
-  const char *type;
-  *((id *) method_get_first_argument (m, arg_frame, &type)) = object;
-  *((SEL *) method_get_next_argument (arg_frame, &type)) = op;
-  return __builtin_apply ((apply_t) m->method_imp, 
-                         arg_frame,
-                         method_get_sizeof_arguments (m));
-}
-
 void
 __objc_init_dispatch_tables ()
 {
@@ -537,34 +509,13 @@ __objc_send_initialize (Class class)
 
       {
        SEL op = sel_registerName ("initialize");
-       IMP imp = 0;
-        struct objc_method_list * method_list = class->class_pointer->methods;
-       
-        while (method_list)
-         {
-           int i;
-           struct objc_method * method;
-           
-           for (i = 0; i < method_list->method_count; i++)
-             {
-               method = &(method_list->method_list[i]);
-               if (method->method_name
-                   && method->method_name->sel_id == op->sel_id)
-                 {
-                   imp = method->method_imp;
-                   break;
-                 }
-             }
-           
-           if (imp)
-             break;
-           
-           method_list = method_list->method_next;
-         }
-       if (imp)
+        struct objc_method *method = search_for_method_in_hierarchy (class->class_pointer, 
+                                                                    op);
+
+       if (method)
          {
            DEBUG_PRINTF (" begin of [%s +initialize]\n", class->name);
-           (*imp) ((id) class, op);
+           (*method->method_imp) ((id)class, op);
            DEBUG_PRINTF (" end of [%s +initialize]\n", class->name);
          }
 #ifdef DEBUG
@@ -664,18 +615,6 @@ class_add_method_list (Class class, struct objc_method_list * list)
   __objc_update_dispatch_table_for_class (class);
 }
 
-struct objc_method *
-class_get_instance_method (Class class, SEL op)
-{
-  return search_for_method_in_hierarchy (class, op);
-}
-
-struct objc_method *
-class_get_class_method (MetaClass class, SEL op)
-{
-  return search_for_method_in_hierarchy (class, op);
-}
-
 struct objc_method *
 class_getInstanceMethod (Class class_, SEL selector)
 {
@@ -883,6 +822,9 @@ search_for_method_in_list (struct objc_method_list * list, SEL op)
   return NULL;
 }
 
+typedef void * retval_t;
+typedef void * arglist_t;
+
 static retval_t __objc_forward (id object, SEL sel, arglist_t args);
 
 /* Forwarding pointers/integers through the normal registers.  */
@@ -936,9 +878,12 @@ __objc_block_forward (id rcv, SEL op, ...)
 }
 
 
-/* This function is installed in the dispatch table for all methods
-   which are not implemented.  Thus, it is called when a selector is
-   not recognized.  */
+/* This function is called for methods which are not implemented,
+   unless a custom forwarding routine has been installed.  Please note
+   that most serious users of libobjc (eg, GNUstep base) do install
+   their own forwarding routines, and hence this is never actually
+   used.  But, if no custom forwarding routine is installed, this is
+   called when a selector is not recognized.  */
 static retval_t
 __objc_forward (id object, SEL sel, arglist_t args)
 {
@@ -977,16 +922,8 @@ __objc_forward (id object, SEL sel, arglist_t args)
              : "instance" ),
              object->class_pointer->name, sel_getName (sel));
 
-    /* TODO: support for error: is surely deprecated ? */
-    err_sel = sel_get_any_uid ("error:");
-    if (__objc_responds_to (object, err_sel))
-      {
-       imp = get_implementation (object, object->class_pointer, err_sel);
-       return (*imp) (object, sel_get_any_uid ("error:"), msg);
-      }
-
-    /* The object doesn't respond to doesNotRecognize: or error:;
-       Therefore, a default action is taken.  */
+    /* The object doesn't respond to doesNotRecognize:.  Therefore, a
+       default action is taken.  */
     _objc_abort ("%s\n", msg);
 
     return 0;
@@ -1023,15 +960,6 @@ __objc_print_dtable_stats (void)
   objc_mutex_unlock (__objc_runtime_mutex);
 }
 
-/* Returns the uninstalled dispatch table indicator.  If a class'
-   dispatch table points to __objc_uninstalled_dtable then that means
-   it needs its dispatch table to be installed.  */
-struct sarray *
-objc_get_uninstalled_dtable (void)
-{
-  return __objc_uninstalled_dtable;
-}
-
 static cache_ptr prepared_dtable_table = 0;
 
 /* This function is called by: objc_msg_lookup, get_imp and
@@ -1117,7 +1045,7 @@ __objc_prepare_dtable_for_class (Class cls)
   struct sarray *dtable;
   struct sarray *super_dtable;
 
-  /* This table could be initialized in init.c.  We can not use the
+  /* This table could be initialized in init.c.  We cannot use the
      class name since the class maintains the instance methods and the
      meta class maintains the the class methods yet both share the
      same name.  Classes should be unique in any program.  */