remove dubious @intFromPtr calls

This commit is contained in:
Meghan Denny
2025-02-12 15:35:07 -08:00
parent 506ea28b36
commit 8305e60bf2
4 changed files with 7 additions and 21 deletions

View File

@@ -3065,7 +3065,7 @@ fn NewRequestContext(comptime ssl_enabled: bool, comptime debug_mode: bool, comp
const streamLog = Output.scoped(.ReadableStream, false);
pub fn didUpgradeWebSocket(this: *RequestContext) bool {
return @intFromPtr(this.upgrade_context) == std.math.maxInt(usize);
return this.upgrade_context == null;
}
fn toAsyncWithoutAbortHandler(ctx: *RequestContext, req: *uws.Request, request_object: *Request) void {
@@ -6271,7 +6271,7 @@ pub fn NewServer(comptime NamespaceType: type, comptime ssl_enabled_: bool, comp
return JSC.jsBoolean(false);
}
if (upgrader.upgrade_context == null or @intFromPtr(upgrader.upgrade_context) == std.math.maxInt(usize)) {
if (upgrader.upgrade_context == null) {
return JSC.jsBoolean(false);
}

View File

@@ -1793,26 +1793,13 @@ pub const fs_t = extern struct {
const UV_FS_CLEANEDUP = 0x0010;
pub inline fn deinit(this: *fs_t) void {
this.assertInitialized();
uv_fs_req_cleanup(this);
this.assertCleanedUp();
}
// This assertion tripping is a sign that .deinit() is going to cause invalid memory access
pub inline fn assertInitialized(this: *const fs_t) void {
if (bun.Environment.allow_assert) {
if (@intFromPtr(this.loop) == 0xAAAAAAAAAAAA0000) {
@panic("uv_fs_t was not initialized");
}
}
}
// This assertion tripping is a sign that a memory leak may happen
pub inline fn assertCleanedUp(this: *const fs_t) void {
if (bun.Environment.allow_assert) {
if (@intFromPtr(this.loop) == 0xAAAAAAAAAAAA0000) {
return;
}
if ((this.flags & UV_FS_CLEANEDUP) != 0) {
return;
}
@@ -1821,7 +1808,6 @@ pub const fs_t = extern struct {
}
pub inline fn ptrAs(this: *fs_t, comptime T: type) T {
this.assertInitialized();
return @ptrCast(this.ptr);
}

View File

@@ -46,7 +46,7 @@ pub const Header = struct {
};
pub fn isMultiline(self: Header) bool {
return @intFromPtr(self.name.ptr) == 0;
return self.name.len == 0;
}
pub fn format(self: Header, comptime _: []const u8, _: fmt.FormatOptions, writer: anytype) !void {

View File

@@ -3362,7 +3362,7 @@ pub const Expr = struct {
pub fn hasAnyPropertyNamed(expr: *const Expr, comptime names: []const string) bool {
if (std.meta.activeTag(expr.data) != .e_object) return false;
const obj = expr.data.e_object;
if (@intFromPtr(obj.properties.ptr) == 0) return false;
if (obj.properties.len == 0) return false;
for (obj.properties.slice()) |prop| {
if (prop.value == null) continue;
@@ -3527,7 +3527,7 @@ pub const Expr = struct {
pub fn asProperty(expr: *const Expr, name: string) ?Query {
if (std.meta.activeTag(expr.data) != .e_object) return null;
const obj = expr.data.e_object;
if (@intFromPtr(obj.properties.ptr) == 0) return null;
if (obj.properties.len == 0) return null;
return obj.asProperty(name);
}
@@ -3535,7 +3535,7 @@ pub const Expr = struct {
pub fn asPropertyStringMap(expr: *const Expr, name: string, allocator: std.mem.Allocator) ?*bun.StringArrayHashMap(string) {
if (std.meta.activeTag(expr.data) != .e_object) return null;
const obj_ = expr.data.e_object;
if (@intFromPtr(obj_.properties.ptr) == 0) return null;
if (obj_.properties.len == 0) return null;
const query = obj_.asProperty(name) orelse return null;
if (query.expr.data != .e_object) return null;
@@ -3581,7 +3581,7 @@ pub const Expr = struct {
pub fn asArray(expr: *const Expr) ?ArrayIterator {
if (std.meta.activeTag(expr.data) != .e_array) return null;
const array = expr.data.e_array;
if (array.items.len == 0 or @intFromPtr(array.items.ptr) == 0) return null;
if (array.items.len == 0) return null;
return ArrayIterator{ .array = array, .index = 0 };
}