Auto cpp->zig bindings (#20881)

Co-authored-by: pfgithub <6010774+pfgithub@users.noreply.github.com>
Co-authored-by: Ben Grant <ben@bun.sh>
Co-authored-by: Claude <noreply@anthropic.com>
This commit is contained in:
pfg
2025-07-21 16:26:07 -07:00
committed by GitHub
parent d2a4fb8124
commit 60faa8696f
35 changed files with 1026 additions and 273 deletions

View File

@@ -45,9 +45,8 @@ pub const WTFStringImplStruct = extern struct {
return if (this.is8Bit()) this.m_length else this.m_length * 2;
}
extern fn WTFStringImpl__isThreadSafe(WTFStringImpl) bool;
pub fn isThreadSafe(this: WTFStringImpl) bool {
return WTFStringImpl__isThreadSafe(this);
return bun.cpp.WTFStringImpl__isThreadSafe(this);
}
pub fn byteSlice(this: WTFStringImpl) []const u8 {
@@ -91,7 +90,7 @@ pub const WTFStringImplStruct = extern struct {
JSC.markBinding(@src());
const current_count = self.refCount();
bun.assert(self.hasAtLeastOneRef()); // do not use current_count, it breaks for static strings
Bun__WTFStringImpl__deref(self);
bun.cpp.Bun__WTFStringImpl__deref(self);
if (comptime bun.Environment.allow_assert) {
if (current_count > 1) {
bun.assert(self.refCount() < current_count or self.isStatic());
@@ -103,7 +102,7 @@ pub const WTFStringImplStruct = extern struct {
JSC.markBinding(@src());
const current_count = self.refCount();
bun.assert(self.hasAtLeastOneRef()); // do not use current_count, it breaks for static strings
Bun__WTFStringImpl__ref(self);
bun.cpp.Bun__WTFStringImpl__ref(self);
bun.assert(self.refCount() > current_count or self.isStatic());
}
@@ -117,11 +116,10 @@ pub const WTFStringImplStruct = extern struct {
return ZigString.Slice.init(this.refCountAllocator(), this.latin1Slice());
}
extern fn Bun__WTFStringImpl__ensureHash(this: WTFStringImpl) void;
/// Compute the hash() if necessary
pub fn ensureHash(this: WTFStringImpl) void {
JSC.markBinding(@src());
Bun__WTFStringImpl__ensureHash(this);
bun.cpp.Bun__WTFStringImpl__ensureHash(this);
}
pub fn toUTF8(this: WTFStringImpl, allocator: std.mem.Allocator) ZigString.Slice {
@@ -217,12 +215,8 @@ pub const WTFStringImplStruct = extern struct {
}
pub fn hasPrefix(self: WTFStringImpl, text: []const u8) bool {
return Bun__WTFStringImpl__hasPrefix(self, text.ptr, text.len);
return bun.cpp.Bun__WTFStringImpl__hasPrefix(self, text.ptr, text.len);
}
extern fn Bun__WTFStringImpl__deref(self: WTFStringImpl) void;
extern fn Bun__WTFStringImpl__ref(self: WTFStringImpl) void;
extern fn Bun__WTFStringImpl__hasPrefix(self: *const WTFStringImplStruct, offset: [*]const u8, length: usize) bool;
};
pub const StringImplAllocator = struct {