Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
* [pushed] [gdb/testsuite] Use try trap in lib/gdb.exp
@ 2026-09-24 16:56 Tom de Vries
  0 siblings, 0 replies; only message in thread
From: Tom de Vries @ 2026-09-24 16:56 UTC (permalink / raw)
  To: gdb-patches

The try ... finally construct has two types of handlers [1]:
- on code variableList script
- trap pattern variableList script

Use a trap handler to simplify file_rename_atomic and tentative_rename.

In the process, fix the return value of file_rename_atomic.  Currently it
returns the return value of catch, so either 0 (TCL_OK) or 1 (TCL_ERROR).

Change this to more typical Tcl return values:
- use 1 for successful rename, and
- use 0 for ignored failure to rename.

[1] https://www.tcl-lang.org/man/tcl8.6/TclCmd/try.htm
---
 gdb/testsuite/lib/gdb.exp | 30 ++++++++++--------------------
 1 file changed, 10 insertions(+), 20 deletions(-)

diff --git a/gdb/testsuite/lib/gdb.exp b/gdb/testsuite/lib/gdb.exp
index 8db13cc9f98..0c697b0b976 100644
--- a/gdb/testsuite/lib/gdb.exp
+++ b/gdb/testsuite/lib/gdb.exp
@@ -6436,18 +6436,14 @@ proc quote_for_host { args } {
 # atomic commit, and it doesn't matter which one wins, as all the
 # copies are identical.
 proc file_rename_atomic {src dst} {
-    set rc [catch { file rename -force -- $src $dst } err opts]
-
-    if {$rc} {
-	set code [dict get $opts -errorcode]
-	if {[llength $code] >= 2 && [lindex $code 1] eq "EBUSY"} {
-	    # Normal parallel race loss.
-	} else {
-	    error $err $opts
-	}
+    try {
+	file rename -force -- $src $dst
+    } trap "POSIX EBUSY" {} {
+	# Normal parallel race loss.
+	return 0
     }
 
-    return $rc
+    return 1
 }
 
 # Set while linker_supports_manifest_embed is running its test link,
@@ -8685,17 +8681,11 @@ proc standard_temp_file {basename} {
 proc tentative_rename { a b } {
     try {
 	file rename -- $a $b
-    } on error {result opts} {
-	set errorcode [dict get $opts -errorcode]
-	if { [lindex $errorcode 0] == "POSIX" \
-		 && [lindex $errorcode 1] == "EEXIST" } {
-	    file delete $a
-	    return 0
-	}
-
-	# Rethrow.
-	return -options $opts $result
+    } trap "POSIX EEXIST" {} {
+	file delete $a
+	return 0
     }
+
     return 1
 }
 

base-commit: f73f2dfbb90d37443d9562f5fccf5e210920ed3a
-- 
2.51.0


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2026-09-24 16:57 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-09-24 16:56 [pushed] [gdb/testsuite] Use try trap in lib/gdb.exp Tom de Vries

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox