dcb3b7
From 463ddf34c08f2c97199b1bb242da1f17494d4d1a Mon Sep 17 00:00:00 2001
dcb3b7
From: =?UTF-8?q?Petr=20P=C3=ADsa=C5=99?= <ppisar@redhat.com>
dcb3b7
Date: Thu, 24 Nov 2016 16:34:09 +0100
dcb3b7
Subject: [PATCH] Fix const correctness in hv_func.h
dcb3b7
MIME-Version: 1.0
dcb3b7
Content-Type: text/plain; charset=UTF-8
dcb3b7
Content-Transfer-Encoding: 8bit
dcb3b7
dcb3b7
Building an XS code with -Wcast-qual yielded warnings about discarding
dcb3b7
const qualifiers from pointer targets like:
dcb3b7
dcb3b7
$ printf '#include "EXTERN.h"\n#include "perl.h"\n' | gcc -Wcast-qual -I/usr/lib64/perl5/CORE -c -x c -
dcb3b7
In file included from /usr/lib64/perl5/CORE/hv.h:629:0,
dcb3b7
                 from /usr/lib64/perl5/CORE/perl.h:3740,
dcb3b7
                 from <stdin>:2:
dcb3b7
/usr/lib64/perl5/CORE/hv_func.h: In function ‘S_perl_hash_siphash_2_4’:
dcb3b7
/usr/lib64/perl5/CORE/hv_func.h:213:17: warning: cast discards ‘const’ qualifier from pointer target type [-Wcast-qual]
dcb3b7
   U64TYPE k0 = ((U64TYPE*)seed)[0];
dcb3b7
                 ^
dcb3b7
dcb3b7
Signed-off-by: Petr Písař <ppisar@redhat.com>
dcb3b7
---
dcb3b7
 hv_func.h | 22 +++++++++++-----------
dcb3b7
 1 file changed, 11 insertions(+), 11 deletions(-)
dcb3b7
dcb3b7
diff --git a/hv_func.h b/hv_func.h
dcb3b7
index 8866db9..57b1ed1 100644
dcb3b7
--- a/hv_func.h
dcb3b7
+++ b/hv_func.h
dcb3b7
@@ -118,7 +118,7 @@
dcb3b7
 
dcb3b7
 #if (BYTEORDER == 0x1234 || BYTEORDER == 0x12345678) && U32SIZE == 4
dcb3b7
   /* CPU endian matches murmurhash algorithm, so read 32-bit word directly */
dcb3b7
-  #define U8TO32_LE(ptr)   (*((U32*)(ptr)))
dcb3b7
+  #define U8TO32_LE(ptr)   (*((const U32*)(ptr)))
dcb3b7
 #elif BYTEORDER == 0x4321 || BYTEORDER == 0x87654321
dcb3b7
   /* TODO: Add additional cases below where a compiler provided bswap32 is available */
dcb3b7
   #if defined(__GNUC__) && (__GNUC__>4 || (__GNUC__==4 && __GNUC_MINOR__>=3))
