--- a/e32tools/elf2e32/source/deflatecompress.cpp Wed Jun 16 16:51:40 2010 +0300
+++ b/e32tools/elf2e32/source/deflatecompress.cpp Wed Jun 23 16:56:47 2010 +0800
@@ -29,6 +29,15 @@
const TUint KDeflateHashMultiplier=0xAC4B9B19u;
const TInt KDeflateHashShift=24;
+#define COMPILE_TIME_ASSERT(e) \
+ switch (0) \
+ { \
+ case 0: \
+ case e: \
+ ; \
+ }
+
+
/**
Class HDeflateHash
@internalComponent
@@ -125,9 +134,31 @@
*/
inline HDeflateHash* HDeflateHash::NewLC(TInt aLinks)
{
- //return new(HMem::Alloc(0,_FOFF(HDeflateHash,iOffset[Min(aLinks,KDeflateMaxDistance)]))) HDeflateHash;
- return new(new char[_FOFF(HDeflateHash,iOffset[Min(aLinks,KDeflateMaxDistance)])]) HDeflateHash;
-}
+#if __GNUC__ >= 4
+ // Try to detect if the class' layout has changed.
+ COMPILE_TIME_ASSERT( sizeof(HDeflateHash) == 1028 );
+ COMPILE_TIME_ASSERT( sizeof(TOffset) == 2 );
+ COMPILE_TIME_ASSERT( offsetof(HDeflateHash, iHash) < offsetof(HDeflateHash, iOffset) );
+
+ // Compute the size of the class, including rounding it up to a multiple of 4
+ // bytes.
+
+ unsigned n = sizeof(TInt) * 256 + sizeof(TOffset) * Min(aLinks, KDeflateMaxDistance);
+
+ while (n & 0x1f)
+ {
+ n++;
+ }
+ // Allocate the raw memory ...
+ void* p = ::operator new(n);
+ // ... And create the object in that memory.
+ return new(p) HDeflateHash;
+#else
+ return new(new char[_FOFF(HDeflateHash,iOffset[Min(aLinks,KDeflateMaxDistance)])]) HDeflateHash;
+#endif
+ }
+
+
/**
Hash function for HDeflateHash