[Python.NET] Updates to callconvutil.cs for .NET 2.0

Greg Chapman glc at well.com
Mon Sep 19 22:50:17 CEST 2005


Michael Eddington wrote:

> Anyone else out there started to mess with Python.NET on the 2.0
> platform?  One of the first hurtles was the output from ildasm does
> not always place the method name on the next line, causing
> callconvutil to place the modopt in the wrong place.  I've added a
> regex in to check for and split the method line if the function name
> is found.

Here's something I just discovered.  You can now (in .NET 2.0) apply
the UnmanagedFunctionPointer attribute to delegate types to get them to
work as cdecl.  For example:

[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
public delegate IntPtr UnaryFunc(IntPtr ob);

>From what I can tell, that delegate type is compatible with any managed
method with the right signature.  When called from unmanaged code, such
delegates will use the cdecl convention (this must be done in some kind
of thunk, since the method itself still uses the normal .NET calling
convention).

Anyway, the upshot is it looks like you can apply that attribute to all
the CallConvCDecl delegates in Interop.cs (removing the CallConvCDecl
attribute, since it's not needed), and then not need callconvutil at
all.

-- 
Greg Chapman




More information about the PythonDotNet mailing list