1#ifndef __NEXT_RUNTIME__ 2#include <objc/encoding.h> 3#endif 4#include "next_mapping.h" 5 6void print_ivars (Class class) 7{ 8 struct objc_ivar_list* ivars = class->ivars; 9 int i; 10 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); 15 } 16} 17 18void compare_structures (Class class, const char* type) 19{ 20 struct objc_struct_layout layout; 21 struct objc_ivar_list* ivars = class->ivars; 22 int i = 0; 23 int position; 24 25 objc_layout_structure (type, &layout); 26 27 while (objc_layout_structure_next_member (&layout)) 28 { 29 struct objc_ivar *ivar; 30 const char *ivar_type; 31 32 if (i > ivars->ivar_count) 33 { 34 printf ("too many ivars in type %s, layout = %s\n", 35 type, layout.type); 36 exit (1); 37 } 38 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) 45 { 46 printf ("offset %d and computed position %d don't match on ivar '%s'" 47 " (i = %d)\n", 48 ivar->ivar_offset, position, ivar->ivar_name, i); 49 exit (1); 50 } 51 i++; 52 } 53 54 printf ("%d ivars checked\n", i); 55} 56 57int main () 58{ 59 struct class_vars 60 { 61 @defs (MyObject); 62 }; 63 int size1, size2; 64 Class class = objc_get_class ("MyObject"); 65 66 printf ("type = %s\n", @encode (struct class_vars)); 67 print_ivars (class); 68 69 compare_structures (class, @encode(struct class_vars)); 70 if ((size1 = objc_sizeof_type (@encode(struct class_vars))) 71 != (size2 = sizeof (struct class_vars))) 72 { 73 printf ("sizes don't match (computed %d, exact %d)\n", size1, size2); 74 abort (); 75 } 76 77 exit (0); 78} 79