aboutsummaryrefslogtreecommitdiffstats
path: root/parser/rxx_allocator.h
diff options
context:
space:
mode:
authorModestas Vainius <modestas@vainius.eu>2010-09-02 10:51:13 -0300
committerHugo Parente Lima <hugo.pl@gmail.com>2012-03-09 19:10:09 -0300
commit396b71f4ddcbcdd7772bb9c02be8df642b7a1be2 (patch)
tree644a225998369b11f85288c2ea30d8a3028079ee /parser/rxx_allocator.h
parent2d170a0b8b1519befc4cdad57a0a46ccf8d16e0a (diff)
Fixes various memory alignment issues which cause generator to crash on alignment-sensitive architectures.
Reviewer: Luciano Wolf <luciano.wolf@openbossa.org> Renato Araújo <renato.filho@openbossa.org>
Diffstat (limited to 'parser/rxx_allocator.h')
-rw-r--r--parser/rxx_allocator.h18
1 files changed, 18 insertions, 0 deletions
diff --git a/parser/rxx_allocator.h b/parser/rxx_allocator.h
index f0159e936..8325edbdf 100644
--- a/parser/rxx_allocator.h
+++ b/parser/rxx_allocator.h
@@ -24,6 +24,18 @@
#include <string.h>
#include <memory>
+// Stride calculation
+template <typename T>
+struct Tchar {
+ T t;
+ char c;
+};
+
+#define strideof(T) \
+ ((sizeof(Tchar<T>) > sizeof(T)) ? \
+ sizeof(Tchar<T>)-sizeof(T) : sizeof(T))
+
+
/**The allocator which uses fixed size blocks for allocation of its elements.
Block size is currently 64k, allocated space is not reclaimed,
if the size of the element being allocated extends the amount of free
@@ -93,6 +105,12 @@ public:
return p;
}
+ pointer allocate(size_type __n, size_type stride, const void* = 0) {
+ if (reinterpret_cast<size_type>(_M_current_block + _M_current_index) % stride > 0)
+ _M_current_index += stride - reinterpret_cast<size_type>(_M_current_block + _M_current_index) % stride;
+ return allocate(__n);
+ }
+
/**Deallocate does nothing in this implementation.*/
void deallocate(pointer /*__p*/, size_type /*__n*/) {}