[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Source-level compatibility of runtime(s) with Apple
From: |
David Chisnall |
Subject: |
Re: Source-level compatibility of runtime(s) with Apple |
Date: |
Mon, 21 Feb 2011 15:33:01 +0000 |
On 21 Feb 2011, at 15:23, Ivan Vučica wrote:
> Hi,
>
> I've ran into a difference between runtime on Debian and Apple's runtime in
> the function name conventions. For example:
>
> Class classFromIsa;
> #if GNUSTEP
> classFromIsa = objc_lookup_class([isaStr UTF8String]);
> #else
> classFromIsa = objc_lookUpClass([isaStr UTF8String]);
> #endif
The correct way of doing this is:
Class classFromIsa = NSClassFromString(isaStr);
> I wanted to ask whether the GNU/GNUstep runtime could additionally include
> the Apple variant of the function name, but fortunately I looked at libobjc2
> source code first. From what I can see, there the Apple's style of the
> function name is used.
>
> What is the future policy regarding this? What should the above #if check for?
It shouldn't check for anything, it should use the Apple version.
If you are using GNUstep libobjc, it will work. The Apple functions are the
authoritative ones, and some legacy compatibility ones are provided for use
with old versions of GNUstep that still call the GCC runtime versions.
If you are using GCC libobjc from GCC 4.6 or later, it will work.
If you are using GCC libobjc from GCC 4.5 or earlier, there is a wrapper that
was originally provided as Étoilé's ObjectiveC2 framework, and is no part of
GNUstep-base[1].
The only problem is with some of the functions that are not part of the
official ObjC Runtime API spec. For example, getting the types of a typed
selector (the Apple / NeXT runtimes don't support typed selectors). The
ObjectiveC2 compatibility layer in -base and the GNUstep runtime provide
sel_getTypes_np(). This will work on the GNUstep runtime, and the GCC runtime
up to 4.5 if you link against GNUstep base or the compatibility layer. The _np
suffix is found on all of the GNUstep runtime functions that are extensions
beyond the Apple-provided ones and are therefore not to be used in portable
code (the _np suffix is a UNIX convention for non-portable extensions to
standard APIs).
For GCC 4.6 or later, you have to use sel_getTypeEncoding() instead.
David
-- Send from my Jacquard Loom
[1] This was originally MIT licensed, to allow it to be used by anyone. It was
copyright assigned to the FSF to allow it to be included in GNUstep or GCC
libobjc, but was not adopted by GCC.