Skip to content

std.heap.DebugAllocator with .safety = true broken on freestanding targets #25978

Description

@Spooky309

Zig Version

0.16.0-dev.1334+06d08daba

Steps to Reproduce and Observed Behavior

Use this config:

const GPA = std.heap.DebugAllocator(.{
    .never_unmap = true,
    .backing_allocator_zeroes = false,
});

with root.os:

fn nullAllocator() std.mem.Allocator {
    return .{ .ptr = undefined, .vtable = undefined };
}
pub const os = struct {
    pub const heap = struct {
        // NEVER USE THIS! This is just to stop it from defaulting fields to POSIX page allocator
        //  DebugAllocator should have its .backing_allocator explicitly set to something else.
        pub const page_allocator = nullAllocator();
    };
};

Yields:

std\posix.zig:3270:18: error: struct 'posix.system__struct_2784' has no member named 'isatty'
    return system.isatty(handle) != 0;
           ~~~~~~^~~~~~~
std\posix.zig:49:13: note: struct declared here
    else => struct {
            ^~~~~~
referenced by:
    isTty: std\fs\File.zig:130:24
    supportsAnsiEscapeCodes: std\fs\File.zig:242:19
    getOrEnableAnsiEscapeSupport: std\fs\File.zig:220:40
    detect: std\Io\tty.zig:58:46
    detectConfig: std\Io\tty.zig:10:19
    free: std\heap\debug_allocator.zig:938:67
    allocator: std\heap\debug_allocator.zig:344:22

Setting .safety to false makes it compile, it seems to me that the only issue are these calls to detectConfig to find out if we can use ANSI colour codes or not.

Expected Behavior

Somewhere in that call stack has a root.os escape hatch, so I can define my own supportsAnsiEscapeCodes function, or somewhere higher up, I'm not sure.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugObserved behavior contradicts documented or intended behavior

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions