[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Forwarding and the GNU runtime one more time (was ANN: GNUstep 2.6.0
From: |
David Chisnall |
Subject: |
Re: Forwarding and the GNU runtime one more time (was ANN: GNUstep 2.6.0 for openSUSE 11.4) |
Date: |
Wed, 22 Jun 2011 08:30:14 +0100 |
You seem to misunderstand the notion of a hook. __objc_msg_forward* are
function pointers in the runtime. They are set in Foundation to something that
handles the forwarding. The hooks in NeXT / Apple libobjc are different.
_objc_msgForward() in the Mac runtimes is a private function, and
implementation detail, and something that you should never touch. The fact
that you are even considering using it directly means that your code is
probably wrong. With the GNU runtimes, there are four different forwarding
hooks that may be invoked, so inspecting the IMP returned by the lookup is
almost certainly wrong.
As Nicola said, what are you actually trying to achieve? There is almost
certainly a much simpler way of doing it than this.
David
On 22 Jun 2011, at 00:06, Nat! wrote:
> Hi
>
> If I ask the GNU ObjC runtime (gcc 4.5) objc_msg_lookup for an IMP of a
> class' method, I get an address to a forwarding/error routine back, if the
> method is not present (without gnustep-base linked in). From looking with
> gdb, there seems to be no symbol attached to the address. To me that implies
> that there is no way to see from the returned value, if it is a resolved
> method or not ?
>
> When I link gnustep-base in, then objc_msg_lookup throws an
> NSInvalidArgumentException, because of the unrecognized selector. So
> objc_msg_lookup is not something I can use. Is there a method that is as
> performant as objc_msg_lookup (using the cache), which does not raise ? I am
> assuming class_get_instance_method is traversing the method chains.
>
>
> Here's my test code and it's output:
>
> #ifndef GNUSTEP
> #include <objc/runtime.h>
> #include <objc/objc-runtime.h>
> #else
> #include <objc/objc.h>
> #endif
> #include <stdio.h>
>
> //
> // apple: cc -g -arch i386 -o x x.m -lobjc
> // gnu: gcc -DGNUSTEP -o x -g x.m -lobjc
> //
>
> @interface Test
> @end
>
> @implementation Test
>
> - (id) xxx
> {
> }
>
> #ifndef GNUSTEP
> - (id) forward:(SEL) sel
> :(marg_list) args
> {
> }
> #endif
>
> @end
>
>
> #ifndef GNUSTEP
> extern id _objc_msgForward( id, SEL, ...);
> #define FWD _objc_msgForward
> #define LOOKUP class_lookupMethod
> #define GETCLS objc_getClass
> #else
> extern IMP *__objc_msg_forward2;
> #define FWD __objc_msg_forward2
> #define LOOKUP objc_msg_lookup
> #define GETCLS objc_get_class
> #endif
>
>
> check( SEL sel)
> {
> IMP imp;
> Class cls;
>
> cls = GETCLS( "Test");
> imp = LOOKUP( cls, sel);
> printf( "%p\n", imp);
>
> }
>
>
> main()
> {
> check( @selector( xxx));
> check( @selector( yyy));
> printf( "(%p)\n", FWD);
> }
>
>
> Apple Output (32bit):
> =====================
> 0x1cd0
> 0x98c37260
> (0x98c37260)
>
>
> GNUstep Output (no gnustep-base):
> =================================
> 0x8048604
> 0xb7736660
> ((nil))
>
> Ciao
> Nat!
>
> P.S.: Not caring about the new stuff just yet :)
> ------------------------------------------------------
> Es ist eine so angenehme Empfindung sich mit etwas zu
> beschäftigen was man nur halb kann, daß Niemand den
> Dilettanten schelten sollte, wenn er sich mit einer
> Kunst abgibt, die er nie lernen wird. -- JWG
>
>
> _______________________________________________
> Gnustep-dev mailing list
> address@hidden
> https://lists.gnu.org/mailman/listinfo/gnustep-dev
-- Sent from my brain
- Forwarding and the GNU runtime one more time (was ANN: GNUstep 2.6.0 for openSUSE 11.4), Nat!, 2011/06/21
- RE: Forwarding and the GNU runtime one more time (was ANN : GNUstep 2.6.0 for openSUSE 11.4), Nicola Pero, 2011/06/21
- Re: Forwarding and the GNU runtime one more time (was ANN: GNUstep 2.6.0 for openSUSE 11.4),
David Chisnall <=
- Re: Forwarding and the GNU runtime one more time (was ANN: GNUstep 2.6.0 for openSUSE 11.4), Nat!, 2011/06/22
- Re: Forwarding and the GNU runtime one more time (was ANN: GNUstep 2.6.0 for openSUSE 11.4), David Chisnall, 2011/06/22
- Re: Forwarding and the GNU runtime one more time (was ANN : GNUstep 2.6.0 for openSUSE 11.4), Nicola Pero, 2011/06/22
- Re: Forwarding and the GNU runtime one more time (was ANN: GNUstep 2.6.0 for openSUSE 11.4), Nat!, 2011/06/22
- Re: Forwarding and the GNU runtime one more time (was ANN : GNUstep 2.6.0 for openSUSE 11.4), Nicola Pero, 2011/06/22
- Re: Forwarding and the GNU runtime one more time (was ANN: GNUstep 2.6.0 for openSUSE 11.4), David Chisnall, 2011/06/22