id object_copy(id obj, size_t size) { Class cls = object_getClass(obj); id cpy = class_createInstance(cls, size - class_getInstanceSize(cls)); memcpy(((char*)cpy + sizeof(id)), ((char*)obj + sizeof(id)), size - sizeof(id)); return cpy; }
OBJCRT_EXPORT void* object_getIndexedIvars(id obj) { return (void*)((uint8_t*)obj + OBJC_ID_PADDED(class_getInstanceSize(object_getClass(obj)))); }
void ConvertIvarList(Class c, const ivar_list_t* list) { LOG << list->count << " ivars within\n"; for (size_t i = 0; i < list->count; i++) { auto* v = &list->ivar_list[i]; int align = __builtin_ffs(v->alignment) - 1; LOG << "Ivar: name: " << v->name << "; type: " << v->type << "; offset: " << *v->offset << "; size: " << v->size << "; alignment: " << v->alignment << std::endl; class_addIvar(c, v->name, v->size, v->alignment, v->type); Ivar ivar = class_getInstanceVariable(c, v->name); if (ivar) { *v->offset = ivar_getOffset(ivar); LOG << "Ivar registered, ivar_getOffset() = " << ivar_getOffset(ivar) << " in " << class_getInstanceSize(c) << std::endl; } assert(ivar != nullptr); // assert(ivar_getOffset(ivar) == *v->offset); } }