1 #import <objc/runtime.h>
7 const char *property_getAttributes(objc_property_t property
) {
8 return property
->attributes
;
11 const char *property_getName(objc_property_t property
) {
12 return property
->name
;
15 id
objc_assign_ivar(id self
, id value
, unsigned int offset
) {
16 // NSCLog("objc_assign_ivar(%x,%s,%x,%s,%d)",self,(self!=nil)?self->isa->name:"nil",value,(value!=nil)?value->isa->name:"nil",offset);
17 id
*ivar
= (id
*)(((uint8_t *)self
) + offset
);
21 void objc_copyStruct(void *dest
, const void *src
, size_t size
, BOOL atomic
, BOOL hasStrong
) {
24 for(i
= 0; i
< size
; i
++)
25 ((uint8_t *)dest
)[i
] = ((uint8_t *)src
)[i
];
28 void objc_setProperty(id self
, SEL _cmd
, size_t offset
, id value
, BOOL isAtomic
, BOOL shouldCopy
) {
30 // NSUnimplementedFunction();
32 void *buffer
= (void *)self
+ offset
;
33 id oldValue
= *(id
*)buffer
;
35 static SEL copySelector
= NULL
;
36 static SEL retainSelector
= NULL
;
37 static SEL releaseSelector
= NULL
;
39 if(copySelector
== NULL
)
40 copySelector
= sel_getUid("copy");
41 if(retainSelector
== NULL
)
42 retainSelector
= sel_getUid("retain");
43 if(releaseSelector
== NULL
)
44 releaseSelector
= sel_getUid("releaseSelector");
46 SEL useSelector
= shouldCopy
? copySelector
: retainSelector
;
47 struct objc_method
*assignMethod
= class_getClassMethod(object_getClass(value
), useSelector
);
49 if(assignMethod
!= NULL
)
50 value
= assignMethod
->method_imp(value
, useSelector
);
52 *(id
*)buffer
= value
;
54 struct objc_method
*releaseMethod
= class_getClassMethod(object_getClass(oldValue
), releaseSelector
);
55 if(releaseMethod
!= NULL
)
56 releaseMethod
->method_imp(oldValue
, releaseSelector
);
59 id
objc_getProperty(id self
, SEL _cmd
, size_t offset
, BOOL isAtomic
) {
61 // NSUnimplementedFunction();
64 void *buffer
= (void *)self
+ offset
;
65 id value
= *(id
*)buffer
;