[PATCH 1/8] [gdb/testsuite] Factor out proc finally

Tom de Vries tdevries@suse.de
Fri Nov 19 20:53:16 GMT 2021


On 11/19/21 8:33 PM, Pedro Alves wrote:
> On 2021-10-25 11:29, Tom de Vries via Gdb-patches wrote:
>> There's a common pattern in the tcl procs to run cleanup code, emulating
>> the 'finally' functionality:
>> ...
>>     set code [catch {
>>       # Try.
>>       ...
>>     } result]
>>
>>     # Finally.
>>     ...
>>
>>     # Return as appropriate.
>>     if { $code == 1 } {
>>         global errorInfo errorCode
>>         return -code error -errorinfo $errorInfo -errorcode $errorCode $result
>>
>>     } elseif { $code > 1 } {
>>         return -code $code $result
>>     }
>>
>>     <use> $result
>> ...
>>
>> Factor this out into a new proc 'finally', such that we can simply write:
>> ...
>>     finally {
>>         # Try.
>>         ...
>>     } {
>>         # Finally.
>>     	...
>>     }
> 
> 
> The position of the "finally" seems super surprising to me.  I'd expect something like one of
> the below:
> 
> try {
>   # Try.
> } finally {
>   # Finally.
> }
> 
> try {
>   # Try.
> } {
>   # Finally.
> }
> 
> try_finally {
>   # Try.
> } {
>   # Finally.
> }
> 
> 
> Can we just use standard try/finally, though?
> 
>   https://wiki.tcl-lang.org/page/try
> 
> It looks exactly like the first example I give above.
> 
> It's available starting with TCL 8.6.  We could add some simple fallback implementation
> similar to yours that only supports try/except if necessary, I think.
> 

Well, the problem is that we have test-cases that rely on non-standard
'finally' behaviour.   I've tried to explain the difference to the
standard 'finally' implementation in the submission, see the notes.

So yes, we could use the tcl finally, if we fix those test-cases first.

Thanks,
- Tom


More information about the Gdb-patches mailing list