* src/wrappers/milena.cc (dyn::mln::init_type): Remove class.
Replace it by...
* src/wrappers/milena.hh, src/wrappers/milena.cc
(dyn::mln::initialize): ...this (new) function.
* test/wrappers/test-milena.cc (main): Call dyn::mln::initialize()
before calling wrappers.
---
dynamic-use-of-static-c++/ChangeLog | 11 +++++++
dynamic-use-of-static-c++/src/wrappers/milena.cc | 32 ++++---------------
dynamic-use-of-static-c++/src/wrappers/milena.hh | 21 +++++++++++++
.../test/wrappers/test-milena.cc | 2 +
4 files changed, 41 insertions(+), 25 deletions(-)
diff --git a/dynamic-use-of-static-c++/ChangeLog b/dynamic-use-of-static-c++/ChangeLog
index 400c9bb..dfbb444 100644
--- a/dynamic-use-of-static-c++/ChangeLog
+++ b/dynamic-use-of-static-c++/ChangeLog
@@ -1,5 +1,16 @@
2009-11-03 Roland Levillain <roland(a)lrde.epita.fr>
+ Make the initialization of Milena wrappers deterministic.
+
+ * src/wrappers/milena.cc (dyn::mln::init_type): Remove class.
+ Replace it by...
+ * src/wrappers/milena.hh, src/wrappers/milena.cc
+ (dyn::mln::initialize): ...this (new) function.
+ * test/wrappers/test-milena.cc (main): Call dyn::mln::initialize()
+ before calling wrappers.
+
+2009-11-03 Roland Levillain <roland(a)lrde.epita.fr>
+
Help Mac OS X's Mach-O dynamic linker (dyld) find libdynmilena.
* swig/run.in: Remove symlink, and replace it by an actual copy of
diff --git a/dynamic-use-of-static-c++/src/wrappers/milena.cc b/dynamic-use-of-static-c++/src/wrappers/milena.cc
index 3ad7a95..9baf0e7 100644
--- a/dynamic-use-of-static-c++/src/wrappers/milena.cc
+++ b/dynamic-use-of-static-c++/src/wrappers/milena.cc
@@ -41,32 +41,14 @@ namespace dyn
| Initialization. |
`-----------------*/
- /* This initialization relies on ctors of the fact that
- constructors of global objects called before `main', or more
- precisely:
-
- [...] the constructor of a global object is called either
- before the first statement of main or may be deferred until
- after the first statement of main but before the first use of
- any object or function in the same translation unit as the
- global object is defined in.
-
- according to this page:
- http://en.allexperts.com/q/C-1040/Constructors-Global-Object.htm. */
-
- struct init_type
+ void initialize()
{
- init_type()
- {
- dyn::include_dir(MILENA_DIR);
- dyn::include("mln/core/image/image2d.hh");
- dyn::include("mln/data/fill.hh");
- dyn::include("mln/debug/iota.hh");
- dyn::include("mln/debug/println.hh");
- }
- };
-
- init_type init;
+ dyn::include_dir(MILENA_DIR);
+ dyn::include("mln/core/image/image2d.hh");
+ dyn::include("mln/data/fill.hh");
+ dyn::include("mln/debug/iota.hh");
+ dyn::include("mln/debug/println.hh");
+ }
/*-------------------------.
diff --git a/dynamic-use-of-static-c++/src/wrappers/milena.hh b/dynamic-use-of-static-c++/src/wrappers/milena.hh
index b0ba1ed..ed4b702 100644
--- a/dynamic-use-of-static-c++/src/wrappers/milena.hh
+++ b/dynamic-use-of-static-c++/src/wrappers/milena.hh
@@ -40,6 +40,27 @@ namespace dyn
namespace mln
{
+ /*-----------------.
+ | Initialization. |
+ `-----------------*/
+
+ /* FIXME: This is not really elegant, but this is a lot safer than
+ the previous approach relying on the (implementation-defined)
+ order of initialization of global objects' ctors. We can
+ probably improve this by reworking dyn::function_loader. See
+ also hints and advice from
+ http://en.allexperts.com/q/C-1040/Constructors-Global-Object.htm. */
+
+ // This function *must* be called prior to any call to the wrapped
+ // routines below in order to find the headers of the functions
+ // they wrap.
+ void initialize();
+
+
+ /*-------------------------.
+ | A few wrapped routines. |
+ `-------------------------*/
+
extern dyn::language::ctor mk_image2d_int;
extern dyn::language::fun fill;
diff --git a/dynamic-use-of-static-c++/test/wrappers/test-milena.cc b/dynamic-use-of-static-c++/test/wrappers/test-milena.cc
index d24d216..831c9db 100644
--- a/dynamic-use-of-static-c++/test/wrappers/test-milena.cc
+++ b/dynamic-use-of-static-c++/test/wrappers/test-milena.cc
@@ -30,6 +30,8 @@
int main()
{
+ dyn::mln::initialize();
+
dyn::language::var ima = dyn::mln::mk_image2d_int(3, 3);
dyn::mln::fill(ima, 0);
dyn::mln::println("ima (before) =", ima);
--
1.6.5
* swig/run.in: Remove symlink, and replace it by an actual copy of
../../swilena/run.in.
(modpath): Append @abs_top_builddir@/src/wrappers/.libs.
---
dynamic-use-of-static-c++/ChangeLog | 8 ++++
dynamic-use-of-static-c++/swig/run.in | 60 ++++++++++++++++++++++++++++++++-
2 files changed, 67 insertions(+), 1 deletions(-)
mode change 120000 => 100755 dynamic-use-of-static-c++/swig/run.in
diff --git a/dynamic-use-of-static-c++/ChangeLog b/dynamic-use-of-static-c++/ChangeLog
index 6921732..81c90c3 100644
--- a/dynamic-use-of-static-c++/ChangeLog
+++ b/dynamic-use-of-static-c++/ChangeLog
@@ -1,3 +1,11 @@
+2009-11-03 Roland Levillain <roland(a)lrde.epita.fr>
+
+ Help Mac OS X's Mach-O dynamic linker (dyld) find libdynmilena.
+
+ * swig/run.in: Remove symlink, and replace it by an actual copy of
+ ../../swilena/run.in.
+ (modpath): Append @abs_top_builddir@/src/wrappers/.libs.
+
2009-11-02 Roland Levillain <roland(a)lrde.epita.fr>
Expose the Milena wrappers to SWIG.
diff --git a/dynamic-use-of-static-c++/swig/run.in b/dynamic-use-of-static-c++/swig/run.in
deleted file mode 120000
index 585aed6..0000000
--- a/dynamic-use-of-static-c++/swig/run.in
+++ /dev/null
@@ -1 +0,0 @@
-../../swilena/run.in
\ No newline at end of file
diff --git a/dynamic-use-of-static-c++/swig/run.in b/dynamic-use-of-static-c++/swig/run.in
new file mode 100755
index 0000000..41ec0e8
--- /dev/null
+++ b/dynamic-use-of-static-c++/swig/run.in
@@ -0,0 +1,59 @@
+#!/bin/sh
+
+# Copyright (C) 2003, 2004, 2006, 2009 Laboratoire d'Informatique de Paris 6
+# (LIP6), département Systèmes Répartis Coopératifs (SRC), Université
+# Pierre et Marie Curie.
+#
+# This file is part of Spot, a model checking library.
+#
+# Spot is free software; you can redistribute it and/or modify it
+# under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# Spot is distributed in the hope that it will be useful, but WITHOUT
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+# or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
+# License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with Spot; see the file COPYING. If not, write to the Free
+# Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
+# 02111-1307, USA.
+
+
+# If we are running from make check (srcdir is set) and VERBOSE is
+# unset, be quiet.
+test -n "$srcdir" && test -z "$VERBOSE" && exec >/dev/null 2>&1
+
+# Darwin needs some help in figuring out where non-installed libtool
+# libraries are (on this platform libtool encodes the expected final
+# path of dependent libraries in each library).
+## FIXME: This path should be configurable from outside the script.
+modpath='.libs:@abs_top_builddir@/src/.libs:@abs_top_builddir@/src/wrappers/.libs'
+
+case $1 in
+ '' | *.py)
+ PYTHONPATH='@abs_builddir@/python:@abs_srcdir@/python':"$PYTHONPATH" \
+ DYLD_LIBRARY_PATH=$modpath \
+ exec @PYTHON@ "$@"
+ ;;
+ # What's the point in adding `.libs' to SWILENA_RUBY_PATH?
+ #
+ # As some of our SWIG interfaces import other SWIG interfaces
+ # (with the `%import' keyword), we must add the `.libs' directory
+ # to SWILENA_RUBY_PATH so that the Ruby interpreter can load the
+ # corresponding dynamic module(s) (SWIG's `%import' statements
+ # generate code in dynamic modules that bypass Ruby's
+ # `Kernel.require' mechanism).
+ *.rb)
+ SWILENA_RUBY_PATH='@abs_builddir@/ruby:@abs_srcdir@/ruby:.libs' \
+ DYLD_LIBRARY_PATH=$modpath \
+ exec @RUBY@ "$@"
+ ;;
+ *.test)
+ exec sh -x "$@";;
+ *)
+ echo "Unknown extension" 2>&1
+ exit 2;;
+esac
--
1.6.5
* swig/mln.i: New.
* swig/Makefile.am (EXTRA_DIST): Add mln.i.
* swig/python/Makefile.am (AM_LIBADD): Remove variable.
(libdyn_la, libdynmilena_la): New variables.
(_dyn_la_LIBADD): s/AM_LIBADD/libdyn_la/.
(pyexec_LTLIBRARIES): Add _mln.la.
(nodist__mln_la_SOURCES, _mln_la_LIBADD): New variables.
(CLEANFILES): Add $(nodist__mln_la_SOURCES), mln.py and
mln.py[co].
(nodist_python_PYTHON): Add mln.py.
---
dynamic-use-of-static-c++/ChangeLog | 15 ++++++++
dynamic-use-of-static-c++/swig/Makefile.am | 2 +-
dynamic-use-of-static-c++/swig/mln.i | 39 +++++++++++++++++++++
dynamic-use-of-static-c++/swig/python/Makefile.am | 22 +++++++++--
4 files changed, 73 insertions(+), 5 deletions(-)
create mode 100644 dynamic-use-of-static-c++/swig/mln.i
diff --git a/dynamic-use-of-static-c++/ChangeLog b/dynamic-use-of-static-c++/ChangeLog
index a483c8d..6921732 100644
--- a/dynamic-use-of-static-c++/ChangeLog
+++ b/dynamic-use-of-static-c++/ChangeLog
@@ -1,5 +1,20 @@
2009-11-02 Roland Levillain <roland(a)lrde.epita.fr>
+ Expose the Milena wrappers to SWIG.
+
+ * swig/mln.i: New.
+ * swig/Makefile.am (EXTRA_DIST): Add mln.i.
+ * swig/python/Makefile.am (AM_LIBADD): Remove variable.
+ (libdyn_la, libdynmilena_la): New variables.
+ (_dyn_la_LIBADD): s/AM_LIBADD/libdyn_la/.
+ (pyexec_LTLIBRARIES): Add _mln.la.
+ (nodist__mln_la_SOURCES, _mln_la_LIBADD): New variables.
+ (CLEANFILES): Add $(nodist__mln_la_SOURCES), mln.py and
+ mln.py[co].
+ (nodist_python_PYTHON): Add mln.py.
+
+2009-11-02 Roland Levillain <roland(a)lrde.epita.fr>
+
Exercise Milena precompiled wrappers.
* test/wrappers/test-milena.cc: New.
diff --git a/dynamic-use-of-static-c++/swig/Makefile.am b/dynamic-use-of-static-c++/swig/Makefile.am
index 2d894af..8743680 100644
--- a/dynamic-use-of-static-c++/swig/Makefile.am
+++ b/dynamic-use-of-static-c++/swig/Makefile.am
@@ -16,6 +16,6 @@
SUBDIRS = python
-EXTRA_DIST = dyn.i
+EXTRA_DIST = dyn.i mln.i
check_SCRIPTS = run
diff --git a/dynamic-use-of-static-c++/swig/mln.i b/dynamic-use-of-static-c++/swig/mln.i
new file mode 100644
index 0000000..e5598ab
--- /dev/null
+++ b/dynamic-use-of-static-c++/swig/mln.i
@@ -0,0 +1,39 @@
+// -*- C++ -*-
+// Copyright (C) 2009 EPITA Research and Development Laboratory (LRDE)
+//
+// This file is part of Olena.
+//
+// Olena is free software: you can redistribute it and/or modify it under
+// the terms of the GNU General Public License as published by the Free
+// Software Foundation, version 2 of the License.
+//
+// Olena is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with Olena. If not, see <http://www.gnu.org/licenses/>.
+//
+// As a special exception, you may use this file as part of a free
+// software project without restriction. Specifically, if other files
+// instantiate templates or use macros or inline functions from this
+// file, or you compile this file and link it with other files to produce
+// an executable, this file does not by itself cause the resulting
+// executable to be covered by the GNU General Public License. This
+// exception does not however invalidate any other reasons why the
+// executable file might be covered by the GNU General Public License.
+
+/// \file
+/// \brief A wrapper of libdynmilena.
+
+%module mln
+
+%import dyn.i
+
+%{
+#include "dyn-all.hh"
+#include "wrappers/milena.hh"
+%}
+
+%include "wrappers/milena.hh"
diff --git a/dynamic-use-of-static-c++/swig/python/Makefile.am b/dynamic-use-of-static-c++/swig/python/Makefile.am
index 81455f7..86611e3 100644
--- a/dynamic-use-of-static-c++/swig/python/Makefile.am
+++ b/dynamic-use-of-static-c++/swig/python/Makefile.am
@@ -26,12 +26,15 @@
CLEANFILES =
AM_CPPFLAGS = -I$(PYTHONINC) -I$(top_builddir)/src -I$(top_srcdir)/src
## FIXME: Define an equivalent to Olena's TOOLS_CXXFLAGS?
-## TOOLS_CXXFLAGS = @TOOLS_CXXFLAGS@
-## AM_CXXFLAGS = $(TOOLS_CXXFLAGS)
+##TOOLS_CXXFLAGS = @TOOLS_CXXFLAGS@
+##AM_CXXFLAGS = $(TOOLS_CXXFLAGS)
+## FIXME: Warning, `AM_SWIGFLAGS' is not a standard Automake variable.
AM_SWIGFLAGS = -Wall -c++ -python -I$(top_builddir)/src -I$(top_srcdir)/src
# We build modules, not plain libs.
AM_LDFLAGS = -avoid-version -module -shared
-AM_LIBADD = $(top_builddir)/src/libdyn.la # $(LIBLTDL)
+# Libraries with their dependencies.
+libdyn_la = $(top_builddir)/src/libdyn.la
+libdynmilena_la = $(top_builddir)/src/wrappers/libdynmilena.la $(libdyn_la)
# Run Swig to create the C++ wrapper files, the Python interface
# files, and the dependency Makefile snippets.
@@ -69,13 +72,24 @@ pyexec_LTLIBRARIES =
## dyn.
pyexec_LTLIBRARIES += _dyn.la
nodist__dyn_la_SOURCES = dyn-wrap.cc
-_dyn_la_LIBADD = $(AM_LIBADD)
+_dyn_la_LIBADD = $(libdyn_la)
CLEANFILES += $(nodist__dyn_la_SOURCES) dyn.py dyn.py[co]
## Include the dependency files. Copied from Automake's generated
## case for C++.
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/_dyn-wrap.Pcc@am__quote@
nodist_python_PYTHON += dyn.py
+# FIXME: Should be optional.
+## mln.
+pyexec_LTLIBRARIES += _mln.la
+nodist__mln_la_SOURCES = mln-wrap.cc
+_mln_la_LIBADD = $(libdynmilena_la)
+CLEANFILES += $(nodist__mln_la_SOURCES) mln.py mln.py[co]
+## Include the dependency files. Copied from Automake's generated
+## case for C++.
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/_mln-wrap.Pcc@am__quote@
+nodist_python_PYTHON += mln.py
+
## ------- ##
## Tests. ##
--
1.6.5
* test/wrappers/test-milena.cc: New.
* test/wrappers/Makefile.am: New.
* test/Makefile.am (SUBDIRS): Append `wrappers' and prepend `.'.
* configure.ac: Configure test/wrappers/Makefile.
---
dynamic-use-of-static-c++/ChangeLog | 9 +++++
dynamic-use-of-static-c++/configure.ac | 1 +
dynamic-use-of-static-c++/test/Makefile.am | 2 +-
.../test/wrappers/Makefile.am | 25 +++++++++++++
.../test/wrappers/test-milena.cc | 38 ++++++++++++++++++++
5 files changed, 74 insertions(+), 1 deletions(-)
create mode 100644 dynamic-use-of-static-c++/test/wrappers/Makefile.am
create mode 100644 dynamic-use-of-static-c++/test/wrappers/test-milena.cc
diff --git a/dynamic-use-of-static-c++/ChangeLog b/dynamic-use-of-static-c++/ChangeLog
index 8f695ef..a483c8d 100644
--- a/dynamic-use-of-static-c++/ChangeLog
+++ b/dynamic-use-of-static-c++/ChangeLog
@@ -1,5 +1,14 @@
2009-11-02 Roland Levillain <roland(a)lrde.epita.fr>
+ Exercise Milena precompiled wrappers.
+
+ * test/wrappers/test-milena.cc: New.
+ * test/wrappers/Makefile.am: New.
+ * test/Makefile.am (SUBDIRS): Append `wrappers' and prepend `.'.
+ * configure.ac: Configure test/wrappers/Makefile.
+
+2009-11-02 Roland Levillain <roland(a)lrde.epita.fr>
+
Start to provide some precompiled wrappers for Milena.
* src/wrappers/milena.hh, src/wrappers/milena.cc: New.
diff --git a/dynamic-use-of-static-c++/configure.ac b/dynamic-use-of-static-c++/configure.ac
index 02dced0..0bfd275 100644
--- a/dynamic-use-of-static-c++/configure.ac
+++ b/dynamic-use-of-static-c++/configure.ac
@@ -214,6 +214,7 @@ AC_CONFIG_FILES([
_config/local-config.rb
test/Makefile
test/vaucanson/Makefile
+ test/wrappers/Makefile
], [chmod +x bin/dyn-config])
# Instantiate the output files.
diff --git a/dynamic-use-of-static-c++/test/Makefile.am b/dynamic-use-of-static-c++/test/Makefile.am
index fd65b67..e0301a6 100644
--- a/dynamic-use-of-static-c++/test/Makefile.am
+++ b/dynamic-use-of-static-c++/test/Makefile.am
@@ -17,7 +17,7 @@
AM_CPPFLAGS = -I$(srcdir)/fixtures -I$(top_srcdir)/src -I$(top_builddir)/src
AM_CXXFLAGS = $(WARNING_CXXFLAGS)
-SUBDIRS = vaucanson
+SUBDIRS = . vaucanson wrappers
#erb# =begin # Read the documentation of erbx to see how to change this part
#erb# <%
diff --git a/dynamic-use-of-static-c++/test/wrappers/Makefile.am b/dynamic-use-of-static-c++/test/wrappers/Makefile.am
new file mode 100644
index 0000000..d947ea2
--- /dev/null
+++ b/dynamic-use-of-static-c++/test/wrappers/Makefile.am
@@ -0,0 +1,25 @@
+# Copyright (C) 2009 EPITA Research and Development Laboratory (LRDE).
+#
+# This file is part of Olena.
+#
+# Olena is free software: you can redistribute it and/or modify it under
+# the terms of the GNU General Public License as published by the Free
+# Software Foundation, version 2 of the License.
+#
+# Olena is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+# General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with Olena. If not, see <http://www.gnu.org/licenses/>.
+
+LDADD = \
+ $(top_builddir)/src/wrappers/libdynmilena.la \
+ $(top_builddir)/src/libdyn.la
+AM_CPPFLAGS = -I$(top_srcdir)/src -I$(top_builddir)/src
+
+check_PROGRAMS = test-milena
+test_milena_SOURCES = test-milena.cc
+
+TESTS = $(check_PROGRAMS)
diff --git a/dynamic-use-of-static-c++/test/wrappers/test-milena.cc b/dynamic-use-of-static-c++/test/wrappers/test-milena.cc
new file mode 100644
index 0000000..d24d216
--- /dev/null
+++ b/dynamic-use-of-static-c++/test/wrappers/test-milena.cc
@@ -0,0 +1,38 @@
+// Copyright (C) 2009 EPITA Research and Development Laboratory (LRDE)
+//
+// This file is part of Olena.
+//
+// Olena is free software: you can redistribute it and/or modify it under
+// the terms of the GNU General Public License as published by the Free
+// Software Foundation, version 2 of the License.
+//
+// Olena is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with Olena. If not, see <http://www.gnu.org/licenses/>.
+//
+// As a special exception, you may use this file as part of a free
+// software project without restriction. Specifically, if other files
+// instantiate templates or use macros or inline functions from this
+// file, or you compile this file and link it with other files to produce
+// an executable, this file does not by itself cause the resulting
+// executable to be covered by the GNU General Public License. This
+// exception does not however invalidate any other reasons why the
+// executable file might be covered by the GNU General Public License.
+
+/// \file
+/// Exercise the Milena wrappers.
+
+#include <wrappers/milena.hh>
+
+int main()
+{
+ dyn::language::var ima = dyn::mln::mk_image2d_int(3, 3);
+ dyn::mln::fill(ima, 0);
+ dyn::mln::println("ima (before) =", ima);
+ dyn::mln::iota(ima);
+ dyn::mln::println("ima (after) =", ima);
+}
--
1.6.5
* src/wrappers/milena.hh, src/wrappers/milena.cc: New.
* src/wrappers/Makefile.am: New.
* src/Makefile.am (SUBDIRS): New.
Add . and wrappers.
* configure.ac: Configure src/wrappers/Makefile.
---
dynamic-use-of-static-c++/ChangeLog | 10 ++
dynamic-use-of-static-c++/configure.ac | 1 +
dynamic-use-of-static-c++/src/Makefile.am | 2 +
dynamic-use-of-static-c++/src/wrappers/Makefile.am | 25 ++++++
dynamic-use-of-static-c++/src/wrappers/milena.cc | 88 ++++++++++++++++++++
dynamic-use-of-static-c++/src/wrappers/milena.hh | 57 +++++++++++++
6 files changed, 183 insertions(+), 0 deletions(-)
create mode 100644 dynamic-use-of-static-c++/src/wrappers/Makefile.am
create mode 100644 dynamic-use-of-static-c++/src/wrappers/milena.cc
create mode 100644 dynamic-use-of-static-c++/src/wrappers/milena.hh
diff --git a/dynamic-use-of-static-c++/ChangeLog b/dynamic-use-of-static-c++/ChangeLog
index 8d30676..8f695ef 100644
--- a/dynamic-use-of-static-c++/ChangeLog
+++ b/dynamic-use-of-static-c++/ChangeLog
@@ -1,5 +1,15 @@
2009-11-02 Roland Levillain <roland(a)lrde.epita.fr>
+ Start to provide some precompiled wrappers for Milena.
+
+ * src/wrappers/milena.hh, src/wrappers/milena.cc: New.
+ * src/wrappers/Makefile.am: New.
+ * src/Makefile.am (SUBDIRS): New.
+ Add . and wrappers.
+ * configure.ac: Configure src/wrappers/Makefile.
+
+2009-11-02 Roland Levillain <roland(a)lrde.epita.fr>
+
Wrap global objects (operator functors) previously ignored.
* swig/dyn.i: Here.
diff --git a/dynamic-use-of-static-c++/configure.ac b/dynamic-use-of-static-c++/configure.ac
index e6ff54b..02dced0 100644
--- a/dynamic-use-of-static-c++/configure.ac
+++ b/dynamic-use-of-static-c++/configure.ac
@@ -208,6 +208,7 @@ AC_CONFIG_FILES([
libmd5/Makefile
src/Makefile
src/config.hh
+ src/wrappers/Makefile
data/Makefile
config/Makefile
_config/local-config.rb
diff --git a/dynamic-use-of-static-c++/src/Makefile.am b/dynamic-use-of-static-c++/src/Makefile.am
index ea01751..0f5fd9b 100644
--- a/dynamic-use-of-static-c++/src/Makefile.am
+++ b/dynamic-use-of-static-c++/src/Makefile.am
@@ -14,6 +14,8 @@
# You should have received a copy of the GNU General Public License
# along with Olena. If not, see <http://www.gnu.org/licenses/>.
+SUBDIRS = . wrappers
+
include_HEADERS = dyn-all.hh dyn-light.hh
lib_LTLIBRARIES = libdyn.la
diff --git a/dynamic-use-of-static-c++/src/wrappers/Makefile.am b/dynamic-use-of-static-c++/src/wrappers/Makefile.am
new file mode 100644
index 0000000..af08122
--- /dev/null
+++ b/dynamic-use-of-static-c++/src/wrappers/Makefile.am
@@ -0,0 +1,25 @@
+# Copyright (C) 2009 EPITA Research and Development Laboratory (LRDE).
+#
+# This file is part of Olena.
+#
+# Olena is free software: you can redistribute it and/or modify it under
+# the terms of the GNU General Public License as published by the Free
+# Software Foundation, version 2 of the License.
+#
+# Olena is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+# General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with Olena. If not, see <http://www.gnu.org/licenses/>.
+
+# FIXME: These wrappers should be optional (and likewise for all
+# milena-related code); have configure provide an `--enable-milena'
+# option.
+
+AM_CPPFLAGS = -I$(top_srcdir)/src -I$(top_builddir)/src
+
+# Wrapping a few Milena routines.
+lib_LTLIBRARIES = libdynmilena.la
+libdynmilena_la_SOURCES = milena.hh milena.cc
diff --git a/dynamic-use-of-static-c++/src/wrappers/milena.cc b/dynamic-use-of-static-c++/src/wrappers/milena.cc
new file mode 100644
index 0000000..3ad7a95
--- /dev/null
+++ b/dynamic-use-of-static-c++/src/wrappers/milena.cc
@@ -0,0 +1,88 @@
+// Copyright (C) 2009 EPITA Research and Development Laboratory (LRDE)
+//
+// This file is part of Olena.
+//
+// Olena is free software: you can redistribute it and/or modify it under
+// the terms of the GNU General Public License as published by the Free
+// Software Foundation, version 2 of the License.
+//
+// Olena is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with Olena. If not, see <http://www.gnu.org/licenses/>.
+//
+// As a special exception, you may use this file as part of a free
+// software project without restriction. Specifically, if other files
+// instantiate templates or use macros or inline functions from this
+// file, or you compile this file and link it with other files to produce
+// an executable, this file does not by itself cause the resulting
+// executable to be covered by the GNU General Public License. This
+// exception does not however invalidate any other reasons why the
+// executable file might be covered by the GNU General Public License.
+
+#include <wrappers/milena.hh>
+
+/// \file
+/// \brief Definition of Milena wrappers.
+///
+/// \todo The next step is to generate (semi-)automatically this file
+/// from Milena's (possibly annotated) source files.
+
+namespace dyn
+{
+
+ namespace mln
+ {
+
+ /*-----------------.
+ | Initialization. |
+ `-----------------*/
+
+ /* This initialization relies on ctors of the fact that
+ constructors of global objects called before `main', or more
+ precisely:
+
+ [...] the constructor of a global object is called either
+ before the first statement of main or may be deferred until
+ after the first statement of main but before the first use of
+ any object or function in the same translation unit as the
+ global object is defined in.
+
+ according to this page:
+ http://en.allexperts.com/q/C-1040/Constructors-Global-Object.htm. */
+
+ struct init_type
+ {
+ init_type()
+ {
+ dyn::include_dir(MILENA_DIR);
+ dyn::include("mln/core/image/image2d.hh");
+ dyn::include("mln/data/fill.hh");
+ dyn::include("mln/debug/iota.hh");
+ dyn::include("mln/debug/println.hh");
+ }
+ };
+
+ init_type init;
+
+
+ /*-------------------------.
+ | A few wrapped routines. |
+ `-------------------------*/
+
+ ctor mk_image2d_int("mln::image2d<int>");
+
+ fun fill("mln::data::fill");
+ fun iota("mln::debug::iota");
+ fun println("mln::debug::println");
+
+ // FIXME: Wrap more routines.
+
+ // ...
+
+ } // end of namespace dyn::mln
+
+} // end of namespace dyn
diff --git a/dynamic-use-of-static-c++/src/wrappers/milena.hh b/dynamic-use-of-static-c++/src/wrappers/milena.hh
new file mode 100644
index 0000000..b0ba1ed
--- /dev/null
+++ b/dynamic-use-of-static-c++/src/wrappers/milena.hh
@@ -0,0 +1,57 @@
+// Copyright (C) 2009 EPITA Research and Development Laboratory (LRDE)
+//
+// This file is part of Olena.
+//
+// Olena is free software: you can redistribute it and/or modify it under
+// the terms of the GNU General Public License as published by the Free
+// Software Foundation, version 2 of the License.
+//
+// Olena is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with Olena. If not, see <http://www.gnu.org/licenses/>.
+//
+// As a special exception, you may use this file as part of a free
+// software project without restriction. Specifically, if other files
+// instantiate templates or use macros or inline functions from this
+// file, or you compile this file and link it with other files to produce
+// an executable, this file does not by itself cause the resulting
+// executable to be covered by the GNU General Public License. This
+// exception does not however invalidate any other reasons why the
+// executable file might be covered by the GNU General Public License.
+
+#ifndef DYN_WRAPPERS_MILENA_HH
+# define DYN_WRAPPERS_MILENA_HH
+
+/// \file
+/// \brief Declaration of Milena wrappers.
+///
+/// \todo The next step is to generate (semi-)automatically this file
+/// from Milena's (possibly annotated) source files.
+
+# include <dyn-all.hh>
+
+namespace dyn
+{
+
+ namespace mln
+ {
+
+ extern dyn::language::ctor mk_image2d_int;
+
+ extern dyn::language::fun fill;
+ extern dyn::language::fun iota;
+ extern dyn::language::fun println;
+
+ // FIXME: Wrap more routines.
+
+ // ...
+
+ } // end of namespace dyn::mln
+
+} // end of namespace dyn
+
+#endif // ! DYN_WRAPPERS_MILENA_HH
--
1.6.5
* swig/dyn.i (make_data_by_cpy): Remove inlined wrapper.
(generate_data_ctor)
(generate_data_ctor_val)
(generate_data_ctor_ref):
New macros.
Use them to generate dyn::data ctors using a proxy-by-value for
`int' and `std::string'.
* swig/python/milena.py: Adjust: use dyn.data directly instead of
helpers dyn.integer and dyn.string.
---
dynamic-use-of-static-c++/ChangeLog | 14 ++++++
dynamic-use-of-static-c++/swig/dyn.i | 53 +++++++++++++++-------
dynamic-use-of-static-c++/swig/python/milena.py | 10 ++--
3 files changed, 55 insertions(+), 22 deletions(-)
diff --git a/dynamic-use-of-static-c++/ChangeLog b/dynamic-use-of-static-c++/ChangeLog
index ce53b40..9eff03c 100644
--- a/dynamic-use-of-static-c++/ChangeLog
+++ b/dynamic-use-of-static-c++/ChangeLog
@@ -1,3 +1,17 @@
+2009-10-30 Roland Levillain <roland(a)lrde.epita.fr>
+
+ Simplify the construction of dyn.data objects in SWIG wrappers.
+
+ * swig/dyn.i (make_data_by_cpy): Remove inlined wrapper.
+ (generate_data_ctor)
+ (generate_data_ctor_val)
+ (generate_data_ctor_ref):
+ New macros.
+ Use them to generate dyn::data ctors using a proxy-by-value for
+ `int' and `std::string'.
+ * swig/python/milena.py: Adjust: use dyn.data directly instead of
+ helpers dyn.integer and dyn.string.
+
2009-10-29 Roland Levillain <roland(a)lrde.epita.fr>
Fix issues w.r.t. MacPorts' libiberty to have Python bindings work.
diff --git a/dynamic-use-of-static-c++/swig/dyn.i b/dynamic-use-of-static-c++/swig/dyn.i
index eaeacdf..b3b6751 100644
--- a/dynamic-use-of-static-c++/swig/dyn.i
+++ b/dynamic-use-of-static-c++/swig/dyn.i
@@ -35,7 +35,7 @@
#include "dyn-all.hh"
%}
-// Ignore global objects causing trouble.
+// Ignore global objects causing trouble to swig.
%ignore dyn::logger;
%ignore dyn::internal::operator_push;
%ignore dyn::internal::operator_pop;
@@ -49,29 +49,48 @@
%include "dyn-all.hh";
-%inline %{
- /* The natural, single-argument ctors of dyn::data manipulate the
- encapulsated by reference, which is wrong when these data are of
- builtin types of the target language (e.g., Pythons' `int's),
- because we have no control on them and they can vanish at any
- moment.
+/*---------------.
+| Construction. |
+`---------------*/
+
+/* The natural, single-argument ctors of dyn::data manipulate the
+ encapsulated member by reference, which is wrong when these data
+ are of builtin types of the target language (e.g., Pythons'
+ `int's), because we have no control on them and they can vanish at
+ any moment.
- To prevent this, provide construction helpers creating dyn::data
- objects manipulating data by value (copy). */
- template <typename T>
- dyn::data make_data_by_cpy(T i)
+ To prevent this, provide constructors helpers creating dyn::data
+ objects manipulating data by value (copy). */
+%define generate_data_ctor(Arg, Type)
+%extend dyn::data
+{
+ data(Arg v)
{
dyn::proxy_tag* dummy = 0;
// This dummy pointer passed as second argument is required to
// call the right ctor.
- dyn::data d(new dyn::data_proxy_by_cpy<T>(i), dummy);
- return d;
+ return new dyn::data(new dyn::data_proxy_by_cpy< Type >(v), dummy);
}
-%}
+}
+%enddef // !generate_data_ctor
+
+// Shortcut to generate a ctor taking its argument by value (copy).
+%define generate_data_ctor_val(Type)
+generate_data_ctor(Type, Type)
+%enddef
+
+// Shortcut to generate a ctor taking its argument by (const) reference.
+%define generate_data_ctor_ref(Type)
+generate_data_ctor(const Type &, Type)
+%enddef
+
+// Generate dyn::data ctors using a proxy-by-value for classic types.
+generate_data_ctor_val(int)
+generate_data_ctor_ref(std::string)
-// Instantiate make_data_by_cpy ctors for some types.
-%template(integer) make_data_by_cpy<int>;
-%template(string) make_data_by_cpy<std::string>;
+/*--------------.
+| Conversions. |
+`--------------*/
// Instantiate dyn::data explicit conversion routines for some types.
%extend dyn::data
diff --git a/dynamic-use-of-static-c++/swig/python/milena.py b/dynamic-use-of-static-c++/swig/python/milena.py
index 85a1cfc..93c384b 100644
--- a/dynamic-use-of-static-c++/swig/python/milena.py
+++ b/dynamic-use-of-static-c++/swig/python/milena.py
@@ -41,11 +41,11 @@ println = dyn.fun("mln::debug::println")
#
# but we just can't. `mk_image2d_int' only accept `dyn.data' as
# arguments, so we have to encapsulate integers in `dyn.data' objects
-# using `dyn.integer' (likewise for strings with `dyn.string').
+# (likewise for strings).
-ima = mk_image2d_int(dyn.integer(3), dyn.integer(3))
+ima = mk_image2d_int(dyn.data(3), dyn.data(3))
-fill(ima, dyn.integer(0))
-println(dyn.string("ima (before) ="), ima)
+fill(ima, dyn.data(0))
+println(dyn.data("ima (before) ="), ima)
iota(ima)
-println(dyn.string("ima (after) ="), ima)
+println(dyn.data("ima (after) ="), ima)
--
1.6.5