Commit 8bed4c4c authored by marko's avatar marko

branches/zip: Do not access the fields of dfield_t directly.

dfield_dup(): New function for duplicating the data pointed to by dfield_t.

dfield_set_len(), dfield_set_data(): Add Valgrind instrumentation.
parent e101c352
......@@ -40,7 +40,7 @@ dfield_data_is_binary_equal(
ulint len, /* in: data length or UNIV_SQL_NULL */
const byte* data) /* in: data */
{
if (len != field->len) {
if (len != dfield_get_len(field)) {
return(FALSE);
}
......@@ -50,7 +50,7 @@ dfield_data_is_binary_equal(
return(TRUE);
}
if (0 != ut_memcmp(field->data, data, len)) {
if (0 != memcmp(dfield_get_data(field), data, len)) {
return(FALSE);
}
......@@ -251,7 +251,7 @@ dtuple_validate(
if (!dfield_is_null(field)) {
data = field->data;
data = dfield_get_data(field);
UNIV_MEM_ASSERT_RW(data, len);
for (j = 0; j < len; j++) {
......@@ -493,10 +493,10 @@ dfield_print_raw(
FILE* f, /* in: output stream */
const dfield_t* dfield) /* in: dfield */
{
ulint len = dfield->len;
ulint len = dfield_get_len(dfield);
if (!dfield_is_null(dfield)) {
ulint print_len = ut_min(len, 1000);
ut_print_buf(f, dfield->data, print_len);
ut_print_buf(f, dfield_get_data(dfield), print_len);
if (len != print_len) {
fprintf(f, "(total %lu bytes%s)",
(ulong) len,
......@@ -614,11 +614,13 @@ dtuple_convert_big_rec(
if (ifield->fixed_len
|| dfield_is_null(dfield)
|| dfield_is_ext(dfield)
|| dfield->len <= BTR_EXTERN_FIELD_REF_SIZE * 2) {
|| dfield_get_len(dfield)
<= BTR_EXTERN_FIELD_REF_SIZE * 2) {
goto skip_field;
}
savings = dfield->len - BTR_EXTERN_FIELD_REF_SIZE;
savings = dfield_get_len(dfield)
- BTR_EXTERN_FIELD_REF_SIZE;
/* Check that there would be savings */
if (longest >= savings) {
......@@ -650,9 +652,9 @@ dtuple_convert_big_rec(
ifield = dict_index_get_nth_field(index, longest_i);
vector->fields[n_fields].field_no = longest_i;
vector->fields[n_fields].len = dfield->len;
vector->fields[n_fields].len = dfield_get_len(dfield);
vector->fields[n_fields].data = dfield->data;
vector->fields[n_fields].data = dfield_get_data(dfield);
/* Set the extern field reference in dfield to zero */
dfield_set_data(dfield,
......
......@@ -3729,7 +3729,7 @@ calc_row_difference(
from the MySQL column format to the InnoDB format */
dict_col_copy_type(prebuilt->table->cols + i,
&dfield.type);
dfield_get_type(&dfield));
if (n_len != UNIV_SQL_NULL) {
buf = row_mysql_store_col_in_innobase_format(
......
......@@ -1525,12 +1525,13 @@ ibuf_entry_build(
#ifdef UNIV_DEBUG
if (fixed_len) {
/* dict_index_add_col() should guarantee these */
ut_ad(fixed_len <= (ulint) entry_field->type.len);
ut_ad(fixed_len <= (ulint)
dfield_get_type(entry_field)->len);
if (ifield->prefix_len) {
ut_ad(ifield->prefix_len == fixed_len);
} else {
ut_ad(fixed_len
== (ulint) entry_field->type.len);
ut_ad(fixed_len == (ulint)
dfield_get_type(entry_field)->len);
}
}
#endif /* UNIV_DEBUG */
......
......@@ -128,6 +128,14 @@ dfield_copy(
dfield_t* field1, /* out: field to copy to */
const dfield_t* field2);/* in: field to copy from */
/*************************************************************************
Copies the data pointed to by a data field. */
UNIV_INLINE
void
dfield_dup(
/*=======*/
dfield_t* field, /* in/out: data field */
mem_heap_t* heap); /* in: memory heap where allocated */
/*************************************************************************
Tests if data length and content is equal for two dfields. */
UNIV_INLINE
ibool
......
......@@ -86,6 +86,9 @@ dfield_set_len(
ulint len) /* in: length or UNIV_SQL_NULL */
{
ut_ad(field);
#ifdef UNIV_VALGRIND_DEBUG
if (len != UNIV_SQL_NULL) UNIV_MEM_ASSERT_RW(field->data, len);
#endif /* UNIV_VALGRIND_DEBUG */
field->ext = 0;
field->len = len;
......@@ -144,6 +147,9 @@ dfield_set_data(
{
ut_ad(field);
#ifdef UNIV_VALGRIND_DEBUG
if (len != UNIV_SQL_NULL) UNIV_MEM_ASSERT_RW(data, len);
#endif /* UNIV_VALGRIND_DEBUG */
field->data = (void*) data;
field->ext = 0;
field->len = len;
......@@ -188,6 +194,21 @@ dfield_copy(
*field1 = *field2;
}
/*************************************************************************
Copies the data pointed to by a data field. */
UNIV_INLINE
void
dfield_dup(
/*=======*/
dfield_t* field, /* in/out: data field */
mem_heap_t* heap) /* in: memory heap where allocated */
{
if (!dfield_is_null(field)) {
UNIV_MEM_ASSERT_RW(field->data, field->len);
field->data = mem_heap_dup(heap, field->data, field->len);
}
}
/*************************************************************************
Tests if data length and content is equal for two dfields. */
UNIV_INLINE
......@@ -202,15 +223,9 @@ dfield_datas_are_binary_equal(
len = field1->len;
if ((len != field2->len)
|| ((len != UNIV_SQL_NULL)
&& (0 != ut_memcmp(field1->data, field2->data,
len)))) {
return(FALSE);
}
return(TRUE);
return(len == field2->len
&& (len == UNIV_SQL_NULL
|| !memcmp(field1->data, field2->data, len)));
}
/*************************************************************************
......
......@@ -126,7 +126,7 @@ que_node_get_data_type(
{
ut_ad(node);
return(&(((que_common_t*)node)->val.type));
return(dfield_get_type(&((que_common_t*) node)->val));
}
/*************************************************************************
......
......@@ -102,7 +102,7 @@ sym_tab_add_int_lit(
node->indirection = NULL;
dtype_set(&(node->common.val.type), DATA_INT, 0, 4);
dtype_set(dfield_get_type(&node->common.val), DATA_INT, 0, 4);
data = mem_heap_alloc(sym_tab->heap, 4);
mach_write_to_4(data, val);
......@@ -144,7 +144,8 @@ sym_tab_add_str_lit(
node->indirection = NULL;
dtype_set(&(node->common.val.type), DATA_VARCHAR, DATA_ENGLISH, 0);
dtype_set(dfield_get_type(&node->common.val),
DATA_VARCHAR, DATA_ENGLISH, 0);
if (len) {
data = mem_heap_alloc(sym_tab->heap, len);
......@@ -226,7 +227,8 @@ sym_tab_add_bound_lit(
ut_error;
}
dtype_set(&(node->common.val.type), blit->type, blit->prtype, len);
dtype_set(dfield_get_type(&node->common.val),
blit->type, blit->prtype, len);
dfield_set_data(&(node->common.val), blit->address, blit->length);
......@@ -261,7 +263,7 @@ sym_tab_add_null_lit(
node->indirection = NULL;
node->common.val.type.mtype = DATA_ERROR;
dfield_get_type(&node->common.val)->mtype = DATA_ERROR;
dfield_set_null(&node->common.val);
......
......@@ -757,7 +757,7 @@ rec_get_converted_size_comp(
case REC_STATUS_NODE_PTR:
n_fields--;
ut_ad(n_fields == dict_index_get_n_unique_in_tree(index));
ut_ad(fields[n_fields].len == 4);
ut_ad(dfield_get_len(&fields[n_fields]) == 4);
data_size = 4; /* child page number */
break;
case REC_STATUS_INFIMUM:
......
......@@ -475,6 +475,7 @@ row_ins_cascade_calc_update_vec(
ulint min_size;
const dict_col_t* col;
ulint ufield_len;
col = dict_index_get_nth_col(index, i);
......@@ -490,7 +491,10 @@ row_ins_cascade_calc_update_vec(
ufield->exp = NULL;
ufield->new_val = parent_ufield->new_val;
ufield->new_val.ext = 0;
ufield_len = dfield_get_len(&ufield->new_val);
/* Clear the "external storage" flag */
dfield_set_len(&ufield->new_val, ufield_len);
/* Do not allow a NOT NULL column to be
updated as NULL */
......@@ -509,9 +513,9 @@ row_ins_cascade_calc_update_vec(
col->prtype,
col->mbminlen, col->mbmaxlen,
col->len,
ufield->new_val.len,
ufield->new_val.data)
< ufield->new_val.len) {
ufield_len,
dfield_get_data(&ufield->new_val))
< ufield_len) {
return(ULINT_UNDEFINED);
}
......@@ -523,28 +527,31 @@ row_ins_cascade_calc_update_vec(
min_size = dict_col_get_min_size(col);
if (min_size
&& !dfield_is_null(&ufield->new_val)
&& ufield->new_val.len < min_size) {
/* Because UNIV_SQL_NULL (the marker
of SQL NULL values) exceeds all possible
values of min_size, the test below will
not hold for SQL NULL columns. */
if (min_size > ufield_len) {
char* pad_start;
const char* pad_end;
ufield->new_val.data = mem_heap_alloc(
heap, min_size);
pad_start = ((char*) ufield
->new_val.data)
+ ufield->new_val.len;
pad_end = ((char*) ufield
->new_val.data)
+ min_size;
ufield->new_val.len = min_size;
ut_memcpy(ufield->new_val.data,
parent_ufield->new_val.data,
parent_ufield->new_val.len);
char* padded_data
= mem_heap_alloc(
heap, min_size);
pad_start = padded_data + ufield_len;
pad_end = padded_data + min_size;
memcpy(padded_data,
dfield_get_data(&ufield
->new_val),
dfield_get_len(&ufield
->new_val));
switch (UNIV_EXPECT(col->mbminlen,1)) {
default:
ut_error;
return(ULINT_UNDEFINED);
case 1:
if (UNIV_UNLIKELY
(dtype_get_charset_coll(
......@@ -561,8 +568,7 @@ row_ins_cascade_calc_update_vec(
break;
case 2:
/* space=0x0020 */
ut_a(!(ufield->new_val.len
% 2));
ut_a(!(ufield_len % 2));
ut_a(!(min_size % 2));
do {
*pad_start++ = 0x00;
......@@ -570,6 +576,9 @@ row_ins_cascade_calc_update_vec(
} while (pad_start < pad_end);
break;
}
dfield_set_data(&ufield->new_val,
padded_data, min_size);
}
n_fields_updated++;
......@@ -2234,10 +2243,12 @@ row_ins_index_entry_set_vals(
len = dtype_get_at_most_n_mbchars(
col->prtype, col->mbminlen, col->mbmaxlen,
ind_field->prefix_len,
len, row_field->data);
len, dfield_get_data(row_field));
ut_ad(!dfield_is_ext(row_field));
}
dfield_set_data(field, row_field->data, len);
dfield_set_data(field, dfield_get_data(row_field), len);
if (dfield_is_ext(row_field)) {
ut_ad(dict_index_is_clust(index));
dfield_set_ext(field);
......
......@@ -113,16 +113,16 @@ row_merge_tuple_print(
if (dfield_is_null(field)) {
fputs("\n NULL;", f);
} else {
ulint len = ut_min(field->len, 20);
ulint field_len = dfield_get_len(field);
ulint len = ut_min(field_len, 20);
if (dfield_is_ext(field)) {
fputs("\nE", f);
} else {
fputs("\n ", f);
}
ut_print_buf(f, field->data, len);
if (len != field->len) {
fprintf(f, " (total %lu bytes)",
(ulong) field->len);
ut_print_buf(f, dfield_get_data(field), len);
if (len != field_len) {
fprintf(f, " (total %lu bytes)", field_len);
}
}
}
......@@ -261,34 +261,36 @@ row_merge_buf_add(
ulint col_no;
const dfield_t* row_field;
ulint len;
const void* field_data;
ifield = dict_index_get_nth_field(index, i);
col = ifield->col;
col_no = dict_col_get_no(col);
row_field = dtuple_get_nth_field(row, col_no);
dfield_copy(field, row_field);
len = field->len;
len = dfield_get_len(field);
field_data = dfield_get_data(field);
if (dfield_is_null(field)) {
ut_ad(!(col->prtype & DATA_NOT_NULL));
field->data = NULL;
ut_ad(field_data == NULL);
continue;
} else if (UNIV_LIKELY(!ext)) {
} else if (dict_index_is_clust(index)) {
/* Flag externally stored fields. */
byte* buf = row_ext_lookup(ext, col_no,
field->data, len, &len);
field_data, len, &len);
if (UNIV_LIKELY_NULL(buf)) {
if (i < dict_index_get_n_unique(index)) {
dfield_set_data(field, buf, len);
} else {
dfield_set_ext(field);
len = field->len;
len = dfield_get_len(field);
}
}
} else {
byte* buf = row_ext_lookup(ext, col_no,
field->data, len, &len);
field_data, len, &len);
if (UNIV_LIKELY_NULL(buf)) {
dfield_set_data(field, buf, len);
}
......@@ -297,11 +299,12 @@ row_merge_buf_add(
/* If a column prefix index, take only the prefix */
if (ifield->prefix_len) {
field->len = len = dtype_get_at_most_n_mbchars(
len = dtype_get_at_most_n_mbchars(
col->prtype,
col->mbminlen, col->mbmaxlen,
ifield->prefix_len,
len, field->data);
len, dfield_get_data(field));
dfield_set_len(field, len);
}
ut_ad(len <= col->len || col->mtype == DATA_BLOB);
......@@ -365,12 +368,7 @@ row_merge_buf_add(
/* Copy the data fields. */
do {
if (!dfield_is_null(field)) {
field->data = mem_heap_dup(buf->heap,
field->data, field->len);
}
field++;
dfield_dup(field++, buf->heap);
} while (--n_fields);
return(TRUE);
......@@ -1163,8 +1161,10 @@ row_merge_read_clustered_index(
for (i = 0; i < n_nonnull; i++) {
dfield_t* field
= &row->fields[nonnull[i]];
dtype_t* field_type
= dfield_get_type(field);
ut_a(!(field->type.prtype
ut_a(!(field_type->prtype
& DATA_NOT_NULL));
if (dfield_is_null(field)) {
......@@ -1173,7 +1173,7 @@ row_merge_read_clustered_index(
goto err_exit;
}
field->type.prtype |= DATA_NOT_NULL;
field_type->prtype |= DATA_NOT_NULL;
}
}
}
......
......@@ -414,7 +414,9 @@ row_purge_upd_exist_or_extern(
can calculate from node->roll_ptr the file
address of the new_val data */
internal_offset = ((const byte*)ufield->new_val.data)
internal_offset
= ((const byte*)
dfield_get_data(&ufield->new_val))
- node->undo_rec;
ut_a(internal_offset < UNIV_PAGE_SIZE);
......@@ -452,9 +454,11 @@ row_purge_upd_exist_or_extern(
data_field = buf_block_get_frame(block)
+ offset + internal_offset;
ut_a(ufield->new_val.len >= BTR_EXTERN_FIELD_REF_SIZE);
ut_a(dfield_get_len(&ufield->new_val)
>= BTR_EXTERN_FIELD_REF_SIZE);
btr_free_externally_stored_field(
index, data_field + ufield->new_val.len
index,
data_field + dfield_get_len(&ufield->new_val)
- BTR_EXTERN_FIELD_REF_SIZE,
NULL, NULL, NULL, 0, FALSE, &mtr);
mtr_commit(&mtr);
......
......@@ -75,9 +75,6 @@ row_build_index_entry(
{
dtuple_t* entry;
ulint entry_len;
dict_field_t* ind_field;
dfield_t* dfield;
const dfield_t* dfield2;
ulint i;
ut_ad(row && index && heap);
......@@ -101,24 +98,26 @@ row_build_index_entry(
}
for (i = 0; i < entry_len; i++) {
const dict_col_t* col;
ulint col_no;
ind_field = dict_index_get_nth_field(index, i);
col = ind_field->col;
col_no = dict_col_get_no(col);
dfield = dtuple_get_nth_field(entry, i);
dfield2 = dtuple_get_nth_field(row, col_no);
const dict_field_t* ind_field
= dict_index_get_nth_field(index, i);
const dict_col_t* col
= ind_field->col;
ulint col_no
= dict_col_get_no(col);
dfield_t* dfield
= dtuple_get_nth_field(entry, i);
const dfield_t* dfield2
= dtuple_get_nth_field(row, col_no);
ulint len
= dfield_get_len(dfield);
dfield_copy(dfield, dfield2);
if (UNIV_LIKELY_NULL(ext) && !dfield_is_null(dfield)) {
/* See if the column is stored externally. */
ulint len = dfield_get_len(dfield);
byte* buf = row_ext_lookup(ext, col_no,
dfield->data,
dfield->len, &len);
dfield_get_data(dfield),
len, &len);
if (UNIV_LIKELY_NULL(buf)) {
dfield_set_data(dfield, buf, len);
}
......@@ -126,10 +125,11 @@ row_build_index_entry(
/* If a column prefix index, take only the prefix */
if (ind_field->prefix_len > 0 && !dfield_is_null(dfield)) {
dfield->len = dtype_get_at_most_n_mbchars(
len = dtype_get_at_most_n_mbchars(
col->prtype, col->mbminlen, col->mbmaxlen,
ind_field->prefix_len,
dfield->len, dfield->data);
len, dfield_get_data(dfield));
dfield_set_len(dfield, len);
}
}
......@@ -639,9 +639,14 @@ row_build_row_ref_from_row(
if (field->prefix_len > 0 && !dfield_is_null(dfield)) {
dfield->len = dtype_get_at_most_n_mbchars(
ulint len = dfield_get_len(dfield);
len = dtype_get_at_most_n_mbchars(
col->prtype, col->mbminlen, col->mbmaxlen,
field->prefix_len, dfield->len, dfield->data);
field->prefix_len,
len, dfield_get_data(dfield));
dfield_set_len(dfield, len);
}
}
......
......@@ -2432,7 +2432,9 @@ row_sel_convert_mysql_key_to_innobase(
fprintf(stderr, "\n");
if (!is_null) {
dfield->len -= (ulint)(key_ptr - key_end);
ulint len = dfield_get_len(dfield);
dfield_set_len(dfield, len
- (ulint) (key_ptr - key_end));
}
}
......
......@@ -583,20 +583,22 @@ row_upd_index_write_log(
new_val = &(upd_field->new_val);
len = new_val->len;
len = dfield_get_len(new_val);
log_ptr += mach_write_compressed(log_ptr, upd_field->field_no);
log_ptr += mach_write_compressed(log_ptr, len);
if (len != UNIV_SQL_NULL) {
if (log_ptr + len < buf_end) {
ut_memcpy(log_ptr, new_val->data, len);
memcpy(log_ptr, dfield_get_data(new_val), len);
log_ptr += len;
} else {
mlog_close(mtr, log_ptr);
mlog_catenate_string(mtr, new_val->data, len);
mlog_catenate_string(mtr,
dfield_get_data(new_val),
len);
log_ptr = mlog_open(mtr, MLOG_BUF_MARGIN);
buf_end = log_ptr + MLOG_BUF_MARGIN;
......@@ -887,24 +889,25 @@ row_upd_index_replace_new_col_vals_index_pos(
}
if (heap) {
dfield->data = mem_heap_dup(
heap,
dfield->data, dfield->len);
dfield_dup(dfield, heap);
}
if (field->prefix_len > 0) {
const dict_col_t* col
= dict_field_get_col(field);
dfield->len
= dtype_get_at_most_n_mbchars(
col->prtype,
col->mbminlen,
col->mbmaxlen,
field->prefix_len,
dfield->len,
dfield->data);
ulint len
= dfield_get_len(dfield);
len = dtype_get_at_most_n_mbchars(
col->prtype,
col->mbminlen,
col->mbmaxlen,
field->prefix_len,
len,
dfield_get_data(dfield));
dfield_set_len(dfield, len);
}
}
}
......@@ -962,24 +965,25 @@ row_upd_index_replace_new_col_vals(
}
if (heap) {
dfield->data = mem_heap_dup(
heap,
dfield->data, dfield->len);
dfield_dup(dfield, heap);
}
if (field->prefix_len > 0) {
const dict_col_t* col
= dict_field_get_col(field);
dfield->len
= dtype_get_at_most_n_mbchars(
col->prtype,
col->mbminlen,
col->mbmaxlen,
field->prefix_len,
dfield->len,
dfield->data);
ulint len
= dfield_get_len(dfield);
len = dtype_get_at_most_n_mbchars(
col->prtype,
col->mbminlen,
col->mbmaxlen,
field->prefix_len,
len,
dfield_get_data(dfield));
dfield_set_len(dfield, len);
}
}
}
......
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