Package: liblucy-perl / 0.3.3-7

mips-unaligned-access.patch Patch series | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
Description: fix misaligned double access on mips
 Mips architecture allows accessing doubles only on 8-byte (sizeof(double))
 aligned addresses. The code tries to align these on sizeof(void*) which is 4
 on mips.
Author: Dejan Latinovic <Dejan.Latinovic@imgtec.com>
Acked-By: Damyan Ivanov <dmn@debian.org>
Bug-Debian: https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=762958
Forwarded: https://rt.cpan.org/Ticket/Display.html?id=99171
Bug: https://rt.cpan.org/Ticket/Display.html?id=99171

--- a/core/Lucy/Util/MemoryPool.c
+++ b/core/Lucy/Util/MemoryPool.c
@@ -24,12 +24,19 @@ S_init_arena(MemoryPool *self, size_t am
 
 #define DEFAULT_BUF_SIZE 0x100000 // 1 MiB
 
+// On MIPS, access to double values need to be 8-bytes aligned.
+#if defined (__mips__)
+#define BYTE_ALIGNED sizeof(double);
+#else
+#define BYTE_ALIGNED sizeof(void*);
+#endif
+
 // Enlarge amount so pointers will always be aligned.
 #define INCREASE_TO_WORD_MULTIPLE(_amount) \
     do { \
-        const size_t _remainder = _amount % sizeof(void*); \
+        const size_t _remainder = _amount % BYTE_ALIGNED; \
         if (_remainder) { \
-            _amount += sizeof(void*); \
+            _amount += BYTE_ALIGNED; \
             _amount -= _remainder; \
         } \
     } while (0)