Commit 2ddbc912 authored by marko's avatar marko

branches/zip: Silence most GCC 4.2.1 warnings about const pointers.

For some reason, GCC 4.2.1 ignores casts (for removing constness)
in calls to inline functions.

page_align(), ut_align_down(): Make the parameter const void*, but still
return a non-const pointer.  This is ugly, but these functions cannot be
replaced with a const-preserving macro in a portable way, given that
the pointer argument is not always pointing to bytes.

buf_block_get_page_zip(): Implement as a const-preserving macro.

buf_frame_get_page_zip(), buf_block_align(): Add const qualifiers.

lock_rec_get_prev(): Silence GCC 4.2.1 warnings.

mlog_write_initial_log_record(), mlog_write_initial_log_record_fast(),
mtr_memo_contains(): Add const qualifier to the pointer.

page_header_get_ptr(): Rewrite as page_header_get_offs(), and
implement as a macro that calls this function.
parent e9507ea6
......@@ -535,7 +535,7 @@ btr_node_ptr_get_child(
ulint space;
ut_ad(rec_offs_validate(node_ptr, index, offsets));
space = page_get_space_id(page_align((rec_t*) node_ptr));
space = page_get_space_id(page_align(node_ptr));
page_no = btr_node_ptr_get_child_page_no(node_ptr, offsets);
return(btr_block_get(space, dict_table_zip_size(index->table),
......@@ -2252,12 +2252,14 @@ btr_lift_page_up(
(!page_copy_rec_list_end(father_block, block,
page_get_infimum_rec(page),
index, mtr))) {
const page_zip_des_t* page_zip
= buf_block_get_page_zip(block);
ut_a(father_page_zip);
ut_a(page_zip);
/* Copy the page byte for byte. */
page_zip_copy(father_page_zip, father_page,
buf_block_get_page_zip(block),
page, index, mtr);
page_zip, page, index, mtr);
}
lock_update_copy_and_discard(father_block, block);
......@@ -2432,8 +2434,11 @@ btr_compress(
merge_page_zip = buf_block_get_page_zip(merge_block);
#ifdef UNIV_ZIP_DEBUG
if (UNIV_LIKELY_NULL(merge_page_zip)) {
const page_zip_des_t* page_zip
= buf_block_get_page_zip(block);
ut_a(page_zip);
ut_a(page_zip_validate(merge_page_zip, merge_page));
ut_a(page_zip_validate(buf_block_get_page_zip(block), page));
ut_a(page_zip_validate(page_zip, page));
}
#endif /* UNIV_ZIP_DEBUG */
......
......@@ -494,10 +494,11 @@ btr_cur_search_to_nth_level(
page = buf_block_get_frame(block);
#ifdef UNIV_ZIP_DEBUG
ut_a(rw_latch == RW_NO_LATCH
|| !buf_block_get_page_zip(block)
|| page_zip_validate(buf_block_get_page_zip(block),
page));
if (rw_latch != RW_NO_LATCH) {
const page_zip_des_t* page_zip
= buf_block_get_page_zip(block);
ut_a(!page_zip || page_zip_validate(page_zip, page));
}
#endif /* UNIV_ZIP_DEBUG */
block->check_index_page_at_flush = TRUE;
......@@ -1048,8 +1049,10 @@ btr_cur_optimistic_insert(
/* If necessary for updating the insert buffer bitmap,
calculate the current maximum insert size on a compressed page. */
if (zip_size && UNIV_LIKELY(leaf) && !dict_index_is_clust(index)) {
lint zip_max = page_zip_max_ins_size(
buf_block_get_page_zip(block), FALSE);
const page_zip_des_t* page_zip
= buf_block_get_page_zip(block);
lint zip_max
= page_zip_max_ins_size(page_zip, FALSE);
if (zip_max >= 0 && max_size > (ulint) zip_max) {
max_size_zip = (ulint) zip_max;
......
......@@ -776,7 +776,7 @@ btr_search_guess_on_hash(
goto failure_unlock;
}
page = page_align((rec_t*) rec);
page = page_align(rec);
{
ulint page_no = page_get_page_no(page);
ulint space_id = page_get_space_id(page);
......
......@@ -258,7 +258,7 @@ btr_node_ptr_get_child_page_no(
"InnoDB: a nonsensical page number 0"
" in a node ptr record at offset %lu\n",
(ulong) page_offset(rec));
buf_page_print(page_align((rec_t*) rec), 0);
buf_page_print(page_align(rec), 0);
}
return(page_no);
......
......@@ -854,32 +854,26 @@ buf_block_get_zip_size(
/*************************************************************************
Gets the compressed page descriptor corresponding to an uncompressed page
if applicable. */
UNIV_INLINE
page_zip_des_t*
buf_block_get_page_zip(
/*===================*/
/* out: compressed page descriptor, or NULL */
buf_block_t* block) /* in: pointer to the control block */
__attribute((pure));
#define buf_block_get_page_zip(block) \
(UNIV_LIKELY_NULL((block)->page.zip.data) ? &(block)->page.zip : NULL)
#if defined UNIV_DEBUG || defined UNIV_ZIP_DEBUG
/***********************************************************************
Gets the block to whose frame the pointer is pointing to. */
UNIV_INLINE
buf_block_t*
const buf_block_t*
buf_block_align(
/*============*/
/* out: pointer to block */
byte* ptr); /* in: pointer to a frame */
const byte* ptr); /* in: pointer to a frame */
/*************************************************************************
Gets the compressed page descriptor corresponding to an uncompressed page
if applicable. */
UNIV_INLINE
page_zip_des_t*
const page_zip_des_t*
buf_frame_get_page_zip(
/*===================*/
/* out: compressed page descriptor, or NULL */
byte* ptr) /* in: pointer to the page */
__attribute((pure));
const byte* ptr); /* in: pointer to the page */
#endif /* UNIV_DEBUG || UNIV_ZIP_DEBUG */
/************************************************************************
This function is used to get info if there is an io operation
......
......@@ -598,41 +598,24 @@ buf_block_get_zip_size(
return(block->page.zip.ssize ? 512 << block->page.zip.ssize : 0);
}
/*************************************************************************
Gets the compressed page descriptor corresponding to an uncompressed page
if applicable. */
UNIV_INLINE
page_zip_des_t*
buf_block_get_page_zip(
/*===================*/
/* out: compressed page descriptor, or NULL */
buf_block_t* block) /* in: pointer to the control block */
{
if (UNIV_LIKELY_NULL(block->page.zip.data)) {
return(&block->page.zip);
}
return(NULL);
}
#if defined UNIV_DEBUG || defined UNIV_ZIP_DEBUG
/***********************************************************************
Gets the block to whose frame the pointer is pointing to. */
UNIV_INLINE
buf_block_t*
const buf_block_t*
buf_block_align(
/*============*/
/* out: pointer to block */
byte* ptr) /* in: pointer to a frame */
const byte* ptr) /* in: pointer to a frame */
{
buf_block_t* block;
const buf_block_t* block;
ulint space_id, page_no;
ptr = ut_align_down(ptr, UNIV_PAGE_SIZE);
page_no = mach_read_from_4(ptr + FIL_PAGE_OFFSET);
space_id = mach_read_from_4(ptr + FIL_PAGE_ARCH_LOG_NO_OR_SPACE_ID);
block = (buf_block_t*) buf_page_hash_get(space_id, page_no);
block = (const buf_block_t*) buf_page_hash_get(space_id, page_no);
ut_ad(block);
ut_ad(buf_block_get_state(block) == BUF_BLOCK_FILE_PAGE);
ut_ad(block->frame == ptr);
......@@ -643,11 +626,11 @@ buf_block_align(
Gets the compressed page descriptor corresponding to an uncompressed page
if applicable. */
UNIV_INLINE
page_zip_des_t*
const page_zip_des_t*
buf_frame_get_page_zip(
/*===================*/
/* out: compressed page descriptor, or NULL */
byte* ptr) /* in: pointer to the page */
const byte* ptr) /* in: pointer to the page */
{
page_zip_des_t* page_zip;
mutex_enter(&buf_pool->mutex);
......@@ -668,7 +651,7 @@ buf_ptr_get_fsp_addr(
ulint* space, /* out: space id */
fil_addr_t* addr) /* out: page offset and byte offset */
{
const page_t* page = (const page_t*) ut_align_down((void*) ptr,
const page_t* page = (const page_t*) ut_align_down(ptr,
UNIV_PAGE_SIZE);
*space = mach_read_from_4(page + FIL_PAGE_ARCH_LOG_NO_OR_SPACE_ID);
......
......@@ -62,9 +62,9 @@ type and four-byte space and page numbers. */
void
mlog_write_initial_log_record(
/*==========================*/
byte* ptr, /* in: pointer to (inside) a buffer frame
holding the file page where modification
is made */
const byte* ptr, /* in: pointer to (inside) a buffer
frame holding the file page where
modification is made */
byte type, /* in: log item type: MLOG_1BYTE, ... */
mtr_t* mtr); /* in: mini-transaction handle */
/************************************************************
......@@ -141,10 +141,12 @@ byte*
mlog_write_initial_log_record_fast(
/*===============================*/
/* out: new value of log_ptr */
byte* ptr, /* in: pointer to (inside) a buffer frame holding the
file page where modification is made */
const byte* ptr, /* in: pointer to (inside) a buffer
frame holding the file page where
modification is made */
byte type, /* in: log item type: MLOG_1BYTE, ... */
byte* log_ptr,/* in: pointer to mtr log which has been opened */
byte* log_ptr,/* in: pointer to mtr log which has
been opened */
mtr_t* mtr); /* in: mtr */
/************************************************************
Parses an initial log record written by mlog_write_initial_log_record. */
......
......@@ -154,10 +154,12 @@ byte*
mlog_write_initial_log_record_fast(
/*===============================*/
/* out: new value of log_ptr */
byte* ptr, /* in: pointer to (inside) a buffer frame holding the
file page where modification is made */
const byte* ptr, /* in: pointer to (inside) a buffer
frame holding the file page where
modification is made */
byte type, /* in: log item type: MLOG_1BYTE, ... */
byte* log_ptr,/* in: pointer to mtr log which has been opened */
byte* log_ptr,/* in: pointer to mtr log which has
been opened */
mtr_t* mtr) /* in: mtr */
{
#ifdef UNIV_DEBUG
......@@ -191,7 +193,7 @@ mlog_write_initial_log_record_fast(
#ifdef UNIV_DEBUG
mutex_enter(&buf_pool->mutex);
/* We now assume that all x-latched pages have been modified! */
block = buf_block_align(ptr);
block = (buf_block_t*) buf_block_align(ptr);
mutex_exit(&buf_pool->mutex);
if (!mtr_memo_contains(mtr, block, MTR_MEMO_MODIFY)) {
......
......@@ -274,7 +274,7 @@ mtr_memo_contains(
/*==============*/
/* out: TRUE if contains */
mtr_t* mtr, /* in: mtr */
void* object, /* in: object to search */
const void* object, /* in: object to search */
ulint type); /* in: type of object */
/**************************************************************
......
......@@ -122,7 +122,7 @@ mtr_memo_contains(
/*==============*/
/* out: TRUE if contains */
mtr_t* mtr, /* in: mtr */
void* object, /* in: object to search */
const void* object, /* in: object to search */
ulint type) /* in: type of object */
{
mtr_memo_slot_t* slot;
......
......@@ -147,7 +147,7 @@ page_t*
page_align(
/*=======*/
/* out: start of the page */
void* ptr) /* in: pointer to page frame */
const void* ptr) /* in: pointer to page frame */
__attribute__((const));
/****************************************************************
Gets the offset within a page. */
......@@ -205,14 +205,22 @@ page_header_set_field(
ulint field, /* in: PAGE_N_DIR_SLOTS, ... */
ulint val); /* in: value */
/*****************************************************************
Returns the pointer stored in the given header field. */
Returns the offset stored in the given header field. */
UNIV_INLINE
byte*
page_header_get_ptr(
/*================*/
/* out: pointer or NULL */
page_t* page, /* in: page */
ulint field); /* in: PAGE_FREE, ... */
ulint
page_header_get_offs(
/*=================*/
/* out: offset from the start of the page,
or 0 */
const page_t* page, /* in: page */
ulint field) /* in: PAGE_FREE, ... */
__attribute__((nonnull, pure));
/*****************************************************************
Returns the pointer stored in the given header field, or NULL. */
#define page_header_get_ptr(page, field) \
(page_header_get_offs(page, field) \
? page + page_header_get_offs(page, field) : NULL)
/*****************************************************************
Sets the pointer stored in the given header field. */
UNIV_INLINE
......
......@@ -23,7 +23,7 @@ page_t*
page_align(
/*=======*/
/* out: start of the page */
void* ptr) /* in: pointer to page frame */
const void* ptr) /* in: pointer to page frame */
{
return((page_t*) ut_align_down(ptr, UNIV_PAGE_SIZE));
}
......@@ -112,13 +112,14 @@ page_header_set_field(
}
/*****************************************************************
Returns the pointer stored in the given header field. */
Returns the offset stored in the given header field. */
UNIV_INLINE
byte*
page_header_get_ptr(
/*================*/
/* out: pointer or NULL */
page_t* page, /* in: page */
ulint
page_header_get_offs(
/*=================*/
/* out: offset from the start of the page,
or 0 */
const page_t* page, /* in: page */
ulint field) /* in: PAGE_FREE, ... */
{
ulint offs;
......@@ -132,12 +133,7 @@ page_header_get_ptr(
ut_ad((field != PAGE_HEAP_TOP) || offs);
if (offs == 0) {
return(NULL);
}
return(page + offs);
return(offs);
}
/*****************************************************************
......@@ -218,7 +214,7 @@ page_rec_is_comp(
/* out: nonzero if in compact format */
const rec_t* rec) /* in: record */
{
return(page_is_comp(page_align((rec_t*) rec)));
return(page_is_comp(page_align(rec)));
}
/*******************************************************************
......@@ -562,7 +558,7 @@ page_rec_check(
/* out: TRUE if succeed */
const rec_t* rec) /* in: record */
{
const page_t* page = page_align((rec_t*) rec);
const page_t* page = page_align(rec);
ut_a(rec);
......@@ -862,9 +858,10 @@ page_mem_alloc_free(
ulint garbage;
#ifdef UNIV_DEBUG
rec_t* old_rec = page_header_get_ptr(page, PAGE_FREE);
const rec_t* old_rec = page_header_get_ptr(page, PAGE_FREE);
ut_ad(old_rec);
ut_ad(next_rec == rec_get_next_ptr(old_rec, page_is_comp(page)));
ut_ad(next_rec == page + rec_get_next_offs(old_rec,
page_is_comp(page)));
#endif
page_header_set_ptr(page, page_zip, PAGE_FREE, next_rec);
......
......@@ -350,7 +350,7 @@ page_zip_write_header(
{
ulint pos;
ut_ad(buf_frame_get_page_zip((byte*)str) == page_zip);
ut_ad(buf_frame_get_page_zip(str) == page_zip);
ut_ad(page_zip_simple_validate(page_zip));
pos = page_offset(str);
......
......@@ -227,7 +227,7 @@ void*
ut_align_down(
/*==========*/
/* out: aligned pointer */
void* ptr, /* in: pointer */
const void* ptr, /* in: pointer */
ulint align_no) /* in: align by this number */
__attribute__((const));
/*************************************************************
......
......@@ -359,7 +359,7 @@ void*
ut_align_down(
/*==========*/
/* out: aligned pointer */
void* ptr, /* in: pointer */
const void* ptr, /* in: pointer */
ulint align_no) /* in: align by this number */
{
ut_ad(align_no > 0);
......
......@@ -573,7 +573,7 @@ lock_sec_rec_cons_read_sees(
return(FALSE);
}
max_trx_id = page_get_max_trx_id(page_align((rec_t*) rec));
max_trx_id = page_get_max_trx_id(page_align(rec));
return(ut_dulint_cmp(max_trx_id, view->up_limit_id) < 0);
}
......@@ -1322,10 +1322,10 @@ lock_rec_get_prev(
const lock_t* in_lock,/* in: record lock */
ulint heap_no)/* in: heap number of the record */
{
const lock_t* lock;
lock_t* lock;
ulint space;
ulint page_no;
const lock_t* found_lock = NULL;
lock_t* found_lock = NULL;
ut_ad(mutex_own(&kernel_mutex));
ut_ad(lock_get_type_low(in_lock) == LOCK_REC);
......@@ -1348,7 +1348,7 @@ lock_rec_get_prev(
found_lock = lock;
}
lock = lock_rec_get_next_on_page((lock_t*) lock);
lock = lock_rec_get_next_on_page(lock);
}
}
......@@ -1586,7 +1586,7 @@ lock_sec_rec_some_has_impl_off_kernel(
dict_index_t* index, /* in: secondary index */
const ulint* offsets)/* in: rec_get_offsets(rec, index) */
{
const page_t* page = page_align((rec_t*) rec);
const page_t* page = page_align(rec);
ut_ad(mutex_own(&kernel_mutex));
ut_ad(!dict_index_is_clust(index));
......@@ -2774,8 +2774,8 @@ lock_move_rec_list_start(
lock_t* lock;
const ulint comp = page_rec_is_comp(rec);
ut_ad(block->frame == page_align((rec_t*) rec));
ut_ad(new_block->frame == page_align((rec_t*) old_end));
ut_ad(block->frame == page_align(rec));
ut_ad(new_block->frame == page_align(old_end));
lock_mutex_enter_kernel();
......@@ -3014,7 +3014,7 @@ lock_update_merge_left(
{
const rec_t* left_next_rec;
ut_ad(left_block->frame == page_align((rec_t*) orig_pred));
ut_ad(left_block->frame == page_align(orig_pred));
lock_mutex_enter_kernel();
......@@ -3149,7 +3149,7 @@ lock_update_insert(
ulint receiver_heap_no;
ulint donator_heap_no;
ut_ad(block->frame == page_align((rec_t*) rec));
ut_ad(block->frame == page_align(rec));
/* Inherit the gap-locking locks for rec, in gap mode, from the next
record */
......@@ -3228,7 +3228,7 @@ lock_rec_store_on_page_infimum(
{
ulint heap_no = page_rec_get_heap_no(rec);
ut_ad(block->frame == page_align((rec_t*) rec));
ut_ad(block->frame == page_align(rec));
lock_mutex_enter_kernel();
......@@ -3899,7 +3899,7 @@ lock_rec_unlock(
ulint heap_no;
ut_ad(trx && rec);
ut_ad(block->frame == page_align((rec_t*) rec));
ut_ad(block->frame == page_align(rec));
heap_no = page_rec_get_heap_no(rec);
......@@ -4569,7 +4569,7 @@ lock_rec_queue_validate(
ulint heap_no;
ut_a(rec);
ut_a(block->frame == page_align((rec_t*) rec));
ut_a(block->frame == page_align(rec));
ut_ad(rec_offs_validate(rec, index, offsets));
ut_ad(!page_rec_is_comp(rec) == !rec_offs_comp(offsets));
......@@ -5044,7 +5044,7 @@ lock_clust_rec_modify_check_and_lock(
ut_ad(rec_offs_validate(rec, index, offsets));
ut_ad(dict_index_is_clust(index));
ut_ad(block->frame == page_align((rec_t*) rec));
ut_ad(block->frame == page_align(rec));
if (flags & BTR_NO_LOCKING_FLAG) {
......@@ -5179,7 +5179,7 @@ lock_sec_rec_read_check_and_lock(
ulint heap_no;
ut_ad(!dict_index_is_clust(index));
ut_ad(block->frame == page_align((rec_t*) rec));
ut_ad(block->frame == page_align(rec));
ut_ad(page_rec_is_user_rec(rec) || page_rec_is_supremum(rec));
ut_ad(rec_offs_validate(rec, index, offsets));
......@@ -5255,7 +5255,7 @@ lock_clust_rec_read_check_and_lock(
ulint heap_no;
ut_ad(dict_index_is_clust(index));
ut_ad(block->frame == page_align((rec_t*) rec));
ut_ad(block->frame == page_align(rec));
ut_ad(page_rec_is_user_rec(rec) || page_rec_is_supremum(rec));
ut_ad(gap_mode == LOCK_ORDINARY || gap_mode == LOCK_GAP
|| gap_mode == LOCK_REC_NOT_GAP);
......
......@@ -47,8 +47,9 @@ to the mtr memo that a buffer page has been modified. */
void
mlog_write_initial_log_record(
/*==========================*/
byte* ptr, /* in: pointer to (inside) a buffer frame holding the
file page where modification is made */
const byte* ptr, /* in: pointer to (inside) a buffer
frame holding the file page where
modification is made */
byte type, /* in: log item type: MLOG_1BYTE, ... */
mtr_t* mtr) /* in: mini-transaction handle */
{
......
......@@ -315,7 +315,7 @@ mtr_memo_contains_page(
ibool ret;
mutex_enter(&buf_pool->mutex);
ret = mtr_memo_contains(mtr, buf_block_align((byte*) ptr), type);
ret = mtr_memo_contains(mtr, buf_block_align(ptr), type);
mutex_exit(&buf_pool->mutex);
return(ret);
}
......
......@@ -478,15 +478,17 @@ page_create_zip(
mtr_t* mtr) /* in: mini-transaction handle */
{
page_t* page;
page_zip_des_t* page_zip = buf_block_get_page_zip(block);
ut_ad(block && buf_block_get_page_zip(block) && index);
ut_ad(block);
ut_ad(page_zip);
ut_ad(index);
ut_ad(dict_table_is_comp(index->table));
page = page_create_low(block, TRUE);
mach_write_to_2(page + PAGE_HEADER + PAGE_LEVEL, level);
if (UNIV_UNLIKELY(!page_zip_compress(buf_block_get_page_zip(block),
page, index, mtr))) {
if (UNIV_UNLIKELY(!page_zip_compress(page_zip, page, index, mtr))) {
/* The compression of a newly created page
should always succeed. */
ut_error;
......
......@@ -279,7 +279,7 @@ page_zip_get_n_prev_extern(
on a B-tree leaf page */
dict_index_t* index) /* in: record descriptor */
{
const page_t* page = page_align((rec_t*) rec);
const page_t* page = page_align(rec);
ulint n_ext = 0;
ulint i;
ulint left;
......@@ -2848,7 +2848,7 @@ page_zip_write_rec(
ulint heap_no;
byte* slot;
ut_ad(buf_frame_get_page_zip((byte*) rec) == page_zip);
ut_ad(buf_frame_get_page_zip(rec) == page_zip);
ut_ad(page_zip_simple_validate(page_zip));
ut_ad(page_zip_get_size(page_zip)
> PAGE_DATA + page_zip_dir_size(page_zip));
......@@ -2857,7 +2857,7 @@ page_zip_write_rec(
ut_ad(page_zip->m_start >= PAGE_DATA);
page = page_align((rec_t*) rec);
page = page_align(rec);
ut_ad(page_zip_header_cmp(page_zip, page));
ut_ad(page_simple_validate_new((page_t*) page));
......@@ -2895,7 +2895,7 @@ page_zip_write_rec(
ut_ad(!*data);
{
const byte* start = rec_get_start((rec_t*) rec, offsets);
const byte* start = rec - rec_offs_extra_size(offsets);
const byte* b = rec - REC_N_NEW_EXTRA_BYTES;
/* Write the extra bytes backwards, so that
......@@ -3010,7 +3010,7 @@ page_zip_write_rec(
page_zip->m_nonempty = TRUE;
#ifdef UNIV_ZIP_DEBUG
ut_a(page_zip_validate(page_zip, page_align((byte*) rec)));
ut_a(page_zip_validate(page_zip, page_align(rec)));
#endif /* UNIV_ZIP_DEBUG */
}
......@@ -3091,12 +3091,12 @@ page_zip_write_blob_ptr(
{
const byte* field;
byte* externs;
page_t* page = page_align((byte*) rec);
const page_t* page = page_align(rec);
ulint blob_no;
ulint len;
ut_ad(buf_frame_get_page_zip((byte*) rec) == page_zip);
ut_ad(page_simple_validate_new(page));
ut_ad(buf_frame_get_page_zip(rec) == page_zip);
ut_ad(page_simple_validate_new((page_t*) page));
ut_ad(page_zip_simple_validate(page_zip));
ut_ad(page_zip_get_size(page_zip)
> PAGE_DATA + page_zip_dir_size(page_zip));
......@@ -3128,7 +3128,7 @@ page_zip_write_blob_ptr(
memcpy(externs, field, BTR_EXTERN_FIELD_REF_SIZE);
#ifdef UNIV_ZIP_DEBUG
ut_a(page_zip_validate(page_zip, page_align((rec_t*) rec)));
ut_a(page_zip_validate(page_zip, page));
#endif /* UNIV_ZIP_DEBUG */
if (mtr) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment