From ec53e8de69ff96f11b5a1e8320d5ccb52e7ce076 Mon Sep 17 00:00:00 2001 From: Mads Marquart Date: Thu, 6 Oct 2022 09:22:12 +0200 Subject: [PATCH] Fix out parameters (except for NSError) Assuming we find a good solution to https://github.com/madsmtm/objc2/pull/277 --- header-translator/src/rust_type.rs | 85 +++++++++++++------ .../src/generated/Foundation/NSAppleScript.rs | 8 +- icrate/src/generated/Foundation/NSCalendar.rs | 6 +- .../Foundation/NSDateComponentsFormatter.rs | 4 +- .../generated/Foundation/NSDateFormatter.rs | 2 +- .../generated/Foundation/NSEnergyFormatter.rs | 4 +- .../src/generated/Foundation/NSFileManager.rs | 6 +- .../src/generated/Foundation/NSFormatter.rs | 12 +-- .../generated/Foundation/NSKeyValueCoding.rs | 4 +- .../generated/Foundation/NSLengthFormatter.rs | 4 +- .../Foundation/NSLinguisticTagger.rs | 10 +-- .../generated/Foundation/NSMassFormatter.rs | 4 +- .../generated/Foundation/NSNumberFormatter.rs | 2 +- .../generated/Foundation/NSPathUtilities.rs | 4 +- .../NSPersonNameComponentsFormatter.rs | 4 +- icrate/src/generated/Foundation/NSScanner.rs | 8 +- icrate/src/generated/Foundation/NSStream.rs | 12 +-- icrate/src/generated/Foundation/NSString.rs | 2 +- icrate/src/generated/Foundation/NSURL.rs | 4 +- .../generated/Foundation/NSURLConnection.rs | 2 +- 20 files changed, 111 insertions(+), 76 deletions(-) diff --git a/header-translator/src/rust_type.rs b/header-translator/src/rust_type.rs index 1149bb3db..c66b2dc37 100644 --- a/header-translator/src/rust_type.rs +++ b/header-translator/src/rust_type.rs @@ -575,33 +575,68 @@ impl ToTokens for RustType { nullability, is_const, pointee, - } => { - let tokens = match &**pointee { - Self::Id { - type_, - is_return: _, - is_const, - lifetime: _, - nullability, - } => { - if *nullability == Nullability::NonNull { - quote!(NonNull<#type_>) - } else if *is_const { - quote!(*const #type_) - } else { - quote!(*mut #type_) - } + } => match &**pointee { + Self::Id { + type_: tokens, + is_return: false, + is_const: false, + lifetime: Lifetime::Autoreleasing, + nullability: inner_nullability, + } => { + let tokens = quote!(Id<#tokens, Shared>); + let tokens = if *inner_nullability == Nullability::NonNull { + tokens + } else { + quote!(Option<#tokens>) + }; + + let tokens = if *is_const { + quote!(&#tokens) + } else { + quote!(&mut #tokens) + }; + if *nullability == Nullability::NonNull { + tokens + } else { + quote!(Option<#tokens>) } - pointee => quote!(#pointee), - }; - if *nullability == Nullability::NonNull { - quote!(NonNull<#tokens>) - } else if *is_const { - quote!(*const #tokens) - } else { - quote!(*mut #tokens) } - } + Self::Id { + type_: tokens, + is_return: false, + is_const: false, + lifetime: Lifetime::Unspecified, + nullability: inner_nullability, + } => { + if tokens.name != "NSError" { + println!("id*: {self:?}"); + } + let tokens = if *inner_nullability == Nullability::NonNull { + quote!(NonNull<#tokens>) + } else { + quote!(*mut #tokens) + }; + if *nullability == Nullability::NonNull { + quote!(NonNull<#tokens>) + } else if *is_const { + quote!(*const #tokens) + } else { + quote!(*mut #tokens) + } + } + Self::Id { .. } => { + unreachable!("there should be no id with other values: {self:?}") + } + pointee => { + if *nullability == Nullability::NonNull { + quote!(NonNull<#pointee>) + } else if *is_const { + quote!(*const #pointee) + } else { + quote!(*mut #pointee) + } + } + }, Array { element_type, num_elements, diff --git a/icrate/src/generated/Foundation/NSAppleScript.rs b/icrate/src/generated/Foundation/NSAppleScript.rs index 873174e0b..6d0832277 100644 --- a/icrate/src/generated/Foundation/NSAppleScript.rs +++ b/icrate/src/generated/Foundation/NSAppleScript.rs @@ -18,7 +18,7 @@ impl NSAppleScript { pub unsafe fn initWithContentsOfURL_error( &self, url: &NSURL, - errorInfo: *mut *mut NSDictionary, + errorInfo: Option<&mut Option, Shared>>>, ) -> Option> { msg_send_id![self, initWithContentsOfURL: url, error: errorInfo] } @@ -27,20 +27,20 @@ impl NSAppleScript { } pub unsafe fn compileAndReturnError( &self, - errorInfo: *mut *mut NSDictionary, + errorInfo: Option<&mut Option, Shared>>>, ) -> bool { msg_send![self, compileAndReturnError: errorInfo] } pub unsafe fn executeAndReturnError( &self, - errorInfo: *mut *mut NSDictionary, + errorInfo: Option<&mut Option, Shared>>>, ) -> Id { msg_send_id![self, executeAndReturnError: errorInfo] } pub unsafe fn executeAppleEvent_error( &self, event: &NSAppleEventDescriptor, - errorInfo: *mut *mut NSDictionary, + errorInfo: Option<&mut Option, Shared>>>, ) -> Id { msg_send_id![self, executeAppleEvent: event, error: errorInfo] } diff --git a/icrate/src/generated/Foundation/NSCalendar.rs b/icrate/src/generated/Foundation/NSCalendar.rs index fb8437ccb..ebd88f032 100644 --- a/icrate/src/generated/Foundation/NSCalendar.rs +++ b/icrate/src/generated/Foundation/NSCalendar.rs @@ -67,7 +67,7 @@ impl NSCalendar { pub unsafe fn rangeOfUnit_startDate_interval_forDate( &self, unit: NSCalendarUnit, - datep: *mut *mut NSDate, + datep: Option<&mut Option>>, tip: *mut NSTimeInterval, date: &NSDate, ) -> bool { @@ -273,7 +273,7 @@ impl NSCalendar { } pub unsafe fn rangeOfWeekendStartDate_interval_containingDate( &self, - datep: *mut *mut NSDate, + datep: Option<&mut Option>>, tip: *mut NSTimeInterval, date: &NSDate, ) -> bool { @@ -286,7 +286,7 @@ impl NSCalendar { } pub unsafe fn nextWeekendStartDate_interval_options_afterDate( &self, - datep: *mut *mut NSDate, + datep: Option<&mut Option>>, tip: *mut NSTimeInterval, options: NSCalendarOptions, date: &NSDate, diff --git a/icrate/src/generated/Foundation/NSDateComponentsFormatter.rs b/icrate/src/generated/Foundation/NSDateComponentsFormatter.rs index b24c18994..ed284ef87 100644 --- a/icrate/src/generated/Foundation/NSDateComponentsFormatter.rs +++ b/icrate/src/generated/Foundation/NSDateComponentsFormatter.rs @@ -50,9 +50,9 @@ impl NSDateComponentsFormatter { } pub unsafe fn getObjectValue_forString_errorDescription( &self, - obj: *mut *mut Object, + obj: Option<&mut Option>>, string: &NSString, - error: *mut *mut NSString, + error: Option<&mut Option>>, ) -> bool { msg_send![ self, diff --git a/icrate/src/generated/Foundation/NSDateFormatter.rs b/icrate/src/generated/Foundation/NSDateFormatter.rs index 599af7aba..8a24f3dea 100644 --- a/icrate/src/generated/Foundation/NSDateFormatter.rs +++ b/icrate/src/generated/Foundation/NSDateFormatter.rs @@ -22,7 +22,7 @@ extern_class!( impl NSDateFormatter { pub unsafe fn getObjectValue_forString_range_error( &self, - obj: *mut *mut Object, + obj: Option<&mut Option>>, string: &NSString, rangep: *mut NSRange, error: *mut *mut NSError, diff --git a/icrate/src/generated/Foundation/NSEnergyFormatter.rs b/icrate/src/generated/Foundation/NSEnergyFormatter.rs index 4eef5e1c3..11a887cd8 100644 --- a/icrate/src/generated/Foundation/NSEnergyFormatter.rs +++ b/icrate/src/generated/Foundation/NSEnergyFormatter.rs @@ -37,9 +37,9 @@ impl NSEnergyFormatter { } pub unsafe fn getObjectValue_forString_errorDescription( &self, - obj: *mut *mut Object, + obj: Option<&mut Option>>, string: &NSString, - error: *mut *mut NSString, + error: Option<&mut Option>>, ) -> bool { msg_send![ self, diff --git a/icrate/src/generated/Foundation/NSFileManager.rs b/icrate/src/generated/Foundation/NSFileManager.rs index 45e0af211..618186fe2 100644 --- a/icrate/src/generated/Foundation/NSFileManager.rs +++ b/icrate/src/generated/Foundation/NSFileManager.rs @@ -286,7 +286,7 @@ impl NSFileManager { pub unsafe fn trashItemAtURL_resultingItemURL_error( &self, url: &NSURL, - outResultingURL: *mut *mut NSURL, + outResultingURL: Option<&mut Option>>, error: *mut *mut NSError, ) -> bool { msg_send![ @@ -463,7 +463,7 @@ impl NSFileManager { newItemURL: &NSURL, backupItemName: Option<&NSString>, options: NSFileManagerItemReplacementOptions, - resultingURL: *mut *mut NSURL, + resultingURL: Option<&mut Option>>, error: *mut *mut NSError, ) -> bool { msg_send![ @@ -517,7 +517,7 @@ impl NSFileManager { pub unsafe fn URLForPublishingUbiquitousItemAtURL_expirationDate_error( &self, url: &NSURL, - outDate: *mut *mut NSDate, + outDate: Option<&mut Option>>, error: *mut *mut NSError, ) -> Option> { msg_send_id![ diff --git a/icrate/src/generated/Foundation/NSFormatter.rs b/icrate/src/generated/Foundation/NSFormatter.rs index 2c2f419d6..ad167c183 100644 --- a/icrate/src/generated/Foundation/NSFormatter.rs +++ b/icrate/src/generated/Foundation/NSFormatter.rs @@ -38,9 +38,9 @@ impl NSFormatter { } pub unsafe fn getObjectValue_forString_errorDescription( &self, - obj: *mut *mut Object, + obj: Option<&mut Option>>, string: &NSString, - error: *mut *mut NSString, + error: Option<&mut Option>>, ) -> bool { msg_send![ self, @@ -52,8 +52,8 @@ impl NSFormatter { pub unsafe fn isPartialStringValid_newEditingString_errorDescription( &self, partialString: &NSString, - newString: *mut *mut NSString, - error: *mut *mut NSString, + newString: Option<&mut Option>>, + error: Option<&mut Option>>, ) -> bool { msg_send![ self, @@ -64,11 +64,11 @@ impl NSFormatter { } pub unsafe fn isPartialStringValid_proposedSelectedRange_originalString_originalSelectedRange_errorDescription( &self, - partialStringPtr: NonNull>, + partialStringPtr: &mut Id, proposedSelRangePtr: NSRangePointer, origString: &NSString, origSelRange: NSRange, - error: *mut *mut NSString, + error: Option<&mut Option>>, ) -> bool { msg_send![ self, diff --git a/icrate/src/generated/Foundation/NSKeyValueCoding.rs b/icrate/src/generated/Foundation/NSKeyValueCoding.rs index eea58f859..45b90c887 100644 --- a/icrate/src/generated/Foundation/NSKeyValueCoding.rs +++ b/icrate/src/generated/Foundation/NSKeyValueCoding.rs @@ -20,7 +20,7 @@ impl NSObject { } pub unsafe fn validateValue_forKey_error( &self, - ioValue: NonNull<*mut Object>, + ioValue: &mut Option>, inKey: &NSString, outError: *mut *mut NSError, ) -> bool { @@ -46,7 +46,7 @@ impl NSObject { } pub unsafe fn validateValue_forKeyPath_error( &self, - ioValue: NonNull<*mut Object>, + ioValue: &mut Option>, inKeyPath: &NSString, outError: *mut *mut NSError, ) -> bool { diff --git a/icrate/src/generated/Foundation/NSLengthFormatter.rs b/icrate/src/generated/Foundation/NSLengthFormatter.rs index f57031b05..40e2ddafc 100644 --- a/icrate/src/generated/Foundation/NSLengthFormatter.rs +++ b/icrate/src/generated/Foundation/NSLengthFormatter.rs @@ -37,9 +37,9 @@ impl NSLengthFormatter { } pub unsafe fn getObjectValue_forString_errorDescription( &self, - obj: *mut *mut Object, + obj: Option<&mut Option>>, string: &NSString, - error: *mut *mut NSString, + error: Option<&mut Option>>, ) -> bool { msg_send![ self, diff --git a/icrate/src/generated/Foundation/NSLinguisticTagger.rs b/icrate/src/generated/Foundation/NSLinguisticTagger.rs index 6cae856b7..1ec2edd54 100644 --- a/icrate/src/generated/Foundation/NSLinguisticTagger.rs +++ b/icrate/src/generated/Foundation/NSLinguisticTagger.rs @@ -104,7 +104,7 @@ impl NSLinguisticTagger { unit: NSLinguisticTaggerUnit, scheme: &NSLinguisticTagScheme, options: NSLinguisticTaggerOptions, - tokenRanges: *mut *mut NSArray, + tokenRanges: Option<&mut Option, Shared>>>, ) -> Id, Shared> { msg_send_id![ self, @@ -150,7 +150,7 @@ impl NSLinguisticTagger { range: NSRange, tagScheme: &NSString, opts: NSLinguisticTaggerOptions, - tokenRanges: *mut *mut NSArray, + tokenRanges: Option<&mut Option, Shared>>>, ) -> Id, Shared> { msg_send_id![ self, @@ -188,7 +188,7 @@ impl NSLinguisticTagger { scheme: &NSLinguisticTagScheme, options: NSLinguisticTaggerOptions, orthography: Option<&NSOrthography>, - tokenRanges: *mut *mut NSArray, + tokenRanges: Option<&mut Option, Shared>>>, ) -> Id, Shared> { msg_send_id![ Self::class(), @@ -227,7 +227,7 @@ impl NSLinguisticTagger { tagScheme: &NSString, tokenRange: NSRangePointer, sentenceRange: NSRangePointer, - scores: *mut *mut NSArray, + scores: Option<&mut Option, Shared>>>, ) -> Option, Shared>> { msg_send_id![ self, @@ -259,7 +259,7 @@ impl NSString { scheme: &NSLinguisticTagScheme, options: NSLinguisticTaggerOptions, orthography: Option<&NSOrthography>, - tokenRanges: *mut *mut NSArray, + tokenRanges: Option<&mut Option, Shared>>>, ) -> Id, Shared> { msg_send_id![ self, diff --git a/icrate/src/generated/Foundation/NSMassFormatter.rs b/icrate/src/generated/Foundation/NSMassFormatter.rs index 39b4a1c5f..1eeb09405 100644 --- a/icrate/src/generated/Foundation/NSMassFormatter.rs +++ b/icrate/src/generated/Foundation/NSMassFormatter.rs @@ -42,9 +42,9 @@ impl NSMassFormatter { } pub unsafe fn getObjectValue_forString_errorDescription( &self, - obj: *mut *mut Object, + obj: Option<&mut Option>>, string: &NSString, - error: *mut *mut NSString, + error: Option<&mut Option>>, ) -> bool { msg_send![ self, diff --git a/icrate/src/generated/Foundation/NSNumberFormatter.rs b/icrate/src/generated/Foundation/NSNumberFormatter.rs index 10942f27d..6b8cb7883 100644 --- a/icrate/src/generated/Foundation/NSNumberFormatter.rs +++ b/icrate/src/generated/Foundation/NSNumberFormatter.rs @@ -20,7 +20,7 @@ extern_class!( impl NSNumberFormatter { pub unsafe fn getObjectValue_forString_range_error( &self, - obj: *mut *mut Object, + obj: Option<&mut Option>>, string: &NSString, rangep: *mut NSRange, error: *mut *mut NSError, diff --git a/icrate/src/generated/Foundation/NSPathUtilities.rs b/icrate/src/generated/Foundation/NSPathUtilities.rs index df0f014a3..731daeb29 100644 --- a/icrate/src/generated/Foundation/NSPathUtilities.rs +++ b/icrate/src/generated/Foundation/NSPathUtilities.rs @@ -26,9 +26,9 @@ impl NSString { } pub unsafe fn completePathIntoString_caseSensitive_matchesIntoArray_filterTypes( &self, - outputName: *mut *mut NSString, + outputName: Option<&mut Option>>, flag: bool, - outputArray: *mut *mut NSArray, + outputArray: Option<&mut Option, Shared>>>, filterTypes: Option<&NSArray>, ) -> NSUInteger { msg_send![ diff --git a/icrate/src/generated/Foundation/NSPersonNameComponentsFormatter.rs b/icrate/src/generated/Foundation/NSPersonNameComponentsFormatter.rs index fcc275e02..d6a6e15f5 100644 --- a/icrate/src/generated/Foundation/NSPersonNameComponentsFormatter.rs +++ b/icrate/src/generated/Foundation/NSPersonNameComponentsFormatter.rs @@ -44,9 +44,9 @@ impl NSPersonNameComponentsFormatter { } pub unsafe fn getObjectValue_forString_errorDescription( &self, - obj: *mut *mut Object, + obj: Option<&mut Option>>, string: &NSString, - error: *mut *mut NSString, + error: Option<&mut Option>>, ) -> bool { msg_send![ self, diff --git a/icrate/src/generated/Foundation/NSScanner.rs b/icrate/src/generated/Foundation/NSScanner.rs index 5c3d569c7..5a38e7ca9 100644 --- a/icrate/src/generated/Foundation/NSScanner.rs +++ b/icrate/src/generated/Foundation/NSScanner.rs @@ -80,28 +80,28 @@ impl NSScanner { pub unsafe fn scanString_intoString( &self, string: &NSString, - result: *mut *mut NSString, + result: Option<&mut Option>>, ) -> bool { msg_send![self, scanString: string, intoString: result] } pub unsafe fn scanCharactersFromSet_intoString( &self, set: &NSCharacterSet, - result: *mut *mut NSString, + result: Option<&mut Option>>, ) -> bool { msg_send![self, scanCharactersFromSet: set, intoString: result] } pub unsafe fn scanUpToString_intoString( &self, string: &NSString, - result: *mut *mut NSString, + result: Option<&mut Option>>, ) -> bool { msg_send![self, scanUpToString: string, intoString: result] } pub unsafe fn scanUpToCharactersFromSet_intoString( &self, set: &NSCharacterSet, - result: *mut *mut NSString, + result: Option<&mut Option>>, ) -> bool { msg_send![self, scanUpToCharactersFromSet: set, intoString: result] } diff --git a/icrate/src/generated/Foundation/NSStream.rs b/icrate/src/generated/Foundation/NSStream.rs index ed8d53fe3..5c3f3a3c0 100644 --- a/icrate/src/generated/Foundation/NSStream.rs +++ b/icrate/src/generated/Foundation/NSStream.rs @@ -120,8 +120,8 @@ impl NSStream { pub unsafe fn getStreamsToHostWithName_port_inputStream_outputStream( hostname: &NSString, port: NSInteger, - inputStream: *mut *mut NSInputStream, - outputStream: *mut *mut NSOutputStream, + inputStream: Option<&mut Option>>, + outputStream: Option<&mut Option>>, ) { msg_send![ Self::class(), @@ -134,8 +134,8 @@ impl NSStream { pub unsafe fn getStreamsToHost_port_inputStream_outputStream( host: &NSHost, port: NSInteger, - inputStream: *mut *mut NSInputStream, - outputStream: *mut *mut NSOutputStream, + inputStream: Option<&mut Option>>, + outputStream: Option<&mut Option>>, ) { msg_send![ Self::class(), @@ -150,8 +150,8 @@ impl NSStream { impl NSStream { pub unsafe fn getBoundStreamsWithBufferSize_inputStream_outputStream( bufferSize: NSUInteger, - inputStream: *mut *mut NSInputStream, - outputStream: *mut *mut NSOutputStream, + inputStream: Option<&mut Option>>, + outputStream: Option<&mut Option>>, ) { msg_send![ Self::class(), diff --git a/icrate/src/generated/Foundation/NSString.rs b/icrate/src/generated/Foundation/NSString.rs index 141431c4e..2a1e22991 100644 --- a/icrate/src/generated/Foundation/NSString.rs +++ b/icrate/src/generated/Foundation/NSString.rs @@ -768,7 +768,7 @@ impl NSString { pub unsafe fn stringEncodingForData_encodingOptions_convertedString_usedLossyConversion( data: &NSData, opts: Option<&NSDictionary>, - string: *mut *mut NSString, + string: Option<&mut Option>>, usedLossyConversion: *mut bool, ) -> NSStringEncoding { msg_send![ diff --git a/icrate/src/generated/Foundation/NSURL.rs b/icrate/src/generated/Foundation/NSURL.rs index 063f7e466..b25ff772e 100644 --- a/icrate/src/generated/Foundation/NSURL.rs +++ b/icrate/src/generated/Foundation/NSURL.rs @@ -201,7 +201,7 @@ impl NSURL { } pub unsafe fn getResourceValue_forKey_error( &self, - value: NonNull<*mut Object>, + value: &mut Option>, key: &NSURLResourceKey, error: *mut *mut NSError, ) -> bool { @@ -410,7 +410,7 @@ impl NSURL { impl NSURL { pub unsafe fn getPromisedItemResourceValue_forKey_error( &self, - value: NonNull<*mut Object>, + value: &mut Option>, key: &NSURLResourceKey, error: *mut *mut NSError, ) -> bool { diff --git a/icrate/src/generated/Foundation/NSURLConnection.rs b/icrate/src/generated/Foundation/NSURLConnection.rs index 93b15a657..39d6cb4c9 100644 --- a/icrate/src/generated/Foundation/NSURLConnection.rs +++ b/icrate/src/generated/Foundation/NSURLConnection.rs @@ -87,7 +87,7 @@ pub type NSURLConnectionDownloadDelegate = NSObject; impl NSURLConnection { pub unsafe fn sendSynchronousRequest_returningResponse_error( request: &NSURLRequest, - response: *mut *mut NSURLResponse, + response: Option<&mut Option>>, error: *mut *mut NSError, ) -> Option> { msg_send_id![