modern Tcl and correct quoting
Joshua Root
jmr at macports.org
Thu Jun 13 03:43:07 PDT 2013
On 2013-6-13 14:07 , Poor Yorick wrote:
> Here's another example from the patch. The original version looks like this:
>
> if {[catch {eval curl fetch $verboseflag {$source} {$tarpath}} error]} {
> ...
> }
>
> Taking a look at just the [eval] part:
>
> eval curl fetch $verboseflag {$source} {$tarpath}
>
> The curly brackets around {$source} and {$tarpath} are there to escape
> substitution as Tcl prepares to invoke [eval], and this is not necessarily
> incorrect, but there are some caveats. $verboseflag is resolved prior to the
> invocation of [eval], but $source and $tarpath are passed as literal strings.
> If $verboseflag is "yes", [eval] will get exactly five values as arguments:
>
> curl
>
> fetch
>
> yes
>
> $source
>
> $tarpath
>
> It will then concatenate these arguments into a script which it will then pass to the interpreter:
>
> curl fetch yes $source $tarpath
>
> $source and $tarpath have not been resolved yet. As it prepares to execute
> [curl], the the interpreter will resolve them, and [curl] will receive exactly
> 4 arguments.
$verboseflag is actually either empty or "-v". The intent of the
existing code is that curl will get only 3 arguments when $verboseflag
is empty. If it weren't for this, the eval could be omitted entirely, right?
So actually using list will change the behaviour by passing the empty
string as an arg.
- Josh
More information about the macports-dev
mailing list