[Mono-dev] HandleRef regression in mono 1.2.3

Miguel de Icaza miguel at novell.com
Sun Feb 11 08:17:36 EST 2007


Hello Jonathan,

> I beg to differ -- HandleRef has been implemented for quite some time,
> and was initially used in Mono.Unix.Native.FilePosition in revision
> 38204 (~2004, iirc).  I used HandleRef in it because my tests had shown
> it to work, and this was *after* I had written that section of
> http://www.mono-project.com/Dllimport.
> 
> In fact, I still have the program I used to test/validate HandleRef
> support, and it's dated October 8, *2003*.  (I have *got* to clear out
> my ~/tmp directory some year....)

The class 'HandleRef' has been implemented forever, you did get that
right.   But the semantics in the runtime to make it do the right thing
were not.

The class HandleRef is a struct, that contains:

	public struct HandleRef {
                object wrapper;
                IntPtr handle;
	}

If you have a function that takes a HandleRef, say:

	extern static void write_char (HandleRef r, int char)

The runtime was supposed to pass r.handle, not a copy of r.

Special support is required for HandleRef in the runtime to know that it
should not marshal "HandleRef" as every other struct, but by passing the
value stored in handle. 

For example, try the handleref.cs test that I just added in
mono/mono/tests and bring with you the libtest.c, in previous versions
it would not have worked.

And if it did, it was by mere luck (maybe the 'wrapper' object was
ignored, maybe it was copied later), but the runtime never had it
implemented (see HandleRef documentation in MSDN).

Miguel.



More information about the Mono-devel-list mailing list