gm2
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Gm2] Calling Modula-2 from C


From: Gaius Mulley
Subject: Re: [Gm2] Calling Modula-2 from C
Date: Sat, 30 May 2009 15:53:54 +0100
User-agent: Gnus/5.11 (Gnus v5.11) Emacs/22.2 (gnu/linux)

Ron Kneusel <address@hidden> writes:

>> at present it is probably easier to make Modula-2 call C. Thus
>> allowing Modula-2 to create the main function. So you might write the
>> C module as:
>
> Thanks for the reply.  Unfortunately, that won't work in my case.  I am 
> looking
> to use Modula-2 to write extensions for an existing C application and
> ultimately I need to create a shared object.  I have been playing with XDS
> Modula-2 as well and have succeeded in going a bit further.  I can compile and
> link without trouble but get a segmentation fault when I try to call
> WriteString().

Hi,

ok, you can generate shared libraries using gm2.  There are some
examples in:

gcc-4.1.2/gcc/gm2/examples/swig/full-strlib/

which compile StrLib as a shared library, then links it to produce
_StrLib.so and proceeds to make python call StrLen.  There are also
some screencasts available here:

http://floppsie.comp.glam.ac.uk/download/screencasts/gnu-modula-2/python/python-numberio.mp4

which show it in action.

If you want to make your C application call Modula-2 it is possible -
but you have to manually resolve the module dependencies and call the

   _M2_modulename1_init(argc, argv);
   _M2_modulename2_init(argc, argv);

   it is now safe to call modulename2_myfunc()  etc

   _M2_modulename2_finish(argc, argv);
   _M2_modulename1_finish(argc, argv);

in a sensible sequence.  I'd suggest manually using gm2l to generate
the dependencies sequence (it does this based on imports) and then
adjust the order by hand and then using that to build the above
initialisation.  You can also use gm2lorder to fix the critical
runtime order of SYSTEM, M2RTS and EXCEPTIONS.  Finally you could also
use gm2lgen to generate the above init/finish code and maybe adjust it
to fit your application..

regards,
Gaius






reply via email to

[Prev in Thread] Current Thread [Next in Thread]