aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--include/allocate.h2
-rw-r--r--include/defalloc.h2
-rw-r--r--include/libstate.h2
-rw-r--r--include/modules.h3
-rw-r--r--modules/alloc_mmap/mmap_mem.h1
-rw-r--r--src/init_def.cpp12
-rw-r--r--src/libstate.cpp6
-rw-r--r--src/modules.cpp6
8 files changed, 20 insertions, 14 deletions
diff --git a/include/allocate.h b/include/allocate.h
index a3f59cf1b..d30e4e0bc 100644
--- a/include/allocate.h
+++ b/include/allocate.h
@@ -20,6 +20,8 @@ class Allocator
virtual void* allocate(u32bit) = 0;
virtual void deallocate(void*, u32bit) = 0;
+ virtual std::string type() const = 0;
+
virtual void init() {}
virtual void destroy() {}
diff --git a/include/defalloc.h b/include/defalloc.h
index ef675d3a8..eb6fd9871 100644
--- a/include/defalloc.h
+++ b/include/defalloc.h
@@ -17,6 +17,7 @@ class Malloc_Allocator : public Pooling_Allocator
{
public:
Malloc_Allocator() : Pooling_Allocator(64*1024, false) {}
+ std::string type() const { return "malloc"; }
private:
void* alloc_block(u32bit);
void dealloc_block(void*, u32bit);
@@ -29,6 +30,7 @@ class Locking_Allocator : public Pooling_Allocator
{
public:
Locking_Allocator() : Pooling_Allocator(64*1024, true) {}
+ std::string type() const { return "locking"; }
private:
void* alloc_block(u32bit);
void dealloc_block(void*, u32bit);
diff --git a/include/libstate.h b/include/libstate.h
index 531824670..d242e5967 100644
--- a/include/libstate.h
+++ b/include/libstate.h
@@ -31,7 +31,7 @@ class Library_State
friend class Engine_Iterator;
Allocator* get_allocator(const std::string& = "") const;
- void add_allocator(const std::string&, Allocator*);
+ void add_allocator(Allocator*);
void set_prng(RandomNumberGenerator*);
void randomize(byte[], u32bit);
diff --git a/include/modules.h b/include/modules.h
index 499782c69..e09c18e9b 100644
--- a/include/modules.h
+++ b/include/modules.h
@@ -8,7 +8,6 @@
#include <vector>
#include <string>
-#include <map>
namespace Botan {
@@ -30,7 +29,7 @@ class Mutex_Factory* get_mutex_factory();
class Timer* get_timer();
std::vector<EntropySource*> get_entropy_sources();
std::vector<Engine*> get_engines();
-std::map<std::string, Allocator*> get_allocators();
+std::vector<Allocator*> get_allocators();
}
diff --git a/modules/alloc_mmap/mmap_mem.h b/modules/alloc_mmap/mmap_mem.h
index 0530e54be..04923571d 100644
--- a/modules/alloc_mmap/mmap_mem.h
+++ b/modules/alloc_mmap/mmap_mem.h
@@ -17,6 +17,7 @@ class MemoryMapping_Allocator : public Pooling_Allocator
{
public:
MemoryMapping_Allocator() : Pooling_Allocator(64*1024, false) {}
+ std::string type() const { return "mmap"; }
private:
void* alloc_block(u32bit);
void dealloc_block(void*, u32bit);
diff --git a/src/init_def.cpp b/src/init_def.cpp
index 9d07d730b..30f2228f5 100644
--- a/src/init_def.cpp
+++ b/src/init_def.cpp
@@ -86,15 +86,15 @@ void initialize(const std::string& arg_string)
set_global_state(new Library_State(mutex_factory,
Modules::get_timer()));
- global_state().add_allocator("malloc", new Malloc_Allocator);
- global_state().add_allocator("locking", new Locking_Allocator);
+ global_state().add_allocator(new Malloc_Allocator);
+ global_state().add_allocator(new Locking_Allocator);
if(arg_set(args, "secure_memory"))
{
- std::map<std::string, Allocator*> allocators = Modules::get_allocators();
- for(std::map<std::string, Allocator*>::iterator i = allocators.begin();
- i != allocators.end(); ++i)
- global_state().add_allocator(i->first, i->second);
+ std::vector<Allocator*> allocators = Modules::get_allocators();
+
+ for(u32bit j = 0; j != allocators.size(); ++j)
+ global_state().add_allocator(allocators[j]);
}
if(arg_set(args, "config") && args["config"] != "")
diff --git a/src/libstate.cpp b/src/libstate.cpp
index e27332025..98ccb5e7c 100644
--- a/src/libstate.cpp
+++ b/src/libstate.cpp
@@ -113,14 +113,16 @@ Allocator* Library_State::get_allocator(const std::string& type) const
/*************************************************
* Create a new name to object mapping *
*************************************************/
-void Library_State::add_allocator(const std::string& type,
- Allocator* allocator)
+void Library_State::add_allocator(Allocator* allocator)
{
Named_Mutex_Holder lock(locks, "allocator");
allocator->init();
+
+ const std::string type = allocator->type();
if(alloc_factory[type])
delete alloc_factory[type];
+
alloc_factory[type] = allocator;
}
diff --git a/src/modules.cpp b/src/modules.cpp
index 33731100c..ccbe65739 100644
--- a/src/modules.cpp
+++ b/src/modules.cpp
@@ -109,12 +109,12 @@ Timer* get_timer()
/*************************************************
* Find any usable allocators *
*************************************************/
-std::map<std::string, Allocator*> get_allocators()
+std::vector<Allocator*> get_allocators()
{
- std::map<std::string, Allocator*> allocators;
+ std::vector<Allocator*> allocators;
#if defined(BOTAN_EXT_ALLOC_MMAP)
- allocators["mmap"] = new MemoryMapping_Allocator;
+ allocators.push_back(new MemoryMapping_Allocator);
#endif
return allocators;