Tags on pointers need to be cleared on Linux

This commit is contained in:
Jarred SUmner
2022-01-21 15:19:50 -08:00
parent 8f7cf6bf47
commit c0a446df02
3 changed files with 14 additions and 18 deletions

View File

@@ -203,13 +203,11 @@ pub const TransformTask = struct {
if (printed > 0) {
buffer_writer = printer.ctx;
buffer_writer.buffer.list.expandToCapacity();
buffer_writer.buffer.list.items = buffer_writer.written;
// This works around a mimalloc and/or Zig allocator bug
buffer_writer.buffer.list.items = buffer_writer.buffer.list.items[0..printed];
var output_code = JSC.ZigString.init(buffer_writer.buffer.toOwnedSlice());
output_code.mark();
this.output_code = output_code;
this.output_code = JSC.ZigString.init(buffer_writer.written);
this.output_code.mark();
} else {
this.output_code = ZigString.init("");
}

View File

@@ -97,7 +97,7 @@ pub const ZigString = extern struct {
}
pub inline fn utf16Slice(this: *const ZigString) []align(1) const u16 {
return @ptrCast([*]align(1) const u16, this.ptr)[0..this.len];
return @ptrCast([*]align(1) const u16, untagged(this.ptr))[0..this.len];
}
pub fn fromStringPointer(ptr: StringPointer, buf: string, to: *ZigString) void {
@@ -163,8 +163,14 @@ pub const ZigString = extern struct {
pub const Empty = ZigString{ .ptr = "", .len = 0 };
inline fn untagged(ptr: [*]const u8) [*]const u8 {
// this can be null ptr, so long as it's also a 0 length string
@setRuntimeSafety(false);
return @intToPtr([*]const u8, @truncate(u53, @ptrToInt(ptr)));
}
pub fn slice(this: *const ZigString) []const u8 {
return this.ptr[0..@minimum(this.len, std.math.maxInt(u32))];
return untagged(this.ptr)[0..@minimum(this.len, std.math.maxInt(u32))];
}
pub fn sliceZBuf(this: ZigString, buf: *[std.fs.MAX_PATH_BYTES]u8) ![:0]const u8 {
@@ -172,7 +178,7 @@ pub const ZigString = extern struct {
}
pub inline fn full(this: *const ZigString) []const u8 {
return this.ptr[0..this.len];
return untagged(this.ptr)[0..this.len];
}
pub fn trimmedSlice(this: *const ZigString) []const u8 {

View File

@@ -90,19 +90,11 @@ static const WTF::String toString(ZigString str) {
}
static const WTF::String toStringCopy(ZigString str) {
if (str.len == 0 || str.ptr == nullptr) { return WTF::String(); }
return !isTaggedUTF16Ptr(str.ptr) ? WTF::String(WTF::StringImpl::create(str.ptr, str.len))
: WTF::String(WTF::StringImpl::create(
reinterpret_cast<const UChar *>(str.ptr), str.len));
return toString(str).isolatedCopy();
}
static WTF::String toStringNotConst(ZigString str) {
if (str.len == 0 || str.ptr == nullptr) { return WTF::String(); }
return !isTaggedUTF16Ptr(str.ptr) ? WTF::String(WTF::StringImpl::create(str.ptr, str.len))
: WTF::String(WTF::StringImpl::create(
reinterpret_cast<const UChar *>(str.ptr), str.len));
return toString(str).isolatedCopy();
}
static const JSC::JSString *toJSString(ZigString str, JSC::JSGlobalObject *global) {