aboutsummaryrefslogtreecommitdiff
path: root/std
diff options
context:
space:
mode:
authorAndrew Kelley <andrew@ziglang.org>2019-06-15 10:34:04 -0400
committerAndrew Kelley <andrew@ziglang.org>2019-06-15 10:34:04 -0400
commit60025a37045835c8bbf914eccdbeba6d6e2c275f (patch)
tree38282635e1f5aa5be22cf96e6b8cddbb72e971f4 /std
parentacf16b5fb34e3ce985df16cba1be1455492e4564 (diff)
parent7c5ceb0c4cdf5fafadd92b13048bc9878554abc4 (diff)
downloadzig-60025a37045835c8bbf914eccdbeba6d6e2c275f.tar.gz
zig-60025a37045835c8bbf914eccdbeba6d6e2c275f.zip
Merge remote-tracking branch 'origin/master' into copy-elision-3
Diffstat (limited to 'std')
-rw-r--r--std/debug.zig11
-rw-r--r--std/hash_map.zig29
-rw-r--r--std/process.zig2
3 files changed, 32 insertions, 10 deletions
diff --git a/std/debug.zig b/std/debug.zig
index 253f250713..ae9a5227c9 100644
--- a/std/debug.zig
+++ b/std/debug.zig
@@ -85,8 +85,8 @@ fn wantTtyColor() bool {
/// TODO multithreaded awareness
pub fn dumpCurrentStackTrace(start_addr: ?usize) void {
const stderr = getStderrStream() catch return;
- if (os.wasi.is_the_target) {
- stderr.print("Unable to dump stack trace: unimplemented on WASI\n") catch return;
+ if (builtin.strip_debug_info) {
+ stderr.print("Unable to dump stack trace: debug info stripped\n") catch return;
return;
}
const debug_info = getSelfDebugInfo() catch |err| {
@@ -151,8 +151,8 @@ pub fn captureStackTrace(first_address: ?usize, stack_trace: *builtin.StackTrace
/// TODO multithreaded awareness
pub fn dumpStackTrace(stack_trace: builtin.StackTrace) void {
const stderr = getStderrStream() catch return;
- if (os.wasi.is_the_target) {
- stderr.print("Unable to dump stack trace: unimplemented on WASI\n") catch return;
+ if (builtin.strip_debug_info) {
+ stderr.print("Unable to dump stack trace: debug info stripped\n") catch return;
return;
}
const debug_info = getSelfDebugInfo() catch |err| {
@@ -223,6 +223,7 @@ pub fn writeStackTrace(
debug_info: *DebugInfo,
tty_color: bool,
) !void {
+ if (builtin.strip_debug_info) return error.MissingDebugInfo;
var frame_index: usize = 0;
var frames_left: usize = std.math.min(stack_trace.index, stack_trace.instruction_addresses.len);
@@ -783,6 +784,8 @@ pub const OpenSelfDebugInfoError = error{
};
pub fn openSelfDebugInfo(allocator: *mem.Allocator) !DebugInfo {
+ if (builtin.strip_debug_info)
+ return error.MissingDebugInfo;
if (windows.is_the_target) {
return openSelfDebugInfoWindows(allocator);
}
diff --git a/std/hash_map.zig b/std/hash_map.zig
index 7336817954..df7ba740e8 100644
--- a/std/hash_map.zig
+++ b/std/hash_map.zig
@@ -183,6 +183,11 @@ pub fn HashMap(comptime K: type, comptime V: type, comptime hash: fn (key: K) u3
return putAssumeCapacity(self, key, value);
}
+ /// Calls put() and asserts that no kv pair is clobbered.
+ pub fn putNoClobber(self: *Self, key: K, value: V) !void {
+ assert((try self.put(key, value)) == null);
+ }
+
pub fn putAssumeCapacity(self: *Self, key: K, value: V) ?KV {
assert(self.count() < self.entries.len);
self.incrementModificationCount();
@@ -199,10 +204,15 @@ pub fn HashMap(comptime K: type, comptime V: type, comptime hash: fn (key: K) u3
return hm.internalGet(key);
}
+ pub fn getValue(hm: *const Self, key: K) ?V {
+ return if (hm.get(key)) |kv| kv.value else null;
+ }
+
pub fn contains(hm: *const Self, key: K) bool {
return hm.get(key) != null;
}
+ /// Returns any kv pair that was removed.
pub fn remove(hm: *Self, key: K) ?KV {
if (hm.entries.len == 0) return null;
hm.incrementModificationCount();
@@ -236,6 +246,11 @@ pub fn HashMap(comptime K: type, comptime V: type, comptime hash: fn (key: K) u3
return null;
}
+ /// Calls remove(), asserts that a kv pair is removed, and discards it.
+ pub fn removeAssertDiscard(hm: *Self, key: K) void {
+ assert(hm.remove(key) != null);
+ }
+
pub fn iterator(hm: *const Self) Iterator {
return Iterator{
.hm = hm,
@@ -250,7 +265,7 @@ pub fn HashMap(comptime K: type, comptime V: type, comptime hash: fn (key: K) u3
try other.initCapacity(self.entries.len);
var it = self.iterator();
while (it.next()) |entry| {
- assert((try other.put(entry.key, entry.value)) == null);
+ try other.putNoClobber(entry.key, entry.value);
}
return other;
}
@@ -392,8 +407,8 @@ test "basic hash map usage" {
testing.expect((try map.put(2, 22)) == null);
testing.expect((try map.put(3, 33)) == null);
testing.expect((try map.put(4, 44)) == null);
- testing.expect((try map.put(5, 55)) == null);
+ try map.putNoClobber(5, 55);
testing.expect((try map.put(5, 66)).?.value == 55);
testing.expect((try map.put(5, 55)).?.value == 66);
@@ -416,12 +431,16 @@ test "basic hash map usage" {
testing.expect(map.contains(2));
testing.expect(map.get(2).?.value == 22);
+ testing.expect(map.getValue(2).? == 22);
const rmv1 = map.remove(2);
testing.expect(rmv1.?.key == 2);
testing.expect(rmv1.?.value == 22);
testing.expect(map.remove(2) == null);
testing.expect(map.get(2) == null);
+ testing.expect(map.getValue(2) == null);
+
+ map.removeAssertDiscard(3);
}
test "iterator hash map" {
@@ -431,9 +450,9 @@ test "iterator hash map" {
var reset_map = AutoHashMap(i32, i32).init(&direct_allocator.allocator);
defer reset_map.deinit();
- testing.expect((try reset_map.put(1, 11)) == null);
- testing.expect((try reset_map.put(2, 22)) == null);
- testing.expect((try reset_map.put(3, 33)) == null);
+ try reset_map.putNoClobber(1, 11);
+ try reset_map.putNoClobber(2, 22);
+ try reset_map.putNoClobber(3, 33);
var keys = [_]i32{
3,
diff --git a/std/process.zig b/std/process.zig
index 410575297e..b39c6e1196 100644
--- a/std/process.zig
+++ b/std/process.zig
@@ -388,7 +388,7 @@ pub fn args() ArgIterator {
}
/// Caller must call argsFree on result.
-pub fn argsAlloc(allocator: *mem.Allocator) ![]const []u8 {
+pub fn argsAlloc(allocator: *mem.Allocator) ![][]u8 {
if (builtin.os == .wasi) {
var count: usize = undefined;
var buf_size: usize = undefined;