Commit 2682b41da5
Changed files (3)
lib
std
lib/std/heap/general_purpose_allocator.zig
@@ -341,9 +341,15 @@ pub fn GeneralPurposeAllocator(comptime config: Config) type {
const slot_index = @intCast(SlotIndex, used_bits_byte * 8 + bit_index);
const stack_trace = bucketStackTrace(bucket, size_class, slot_index, .alloc);
const addr = bucket.page + slot_index * size_class;
- log.err("memory address 0x{x} leaked: {s}", .{
- @ptrToInt(addr), stack_trace,
- });
+ if (builtin.zig_backend == .stage1) {
+ log.err("memory address 0x{x} leaked: {s}", .{
+ @ptrToInt(addr), stack_trace,
+ });
+ } else { // TODO
+ log.err("memory address 0x{x} leaked", .{
+ @ptrToInt(addr),
+ });
+ }
leaks = true;
}
if (bit_index == math.maxInt(u3))
@@ -372,9 +378,16 @@ pub fn GeneralPurposeAllocator(comptime config: Config) type {
var it = self.large_allocations.valueIterator();
while (it.next()) |large_alloc| {
if (config.retain_metadata and large_alloc.freed) continue;
- log.err("memory address 0x{x} leaked: {s}", .{
- @ptrToInt(large_alloc.bytes.ptr), large_alloc.getStackTrace(.alloc),
- });
+ const stack_trace = large_alloc.getStackTrace(.alloc);
+ if (builtin.zig_backend == .stage1) {
+ log.err("memory address 0x{x} leaked: {s}", .{
+ @ptrToInt(large_alloc.bytes.ptr), stack_trace,
+ });
+ } else { // TODO
+ log.err("memory address 0x{x} leaked", .{
+ @ptrToInt(large_alloc.bytes.ptr),
+ });
+ }
leaks = true;
}
return leaks;
lib/std/special/test_runner.zig
@@ -46,9 +46,10 @@ pub fn main() void {
var leaks: usize = 0;
for (test_fn_list) |test_fn, i| {
- if (builtin.zig_backend != .stage2_llvm) std.testing.allocator_instance = .{};
+ const gpa_works = builtin.zig_backend == .stage1 or builtin.os.tag != .macos;
+ if (gpa_works) std.testing.allocator_instance = .{};
defer {
- if (builtin.zig_backend != .stage2_llvm and std.testing.allocator_instance.deinit()) {
+ if (gpa_works and std.testing.allocator_instance.deinit()) {
leaks += 1;
}
}
lib/std/hash_map.zig
@@ -738,7 +738,7 @@ pub fn HashMapUnmanaged(
value: V,
};
- const Header = packed struct {
+ const Header = struct {
values: [*]V,
keys: [*]K,
capacity: Size,
@@ -932,7 +932,7 @@ pub fn HashMapUnmanaged(
}
fn header(self: *const Self) *Header {
- return @ptrCast(*Header, @ptrCast([*]Header, self.metadata.?) - 1);
+ return @ptrCast(*Header, @ptrCast([*]Header, @alignCast(@alignOf(Header), self.metadata.?)) - 1);
}
fn keys(self: *const Self) [*]K {