1 /* Make sure that array arguments to methods are given the size of pointers. */
2 /* As in the case of ivars, arrays without size (e.g., 'int []') are
3 encoded as pointers as well. */
4 /* Contributed by Ziemowit Laski <zlaski@apple.com>. */
8 #ifdef __NEXT_RUNTIME__
9 #include <objc/objc-runtime.h>
10 #define OBJC_GETCLASS objc_getClass
11 #define CLASS_GETINSTANCEMETHOD class_getInstanceMethod
13 #include <objc/objc-api.h>
14 #define OBJC_GETCLASS objc_get_class
15 #define CLASS_GETINSTANCEMETHOD class_get_instance_method
18 extern int sscanf(const char *str, const char *format, ...);
19 extern void abort(void);
20 #define CHECK_IF(expr) if(!(expr)) abort()
22 enum Enum { one, two, three, four };
25 - (const char *)str:(signed char [])arg1 with:(unsigned char *)arg2 and:(enum Enum[4])en;
26 - (int)meth1:(int [])arg1 with:(int [0])arg2 with:(int [2])arg3;
29 @implementation ArrayTest
30 - (int)meth1:(int [])arg1 with:(int [0])arg2 with:(int [2])arg3 { return 0; }
31 - (const char *)str:(signed char [])arg1 with:(unsigned char *)arg2 and:(enum Enum[4])en { return "str"; }
35 struct objc_method *meth;
36 unsigned totsize, offs0, offs1, offs2, offs3, offs4, offs5, offs6, offs7;
38 static void scan_initial(const char *pattern) {
39 totsize = offs0 = offs1 = offs2 = offs3 = offs4 = offs5 = offs6 = offs7 = (unsigned)-1;
40 sscanf(meth->method_types, pattern, &totsize, &offs0, &offs1, &offs2, &offs3,
41 &offs4, &offs5, &offs6, &offs7);
42 CHECK_IF(!offs0 && offs1 == sizeof(id) && offs2 == offs1 + sizeof(SEL) && totsize >= offs2);
46 cls = OBJC_GETCLASS("ArrayTest");
48 meth = CLASS_GETINSTANCEMETHOD(cls, @selector(str:with:and:));
49 scan_initial("r*%u@%u:%u*%u*%u[4i]%u");
50 CHECK_IF(offs3 == offs2 + sizeof(signed char *) && offs4 == offs3 + sizeof(unsigned char *));
51 CHECK_IF(totsize == offs4 + sizeof(enum Enum *));
52 meth = CLASS_GETINSTANCEMETHOD(cls, @selector(meth1:with:with:));
53 scan_initial("i%u@%u:%u^i%u[0i]%u[2i]%u");
54 CHECK_IF(offs3 == offs2 + sizeof(int *) && offs4 == offs3 + sizeof(int *));
55 CHECK_IF(totsize == offs4 + sizeof(int *));