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 {
21312131 }
21322132
21332133 /// 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.
21352135 pub fn isNull(val: Value, mod: *Module) bool {
21362136 return switch (val.toIntern()) {
21372137 .undef => unreachable,
21382138 .unreachable_value => unreachable,
2139
21402139 .null_value => true,
2141
21422140 else => return switch (mod.intern_pool.indexToKey(val.toIntern())) {
21432141 .undef => unreachable,
2144 .int => {
2145 var buf: BigIntSpace = undefined;
2146 return val.toBigInt(&buf, mod).eqZero();
2142 .ptr => |ptr| switch (ptr.addr) {
2143 .int => {
2144 var buf: BigIntSpace = undefined;
2145 return val.toBigInt(&buf, mod).eqZero();
2146 },
2147 else => false,
21472148 },
21482149 .opt => |opt| opt.val == .none,
21492150 else => false,