From e933786bcdc0be5b01a64a70b3997013220443c0 Mon Sep 17 00:00:00 2001 From: Kaz Kylheku Date: Fri, 21 Oct 2016 05:47:35 -0700 Subject: Fix circular printing across print methods. * lib.c (obj_print): When invoked recursively in circular printing mode, collect the nodes of the new object into a separate hash table. Then merge these entries into to the previous hash table. If the newly visited object visits objects we have already seen, suppress those entries. --- lib.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/lib.c b/lib.c index f81b791a..0028f543 100644 --- a/lib.c +++ b/lib.c @@ -9436,7 +9436,17 @@ val obj_print(val obj, val out, val pretty) uw_simple_catch_begin; if (ctx) { + val cell, iter; + val prev_hash = ctx->obj_hash; + ctx->obj_hash = make_hash(nil, nil, nil); populate_obj_hash(obj, ctx); + for (iter = hash_begin(ctx->obj_hash); (cell = hash_next(iter));) { + val new_p; + val pcell = gethash_c(prev_hash, car(cell), mkcloc(new_p)); + if (new_p) + rplacd(pcell, cdr(cell)); + } + ctx->obj_hash = prev_hash; } else { if (cdr(lookup_var(nil, print_circle_s))) { ctx = &ctx_struct; -- cgit v1.2.3