Re: Porting to 64Bit -descriptionForInstanceMethod:

2019-06-18 Thread Andreas Höschler
Hi David,

> On 18 Jun 2019, at 17:34, David Chisnall  wrote:
> 
>> I wonder why I haven’t found that. Thanks!
>>  struct objc_method_description methodDesc = 
>> protocol_getMethodDescription(_protocol, aSelector, YES, YES);
>>  types = methodDesc.types;
>>  This works great as long as I build with -m32. But as soon as I switch to
> 
> This function is in the Apple headers, so the only explanation I can think of 
> is that you're failing to #include  in the 64-bit case.  You 
> may be implicitly including it via some other header that has a conditional 
> include based on pointer size?

Bumahh! :-( That was it!

Thanks so much! Works now!

Andreas

___
Discuss-gnustep mailing list
Discuss-gnustep@gnu.org
https://lists.gnu.org/mailman/listinfo/discuss-gnustep


Re: Porting to 64Bit -descriptionForInstanceMethod:

2019-06-18 Thread Andreas Höschler
Hi David,

I checked 

make messages=yes

and found that

gcc SRProxy.m -c -MMD -MP -DNeXT_Foundation_LIBRARY=1 -DNeXT_GUI_LIBRARY=1 
-DNeXT_RUNTIME=1 -dynamic -fno-common -Wall -DGSWARN -DGSDIAGNOSE -Wno-import 
-g -O2 -fno-strict-aliasing -fnext-runtime -m32 -Wno-deprecated-declarations 
-Wno-deprecated -Wno-format-security -Wno-parentheses -Wno-import -I 
/usr/local/ssl/include -I/Build/SRFoundation/derived_src -I. 
-I/usr/local/include/ -F/Library/Frameworks/ -o 
/Build/SRFoundation/obj/SRFoundation.obj/SRProxy.m.o

succeeds but 

gcc SRProxy.m -c -MMD -MP -DNeXT_Foundation_LIBRARY=1 -DNeXT_GUI_LIBRARY=1 
-DNeXT_RUNTIME=1 -dynamic -fno-common -Wall -DGSWARN -DGSDIAGNOSE -Wno-import 
-g -O2 -fno-strict-aliasing -fnext-runtime -m64 -Wno-deprecated-declarations 
-Wno-deprecated -Wno-format-security -Wno-parentheses -Wno-import -I 
/usr/local/ssl/include -I/Build/SRFoundation/derived_src -I. 
-I/usr/local/include/ -F/Library/Frameworks/ -o 
/Build/SRFoundation/obj/SRFoundation.obj/SRProxy.m.o

produces the below reported error!? :-(

Andreas


 - descriptionForInstanceMethod: is gone.  Don't use it, use the runtime 
 functions instead.
>>> 
>>> Thanks for the hint. 
>>> 
>>> Where would I find a list (the declaration) of these runtime functions on 
>>> MacOSX and GNUstep? Are they even identically named? I guess no!?
>>> 
>> 
>> Here is the top hit for a DDG search for ‘Objective-C Runtime’:
>> 
>> https://developer.apple.com/documentation/objectivec/objective-c_runtime?language=objc
>>  
>> 
>> 
>> It provides you with the Objective-C Runtime API Reference.  The GNUstep 
>> runtime also implements this interface and is source compatible
> 
> That’s great! 
> 
>> (it also implements some non-portable functions, which I would suggest that 
>> you avoid).  You can find these all in objc/runtime.h.  
>> 
>> The method that you are probably looking for is 
>> protocol_getMethodDescription.
> 
> I wonder why I haven’t found that. Thanks!
> 
>  struct objc_method_description methodDesc = 
> protocol_getMethodDescription(_protocol, aSelector, YES, YES);
>  types = methodDesc.types;
> 
>  This works great as long as I build with -m32. But as soon as I switch to 
> 
> ...
> ADDITIONAL_OBJCFLAGS += -m64 -Wno-deprecated-declarations -Wno-deprecated 
> -Wno-format-security
> ADDITIONAL_CFLAGS += -m64
> ADDITIONAL_LDFLAGS += -m64
> …
> 
> in GNUmakefile I get
> 
>  Compiling file SRProxy.m ... 
>~~ ^
> %lu   
>  (unsigned long)
> SRProxy.m:425:54: warning: implicit declaration of function 
> 'protocol_getMethodDescription' is invalid in C99 
> [-Wimplicit-function-declaration]
>  struct objc_method_description methodDesc = 
> protocol_getMethodDescription(_protocol, aSelector, YES, YES);
>  ^
> SRProxy.m:425:41: error: variable has incomplete type 'struct 
> objc_method_description'
>  struct objc_method_description methodDesc = 
> protocol_getMethodDescription(_protocol, aSelector, YES, YES);
> ^
> SRProxy.m:425:17: note: forward declaration of 'struct 
> objc_method_description'
>  struct objc_method_description methodDesc = 
> protocol_getMethodDescription(_protocol, aSelector, YES, YES);
> ^
> Any idea why this works for 32bit code only. I am currently trying to build 
> this on MacOSX 10.10. MacOSX 10.12 gave the same error!? :-(
> 
> Thanks so much,
> 
>  Andreas
> 


___
Discuss-gnustep mailing list
Discuss-gnustep@gnu.org
https://lists.gnu.org/mailman/listinfo/discuss-gnustep


Re: Porting to 64Bit -descriptionForInstanceMethod:

2019-06-18 Thread Andreas Höschler
Hi David,

> On 18 Jun 2019, at 16:22, David Chisnall  wrote:
> 
>>> - descriptionForInstanceMethod: is gone.  Don't use it, use the runtime 
>>> functions instead.
>> 
>> Thanks for the hint. 
>> 
>> Where would I find a list (the declaration) of these runtime functions on 
>> MacOSX and GNUstep? Are they even identically named? I guess no!?
>> 
> 
> Here is the top hit for a DDG search for ‘Objective-C Runtime’:
> 
> https://developer.apple.com/documentation/objectivec/objective-c_runtime?language=objc
>  
> 
> 
> It provides you with the Objective-C Runtime API Reference.  The GNUstep 
> runtime also implements this interface and is source compatible

That’s great! 

> (it also implements some non-portable functions, which I would suggest that 
> you avoid).  You can find these all in objc/runtime.h.  
> 
> The method that you are probably looking for is protocol_getMethodDescription.

I wonder why I haven’t found that. Thanks!

 struct objc_method_description methodDesc = 
protocol_getMethodDescription(_protocol, aSelector, YES, YES);
 types = methodDesc.types;

 This works great as long as I build with -m32. But as soon as I switch to 

...
ADDITIONAL_OBJCFLAGS += -m64 -Wno-deprecated-declarations -Wno-deprecated 
-Wno-format-security
ADDITIONAL_CFLAGS += -m64
ADDITIONAL_LDFLAGS += -m64
…

in GNUmakefile I get

 Compiling file SRProxy.m ...   
 ~~ ^
%lu 
   (unsigned long)
SRProxy.m:425:54: warning: implicit declaration of function 
'protocol_getMethodDescription' is invalid in C99 
[-Wimplicit-function-declaration]
 struct objc_method_description methodDesc = 
protocol_getMethodDescription(_protocol, aSelector, YES, YES);
 ^
SRProxy.m:425:41: error: variable has incomplete type 'struct 
objc_method_description'
 struct objc_method_description methodDesc = 
protocol_getMethodDescription(_protocol, aSelector, YES, YES);
^
SRProxy.m:425:17: note: forward declaration of 'struct objc_method_description'
 struct objc_method_description methodDesc = 
protocol_getMethodDescription(_protocol, aSelector, YES, YES);
^
Any idea why this works for 32bit code only. I am currently trying to build 
this on MacOSX 10.10. MacOSX 10.12 gave the same error!? :-(

Thanks so much,

 Andreas

___
Discuss-gnustep mailing list
Discuss-gnustep@gnu.org
https://lists.gnu.org/mailman/listinfo/discuss-gnustep


Re: Porting to 64Bit -descriptionForInstanceMethod:

2019-06-18 Thread David Chisnall

On 18/06/2019 16:20, Andreas Höschler wrote:

I wonder why I haven’t found that. Thanks!

          struct objc_method_description methodDesc = 
protocol_getMethodDescription(_protocol, aSelector, YES, YES);

          types = methodDesc.types;

  This works great as long as I build with -m32. But as soon as I switch to


This function is in the Apple headers, so the only explanation I can 
think of is that you're failing to #include  in the 
64-bit case.  You may be implicitly including it via some other header 
that has a conditional include based on pointer size?


David

___
Discuss-gnustep mailing list
Discuss-gnustep@gnu.org
https://lists.gnu.org/mailman/listinfo/discuss-gnustep


Re: Porting to 64Bit -descriptionForInstanceMethod:

2019-06-18 Thread David Chisnall
On 18 Jun 2019, at 13:47, Andreas Höschler  wrote:
> 
> Hi David,
> 
>> - descriptionForInstanceMethod: is gone.  Don't use it, use the runtime 
>> functions instead.
> 
> Thanks for the hint. 
> 
> Where would I find a list (the declaration) of these runtime functions on 
> MacOSX and GNUstep? Are they even identically named? I guess no!?
> 

Here is the top hit for a DDG search for ‘Objective-C Runtime’:

https://developer.apple.com/documentation/objectivec/objective-c_runtime?language=objc

It provides you with the Objective-C Runtime API Reference.  The GNUstep 
runtime also implements this interface and is source compatible (it also 
implements some non-portable functions, which I would suggest that you avoid).  
You can find these all in objc/runtime.h.  

The method that you are probably looking for is protocol_getMethodDescription.

David


___
Discuss-gnustep mailing list
Discuss-gnustep@gnu.org
https://lists.gnu.org/mailman/listinfo/discuss-gnustep


Re: Porting to 64Bit -descriptionForInstanceMethod:

2019-06-18 Thread Andreas Höschler
Hi David and all,

a google search for Objective-C runtime functions of course led to 


https://developer.apple.com/documentation/objectivec/objective-c_runtime?language=objc

and I thought I just had to select the proper method from the list and am done. 
But this does not seem to be that simple!? I found

 NSMethodSignature *methodSig = [[self class] 
instanceMethodSignatureForSelector:mySelector];
 NSInvocation *invocation = [NSInvocation 
invocationWithMethodSignature:methodSig]; 

for getting the method signature of an instance method for a known class. But 
in my case I just have a protocol. What would be the replacement for

methodDescription = [_protocol descriptionForInstanceMethod:aSelector];
char *types = methodDescription->types;
NSMethodSignature *methodSig  = [NSMethodSignature 
signatureWithObjCTypes:types];

with current objective-C runtime functions? Is that still possible at all? My 
search attempts for the proper runtime function so far led to 

void method_getReturnType(Method m, char *dst, size_t dst_len);
void method_getArgumentType(Method m, unsigned int index, char *dst, size_t 
dst_len);
unsigned int method_getNumberOfArguments(Method m);

So I might be able to construct 

 char *types = NULL;

from this and then do 

NSMethodSignature *methodSig  = [NSMethodSignature 
signatureWithObjCTypes:types];

but how do I get a Method from a given selector and protocol??

I am lost! :-(

Thanks a lot,

 Andreas


> On 18 Jun 2019, at 14:12, David Chisnall  wrote:
> 
>> *SRProxy.m:419:29: **warning: **instance method 
>> '-descriptionForInstanceMethod:' not found (return type defaults to 'id') 
>> [-Wobjc-method-access]*
>>  types = [_protocol descriptionForInstanceMethod:aSelector]->types;
>> *^~~~*
>> */usr/include/objc/Protocol.h:45:12: note: *receiver is instance of class 
>> declared here
>> @interface Protocol : NSObject
>> *   ^*
>> *SRProxy.m:419:70: **error: **no member named 'types' in 'struct 
>> objc_object'*
>> *
>> *
> 
> With the 'Modern' Objective-C ABI (circa 2006) on Apple platforms, the only 
> option on 64-bit and the default for a very long time on 32-bit, Protocol no 
> longer has any methods exposed on it.  This means:
> 
> - descriptionForInstanceMethod: is gone.  Don't use it, use the runtime 
> functions instead.  There is no point paying the overhead of an Objective-C 
> message send for a function where all of the types are known at compile time.
> 
> - The compiler assumes that the nonexistent method 
> -descriptionForInstanceMethod: returns id, which is a typedef for struct 
> objc_object, which has no fields other than isa (probably not even isa, 
> because direct access to isa is also deprecated).


___
Discuss-gnustep mailing list
Discuss-gnustep@gnu.org
https://lists.gnu.org/mailman/listinfo/discuss-gnustep


Re: Porting to 64Bit -descriptionForInstanceMethod:

2019-06-18 Thread Andreas Höschler
Hi David,

> - descriptionForInstanceMethod: is gone.  Don't use it, use the runtime 
> functions instead.

Thanks for the hint. 

Where would I find a list (the declaration) of these runtime functions on 
MacOSX and GNUstep? Are they even identically named? I guess no!?

Thanks,

 Andreas

___
Discuss-gnustep mailing list
Discuss-gnustep@gnu.org
https://lists.gnu.org/mailman/listinfo/discuss-gnustep


Re: Porting to 64Bit -descriptionForInstanceMethod:

2019-06-18 Thread David Chisnall

Wow, this is really old code!

On 18/06/2019 12:59, Andreas Höschler wrote:
*SRProxy.m:419:29: **warning: **instance method 
'-descriptionForInstanceMethod:' not found (return type defaults to 
'id') [-Wobjc-method-access]*
          types = [_protocol 
descriptionForInstanceMethod:aSelector]->types;

*                            ^~~~*
*/usr/include/objc/Protocol.h:45:12: note: *receiver is instance of 
class declared here

@interface Protocol : NSObject
*           ^*
*SRProxy.m:419:70: **error: **no member named 'types' in 'struct 
objc_object'*

*
*


With the 'Modern' Objective-C ABI (circa 2006) on Apple platforms, the 
only option on 64-bit and the default for a very long time on 32-bit, 
Protocol no longer has any methods exposed on it.  This means:


- descriptionForInstanceMethod: is gone.  Don't use it, use the runtime 
functions instead.  There is no point paying the overhead of an 
Objective-C message send for a function where all of the types are known 
at compile time.


- The compiler assumes that the nonexistent method 
-descriptionForInstanceMethod: returns id, which is a typedef for struct 
objc_object, which has no fields other than isa (probably not even isa, 
because direct access to isa is also deprecated).


David

___
Discuss-gnustep mailing list
Discuss-gnustep@gnu.org
https://lists.gnu.org/mailman/listinfo/discuss-gnustep