[Debtags-commits] [svn] r1674 - in tagcoll/trunk: . tagcoll
Enrico Zini
enrico at costa.debian.org
Thu Apr 20 11:09:02 UTC 2006
Author: enrico
Date: Thu Apr 20 11:09:01 2006
New Revision: 1674
Modified:
tagcoll/trunk/ (props changed)
tagcoll/trunk/Makefile.am
tagcoll/trunk/tagcoll/MMapIndex.cc
tagcoll/trunk/tagcoll/MMapIndex.h
Log:
r8666 at viaza: enrico | 2006-04-20 12:08:13 +0100
word-align indexes in tests, to avoid bus errors
Added a comment about word alignment, and a utility function to do it
Compile tools/ before tests/, since tests/tagcoll-test needs it
Modified: tagcoll/trunk/Makefile.am
==============================================================================
--- tagcoll/trunk/Makefile.am (original)
+++ tagcoll/trunk/Makefile.am Thu Apr 20 11:09:01 2006
@@ -1,6 +1,6 @@
## Process this file with automake to produce Makefile.in
-SUBDIRS = tagcoll tests bench tools doc .
+SUBDIRS = tagcoll tools tests bench doc .
pkgconfigdir = $(libdir)/pkgconfig
pkgconfig_DATA=libtagcoll.pc
Modified: tagcoll/trunk/tagcoll/MMapIndex.cc
==============================================================================
--- tagcoll/trunk/tagcoll/MMapIndex.cc (original)
+++ tagcoll/trunk/tagcoll/MMapIndex.cc Thu Apr 20 11:09:01 2006
@@ -214,7 +214,7 @@
virtual ~TestIndexer() {}
/// Return the size of the encoded index data (in bytes)
- virtual int encodedSize() const { return data.size() + 1; }
+ virtual int encodedSize() const { return MMapIndex::align(data.size() + 1); }
/// Write the index data in the given buffer, which should be at least
/// encodedSize bytes
@@ -248,15 +248,15 @@
MasterMMapIndex master(fname);
TestIndex index1(master, 0);
- gen_ensure_equals(index1.size(), 6u);
+ gen_ensure_equals(index1.size(), MMapIndex::align(6u));
gen_ensure_equals(string(index1.get()), string("pippo"));
TestIndex index2(master, 1);
- gen_ensure_equals(index2.size(), 6u);
+ gen_ensure_equals(index2.size(), MMapIndex::align(6u));
gen_ensure_equals(string(index2.get()), string("pluto"));
TestIndex index3(master, 2);
- gen_ensure_equals(index3.size(), 9u);
+ gen_ensure_equals(index3.size(), MMapIndex::align(9u));
gen_ensure_equals(string(index3.get()), string("paperino"));
}
Modified: tagcoll/trunk/tagcoll/MMapIndex.h
==============================================================================
--- tagcoll/trunk/tagcoll/MMapIndex.h (original)
+++ tagcoll/trunk/tagcoll/MMapIndex.h Thu Apr 20 11:09:01 2006
@@ -39,6 +39,9 @@
* other, prefixed by an int that specifies their length:
*
* [size of index 1][index1][size of index 2][index]...
+ *
+ * Every index must make sure that its size is int-aligned, otherwise accessing
+ * it would cause a bus error in many architectures.
*/
class MasterMMapIndex
{
@@ -72,6 +75,13 @@
void init(const char* buf, int size);
void init(const MasterMMapIndex& master, size_t idx);
+
+ /// Round a value to the next word size in the current architecture
+ template<class INT>
+ static inline INT align(INT val)
+ {
+ return (val + sizeof(int) - 1) & ~(sizeof(int) - 1);
+ }
};
/**
More information about the Debtags-commits
mailing list