| 1 |
/* Test a little inefficiency that was fixed in libobjc when dealing |
| 2 |
with selectors (PR libobjc/45953). */ |
| 3 |
|
| 4 |
/* { dg-do run } */ |
| 5 |
/* { dg-skip-if "" { *-*-* } { "-fnext-runtime" } { "" } } */ |
| 6 |
|
| 7 |
/* To get the modern GNU Objective-C Runtime API, you include |
| 8 |
objc/runtime.h. */ |
| 9 |
#include <objc/runtime.h> |
| 10 |
#include <stdlib.h> |
| 11 |
|
| 12 |
/* Test that registering a new selector, with the same name but a |
| 13 |
different type than the previous one, does not change the original |
| 14 |
name string. It is actually fine to change it (there is no |
| 15 |
guarantee that it won't change), except for runtime performance / |
| 16 |
memory consumption, since changing it means that the runtime is |
| 17 |
doing an unneeded objc_malloc()/strcpy(), which is inefficient. */ |
| 18 |
|
| 19 |
int main (void) |
| 20 |
{ |
| 21 |
SEL selector_1; |
| 22 |
SEL selector_2; |
| 23 |
const char *name_1; |
| 24 |
const char *name_2; |
| 25 |
|
| 26 |
/* These method type strings may well be invalid. Please don't use |
| 27 |
them as examples. They are irrelevant for this test; any string |
| 28 |
will do. */ |
| 29 |
selector_1 = sel_registerTypedName ("method", "v@:"); |
| 30 |
name_1 = sel_getName (selector_1); |
| 31 |
|
| 32 |
selector_2 = sel_registerTypedName ("method", "i@:"); |
| 33 |
name_2 = sel_getName (selector_1); |
| 34 |
|
| 35 |
if (name_1 != name_2) |
| 36 |
abort (); |
| 37 |
|
| 38 |
return 0; |
| 39 |
} |