diff options
author | jan.nijtmans <nijtmans@users.sourceforge.net> | 2016-02-22 11:42:09 (GMT) |
---|---|---|
committer | jan.nijtmans <nijtmans@users.sourceforge.net> | 2016-02-22 11:42:09 (GMT) |
commit | 58678c630d56e744440b1f808e9fa57aba09fed9 (patch) | |
tree | fdd7aef9911da2e29cc5b1c96e0ada1c8b02c8b1 | |
parent | f7ea5b6cc57fafcbcb3377e83fdbc4d999d123d4 (diff) | |
parent | 3a234ba343433d741a7a0c873702da6cb7987ae5 (diff) | |
download | tcl-58678c630d56e744440b1f808e9fa57aba09fed9.zip tcl-58678c630d56e744440b1f808e9fa57aba09fed9.tar.gz tcl-58678c630d56e744440b1f808e9fa57aba09fed9.tar.bz2 |
Fix [9b47029467631832]: testing existence of env(some_thing) destroys traces. With test-case demonstrating the problem.
-rw-r--r-- | generic/tclEnv.c | 6 | ||||
-rw-r--r-- | tests/env.test | 13 |
2 files changed, 16 insertions, 3 deletions
diff --git a/generic/tclEnv.c b/generic/tclEnv.c index 2cb240d..66ddb57 100644 --- a/generic/tclEnv.c +++ b/generic/tclEnv.c @@ -551,7 +551,8 @@ TclGetEnv( * array. * * Results: - * Always returns NULL to indicate success. + * Returns NULL to indicate success, or an error-message if the array + * element being handled doesn't exist. * * Side effects: * Environment variable changes get propagated. If the whole "env" array @@ -609,8 +610,7 @@ EnvTraceProc( const char *value = TclGetEnv(name2, &valueString); if (value == NULL) { - Tcl_UnsetVar2(interp, name1, name2, 0); - return NULL; + return (char *) "no such variable"; } Tcl_SetVar2(interp, name1, name2, value, 0); Tcl_DStringFree(&valueString); diff --git a/tests/env.test b/tests/env.test index 83d99e0..f9df4d6 100644 --- a/tests/env.test +++ b/tests/env.test @@ -314,6 +314,19 @@ test env-7.2 {[219226]: links to env elements should not be removed by read} { }} } ok +test env-7.3 {[9b4702]: testing existence of env(some_thing) should not destroy trace} { + apply {{} { + catch {unset ::env(test7_3)} + proc foo args { + set ::env(test7_3) ok + } + trace add variable ::env(not_yet_existent) write foo + info exists ::env(not_yet_existent) + set ::env(not_yet_existent) "Now I'm here"; + info exists ::env(test7_3) + }} +} 1 + # Restore the environment variables at the end of the test. foreach name [array names env] { |