Commit 612c7093 authored by Roland Levillain's avatar Roland Levillain
Browse files

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.

git-svn-id: https://svn.lrde.epita.fr/svn/oln/trunk@4702 4aad255d-cdde-0310-9447-f3009e2ae8c0
parent f7614877
2009-11-03 Roland Levillain <roland@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@lrde.epita.fr>
Help Mac OS X's Mach-O dynamic linker (dyld) find libdynmilena.
......
......@@ -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");
}
/*-------------------------.
......
......@@ -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;
......
......@@ -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);
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment