From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: 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 B6ADC1396D0 for ; Sat, 23 Sep 2017 10:43:06 +0000 (UTC) Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id 20DA4E085E; Sat, 23 Sep 2017 10:43:06 +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 E6E9FE085E for ; Sat, 23 Sep 2017 10:43:05 +0000 (UTC) Received: from oystercatcher.gentoo.org (unknown [IPv6:2a01:4f8:202:4333:225:90ff:fed9:fc84]) (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 990FB34071C for ; Sat, 23 Sep 2017 10:43:04 +0000 (UTC) Received: from localhost.localdomain (localhost [IPv6:::1]) by oystercatcher.gentoo.org (Postfix) with ESMTP id 0CCBC906C for ; Sat, 23 Sep 2017 10:43:03 +0000 (UTC) From: "Ulrich Müller" 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" Message-ID: <1506157123.7637f7476023183cdad69a7b28216e65eb4ad35a.ulm@gentoo> Subject: [gentoo-commits] repo/gentoo:eapi7-ver 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: 7637f7476023183cdad69a7b28216e65eb4ad35a X-VCS-Branch: eapi7-ver Date: Sat, 23 Sep 2017 10:43:03 +0000 (UTC) Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-Id: Gentoo Linux mail X-BeenThere: gentoo-commits@lists.gentoo.org X-Archives-Salt: fa4f8e5b-da41-4b53-a546-a9fca2a98222 X-Archives-Hash: 03c41075d5d82e70f4e4669ece48a23b commit: 7637f7476023183cdad69a7b28216e65eb4ad35a Author: Ulrich Müller gentoo org> AuthorDate: Sat Sep 23 08:58:43 2017 +0000 Commit: Ulrich Müller gentoo org> CommitDate: Sat Sep 23 08:58:43 2017 +0000 URL: https://gitweb.gentoo.org/repo/gentoo.git/commit/?id=7637f747 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: +# @RETURN: 0 if -eq , 1 if -lt , 3 if -gt +# @INTERNAL +# @DESCRIPTION: +# Compare two non-negative integers and , of arbitrary length. +# If is equal to, less than, or greater than , 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: # @RETURN: 1 if < , 2 if = , 3 if > @@ -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 7f0ae880767..1bd0bd1d81a 100755 --- a/eclass/tests/eapi7-ver.sh +++ b/eclass/tests/eapi7-ver.sh @@ -152,7 +152,7 @@ teqr 0 ver_test 1.2_pre08-r09 -eq 1.2_pre8-r9 teqr 0 ver_test 0 -lt 2147483648 # 2**31 teqr 0 ver_test 0 -lt 4294967296 # 2**32 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