summaryrefslogtreecommitdiff
path: root/gcc/testsuite/objc.dg/libobjc-selector-1.m
blob: 49947d7b8722fedfade09e7cfc493c74cdcf9866 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
/* Test a little inefficiency that was fixed in libobjc when dealing
   with selectors (PR libobjc/45953).  */

/* { dg-do run } */
/* { dg-skip-if "" { *-*-* } { "-fnext-runtime" } { "" } } */

/* To get the modern GNU Objective-C Runtime API, you include
   objc/runtime.h.  */
#include <objc/runtime.h>
#include <stdlib.h>

/* Test that registering a new selector, with the same name but a
   different type than the previous one, does not change the original
   name string.  It is actually fine to change it (there is no
   guarantee that it won't change), except for runtime performance /
   memory consumption, since changing it means that the runtime is
   doing an unneeded objc_malloc()/strcpy(), which is inefficient.  */

int main (void)
{
  SEL selector_1;
  SEL selector_2;
  const char *name_1;
  const char *name_2;

  /* These method type strings may well be invalid.  Please don't use
     them as examples.  They are irrelevant for this test; any string
     will do.  */
  selector_1 = sel_registerTypedName ("method", "v@:");
  name_1 = sel_getName (selector_1);

  selector_2 = sel_registerTypedName ("method", "i@:");
  name_2 = sel_getName (selector_1);

  if (name_1 != name_2)
    abort ();

  return 0;
}