[Mono-bugs] [Bug 79312][Nor] Changed - returning a struct by value giving unexpected results

bugzilla-daemon at bugzilla.ximian.com bugzilla-daemon at bugzilla.ximian.com
Thu Sep 7 23:09:53 EDT 2006


Please do not reply to this email- if you want to comment on the bug, go to the
URL shown below and enter your comments there.

Changed by jonpryor at vt.edu.

http://bugzilla.ximian.com/show_bug.cgi?id=79312

--- shadow/79312	2006-09-07 21:07:15.000000000 -0400
+++ shadow/79312.tmp.25334	2006-09-07 23:09:53.000000000 -0400
@@ -384,6 +384,35 @@
 No. Struct (composite) return values are always marshaled as
 defined by the ABI.
 
 
 ------- Additional Comments From james.eberle at comcast.net  2006-09-07 21:07 -------
 Thanks, Robert, for clearing all this up.
+
+------- Additional Comments From jonpryor at vt.edu  2006-09-07 23:09 -------
+> I would really like to avoid that, since I'm wrapping many Carbon 
+> functions, and would like to maintain type safety. 
+
+There are three solutions to provide type safety instead of using IntPtr.
+
+1. Copy the IntPtr into another structure, as suggested by Robert Jordan.
+
+2. Use unsafe code + pointers:
+
+struct EventLoop {};
+struct HI {
+  [DllImport (...)]
+  public static unsafe EventLoop* GetCurrentEventLoop();
+}
+
+The downside is that this is not CLS compliant.
+
+3. If you can target .NET 2.0 APIs, you can eventually use SafeHandles.
+
+class EventLoopHandle : SafeHandle {...}
+struct HI {
+  [DllImport (...)]
+  public static extern EventLoopHandle GetCurrentEventLoop ();
+}
+
+The downside is that Mono doesn't currently support this feature, but
+it should eventually (and perhaps you can help implement it if desired ;-)


More information about the mono-bugs mailing list