From 8a762d447813db1b1c3fe52b24e638581235460e Mon Sep 17 00:00:00 2001 From: Muxi Yan Date: Thu, 15 Nov 2018 12:56:08 -0800 Subject: [PATCH] Polish nullability + something else --- src/objective-c/GRPCClient/GRPCCall.h | 28 +++++------ src/objective-c/GRPCClient/GRPCCall.m | 4 +- src/objective-c/GRPCClient/GRPCCallOptions.h | 46 +++++++++---------- .../GRPCClient/private/GRPCChannel.h | 2 +- .../GRPCClient/private/GRPCChannel.m | 10 ++-- .../GRPCClient/private/GRPCChannelFactory.h | 4 +- .../GRPCClient/private/GRPCChannelPool.m | 2 +- .../private/GRPCConnectivityMonitor.m | 4 +- .../private/GRPCCronetChannelFactory.m | 22 +++------ .../private/GRPCInsecureChannelFactory.m | 10 ++-- .../private/GRPCSecureChannelFactory.m | 22 ++++----- src/objective-c/ProtoRPC/ProtoRPC.h | 12 ++--- src/objective-c/ProtoRPC/ProtoRPC.m | 14 +++--- src/objective-c/tests/InteropTests.m | 8 ++-- 14 files changed, 86 insertions(+), 102 deletions(-) diff --git a/src/objective-c/GRPCClient/GRPCCall.h b/src/objective-c/GRPCClient/GRPCCall.h index bde69f01c52..fcda4dc8acd 100644 --- a/src/objective-c/GRPCClient/GRPCCall.h +++ b/src/objective-c/GRPCClient/GRPCCall.h @@ -159,14 +159,14 @@ extern NSString *const kGRPCTrailersKey; * Issued when initial metadata is received from the server. The task must be scheduled onto the * dispatch queue in property \a dispatchQueue. */ -- (void)receivedInitialMetadata:(NSDictionary *_Nullable)initialMetadata; +- (void)receivedInitialMetadata:(nullable NSDictionary *)initialMetadata; /** * Issued when a message is received from the server. The message is the raw data received from the * server, with decompression and without proto deserialization. The task must be scheduled onto the * dispatch queue in property \a dispatchQueue. */ -- (void)receivedRawMessage:(NSData *_Nullable)message; +- (void)receivedRawMessage:(nullable NSData *)message; /** * Issued when a call finished. If the call finished successfully, \a error is nil and \a @@ -175,8 +175,8 @@ extern NSString *const kGRPCTrailersKey; * error descriptions. The task must be scheduled onto the dispatch queue in property * \a dispatchQueue. */ -- (void)closedWithTrailingMetadata:(NSDictionary *_Nullable)trailingMetadata - error:(NSError *_Nullable)error; +- (void)closedWithTrailingMetadata:(nullable NSDictionary *)trailingMetadata + error:(nullable NSError *)error; @required @@ -234,7 +234,7 @@ extern NSString *const kGRPCTrailersKey; */ - (instancetype)initWithRequestOptions:(GRPCRequestOptions *)requestOptions responseHandler:(id)responseHandler - callOptions:(GRPCCallOptions *_Nullable)callOptions + callOptions:(nullable GRPCCallOptions *)callOptions NS_DESIGNATED_INITIALIZER; /** * Convenience initializer for a call that uses default call options (see GRPCCallOptions.m for @@ -342,9 +342,9 @@ NS_ASSUME_NONNULL_END * host parameter should not contain the scheme (http:// or https://), only the name or IP addr * and the port number, for example @"localhost:5050". */ -- (instancetype _Null_unspecified)initWithHost:(NSString *_Null_unspecified)host - path:(NSString *_Null_unspecified)path - requestsWriter:(GRXWriter *_Null_unspecified)requestWriter; +- (null_unspecified instancetype)initWithHost:(null_unspecified NSString *)host + path:(null_unspecified NSString *)path + requestsWriter:(null_unspecified GRXWriter *)requestWriter; /** * Finishes the request side of this call, notifies the server that the RPC should be cancelled, and @@ -356,11 +356,11 @@ NS_ASSUME_NONNULL_END * The following methods are deprecated. */ + (void)setCallSafety:(GRPCCallSafety)callSafety - host:(NSString *_Null_unspecified)host - path:(NSString *_Null_unspecified)path; + host:(null_unspecified NSString *)host + path:(null_unspecified NSString *)path; @property(null_unspecified, atomic, copy, readwrite) NSString *serverName; @property NSTimeInterval timeout; -- (void)setResponseDispatchQueue:(dispatch_queue_t _Null_unspecified)queue; +- (void)setResponseDispatchQueue:(null_unspecified dispatch_queue_t)queue; @end @@ -371,11 +371,11 @@ DEPRECATED_MSG_ATTRIBUTE("Use NSDictionary or NSMutableDictionary instead.") @protocol GRPCRequestHeaders @property(nonatomic, readonly) NSUInteger count; -- (id _Null_unspecified)objectForKeyedSubscript:(id _Null_unspecified)key; -- (void)setObject:(id _Null_unspecified)obj forKeyedSubscript:(id _Null_unspecified)key; +- (null_unspecified id)objectForKeyedSubscript:(null_unspecified id)key; +- (void)setObject:(null_unspecified id)obj forKeyedSubscript:(null_unspecified id)key; - (void)removeAllObjects; -- (void)removeObjectForKey:(id _Null_unspecified)key; +- (void)removeObjectForKey:(null_unspecified id)key; @end #pragma clang diagnostic push diff --git a/src/objective-c/GRPCClient/GRPCCall.m b/src/objective-c/GRPCClient/GRPCCall.m index 788afeb6c3c..68b51d8c846 100644 --- a/src/objective-c/GRPCClient/GRPCCall.m +++ b/src/objective-c/GRPCClient/GRPCCall.m @@ -114,7 +114,7 @@ const char *kCFStreamVarName = "grpc_cfstream"; - (instancetype)initWithRequestOptions:(GRPCRequestOptions *)requestOptions responseHandler:(id)responseHandler - callOptions:(GRPCCallOptions *_Nullable)callOptions { + callOptions:(GRPCCallOptions *)callOptions { NSAssert(requestOptions.host.length != 0 && requestOptions.path.length != 0, @"Neither host nor path can be nil."); NSAssert(requestOptions.safety <= GRPCCallSafetyCacheableRequest, @@ -134,7 +134,7 @@ const char *kCFStreamVarName = "grpc_cfstream"; if (@available(iOS 8.0, *)) { _dispatchQueue = dispatch_queue_create( NULL, - dispatch_queue_attr_make_with_qos_class(DISPATCH_QUEUE_SERIAL, QOS_CLASS_DEFAULT, -1)); + dispatch_queue_attr_make_with_qos_class(DISPATCH_QUEUE_SERIAL, QOS_CLASS_DEFAULT, 0)); } else { // Fallback on earlier versions _dispatchQueue = dispatch_queue_create(NULL, DISPATCH_QUEUE_SERIAL); diff --git a/src/objective-c/GRPCClient/GRPCCallOptions.h b/src/objective-c/GRPCClient/GRPCCallOptions.h index bb8a1d251a9..61d85642863 100644 --- a/src/objective-c/GRPCClient/GRPCCallOptions.h +++ b/src/objective-c/GRPCClient/GRPCCallOptions.h @@ -78,7 +78,7 @@ typedef NS_ENUM(NSUInteger, GRPCTransportType) { * :authority header field of the call and performs an extra check that server's certificate * matches the :authority header. */ -@property(copy, readonly) NSString *serverAuthority; +@property(copy, readonly, nullable) NSString *serverAuthority; /** * The timeout for the RPC call in seconds. If set to 0, the call will not timeout. If set to @@ -94,18 +94,18 @@ typedef NS_ENUM(NSUInteger, GRPCTransportType) { * request's "authorization" header field. This parameter should not be used simultaneously with * \a authTokenProvider. */ -@property(copy, readonly) NSString *oauth2AccessToken; +@property(copy, readonly, nullable) NSString *oauth2AccessToken; /** * The interface to get the OAuth2 access token string. gRPC will attempt to acquire token when * initiating the call. This parameter should not be used simultaneously with \a oauth2AccessToken. */ -@property(readonly) id authTokenProvider; +@property(readonly, nullable) id authTokenProvider; /** * Initial metadata key-value pairs that should be included in the request. */ -@property(copy, readonly) NSDictionary *initialMetadata; +@property(copy, readonly, nullable) NSDictionary *initialMetadata; // Channel parameters; take into account of channel signature. @@ -113,7 +113,7 @@ typedef NS_ENUM(NSUInteger, GRPCTransportType) { * Custom string that is prefixed to a request's user-agent header field before gRPC's internal * user-agent string. */ -@property(copy, readonly) NSString *userAgentPrefix; +@property(copy, readonly, nullable) NSString *userAgentPrefix; /** * The size limit for the response received from server. If it is exceeded, an error with status @@ -152,7 +152,7 @@ typedef NS_ENUM(NSUInteger, GRPCTransportType) { * Specify channel args to be used for this call. For a list of channel args available, see * grpc/grpc_types.h */ -@property(copy, readonly) NSDictionary *additionalChannelArgs; +@property(copy, readonly, nullable) NSDictionary *additionalChannelArgs; // Parameters for SSL authentication. @@ -160,17 +160,17 @@ typedef NS_ENUM(NSUInteger, GRPCTransportType) { * PEM format root certifications that is trusted. If set to nil, gRPC uses a list of default * root certificates. */ -@property(copy, readonly) NSString *PEMRootCertificates; +@property(copy, readonly, nullable) NSString *PEMRootCertificates; /** * PEM format private key for client authentication, if required by the server. */ -@property(copy, readonly) NSString *PEMPrivateKey; +@property(copy, readonly, nullable) NSString *PEMPrivateKey; /** * PEM format certificate chain for client authentication, if required by the server. */ -@property(copy, readonly) NSString *PEMCertChain; +@property(copy, readonly, nullable) NSString *PEMCertChain; /** * Select the transport type to be used for this call. @@ -180,13 +180,13 @@ typedef NS_ENUM(NSUInteger, GRPCTransportType) { /** * Override the hostname during the TLS hostname validation process. */ -@property(copy, readonly) NSString *hostNameOverride; +@property(copy, readonly, nullable) NSString *hostNameOverride; /** * A string that specify the domain where channel is being cached. Channels with different domains * will not get cached to the same connection. */ -@property(copy, readonly) NSString *channelPoolDomain; +@property(copy, readonly, nullable) NSString *channelPoolDomain; /** * Channel id allows control of channel caching within a channelPoolDomain. A call with a unique @@ -199,7 +199,7 @@ typedef NS_ENUM(NSUInteger, GRPCTransportType) { /** * Return if the channel options are equal to another object. */ -- (BOOL)hasChannelOptionsEqualTo:(GRPCCallOptions *)callOptions; +- (BOOL)hasChannelOptionsEqualTo:(nonnull GRPCCallOptions *)callOptions; /** * Hash for channel options. @@ -219,7 +219,7 @@ typedef NS_ENUM(NSUInteger, GRPCTransportType) { * :authority header field of the call and performs an extra check that server's certificate * matches the :authority header. */ -@property(copy, readwrite) NSString *serverAuthority; +@property(copy, readwrite, nullable) NSString *serverAuthority; /** * The timeout for the RPC call in seconds. If set to 0, the call will not timeout. If set to @@ -236,18 +236,18 @@ typedef NS_ENUM(NSUInteger, GRPCTransportType) { * request's "authorization" header field. This parameter should not be used simultaneously with * \a authTokenProvider. */ -@property(copy, readwrite) NSString *oauth2AccessToken; +@property(copy, readwrite, nullable) NSString *oauth2AccessToken; /** * The interface to get the OAuth2 access token string. gRPC will attempt to acquire token when * initiating the call. This parameter should not be used simultaneously with \a oauth2AccessToken. */ -@property(readwrite) id authTokenProvider; +@property(readwrite, nullable) id authTokenProvider; /** * Initial metadata key-value pairs that should be included in the request. */ -@property(copy, readwrite) NSDictionary *initialMetadata; +@property(copy, readwrite, nullable) NSDictionary *initialMetadata; // Channel parameters; take into account of channel signature. @@ -255,7 +255,7 @@ typedef NS_ENUM(NSUInteger, GRPCTransportType) { * Custom string that is prefixed to a request's user-agent header field before gRPC's internal * user-agent string. */ -@property(copy, readwrite) NSString *userAgentPrefix; +@property(copy, readwrite, nullable) NSString *userAgentPrefix; /** * The size limit for the response received from server. If it is exceeded, an error with status @@ -296,7 +296,7 @@ typedef NS_ENUM(NSUInteger, GRPCTransportType) { * Specify channel args to be used for this call. For a list of channel args available, see * grpc/grpc_types.h */ -@property(copy, readwrite) NSDictionary *additionalChannelArgs; +@property(copy, readwrite, nullable) NSDictionary *additionalChannelArgs; // Parameters for SSL authentication. @@ -304,17 +304,17 @@ typedef NS_ENUM(NSUInteger, GRPCTransportType) { * PEM format root certifications that is trusted. If set to nil, gRPC uses a list of default * root certificates. */ -@property(copy, readwrite) NSString *PEMRootCertificates; +@property(copy, readwrite, nullable) NSString *PEMRootCertificates; /** * PEM format private key for client authentication, if required by the server. */ -@property(copy, readwrite) NSString *PEMPrivateKey; +@property(copy, readwrite, nullable) NSString *PEMPrivateKey; /** * PEM format certificate chain for client authentication, if required by the server. */ -@property(copy, readwrite) NSString *PEMCertChain; +@property(copy, readwrite, nullable) NSString *PEMCertChain; /** * Select the transport type to be used for this call. @@ -324,7 +324,7 @@ typedef NS_ENUM(NSUInteger, GRPCTransportType) { /** * Override the hostname during the TLS hostname validation process. */ -@property(copy, readwrite) NSString *hostNameOverride; +@property(copy, readwrite, nullable) NSString *hostNameOverride; /** * A string that specify the domain where channel is being cached. Channels with different domains @@ -332,7 +332,7 @@ typedef NS_ENUM(NSUInteger, GRPCTransportType) { * domain 'io.grpc.example' so that its calls do not reuse the channel created by other modules in * the same process. */ -@property(copy, readwrite) NSString *channelPoolDomain; +@property(copy, readwrite, nullable) NSString *channelPoolDomain; /** * Channel id allows a call to force creating a new channel (connection) rather than using a cached diff --git a/src/objective-c/GRPCClient/private/GRPCChannel.h b/src/objective-c/GRPCClient/private/GRPCChannel.h index 32e68bb2625..4dbe0c276ce 100644 --- a/src/objective-c/GRPCClient/private/GRPCChannel.h +++ b/src/objective-c/GRPCClient/private/GRPCChannel.h @@ -85,7 +85,7 @@ NS_ASSUME_NONNULL_BEGIN - (nullable grpc_call *)unmanagedCallWithPath:(NSString *)path completionQueue:(GRPCCompletionQueue *)queue callOptions:(GRPCCallOptions *)callOptions - disconnected:(BOOL *_Nullable)disconnected; + disconnected:(nullable BOOL *)disconnected; /** * Unref the channel when a call is done. It also decreases the channel's refcount. If the refcount diff --git a/src/objective-c/GRPCClient/private/GRPCChannel.m b/src/objective-c/GRPCClient/private/GRPCChannel.m index ab084fba480..de3302598ef 100644 --- a/src/objective-c/GRPCClient/private/GRPCChannel.m +++ b/src/objective-c/GRPCClient/private/GRPCChannel.m @@ -39,7 +39,7 @@ static const NSTimeInterval kDefaultChannelDestroyDelay = 30; @implementation GRPCChannelConfiguration -- (nullable instancetype)initWithHost:(NSString *)host callOptions:(GRPCCallOptions *)callOptions { +- (instancetype)initWithHost:(NSString *)host callOptions:(GRPCCallOptions *)callOptions { NSAssert(host.length, @"Host must not be empty."); NSAssert(callOptions != nil, @"callOptions must not be empty."); if ((self = [super init])) { @@ -143,7 +143,7 @@ static const NSTimeInterval kDefaultChannelDestroyDelay = 30; return args; } -- (nonnull id)copyWithZone:(nullable NSZone *)zone { +- (id)copyWithZone:(NSZone *)zone { GRPCChannelConfiguration *newConfig = [[GRPCChannelConfiguration alloc] initWithHost:_host callOptions:_callOptions]; @@ -184,13 +184,13 @@ static const NSTimeInterval kDefaultChannelDestroyDelay = 30; } @synthesize disconnected = _disconnected; -- (nullable instancetype)initWithChannelConfiguration: +- (instancetype)initWithChannelConfiguration: (GRPCChannelConfiguration *)channelConfiguration { return [self initWithChannelConfiguration:channelConfiguration destroyDelay:kDefaultChannelDestroyDelay]; } -- (nullable instancetype)initWithChannelConfiguration: +- (instancetype)initWithChannelConfiguration: (GRPCChannelConfiguration *)channelConfiguration destroyDelay:(NSTimeInterval)destroyDelay { NSAssert(channelConfiguration != nil, @@ -201,7 +201,7 @@ static const NSTimeInterval kDefaultChannelDestroyDelay = 30; if (@available(iOS 8.0, *)) { _dispatchQueue = dispatch_queue_create( NULL, - dispatch_queue_attr_make_with_qos_class(DISPATCH_QUEUE_SERIAL, QOS_CLASS_DEFAULT, -1)); + dispatch_queue_attr_make_with_qos_class(DISPATCH_QUEUE_SERIAL, QOS_CLASS_DEFAULT, 0)); } else { _dispatchQueue = dispatch_queue_create(NULL, DISPATCH_QUEUE_SERIAL); } diff --git a/src/objective-c/GRPCClient/private/GRPCChannelFactory.h b/src/objective-c/GRPCClient/private/GRPCChannelFactory.h index 3a3500fc95e..a934e966e9d 100644 --- a/src/objective-c/GRPCClient/private/GRPCChannelFactory.h +++ b/src/objective-c/GRPCClient/private/GRPCChannelFactory.h @@ -26,8 +26,8 @@ NS_ASSUME_NONNULL_BEGIN @protocol GRPCChannelFactory /** Create a channel with specific channel args to a specific host. */ -- (grpc_channel *_Nullable)createChannelWithHost:(NSString *)host - channelArgs:(NSDictionary *_Nullable)args; +- (nullable grpc_channel *)createChannelWithHost:(NSString *)host + channelArgs:(nullable NSDictionary *)args; @end diff --git a/src/objective-c/GRPCClient/private/GRPCChannelPool.m b/src/objective-c/GRPCClient/private/GRPCChannelPool.m index 6745010bd49..72554ca6dc8 100644 --- a/src/objective-c/GRPCClient/private/GRPCChannelPool.m +++ b/src/objective-c/GRPCClient/private/GRPCChannelPool.m @@ -41,7 +41,7 @@ static dispatch_once_t gInitChannelPool; NSMutableDictionary *_channelPool; } -+ (nullable instancetype)sharedInstance { ++ (instancetype)sharedInstance { dispatch_once(&gInitChannelPool, ^{ gChannelPool = [[GRPCChannelPool alloc] init]; NSAssert(gChannelPool != nil, @"Cannot initialize global channel pool."); diff --git a/src/objective-c/GRPCClient/private/GRPCConnectivityMonitor.m b/src/objective-c/GRPCClient/private/GRPCConnectivityMonitor.m index a36788b35aa..bb8618ff335 100644 --- a/src/objective-c/GRPCClient/private/GRPCConnectivityMonitor.m +++ b/src/objective-c/GRPCClient/private/GRPCConnectivityMonitor.m @@ -76,14 +76,14 @@ static void ReachabilityCallback(SCNetworkReachabilityRef target, SCNetworkReach } } -+ (void)registerObserver:(_Nonnull id)observer selector:(SEL)selector { ++ (void)registerObserver:(id)observer selector:(SEL)selector { [[NSNotificationCenter defaultCenter] addObserver:observer selector:selector name:kGRPCConnectivityNotification object:nil]; } -+ (void)unregisterObserver:(_Nonnull id)observer { ++ (void)unregisterObserver:(id)observer { [[NSNotificationCenter defaultCenter] removeObserver:observer]; } diff --git a/src/objective-c/GRPCClient/private/GRPCCronetChannelFactory.m b/src/objective-c/GRPCClient/private/GRPCCronetChannelFactory.m index 781881d211b..74ea9723b3d 100644 --- a/src/objective-c/GRPCClient/private/GRPCCronetChannelFactory.m +++ b/src/objective-c/GRPCClient/private/GRPCCronetChannelFactory.m @@ -26,13 +26,11 @@ #import #include -NS_ASSUME_NONNULL_BEGIN - @implementation GRPCCronetChannelFactory { stream_engine *_cronetEngine; } -+ (instancetype _Nullable)sharedInstance { ++ (instancetype)sharedInstance { static GRPCCronetChannelFactory *instance; static dispatch_once_t onceToken; dispatch_once(&onceToken, ^{ @@ -41,7 +39,7 @@ NS_ASSUME_NONNULL_BEGIN return instance; } -- (instancetype _Nullable)initWithEngine:(stream_engine *)engine { +- (instancetype)initWithEngine:(stream_engine *)engine { if (!engine) { [NSException raise:NSInvalidArgumentException format:@"Cronet engine is NULL. Set it first."]; return nil; @@ -52,8 +50,8 @@ NS_ASSUME_NONNULL_BEGIN return self; } -- (grpc_channel *_Nullable)createChannelWithHost:(NSString *)host - channelArgs:(NSDictionary *_Nullable)args { +- (grpc_channel *)createChannelWithHost:(NSString *)host + channelArgs:(NSDictionary *)args { grpc_channel_args *channelArgs = GRPCBuildChannelArgs(args); grpc_channel *unmanagedChannel = grpc_cronet_secure_channel_create(_cronetEngine, host.UTF8String, channelArgs, NULL); @@ -63,22 +61,18 @@ NS_ASSUME_NONNULL_BEGIN @end -NS_ASSUME_NONNULL_END - #else -NS_ASSUME_NONNULL_BEGIN - @implementation GRPCCronetChannelFactory -+ (instancetype _Nullable)sharedInstance { ++ (instancetype)sharedInstance { [NSException raise:NSInvalidArgumentException format:@"Must enable macro GRPC_COMPILE_WITH_CRONET to build Cronet channel."]; return nil; } -- (grpc_channel *_Nullable)createChannelWithHost:(NSString *)host - channelArgs:(NSDictionary *_Nullable)args { +- (grpc_channel *)createChannelWithHost:(NSString *)host + channelArgs:(NSDictionary *)args { [NSException raise:NSInvalidArgumentException format:@"Must enable macro GRPC_COMPILE_WITH_CRONET to build Cronet channel."]; return NULL; @@ -86,6 +80,4 @@ NS_ASSUME_NONNULL_BEGIN @end -NS_ASSUME_NONNULL_END - #endif diff --git a/src/objective-c/GRPCClient/private/GRPCInsecureChannelFactory.m b/src/objective-c/GRPCClient/private/GRPCInsecureChannelFactory.m index 99698877124..3e9ebe7ae02 100644 --- a/src/objective-c/GRPCClient/private/GRPCInsecureChannelFactory.m +++ b/src/objective-c/GRPCClient/private/GRPCInsecureChannelFactory.m @@ -21,11 +21,9 @@ #import "ChannelArgsUtil.h" #import "GRPCChannel.h" -NS_ASSUME_NONNULL_BEGIN - @implementation GRPCInsecureChannelFactory -+ (instancetype _Nullable)sharedInstance { ++ (instancetype)sharedInstance { static GRPCInsecureChannelFactory *instance; static dispatch_once_t onceToken; dispatch_once(&onceToken, ^{ @@ -34,8 +32,8 @@ NS_ASSUME_NONNULL_BEGIN return instance; } -- (grpc_channel *_Nullable)createChannelWithHost:(NSString *)host - channelArgs:(NSDictionary *_Nullable)args { +- (grpc_channel *)createChannelWithHost:(NSString *)host + channelArgs:(NSDictionary *)args { grpc_channel_args *coreChannelArgs = GRPCBuildChannelArgs([args copy]); grpc_channel *unmanagedChannel = grpc_insecure_channel_create(host.UTF8String, coreChannelArgs, NULL); @@ -44,5 +42,3 @@ NS_ASSUME_NONNULL_BEGIN } @end - -NS_ASSUME_NONNULL_END diff --git a/src/objective-c/GRPCClient/private/GRPCSecureChannelFactory.m b/src/objective-c/GRPCClient/private/GRPCSecureChannelFactory.m index f5e7a2b9e20..2e7f1a0dbe2 100644 --- a/src/objective-c/GRPCClient/private/GRPCSecureChannelFactory.m +++ b/src/objective-c/GRPCClient/private/GRPCSecureChannelFactory.m @@ -24,15 +24,13 @@ #import "GRPCChannel.h" #import "utilities.h" -NS_ASSUME_NONNULL_BEGIN - @implementation GRPCSecureChannelFactory { grpc_channel_credentials *_channelCreds; } -+ (instancetype _Nullable)factoryWithPEMRootCertificates:(NSString *_Nullable)rootCerts - privateKey:(NSString *_Nullable)privateKey - certChain:(NSString *_Nullable)certChain ++ (instancetype)factoryWithPEMRootCertificates:(NSString *)rootCerts + privateKey:(NSString *)privateKey + certChain:(NSString *)certChain error:(NSError **)errorPtr { return [[self alloc] initWithPEMRootCerts:rootCerts privateKey:privateKey @@ -40,7 +38,7 @@ NS_ASSUME_NONNULL_BEGIN error:errorPtr]; } -- (NSData *_Nullable)nullTerminatedDataWithString:(NSString *_Nullable)string { +- (NSData *)nullTerminatedDataWithString:(NSString *)string { // dataUsingEncoding: does not return a null-terminated string. NSData *data = [string dataUsingEncoding:NSASCIIStringEncoding allowLossyConversion:YES]; if (data == nil) { @@ -51,9 +49,9 @@ NS_ASSUME_NONNULL_BEGIN return nullTerminated; } -- (instancetype _Nullable)initWithPEMRootCerts:(NSString *_Nullable)rootCerts - privateKey:(NSString *_Nullable)privateKey - certChain:(NSString *_Nullable)certChain +- (instancetype)initWithPEMRootCerts:(NSString *)rootCerts + privateKey:(NSString *)privateKey + certChain:(NSString *)certChain error:(NSError **)errorPtr { static NSData *defaultRootsASCII; static NSError *defaultRootsError; @@ -117,8 +115,8 @@ NS_ASSUME_NONNULL_BEGIN return self; } -- (grpc_channel *_Nullable)createChannelWithHost:(NSString *)host - channelArgs:(NSDictionary *_Nullable)args { +- (grpc_channel *)createChannelWithHost:(NSString *)host + channelArgs:(NSDictionary *)args { grpc_channel_args *coreChannelArgs = GRPCBuildChannelArgs([args copy]); grpc_channel *unmanagedChannel = grpc_secure_channel_create(_channelCreds, host.UTF8String, coreChannelArgs, NULL); @@ -133,5 +131,3 @@ NS_ASSUME_NONNULL_BEGIN } @end - -NS_ASSUME_NONNULL_END diff --git a/src/objective-c/ProtoRPC/ProtoRPC.h b/src/objective-c/ProtoRPC/ProtoRPC.h index b0f4ced99e8..dc776368a8f 100644 --- a/src/objective-c/ProtoRPC/ProtoRPC.h +++ b/src/objective-c/ProtoRPC/ProtoRPC.h @@ -33,13 +33,13 @@ NS_ASSUME_NONNULL_BEGIN /** * Issued when initial metadata is received from the server. The task must be scheduled onto the * dispatch queue in property \a dispatchQueue. */ -- (void)receivedInitialMetadata:(NSDictionary *_Nullable)initialMetadata; +- (void)receivedInitialMetadata:(nullable NSDictionary *)initialMetadata; /** * Issued when a message is received from the server. The message is the deserialized proto object. * The task must be scheduled onto the dispatch queue in property \a dispatchQueue. */ -- (void)receivedProtoMessage:(GPBMessage *_Nullable)message; +- (void)receivedProtoMessage:(nullable GPBMessage *)message; /** * Issued when a call finished. If the call finished successfully, \a error is nil and \a @@ -48,8 +48,8 @@ NS_ASSUME_NONNULL_BEGIN * error descriptions. The task must be scheduled onto the dispatch queue in property * \a dispatchQueue. */ -- (void)closedWithTrailingMetadata:(NSDictionary *_Nullable)trailingMetadata - error:(NSError *_Nullable)error; +- (void)closedWithTrailingMetadata:(nullable NSDictionary *)trailingMetadata + error:(nullable NSError *)error; @required @@ -75,7 +75,7 @@ NS_ASSUME_NONNULL_BEGIN - (instancetype)initWithRequestOptions:(GRPCRequestOptions *)requestOptions message:(GPBMessage *)message responseHandler:(id)handler - callOptions:(GRPCCallOptions *_Nullable)callOptions + callOptions:(nullable GRPCCallOptions *)callOptions responseClass:(Class)responseClass NS_DESIGNATED_INITIALIZER; /** @@ -100,7 +100,7 @@ NS_ASSUME_NONNULL_BEGIN */ - (instancetype)initWithRequestOptions:(GRPCRequestOptions *)requestOptions responseHandler:(id)handler - callOptions:(GRPCCallOptions *_Nullable)callOptions + callOptions:(nullable GRPCCallOptions *)callOptions responseClass:(Class)responseClass NS_DESIGNATED_INITIALIZER; /** diff --git a/src/objective-c/ProtoRPC/ProtoRPC.m b/src/objective-c/ProtoRPC/ProtoRPC.m index 34891e8953b..f99da45fef9 100644 --- a/src/objective-c/ProtoRPC/ProtoRPC.m +++ b/src/objective-c/ProtoRPC/ProtoRPC.m @@ -52,7 +52,7 @@ static NSError *ErrorForBadProto(id proto, Class expectedClass, NSError *parsing - (instancetype)initWithRequestOptions:(GRPCRequestOptions *)requestOptions message:(GPBMessage *)message responseHandler:(id)handler - callOptions:(GRPCCallOptions *_Nullable)callOptions + callOptions:(GRPCCallOptions *)callOptions responseClass:(Class)responseClass { if ((self = [super init])) { _call = [[GRPCStreamingProtoCall alloc] initWithRequestOptions:requestOptions @@ -88,7 +88,7 @@ static NSError *ErrorForBadProto(id proto, Class expectedClass, NSError *parsing - (instancetype)initWithRequestOptions:(GRPCRequestOptions *)requestOptions responseHandler:(id)handler - callOptions:(GRPCCallOptions *_Nullable)callOptions + callOptions:(GRPCCallOptions *)callOptions responseClass:(Class)responseClass { if (requestOptions.host.length == 0 || requestOptions.path.length == 0) { [NSException raise:NSInvalidArgumentException format:@"Neither host nor path can be nil."]; @@ -108,7 +108,7 @@ static NSError *ErrorForBadProto(id proto, Class expectedClass, NSError *parsing if (@available(iOS 8.0, *)) { _dispatchQueue = dispatch_queue_create( NULL, - dispatch_queue_attr_make_with_qos_class(DISPATCH_QUEUE_SERIAL, QOS_CLASS_DEFAULT, -1)); + dispatch_queue_attr_make_with_qos_class(DISPATCH_QUEUE_SERIAL, QOS_CLASS_DEFAULT, 0)); } else { _dispatchQueue = dispatch_queue_create(nil, DISPATCH_QUEUE_SERIAL); } @@ -171,7 +171,7 @@ static NSError *ErrorForBadProto(id proto, Class expectedClass, NSError *parsing }); } -- (void)receivedInitialMetadata:(NSDictionary *_Nullable)initialMetadata { +- (void)receivedInitialMetadata:(NSDictionary *)initialMetadata { dispatch_async(_dispatchQueue, ^{ if (initialMetadata != nil && [self->_handler respondsToSelector:@selector(initialMetadata:)]) { [self->_handler receivedInitialMetadata:initialMetadata]; @@ -179,7 +179,7 @@ static NSError *ErrorForBadProto(id proto, Class expectedClass, NSError *parsing }); } -- (void)receivedRawMessage:(NSData *_Nullable)message { +- (void)receivedRawMessage:(NSData *)message { dispatch_async(_dispatchQueue, ^{ if (self->_handler && message != nil) { NSError *error = nil; @@ -202,8 +202,8 @@ static NSError *ErrorForBadProto(id proto, Class expectedClass, NSError *parsing }); } -- (void)closedWithTrailingMetadata:(NSDictionary *_Nullable)trailingMetadata - error:(NSError *_Nullable)error { +- (void)closedWithTrailingMetadata:(NSDictionary *)trailingMetadata + error:(NSError *)error { dispatch_async(_dispatchQueue, ^{ if ([self->_handler respondsToSelector:@selector(closedWithTrailingMetadata:error:)]) { [self->_handler closedWithTrailingMetadata:trailingMetadata error:error]; diff --git a/src/objective-c/tests/InteropTests.m b/src/objective-c/tests/InteropTests.m index c42718f15ee..dcc8f1b589a 100644 --- a/src/objective-c/tests/InteropTests.m +++ b/src/objective-c/tests/InteropTests.m @@ -102,7 +102,7 @@ BOOL isRemoteInteropTest(NSString *host) { return self; } -- (void)receivedInitialMetadata:(NSDictionary *_Nullable)initialMetadata { +- (void)receivedInitialMetadata:(NSDictionary *)initialMetadata { dispatch_async(_dispatchQueue, ^{ if (_initialMetadataCallback) { _initialMetadataCallback(initialMetadata); @@ -110,7 +110,7 @@ BOOL isRemoteInteropTest(NSString *host) { }); } -- (void)receivedProtoMessage:(GPBMessage *_Nullable)message { +- (void)receivedProtoMessage:(GPBMessage *)message { dispatch_async(_dispatchQueue, ^{ if (_messageCallback) { _messageCallback(message); @@ -118,8 +118,8 @@ BOOL isRemoteInteropTest(NSString *host) { }); } -- (void)closedWithTrailingMetadata:(NSDictionary *_Nullable)trailingMetadata - error:(NSError *_Nullable)error { +- (void)closedWithTrailingMetadata:(NSDictionary *)trailingMetadata + error:(NSError *)error { dispatch_async(_dispatchQueue, ^{ if (_closeCallback) { _closeCallback(trailingMetadata, error);