From: levill_r <levill_r@4aad255d-cdde-0310-9447-f3009e2ae8c0>
* src/function_loader.cc (HAVE_DYN_RUBY_GENERATOR): New macro,
depending on DYN_RUBY_GENERATOR.
(dyn::function_loader_t::function_loader_t): Feed the Ruby stream
only if HAVE_DYN_RUBY_GENERATOR is true.
(dyn::function_loader_t::load): Rename method as...
(dyn::function_loader_t::ruby_load): ...this.
(dyn::load_function) [HAVE_DYN_RUBY_GENERATOR]: Delegate the call
to function_loader.ruby_load.
(dyn::load_function) [!HAVE_DYN_RUBY_GENERATOR]: Delegate the call
to function_loader.cxx_load.
git-svn-id:
https://svn.lrde.epita.fr/svn/oln/trunk@4665
4aad255d-cdde-0310-9447-f3009e2ae8c0
---
dynamic-use-of-static-c++/ChangeLog | 15 +++++++++
dynamic-use-of-static-c++/src/function_loader.cc | 37 ++++++++++++++++------
2 files changed, 42 insertions(+), 10 deletions(-)
diff --git a/dynamic-use-of-static-c++/ChangeLog b/dynamic-use-of-static-c++/ChangeLog
index 89224a7..24cf3d1 100644
--- a/dynamic-use-of-static-c++/ChangeLog
+++ b/dynamic-use-of-static-c++/ChangeLog
@@ -1,5 +1,20 @@
2009-10-22 Roland Levillain <roland(a)lrde.epita.fr>
+ Have the dynamic function loader use the C++ framework by default.
+
+ * src/function_loader.cc (HAVE_DYN_RUBY_GENERATOR): New macro,
+ depending on DYN_RUBY_GENERATOR.
+ (dyn::function_loader_t::function_loader_t): Feed the Ruby stream
+ only if HAVE_DYN_RUBY_GENERATOR is true.
+ (dyn::function_loader_t::load): Rename method as...
+ (dyn::function_loader_t::ruby_load): ...this.
+ (dyn::load_function) [HAVE_DYN_RUBY_GENERATOR]: Delegate the call
+ to function_loader.ruby_load.
+ (dyn::load_function) [!HAVE_DYN_RUBY_GENERATOR]: Delegate the call
+ to function_loader.cxx_load.
+
+2009-10-22 Roland Levillain <roland(a)lrde.epita.fr>
+
Provide a C++ implementation of the dynamic function loader.
* src/function_loader.cc (dyn::function_loader_t::cxx_load):
diff --git a/dynamic-use-of-static-c++/src/function_loader.cc
b/dynamic-use-of-static-c++/src/function_loader.cc
index 113213a..cc25268 100644
--- a/dynamic-use-of-static-c++/src/function_loader.cc
+++ b/dynamic-use-of-static-c++/src/function_loader.cc
@@ -18,6 +18,14 @@
# include "function_loader.hh"
# include "ruby_stream.hh"
+// For more details about this, see
+//
http://www.gnu.org/prep/standards/html_node/Conditional-Compilation.html
+# ifdef DYN_RUBY_GENERATOR
+# define HAVE_DYN_RUBY_GENERATOR true
+# else
+# define HAVE_DYN_RUBY_GENERATOR false
+# endif
+
namespace bfs = boost::filesystem;
namespace ba = boost::algorithm;
@@ -116,10 +124,13 @@ namespace dyn {
function_loader_t()
{
lt_dlinit();
- ruby << "$: << \"" << DYNDIR <<
"\"" << ruby::eval;
- ruby << "require 'function_loader'" << ruby::eval;
- ruby << "require 'md5'" << ruby::eval;
- ruby << "Signal.trap(:SEGV, 'IGNORE')" <<
ruby::eval;
+ if (HAVE_DYN_RUBY_GENERATOR)
+ {
+ ruby << "$: << \"" << DYNDIR <<
"\"" << ruby::eval;
+ ruby << "require 'function_loader'" << ruby::eval;
+ ruby << "require 'md5'" << ruby::eval;
+ ruby << "Signal.trap(:SEGV, 'IGNORE')" << ruby::eval;
+ }
}
~function_loader_t()
@@ -339,11 +350,12 @@ namespace dyn {
}
}
+ // Most of the ruby-dependent code generator is in this function.
void*
- load(fun_kind kind,
- const std::string& name,
- const arguments_types_t& arguments_types,
- const std::string& paths)
+ ruby_load(fun_kind kind,
+ const std::string& name,
+ const arguments_types_t& arguments_types,
+ const std::string& paths)
{
std::ostringstream ostr;
ostr << name << '(';
@@ -405,7 +417,7 @@ namespace dyn {
return ptr;
}
- // FIXME: This C++ version of load shares a lot with the latter.
+ // FIXME: This C++ version of ruby_load shares a lot with the latter.
void*
cxx_load(fun_kind kind,
const std::string& name,
@@ -530,7 +542,12 @@ namespace dyn {
const arguments_types_t& arguments_types,
const std::string& header_path)
{
- return function_loader.load(kind, name, arguments_types, header_path);
+ if (HAVE_DYN_RUBY_GENERATOR)
+ return function_loader.ruby_load(kind, name, arguments_types,
+ header_path);
+ else
+ return function_loader.cxx_load(kind, name, arguments_types,
+ header_path);
}
} // end of namespace dyn
--
1.6.5