From b75f188c4991ac07ce7d6db8caaccda8ed4e1542 Mon Sep 17 00:00:00 2001 From: Kaz Kylheku Date: Sun, 29 Jan 2017 14:17:18 -0800 Subject: bugfix: read print consistency of shadowed symbols. Suppose that a program-defined package is current, has usr as its :fallback, and has a :local symbol list. Then if 'usr:list is printed, it must print with the usr: package symbol because it is not visible. It is printing without the prefix. * lib.c (symbol_present): Function renamed to symbol_visible, which is much more descriptive of what its return value means. The bug in this function is that it does not stop searching when, in its search path, it encounters a symbol which has the same name as sym, but which isn't sym. But such a symbol makes sym invisible. This is now fixed. --- lib.c | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) (limited to 'lib.c') diff --git a/lib.c b/lib.c index 2c4bb209..69af823b 100644 --- a/lib.c +++ b/lib.c @@ -5021,23 +5021,30 @@ val unuse_package(val unuse_list, val package_in) return unuse_package_list; } -static val symbol_present(val package, val sym) +static val symbol_visible(val package, val sym) { + val name = symbol_name(sym); type_check (package, PKG); if (sym->s.package == package) return t; - if (gethash(package->pk.symhash, symbol_name(sym)) == sym) - return t; + { + val cell = gethash_e(package->pk.symhash, name); + + if (cell) + return eq(car(cell), sym); + } { val fallback = get_hash_userdata(package->pk.symhash); for (; fallback; fallback = cdr(fallback)) { val fb_pkg = car(fallback); - if (gethash(fb_pkg->pk.symhash, symbol_name(sym)) == sym) - return t; + val cell = gethash_e(fb_pkg->pk.symhash, name); + + if (cell) + return eq(car(cell), sym); } } @@ -9659,7 +9666,7 @@ static int unquote_star_check(val obj, val pretty) return 0; if (car(obj->s.name) != chr('*')) return 0; - return pretty || symbol_present(cur_package, obj); + return pretty || symbol_visible(cur_package, obj); } val obj_print_impl(val obj, val out, val pretty, struct strm_ctx *ctx) @@ -9914,7 +9921,7 @@ dot: put_string(lit("#:"), out); } else if (obj->s.package == keyword_package) { put_char(chr(':'), out); - } else if (!symbol_present(cur_package, obj)) { + } else if (!symbol_visible(cur_package, obj)) { put_string(obj->s.package->pk.name, out); put_char(chr(':'), out); } -- cgit v1.2.3