diff options
author | Marko Mäkelä <marko.makela@mariadb.com> | 2018-04-30 15:46:09 +0300 |
---|---|---|
committer | Marko Mäkelä <marko.makela@mariadb.com> | 2018-04-30 18:22:52 +0300 |
commit | 9801715cb0ce71ab248464bdcfad0cfa82e998e6 (patch) | |
tree | 14a196c02b6f081e74abeccc0a57c64ef5b65112 /storage/innobase | |
parent | 8cd55ae2a998626631a41c8d3a4ec38c59b4b607 (diff) | |
download | mariadb-git-9801715cb0ce71ab248464bdcfad0cfa82e998e6.tar.gz |
Use compile_time_assert() in InnoDB
Replace most use of #error. Some checks were impossible to
evaluate in the preprocessor due to the use of named
integer constants or enumerations.
Diffstat (limited to 'storage/innobase')
28 files changed, 102 insertions, 262 deletions
diff --git a/storage/innobase/btr/btr0btr.cc b/storage/innobase/btr/btr0btr.cc index 47a1ed30d92..c62b7cf4c35 100644 --- a/storage/innobase/btr/btr0btr.cc +++ b/storage/innobase/btr/btr0btr.cc @@ -4008,9 +4008,7 @@ retry: #ifdef UNIV_BTR_DEBUG memcpy(fil_page_prev, merge_page + FIL_PAGE_PREV, 4); #endif /* UNIV_BTR_DEBUG */ -#if FIL_NULL != 0xffffffff -# error "FIL_NULL != 0xffffffff" -#endif + compile_time_assert(FIL_NULL == 0xffffffffU); memset(merge_page + FIL_PAGE_PREV, 0xff, 4); } diff --git a/storage/innobase/btr/btr0cur.cc b/storage/innobase/btr/btr0cur.cc index 0318b1eea57..b59371ced0c 100644 --- a/storage/innobase/btr/btr0cur.cc +++ b/storage/innobase/btr/btr0cur.cc @@ -205,18 +205,6 @@ btr_rec_free_externally_stored_fields( /*==================== B-TREE SEARCH =========================*/ -/** -#if MTR_MEMO_PAGE_S_FIX != RW_S_LATCH -#error "MTR_MEMO_PAGE_S_FIX != RW_S_LATCH" -#endif -#if MTR_MEMO_PAGE_X_FIX != RW_X_LATCH -#error "MTR_MEMO_PAGE_X_FIX != RW_X_LATCH" -#endif -#if MTR_MEMO_PAGE_SX_FIX != RW_SX_LATCH -#error "MTR_MEMO_PAGE_SX_FIX != RW_SX_LATCH" -#endif -*/ - /** Latches the leaf page or pages requested. @param[in] block leaf page where the search converged @param[in] page_id page id of the leaf @@ -241,6 +229,10 @@ btr_cur_latch_leaves( bool spatial; btr_latch_leaves_t latch_leaves = {{NULL, NULL, NULL}, {0, 0, 0}}; + compile_time_assert(int(MTR_MEMO_PAGE_S_FIX) == int(RW_S_LATCH)); + compile_time_assert(int(MTR_MEMO_PAGE_X_FIX) == int(RW_X_LATCH)); + compile_time_assert(int(MTR_MEMO_PAGE_SX_FIX) == int(RW_SX_LATCH)); + spatial = dict_index_is_spatial(cursor->index) && cursor->rtr_info; ut_ad(buf_page_in_file(&block->page)); diff --git a/storage/innobase/buf/buf0buddy.cc b/storage/innobase/buf/buf0buddy.cc index c5239db8ec2..27a45654966 100644 --- a/storage/innobase/buf/buf0buddy.cc +++ b/storage/innobase/buf/buf0buddy.cc @@ -73,10 +73,6 @@ list. This value is stamped at BUF_BUDDY_STAMP_OFFSET offset */ value by the consumer of the block */ #define BUF_BUDDY_STAMP_NONFREE 0XFFFFFFFFUL -#if BUF_BUDDY_STAMP_FREE >= BUF_BUDDY_STAMP_NONFREE -# error "BUF_BUDDY_STAMP_FREE >= BUF_BUDDY_STAMP_NONFREE" -#endif - /** Return type of buf_buddy_is_free() */ enum buf_buddy_state_t { BUF_BUDDY_STATE_FREE, /*!< If the buddy to completely free */ @@ -114,6 +110,7 @@ buf_buddy_stamp_is_free( /*====================*/ const buf_buddy_free_t* buf) /*!< in: block to check */ { + compile_time_assert(BUF_BUDDY_STAMP_FREE < BUF_BUDDY_STAMP_NONFREE); return(mach_read_from_4(buf->stamp.bytes + BUF_BUDDY_STAMP_OFFSET) == BUF_BUDDY_STAMP_FREE); } @@ -138,13 +135,12 @@ buf_buddy_stamp_free( Stamps a buddy nonfree. @param[in,out] buf block to stamp @param[in] i block size */ -#define buf_buddy_stamp_nonfree(buf, i) do { \ - buf_buddy_mem_invalid(buf, i); \ - memset(buf->stamp.bytes + BUF_BUDDY_STAMP_OFFSET, 0xff, 4); \ -} while (0) -#if BUF_BUDDY_STAMP_NONFREE != 0xffffffff -# error "BUF_BUDDY_STAMP_NONFREE != 0xffffffff" -#endif +static inline void buf_buddy_stamp_nonfree(buf_buddy_free_t* buf, ulint i) +{ + buf_buddy_mem_invalid(buf, i); + compile_time_assert(BUF_BUDDY_STAMP_NONFREE == 0xffffffffU); + memset(buf->stamp.bytes + BUF_BUDDY_STAMP_OFFSET, 0xff, 4); +} /**********************************************************************//** Get the offset of the buddy of a compressed page frame. diff --git a/storage/innobase/buf/buf0buf.cc b/storage/innobase/buf/buf0buf.cc index 250b879467d..29989ccca7f 100644 --- a/storage/innobase/buf/buf0buf.cc +++ b/storage/innobase/buf/buf0buf.cc @@ -910,9 +910,7 @@ buf_page_is_corrupted( checksum_field2 = mach_read_from_4( read_buf + page_size.logical() - FIL_PAGE_END_LSN_OLD_CHKSUM); -#if FIL_PAGE_LSN % 8 -#error "FIL_PAGE_LSN must be 64 bit aligned" -#endif + compile_time_assert(!(FIL_PAGE_LSN % 8)); /* declare empty pages non-corrupted */ if (checksum_field1 == 0 diff --git a/storage/innobase/buf/buf0lru.cc b/storage/innobase/buf/buf0lru.cc index 88eeaa555e6..8b32a2cb533 100644 --- a/storage/innobase/buf/buf0lru.cc +++ b/storage/innobase/buf/buf0lru.cc @@ -59,9 +59,6 @@ static const ulint BUF_LRU_OLD_TOLERANCE = 20; (that is, when there are more than BUF_LRU_OLD_MIN_LEN blocks). @see buf_LRU_old_adjust_len */ #define BUF_LRU_NON_OLD_MIN_LEN 5 -#if BUF_LRU_NON_OLD_MIN_LEN >= BUF_LRU_OLD_MIN_LEN -# error "BUF_LRU_NON_OLD_MIN_LEN >= BUF_LRU_OLD_MIN_LEN" -#endif /** When dropping the search hash index entries before deleting an ibd file, we build a local array of pages belonging to that tablespace @@ -1208,8 +1205,12 @@ buf_LRU_old_adjust_len( ut_ad(buf_pool_mutex_own(buf_pool)); ut_ad(buf_pool->LRU_old_ratio >= BUF_LRU_OLD_RATIO_MIN); ut_ad(buf_pool->LRU_old_ratio <= BUF_LRU_OLD_RATIO_MAX); + compile_time_assert(BUF_LRU_OLD_RATIO_MIN * BUF_LRU_OLD_MIN_LEN + > BUF_LRU_OLD_RATIO_DIV + * (BUF_LRU_OLD_TOLERANCE + 5)); + compile_time_assert(BUF_LRU_NON_OLD_MIN_LEN < BUF_LRU_OLD_MIN_LEN); + #ifdef UNIV_LRU_DEBUG - compile_time_assert(BUF_LRU_OLD_RATIO_MIN * BUF_LRU_OLD_MIN_LEN <= BUF_LRU_OLD_RATIO_DIV * (BUF_LRU_OLD_TOLERANCE + 5)); /* buf_pool->LRU_old must be the first item in the LRU list whose "old" flag is set. */ ut_a(buf_pool->LRU_old->old); diff --git a/storage/innobase/dict/dict0dict.cc b/storage/innobase/dict/dict0dict.cc index 6c975fdf05b..8fa6f6ad4c6 100644 --- a/storage/innobase/dict/dict0dict.cc +++ b/storage/innobase/dict/dict0dict.cc @@ -1242,28 +1242,19 @@ dict_table_add_system_columns( DATA_ROW_ID | DATA_NOT_NULL, DATA_ROW_ID_LEN); -#if DATA_ROW_ID != 0 -#error "DATA_ROW_ID != 0" -#endif + compile_time_assert(DATA_ROW_ID == 0); dict_mem_table_add_col(table, heap, "DB_TRX_ID", DATA_SYS, DATA_TRX_ID | DATA_NOT_NULL, DATA_TRX_ID_LEN); -#if DATA_TRX_ID != 1 -#error "DATA_TRX_ID != 1" -#endif - + compile_time_assert(DATA_TRX_ID == 1); dict_mem_table_add_col(table, heap, "DB_ROLL_PTR", DATA_SYS, DATA_ROLL_PTR | DATA_NOT_NULL, DATA_ROLL_PTR_LEN); -#if DATA_ROLL_PTR != 2 -#error "DATA_ROLL_PTR != 2" -#endif + compile_time_assert(DATA_ROLL_PTR == 2); /* This check reminds that if a new system column is added to the program, it should be dealt with here */ -#if DATA_N_SYS_COLS != 3 -#error "DATA_N_SYS_COLS != 3" -#endif + compile_time_assert(DATA_N_SYS_COLS == 3); } /** Add the table definition to the data dictionary cache */ @@ -2077,19 +2068,13 @@ dict_col_name_is_reserved( /*======================*/ const char* name) /*!< in: column name */ { - /* This check reminds that if a new system column is added to - the program, it should be dealt with here. */ -#if DATA_N_SYS_COLS != 3 -#error "DATA_N_SYS_COLS != 3" -#endif - static const char* reserved_names[] = { "DB_ROW_ID", "DB_TRX_ID", "DB_ROLL_PTR" }; - ulint i; + compile_time_assert(UT_ARR_SIZE(reserved_names) == DATA_N_SYS_COLS); - for (i = 0; i < UT_ARR_SIZE(reserved_names); i++) { + for (ulint i = 0; i < UT_ARR_SIZE(reserved_names); i++) { if (innobase_strcasecmp(name, reserved_names[i]) == 0) { return(TRUE); @@ -2799,12 +2784,11 @@ dict_index_add_col( if (field->fixed_len > DICT_MAX_FIXED_COL_LEN) { field->fixed_len = 0; } -#if DICT_MAX_FIXED_COL_LEN != 768 + /* The comparison limit above must be constant. If it were changed, the disk format of some fixed-length columns would change, which would be a disaster. */ -# error "DICT_MAX_FIXED_COL_LEN != 768" -#endif + compile_time_assert(DICT_MAX_FIXED_COL_LEN == 768); if (!(col->prtype & DATA_NOT_NULL)) { index->n_nullable++; @@ -2999,15 +2983,9 @@ dict_index_build_internal_clust( trx_id_pos = new_index->n_def; -#if DATA_ROW_ID != 0 -# error "DATA_ROW_ID != 0" -#endif -#if DATA_TRX_ID != 1 -# error "DATA_TRX_ID != 1" -#endif -#if DATA_ROLL_PTR != 2 -# error "DATA_ROLL_PTR != 2" -#endif + compile_time_assert(DATA_ROW_ID == 0); + compile_time_assert(DATA_TRX_ID == 1); + compile_time_assert(DATA_ROLL_PTR == 2); if (!dict_index_is_unique(index)) { dict_index_add_col(new_index, table, diff --git a/storage/innobase/fil/fil0fil.cc b/storage/innobase/fil/fil0fil.cc index 4ea9eae809a..1b217dd4b6f 100644 --- a/storage/innobase/fil/fil0fil.cc +++ b/storage/innobase/fil/fil0fil.cc @@ -4388,12 +4388,10 @@ fil_io( ut_ad(byte_offset < srv_page_size); ut_ad(!page_size.is_compressed() || byte_offset == 0); ut_ad(srv_page_size == 1UL << srv_page_size_shift); -#if (1 << UNIV_PAGE_SIZE_SHIFT_MAX) != UNIV_PAGE_SIZE_MAX -# error "(1 << UNIV_PAGE_SIZE_SHIFT_MAX) != UNIV_PAGE_SIZE_MAX" -#endif -#if (1 << UNIV_PAGE_SIZE_SHIFT_MIN) != UNIV_PAGE_SIZE_MIN -# error "(1 << UNIV_PAGE_SIZE_SHIFT_MIN) != UNIV_PAGE_SIZE_MIN" -#endif + compile_time_assert((1U << UNIV_PAGE_SIZE_SHIFT_MAX) + == UNIV_PAGE_SIZE_MAX); + compile_time_assert((1U << UNIV_PAGE_SIZE_SHIFT_MIN) + == UNIV_PAGE_SIZE_MIN); ut_ad(fil_validate_skip()); /* ibuf bitmap pages must be read in the sync AIO mode: */ diff --git a/storage/innobase/handler/i_s.cc b/storage/innobase/handler/i_s.cc index e761d1f126a..0d227643b0c 100644 --- a/storage/innobase/handler/i_s.cc +++ b/storage/innobase/handler/i_s.cc @@ -87,11 +87,6 @@ in i_s_page_type[] array */ #define I_S_PAGE_TYPE_BITS 4 -/* Check if we can hold all page types */ -#if I_S_PAGE_TYPE_LAST >= 1 << I_S_PAGE_TYPE_BITS -# error i_s_page_type[] is too large -#endif - /** Name string for File Page Types */ static buf_page_desc_t i_s_page_type[] = { {"ALLOCATED", FIL_PAGE_TYPE_ALLOCATED}, @@ -4852,6 +4847,8 @@ i_s_innodb_buffer_page_fill( TABLE* table; Field** fields; + compile_time_assert(I_S_PAGE_TYPE_LAST < 1 << I_S_PAGE_TYPE_BITS); + DBUG_ENTER("i_s_innodb_buffer_page_fill"); table = tables->table; @@ -4955,10 +4952,7 @@ i_s_innodb_buffer_page_fill( page_info->zip_ssize ? (UNIV_ZIP_SIZE_MIN >> 1) << page_info->zip_ssize : 0, true)); - -#if BUF_PAGE_STATE_BITS > 3 -# error "BUF_PAGE_STATE_BITS > 3, please ensure that all 1<<BUF_PAGE_STATE_BITS values are checked for" -#endif + compile_time_assert(BUF_PAGE_STATE_BITS == 3); state = static_cast<enum buf_page_state>(page_info->page_state); switch (state) { diff --git a/storage/innobase/ibuf/ibuf0ibuf.cc b/storage/innobase/ibuf/ibuf0ibuf.cc index b0032397f9c..1dcccc61a68 100644 --- a/storage/innobase/ibuf/ibuf0ibuf.cc +++ b/storage/innobase/ibuf/ibuf0ibuf.cc @@ -36,9 +36,6 @@ my_bool srv_ibuf_disable_background_merge; /** Number of bits describing a single page */ #define IBUF_BITS_PER_PAGE 4 -#if IBUF_BITS_PER_PAGE % 2 -# error "IBUF_BITS_PER_PAGE must be an even number!" -#endif /** The start address for an insert buffer bitmap page bitmap */ #define IBUF_BITMAP PAGE_DATA @@ -258,9 +255,6 @@ type, counter, and some flags. */ /* @{ */ #define IBUF_REC_INFO_SIZE 4 /*!< Combined size of info fields at the beginning of the fourth field */ -#if IBUF_REC_INFO_SIZE >= DATA_NEW_ORDER_NULL_TYPE_BUF_SIZE -# error "IBUF_REC_INFO_SIZE >= DATA_NEW_ORDER_NULL_TYPE_BUF_SIZE" -#endif /* Offsets for the fields at the beginning of the fourth field */ #define IBUF_REC_OFFSET_COUNTER 0 /*!< Operation counter */ @@ -611,6 +605,7 @@ ibuf_bitmap_page_init( fil_page_set_type(page, FIL_PAGE_IBUF_BITMAP); /* Write all zeros to the bitmap */ + compile_time_assert(!(IBUF_BITS_PER_PAGE % 2)); byte_offset = UT_BITS_IN_BYTES(block->page.size.physical() * IBUF_BITS_PER_PAGE); @@ -694,9 +689,7 @@ ibuf_bitmap_page_get_bits_low( ulint value; ut_ad(bit < IBUF_BITS_PER_PAGE); -#if IBUF_BITS_PER_PAGE % 2 -# error "IBUF_BITS_PER_PAGE % 2 != 0" -#endif + compile_time_assert(!(IBUF_BITS_PER_PAGE % 2)); ut_ad(mtr_memo_contains_page(mtr, page, latch_type)); bit_offset = (page_id.page_no() % page_size.physical()) @@ -742,9 +735,7 @@ ibuf_bitmap_page_set_bits( ulint map_byte; ut_ad(bit < IBUF_BITS_PER_PAGE); -#if IBUF_BITS_PER_PAGE % 2 -# error "IBUF_BITS_PER_PAGE % 2 != 0" -#endif + compile_time_assert(!(IBUF_BITS_PER_PAGE % 2)); ut_ad(mtr_memo_contains_page(mtr, page, MTR_MEMO_PAGE_X_FIX)); ut_ad(mtr->is_named_space(page_id.space())); #ifdef UNIV_IBUF_COUNT_DEBUG @@ -1330,6 +1321,8 @@ ibuf_rec_get_info_func( types = rec_get_nth_field_old(rec, IBUF_REC_FIELD_METADATA, &len); info_len_local = len % DATA_NEW_ORDER_NULL_TYPE_BUF_SIZE; + compile_time_assert(IBUF_REC_INFO_SIZE + < DATA_NEW_ORDER_NULL_TYPE_BUF_SIZE); switch (info_len_local) { case 0: diff --git a/storage/innobase/include/data0type.ic b/storage/innobase/include/data0type.ic index 8898642a152..56a588562ee 100644 --- a/storage/innobase/include/data0type.ic +++ b/storage/innobase/include/data0type.ic @@ -235,9 +235,8 @@ dtype_new_store_for_order_and_null_size( ulint prefix_len)/*!< in: prefix length to replace type->len, or 0 */ { -#if 6 != DATA_NEW_ORDER_NULL_TYPE_BUF_SIZE -#error "6 != DATA_NEW_ORDER_NULL_TYPE_BUF_SIZE" -#endif + compile_time_assert(6 == DATA_NEW_ORDER_NULL_TYPE_BUF_SIZE); + ulint len; ut_ad(type); @@ -280,10 +279,7 @@ dtype_read_for_order_and_null_size( dtype_t* type, /*!< in: type struct */ const byte* buf) /*!< in: buffer for stored type order info */ { -#if 4 != DATA_ORDER_NULL_TYPE_BUF_SIZE -# error "4 != DATA_ORDER_NULL_TYPE_BUF_SIZE" -#endif - + compile_time_assert(4 == DATA_ORDER_NULL_TYPE_BUF_SIZE); type->mtype = buf[0] & 63; type->prtype = buf[1]; @@ -309,11 +305,7 @@ dtype_new_read_for_order_and_null_size( dtype_t* type, /*!< in: type struct */ const byte* buf) /*!< in: buffer for stored type order info */ { - ulint charset_coll; - -#if 6 != DATA_NEW_ORDER_NULL_TYPE_BUF_SIZE -#error "6 != DATA_NEW_ORDER_NULL_TYPE_BUF_SIZE" -#endif + compile_time_assert(6 == DATA_NEW_ORDER_NULL_TYPE_BUF_SIZE); type->mtype = buf[0] & 63; type->prtype = buf[1]; @@ -328,7 +320,7 @@ dtype_new_read_for_order_and_null_size( type->len = mach_read_from_2(buf + 2); - charset_coll = mach_read_from_2(buf + 4) & CHAR_COLL_MASK; + ulint charset_coll = mach_read_from_2(buf + 4) & CHAR_COLL_MASK; if (dtype_is_string_type(type->mtype)) { ut_a(charset_coll <= MAX_CHAR_COLL_NUM); diff --git a/storage/innobase/include/dict0boot.ic b/storage/innobase/include/dict0boot.ic index e40c3f844e3..845a0a3888d 100644 --- a/storage/innobase/include/dict0boot.ic +++ b/storage/innobase/include/dict0boot.ic @@ -58,10 +58,7 @@ dict_sys_read_row_id( /*=================*/ const byte* field) /*!< in: record field */ { -#if DATA_ROW_ID_LEN != 6 -# error "DATA_ROW_ID_LEN != 6" -#endif - + compile_time_assert(DATA_ROW_ID_LEN == 6); return(mach_read_from_6(field)); } @@ -74,10 +71,7 @@ dict_sys_write_row_id( byte* field, /*!< in: record field */ row_id_t row_id) /*!< in: row id */ { -#if DATA_ROW_ID_LEN != 6 -# error "DATA_ROW_ID_LEN != 6" -#endif - + compile_time_assert(DATA_ROW_ID_LEN == 6); mach_write_to_6(field, row_id); } diff --git a/storage/innobase/include/dict0dict.ic b/storage/innobase/include/dict0dict.ic index 84bedcd4dc7..9db5f078e2c 100644 --- a/storage/innobase/include/dict0dict.ic +++ b/storage/innobase/include/dict0dict.ic @@ -555,11 +555,6 @@ dict_table_is_comp( const dict_table_t* table) /*!< in: table */ { ut_ad(table); - -#if DICT_TF_COMPACT != 1 -#error "DICT_TF_COMPACT must be 1" -#endif - return (table->flags & DICT_TF_COMPACT) != 0; } diff --git a/storage/innobase/include/fsp0fsp.ic b/storage/innobase/include/fsp0fsp.ic index 1efee63df7e..38d890fd2f3 100644 --- a/storage/innobase/include/fsp0fsp.ic +++ b/storage/innobase/include/fsp0fsp.ic @@ -92,18 +92,12 @@ xdes_calc_descriptor_page( const page_size_t& page_size, ulint offset) { -#ifndef DOXYGEN /* Doxygen gets confused by these */ -# if UNIV_PAGE_SIZE_MAX <= XDES_ARR_OFFSET \ - + (UNIV_PAGE_SIZE_MAX / FSP_EXTENT_SIZE_MAX) \ - * XDES_SIZE_MAX -# error -# endif -# if UNIV_ZIP_SIZE_MIN <= XDES_ARR_OFFSET \ - + (UNIV_ZIP_SIZE_MIN / FSP_EXTENT_SIZE_MIN) \ - * XDES_SIZE_MIN -# error -# endif -#endif /* !DOXYGEN */ + compile_time_assert(UNIV_PAGE_SIZE_MAX > XDES_ARR_OFFSET + + (UNIV_PAGE_SIZE_MAX / FSP_EXTENT_SIZE_MAX) + * XDES_SIZE_MAX); + compile_time_assert(UNIV_PAGE_SIZE_MIN > XDES_ARR_OFFSET + + (UNIV_PAGE_SIZE_MIN / FSP_EXTENT_SIZE_MIN) + * XDES_SIZE_MIN); ut_ad(srv_page_size > XDES_ARR_OFFSET + (srv_page_size / FSP_EXTENT_SIZE) diff --git a/storage/innobase/include/ibuf0ibuf.ic b/storage/innobase/include/ibuf0ibuf.ic index a82701fbf98..f91ae5aee4a 100644 --- a/storage/innobase/include/ibuf0ibuf.ic +++ b/storage/innobase/include/ibuf0ibuf.ic @@ -314,9 +314,7 @@ ibuf_update_free_bits_if_full( block->page.size.physical(), max_ins_size); if (max_ins_size >= increase) { -#if ULINT32_UNDEFINED <= UNIV_PAGE_SIZE_MAX -# error "ULINT32_UNDEFINED <= UNIV_PAGE_SIZE_MAX" -#endif + compile_time_assert(ULINT32_UNDEFINED > UNIV_PAGE_SIZE_MAX); after = ibuf_index_page_calc_free_bits( block->page.size.physical(), max_ins_size - increase); #ifdef UNIV_IBUF_DEBUG diff --git a/storage/innobase/include/page0page.ic b/storage/innobase/include/page0page.ic index d096276c988..307803367c0 100644 --- a/storage/innobase/include/page0page.ic +++ b/storage/innobase/include/page0page.ic @@ -829,9 +829,8 @@ page_rec_get_base_extra_size( /*=========================*/ const rec_t* rec) /*!< in: physical record */ { -#if REC_N_NEW_EXTRA_BYTES + 1 != REC_N_OLD_EXTRA_BYTES -# error "REC_N_NEW_EXTRA_BYTES + 1 != REC_N_OLD_EXTRA_BYTES" -#endif + compile_time_assert(REC_N_NEW_EXTRA_BYTES + 1 + == REC_N_OLD_EXTRA_BYTES); return(REC_N_NEW_EXTRA_BYTES + (ulint) !page_rec_is_comp(rec)); } diff --git a/storage/innobase/include/rem0rec.ic b/storage/innobase/include/rem0rec.ic index f945062fa12..5e9dbcdcfb6 100644 --- a/storage/innobase/include/rem0rec.ic +++ b/storage/innobase/include/rem0rec.ic @@ -235,8 +235,8 @@ rec_get_next_ptr_const( { ulint field_value; - ut_ad(REC_NEXT_MASK == 0xFFFFUL); - ut_ad(REC_NEXT_SHIFT == 0); + compile_time_assert(REC_NEXT_MASK == 0xFFFFUL); + compile_time_assert(REC_NEXT_SHIFT == 0); field_value = mach_read_from_2(rec - REC_NEXT); @@ -304,12 +304,8 @@ rec_get_next_offs( ulint comp) /*!< in: nonzero=compact page format */ { ulint field_value; -#if REC_NEXT_MASK != 0xFFFFUL -# error "REC_NEXT_MASK != 0xFFFFUL" -#endif -#if REC_NEXT_SHIFT -# error "REC_NEXT_SHIFT != 0" -#endif + compile_time_assert(REC_NEXT_MASK == 0xFFFFUL); + compile_time_assert(REC_NEXT_SHIFT == 0); field_value = mach_read_from_2(rec - REC_NEXT); @@ -361,13 +357,8 @@ rec_set_next_offs_old( { ut_ad(rec); ut_ad(srv_page_size > next); -#if REC_NEXT_MASK != 0xFFFFUL -# error "REC_NEXT_MASK != 0xFFFFUL" -#endif -#if REC_NEXT_SHIFT -# error "REC_NEXT_SHIFT != 0" -#endif - + compile_time_assert(REC_NEXT_MASK == 0xFFFFUL); + compile_time_assert(REC_NEXT_SHIFT == 0); mach_write_to_2(rec - REC_NEXT, next); } @@ -627,10 +618,8 @@ rec_get_info_and_status_bits( ulint comp) /*!< in: nonzero=compact page format */ { ulint bits; -#if (REC_NEW_STATUS_MASK >> REC_NEW_STATUS_SHIFT) \ -& (REC_INFO_BITS_MASK >> REC_INFO_BITS_SHIFT) -# error "REC_NEW_STATUS_MASK and REC_INFO_BITS_MASK overlap" -#endif + compile_time_assert(!((REC_NEW_STATUS_MASK >> REC_NEW_STATUS_SHIFT) + & (REC_INFO_BITS_MASK >> REC_INFO_BITS_SHIFT))); if (comp) { bits = rec_get_info_bits(rec, TRUE) | ulint(rec_get_status(rec)); @@ -650,10 +639,8 @@ rec_set_info_and_status_bits( rec_t* rec, /*!< in/out: physical record */ ulint bits) /*!< in: info bits */ { -#if (REC_NEW_STATUS_MASK >> REC_NEW_STATUS_SHIFT) \ -& (REC_INFO_BITS_MASK >> REC_INFO_BITS_SHIFT) -# error "REC_NEW_STATUS_MASK and REC_INFO_BITS_MASK overlap" -#endif + compile_time_assert(!((REC_NEW_STATUS_MASK >> REC_NEW_STATUS_SHIFT) + & (REC_INFO_BITS_MASK >> REC_INFO_BITS_SHIFT))); rec_set_status(rec, bits & REC_NEW_STATUS_MASK); rec_set_info_bits_new(rec, bits & ~REC_NEW_STATUS_MASK); } @@ -806,10 +793,6 @@ rec_get_1byte_offs_flag( /*====================*/ const rec_t* rec) /*!< in: physical record */ { -#if TRUE != 1 -#error "TRUE != 1" -#endif - return(rec_get_bit_field_1(rec, REC_OLD_SHORT, REC_OLD_SHORT_MASK, REC_OLD_SHORT_SHIFT)); } @@ -823,10 +806,7 @@ rec_set_1byte_offs_flag( rec_t* rec, /*!< in: physical record */ ibool flag) /*!< in: TRUE if 1byte form */ { -#if TRUE != 1 -#error "TRUE != 1" -#endif - ut_ad(flag <= TRUE); + ut_ad(flag <= 1); rec_set_bit_field_1(rec, flag, REC_OLD_SHORT, REC_OLD_SHORT_MASK, REC_OLD_SHORT_SHIFT); diff --git a/storage/innobase/include/row0upd.ic b/storage/innobase/include/row0upd.ic index 364c876ecc7..5e43a272388 100644 --- a/storage/innobase/include/row0upd.ic +++ b/storage/innobase/include/row0upd.ic @@ -181,9 +181,8 @@ row_upd_rec_sys_fields( offset = row_get_trx_id_offset(index, offsets); } -#if DATA_TRX_ID + 1 != DATA_ROLL_PTR -# error "DATA_TRX_ID + 1 != DATA_ROLL_PTR" -#endif + compile_time_assert(DATA_TRX_ID + 1 == DATA_ROLL_PTR); + /* During IMPORT the trx id in the record can be in the future, if the .ibd file is being imported from another instance. During IMPORT roll_ptr will be 0. */ diff --git a/storage/innobase/include/trx0undo.ic b/storage/innobase/include/trx0undo.ic index 74a014d1d77..630638f6b7b 100644 --- a/storage/innobase/include/trx0undo.ic +++ b/storage/innobase/include/trx0undo.ic @@ -40,9 +40,7 @@ trx_undo_build_roll_ptr( ulint offset) /*!< in: offset of the undo entry within page */ { roll_ptr_t roll_ptr; -#if DATA_ROLL_PTR_LEN != 7 -# error "DATA_ROLL_PTR_LEN != 7" -#endif + compile_time_assert(DATA_ROLL_PTR_LEN == 7); ut_ad(is_insert == 0 || is_insert == 1); ut_ad(rseg_id < TRX_SYS_N_RSEGS); ut_ad(offset < 65536); @@ -67,12 +65,7 @@ trx_undo_decode_roll_ptr( ulint* offset) /*!< out: offset of the undo entry within page */ { -#if DATA_ROLL_PTR_LEN != 7 -# error "DATA_ROLL_PTR_LEN != 7" -#endif -#if TRUE != 1 -# error "TRUE != 1" -#endif + compile_time_assert(DATA_ROLL_PTR_LEN == 7); ut_ad(roll_ptr < (1ULL << 56)); *offset = (ulint) roll_ptr & 0xFFFF; roll_ptr >>= 16; @@ -92,12 +85,7 @@ trx_undo_roll_ptr_is_insert( /*========================*/ roll_ptr_t roll_ptr) /*!< in: roll pointer */ { -#if DATA_ROLL_PTR_LEN != 7 -# error "DATA_ROLL_PTR_LEN != 7" -#endif -#if TRUE != 1 -# error "TRUE != 1" -#endif + compile_time_assert(DATA_ROLL_PTR_LEN == 7); ut_ad(roll_ptr < (1ULL << (ROLL_PTR_INSERT_FLAG_POS + 1))); return((ibool) (roll_ptr >> ROLL_PTR_INSERT_FLAG_POS)); } @@ -111,10 +99,8 @@ trx_undo_trx_id_is_insert( /*======================*/ const byte* trx_id) /*!< in: DB_TRX_ID, followed by DB_ROLL_PTR */ { -#if DATA_TRX_ID + 1 != DATA_ROLL_PTR -# error -#endif - return(static_cast<bool>(trx_id[DATA_TRX_ID_LEN] >> 7)); + compile_time_assert(DATA_TRX_ID + 1 == DATA_ROLL_PTR); + return bool(trx_id[DATA_TRX_ID_LEN] >> 7); } /*****************************************************************//** @@ -129,9 +115,7 @@ trx_write_roll_ptr( written */ roll_ptr_t roll_ptr) /*!< in: roll ptr */ { -#if DATA_ROLL_PTR_LEN != 7 -# error "DATA_ROLL_PTR_LEN != 7" -#endif + compile_time_assert(DATA_ROLL_PTR_LEN == 7); mach_write_to_7(ptr, roll_ptr); } @@ -146,9 +130,7 @@ trx_read_roll_ptr( /*==============*/ const byte* ptr) /*!< in: pointer to memory from where to read */ { -#if DATA_ROLL_PTR_LEN != 7 -# error "DATA_ROLL_PTR_LEN != 7" -#endif + compile_time_assert(DATA_ROLL_PTR_LEN == 7); return(mach_read_from_7(ptr)); } diff --git a/storage/innobase/include/univ.i b/storage/innobase/include/univ.i index 68c904ebd9f..8370fb83b71 100644 --- a/storage/innobase/include/univ.i +++ b/storage/innobase/include/univ.i @@ -463,7 +463,7 @@ typedef ib_uint64_t lsn_t; #define UINT64_UNDEFINED ((ib_uint64_t)(-1)) /** The bitmask of 32-bit unsigned integer */ -#define ULINT32_MASK 0xFFFFFFFF +#define ULINT32_MASK 0xFFFFFFFFU /** The undefined 32-bit unsigned integer */ #define ULINT32_UNDEFINED ULINT32_MASK diff --git a/storage/innobase/include/ut0byte.ic b/storage/innobase/include/ut0byte.ic index 9c0cd6ee3c3..1ef90eca416 100644 --- a/storage/innobase/include/ut0byte.ic +++ b/storage/innobase/include/ut0byte.ic @@ -144,9 +144,6 @@ ut_bit_get_nth( ulint n) /*!< in: nth bit requested */ { ut_ad(n < 8 * sizeof(ulint)); -#if TRUE != 1 -# error "TRUE != 1" -#endif return(1 & (a >> n)); } @@ -162,9 +159,6 @@ ut_bit_set_nth( ibool val) /*!< in: value for the bit to set */ { ut_ad(n < 8 * sizeof(ulint)); -#if TRUE != 1 -# error "TRUE != 1" -#endif if (val) { return(((ulint) 1 << n) | a); } else { diff --git a/storage/innobase/log/log0recv.cc b/storage/innobase/log/log0recv.cc index 8213aa446d1..40746d7c26e 100644 --- a/storage/innobase/log/log0recv.cc +++ b/storage/innobase/log/log0recv.cc @@ -2320,9 +2320,7 @@ loop: /* Do nothing */ break; case MLOG_CHECKPOINT: -#if SIZE_OF_MLOG_CHECKPOINT != 1 + 8 -# error SIZE_OF_MLOG_CHECKPOINT != 1 + 8 -#endif + compile_time_assert(SIZE_OF_MLOG_CHECKPOINT == 1 + 8); lsn = mach_read_from_8(ptr + 1); DBUG_PRINT("ib_log", diff --git a/storage/innobase/mtr/mtr0mtr.cc b/storage/innobase/mtr/mtr0mtr.cc index 2c0ecfeb7d3..0f536d73fa6 100644 --- a/storage/innobase/mtr/mtr0mtr.cc +++ b/storage/innobase/mtr/mtr0mtr.cc @@ -610,9 +610,7 @@ mtr_t::commit_checkpoint( if (write_mlog_checkpoint) { byte* ptr = m_impl.m_log.push<byte*>(SIZE_OF_MLOG_CHECKPOINT); -#if SIZE_OF_MLOG_CHECKPOINT != 9 -# error SIZE_OF_MLOG_CHECKPOINT != 9 -#endif + compile_time_assert(SIZE_OF_MLOG_CHECKPOINT == 1 + 8); *ptr = MLOG_CHECKPOINT; mach_write_to_8(ptr + 1, checkpoint_lsn); } diff --git a/storage/innobase/os/os0file.cc b/storage/innobase/os/os0file.cc index 195059c160b..8dcf936532a 100644 --- a/storage/innobase/os/os0file.cc +++ b/storage/innobase/os/os0file.cc @@ -698,10 +698,6 @@ bool os_has_said_disk_full; /** Default Zip compression level */ extern uint page_zip_level; -#if DATA_TRX_ID_LEN > 6 -#error "COMPRESSION_ALGORITHM will not fit" -#endif /* DATA_TRX_ID_LEN */ - /** Validates the consistency of the aio system. @return true if ok */ static diff --git a/storage/innobase/page/page0cur.cc b/storage/innobase/page/page0cur.cc index 2a21317c9da..ed2c21a80b5 100644 --- a/storage/innobase/page/page0cur.cc +++ b/storage/innobase/page/page0cur.cc @@ -2398,9 +2398,7 @@ page_cur_delete_rec( prev_rec is owned by the same slot, i.e., PAGE_DIR_SLOT_MIN_N_OWNED >= 2. */ -#if PAGE_DIR_SLOT_MIN_N_OWNED < 2 -# error "PAGE_DIR_SLOT_MIN_N_OWNED < 2" -#endif + compile_time_assert(PAGE_DIR_SLOT_MIN_N_OWNED >= 2); ut_ad(cur_n_owned > 1); if (current_rec == page_dir_slot_get_rec(cur_dir_slot)) { diff --git a/storage/innobase/page/page0page.cc b/storage/innobase/page/page0page.cc index 644fbe8e722..46165632b7c 100644 --- a/storage/innobase/page/page0page.cc +++ b/storage/innobase/page/page0page.cc @@ -357,12 +357,10 @@ page_create_low( { page_t* page; -#if PAGE_BTR_IBUF_FREE_LIST + FLST_BASE_NODE_SIZE > PAGE_DATA -# error "PAGE_BTR_IBUF_FREE_LIST + FLST_BASE_NODE_SIZE > PAGE_DATA" -#endif -#if PAGE_BTR_IBUF_FREE_LIST_NODE + FLST_NODE_SIZE > PAGE_DATA -# error "PAGE_BTR_IBUF_FREE_LIST_NODE + FLST_NODE_SIZE > PAGE_DATA" -#endif + compile_time_assert(PAGE_BTR_IBUF_FREE_LIST + FLST_BASE_NODE_SIZE + <= PAGE_DATA); + compile_time_assert(PAGE_BTR_IBUF_FREE_LIST_NODE + FLST_NODE_SIZE + <= PAGE_DATA); buf_block_modify_clock_inc(block); diff --git a/storage/innobase/page/page0zip.cc b/storage/innobase/page/page0zip.cc index f13e20ff447..a0b0429115e 100644 --- a/storage/innobase/page/page0zip.cc +++ b/storage/innobase/page/page0zip.cc @@ -412,9 +412,7 @@ page_zip_compress_write_log( /* Add the space occupied by BLOB pointers. */ trailer_size += page_zip->n_blobs * BTR_EXTERN_FIELD_REF_SIZE; ut_a(page_zip->m_end > PAGE_DATA); -#if FIL_PAGE_DATA > PAGE_DATA -# error "FIL_PAGE_DATA > PAGE_DATA" -#endif + compile_time_assert(FIL_PAGE_DATA <= PAGE_DATA); ut_a(page_zip->m_end + trailer_size <= page_zip_get_size(page_zip)); log_ptr = mlog_write_initial_log_record_fast((page_t*) page, @@ -697,12 +695,11 @@ page_zip_dir_encode( ut_a(heap_no < n_heap); ut_a(offs < srv_page_size - PAGE_DIR); ut_a(offs >= PAGE_ZIP_START); -#if PAGE_ZIP_DIR_SLOT_MASK & (PAGE_ZIP_DIR_SLOT_MASK + 1) -# error PAGE_ZIP_DIR_SLOT_MASK is not 1 less than a power of 2 -#endif -#if PAGE_ZIP_DIR_SLOT_MASK < UNIV_ZIP_SIZE_MAX - 1 -# error PAGE_ZIP_DIR_SLOT_MASK < UNIV_ZIP_SIZE_MAX - 1 -#endif + compile_time_assert(!(PAGE_ZIP_DIR_SLOT_MASK + & (PAGE_ZIP_DIR_SLOT_MASK + 1))); + compile_time_assert(PAGE_ZIP_DIR_SLOT_MASK + >= UNIV_ZIP_SIZE_MAX - 1); + if (UNIV_UNLIKELY(rec_get_n_owned_new(rec) != 0)) { offs |= PAGE_ZIP_DIR_SLOT_OWNED; } @@ -4123,9 +4120,7 @@ page_zip_write_node_ptr( #if defined UNIV_DEBUG || defined UNIV_ZIP_DEBUG ut_a(!memcmp(storage, field, REC_NODE_PTR_SIZE)); #endif /* UNIV_DEBUG || UNIV_ZIP_DEBUG */ -#if REC_NODE_PTR_SIZE != 4 -# error "REC_NODE_PTR_SIZE != 4" -#endif + compile_time_assert(REC_NODE_PTR_SIZE == 4); mach_write_to_4(field, ptr); memcpy(storage, field, REC_NODE_PTR_SIZE); @@ -4191,9 +4186,7 @@ page_zip_write_trx_id_and_roll_ptr( - (rec_get_heap_no_new(rec) - 1) * (DATA_TRX_ID_LEN + DATA_ROLL_PTR_LEN); -#if DATA_TRX_ID + 1 != DATA_ROLL_PTR -# error "DATA_TRX_ID + 1 != DATA_ROLL_PTR" -#endif + compile_time_assert(DATA_TRX_ID + 1 == DATA_ROLL_PTR); field = rec_get_nth_field(rec, offsets, trx_id_col, &len); ut_ad(len == DATA_TRX_ID_LEN); ut_ad(field + DATA_TRX_ID_LEN @@ -4202,13 +4195,9 @@ page_zip_write_trx_id_and_roll_ptr( #if defined UNIV_DEBUG || defined UNIV_ZIP_DEBUG ut_a(!memcmp(storage, field, DATA_TRX_ID_LEN + DATA_ROLL_PTR_LEN)); #endif /* UNIV_DEBUG || UNIV_ZIP_DEBUG */ -#if DATA_TRX_ID_LEN != 6 -# error "DATA_TRX_ID_LEN != 6" -#endif + compile_time_assert(DATA_TRX_ID_LEN == 6); mach_write_to_6(field, trx_id); -#if DATA_ROLL_PTR_LEN != 7 -# error "DATA_ROLL_PTR_LEN != 7" -#endif + compile_time_assert(DATA_ROLL_PTR_LEN == 7); mach_write_to_7(field + DATA_TRX_ID_LEN, roll_ptr); memcpy(storage, field, DATA_TRX_ID_LEN + DATA_ROLL_PTR_LEN); @@ -4726,9 +4715,7 @@ page_zip_write_header_log( ut_ad(offset < PAGE_DATA); ut_ad(offset + length < PAGE_DATA); -#if PAGE_DATA > 255 -# error "PAGE_DATA > 255" -#endif + compile_time_assert(PAGE_DATA < 256U); ut_ad(length > 0); ut_ad(length < 256); @@ -4876,9 +4863,7 @@ page_zip_copy_recs( the records stored in the page. Also copy the field PAGE_MAX_TRX_ID. Skip the rest of the page header and trailer. On the compressed page, there is no trailer. */ -#if PAGE_MAX_TRX_ID + 8 != PAGE_HEADER_PRIV_END -# error "PAGE_MAX_TRX_ID + 8 != PAGE_HEADER_PRIV_END" -#endif + compile_time_assert(PAGE_MAX_TRX_ID + 8 == PAGE_HEADER_PRIV_END); memcpy(PAGE_HEADER + page, PAGE_HEADER + src, PAGE_HEADER_PRIV_END); memcpy(PAGE_DATA + page, PAGE_DATA + src, @@ -5084,9 +5069,7 @@ page_zip_verify_checksum( (data) + FIL_PAGE_SPACE_ID); const page_id_t page_id(space_id, page_no); -#if FIL_PAGE_LSN % 8 -#error "FIL_PAGE_LSN must be 64 bit aligned" -#endif + compile_time_assert(!(FIL_PAGE_LSN % 8)); /* Check if page is empty */ if (stored == 0 diff --git a/storage/innobase/row/row0row.cc b/storage/innobase/row/row0row.cc index 30b0a7a360c..94cee7d7e42 100644 --- a/storage/innobase/row/row0row.cc +++ b/storage/innobase/row/row0row.cc @@ -113,9 +113,8 @@ row_build_index_entry_low( col_no = dict_col_get_no(col); dfield = dtuple_get_nth_field(entry, i); } -#if DATA_MISSING != 0 -# error "DATA_MISSING != 0" -#endif + + compile_time_assert(DATA_MISSING == 0); if (dict_col_is_virtual(col)) { const dict_v_col_t* v_col diff --git a/storage/innobase/row/row0upd.cc b/storage/innobase/row/row0upd.cc index aead23deae4..1e3474a6793 100644 --- a/storage/innobase/row/row0upd.cc +++ b/storage/innobase/row/row0upd.cc @@ -513,9 +513,7 @@ row_upd_rec_sys_fields_in_recovery( field = rec_get_nth_field(rec, offsets, pos, &len); ut_ad(len == DATA_TRX_ID_LEN); -#if DATA_TRX_ID + 1 != DATA_ROLL_PTR -# error "DATA_TRX_ID + 1 != DATA_ROLL_PTR" -#endif + compile_time_assert(DATA_TRX_ID + 1 == DATA_ROLL_PTR); trx_write_trx_id(field, trx_id); trx_write_roll_ptr(field + DATA_TRX_ID_LEN, roll_ptr); } @@ -845,10 +843,7 @@ row_upd_index_write_log( log_ptr += mach_write_compressed(log_ptr, n_fields); for (i = 0; i < n_fields; i++) { - -#if MLOG_BUF_MARGIN <= 30 -# error "MLOG_BUF_MARGIN <= 30" -#endif + compile_time_assert(MLOG_BUF_MARGIN > 30); if (log_ptr + 30 > buf_end) { mlog_close(mtr, log_ptr); |