public inbox for gdb-cvs@sourceware.org
help / color / mirror / Atom feed
* [binutils-gdb] Rewrite version_compare and rust_at_least
@ 2023-03-29 16:14 Tom Tromey
0 siblings, 0 replies; only message in thread
From: Tom Tromey @ 2023-03-29 16:14 UTC (permalink / raw)
To: gdb-cvs
https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=1fa14231efd56ee77a9d8f66f741e285c0040839
commit 1fa14231efd56ee77a9d8f66f741e285c0040839
Author: Tom Tromey <tromey@adacore.com>
Date: Tue Mar 14 07:51:45 2023 -0600
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.
Diff:
---
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] .]]
}
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2023-03-29 16:14 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-03-29 16:14 [binutils-gdb] Rewrite version_compare and rust_at_least Tom Tromey
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).