[Gtk-sharp-list] Upcoming problems.

Miguel de Icaza miguel@ximian.com
26 May 2003 18:53:21 -0400


Hello guys,

   We recently found out that Dllimport signatures like this:

	[Dllimport ("")]
	extern static string method ();

   Carry an explicit invocation to 'free' on the result value returned
by the unmanaged code.  This is done to avoid leaks. 

   Of course, this does not work with a bunch of places where we return
pointers to static memory (or what is flagged as "const" memory in some
header files).   

   To handle this case, the signature must be changed to use IntPtr to
make the return opaque, and then extract the string with
PtrToStringAuto:

   [DllImport ("")]
   extern static IntPtr method ();

   MyRoutine ()
   {
	IntPtr r = method ();
	string s = Marshal.PtrToStringAuto (r);
   }
   
   The bad news is that there are 162 cases like this on the binding,
and we are going to need Mike's help to fix this.

   We have disabled the code that frees the strings in Mono in the
meantime.

Miguel.