From 24bd936a9fa671599f0756595e8abcbd2a7da96f Mon Sep 17 00:00:00 2001 From: Kaz Kyheku Date: Fri, 31 Jan 2020 06:25:01 -0800 Subject: c_str: don't allow symbols. On 2009-10-02, prior to TXR 014, I made a change to the c_str function to allow symbolic arguments, so that c_str(sym) could be used in the code base instead of c_str(symbol_name(sym)). This was a bad idea, and is allowing numerous functions that operate on strings to accept symbols also. That behavior is not documented and not consistently supported. Ironically, I completely forgot about this and have been consistently using symbol_name(sym) anyway. Let us remove this. Compat support is required because this will break user code that accidentally depends on this undocumented behavior. * lib.c (c_str): If the object is type SYM, only return the symbol_name if compatibility with 231 or older is requested, otherwise fall through to the error case. * match.c (dump_var): Fix one case where a symbol is passed directly to put_string. This fails one of the test cases. More testing is required to see if any other such cases occur. * txr.1: New entry in the compatibility notes. --- lib.c | 6 ++++-- match.c | 2 +- txr.1 | 10 ++++++++++ 3 files changed, 15 insertions(+), 3 deletions(-) diff --git a/lib.c b/lib.c index f54a71c4..ec17d81b 100644 --- a/lib.c +++ b/lib.c @@ -3660,11 +3660,13 @@ const wchar_t *c_str(val obj) return litptr(obj); case STR: return obj->st.str; - case SYM: - return c_str(symbol_name(obj)); case LSTR: lazy_str_force(obj); return c_str(obj->ls.prefix); + case SYM: + if (opt_compat && opt_compat <= 231) + return c_str(symbol_name(obj)); + /* fallthrough */ default: type_mismatch(lit("~s is not a string"), obj, nao); } diff --git a/match.c b/match.c index 7ff1b27f..18b3fd20 100644 --- a/match.c +++ b/match.c @@ -170,7 +170,7 @@ static void dump_var(val var, char *pfx1, size_t len1, pprint(value, ss); str = get_string_from_stream(ss); - put_string(var, std_output); + put_string(symbol_name(var), std_output); dump_byte_string(pfx1); dump_byte_string(pfx2); put_char(chr('='), std_output); diff --git a/txr.1 b/txr.1 index d58ff298..49fe9810 100644 --- a/txr.1 +++ b/txr.1 @@ -72394,6 +72394,16 @@ and respectively. If 227 or lower compatibility is selected, these functions become available under their old names in addition to their new names. +.IP 231 +Versions of \*(TX until 231 contained an undocumented feature: some +library functions which are documented as having parameters that must be of +string type were allowing the arguments to be symbols. For such symbolic +arguments, the name of the symbol obtained from +.code symbol-name +was implicitly taken as the required string value. This behavior was removed: +passing symbolic arguments to library function parameters documented as +strings will cause an exception to the thrown. If a compatibility value +of 231 or lower is specified, however, the tolerant behavior is restored. .IP 225 After \*(TX 225, the behavior of the .code do -- cgit v1.2.3