diff --git a/builtins/files.c b/builtins/files.c index 524a862..6c83346 100644 --- a/builtins/files.c +++ b/builtins/files.c @@ -93,7 +93,7 @@ static file_t *_load_file(const char* filename, FILE *file) int64_t line_len = 0; while ((line_len = getline(&line_buf, &line_cap, file)) >= 0) { if (ret->line_capacity <= ret->num_lines) - ret->line_offsets = GC_REALLOC(ret->line_offsets, sizeof(int64_t)*(ret->line_capacity += 32)); + ret->line_offsets = GC_REALLOC(ret->line_offsets, sizeof(int64_t[ret->line_capacity += 32])); ret->line_offsets[ret->num_lines++] = file_size; fwrite(line_buf, sizeof(char), line_len, mem); fflush(mem); diff --git a/builtins/integers.c b/builtins/integers.c index ac8e506..ef9b5df 100644 --- a/builtins/integers.c +++ b/builtins/integers.c @@ -43,7 +43,7 @@ return CORD_asprintf(octal_fmt, (int)digits, (uint64_t)i); \ } \ public array_t KindOfInt ## $bits(c_type x) { \ - array_t bit_array = (array_t){.data=GC_MALLOC_ATOMIC(sizeof(bool)*8*sizeof(c_type)), .atomic=1, .stride=sizeof(bool), .length=8*sizeof(c_type)}; \ + array_t bit_array = (array_t){.data=GC_MALLOC_ATOMIC(sizeof(bool[8*sizeof(c_type)])), .atomic=1, .stride=sizeof(bool), .length=8*sizeof(c_type)}; \ bool *bits = bit_array.data + sizeof(c_type)*8; \ for (size_t i = 0; i < 8*sizeof(c_type); i++) { \ *(bits--) = x & 1; \ diff --git a/builtins/table.c b/builtins/table.c index 591acc9..6b63be8 100644 --- a/builtins/table.c +++ b/builtins/table.c @@ -102,7 +102,7 @@ static void maybe_copy_on_write(table_t *t, const TypeInfo *type) } if (t->bucket_info && t->bucket_info->data_refcount) { - int64_t size = sizeof(bucket_info_t) + t->bucket_info->count*sizeof(bucket_t); + int64_t size = sizeof(bucket_info_t) + sizeof(bucket_t[t->bucket_info->count]); t->bucket_info = memcpy(GC_MALLOC(size), t->bucket_info, size); t->bucket_info->data_refcount = 0; } @@ -208,9 +208,9 @@ static void hashmap_resize_buckets(table_t *t, uint32_t new_capacity, const Type { hdebug("About to resize from %u to %u\n", t->bucket_info ? t->bucket_info->count : 0, new_capacity); hshow(t); - int64_t alloc_size = sizeof(bucket_info_t) + (int64_t)(new_capacity)*sizeof(bucket_t); + int64_t alloc_size = sizeof(bucket_info_t) + sizeof(bucket_t[new_capacity]); t->bucket_info = GC_MALLOC_ATOMIC(alloc_size); - memset(t->bucket_info->buckets, 0, (int64_t)new_capacity * sizeof(bucket_t)); + memset(t->bucket_info->buckets, 0, sizeof(bucket_t[new_capacity])); t->bucket_info->count = new_capacity; t->bucket_info->last_free = new_capacity-1; // Rehash: diff --git a/builtins/text.c b/builtins/text.c index e8c476a..f39d42e 100644 --- a/builtins/text.c +++ b/builtins/text.c @@ -273,7 +273,7 @@ public array_t Text$split(CORD str, CORD split) size_t non_split = u8_strcspn(ustr + i, usplit); CORD chunk = CORD_substr((CORD)ustr, i, non_split); if (capacity <= 0) - strings.data = GC_REALLOC(strings.data, sizeof(CORD)*(capacity += 10)); + strings.data = GC_REALLOC(strings.data, sizeof(CORD[capacity += 10])); ((CORD*)strings.data)[strings.length++] = chunk; i += non_split; @@ -327,7 +327,7 @@ public array_t Text$codepoints(CORD text) uint32_t *codepoints = u8_to_u32(normalized, norm_len-1, codepoint_buf, &codepoint_len); array_t ret = { .length=codepoint_len, - .data=memcpy(GC_MALLOC_ATOMIC(sizeof(int32_t)*codepoint_len), codepoints, sizeof(int32_t)*codepoint_len), + .data=memcpy(GC_MALLOC_ATOMIC(sizeof(int32_t[codepoint_len])), codepoints, sizeof(int32_t[codepoint_len])), .stride=sizeof(int32_t), .atomic=1, }; @@ -345,7 +345,7 @@ public array_t Text$bytes(CORD text) --norm_len; // NUL byte array_t ret = { .length=norm_len, - .data=memcpy(GC_MALLOC_ATOMIC(sizeof(uint8_t)*norm_len), normalized, sizeof(uint8_t)*norm_len), + .data=memcpy(GC_MALLOC_ATOMIC(sizeof(uint8_t[norm_len])), normalized, sizeof(uint8_t[norm_len])), .stride=sizeof(uint8_t), .atomic=1, }; @@ -389,7 +389,7 @@ public int64_t Text$num_bytes(CORD text) public array_t Text$character_names(CORD text) { array_t codepoints = Text$codepoints(text); - array_t ret = {.length=codepoints.length, .stride=sizeof(CORD), .data=GC_MALLOC(sizeof(CORD)*codepoints.length)}; + array_t ret = {.length=codepoints.length, .stride=sizeof(CORD), .data=GC_MALLOC(sizeof(CORD[codepoints.length]))}; for (int64_t i = 0; i < codepoints.length; i++) { char buf[UNINAME_MAX]; unicode_character_name(*(ucs4_t*)(codepoints.data + codepoints.stride*i), buf); diff --git a/builtins/types.h b/builtins/types.h index ac2166f..864a55c 100644 --- a/builtins/types.h +++ b/builtins/types.h @@ -62,7 +62,7 @@ typedef struct TypeInfo { .tag=TableInfo, .TableInfo.key=key_expr, .TableInfo.value=value_expr}) #define $FunctionInfo(typestr) &((TypeInfo){.size=sizeof(void*), .align=__alignof__(void*), \ .tag=FunctionInfo, .FunctionInfo.type_str=typestr}) -#define $ClosureInfo(typestr) &((TypeInfo){.size=2*sizeof(void*), .align=__alignof__(void*), \ +#define $ClosureInfo(typestr) &((TypeInfo){.size=sizeof(void*[2]), .align=__alignof__(void*), \ .tag=FunctionInfo, .FunctionInfo.type_str=typestr}) #define $TypeInfoInfo(typestr) &((TypeInfo){.size=sizeof(TypeInfo), .align=__alignof__(TypeInfo), \ .tag=TypeInfoInfo, .TypeInfoInfo.type_str=typestr})