[Mono-devel-list] malloc and free on CLI
Jeyasankar Kottalam
mono at jey.kottalam.net
Tue Jul 19 12:47:13 EDT 2005
Quoting Massimiliano Mantione <massi at ximian.com>:
>
> On Mon, 2005-07-18 at 11:26 +0200, Paolo Molaro wrote:
>> Icalls are completely out of the question
>> as an implementation for this.
>
> Happy to hear this!
>
>> The managed C compiler should implement two patterns, both of which
>> are required:
>> 1) map a function call to a dllimport
>> 2) map a function call to corlib/System/ManagedLibc methods
>
> This makes sense, and I would add (maybe it was implied) that case
> 2 includes any kind of managed code, including any C library that
> has been compiled into a managed dll.
>
> Later on you describe a way of using C attributes to specify how
> to resolve the two kinds of mapping.
> I agree this should be done, but IMHO another way should also be
> provided.
>
> Think of the following scenario: a library (say zlib) is compiled
> to managed code (so we have zlib.dll).
> Another existing C program that we want to compile to managed code
> uses zlib (which means its sources include the zlib headers).
> Now, the zlib headers do not contain any mapping attribute (and
> IMHO they should stay as they are), so we need another way to tell
> the C compiler how to map those calls.
> I presume the C compiler generates a class with a lot of static
> methods, one for each C function.
> One easy way to specify the mapping outside of the header files
> would be to tell the compiler "all the static methods of these
> classes are managed C functions, and they have precedence over
> their unmanaged dllimported ones".
> Since the C namespace (for linking) is flat, this should work very
> well.
My current plan is to use the linker to automatically determine and
resolve such
cases by generating the appropriate P/Invoke declarations. This is on my TODO
list for this week.
I also think it would be nice if the linker could look into assemblies and
automagically resolve dependencies from "Managed C" to Mono classes. However
this would require some mechanism to generate header files to provide the
declarations to the compiler, or each language front-end would need to be
modified to automatically pick up the prototypes from the assembles. (e.g.
using libmono to read assemblies)
FYI- The compilation process is something like:
1. compile every foo.{c, cpp, pas, f, ...} to foo.s. foo.s contains "linker
annotations" and CIL
2. link all *.s to foo.il
3. ilasm foo.il to foo.exe
-Jey Kottalam
More information about the Mono-devel-list
mailing list