[Mono-dev] Fwd: COM Callable Wrapper Patch

Jon Chambers joncham at gmail.com
Fri Nov 17 14:13:33 EST 2006


I had sent a previous patch for supporting COM Callable Wrappers in mono. I
removed the patch as it was too large to send, and probably to large to
review. I'm breaking it down into a series of smaller patches, and here is
the first. There is some managed changes that are somewhat minor. The big
part of this patch is to put a level of indirection in the creation of
managed->unmanaged wrappers. Right now, a delegate class is needed. I
created another function to seperate out all the delegate specific code.
Then, I can use this new function to create wrappers for managed methods for
COM without a delegate class for each.

BTW, you can read the text below if you want an idea of the overall changes
I will be proposing. All code is code is contributed under the MIT/X11
license. I also understand that this may have to wait until 1.2.* is out the
door. Please let me know if the patch is acceptable and when I can commit
it.

Thanks,
Jonathan

---------- Forwarded message ----------
From: Jon Chambers <joncham at gmail.com>
Date: Nov 10, 2006 11:41 PM
Subject: COM Callable Wrapper Patch
To: Mono Devel List < mono-devel-list at lists.ximian.com>

     This patch adds support for COM Callable Wrappers to mono (exposing
managed objects as COM objects to unmanaged code). I started to clean up
some other cominterop work, but it just made the patch harder to read. So, I
only put new methods at the bottom of the marshal.c file with the long term
goal of all cominterop related methods located there or in another file. I
also implemented/modified alot of the marshalling code to support COM
Interop in both directions. Anyway, there are 2 changes that affect the
runtime in non-cominterop cases. The first is the addition of the
mono_marshal_emit_managed_wrapper. This method incorporates alot of the
functionality contained in the existing mono_marshal_get_managed_wrapper.
Basically, all the delegate specific code is in
mono_marshal_get_managed_wrapper, and the general code for wrapping a
managed method is located in mono_marshal_emit_managed_wrapper so I can
create function pointers for the COM vtable without having a delegate type
for each method. If there is a better approach let me know.
     The second change that affects the runtime is gc.c. Basically, any
managed object can be passed to unmanaged code. At that point, an unmanaged
representation of the managed object is created. This needs cleaned up when
the object is garbage collected. So, I register the object for finalization.
In the finalizer code, I check to see if the object has a ccw. There is a
quick return if no CCW's have been created, so while there is a function
call the hash table lookup only occurs if the program actually uses CCWs.
     As previously mentioned, I would like to clean up the COM Interop code
(mainly by grouping together at the bottom) and inserting some #ifdefs to
allow COM support to be not enabled in the runtime to save space. I'll do
this in some future patches if no one objects. Also, I am pretty sure I need
some more locking around this code for thread safety. I'll also take a look
at that for a future patch.
     Finally, for debugging I find myself putting alot of printf's into the
code. Can leave them in either via
#ifdef DEBUG_COMINTEROP
printf (...)
#endif

or

DEBUG_COMINTEROP (printf (...))

at least during this beginning stage when I'm debugging alot (or someone
give a better suggestion)?

Please review and comment. There are tests added as well for this
functionality with some more to come. As usual, this code is contributed
under the MIT/X11 license, and I signed off in the ChangeLogs within the
runtime code.

Thanks,
Jonathan
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.ximian.com/pipermail/mono-devel-list/attachments/20061117/ddacf779/attachment.html 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: ccw_1.diff
Type: text/x-patch
Size: 18203 bytes
Desc: not available
Url : http://lists.ximian.com/pipermail/mono-devel-list/attachments/20061117/ddacf779/attachment.bin 


More information about the Mono-devel-list mailing list