diff options
author | lloyd <[email protected]> | 2010-09-08 16:06:49 +0000 |
---|---|---|
committer | lloyd <[email protected]> | 2010-09-08 16:06:49 +0000 |
commit | 46ddcdbc63717a48d4275b8071aa31baa18fba6f (patch) | |
tree | eb9028c2fed67d35b0a5482bbecac28c22392a2f | |
parent | 8a3ad04d3e227639abeae02c7a06a139438abbfe (diff) |
Update the dynamic engine protocol. The initial version had an engine
destructor function which would delete the engine; this was to handle
the case that the heaps were not shared between the application and
the library. However in this case we have bigger problems, because we
want to be able to pass std::strings into the engine, and additionally
be able to return objects from the library which are later deleted by
the algorithm factory. So without a major restructuring we can't
support this style of operation anyway; the DLL and application must
share the same heap. This can be done on Windows using the /MD linking
scheme for both the library and the DLL. The library already uses this
model by default on Windows.
-rw-r--r-- | src/engine/dyn_engine/dyn_engine.cpp | 45 |
1 files changed, 15 insertions, 30 deletions
diff --git a/src/engine/dyn_engine/dyn_engine.cpp b/src/engine/dyn_engine/dyn_engine.cpp index 2a1f14e8d..83169f431 100644 --- a/src/engine/dyn_engine/dyn_engine.cpp +++ b/src/engine/dyn_engine/dyn_engine.cpp @@ -13,9 +13,8 @@ namespace Botan { namespace { extern "C" { - typedef Engine* (*creator_function)(void); - typedef void (*destructor_function)(Engine*); - typedef u32bit (*module_version)(void); + typedef Engine* (*creator_func)(void); + typedef u32bit (*module_version_func)(void); } } @@ -28,22 +27,24 @@ Dynamically_Loaded_Engine::Dynamically_Loaded_Engine( try { - module_version version = - lib->resolve<module_version>("module_version"); + module_version_func get_version = + lib->resolve<module_version_func>("module_version"); - u32bit mod_version = version(); + const u32bit mod_version = get_version(); - if(mod_version != 20100728) - throw std::runtime_error("Unexpected or incompatible version in " + - library_path); + if(mod_version != 20100908) + throw std::runtime_error("Incompatible version in " + + library_path + " of " + + to_string(mod_version)); - creator_function creator = - lib->resolve<creator_function>("create_engine"); + creator_func creator = + lib->resolve<creator_func>("create_engine"); engine = creator(); if(!engine) - throw std::runtime_error("Creator function in " + library_path + " failed"); + throw std::runtime_error("Creator function in " + + library_path + " failed"); } catch(...) { @@ -55,24 +56,8 @@ Dynamically_Loaded_Engine::Dynamically_Loaded_Engine( Dynamically_Loaded_Engine::~Dynamically_Loaded_Engine() { - if(lib && engine) - { - try - { - destructor_function destroy = - lib->resolve<destructor_function>("destroy_engine"); - destroy(engine); - } - catch(...) - { - delete lib; - lib = 0; - throw; - } - } - - if(lib) - delete lib; + delete engine; + delete lib; } } |