1 #ifndef __NEXT_RUNTIME__
2 #include <objc/encoding.h>
4 #include "next_mapping.h"
6 void print_ivars (Class
class)
8 struct objc_ivar_list
* ivars
= class->ivars
;
11 for (i
= 0; i
< ivars
->ivar_count
; i
++) {
12 struct objc_ivar
*ivar
= &(ivars
->ivar_list
[i
]);
13 printf ("ivar '%s', type '%s', offset %d\n",
14 ivar
->ivar_name
, ivar
->ivar_type
, ivar
->ivar_offset
);
18 void compare_structures (Class
class, const char* type
)
20 struct objc_struct_layout layout
;
21 struct objc_ivar_list
* ivars
= class->ivars
;
25 objc_layout_structure (type
, &layout
);
27 while (objc_layout_structure_next_member (&layout
))
29 struct objc_ivar
*ivar
;
30 const char *ivar_type
;
32 if (i
> ivars
->ivar_count
)
34 printf ("too many ivars in type %s, layout = %s\n",
39 ivar
= &(ivars
->ivar_list
[i
]);
40 objc_layout_structure_get_info (&layout
, &position
, NULL
, &ivar_type
);
41 printf ("real ivar '%s' offset %d\n",
42 ivar
->ivar_name
, ivar
->ivar_offset
);
43 printf ("computed type '%s' offset %d\n", ivar_type
, position
);
44 if (position
!= ivar
->ivar_offset
)
46 printf ("offset %d and computed position %d don't match on ivar '%s'"
48 ivar
->ivar_offset
, position
, ivar
->ivar_name
, i
);
54 printf ("%d ivars checked\n", i
);
64 Class
class = objc_get_class ("MyObject");
66 printf ("type = %s\n", @
encode (struct class_vars
));
69 compare_structures (class, @
encode(struct class_vars
));
70 if ((size1
= objc_sizeof_type (@
encode(struct class_vars
)))
71 != (size2
= sizeof (struct class_vars
)))
73 printf ("sizes don't match (computed %d, exact %d)\n", size1
, size2
);