mirror of
https://github.com/ziglang/zig.git
synced 2026-02-13 04:48:20 +00:00
Value: fix null test for c pointers
This commit is contained in:
parent
26fac15f48
commit
71c4077c35
@ -2131,19 +2131,20 @@ pub const Value = struct {
|
||||
}
|
||||
|
||||
/// Asserts the value is not undefined and not unreachable.
|
||||
/// Integer value 0 is considered null because of C pointers.
|
||||
/// C pointers with an integer value of 0 are also considered null.
|
||||
pub fn isNull(val: Value, mod: *Module) bool {
|
||||
return switch (val.toIntern()) {
|
||||
.undef => unreachable,
|
||||
.unreachable_value => unreachable,
|
||||
|
||||
.null_value => true,
|
||||
|
||||
else => return switch (mod.intern_pool.indexToKey(val.toIntern())) {
|
||||
.undef => unreachable,
|
||||
.int => {
|
||||
var buf: BigIntSpace = undefined;
|
||||
return val.toBigInt(&buf, mod).eqZero();
|
||||
.ptr => |ptr| switch (ptr.addr) {
|
||||
.int => {
|
||||
var buf: BigIntSpace = undefined;
|
||||
return val.toBigInt(&buf, mod).eqZero();
|
||||
},
|
||||
else => false,
|
||||
},
|
||||
.opt => |opt| opt.val == .none,
|
||||
else => false,
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user