Skip to content

Commit d73189d

Browse files
author
Fabrice Bellard
committed
fixed compilation with clang
1 parent 99e9181 commit d73189d

1 file changed

Lines changed: 11 additions & 6 deletions

File tree

quickjs.c

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -299,7 +299,7 @@ typedef struct {
299299
#ifdef JS_MALLOC_USE_ITER
300300
struct list_head large_block_list; /* list of JSMallocLargeBlockHeader.link */
301301
#endif
302-
JSMallocBlockHeader zero_size_block;
302+
__attribute__((aligned(JS_MALLOC_ALIGN))) uint8_t zero_size_block[sizeof(JSMallocBlockHeader)];
303303

304304
/* callbacks to the host malloc */
305305
JSMallocFunctions mf;
@@ -1457,11 +1457,16 @@ static int get_block_size_index(size_t size)
14571457
}
14581458
}
14591459

1460+
static JSMallocBlockHeader *get_zero_size_block(JSMallocContext *s)
1461+
{
1462+
return (JSMallocBlockHeader *)s->zero_size_block;
1463+
}
1464+
14601465
static void js_malloc_init(JSMallocContext *s)
14611466
{
14621467
int i;
14631468
memset(s, 0, sizeof(*s));
1464-
s->zero_size_block.u.block_idx = FREE_NIL;
1469+
get_zero_size_block(s)->u.block_idx = FREE_NIL;
14651470
for(i = 0; i < JS_MALLOC_BLOCK_SIZE_COUNT; i++) {
14661471
init_list_head(&s->arena_list[i]);
14671472
init_list_head(&s->free_arena_list[i]);
@@ -1537,7 +1542,7 @@ static void *__js_malloc(JSMallocContext *s, size_t size)
15371542
{
15381543
size_t total_size;
15391544
if (unlikely(size == 0)) {
1540-
JSMallocBlockHeader *b = &s->zero_size_block;
1545+
JSMallocBlockHeader *b = get_zero_size_block(s);
15411546
return b->user_data;
15421547
} else {
15431548
total_size = ((size + JS_MALLOC_ALIGN - 1) & ~(JS_MALLOC_ALIGN - 1)) +
@@ -1587,7 +1592,7 @@ static void __js_free(JSMallocContext *s, void *ptr)
15871592
b = container_of(ptr, JSMallocBlockHeader, user_data);
15881593
if (unlikely(b->u.block_idx == FREE_NIL)) {
15891594
/* large or zero size block */
1590-
if (b == &s->zero_size_block) {
1595+
if (b == get_zero_size_block(s)) {
15911596
/* nothing to do */
15921597
} else {
15931598
JSMallocLargeBlockHeader *lb = container_of(ptr, JSMallocLargeBlockHeader, header.user_data);
@@ -1630,7 +1635,7 @@ static void *__js_realloc(JSMallocContext *s, void *ptr, size_t size)
16301635
}
16311636
b = container_of(ptr, JSMallocBlockHeader, user_data);
16321637
if (b->u.block_idx == FREE_NIL) {
1633-
if (b == &s->zero_size_block) {
1638+
if (b == get_zero_size_block(s)) {
16341639
return __js_malloc(s, size);
16351640
} else {
16361641
JSMallocLargeBlockHeader *lb, *new_lb;
@@ -1689,7 +1694,7 @@ static size_t __js_malloc_usable_size(JSMallocContext *s, const char *ptr)
16891694
return 0;
16901695
b = container_of(ptr, JSMallocBlockHeader, user_data);
16911696
if (b->u.block_idx == FREE_NIL) {
1692-
if (b == &s->zero_size_block) {
1697+
if (b == get_zero_size_block(s)) {
16931698
return 0;
16941699
} else {
16951700
JSMallocLargeBlockHeader *lb;

0 commit comments

Comments
 (0)