关于书中187页:objc_msgSendSuper2的第一个参数并不是一个Objective-C对象问题

书中的187页描述:

“objc_msgSendSuper2的第一个参数并不是一个Objective-C对象,我不清楚这到底是LLDB的bug,还是情况确实如此”。

从 objc-abi.h 的接口来看:

/// Specifies the superclass of an instance. 
struct objc_super {
    /// Specifies an instance of a class.
    __unsafe_unretained id receiver;

    /// Specifies the particular superclass of the instance to message. 
#if !defined(__cplusplus)  &&  !__OBJC2__
    /* For compatibility with old objc-runtime.h header */
    __unsafe_unretained Class class;
#else
    __unsafe_unretained Class super_class;
#endif
    /* super_class is the first class to search */
};
#endif

OBJC_EXPORT id objc_msgSendSuper2(struct objc_super *super, SEL op, ...)

第一个参数是一个单纯的struct,没有继承 objc_object / objc_class。

结合调用 super 的代码:

// [super class]
((Class (*)(__rw_objc_super *, SEL))(void *)objc_msgSendSuper)((__rw_objc_super){ (id)self, (id)class_getSuperclass(objc_getClass("Dog")) }, sel_registerName("class"))

应该是 “ 情况确实如此 ” 吧。

1 个赞