2 #include "../../objc-obj-c++-shared/next-mapping.h"
3 #ifndef __NEXT_RUNTIME__
4 #include <objc/encoding.h>
7 void print_ivars (Class
class)
9 struct objc_ivar_list
* ivars
= class->ivars
;
12 for (i
= 0; i
< ivars
->ivar_count
; i
++) {
13 struct objc_ivar
*ivar
= &(ivars
->ivar_list
[i
]);
14 printf ("ivar '%s', type '%s', offset %d\n",
15 ivar
->ivar_name
, ivar
->ivar_type
, ivar
->ivar_offset
);
19 void compare_structures (Class
class, const char* type
)
21 struct objc_struct_layout layout
;
22 struct objc_ivar_list
* ivars
= class->ivars
;
26 objc_layout_structure (type
, &layout
);
28 while (objc_layout_structure_next_member (&layout
))
30 struct objc_ivar
*ivar
;
31 const char *ivar_type
;
33 if (i
> ivars
->ivar_count
)
35 printf ("too many ivars in type %s, layout = %s\n",
40 ivar
= &(ivars
->ivar_list
[i
]);
41 objc_layout_structure_get_info (&layout
, &position
, NULL
, &ivar_type
);
42 printf ("real ivar '%s' offset %d\n",
43 ivar
->ivar_name
, ivar
->ivar_offset
);
44 printf ("computed type '%s' offset %d\n", ivar_type
, position
);
45 if (position
!= ivar
->ivar_offset
)
47 printf ("offset %d and computed position %d don't match on ivar '%s'"
49 ivar
->ivar_offset
, position
, ivar
->ivar_name
, i
);
55 printf ("%d ivars checked\n", i
);
65 Class
class = objc_get_class ("MyObject");
67 printf ("type = %s\n", @
encode (struct class_vars
));
70 compare_structures (class, @
encode(struct class_vars
));
71 if ((size1
= objc_sizeof_type (@
encode(struct class_vars
)))
72 != (size2
= sizeof (struct class_vars
)))
74 printf ("sizes don't match (computed %d, exact %d)\n", size1
, size2
);