From 2e6af871326f4eb6a2674034c5a02afca2877f26 Mon Sep 17 00:00:00 2001 From: Kaz Kylheku Date: Mon, 25 Jan 2021 20:21:07 -0800 Subject: lazy-sub-str: bugfix: invalid substructure sharing. This addresses a bug manifesting itself as a regression in the behavior of @(freeform), which was reported by Frank Schwidom. The sub_str operation calls lazy_subs_str for a lazy string. But lazy_sub_str again relies on sub_str for extracting part of the lazy string prefix. But sub_str can potentially return the whole object rather than a copy of a substring of it. In this case, lazy_sub_str produces a new lazy string object which shares the prefix string object with the original lazy string. This is incorrect because the lazy string data type destructively manipulates the prefix. It means that operations one one lazy string are mucking with the prefix of another lazy string. * lib.c (lazy_sub_str): When creating the new lazy string object, make a copy of the prefix string pulled from the original. We do the carefully: the copy of the prefix is made before the make_obj call which allocates the new lazy string, otherwise we create a wrong-way assignment from the perspective of generational GC. * tests/006/freeform-4.txr: New test case, from Frank. * tests/006/freeform-4.expected: Expected output of test case. --- tests/006/freeform-4.expected | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 tests/006/freeform-4.expected (limited to 'tests/006/freeform-4.expected') diff --git a/tests/006/freeform-4.expected b/tests/006/freeform-4.expected new file mode 100644 index 00000000..62857f54 --- /dev/null +++ b/tests/006/freeform-4.expected @@ -0,0 +1,26 @@ +### +FF: +1 +2 + /FF + +X, Y : 1 2 + +### +FF: +3 +4 + /FF + +X, Y : 3 4 + +X[0]="1" +X[1]="3" +Y[0]="2" +Y[1]="4" +FF[0]="1\ +2\ +" +FF[1]="3\ +4\ +" -- cgit v1.2.3