Bug 487 - ByRef strings are currently not supported
Summary: ByRef strings are currently not supported
Alias: None
Product: MonoMac
Classification: Desktop
Component: Bindings ()
Version: GIT
Hardware: Other Mac OS
: --- normal
Target Milestone: ---
Assignee: Geoff Norton
Depends on:
Reported: 2011-08-26 23:08 UTC by Alex Soto
Modified: 2015-02-09 20:10 UTC (History)
6 users (show)

Is this bug a regression?: ---
Last known good build:

Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.

Please create a new report on Developer Community or GitHub with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:

Description Alex Soto 2011-08-26 23:08:50 UTC
As posted in MonoMac bu Mattiello Josep
NSFormatter uses a lot of output parameters of types like NSString **. I've found that when NSError** 's are used mono uses "out NSError". I've tried doing the same with bote "out string" and "out NSString" but I continue to get bus errors with the following.

       [Export ("isPartialStringValid:newEditingString:errorDescription:")]
       public bool IsPartialStringValid(string partialString, out string newString, out string error){
           error = "";
           newString = "";

           if(partialString.Length <= this.length)
               return true;

           newString = partialString.Substring(0, this.length);

           return false;

I've also tried with out NSString newString where newString = new NSString("foo");
I only get a bus error when encountering the false case immediately after return. I'm assuming that Cocoa isn't able to understand the memory passed to it. I haven't been able to backtrack in gdb, maybe I'm doing it wrong.

Any help would be greatly appreciated. This is driving me nuts. And the NSFormatter class is actually incomplete on a method that also uses NSString** so I'll pass any input forward to fix that.

Many thanks,
- Joe
Comment 1 Geoff Norton 2011-08-26 23:18:37 UTC
Can someone please upload a compilable testcase against the latest monomac and I'll fix it all up?

Comment 2 Miguel de Icaza [MSFT] 2011-08-29 16:20:22 UTC
Alex, I am setting this bug to NEEDINFO until you provide a test case.
Comment 3 Todd Aspeotis 2013-05-03 23:14:36 UTC
I just "guessed" at this signature by trying to convert the arguments 1:1. From observation, it works.

Original signature:

- (BOOL)isPartialStringValid:(NSString *)partialString newEditingString:(NSString **)newString errorDescription:(NSString **)error

My signature:

        [Export ("isPartialStringValid:newEditingString:errorDescription:")]
        public bool IsPartialStringValid(NSString partialString, ref NSString newString, ref NSString error)

Not sure if it's correct/the most correct signature, but it would seem that MonoMac can handle NSString** just fine.

I am somewhat confused by the title of this bug and then the bug report: "ByRef strings are currently not supported" and then OP uses "out" instead of "ref".
Comment 4 Timothy Risi 2015-02-09 20:10:49 UTC
Closing based on comment 3 and lack of test case