authorgravatar for jacobly@ziglang.orgJacob Young <jacobly@ziglang.org> 2023-05-31 01:25:02-04:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2023-06-10 20:47:57-07:00
log71c4077c359096d0706a251a10eeae6c41f299ca
tree52260738aac6b4ff5f2954e6253ac7fa38b0d744
parent26fac15f485e89dc7106256e1aa79184c1761efd

Value: fix null test for c pointers


1 files changed, 7 insertions(+), 6 deletions(-)

src/value.zig+7-6
...@@ -2131,19 +2131,20 @@ pub const Value = struct {...@@ -2131,19 +2131,20 @@ pub const Value = struct {
2131 }2131 }
21322132
2133 /// Asserts the value is not undefined and not unreachable.2133 /// Asserts the value is not undefined and not unreachable.
2134 /// Integer value 0 is considered null because of C pointers.2134 /// C pointers with an integer value of 0 are also considered null.
2135 pub fn isNull(val: Value, mod: *Module) bool {2135 pub fn isNull(val: Value, mod: *Module) bool {
2136 return switch (val.toIntern()) {2136 return switch (val.toIntern()) {
2137 .undef => unreachable,2137 .undef => unreachable,
2138 .unreachable_value => unreachable,2138 .unreachable_value => unreachable,
2139
2140 .null_value => true,2139 .null_value => true,
2141
2142 else => return switch (mod.intern_pool.indexToKey(val.toIntern())) {2140 else => return switch (mod.intern_pool.indexToKey(val.toIntern())) {
2143 .undef => unreachable,2141 .undef => unreachable,
2144 .int => {2142 .ptr => |ptr| switch (ptr.addr) {
2145 var buf: BigIntSpace = undefined;2143 .int => {
2146 return val.toBigInt(&buf, mod).eqZero();2144 var buf: BigIntSpace = undefined;
2145 return val.toBigInt(&buf, mod).eqZero();
2146 },
2147 else => false,
2147 },2148 },
2148 .opt => |opt| opt.val == .none,2149 .opt => |opt| opt.val == .none,
2149 else => false,2150 else => false,