From mboxrd@z Thu Jan  1 00:00:00 1970
Return-Path: <gentoo-commits+bounces-975132-garchives=archives.gentoo.org@lists.gentoo.org>
Received: from lists.gentoo.org (pigeon.gentoo.org [208.92.234.80])
	(using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits))
	(No client certificate requested)
	by finch.gentoo.org (Postfix) with ESMTPS id 816731396D0
	for <garchives@archives.gentoo.org>; Tue, 26 Sep 2017 18:46:37 +0000 (UTC)
Received: from pigeon.gentoo.org (localhost [127.0.0.1])
	by pigeon.gentoo.org (Postfix) with SMTP id CB560E0D5E;
	Tue, 26 Sep 2017 18:46:36 +0000 (UTC)
Received: from smtp.gentoo.org (smtp.gentoo.org [140.211.166.183])
	(using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits))
	(No client certificate requested)
	by pigeon.gentoo.org (Postfix) with ESMTPS id 95E3EE0D5E
	for <gentoo-commits@lists.gentoo.org>; Tue, 26 Sep 2017 18:46:36 +0000 (UTC)
Received: from oystercatcher.gentoo.org (oystercatcher.gentoo.org [148.251.78.52])
	(using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits))
	(No client certificate requested)
	by smtp.gentoo.org (Postfix) with ESMTPS id 5999F33BE25
	for <gentoo-commits@lists.gentoo.org>; Tue, 26 Sep 2017 18:46:35 +0000 (UTC)
Received: from localhost.localdomain (localhost [IPv6:::1])
	by oystercatcher.gentoo.org (Postfix) with ESMTP id D39FA9092
	for <gentoo-commits@lists.gentoo.org>; Tue, 26 Sep 2017 18:46:33 +0000 (UTC)
From: "Ulrich Müller" <ulm@gentoo.org>
To: gentoo-commits@lists.gentoo.org
Content-Transfer-Encoding: 8bit
Content-type: text/plain; charset=UTF-8
Reply-To: gentoo-dev@lists.gentoo.org, "Ulrich Müller" <ulm@gentoo.org>
Message-ID: <1506451587.7175c90c8c4bc1332899dffa6b5fa7a7b30ad2a4.ulm@gentoo>
Subject: [gentoo-commits] repo/gentoo:master commit in: eclass/tests/, eclass/
X-VCS-Repository: repo/gentoo
X-VCS-Files: eclass/eapi7-ver.eclass eclass/tests/eapi7-ver.sh
X-VCS-Directories: eclass/tests/ eclass/
X-VCS-Committer: ulm
X-VCS-Committer-Name: Ulrich Müller
X-VCS-Revision: 7175c90c8c4bc1332899dffa6b5fa7a7b30ad2a4
X-VCS-Branch: master
Date: Tue, 26 Sep 2017 18:46:33 +0000 (UTC)
Precedence: bulk
List-Post: <mailto:gentoo-commits@lists.gentoo.org>
List-Help: <mailto:gentoo-commits+help@lists.gentoo.org>
List-Unsubscribe: <mailto:gentoo-commits+unsubscribe@lists.gentoo.org>
List-Subscribe: <mailto:gentoo-commits+subscribe@lists.gentoo.org>
List-Id: Gentoo Linux mail <gentoo-commits.gentoo.org>
X-BeenThere: gentoo-commits@lists.gentoo.org
X-Archives-Salt: 120b3c5b-cd1e-4bb5-b64a-0455e9e0f37a
X-Archives-Hash: 910d6860d520a2a800950225024ec063

commit:     7175c90c8c4bc1332899dffa6b5fa7a7b30ad2a4
Author:     Ulrich Müller <ulm <AT> gentoo <DOT> org>
AuthorDate: Sat Sep 23 08:58:43 2017 +0000
Commit:     Ulrich Müller <ulm <AT> gentoo <DOT> org>
CommitDate: Tue Sep 26 18:46:27 2017 +0000
URL:        https://gitweb.gentoo.org/repo/gentoo.git/commit/?id=7175c90c

eapi7-ver.eclass: Use lexicographic rather than arithmetic comparison.

This removes the 2**63-1 limit for integer components.

 eclass/eapi7-ver.eclass   | 36 ++++++++++++++++++++++++++----------
 eclass/tests/eapi7-ver.sh |  2 +-
 2 files changed, 27 insertions(+), 11 deletions(-)

