Skip to content

Commit 025688a

Browse files
author
theraven
committed
Added property_getName(). Added non-portable API documentation.
1 parent d705239 commit 025688a

File tree

5 files changed

+160
-19
lines changed

5 files changed

+160
-19
lines changed

API

+134
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,134 @@
1+
GNUstep Runtime APIs
2+
====================
3+
4+
The GNUstep Objective-C runtime aims to implement all of the APIs defined in
5+
Apple's Objective-C Runtime Reference. That document should be taken as the
6+
authoritative reference to the majority of the APIs exposed by this runtime.
7+
Any discrepancies between the implementations in this runtime and the
8+
documentation should be regarded as a bug in the runtime.
9+
10+
In addition to these APIs, the runtime also exposes some non-portable APIs.
11+
These are all marked as OBJC_NONPORTABLE in the headers. Many of these APIs
12+
are also implemented in GNUstep's ObjectiveC2 framework, which uses the GCC
13+
Objective-C runtime for the underlying implementation and provides a portable
14+
set of APIs on top of the GCC runtime structures and functions.
15+
16+
Runtime Capabilities
17+
--------------------
18+
19+
The objc/capabilities.h header defines runtime capabilities. A copy of this
20+
header is also present in the ObjectiveC2 framework, so you can conditionally
21+
include either version.
22+
23+
You can perform two sorts of checks using this header. Constants declared in
24+
the header describe capabilities that the runtime may or may not implement. If
25+
a capability is missing from this header, then it means that you are using an
26+
old version of the runtime, which lacks any knowledge of the header. You can
27+
use this to refuse to compile with old runtime versions.
28+
29+
You can also use the objc_test_capability() function to test whether a
30+
particular capability is present at run time. Several of the capabilities are
31+
optional in this runtime, and may not be compiled in to a given install. If
32+
you require a particular capability, you can use the OBJC_REQUIRE_CAPABILITY()
33+
macro to insert a load function that will abort if the capability is not present.
34+
35+
This shows how to refuse to compile or run with versions of the runtime that do
36+
not support type-dependent dispatch:
37+
38+
#ifndef OBJC_CAP_TYPE_DEPENDENT_DISPATCH
39+
# error Type-dependent dispatch support required!
40+
#else
41+
OBJC_REQUIRE_CAPABILITY(OBJC_CAP_TYPE_DEPENDENT_DISPATCH);
42+
#endif
43+
44+
Typed Selectors
45+
---------------
46+
47+
Like the GCC runtime, this runtime uses typed selectors. In recent versions,
48+
message lookup is also dependent on the type of the selector by default. This
49+
can be disabled by not defining the TYPE_DEPENDENT_DISPATCH macro when
50+
building. When using GNU make, you can get name-dependent dispatch by doing:
51+
52+
$ gmake tdd=no
53+
54+
This is strongly discouraged. It will give compatibility with the semantics of
55+
the NeXT, Apple, and GCC runtimes, however these semantics include random stack
56+
corruption from valid code.
57+
58+
There are three functions for dealing with typed selectors. The first two are
59+
direct equivalents of other functions.
60+
61+
SEL sel_registerTypedName_np(const char *selName, const char *types);
62+
63+
sel_registerName() will register an untyped selector. This variant registers a
64+
typed selector, using the specified name and type encoding.
65+
66+
const char *sel_getType_np(SEL aSel);
67+
68+
This function simply returns the type encoding of the given selector, or NULL for a typed selector.
69+
70+
unsigned sel_copyTypes_np(const char *selName,
71+
const char **types,
72+
unsigned count);
73+
74+
This function copies *all* of the type encodings for a given selector name.
75+
Generally, there are not many of these. In a well-written program, there will
76+
be exactly one type encoding for a given selector. In a typical program, there
77+
will be 1-3. It is not worth allocating a buffer on the heap for most cases,
78+
so this function is designed to take a stack buffer.
79+
80+
Unlike other functions in the runtime, this always returns the total number of
81+
type encodings, not the number that were found. This means that you can call
82+
it once with a smallish on-stack buffer and then call it again with a
83+
malloc()'d buffer if there are a lot of encodings for a specific selector, as
84+
follows.
85+
86+
char *t[16];
87+
char *types = t;
88+
unsigned total = sel_copyTypes_np("alloc", types, total);
89+
if (total > 16)
90+
{
91+
types = calloc(sizeof(char*), total);
92+
sel_copyTypes_np("alloc", types, total);
93+
}
94+
// Do stuff with the types.
95+
if (total > 16)
96+
{
97+
free(types);
98+
}
99+
100+
101+
**Note**: This runtime does not provide any equivalent of the GCC runtime's
102+
sel_get_typed_uid() or sel_get_any_typed_uid(). This is intentional. It is
103+
impossible to use these functions correctly and they should never have been
104+
made part of the public API.
105+
106+
Message Sending
107+
---------------
108+
109+
For ABI compatibility with the GCC runtime, this runtime implements the
110+
objc_msg_lookup() and objc_msg_lookup_super() functions used to implement
111+
message sending.
112+
113+
The new ABI uses the objc_msg_lookup_sender() function in place of
114+
objc_msg_lookup(). This allows fast proxies and caching of the lookup result
115+
at the callsite. You can find more a detailed explanation of how this works in
116+
the README file.
117+
118+
This runtime also provides this semi-private function, which can be of use in
119+
implementing parts of the Foundation framework and similar low-level libraries:
120+
121+
struct objc_slot* objc_get_slot(Class cls, SEL selector);
122+
123+
This looks up the slot for a given selector, without invoking any forwarding
124+
mechanisms. This is most useful for quickly finding the type encoding of a
125+
method (e.g. for implementing forwarding). The lookup is as fast as a normal
126+
message lookup, and the types field of the returned slot provides the type
127+
encoding. This is significantly faster than using class_getInstanceMethod(),
128+
which needs to perform a linear search along a list (O(1) vs O(n)).
129+
130+
Hooks
131+
-----
132+
133+
All of the callback hooks provided by this runtime are described in
134+
objc/hooks.h.

