4 #include "../../objc-obj-c++-shared/runtime.h"
6 /* The following header, together with the implementation included below,
7 emulate functionality provided by the GNU runtime but not available from
9 #include "../../objc-obj-c++-shared/objc-test-suite-next-encode-assist.h"
11 #if defined(__NEXT_RUNTIME__) && !defined(NEXT_OBJC_USE_NEW_INTERFACE)
12 void print_ivars (Class
class)
14 struct objc_ivar_list
* ivars
= class->ivars
;
17 for (i
= 0; i
< ivars
->ivar_count
; i
++) {
18 struct objc_ivar
*ivar
= &(ivars
->ivar_list
[i
]);
19 printf ("ivar '%s', type '%s', offset %d\n",
20 ivar
->ivar_name
, ivar
->ivar_type
, ivar
->ivar_offset
);
24 void compare_structures (Class
class, const char* type
)
26 struct objc_struct_layout layout
;
27 struct objc_ivar_list
* ivars
= class->ivars
;
31 objc_layout_structure (type
, &layout
);
33 while (objc_layout_structure_next_member (&layout
))
35 struct objc_ivar
*ivar
;
36 const char *ivar_type
;
38 if (i
> ivars
->ivar_count
)
40 printf ("too many ivars in type %s, layout = %s\n",
45 ivar
= &(ivars
->ivar_list
[i
]);
46 objc_layout_structure_get_info (&layout
, &position
, NULL
, &ivar_type
);
47 printf ("real ivar '%s' offset %d\n",
48 ivar
->ivar_name
, ivar
->ivar_offset
);
49 printf ("computed type '%s' offset %d\n", ivar_type
, position
);
50 if (position
!= ivar
->ivar_offset
)
52 printf ("offset %d and computed position %d don't match on ivar '%s'"
54 ivar
->ivar_offset
, position
, ivar
->ivar_name
, i
);
60 printf ("%d ivars checked\n", i
);
63 void print_ivars (Class
class)
65 unsigned int count
, i
;
66 Ivar
*list
= class_copyIvarList (class, &count
);
68 for (i
= 0; i
< count
; i
++) {
69 printf ("ivar '%s', type '%s', offset %ud\n",
70 ivar_getName (list
[i
]),
71 ivar_getTypeEncoding (list
[i
]),
72 (unsigned int)ivar_getOffset (list
[i
]));
76 void compare_structures (Class
class, const char* type
)
78 struct objc_struct_layout layout
;
80 Ivar
*list
= class_copyIvarList (class, &count
);
84 objc_layout_structure (type
, &layout
);
86 while (objc_layout_structure_next_member (&layout
))
88 const char *ivar_type
;
92 printf ("too many ivars in type %s, layout = %s\n",
97 objc_layout_structure_get_info (&layout
, &position
, NULL
, &ivar_type
);
98 printf ("real ivar '%s' offset %ud\n",
99 ivar_getName (list
[i
]), (unsigned int)ivar_getOffset (list
[i
]));
100 printf ("computed type '%s' offset %d\n", ivar_type
, position
);
101 if ((unsigned int)position
!= (unsigned int)ivar_getOffset (list
[i
]))
103 printf ("offset %ud and computed position %d don't match on ivar '%s'"
105 (unsigned int)ivar_getOffset (list
[i
]), position
, ivar_getName (list
[i
]), i
);
111 printf ("%d ivars checked\n", i
);
122 Class
class = objc_getClass ("MyObject");
123 printf ("type = %s\n", @
encode (struct class_vars
));
126 compare_structures (class, @
encode(struct class_vars
));
127 if ((size1
= objc_sizeof_type (@
encode(struct class_vars
)))
128 != (size2
= sizeof (struct class_vars
)))
130 printf ("sizes don't match (computed %d, exact %d)\n", size1
, size2
);
136 #include "../../objc-obj-c++-shared/objc-test-suite-next-encode-assist-impl.h"