"Too many arguments to function call" with xCode 12

Any idea why such error when Apple Silicon enabled?
Too many arguments to function call, expected 0, have 3
On line id serializedObject = deserializedObjectFromObjectIMP( cls, @selector(deserializedObjectFromObject), [ dict objectForKey: @"object" ] );


  • (id)deserializedObjectFromDictionary: (NSDictionary *)dict

{
NSString *className = [ dict objectForKey: @"class" ];
Class cls = NSClassFromString( [ self classNameForSerializedClassName: className ] );
if( cls == nil ){
[ NSException raise: NSInvalidArgumentException format: @"Cannot deserialize instances of class %@ : Class not found.", className ];
return nil;
}

IMP
deserializedObjectFromObjectIMP = DMObjectSerializationFindImplementationForSelector( cls, @selector(deserializedObjectFromObject:) );
if( deserializedObjectFromObjectIMP == NULL ){
[ NSException raise: NSInvalidArgumentException format: @"Cannot deserialize instances of class %@ : Class does not respond to deserializedObjectFromObject.", className ];
return nil;
}

  id serializedObject =
deserializedObjectFromObjectIMP( cls, @selector(deserializedObjectFromObject), [ dict objectForKey: @"object" ] );
return serializedObject;
Answered by OOPer in 646624022
Seems the definition of IMP has changed in the recent SDK.
(I'm not sure Apple Silicon has something to do with the change or not.)

You can try to declare the function type explicitly:
Code Block
id (*_deserializedObjectFromObject_IMP)(id, SEL, id) = _DMObjectSerialization_FindImplementationForSelector( cls, @selector(_deserializedObjectFromObject:) );



Please use the code formatter shown as < >.

Accepted Answer
Seems the definition of IMP has changed in the recent SDK.
(I'm not sure Apple Silicon has something to do with the change or not.)

You can try to declare the function type explicitly:
Code Block
id (*_deserializedObjectFromObject_IMP)(id, SEL, id) = _DMObjectSerialization_FindImplementationForSelector( cls, @selector(_deserializedObjectFromObject:) );



Please use the code formatter shown as < >.

Seems to work... what about this other case?
Same error on NSMethodSignature *ret = instanceMethodForSelectorIMP( self->targetObjectClass, @selector(instanceMethodSignatureForSelector:), aSelector );
  • (NSMethodSignature *)methodSignatureForSelector: (SEL)aSelector

{
 //DEBUGLOG( @"" );
 id obj = [ self resolveTargetObject ];
 if( obj == nil ){
  Method instanceMethod = classgetClassMethod( self->targetObjectClass, @selector(instanceMethodSignatureForSelector:) );
  IMP instanceMethodForSelectorIMP = method
getImplementation( instanceMethod );
   
   //AppleM1 NSMethodSignature *ret = instanceMethodForSelectorIMP( self->targetObjectClass, @selector(instanceMethodSignatureForSelector:), aSelector );
    
   NSMethodSignature *ret = instanceMethodForSelectorIMP( self->targetObjectClass, @selector(instanceMethodSignatureForSelector:), aSelector );
  return ret;
 }
 return [ obj methodSignatureForSelector: aSelector ];
}

Please use the code formatter shown as < >.

"Too many arguments to function call" with xCode 12
 
 
Q