OSDN Git Service

2007-04-09 Andrew Ruder <andy@aeruder.net>
[pf3gnuchains/gcc-fork.git] / libobjc / sendmsg.c
index f0b5bbb..c1aed1c 100644 (file)
@@ -16,8 +16,8 @@ details.
 
 You should have received a copy of the GNU General Public License along with
 GCC; see the file COPYING.  If not, write to the Free Software
-Foundation, 59 Temple Place - Suite 330,
-Boston, MA 02111-1307, USA.  */
+Foundation, 51 Franklin Street, Fifth Floor,
+Boston, MA 02110-1301, USA.  */
 
 /* As a special exception, if you link this library with files compiled with
    GCC to produce an executable, this does not cause the resulting executable
@@ -32,9 +32,9 @@ Boston, MA 02111-1307, USA.  */
 #include "tconfig.h"
 #include "coretypes.h"
 #include "tm.h"
-#include "runtime.h"
-#include "sarray.h"
-#include "encoding.h"
+#include "objc/runtime.h"
+#include "objc/sarray.h"
+#include "objc/encoding.h"
 #include "runtime-info.h"
 
 /* This is how we hack STRUCT_VALUE to be 1 or 0.   */
@@ -52,10 +52,15 @@ Boston, MA 02111-1307, USA.  */
 /* The uninstalled dispatch table */
 struct sarray *__objc_uninstalled_dtable = 0;   /* !T:MUTEX */
 
-/* Hook for method forwarding. If it is set, is invoked to return a
-   function that performs the real forwarding. Otherwise the libgcc
-   based functions (__builtin_apply and friends) are used. */
+/* Two hooks for method forwarding. If either is set, it is invoked
+ * to return a function that performs the real forwarding.  If both
+ * are set, the result of __objc_msg_forward2 will be preferred over
+ * that of __objc_msg_forward.  If both return NULL or are unset,
+ * the libgcc based functions (__builtin_apply and friends) are
+ * used.
+ */
 IMP (*__objc_msg_forward) (SEL) = NULL;
+IMP (*__objc_msg_forward2) (id, SEL) = NULL;
 
 /* Send +initialize to class */
 static void __objc_send_initialize (Class);
@@ -69,8 +74,7 @@ static void __objc_init_install_dtable (id, SEL);
    return type for the selector.
    __objc_block_forward for structures.
    __objc_double_forward for floats/doubles.
-   __objc_word_forward for pointers or types that fit in registers.
-   */
+   __objc_word_forward for pointers or types that fit in registers. */
 static double __objc_double_forward (id, SEL, ...);
 static id __objc_word_forward (id, SEL, ...);
 typedef struct { id many[8]; } __big;
@@ -87,10 +91,11 @@ id nil_method (id, SEL);
 /* Given a selector, return the proper forwarding implementation. */
 inline
 IMP
-__objc_get_forward_imp (SEL sel)
+__objc_get_forward_imp (id rcv, SEL sel)
 {
   /* If a custom forwarding hook was registered, try getting a forwarding
-   * function from it.  */
+     function from it. There are two forward routine hooks, one that
+     takes the receiver as an argument and one that does not. */
   if (__objc_msg_forward)
     {
       IMP result;
@@ -99,7 +104,7 @@ __objc_get_forward_imp (SEL sel)
     }
 
   /* In all other cases, use the default forwarding functions built using
-   * __builtin_apply and friends.  */
+     __builtin_apply and friends.  */
     {
       const char *t = sel->sel_types;
 
@@ -168,7 +173,7 @@ get_imp (Class class, SEL sel)
                 is not in the dispatch table.  So the method just
                 doesn't exist for the class.  Return the forwarding
                 implementation. */
-             res = __objc_get_forward_imp (sel);
+             res = __objc_get_forward_imp ((id)class, sel);
            }
        }
     }
@@ -237,7 +242,7 @@ objc_msg_lookup (id receiver, SEL op)
                {
                  /* If the method still just doesn't exist for the
                     class, attempt to forward the method. */
-                 result = __objc_get_forward_imp (op);
+                 result = __objc_get_forward_imp (receiver, op);
                }
            }
        }