dcb3b7
@@ -210,8 +210,8 @@ S_perl_hash_siphash_2_4(const unsigned char * const seed, const unsigned char *i
dcb3b7
   U64 v3 = UINT64_C(0x7465646279746573);
dcb3b7
 
dcb3b7
   U64 b;
dcb3b7
-  U64 k0 = ((U64*)seed)[0];
dcb3b7
-  U64 k1 = ((U64*)seed)[1];
dcb3b7
+  U64 k0 = ((const U64*)seed)[0];
dcb3b7
+  U64 k1 = ((const U64*)seed)[1];
dcb3b7
   U64 m;
dcb3b7
   const int left = inlen & 7;
dcb3b7
   const U8 *end = in + inlen - left;
dcb3b7
@@ -269,7 +269,7 @@ S_perl_hash_siphash_2_4(const unsigned char * const seed, const unsigned char *i
dcb3b7
 
dcb3b7
 PERL_STATIC_INLINE U32
dcb3b7
 S_perl_hash_superfast(const unsigned char * const seed, const unsigned char *str, STRLEN len) {
dcb3b7
-    U32 hash = *((U32*)seed) + (U32)len;
dcb3b7
+    U32 hash = *((const U32*)seed) + (U32)len;
dcb3b7
     U32 tmp;
dcb3b7
     int rem= len & 3;
dcb3b7
     len >>= 2;
dcb3b7
@@ -373,7 +373,7 @@ S_perl_hash_superfast(const unsigned char * const seed, const unsigned char *str
dcb3b7
 /* now we create the hash function */
dcb3b7
 PERL_STATIC_INLINE U32
dcb3b7
 S_perl_hash_murmur3(const unsigned char * const seed, const unsigned char *ptr, STRLEN len) {
dcb3b7
-    U32 h1 = *((U32*)seed);
dcb3b7
+    U32 h1 = *((const U32*)seed);
dcb3b7
     U32 k1;
dcb3b7
     U32 carry = 0;
dcb3b7
 
dcb3b7
@@ -467,7 +467,7 @@ S_perl_hash_murmur3(const unsigned char * const seed, const unsigned char *ptr,
dcb3b7
 PERL_STATIC_INLINE U32
dcb3b7
 S_perl_hash_djb2(const unsigned char * const seed, const unsigned char *str, const STRLEN len) {
dcb3b7
     const unsigned char * const end = (const unsigned char *)str + len;
dcb3b7
-    U32 hash = *((U32*)seed) + (U32)len;
dcb3b7
+    U32 hash = *((const U32*)seed) + (U32)len;
dcb3b7
     while (str < end) {
dcb3b7
         hash = ((hash << 5) + hash) + *str++;
dcb3b7
     }
dcb3b7
@@ -477,7 +477,7 @@ S_perl_hash_djb2(const unsigned char * const seed, const unsigned char *str, con
dcb3b7
 PERL_STATIC_INLINE U32
dcb3b7
 S_perl_hash_sdbm(const unsigned char * const seed, const unsigned char *str, const STRLEN len) {
dcb3b7
     const unsigned char * const end = (const unsigned char *)str + len;
dcb3b7
-    U32 hash = *((U32*)seed) + (U32)len;
dcb3b7
+    U32 hash = *((const U32*)seed) + (U32)len;
dcb3b7
     while (str < end) {
dcb3b7
         hash = (hash << 6) + (hash << 16) - hash + *str++;
dcb3b7
     }
dcb3b7
@@ -503,7 +503,7 @@ S_perl_hash_sdbm(const unsigned char * const seed, const unsigned char *str, con
dcb3b7
 PERL_STATIC_INLINE U32
dcb3b7
 S_perl_hash_one_at_a_time(const unsigned char * const seed, const unsigned char *str, const STRLEN len) {
dcb3b7
     const unsigned char * const end = (const unsigned char *)str + len;
dcb3b7
-    U32 hash = *((U32*)seed) + (U32)len;
dcb3b7
+    U32 hash = *((const U32*)seed) + (U32)len;
dcb3b7
     while (str < end) {
dcb3b7
         hash += *str++;
dcb3b7
         hash += (hash << 10);
dcb3b7
@@ -518,7 +518,7 @@ S_perl_hash_one_at_a_time(const unsigned char * const seed, const unsigned char
dcb3b7
 PERL_STATIC_INLINE U32
dcb3b7
 S_perl_hash_one_at_a_time_hard(const unsigned char * const seed, const unsigned char *str, const STRLEN len) {
dcb3b7
     const unsigned char * const end = (const unsigned char *)str + len;
dcb3b7
-    U32 hash = *((U32*)seed) + (U32)len;
dcb3b7
+    U32 hash = *((const U32*)seed) + (U32)len;
dcb3b7
     
dcb3b7
     while (str < end) {
dcb3b7
         hash += (hash << 10);
dcb3b7
@@ -553,7 +553,7 @@ S_perl_hash_one_at_a_time_hard(const unsigned char * const seed, const unsigned
dcb3b7
 PERL_STATIC_INLINE U32
dcb3b7
 S_perl_hash_old_one_at_a_time(const unsigned char * const seed, const unsigned char *str, const STRLEN len) {
dcb3b7
     const unsigned char * const end = (const unsigned char *)str + len;
dcb3b7
-    U32 hash = *((U32*)seed);
dcb3b7
+    U32 hash = *((const U32*)seed);
dcb3b7
     while (str < end) {
dcb3b7
         hash += *str++;
dcb3b7
         hash += (hash << 10);
dcb3b7
@@ -581,7 +581,7 @@ S_perl_hash_murmur_hash_64a (const unsigned char * const seed, const unsigned ch
dcb3b7
 {
dcb3b7
         const U64 m = UINT64_C(0xc6a4a7935bd1e995);
dcb3b7
         const int r = 47;
dcb3b7
-        U64 h = *((U64*)seed) ^ len;
dcb3b7
+        U64 h = *((const U64*)seed) ^ len;
dcb3b7
         const U64 * data = (const U64 *)str;
dcb3b7
         const U64 * end = data + (len/8);
dcb3b7
         const unsigned char * data2;
dcb3b7
-- 
dcb3b7
2.7.4
dcb3b7