diff options
author | Marko Mäkelä <marko.makela@mariadb.com> | 2020-03-12 19:44:52 +0200 |
---|---|---|
committer | Marko Mäkelä <marko.makela@mariadb.com> | 2020-03-12 19:44:52 +0200 |
commit | d82ac8d374241b100f9e019400b23a5d905f622c (patch) | |
tree | 8b38b91c6963bc14ca3044bd179f19fe44aedf82 /include/my_bitmap.h | |
parent | c7920fa8ff0a29958cfd337bcb3f3fac8703256a (diff) | |
download | mariadb-git-d82ac8d374241b100f9e019400b23a5d905f622c.tar.gz |
MDEV-21907: Fix some -Wconversion outside InnoDB
Some .c and .cc files are compiled as part of Mariabackup.
Enabling -Wconversion for InnoDB would also enable it for
Mariabackup. The .h files are being included during
InnoDB or Mariabackup compilation.
Notably, GCC 5 (but not GCC 4 or 6 or later versions)
would report -Wconversion for x|=y when the type is
unsigned char. So, we will either write x=(uchar)(x|y)
or disable the -Wconversion warning for GCC 5.
bitmap_set_bit(), bitmap_flip_bit(), bitmap_clear_bit(), bitmap_is_set():
Always implement as inline functions.
Diffstat (limited to 'include/my_bitmap.h')
-rw-r--r-- | include/my_bitmap.h | 49 |
1 files changed, 14 insertions, 35 deletions
diff --git a/include/my_bitmap.h b/include/my_bitmap.h index 1b0fbe40d2e..f19254404c1 100644 --- a/include/my_bitmap.h +++ b/include/my_bitmap.h @@ -1,5 +1,5 @@ /* Copyright (c) 2001, 2011, Oracle and/or its affiliates. - Copyright (c) 2009-2011, Monty Program Ab + Copyright (c) 2009, 2020, MariaDB Corporation. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -89,56 +89,35 @@ extern void bitmap_lock_clear_bit(MY_BITMAP *map, uint bitmap_bit); #define no_bytes_in_map(map) (((map)->n_bits + 7)/8) #define no_words_in_map(map) (((map)->n_bits + 31)/32) #define bytes_word_aligned(bytes) (4*((bytes + 3)/4)) -#define _bitmap_set_bit(MAP, BIT) (((uchar*)(MAP)->bitmap)[(BIT) / 8] \ - |= (1 << ((BIT) & 7))) -#define _bitmap_flip_bit(MAP, BIT) (((uchar*)(MAP)->bitmap)[(BIT) / 8] \ - ^= (1 << ((BIT) & 7))) -#define _bitmap_clear_bit(MAP, BIT) (((uchar*)(MAP)->bitmap)[(BIT) / 8] \ - &= ~ (1 << ((BIT) & 7))) -#define _bitmap_is_set(MAP, BIT) (uint) (((uchar*)(MAP)->bitmap)[(BIT) / 8] \ - & (1 << ((BIT) & 7))) -/* - WARNING! - - The below symbols are inline functions in DEBUG builds and macros in - non-DEBUG builds. The latter evaluate their 'bit' argument twice. - - NEVER use an increment/decrement operator with the 'bit' argument. - It would work with DEBUG builds, but fails later in production builds! - - FORBIDDEN: bitmap_set_bit($my_bitmap, (field++)->field_index); -*/ -#ifndef DBUG_OFF +/* The following functions must be compatible with create_last_word_mask()! */ static inline void bitmap_set_bit(MY_BITMAP *map,uint bit) { - DBUG_ASSERT(bit < (map)->n_bits); - _bitmap_set_bit(map,bit); + uchar *b= (uchar*) map->bitmap + bit / 8; + DBUG_ASSERT(bit < map->n_bits); + *b= (uchar) (*b | 1U << (bit & 7)); } static inline void bitmap_flip_bit(MY_BITMAP *map,uint bit) { - DBUG_ASSERT(bit < (map)->n_bits); - _bitmap_flip_bit(map,bit); + uchar *b= (uchar*) map->bitmap + bit / 8; + DBUG_ASSERT(bit < map->n_bits); + *b= (uchar) (*b ^ 1U << (bit & 7)); } static inline void bitmap_clear_bit(MY_BITMAP *map,uint bit) { - DBUG_ASSERT(bit < (map)->n_bits); - _bitmap_clear_bit(map,bit); + uchar *b= (uchar*) map->bitmap + bit / 8; + DBUG_ASSERT(bit < map->n_bits); + *b= (uchar) (*b & ~(1U << (bit & 7))); } static inline uint bitmap_is_set(const MY_BITMAP *map,uint bit) { - DBUG_ASSERT(bit < (map)->n_bits); - return _bitmap_is_set(map,bit); + const uchar *b= (const uchar*) map->bitmap + bit / 8; + DBUG_ASSERT(bit < map->n_bits); + return !!(*b & (1U << (bit & 7))); } -#else -#define bitmap_set_bit(MAP, BIT) _bitmap_set_bit(MAP, BIT) -#define bitmap_flip_bit(MAP, BIT) _bitmap_flip_bit(MAP, BIT) -#define bitmap_clear_bit(MAP, BIT) _bitmap_clear_bit(MAP, BIT) -#define bitmap_is_set(MAP, BIT) _bitmap_is_set(MAP, BIT) -#endif static inline my_bool bitmap_cmp(const MY_BITMAP *map1, const MY_BITMAP *map2) { |