Skip to content

Commit

Permalink
FEAT: handle gracefully bind with recursive data
Browse files Browse the repository at this point in the history
  • Loading branch information
Oldes committed Apr 17, 2024
1 parent ddad4bb commit f95e6f2
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
14 changes: 11 additions & 3 deletions src/core/c-frame.c
Original file line number Diff line number Diff line change
Expand Up @@ -814,8 +814,7 @@
REBINT *binds = WORDS_HEAD(Bind_Table); // GC safe to do here
REBCNT n;
REBFLG selfish = !IS_SELFLESS(frame);

CHECK_STACK(&n);
REBVAL *val;

for (; NOT_END(value); value++) {
if (ANY_WORD(value)) {
Expand All @@ -840,11 +839,20 @@
}
}
}
else if ((ANY_BLOCK(value) || IS_MAP(value)) && (mode & BIND_DEEP))
else if ((ANY_BLOCK(value) || IS_MAP(value)) && (mode & BIND_DEEP)) {
// Recursion check: (variation of: Find_Same_Block(MOLD_LOOP, value))
for (val = BLK_HEAD(MOLD_LOOP); NOT_END(val); val++) {
if (VAL_SERIES(val) == VAL_SERIES(value)) return;
}
val = Append_Value(MOLD_LOOP);
Set_Block(val, VAL_SERIES(value));
Bind_Block_Words(frame, VAL_BLK_DATA(value), mode);
Remove_Last(MOLD_LOOP);
}
else if ((IS_FUNCTION(value) || IS_CLOSURE(value)) && (mode & BIND_FUNC))
Bind_Block_Words(frame, BLK_HEAD(VAL_FUNC_BODY(value)), mode);
}

}


Expand Down
8 changes: 7 additions & 1 deletion src/tests/units/crash-test.r3
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,13 @@ foreach [n s] system/schemes [
obj: make object! [x: 10]
blk: copy [x]
append/only blk blk
--assert all [error? e: try [bind block obj] e/id = 'stack-overflow]
--assert all [
block? try [bind blk obj]
same? blk/1 blk/2/1
10 == get blk/1
10 == get blk/2/1
10 == get blk/2/2/1
]

===end-group===

Expand Down

0 comments on commit f95e6f2

Please sign in to comment.