public inbox for gentoo-dev@lists.gentoo.org
 help / color / mirror / Atom feed
* [gentoo-dev] [PATCH v2 1/2] kernel-2.eclass: Replace bit-shift arithmetic by ver_test
@ 2021-08-28  5:41 Ulrich Müller
  2021-08-28  5:41 ` [gentoo-dev] [PATCH v2 2/2] linux-info.eclass: " Ulrich Müller
  2021-08-28  5:52 ` [gentoo-dev] [PATCH v2 1/2] kernel-2.eclass: " Ulrich Müller
  0 siblings, 2 replies; 3+ messages in thread
From: Ulrich Müller @ 2021-08-28  5:41 UTC (permalink / raw
  To: gentoo-dev; +Cc: Ulrich Müller

There are kernel versions like 4.9.280, therefore shifting version
components by 8 bits in kernel_is() may fail.

Signed-off-by: Ulrich Müller <ulm@gentoo.org>
---
v2: Protect against empty KV_{MAJOR,MINOR,PATCH}

 eclass/kernel-2.eclass | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)

diff --git a/eclass/kernel-2.eclass b/eclass/kernel-2.eclass
index 8c1740998272..05c07c4d153e 100644
--- a/eclass/kernel-2.eclass
+++ b/eclass/kernel-2.eclass
@@ -560,7 +560,7 @@ kernel_is() {
 	[[ ${n} -eq 1 ]] && detect_version
 
 	# Now we can continue
-	local operator test value
+	local operator
 
 	case ${1#-} in
 	  lt) operator="-lt"; shift;;
@@ -572,9 +572,10 @@ kernel_is() {
 	esac
 	[[ $# -gt 3 ]] && die "Error in kernel-2_kernel_is(): too many parameters"
 
-	: $(( test = (KV_MAJOR << 16) + (KV_MINOR << 8) + KV_PATCH ))
-	: $(( value = (${1:-${KV_MAJOR}} << 16) + (${2:-${KV_MINOR}} << 8) + ${3:-${KV_PATCH}} ))
-	[ ${test} ${operator} ${value} ]
+	ver_test \
+		"${KV_MAJOR:-0}.${KV_MINOR:-0}.${KV_PATCH:-0}" \
+		"${operator}" \
+		"${1:-${KV_MAJOR:-0}}.${2:-${KV_MINOR:-0}}.${3:-${KV_PATCH:-0}}"
 }
 
 # Capture the sources type and set DEPENDs
-- 
2.33.0



^ permalink raw reply related	[flat|nested] 3+ messages in thread

* [gentoo-dev] [PATCH v2 2/2] linux-info.eclass: Replace bit-shift arithmetic by ver_test
  2021-08-28  5:41 [gentoo-dev] [PATCH v2 1/2] kernel-2.eclass: Replace bit-shift arithmetic by ver_test Ulrich Müller
@ 2021-08-28  5:41 ` Ulrich Müller
  2021-08-28  5:52 ` [gentoo-dev] [PATCH v2 1/2] kernel-2.eclass: " Ulrich Müller
  1 sibling, 0 replies; 3+ messages in thread
From: Ulrich Müller @ 2021-08-28  5:41 UTC (permalink / raw
  To: gentoo-dev; +Cc: Ulrich Müller

There are kernel versions like 4.9.280, therefore shifting version
components by 8 bits in kernel_is() may fail.

Signed-off-by: Ulrich Müller <ulm@gentoo.org>
---
v2: Protect against empty KV_{MAJOR,MINOR,PATCH}

 eclass/linux-info.eclass | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)

diff --git a/eclass/linux-info.eclass b/eclass/linux-info.eclass
index 124fb70e78ad..8edd17c317d4 100644
--- a/eclass/linux-info.eclass
+++ b/eclass/linux-info.eclass
@@ -395,7 +395,7 @@ kernel_is() {
 	linux-info_get_any_version
 
 	# Now we can continue
-	local operator test value
+	local operator
 
 	case ${1#-} in
 	  lt) operator="-lt"; shift;;
@@ -407,9 +407,10 @@ kernel_is() {
 	esac
 	[[ $# -gt 3 ]] && die "Error in kernel-2_kernel_is(): too many parameters"
 
-	: $(( test = (KV_MAJOR << 16) + (KV_MINOR << 8) + KV_PATCH ))
-	: $(( value = (${1:-${KV_MAJOR}} << 16) + (${2:-${KV_MINOR}} << 8) + ${3:-${KV_PATCH}} ))
-	[ ${test} ${operator} ${value} ]
+	ver_test \
+		"${KV_MAJOR:-0}.${KV_MINOR:-0}.${KV_PATCH:-0}" \
+		"${operator}" \
+		"${1:-${KV_MAJOR:-0}}.${2:-${KV_MINOR:-0}}.${3:-${KV_PATCH:-0}}"
 }
 
 get_localversion() {
-- 
2.33.0



^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [gentoo-dev] [PATCH v2 1/2] kernel-2.eclass: Replace bit-shift arithmetic by ver_test
  2021-08-28  5:41 [gentoo-dev] [PATCH v2 1/2] kernel-2.eclass: Replace bit-shift arithmetic by ver_test Ulrich Müller
  2021-08-28  5:41 ` [gentoo-dev] [PATCH v2 2/2] linux-info.eclass: " Ulrich Müller
@ 2021-08-28  5:52 ` Ulrich Müller
  1 sibling, 0 replies; 3+ messages in thread
From: Ulrich Müller @ 2021-08-28  5:52 UTC (permalink / raw
  To: gentoo-dev

[-- Attachment #1: Type: text/plain, Size: 657 bytes --]

> +	ver_test \
> +		"${KV_MAJOR:-0}.${KV_MINOR:-0}.${KV_PATCH:-0}" \
> +		"${operator}" \
> +		"${1:-${KV_MAJOR:-0}}.${2:-${KV_MINOR:-0}}.${3:-${KV_PATCH:-0}}"

I've added fallbacks to 0, because it turns out that these components
can be empty.

There may also be a problem in detect_version().
For gentoo-sources-5.10.52 I get: 

   KV_MAJOR=5
   KV_MINOR=10
   KV_PATCH=52

but for git-sources-5.14_rc7:

   KV_MAJOR=5
   KV_MINOR=   # empty
   KV_PATCH=14

According to a comment in detect_version() the intended behaviour is
"if KV_MAJOR >= 3, then we have no more KV_MINOR" but looks like that
isn't always happening.

Ulrich

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 507 bytes --]

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2021-08-28  5:52 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2021-08-28  5:41 [gentoo-dev] [PATCH v2 1/2] kernel-2.eclass: Replace bit-shift arithmetic by ver_test Ulrich Müller
2021-08-28  5:41 ` [gentoo-dev] [PATCH v2 2/2] linux-info.eclass: " Ulrich Müller
2021-08-28  5:52 ` [gentoo-dev] [PATCH v2 1/2] kernel-2.eclass: " Ulrich Müller

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox