aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/allocate.cpp23
-rw-r--r--src/defalloc.cpp17
-rw-r--r--src/libstate.cpp38
-rw-r--r--src/mem_pool.cpp10
4 files changed, 40 insertions, 48 deletions
diff --git a/src/allocate.cpp b/src/allocate.cpp
deleted file mode 100644
index 72b1f873a..000000000
--- a/src/allocate.cpp
+++ /dev/null
@@ -1,23 +0,0 @@
-/*************************************************
-* Allocator Factory Source File *
-* (C) 1999-2006 The Botan Project *
-*************************************************/
-
-#include <botan/allocate.h>
-#include <botan/libstate.h>
-
-namespace Botan {
-
-/*************************************************
-* Get an allocator *
-*************************************************/
-Allocator* get_allocator(const std::string& type)
- {
- Allocator* alloc = global_state().get_allocator(type);
- if(alloc)
- return alloc;
-
- throw Exception("Couldn't find an allocator to use in get_allocator");
- }
-
-}
diff --git a/src/defalloc.cpp b/src/defalloc.cpp
index ad54fb3ca..5b61e7fac 100644
--- a/src/defalloc.cpp
+++ b/src/defalloc.cpp
@@ -4,6 +4,7 @@
*************************************************/
#include <botan/defalloc.h>
+#include <botan/libstate.h>
#include <botan/util.h>
#include <cstdlib>
#include <cstring>
@@ -78,4 +79,20 @@ void Locking_Allocator::dealloc_block(void* ptr, u32bit n)
do_free(ptr, n, true);
}
+/*************************************************
+* Get an allocator *
+*************************************************/
+Allocator* Allocator::get(bool locking)
+ {
+ std::string type = "";
+ if(!locking)
+ type = "malloc";
+
+ Allocator* alloc = global_state().get_allocator(type);
+ if(alloc)
+ return alloc;
+
+ throw Exception("Couldn't find an allocator to use in get_allocator");
+ }
+
}
diff --git a/src/libstate.cpp b/src/libstate.cpp
index 1bb27e74a..a782f4c60 100644
--- a/src/libstate.cpp
+++ b/src/libstate.cpp
@@ -110,21 +110,28 @@ Allocator* Library_State::get_allocator(const std::string& type) const
/*************************************************
* Create a new name to object mapping *
*************************************************/
-void Library_State::add_allocator(Allocator* allocator,
- bool set_as_default)
+void Library_State::add_allocator(Allocator* allocator)
{
Named_Mutex_Holder lock("allocator");
allocator->init();
- const std::string type = allocator->type();
- if(alloc_factory[type])
- delete alloc_factory[type];
+ allocators.push_back(allocator);
+ alloc_factory[allocator->type()] = allocator;
+ }
- alloc_factory[type] = allocator;
+/*************************************************
+* Set the default allocator type *
+*************************************************/
+void Library_State::set_default_allocator(const std::string& type) const
+ {
+ Named_Mutex_Holder lock("allocator");
- if(set_as_default)
- config().set("conf", "base/default_allocator", type);
+ if(type == "")
+ return;
+
+ config().set("conf", "base/default_allocator", type);
+ cached_default_allocator = 0;
}
/*************************************************
@@ -307,11 +314,11 @@ void Library_State::load(Modules& modules)
set_timer(modules.timer());
set_transcoder(modules.transcoder());
- std::vector<Allocator*> allocators = modules.allocators();
+ std::vector<Allocator*> mod_allocs = modules.allocators();
+ for(u32bit j = 0; j != mod_allocs.size(); j++)
+ add_allocator(mod_allocs[j]);
- for(u32bit j = 0; j != allocators.size(); j++)
- add_allocator(allocators[j],
- allocators[j]->type() == modules.default_allocator());
+ set_default_allocator(modules.default_allocator());
std::vector<Engine*> engines = modules.engines();
for(u32bit j = 0; j != engines.size(); ++j)
@@ -361,11 +368,10 @@ Library_State::~Library_State()
cached_default_allocator = 0;
- for(std::map<std::string, Allocator*>::iterator j = alloc_factory.begin();
- j != alloc_factory.end(); ++j)
+ for(u32bit j = 0; j != allocators.size(); j++)
{
- j->second->destroy();
- delete j->second;
+ allocators[j]->destroy();
+ delete allocators[j];
}
std::for_each(locks.begin(), locks.end(),
diff --git a/src/mem_pool.cpp b/src/mem_pool.cpp
index 00a9f2d06..24866d172 100644
--- a/src/mem_pool.cpp
+++ b/src/mem_pool.cpp
@@ -52,7 +52,7 @@ Pooling_Allocator::Memory_Block::Memory_Block(void* buf, u32bit map_size,
/*************************************************
* Compare a Memory_Block with a void pointer *
*************************************************/
-bool Pooling_Allocator::Memory_Block::operator<(const void* other) const
+inline bool Pooling_Allocator::Memory_Block::operator<(const void* other) const
{
if(buffer <= other && other < buffer_end)
return false;
@@ -60,14 +60,6 @@ bool Pooling_Allocator::Memory_Block::operator<(const void* other) const
}
/*************************************************
-* Compare two Memory_Block objects *
-*************************************************/
-bool Pooling_Allocator::Memory_Block::operator<(const Memory_Block& blk) const
- {
- return (buffer < blk.buffer);
- }
-
-/*************************************************
* See if ptr is contained by this block *
*************************************************/
bool Pooling_Allocator::Memory_Block::contains(void* ptr,