@@ -30,10 +30,11 @@ void methodIMP(ffi_cif *cfi,void *ret,void **args, void*userdata){
3030 __unsafe_unretained id target = *(__unsafe_unretained id *)args[0 ];
3131 SEL sel = *(SEL *)args[1 ];
3232 BOOL classMethod = object_isClass (target);
33- NSMethodSignature *sig = [target methodSignatureForSelector: sel];
34- NSMutableArray <MFValue *> *argValues = [NSMutableArray array ];
35- for (NSUInteger i = 2 ; i < sig.numberOfArguments ; i++) {
36- MFValue *argValue = [[MFValue alloc ] initTypeEncode: [sig getArgumentTypeAtIndex: i] pointer: args[i]];
33+ NSArray <ORTypeVarPair *> *paramTypes = methodImp.declare .parameterTypes ;
34+ FATAL_CHECK (cfi->nargs == 2 + paramTypes.count , @" ffi_cif nargs mismatch with parameterTypes" );
35+ NSMutableArray <MFValue *> *argValues = [NSMutableArray arrayWithCapacity: paramTypes.count];
36+ for (NSUInteger i = 0 ; i < paramTypes.count ; i++) {
37+ MFValue *argValue = [[MFValue alloc ] initTypeEncode: paramTypes[i].typeEncode pointer: args[i + 2 ]];
3738 // 针对系统传入的block,检查一次签名,如果没有,将在结构体中添加签名信息.
3839 if (argValue.isObject && argValue.isBlockValue && argValue.objectValue != nil ) {
3940 struct MFSimulateBlock *bb = (void *)argValue->realBaseValue .pointerValue ;
@@ -43,7 +44,7 @@ void methodIMP(ffi_cif *cfi,void *ret,void **args, void*userdata){
4344 argValue.pointer = &copied;
4445 }
4546 if (NSBlockHasSignature(argValue.objectValue ) == NO ) {
46- ORTypeVarPair *blockdecl = methodImp. declare . parameterTypes [i - 2 ];
47+ ORTypeVarPair *blockdecl = paramTypes[i ];
4748 if ([blockdecl.var isKindOfClass: [ORFuncVariable class ]]) {
4849 NSBlockSetSignature (argValue.objectValue, blockdecl.blockSignature);
4950 }
@@ -67,7 +68,7 @@ void methodIMP(ffi_cif *cfi,void *ret,void **args, void*userdata){
6768 returnValue = [methodImp execute: scope];
6869 if (returnValue.type != TypeVoid && returnValue.pointer != NULL ){
6970 // 类型转换
70- [returnValue writePointer: ret typeEncode: [sig methodReturnType ] ];
71+ [returnValue writePointer: ret typeEncode: methodImp.declare.returnType.typeEncode ];
7172 }
7273
7374 if (ctx.isDeallocScope ) {
@@ -112,22 +113,20 @@ void getterImp(ffi_cif *cfi,void *ret,void **args, void*userdata){
112113 SEL sel = *(SEL *)args[1 ];
113114 ORPropertyDeclare *propDef = (__bridge ORPropertyDeclare *)userdata;
114115 NSString *propName = propDef.var .var .varname ;
115- NSMethodSignature *sig = [target methodSignatureForSelector: sel];
116116 __autoreleasing MFValue *propValue = objc_getAssociatedObject (target, mf_propKey (propName));
117117 if (!propValue) {
118118 propValue = [MFValue defaultValueWithTypeEncoding: propDef.var.typeEncode];
119119 }
120120 if (propValue.type != TypeVoid && propValue.pointer != NULL ){
121- [propValue writePointer: ret typeEncode: sig.methodReturnType ];
121+ [propValue writePointer: ret typeEncode: propDef.var.typeEncode ];
122122 }
123123}
124124
125125void setterImp (ffi_cif *cfi,void *ret,void **args, void *userdata){
126126 id target = *(__strong id *)args[0 ];
127- SEL sel = *(SEL *)args[1 ];
128- const char *argTypeEncode = [[target methodSignatureForSelector: sel] getArgumentTypeAtIndex: 2 ];
129- MFValue *value = [MFValue valueWithTypeEncode: argTypeEncode pointer: args[2 ]];
130127 ORPropertyDeclare *propDef = (__bridge ORPropertyDeclare *)userdata;
128+ const char *argTypeEncode = propDef.var .typeEncode ;
129+ MFValue *value = [MFValue valueWithTypeEncode: argTypeEncode pointer: args[2 ]];
131130 NSString *propName = propDef.var .var .varname ;
132131 MFPropertyModifier modifier = propDef.modifier ;
133132 if (modifier & MFPropertyModifierMemWeak) {
0 commit comments