diff options
| author | Andrew Kelley <superjoe30@gmail.com> | 2016-11-18 23:52:42 -0500 |
|---|---|---|
| committer | Andrew Kelley <superjoe30@gmail.com> | 2016-11-18 23:52:42 -0500 |
| commit | 19037014e5a25eaac9564d22cc04cf12fb6ef98e (patch) | |
| tree | ec7ec61515ddf48ab94585d054bb69c329febce3 /std | |
| parent | 31565efe9d6cde2e4909f986d50f8c46166d3311 (diff) | |
| download | zig-19037014e5a25eaac9564d22cc04cf12fb6ef98e.tar.gz zig-19037014e5a25eaac9564d22cc04cf12fb6ef98e.zip | |
IR: more maybe type support
Diffstat (limited to 'std')
| -rw-r--r-- | std/builtin.zig | 19 |
1 files changed, 13 insertions, 6 deletions
diff --git a/std/builtin.zig b/std/builtin.zig index 76978a34b4..5371c2c99e 100644 --- a/std/builtin.zig +++ b/std/builtin.zig @@ -1,24 +1,31 @@ // These functions are provided when not linking against libc because LLVM // sometimes generates code that calls them. -// TODO dest should be nullable and return value should be nullable -export fn memset(dest: &u8, c: u8, n: usize) -> &u8 { +export fn memset(dest: ?&u8, c: u8, n: usize) -> ?&u8 { @setDebugSafety(this, false); + if (n == 0) + return dest; + + const d = ??dest; var index: usize = 0; while (index != n; index += 1) - dest[index] = c; + d[index] = c; return dest; } -// TODO dest, source, and return value should be nullable -export fn memcpy(noalias dest: &u8, noalias src: &const u8, n: usize) -> &u8 { +export fn memcpy(noalias dest: ?&u8, noalias src: ?&const u8, n: usize) -> ?&u8 { @setDebugSafety(this, false); + if (n == 0) + return dest; + + const d = ??dest; + const s = ??src; var index: usize = 0; while (index != n; index += 1) - dest[index] = src[index]; + d[index] = s[index]; return dest; } |
