diff options
author | John Viega <viega@users.noreply.github.com> | 2023-11-26 00:32:32 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-11-26 06:32:32 +0100 |
commit | 5b2fcabff5dc28b3df49960c052feeda98dbb7d0 (patch) | |
tree | f42b0ae0e144c7173c7947cdcc6152d32f4a3325 /tests | |
parent | 26f2ea149c50ebfe882560c83d1d7cf7bb9d10c4 (diff) | |
download | Nim-5b2fcabff5dc28b3df49960c052feeda98dbb7d0.tar.gz |
fix: std/marshal unmarshaling of ref objects (#22983)
Fixes #16496  Test case added. Note that this test (t9754) does pass locally, but there are tons of failures by default on OS X arm64, mostly around the bohem GC, so it's pretty spammy, and could easily have missed something. If there are better instructions please do let me know. --------- Co-authored-by: John Viega <viega@Johns-MacBook-Pro.local> Co-authored-by: John Viega <viega@Johns-MBP.localdomain> Co-authored-by: ringabout <43030857+ringabout@users.noreply.github.com>
Diffstat (limited to 'tests')
-rw-r--r-- | tests/stdlib/tmarshal.nim | 42 |
1 files changed, 41 insertions, 1 deletions
diff --git a/tests/stdlib/tmarshal.nim b/tests/stdlib/tmarshal.nim index f972332a2..32991ccc9 100644 --- a/tests/stdlib/tmarshal.nim +++ b/tests/stdlib/tmarshal.nim @@ -3,7 +3,7 @@ discard """ """ import std/marshal -import std/[assertions, objectdollar] +import std/[assertions, objectdollar, streams] # TODO: add static tests @@ -166,6 +166,46 @@ block: let a: ref A = new(B) doAssert $$a[] == "{}" # not "{f: 0}" +# bug #16496 +block: + type + A = ref object + data: seq[int] + + B = ref object + x: A + let o = A(data: @[1, 2, 3, 4]) + let s1 = @[B(x: o), B(x: o)] + let m = $$ s1 + let s2 = to[seq[B]](m) + doAssert s2[0].x.data == s2[1].x.data + doAssert s1[0].x.data == s2[1].x.data + + +block: + type + Obj = ref object + i: int + b: bool + + let + strm = newStringStream() + + var + o = Obj(i: 1, b: false) + t1 = @[o, o] + t2: seq[Obj] + + doAssert t1[0] == t1[1] + + strm.store(t1) + strm.setPosition(0) + strm.load(t2) + strm.close() + + doAssert t2[0] == t2[1] + + template checkMarshal(data: typed) = let orig = data let m = $$orig |