From: levill_r <levill_r@4aad255d-cdde-0310-9447-f3009e2ae8c0>
* src/function_loader.cc (dyn::function_loader_t::cache_type): Use
C++ string as keys so as to solve some memory management issues.
(dyn::function_loader_t::ruby_load)
(dyn::function_loader_t::cxx_load):
Adjust.
(dyn::ltstr): Remove functor class.
git-svn-id:
https://svn.lrde.epita.fr/svn/oln/trunk@4669
4aad255d-cdde-0310-9447-f3009e2ae8c0
---
dynamic-use-of-static-c++/ChangeLog | 11 +++++++++++
dynamic-use-of-static-c++/src/function_loader.cc | 20 +++++++++-----------
2 files changed, 20 insertions(+), 11 deletions(-)
diff --git a/dynamic-use-of-static-c++/ChangeLog b/dynamic-use-of-static-c++/ChangeLog
index 5b9e6e1..9a6d4bc 100644
--- a/dynamic-use-of-static-c++/ChangeLog
+++ b/dynamic-use-of-static-c++/ChangeLog
@@ -1,5 +1,16 @@
2009-10-26 Roland Levillain <roland(a)lrde.epita.fr>
+ Fix the caching system.
+
+ * src/function_loader.cc (dyn::function_loader_t::cache_type): Use
+ C++ string as keys so as to solve some memory management issues.
+ (dyn::function_loader_t::ruby_load)
+ (dyn::function_loader_t::cxx_load):
+ Adjust.
+ (dyn::ltstr): Remove functor class.
+
+2009-10-26 Roland Levillain <roland(a)lrde.epita.fr>
+
Clean the test repository during general cleaning.
* test/Makefile.am (repository_clean): Rename target as...
diff --git a/dynamic-use-of-static-c++/src/function_loader.cc
b/dynamic-use-of-static-c++/src/function_loader.cc
index cc25268..e1b0329 100644
--- a/dynamic-use-of-static-c++/src/function_loader.cc
+++ b/dynamic-use-of-static-c++/src/function_loader.cc
@@ -49,14 +49,6 @@ namespace dyn {
ruby::environment ruby_environment;
- struct ltstr
- {
- bool operator()(const char* s1, const char* s2) const
- {
- return strcmp(s1, s2) < 0;
- }
- };
-
std::list<std::string> includes_;
template <typename Fun>
@@ -376,7 +368,7 @@ namespace dyn {
std::string prototype = ostr.str();
ruby << "MD5.new(%q{" << prototype.c_str() <<
"}).to_s" << ruby::eval;
- const char* identifier = STR2CSTR(ruby.last_value());
+ std::string identifier = STR2CSTR(ruby.last_value());
cache_type::iterator ptr_it = cache.find(identifier);
@@ -446,7 +438,7 @@ namespace dyn {
// the interface of libmd5.
std::string identifier(MD5((unsigned char*)prototype.c_str()).hex_digest());
- cache_type::iterator ptr_it = cache.find(identifier.c_str());
+ cache_type::iterator ptr_it = cache.find(identifier);
// FIXME: It seems the cache doesn't work at all (we almost
// never hit). See why this is happening.
@@ -506,7 +498,13 @@ namespace dyn {
}
protected:
- typedef std::map<const char*, void*, ltstr> cache_type;
+ typedef std::map<std::string, void*> cache_type;
+ /* FIXME: Introduce a real cache object, with
+ debugging/pretty-printing methods. */
+ /* FIXME: It seems this cache is only valid for a (single) run,
+ i.e., cached values won't be preserved across several
+ executions. Of course, this is safer, but it would be great to
+ benefit from a long-term cache. */
cache_type cache;
std::list<std::string> cflags_, ldflags_;
ruby::stream ruby;
--
1.6.5