Artifact de7b955371913963c8c188091427e2fde8dfa7603caf26cf54b0e4bcf080c03c:
- File
src/OFInvocation.m
— part of check-in
[2f4e0df8be]
at
2017-10-17 00:33:37
on branch trunk
— Do not use implicit method return types
Instead, explicitly declare them, as OF_ASSUME_NONNULL_{BEGIN,END} does
not apply to implicit return types. This means that after this commit,
all init methods have a nonnull return type, as they should have. (user: js, size: 2853) [annotate] [blame] [check-ins using]
/* * Copyright (c) 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017 * Jonathan Schleifer <js@heap.zone> * * All rights reserved. * * This file is part of ObjFW. It may be distributed under the terms of the * Q Public License 1.0, which can be found in the file LICENSE.QPL included in * the packaging of this file. * * Alternatively, it may be distributed under the terms of the GNU General * Public License, either version 2 or 3, which can be found in the file * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this * file. */ #include "config.h" #include <string.h> #import "OFInvocation.h" #import "OFArray.h" #import "OFData.h" #import "OFMethodSignature.h" #ifdef OF_INVOCATION_CAN_INVOKE extern void of_invocation_invoke(OFInvocation *); #endif @implementation OFInvocation @synthesize methodSignature = _methodSignature; + (instancetype)invocationWithMethodSignature: (OFMethodSignature *)signature { return [[[self alloc] initWithMethodSignature: signature] autorelease]; } - (instancetype)initWithMethodSignature: (OFMethodSignature *)signature { self = [super init]; @try { void *pool = objc_autoreleasePoolPush(); size_t numberOfArguments = [signature numberOfArguments]; const char *typeEncoding; size_t typeSize; _methodSignature = [signature retain]; _arguments = [[OFMutableArray alloc] init]; for (size_t i = 0; i < numberOfArguments; i++) { OFMutableData *data; typeEncoding = [_methodSignature argumentTypeAtIndex: i]; typeSize = of_sizeof_type_encoding(typeEncoding); data = [OFMutableData dataWithItemSize: typeSize capacity: 1]; [data increaseCountBy: 1]; [_arguments addObject: data]; } typeEncoding = [_methodSignature methodReturnType]; typeSize = of_sizeof_type_encoding(typeEncoding); _returnValue = [[OFMutableData alloc] initWithItemSize: typeSize capacity: 1]; [_returnValue increaseCountBy: 1]; objc_autoreleasePoolPop(pool); } @catch (id e) { [self release]; @throw e; } return self; } - (void)dealloc { [_methodSignature release]; [_arguments release]; [_returnValue release]; [super dealloc]; } - (void)setArgument: (const void *)buffer atIndex: (size_t)index { OFMutableData *data = [_arguments objectAtIndex: index]; memcpy([data items], buffer, [data itemSize]); } - (void)getArgument: (void *)buffer atIndex: (size_t)index { OFData *data = [_arguments objectAtIndex: index]; memcpy(buffer, [data items], [data itemSize]); } - (void)setReturnValue: (const void *)buffer { memcpy([_returnValue items], buffer, [_returnValue itemSize]); } - (void)getReturnValue: (void *)buffer { memcpy(buffer, [_returnValue items], [_returnValue itemSize]); } #ifdef OF_INVOCATION_CAN_INVOKE - (void)invoke { of_invocation_invoke(self); } #endif @end