mirror of
https://github.com/roc-lang/roc.git
synced 2025-08-03 19:58:18 +00:00
better debug info if inc on invalid pointer
This commit is contained in:
parent
c19ad4ecfd
commit
dd8739b847
1 changed files with 11 additions and 5 deletions
|
@ -152,22 +152,28 @@ const RC_TYPE = Refcount.normal;
|
|||
|
||||
pub fn increfRcPtrC(ptr_to_refcount: *isize, amount: isize) callconv(.C) void {
|
||||
if (RC_TYPE == Refcount.none) return;
|
||||
|
||||
if (DEBUG_INCDEC and builtin.target.cpu.arch != .wasm32) {
|
||||
std.debug.print("| increment {*}: ", .{ptr_to_refcount});
|
||||
}
|
||||
|
||||
// Ensure that the refcount is not whole program lifetime.
|
||||
if (ptr_to_refcount.* != REFCOUNT_MAX_ISIZE) {
|
||||
// Note: we assume that a refcount will never overflow.
|
||||
// As such, we do not need to cap incrementing.
|
||||
switch (RC_TYPE) {
|
||||
Refcount.normal => {
|
||||
const old = @bitCast(usize, ptr_to_refcount.*);
|
||||
ptr_to_refcount.* += amount;
|
||||
const new = @bitCast(usize, ptr_to_refcount.*);
|
||||
|
||||
if (DEBUG_INCDEC and builtin.target.cpu.arch != .wasm32) {
|
||||
const old = @bitCast(usize, ptr_to_refcount.*);
|
||||
const new = old + @intCast(usize, amount);
|
||||
|
||||
const oldH = old - REFCOUNT_ONE + 1;
|
||||
const newH = new - REFCOUNT_ONE + 1;
|
||||
|
||||
std.debug.print("| increment {*}: {} + {} = {}!\n", .{ ptr_to_refcount, oldH, amount, newH });
|
||||
std.debug.print("{} + {} = {}!\n", .{ oldH, amount, newH });
|
||||
}
|
||||
|
||||
ptr_to_refcount.* += amount;
|
||||
},
|
||||
Refcount.atomic => {
|
||||
_ = @atomicRmw(isize, ptr_to_refcount, std.builtin.AtomicRmwOp.Add, amount, Monotonic);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue