[Mono-list] PInvoke Conventions

Sam Ruby rubys@us.ibm.com
Thu, 19 Jul 2001 19:38:42 -0400

Miguel de Icaza wrote:
> [DllImport("libc"),PosixProto(int,off_t,int)]
> int lseek (int, long, int)

or even better:

  long lseek (int, long, int)

Such a declaration would work on systems where the number of bits in a "C"
int is in the range of 32 to 64.

Rhys Weatherley wrote:
> This assumes that there will be different library builds for each
> platform.  This may not be too bad for core stuff, but may be a
> hassle for extension libraries.
> The key issue actually isn't how to make PInvoke work, but rather
> to make it work the same.  An application that imports "lseek"
> needs to work regardless of how the call is marshalled to the
> underlying OS.  When the application is compiled, the method
> signature will be placed into it by the compiler.  It can only run
> if the CLR/library exports a method with the correct signature.
> So, autoconf would need to detect the exact system
> characteristics and then write out marshalling information
> to convert the agreed-upon method signature into the
> system-specific one.

I lost track of what you would be "autoconf'ing"... the compiler? The jit?
The runtime libraries?

Not only would separate builds be a hassle... think about what happens when
you bring multiple languages into the picture...  Will the Python to CIL
compiler also need to be autoconf'ed, or does it only need to support
custom attributes?

My 2 cents: it would be highly desirable for the bytecodes produced by a
compiler to be portable, and any necessary mapping done at JIT time
(preferred) or dynamically at runtime.

- Sam Ruby