* [bug#29132] [PATCH] system: vm: Use 2^32 - 1 as hash size.
@ 2017-11-03 12:49 Mathieu Othacehe
2017-11-05 20:48 ` Ludovic Courtès
0 siblings, 1 reply; 5+ messages in thread
From: Mathieu Othacehe @ 2017-11-03 12:49 UTC (permalink / raw)
To: 29132
* gnu/system/vm.scm (operating-system-uuid): Use 2^32 - 1 instead of
2^32 as hash size.
On some 32 bit system (ARM for example), 2^32 exceeds hash max
size (ULONG_MAX = 2^32 - 1).
---
gnu/system/vm.scm | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/gnu/system/vm.scm b/gnu/system/vm.scm
index 3127b30..4424608 100644
--- a/gnu/system/vm.scm
+++ b/gnu/system/vm.scm
@@ -372,13 +372,13 @@ TYPE (one of 'iso9660 or 'dce). Return a UUID object."
(bytevector->uuid
(uint-list->bytevector
(list (hash file-system-type
- (expt 2 32))
+ (- (expt 2 32) 1))
(hash (operating-system-host-name os)
- (expt 2 32))
+ (- (expt 2 32) 1))
(hash (operating-system-services os)
- (expt 2 32))
+ (- (expt 2 32) 1))
(hash (operating-system-file-systems os)
- (expt 2 32)))
+ (- (expt 2 32) 1)))
(endianness little)
4)
type)))
--
2.7.4
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [bug#29132] [PATCH] system: vm: Use 2^32 - 1 as hash size.
2017-11-03 12:49 [bug#29132] [PATCH] system: vm: Use 2^32 - 1 as hash size Mathieu Othacehe
@ 2017-11-05 20:48 ` Ludovic Courtès
2017-11-05 20:56 ` Mathieu Othacehe
0 siblings, 1 reply; 5+ messages in thread
From: Ludovic Courtès @ 2017-11-05 20:48 UTC (permalink / raw)
To: Mathieu Othacehe; +Cc: 29132
Hello!
Mathieu Othacehe <m.othacehe@gmail.com> skribis:
> * gnu/system/vm.scm (operating-system-uuid): Use 2^32 - 1 instead of
> 2^32 as hash size.
>
> On some 32 bit system (ARM for example), 2^32 exceeds hash max
> size (ULONG_MAX = 2^32 - 1).
> ---
> gnu/system/vm.scm | 8 ++++----
> 1 file changed, 4 insertions(+), 4 deletions(-)
>
> diff --git a/gnu/system/vm.scm b/gnu/system/vm.scm
> index 3127b30..4424608 100644
> --- a/gnu/system/vm.scm
> +++ b/gnu/system/vm.scm
> @@ -372,13 +372,13 @@ TYPE (one of 'iso9660 or 'dce). Return a UUID object."
> (bytevector->uuid
> (uint-list->bytevector
> (list (hash file-system-type
> - (expt 2 32))
> + (- (expt 2 32) 1))
‘hash’ is documented like this:
-- Scheme Procedure: hash key size
-- Scheme Procedure: hashq key size
-- Scheme Procedure: hashv key size
-- C Function: scm_hash (key, size)
-- C Function: scm_hashq (key, size)
-- C Function: scm_hashv (key, size)
Return a hash value for KEY. This is a number in the range 0 to
SIZE-1, which is suitable for use in a hash table of the given
SIZE.
So I take it that you always get something in the range 0–2³²-1, no?
Ludo’.
^ permalink raw reply [flat|nested] 5+ messages in thread
* [bug#29132] [PATCH] system: vm: Use 2^32 - 1 as hash size.
2017-11-05 20:48 ` Ludovic Courtès
@ 2017-11-05 20:56 ` Mathieu Othacehe
2017-11-06 8:41 ` Ludovic Courtès
0 siblings, 1 reply; 5+ messages in thread
From: Mathieu Othacehe @ 2017-11-05 20:56 UTC (permalink / raw)
To: Ludovic Courtès; +Cc: 29132
Hey Ludo,
> So I take it that you always get something in the range 0–2³²-1, no?
Well I agree, but looking to hash code, we have :
--8<---------------cut here---------------start------------->8---
#define FUNC_NAME s_scm_hash
{
unsigned long sz = scm_to_unsigned_integer (size, 1, ULONG_MAX);
--8<---------------cut here---------------end--------------->8---
And 2^32 > ULONG_MAX == 2^32 - 1 on ARM.
This results in this exception :
--8<---------------cut here---------------start------------->8---
scheme@(guile-user)> (hash 'test (expt 2 32))
ERROR: In procedure hash:
ERROR: Value out of range 1 to 4294967295: 4294967296
--8<---------------cut here---------------end--------------->8---
Mathieu
^ permalink raw reply [flat|nested] 5+ messages in thread
* [bug#29132] [PATCH] system: vm: Use 2^32 - 1 as hash size.
2017-11-05 20:56 ` Mathieu Othacehe
@ 2017-11-06 8:41 ` Ludovic Courtès
2017-11-06 19:04 ` Mathieu Othacehe
0 siblings, 1 reply; 5+ messages in thread
From: Ludovic Courtès @ 2017-11-06 8:41 UTC (permalink / raw)
To: Mathieu Othacehe; +Cc: 29132
Mathieu Othacehe <m.othacehe@gmail.com> skribis:
> Hey Ludo,
>
>> So I take it that you always get something in the range 0–2³²-1, no?
>
> Well I agree, but looking to hash code, we have :
>
> #define FUNC_NAME s_scm_hash
> {
> unsigned long sz = scm_to_unsigned_integer (size, 1, ULONG_MAX);
Oh, got it. Well, OK for the patch!
Thank you,
Ludo’.
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2017-11-06 19:05 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-11-03 12:49 [bug#29132] [PATCH] system: vm: Use 2^32 - 1 as hash size Mathieu Othacehe
2017-11-05 20:48 ` Ludovic Courtès
2017-11-05 20:56 ` Mathieu Othacehe
2017-11-06 8:41 ` Ludovic Courtès
2017-11-06 19:04 ` Mathieu Othacehe
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/guix.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.