diff options
author | Kaz Kyheku <kaz@kylheku.com> | 2020-01-31 06:25:01 -0800 |
---|---|---|
committer | Kaz Kylheku <kaz@kylheku.com> | 2020-01-31 06:25:01 -0800 |
commit | 24bd936a9fa671599f0756595e8abcbd2a7da96f (patch) | |
tree | f3e0de12ad825a9ecc50ae9bda3bd75b707cef2a /lib.c | |
parent | b0ebc5943d7de0e76e3e908fb2d543f34396b69f (diff) | |
download | txr-24bd936a9fa671599f0756595e8abcbd2a7da96f.tar.gz txr-24bd936a9fa671599f0756595e8abcbd2a7da96f.tar.bz2 txr-24bd936a9fa671599f0756595e8abcbd2a7da96f.zip |
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.
Diffstat (limited to 'lib.c')
-rw-r--r-- | lib.c | 6 |
1 files changed, 4 insertions, 2 deletions
@@ -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); } |