Fix one of the astro segfaults, also fix bun init version (#4079)

* 4->16

* add assertions

* fix version stuff
This commit is contained in:
dave caruso
2023-08-08 22:27:18 -07:00
committed by GitHub
parent 63f58f4026
commit 450b066cb8
2 changed files with 22 additions and 15 deletions

View File

@@ -1480,9 +1480,12 @@ pub fn convertUTF16ToUTF8(list_: std.ArrayList(u8), comptime Type: type, utf16:
pub fn toUTF8AllocWithType(allocator: std.mem.Allocator, comptime Type: type, utf16: Type) ![]u8 {
if (bun.FeatureFlags.use_simdutf and comptime Type == []const u16) {
const length = bun.simdutf.length.utf8.from.utf16.le(utf16);
// add 4 bytes of padding for SIMDUTF
var list = try std.ArrayList(u8).initCapacity(allocator, length + 4);
// add 16 bytes of padding for SIMDUTF
var list = try std.ArrayList(u8).initCapacity(allocator, length + 16);
list = try convertUTF16ToUTF8(list, Type, utf16);
if (Environment.allow_assert) {
std.debug.assert(list.items.len == length);
}
return list.items;
}
@@ -1496,7 +1499,11 @@ pub fn toUTF8ListWithType(list_: std.ArrayList(u8), comptime Type: type, utf16:
var list = list_;
const length = bun.simdutf.length.utf8.from.utf16.le(utf16);
try list.ensureTotalCapacityPrecise(length + 16);
return convertUTF16ToUTF8(list, Type, utf16);
const buf = try convertUTF16ToUTF8(list, Type, utf16);
if (Environment.allow_assert) {
std.debug.assert(buf.items.len == length);
}
return buf;
}
return toUTF8ListWithTypeBun(list_, Type, utf16);