[Mono-dev] SIGSEGV in Cairo.CairoAPI:cairo_get/set_matrix()
Jonathan Pryor
jonpryor at vt.edu
Mon Oct 31 21:37:39 EST 2005
On Mon, 2005-10-31 at 18:54 -0700, Peter Dennis Bartok wrote:
> >Regarding use of ref/out/neither: I think use of ref or out is
> >*required*. It seems that (most) cairo calls involving matrices expect a
> >cairo_matrix_t* argument. As I understand it, this means that these
> That is correct, cairo expects a pointer (aka reference), not the actual
> value, therefore ref (or [in, out]) is required. If you drop the ref you
> will be passing by value (ie putting the whole struct on the stack, instead
> of just the pointer)
Just to mention (for completeness), Matrix_T could instead be a class
with a [StructLayout (LayoutKind.Sequential)] attribute applied to the
class. This would marshal as a pointer, meaning:
1. You wouldn't need `ref' or `out' anymore
2. You can't pass any instances by value
Given that you're always passing parameters by pointer, this may be a
desirable feature. Beware class types as DllImport return values
though, since the runtime expects to free the memory returned from the
DllImported function using platform-specific mechanisms.
See also:
http://www.mono-project.com/Interop_with_Native_Libraries#Summary
http://www.mono-project.com/Interop_with_Native_Libraries#Classes_and_Structures_as_Return_Values
(With a cautionary note that the above is probably partially wrong --
Marshal.PtrToStructure() probably works with classes as well as structs.
I have to test that.)
- Jon
More information about the Mono-devel-list
mailing list