Skip to content

Commit

Permalink
Allocator/Random: document that comparing ptr may result in illegal…
Browse files Browse the repository at this point in the history
… behavior

See #21756 and #17704
  • Loading branch information
squeek502 authored and alexrp committed Feb 3, 2025
1 parent 1910b1f commit 16200c8
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
3 changes: 3 additions & 0 deletions lib/std/Random.zig
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ pub const RomuTrio = @import("Random/RomuTrio.zig");
pub const SplitMix64 = @import("Random/SplitMix64.zig");
pub const ziggurat = @import("Random/ziggurat.zig");

/// Any comparison of this field may result in illegal behavior, since it may be set to
/// `undefined` in cases where the random implementation does not have any associated
/// state.
ptr: *anyopaque,
fillFn: *const fn (ptr: *anyopaque, buf: []u8) void,

Expand Down
5 changes: 4 additions & 1 deletion lib/std/mem/Allocator.zig
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@ const builtin = @import("builtin");
pub const Error = error{OutOfMemory};
pub const Log2Align = math.Log2Int(usize);

// The type erased pointer to the allocator implementation
/// The type erased pointer to the allocator implementation.
/// Any comparison of this field may result in illegal behavior, since it may be set to
/// `undefined` in cases where the allocator implementation does not have any associated
/// state.
ptr: *anyopaque,
vtable: *const VTable,

Expand Down

0 comments on commit 16200c8

Please sign in to comment.