public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
From: Tom Tromey <tromey@adacore.com>
To: gdb-patches@sourceware.org
Cc: Tom Tromey <tromey@adacore.com>
Subject: [PATCH v2 2/3] Rewrite version_compare and rust_at_least
Date: Tue, 14 Mar 2023 08:02:50 -0600	[thread overview]
Message-ID: <20230314140251.1081243-3-tromey@adacore.com> (raw)
In-Reply-To: <20230314140251.1081243-1-tromey@adacore.com>

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.39.1


  parent reply	other threads:[~2023-03-14 14:03 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-03-14 14:02 [PATCH 0/3] Version comparisons in the test suite Tom Tromey
2023-03-14 14:02 ` [PATCH v2 1/3] Introduce rust_at_least helper proc Tom Tromey
2023-03-14 14:02 ` Tom Tromey [this message]
2023-03-14 14:02 ` [PATCH v2 3/3] Remove version_at_least Tom Tromey
2023-03-29 16:09 ` [PATCH 0/3] Version comparisons in the test suite Tom Tromey

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230314140251.1081243-3-tromey@adacore.com \
    --to=tromey@adacore.com \
    --cc=gdb-patches@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).