summaryrefslogtreecommitdiffstats
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
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>
-rw-r--r--parser/ast.h2
-rw-r--r--parser/list.h2
-rw-r--r--parser/rpp/pp-symbol.h9
-rw-r--r--parser/rxx_allocator.h18
-rw-r--r--parser/smallobject.h6
5 files changed, 33 insertions, 4 deletions
diff --git a/parser/ast.h b/parser/ast.h
index aa98ee4d..d9849764 100644
--- a/parser/ast.h
+++ b/parser/ast.h
@@ -862,7 +862,7 @@ struct QEnumsAST : public DeclarationAST
template <class _Tp>
_Tp *CreateNode(pool *memory_pool)
{
- _Tp *node = reinterpret_cast<_Tp*>(memory_pool->allocate(sizeof(_Tp)));
+ _Tp *node = reinterpret_cast<_Tp*>(memory_pool->allocate(sizeof(_Tp), strideof(_Tp)));
node->kind = _Tp::__node_kind;
return node;
}
diff --git a/parser/list.h b/parser/list.h
index 64aef452..fe0e6276 100644
--- a/parser/list.h
+++ b/parser/list.h
@@ -35,7 +35,7 @@ struct ListNode {
mutable const ListNode<Tp> *next;
static ListNode *create(const Tp &element, pool *p) {
- ListNode<Tp> *node = new(p->allocate(sizeof(ListNode))) ListNode();
+ ListNode<Tp> *node = new(p->allocate(sizeof(ListNode), strideof(ListNode))) ListNode();
node->element = element;
node->index = 0;
node->next = node;
diff --git a/parser/rpp/pp-symbol.h b/parser/rpp/pp-symbol.h
index eef66837..8078aba8 100644
--- a/parser/rpp/pp-symbol.h
+++ b/parser/rpp/pp-symbol.h
@@ -39,6 +39,11 @@ class pp_symbol
static rxx_allocator<char>__allocator;
return __allocator;
}
+ static rxx_allocator<pp_fast_string> &ppfs_allocator_instance ()
+ {
+ static rxx_allocator<pp_fast_string>__ppfs_allocator;
+ return __ppfs_allocator;
+ }
public:
static int &N() {
@@ -52,7 +57,7 @@ public:
memcpy(data, __data, __size);
data[__size] = '\0';
- char *where = allocator_instance().allocate(sizeof(pp_fast_string));
+ pp_fast_string *where = ppfs_allocator_instance ().allocate (sizeof (pp_fast_string));
return new(where) pp_fast_string(data, __size);
}
@@ -71,7 +76,7 @@ public:
std::copy(__first, __last, data);
data[__size] = '\0';
- char *where = allocator_instance().allocate(sizeof(pp_fast_string));
+ pp_fast_string *where = ppfs_allocator_instance ().allocate (sizeof (pp_fast_string));
return new(where) pp_fast_string(data, __size);
}
diff --git a/parser/rxx_allocator.h b/parser/rxx_allocator.h
index f0159e93..8325edbd 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*/) {}
diff --git a/parser/smallobject.h b/parser/smallobject.h
index 52cdc232..a9eb4990 100644
--- a/parser/smallobject.h
+++ b/parser/smallobject.h
@@ -35,6 +35,7 @@ class pool
public:
inline void *allocate(std::size_t __size);
+ inline void *allocate(std::size_t __size, std::size_t __stride);
};
inline void *pool::allocate(std::size_t __size)
@@ -42,6 +43,11 @@ inline void *pool::allocate(std::size_t __size)
return __alloc.allocate(__size);
}
+inline void *pool::allocate(std::size_t __size, std::size_t __stride)
+{
+ return __alloc.allocate(__size, __stride);
+}
+
#endif
// kate: space-indent on; indent-width 2; replace-tabs on;