objc/Availability.h

+8
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,11 @@
1010
#else
1111
# define OBJC_DEPRECATED __attribute__((deprecated))
1212
#endif
13+
14+
#ifdef ERROR_UNSUPPORTED_RUNTIME_FUNCTIONS
15+
# define OBJC_GNUSTEP_RUNTIME_UNSUPPORTED(x) \
16+
__attribute__((error(x " not supported by this runtime")))
17+
#else
18+
# define OBJC_GNUSTEP_RUNTIME_UNSUPPORTED(x)
19+
#endif
20+

objc/capabilities.h

+7-1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,12 @@
1212
* although they are present in the header and understood by the runtime, they
1313
* may not be supported by the installed runtime.
1414
*/
15+
#include "Availability.h"
16+
17+
#ifndef __GNUSTEP_RUNTIME__
18+
# define __GNUSTEP_RUNTIME__
19+
#endif
20+
1521

1622
/**
1723
* The runtime supports zero-cost exceptions.
@@ -68,4 +74,4 @@
6874
* Run time feature test. This function returns 1 if the runtime supports the
6975
* specified feature or 0 if it does not.
7076
*/
71-
int objc_test_capability(int x);
77+
int objc_test_capability(int x) OBJC_NONPORTABLE;

objc/runtime.h

+7-18
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
#ifndef __LIBOBJC_RUNTIME_H_INCLUDED__
22
#define __LIBOBJC_RUNTIME_H_INCLUDED__
33

4-
// If __LEGACY_GNU_MODE__ is defined then we include the old GNU runtime header
5-
// instead of this one
6-
#define __GNUSTEP_RUNTIME__
4+
#ifndef __GNUSTEP_RUNTIME__
5+
# define __GNUSTEP_RUNTIME__
6+
#endif
77

88

99

@@ -12,13 +12,6 @@
1212
#include <sys/types.h>
1313
#include "Availability.h"
1414

15-
#ifdef ERROR_UNSUPPORTED_RUNTIME_FUNCTIONS
16-
# define OBJC_GNUSTEP_RUNTIME_UNSUPPORTED(x) \
17-
__attribute__((error(x " not supported by this runtime")))
18-
#else
19-
# define OBJC_GNUSTEP_RUNTIME_UNSUPPORTED(x)
20-
#endif
21-
2215
// Undo GNUstep substitutions
2316
#ifdef class_setVersion
2417
# undef class_setVersion
@@ -260,8 +253,10 @@ Class object_setClass(id obj, Class cls);
260253

261254
const char *object_getClassName(id obj);
262255

263-
IMP objc_msg_lookup(id, SEL);
264-
IMP objc_msg_lookup_super(struct objc_super*, SEL);
256+
IMP objc_msg_lookup(id, SEL) OBJC_NONPORTABLE;
257+
IMP objc_msg_lookup_super(struct objc_super*, SEL) OBJC_NONPORTABLE;
258+
259+
const char *property_getName(objc_property_t property);
265260

266261
BOOL protocol_conformsToProtocol(Protocol *p, Protocol *other);
267262

@@ -316,12 +311,6 @@ const char *sel_getType_np(SEL aSel) OBJC_NONPORTABLE;
316311
*/
317312
unsigned sel_copyTypes_np(const char *selName, const char **types, unsigned count) OBJC_NONPORTABLE;
318313

319-
/**
320-
* Copies all of the type encodings associated with a given selector name into
321-
* types, returning the number of types.
322-
*/
323-
unsigned sel_copyTypes(const char *selName, const char **types, unsigned count);
324-
325314
/**
326315
* New ABI lookup function. Receiver may be modified during lookup or proxy
327316
* forwarding and the sender may affect how lookup occurs.

properties.m

+4
Original file line numberDiff line numberDiff line change
@@ -172,3 +172,7 @@ objc_property_t class_getProperty(Class cls, const char *name)
172172
return list;
173173
}
174174

175+
const char *property_getName(objc_property_t property)
176+
{
177+
return property->name;
178+
}

0 commit comments

Comments
 (0)