Skip to content

Commit

Permalink
Do not cast away constness
Browse files Browse the repository at this point in the history
Fix most compiler warnings caused by building Perl extensions with
-Wcast-qual. This is realized by changing the type of multiple T *
arguments into const T * and by changing a few (T *) casts
into (const T *).
  • Loading branch information
bvanassche authored and leonerd committed Dec 13, 2022
1 parent 84fa78b commit 1829598
Show file tree
Hide file tree
Showing 6 changed files with 10 additions and 9 deletions.
1 change: 1 addition & 0 deletions AUTHORS
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@ Bah <[email protected]>
Barrie Slaymaker <[email protected]>
Barry Friedman
Bart Kedryna <[email protected]>
Bart Van Assche <[email protected]>
Bas van Sisseren <[email protected]>
Beau Cox
Ben Carter <[email protected]>
Expand Down
6 changes: 3 additions & 3 deletions hv_func.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@
# define PVT__PERL_HASH_SEED_BYTES (PVT__PERL_HASH_WORD_SIZE * 2)
# define PVT__PERL_HASH_STATE_BYTES (PVT__PERL_HASH_WORD_SIZE * 4)
# define PVT__PERL_HASH_SEED_STATE(seed,state) S_perl_siphash_seed_state(seed,state)
# define PVT__PERL_HASH_WITH_STATE(state,str,len) S_perl_hash_siphash_1_3_with_state((state),(U8*)(str),(len))
# define PVT__PERL_HASH_WITH_STATE(state,str,len) S_perl_hash_siphash_1_3_with_state((state),(const U8*)(str),(len))
#elif defined(PERL_HASH_FUNC_ZAPHOD32)
# define PERL_HASH_FUNC_DEFINE "PERL_HASH_FUNC_ZAPHOD32"
# define PVT__PERL_HASH_FUNC "ZAPHOD32"
Expand Down Expand Up @@ -119,15 +119,15 @@

#define PVT_PERL_HASH_WITH_STATE(state,str,len) \
(LIKELY(len <= SBOX32_MAX_LEN) \
? sbox32_hash_with_state((state + PVT__PERL_HASH_STATE_BYTES),(U8*)(str),(len)) \
? sbox32_hash_with_state((state + PVT__PERL_HASH_STATE_BYTES),(const U8*)(str),(len)) \
: PVT__PERL_HASH_WITH_STATE((state),(str),(len)))

#endif

#define PERL_HASH_WITH_SEED(seed,hash,str,len) \
(hash) = S_perl_hash_with_seed((const U8 *) seed, (const U8 *) str,len)
#define PERL_HASH_WITH_STATE(state,hash,str,len) \
(hash) = PVT_PERL_HASH_WITH_STATE((state),(U8*)(str),(len))
(hash) = PVT_PERL_HASH_WITH_STATE((state),(const U8*)(str),(len))

#define PERL_HASH_SEED_STATE(seed,state) PVT_PERL_HASH_SEED_STATE(seed,state)
#define PERL_HASH_SEED_BYTES PVT_PERL_HASH_SEED_roundup(PVT_PERL_HASH_SEED_BYTES)
Expand Down
2 changes: 1 addition & 1 deletion hv_macro.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
*/

#ifndef U8TO16_LE
#define _shifted_octet(type,ptr,idx,shift) (((type)(((U8*)(ptr))[(idx)]))<<(shift))
#define _shifted_octet(type,ptr,idx,shift) (((type)(((const U8*)(ptr))[(idx)]))<<(shift))
#if defined(USE_UNALIGNED_PTR_DEREF) && (BYTEORDER == 0x1234 || BYTEORDER == 0x12345678)
#define U8TO16_LE(ptr) (*((const U16*)(ptr)))
#define U8TO32_LE(ptr) (*((const U32*)(ptr)))
Expand Down
4 changes: 2 additions & 2 deletions inline.h
Original file line number Diff line number Diff line change
Expand Up @@ -568,7 +568,7 @@ Perl_is_utf8_invariant_string_loc(const U8* const s, STRLEN len, const U8 ** ep)
/* Here, we know we have at least one full word to process. Process
* per-word as long as we have at least a full word left */
do {
if ((* (PERL_UINTMAX_T *) x) & PERL_VARIANTS_WORD_MASK) {
if ((* (const PERL_UINTMAX_T *) x) & PERL_VARIANTS_WORD_MASK) {

/* Found a variant. Just return if caller doesn't want its
* exact position */
Expand All @@ -579,7 +579,7 @@ Perl_is_utf8_invariant_string_loc(const U8* const s, STRLEN len, const U8 ** ep)
# if BYTEORDER == 0x1234 || BYTEORDER == 0x12345678 \
|| BYTEORDER == 0x4321 || BYTEORDER == 0x87654321

*ep = x + variant_byte_number(* (PERL_UINTMAX_T *) x);
*ep = x + variant_byte_number(* (const PERL_UINTMAX_T *) x);
assert(*ep >= s && *ep < send);

return FALSE;
Expand Down
4 changes: 2 additions & 2 deletions sbox32_hash.h
Original file line number Diff line number Diff line change
Expand Up @@ -1409,7 +1409,7 @@ SBOX32_STATIC_INLINE void sbox32_seed_state128 (
const U8 *seed_ch,
U8 *state_ch
) {
U32 *seed= (U32 *)seed_ch;
const U32 *seed= (const U32 *)seed_ch;
U32 *state= (U32 *)state_ch;
U32 *state_cursor = state + 1;
U32 *sbox32_end = state + 1 + (256 * SBOX32_MAX_LEN);
Expand Down Expand Up @@ -1458,7 +1458,7 @@ SBOX32_STATIC_INLINE U32 sbox32_hash_with_state(
const U8 *key,
const STRLEN key_len
) {
U32 *state= (U32 *)state_ch;
const U32 *state= (const U32 *)state_ch;
U32 hash = *state;
switch (key_len) {
default: return zaphod32_hash_with_state(state_ch, key, key_len);
Expand Down
2 changes: 1 addition & 1 deletion zaphod32_hash.h
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ U32 zaphod32_hash_with_state(
const U8 *key,
const STRLEN key_len
) {
U32 *state= (U32 *)state_ch;
const U32 *state= (const U32 *)state_ch;
const U8 *end;
STRLEN len = key_len;
U32 v0= state[0];
Expand Down

0 comments on commit 1829598

Please sign in to comment.