Skip to content

Commit ab69f59

Browse files
author
kalibera
committed
Fix alignment with custom memory allocator in tre.
git-svn-id: https://svn.r-project.org/R/trunk@87512 00db46b3-68df-0310-9c12-caf00c1e9a41
1 parent f165c3c commit ab69f59

File tree

4 files changed

+17
-8
lines changed

4 files changed

+17
-8
lines changed

src/extra/tre/tre-internal.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,15 @@ typedef enum { STR_WIDE, STR_BYTE, STR_MBS, STR_USER } tre_str_type_t;
155155
? (sizeof(type) - (((size_t)ptr) % sizeof(type))) \
156156
: 0)
157157

158+
/* R addition, only "long" has been used before for alignment of allocated
159+
data. With C11, one could use max_align_t. */
160+
typedef union {
161+
void *ptr;
162+
void (*funptr)(void);
163+
long long ll;
164+
double dbl;
165+
} anytype;
166+
158167
#undef MAX
159168
#undef MIN
160169
#define MAX(a, b) (((a) >= (b)) ? (a) : (b))

src/extra/tre/tre-match-approx.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -294,17 +294,17 @@ tre_tnfa_run_approx(const tre_tnfa_t *tnfa, const void *string, int len,
294294
/* Allocate `tmp_tags' from `buf'. */
295295
tmp_tags = (void *)buf;
296296
buf_cursor = buf + tag_bytes;
297-
buf_cursor += ALIGN(buf_cursor, long);
297+
buf_cursor += ALIGN(buf_cursor, anytype);
298298

299299
/* Allocate `reach' from `buf'. */
300300
reach = (void *)buf_cursor;
301301
buf_cursor += reach_bytes;
302-
buf_cursor += ALIGN(buf_cursor, long);
302+
buf_cursor += ALIGN(buf_cursor, anytype);
303303

304304
/* Allocate `reach_next' from `buf'. */
305305
reach_next = (void *)buf_cursor;
306306
buf_cursor += reach_bytes;
307-
buf_cursor += ALIGN(buf_cursor, long);
307+
buf_cursor += ALIGN(buf_cursor, anytype);
308308

309309
/* Allocate tag arrays for `reach' and `reach_next' from `buf'. */
310310
for (i = 0; i < tnfa->num_states; i++)

src/extra/tre/tre-match-parallel.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -177,16 +177,16 @@ tre_tnfa_run_parallel(const tre_tnfa_t *tnfa, const void *string, int len,
177177
/* Get the various pointers within tmp_buf (properly aligned). */
178178
tmp_tags = (void *)buf;
179179
tmp_buf = buf + tbytes;
180-
tmp_buf += ALIGN(tmp_buf, long);
180+
tmp_buf += ALIGN(tmp_buf, anytype);
181181
reach_next = (void *)tmp_buf;
182182
tmp_buf += rbytes;
183-
tmp_buf += ALIGN(tmp_buf, long);
183+
tmp_buf += ALIGN(tmp_buf, anytype);
184184
reach = (void *)tmp_buf;
185185
tmp_buf += rbytes;
186-
tmp_buf += ALIGN(tmp_buf, long);
186+
tmp_buf += ALIGN(tmp_buf, anytype);
187187
reach_pos = (void *)tmp_buf;
188188
tmp_buf += pbytes;
189-
tmp_buf += ALIGN(tmp_buf, long);
189+
tmp_buf += ALIGN(tmp_buf, anytype);
190190
for (i = 0; i < tnfa->num_states; i++)
191191
{
192192
reach[i].tags = (void *)tmp_buf;

src/extra/tre/tre-mem.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ tre_mem_alloc_impl(tre_mem_t mem, int provided, void *provided_block,
138138
}
139139

140140
/* Make sure the next pointer will be aligned. */
141-
size += ALIGN(mem->ptr + size, long);
141+
size += ALIGN(mem->ptr + size, anytype);
142142

143143
/* Allocate from current block. */
144144
ptr = mem->ptr;

0 commit comments

Comments
 (0)