-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into err-ret-trace-improvements-1923
- Loading branch information
Showing
27 changed files
with
3,108 additions
and
2,518 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
const std = @import("std"); | ||
const common = @import("./common.zig"); | ||
|
||
comptime { | ||
@export(bcmp, .{ .name = "bcmp", .linkage = common.linkage }); | ||
} | ||
|
||
pub fn bcmp(vl: [*]allowzero const u8, vr: [*]allowzero const u8, n: usize) callconv(.C) c_int { | ||
@setRuntimeSafety(false); | ||
|
||
var index: usize = 0; | ||
while (index != n) : (index += 1) { | ||
if (vl[index] != vr[index]) { | ||
return 1; | ||
} | ||
} | ||
|
||
return 0; | ||
} | ||
|
||
test "bcmp" { | ||
const base_arr = &[_]u8{ 1, 1, 1 }; | ||
const arr1 = &[_]u8{ 1, 1, 1 }; | ||
const arr2 = &[_]u8{ 1, 0, 1 }; | ||
const arr3 = &[_]u8{ 1, 2, 1 }; | ||
|
||
try std.testing.expect(bcmp(base_arr[0..], arr1[0..], base_arr.len) == 0); | ||
try std.testing.expect(bcmp(base_arr[0..], arr2[0..], base_arr.len) != 0); | ||
try std.testing.expect(bcmp(base_arr[0..], arr3[0..], base_arr.len) != 0); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
const std = @import("std"); | ||
const common = @import("./common.zig"); | ||
|
||
comptime { | ||
@export(memcmp, .{ .name = "memcmp", .linkage = common.linkage }); | ||
} | ||
|
||
pub fn memcmp(vl: ?[*]const u8, vr: ?[*]const u8, n: usize) callconv(.C) c_int { | ||
@setRuntimeSafety(false); | ||
|
||
var index: usize = 0; | ||
while (index != n) : (index += 1) { | ||
const compare_val = @bitCast(i8, vl.?[index] -% vr.?[index]); | ||
if (compare_val != 0) { | ||
return compare_val; | ||
} | ||
} | ||
|
||
return 0; | ||
} | ||
|
||
test "memcmp" { | ||
const base_arr = &[_]u8{ 1, 1, 1 }; | ||
const arr1 = &[_]u8{ 1, 1, 1 }; | ||
const arr2 = &[_]u8{ 1, 0, 1 }; | ||
const arr3 = &[_]u8{ 1, 2, 1 }; | ||
|
||
try std.testing.expect(memcmp(base_arr[0..], arr1[0..], base_arr.len) == 0); | ||
try std.testing.expect(memcmp(base_arr[0..], arr2[0..], base_arr.len) > 0); | ||
try std.testing.expect(memcmp(base_arr[0..], arr3[0..], base_arr.len) < 0); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
const std = @import("std"); | ||
const common = @import("./common.zig"); | ||
|
||
comptime { | ||
@export(memcpy, .{ .name = "memcpy", .linkage = common.linkage }); | ||
} | ||
|
||
pub fn memcpy(noalias dest: ?[*]u8, noalias src: ?[*]const u8, len: usize) callconv(.C) ?[*]u8 { | ||
@setRuntimeSafety(false); | ||
|
||
if (len != 0) { | ||
var d = dest.?; | ||
var s = src.?; | ||
var n = len; | ||
while (true) { | ||
d[0] = s[0]; | ||
n -= 1; | ||
if (n == 0) break; | ||
d += 1; | ||
s += 1; | ||
} | ||
} | ||
|
||
return dest; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
const std = @import("std"); | ||
const common = @import("./common.zig"); | ||
|
||
comptime { | ||
@export(memmove, .{ .name = "memmove", .linkage = common.linkage }); | ||
} | ||
|
||
pub fn memmove(dest: ?[*]u8, src: ?[*]const u8, n: usize) callconv(.C) ?[*]u8 { | ||
@setRuntimeSafety(false); | ||
|
||
if (@ptrToInt(dest) < @ptrToInt(src)) { | ||
var index: usize = 0; | ||
while (index != n) : (index += 1) { | ||
dest.?[index] = src.?[index]; | ||
} | ||
} else { | ||
var index = n; | ||
while (index != 0) { | ||
index -= 1; | ||
dest.?[index] = src.?[index]; | ||
} | ||
} | ||
|
||
return dest; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
const std = @import("std"); | ||
const common = @import("./common.zig"); | ||
|
||
comptime { | ||
@export(memset, .{ .name = "memset", .linkage = common.linkage }); | ||
@export(__memset, .{ .name = "__memset", .linkage = common.linkage }); | ||
} | ||
|
||
pub fn memset(dest: ?[*]u8, c: u8, len: usize) callconv(.C) ?[*]u8 { | ||
@setRuntimeSafety(false); | ||
|
||
if (len != 0) { | ||
var d = dest.?; | ||
var n = len; | ||
while (true) { | ||
d[0] = c; | ||
n -= 1; | ||
if (n == 0) break; | ||
d += 1; | ||
} | ||
} | ||
|
||
return dest; | ||
} | ||
|
||
pub fn __memset(dest: ?[*]u8, c: u8, n: usize, dest_n: usize) callconv(.C) ?[*]u8 { | ||
if (dest_n < n) | ||
@panic("buffer overflow"); | ||
return memset(dest, c, n); | ||
} |
Oops, something went wrong.