[Mono-dev] Summer of Code / C++ Interop

Alex Corrado alexander.corrado at gmail.com
Fri Apr 9 03:04:25 EDT 2010

Hi Andreas,

On Thu, Apr 8, 2010 at 6:06 AM, Andreas Färber <andreas.faerber at web.de>wrote:

> CSimpleClass.cs looks as if it was written manually. I see a problem with
> changing C++ code there: To allow managed code to instantiate such a class,
> your private struct needs to match exactly the size of the native code. If
> however someone adds a private field in C++ but does not update the interop
> code, it will fail. Would it be possible to leave the memory allocation to
> C++ (the ABI document mentions "nw" in the name-mangling section) and in C#
> just map the methods we actually want to call?
>From my brief review of the ABI document, I think the "nw" function you
mention is only defined when the "new" operator is overridden. Although, if
that operator is overridden, the interop code should probably respect that
and use that function to allocate the memory for the object instead of doing
it manually. (I guess I'll have to add that to the TODO list :).

However, I'm pretty sure that in most cases there is no such function and
that, in C++, the caller usually allocates the memory when instantiating an
object and passes the pointer to the constructor. This is usually pretty
straightforward, since including the header includes the class definition,
which defines the exact size of the class. My eventual goal is to have a
tool that will parse C++ headers and generate the managed interface and
struct for you. At this point, however, the interface does have to be
written manually, and the struct does have to reflect the exact size of the
C++ class.

> For your proposed project, would you be focussing on the p/invoke ABI
> infrastructure only? Any plans for SWIG-like autogeneration of the (C#)
> proxy interfaces from C++ headers? And what about C++ interop inside Mono's
> class libraries?

I think that, for the scope of the Summer of Code, I will focus on making
the implementation of the Itanium ABI more complete. Since this is an open
standard that is implemented by GCC 3.2+, and GCC is the primary C++
compiler on Mac and Linux, this will be a big step for C++ interop in Mono.

Eventually, I'd like to implement a SWIG-like generation of the managed
interfaces from the C++ headers like you mention, and I'd like to implement
the Microsoft Visual C++ ABI as well. But it will probably be quite awhile
until those features are implemented, unless I have some help :). I'm not
sure what you mean by C++ interop inside Mono's class libraries. If you mean
including the interop features I'm developing in the core class libraries,
I'm all for it, but I guess that's up to the Mono maintainers.

I really appreciate your feedback. Please let me know if I can clarify
anything else for you.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.ximian.com/pipermail/mono-devel-list/attachments/20100409/8bc821d7/attachment.html 

More information about the Mono-devel-list mailing list