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
const std = @import("std"); | |
const builtin = @import("builtin"); | |
const Builder = @import("std").build.Builder; | |
pub fn build(b: *Builder) void { | |
const target = b.standardTargetOptions(.{}); | |
const exe = b.addExecutable("huh", "main.zig"); | |
exe.setTarget(target); | |
exe.linkSystemLibrary("c"); | |
exe.install(); | |
} |
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
const std = @import("std"); | |
const CAllocator = std.heap.c_allocator; | |
const out = std.io.getStdOut().outStream(); | |
const LogAllocator = &std.heap.loggingAllocator(CAllocator, out); | |
pub fn main() !void { | |
var allocator = LogAllocator.allocator; | |
var new_bytes: []u8 = allocator.alloc(u8, 1) catch unreachable; | |
std.log.info("len {}", .{new_bytes.len}); | |
} |
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
turnip /tmp/zig-bug$ zig version | |
0.7.1+e93cb2254 | |
turnip /tmp/zig-bug$ zig build | |
turnip /tmp/zig-bug$ ./zig-cache/bin/huh | |
Segmentation fault at address 0x0 | |
/opt/zig/0.7.1/lib/zig/std/heap/logging_allocator.zig:40:49: 0x20386d in std.heap.logging_allocator.LoggingAllocator(std.io.writer.Writer(std.fs.file.File,std.os.WriteError,std.fs.file.File.write)).alloc (huh) | |
const result = self.parent_allocator.allocFn(self.parent_allocator, len, ptr_align, len_align, ra); | |
^ | |
/opt/zig/0.7.1/lib/zig/std/mem/Allocator.zig:294:40: 0x2063d1 in std.mem.Allocator.allocAdvancedWithRetAddr (huh) | |
const byte_slice = try self.allocFn(self, byte_count, a, len_align, return_address); | |
^ | |
/opt/zig/0.7.1/lib/zig/std/mem/Allocator.zig:186:41: 0x2047da in std.mem.Allocator.alloc (huh) | |
return self.allocAdvancedWithRetAddr(T, null, n, .exact, @returnAddress()); | |
^ | |
/tmp/zig-bug/main.zig:9:40: 0x204737 in main (huh) | |
var new_bytes: []u8 = allocator.alloc(u8, 1) catch unreachable; | |
^ | |
/opt/zig/0.7.1/lib/zig/std/start.zig:344:37: 0x204a85 in std.start.main (huh) | |
const result = root.main() catch |err| { | |
^ | |
zsh: abort (core dumped) ./zig-cache/bin/huh |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment