Writing bindings for C++ (template) libraries in Mathemagix (fwd)

Richard B. Kreckel kreckel at thep.physik.uni-mainz.de
Fri Jun 25 21:53:02 CEST 2004


Hi,

I just received an email from Joris van der Hoeven.
In case somebody wishes to give it a try.

Have fun
      -richy.
-- 
Richard B. Kreckel
<http://www.ginac.de/~kreckel/>

---------- Forwarded message ----------
Date: Fri, 25 Jun 2004 16:45:34 +0200 (CEST)
From: Joris van der Hoeven <vdhoeven at texmacs.org>
To: mathemagix-devel at mathemagix.org
Cc: kreckel at thep.physik.uni-mainz.de, haible at ilog.fr
Subject: Writing bindings for C++ (template) libraries in Mathemagix


Hi All,

I am happy to announce that the new version 0.1.41 of Mathemagix
(available from mathemagix.org) should  allow you to easily glue
C++ libraries as well as C++ template libraries to the interpreter.

The main mechanism is as follows: from an abstract description of
your library in a file like 'myglue.mmh' (see the examples provided
in src/glue), the mmx-extend script automatically generates a C++ file
which is compiled as a shared library 'mmx-myglue.so'. This library
can be loaded dynamically into Mathemagix via 'use "myglue"'.

Your library may also contain templates and the mmx-extend script
*automatically* creates an extension of your library which enables
you to use these templates in a generic way. I.e., having a template
class "Matrix", you will typically be able to use matrices over
matrices over matrices over integers.

Moreover, this generic extension should imply only a minimal overhead.
In the above matrix example, and as long as the operations on the scalars
are implemented in your library, no re-entrant calls to Mathemagix
are needed and operations are done quickly using some void* magic.

The code has been (incompletely) tested together with several libraries
(STL, Gmp, Synaps and Mmxlib) and contributions in this direction would
be *very much* appreciated. Apart from completing the existing binding
files, support for the following mathematical libraries would be nice:

	mpfr
	mpfi
	CLN
	NTL
	GiNaC
	Linbox
	libfactory
	CGAL
	etc.

Further suggestions for interesting scientific libraries are welcome,
the aim being to focus on incorporating as much existing software as
possible before starting to write programs in Mathemagix itself.
It would also be interesting to have bindings for libraries like
gtk, qt, opengl, unicode, cryptography, etc. etc.

Some shortcomings of the current implementation are as follows:

  * The GC garbage collector from Boehm seems to be bugged;
    it does not allow the use of dynamic libraries ;^(
    You may either configure Mathemagix using

	./configure --disable-gc

    or add an additional section for your library in the current
    configure.in file, add your bindings to the src/glue directory
    and use static compilation.

  * It is only possible to import generic routines from Mathemagix.
    Such routines correspond to the operations you wish to perform
    on types which occur as template arguments (like the scalar
    type for matrices).

    It is not possible yet to import ordinary routines or types
    from Mathemagix. As a consequence, if you want to write bindings
    for several libraries, then you usually have to produce the glue
    for all of them together. From an efficiency point of view,
    this is better anyway.

  * The names of exported C++ classes and functions should be
    of the form "identifier" or "identifier<id1,...,idn>".
    Special syntactic forms for operations like "x.f", "x->f",
    "x::f", etc. are not provided yet. You may always add
    the necessary macros or code to the preamble though.

  * There may still be some bugs. Feedback on this is appreciated.

Don't hesitate to ask further questions on this list.
Any feedback is appreciated.

Best wishes, Joris



More information about the GiNaC-devel mailing list