bug-gnustep
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[bug #36706] performSelector: not working with message fowarding


From: Michael Johnston
Subject: [bug #36706] performSelector: not working with message fowarding
Date: Fri, 06 Jul 2012 10:54:59 +0000
User-agent: Mozilla/5.0 (X11; Linux i686) AppleWebKit/535.19 (KHTML, like Gecko) Ubuntu/11.04 Chromium/18.0.1025.151 Chrome/18.0.1025.151 Safari/535.19

Follow-up Comment #8, bug #36706 (project gnustep):

After some investigation the main problem occurs when sending an unknown
method i.e. that has no implementation locally, to an object, which you want
to redirect to some other implemented method.

In this case you would have methodSignatureForSelector: return the sig of the
method the method to be redirected to, and fowardInvocation: replace the
invocations selector with that of the method to be redirected to.

There are then three situations when calling [Foo performSelector:
@selector(wibble)]
1. It works if wibble is declared in some other class
2. It works if wibble is not declared but [foo wibble] was called previously
3. It raises an exception if wibble not declared and [foo wibble] not called
previously.

I've attached a modified version of the code in the previous comment which
demonstrates the above. For some reason I can't catch the exception raised in
the third situation (the third test in the code). So to see situation two you
have to comment out the third test. I've also attached the output for the two
cases (output1.txt, output2.txt).

What happens is that performSelector: causes gs_objc_msg_forward2 to be called
with a class, whereas if its directly sent it is called with the object. When
called with a class methodSignatureToSelector: is sent to the class. This
causes the classes instanceMethodSignatureForSelector: to be called which just
checks if the class implements the method (it doesn't call an instances
methodSignatureForSelector:) - so this always returns nil if the class doesn't
implement the method.

The reason it works if wibble is declared somewhere is that
gs_find_best_typed_sel comes up with something and the sig is created using
signatureWithObjcTypes: (GSFFIInvocation,m:187-191). For some reason this also
succeeds for an undeclared method once that method has been sent directly, but
otherwise it fails.

Fred, you mentioned that a possible solution is that the class should
implement +methodSignatureForSelector: - This could work but this is not an
NSObject method and from the docs I've read it shouldn't be required to get
the forwarding to work. Similarly overriding
instanceMethodSignatureForSelector: could also work but shouldn't be required.
I note that the attached code works fine on OSX and gnustep-base pre 1.22.

Another issue I noticed was that even if methodSignatureForSelector: returns
nil, [Foo wibble] and [Foo performSelector: @selector(wibble)] will work. This
doesn't seem correct to me. You can test it by calling super to try to get the
signature instead of a Bar object (in Foo methodSignatureForSelector:). I also
attached the output of this (output3.txt).




(file #26153, file #26154, file #26155, file #26156)
    _______________________________________________________

Additional Item Attachment:

File name: test.m                         Size:1 KB
File name: output2.txt                    Size:2 KB
File name: output1.txt                    Size:1 KB
File name: output3.txt                    Size:1 KB


    _______________________________________________________

Reply to this item at:

  <http://savannah.gnu.org/bugs/?36706>

_______________________________________________
  Message sent via/by Savannah
  http://savannah.gnu.org/




reply via email to

[Prev in Thread] Current Thread [Next in Thread]