From 1fa14231efd56ee77a9d8f66f741e285c0040839 Mon Sep 17 00:00:00 2001 From: Tom Tromey Date: Tue, 14 Mar 2023 07:51:45 -0600 Subject: [PATCH] Rewrite version_compare and rust_at_least This rewrites version_compare to allow the input lists to have different lengths, then rewrites rust_at_least to use version_compare. --- gdb/testsuite/lib/gdb-utils.exp | 51 ++++++++++++------------------ gdb/testsuite/lib/rust-support.exp | 22 ++----------- 2 files changed, 23 insertions(+), 50 deletions(-) diff --git a/gdb/testsuite/lib/gdb-utils.exp b/gdb/testsuite/lib/gdb-utils.exp index fb5c953a6c4..a010e14fc04 100644 --- a/gdb/testsuite/lib/gdb-utils.exp +++ b/gdb/testsuite/lib/gdb-utils.exp @@ -101,49 +101,40 @@ proc gdb_get_bp_addr { num } { return "" } -# Compare the version numbers in L1 to those in L2 using OP, and return -# 1 if the comparison is true. +# Compare the version numbers in L1 to those in L2 using OP, and +# return 1 if the comparison is true. OP can be "<", "<=", or "==". +# It is ok if the lengths of the lists differ. proc version_compare { l1 op l2 } { - set len [llength $l1] - if { $len != [llength $l2] } { - error "l2 not the same length as l1" - } - switch -exact $op { "==" - + "<=" - "<" {} - "<=" { return [expr [version_compare $l1 < $l2] \ - || [version_compare $l1 == $l2]]} default { error "unsupported op: $op" } } # Handle ops < and ==. - set idx 0 - foreach v1 $l1 { - set v2 [lindex $l2 $idx] - incr idx - set last [expr $len == $idx] - - set cmp [expr $v1 $op $v2] - if { $op == "==" } { - if { $cmp } { - continue - } else { - return 0 - } - } else { - # $op == "<". - if { $cmp } { + foreach v1 $l1 v2 $l2 { + if {$v1 == ""} { + # This is: "1.2 OP 1.2.1". + if {$op != "=="} { return 1 - } else { - if { !$last && $v1 == $v2 } { - continue - } - return 0 } + return 0 } + if {$v2 == ""} { + # This is: "1.2.1 OP 1.2". + return 0 + } + if {$v1 == $v2} { + continue + } + return [expr $v1 $op $v2] } + if {$op == "<"} { + # They are equal. + return 0 + } return 1 } diff --git a/gdb/testsuite/lib/rust-support.exp b/gdb/testsuite/lib/rust-support.exp index 381871e22f4..e9a3c5c0543 100644 --- a/gdb/testsuite/lib/rust-support.exp +++ b/gdb/testsuite/lib/rust-support.exp @@ -116,24 +116,6 @@ gdb_caching_proc rust_compiler_version {} { # A helper that checks that the rust compiler is at least the given # version. This is handy for use with 'require'. proc rust_at_least {atleast} { - foreach n1 [split [rust_compiler_version] .] n2 [split $atleast .] { - if {$n1 == ""} { - # Have 1.2, wanted 1.2.1. - return 0 - } - if {$n2 == ""} { - # Have 1.2.1, wanted 1.2. - return 1 - } - if {$n1 > $n2} { - # Have 1.3, wanted 1.2. - return 1 - } - if {$n1 < $n2} { - # Have 1.1, wanted 1.2. - return 0 - } - } - # Completely equal. - return 1 + return [version_compare [split $atleast .] \ + <= [split [rust_compiler_version] .]] } -- 2.30.2