2 /* See if -forward:: is able to work. */
3 /* { dg-skip-if "Needs OBJC2 Implementation" { *-*-darwin8* && { lp64 && { ! objc2 } } } { "-fnext-runtime" } { "" } } */
8 #include "../../objc-obj-c++-shared/TestsuiteObject.m"
10 #define VALUETOUSE 1234567890
12 id forwarder, receiver;
14 @interface Forwarder: TestsuiteObject
19 -initWithReceiver:theReceiver;
23 @interface Receiver:TestsuiteObject
28 -initWithFoo:(int)theFoo;
30 @implementation Receiver
32 -initWithFoo: (int)theFoo
40 printf ("Executing display\n");
41 /* Check to see if we are really the reciever. */
44 /* And the value of foo is set correctly. */
45 if (foo != VALUETOUSE)
52 @implementation Forwarder
53 -initWithReceiver: theReceiver
56 receiver = theReceiver;
59 -(void *) forward: (SEL)theSel: (void *)theArgFrame
61 /* If we have a reciever try to perform on that object */
64 /* Simple forward that works for methods with no
66 typedef id (*method_with_no_args) (id receiver, SEL _cmd);
67 Method method = class_getInstanceMethod (object_getClass (receiver),
69 method_with_no_args imp = (method_with_no_args)(method_getImplementation
71 return (*imp)(receiver, theSel);
74 /* Normally you'd emit an error here. */
75 printf ("Unrecognized selector\n");
81 /* Init the reciever. */
82 receiver = [[Receiver alloc] initWithFoo: VALUETOUSE];
83 /* Init the fowarder. */
84 forwarder = [[Forwarder alloc] initWithReceiver: receiver];
85 /* Call display on the forwarder which in turns calls display on