diff --git a/eclass/eapi7-ver.eclass b/eclass/eapi7-ver.eclass
index 5ca8b8143af..7eb070c6817 100644
--- a/eclass/eapi7-ver.eclass
+++ b/eclass/eapi7-ver.eclass
@@ -174,6 +174,28 @@ ver_rs() {
 	echo "${comp[*]}"
 }
 
+# @FUNCTION: _ver_compare_int
+# @USAGE: <a> <b>
+# @RETURN: 0 if <a> -eq <b>, 1 if <a> -lt <b>, 3 if <a> -gt <b>
+# @INTERNAL
+# @DESCRIPTION:
+# Compare two non-negative integers <a> and <b>, of arbitrary length.
+# If <a> is equal to, less than, or greater than <b>, return 0, 1, or 3
+# as exit status, respectively.
+_ver_compare_int() {
+	local a=$1 b=$2 d=$(( ${#1}-${#2} ))
+
+	# Zero-pad to equal length if necessary.
+	if [[ ${d} -gt 0 ]]; then
+		printf -v b "%0${d}d%s" 0 "${b}"
+	elif [[ ${d} -lt 0 ]]; then
+		printf -v a "%0$(( -d ))d%s" 0 "${a}"
+	fi
+
+	[[ ${a} > ${b} ]] && return 3
+	[[ ${a} == "${b}" ]]
+}
+
 # @FUNCTION: _ver_compare
 # @USAGE: <va> <vb>
 # @RETURN: 1 if <va> < <vb>, 2 if <va> = <vb>, 3 if <va> > <vb>
@@ -200,10 +222,7 @@ _ver_compare() {
 
 	# Compare numeric components (PMS algorithm 3.2)
 	# First component
-	a=${an%%.*}
-	b=${bn%%.*}
-	[[ 10#${a} -gt 10#${b} ]] && return 3
-	[[ 10#${a} -lt 10#${b} ]] && return 1
+	_ver_compare_int "${an%%.*}" "${bn%%.*}" || return
 
 	while [[ ${an} == *.* && ${bn} == *.* ]]; do
 		# Other components (PMS algorithm 3.3)
@@ -218,8 +237,7 @@ _ver_compare() {
 			[[ ${a} > ${b} ]] && return 3
 			[[ ${a} < ${b} ]] && return 1
 		else
-			[[ ${a} -gt ${b} ]] && return 3
-			[[ ${a} -lt ${b} ]] && return 1
+			_ver_compare_int "${a}" "${b}" || return
 		fi
 	done
 	[[ ${an} == *.* ]] && return 3
@@ -237,8 +255,7 @@ _ver_compare() {
 		a=${as%%_*}
 		b=${bs%%_*}
 		if [[ ${a%%[0-9]*} == "${b%%[0-9]*}" ]]; then
-			[[ 10#${a##*[a-z]} -gt 10#${b##*[a-z]} ]] && return 3
-			[[ 10#${a##*[a-z]} -lt 10#${b##*[a-z]} ]] && return 1
+			_ver_compare_int "${a##*[a-z]}" "${b##*[a-z]}" || return
 		else
 			# Check for p first
 			[[ ${a%%[0-9]*} == p ]] && return 3
@@ -256,8 +273,7 @@ _ver_compare() {
 	fi
 
 	# Compare revision components (PMS algorithm 3.7)
-	[[ 10#${ar#-r} -gt 10#${br#-r} ]] && return 3
-	[[ 10#${ar#-r} -lt 10#${br#-r} ]] && return 1
+	_ver_compare_int "${ar#-r}" "${br#-r}" || return
 
 	return 2
 }

diff --git a/eclass/tests/eapi7-ver.sh b/eclass/tests/eapi7-ver.sh
index fd085a415b6..d4aa4fdbd28 100755
--- a/eclass/tests/eapi7-ver.sh
+++ b/eclass/tests/eapi7-ver.sh
@@ -150,7 +150,7 @@ teqr 0 ver_test 1.010 -eq 1.01
 teqr 0 ver_test 1.01 -lt 1.1
 teqr 0 ver_test 1.2_pre08-r09 -eq 1.2_pre8-r9
 teqr 0 ver_test 0 -lt 576460752303423488 # 2**59
-#teqr 0 ver_test 0 -lt 9223372036854775808 # 2**63 fails, integer rollover
+teqr 0 ver_test 0 -lt 9223372036854775808 # 2**63
 
 # Bad number or ordering of arguments
 txf ver_test 1