Commit e00bf403 authored by marko@hundin.mysql.fi's avatar marko@hundin.mysql.fi

InnoDB cleanup: fixing buffer overflows and quoting of quotes

parent ebc7b6ba
......@@ -37,67 +37,6 @@ static
dtuple_t*
dict_create_sys_tables_tuple(
/*=========================*/
/* out: the tuple which should be inserted */
dict_table_t* table, /* in: table */
mem_heap_t* heap); /* in: memory heap from which the memory for
the built tuple is allocated */
/*********************************************************************
Based on a table object, this function builds the entry to be inserted
in the SYS_COLUMNS system table. */
static
dtuple_t*
dict_create_sys_columns_tuple(
/*==========================*/
/* out: the tuple which should be inserted */
dict_table_t* table, /* in: table */
ulint i, /* in: column number */
mem_heap_t* heap); /* in: memory heap from which the memory for
the built tuple is allocated */
/*********************************************************************
Based on an index object, this function builds the entry to be inserted
in the SYS_INDEXES system table. */
static
dtuple_t*
dict_create_sys_indexes_tuple(
/*==========================*/
/* out: the tuple which should be inserted */
dict_index_t* index, /* in: index */
mem_heap_t* heap, /* in: memory heap from which the memory for
the built tuple is allocated */
trx_t* trx); /* in: transaction handle */
/*********************************************************************
Based on an index object, this function builds the entry to be inserted
in the SYS_FIELDS system table. */
static
dtuple_t*
dict_create_sys_fields_tuple(
/*=========================*/
/* out: the tuple which should be inserted */
dict_index_t* index, /* in: index */
ulint i, /* in: field number */
mem_heap_t* heap); /* in: memory heap from which the memory for
the built tuple is allocated */
/*********************************************************************
Creates the tuple with which the index entry is searched for
writing the index tree root page number, if such a tree is created. */
static
dtuple_t*
dict_create_search_tuple(
/*=====================*/
/* out: the tuple for search */
dtuple_t* tuple, /* in: the tuple inserted in the SYS_INDEXES
table */
mem_heap_t* heap); /* in: memory heap from which the memory for
the built tuple is allocated */
/*********************************************************************
Based on a table object, this function builds the entry to be inserted
in the SYS_TABLES system table. */
static
dtuple_t*
dict_create_sys_tables_tuple(
/*=========================*/
/* out: the tuple which should be inserted */
dict_table_t* table, /* in: table */
mem_heap_t* heap) /* in: memory heap from which the memory for
the built tuple is allocated */
......@@ -331,9 +270,8 @@ dict_create_sys_indexes_tuple(
/*==========================*/
/* out: the tuple which should be inserted */
dict_index_t* index, /* in: index */
mem_heap_t* heap, /* in: memory heap from which the memory for
mem_heap_t* heap) /* in: memory heap from which the memory for
the built tuple is allocated */
trx_t* trx) /* in: transaction handle */
{
dict_table_t* sys_indexes;
dict_table_t* table;
......@@ -341,7 +279,6 @@ dict_create_sys_indexes_tuple(
dfield_t* dfield;
byte* ptr;
UT_NOT_USED(trx);
#ifdef UNIV_SYNC_DEBUG
ut_ad(mutex_own(&(dict_sys->mutex)));
#endif /* UNIV_SYNC_DEBUG */
......@@ -387,7 +324,9 @@ dict_create_sys_indexes_tuple(
dfield_set_data(dfield, ptr, 4);
/* 7: SPACE --------------------------*/
ut_a(DICT_SYS_INDEXES_SPACE_NO_FIELD == 7);
#if DICT_SYS_INDEXES_SPACE_NO_FIELD != 7
#error "DICT_SYS_INDEXES_SPACE_NO_FIELD != 7"
#endif
dfield = dtuple_get_nth_field(entry, 5);
......@@ -397,7 +336,9 @@ dict_create_sys_indexes_tuple(
dfield_set_data(dfield, ptr, 4);
/* 8: PAGE_NO --------------------------*/
ut_a(DICT_SYS_INDEXES_PAGE_NO_FIELD == 8);
#if DICT_SYS_INDEXES_PAGE_NO_FIELD != 8
#error "DICT_SYS_INDEXES_PAGE_NO_FIELD != 8"
#endif
dfield = dtuple_get_nth_field(entry, 6);
......@@ -565,8 +506,7 @@ dict_build_index_def_step(
index->page_no = FIL_NULL;
row = dict_create_sys_indexes_tuple(index, node->heap,
thr_get_trx(thr));
row = dict_create_sys_indexes_tuple(index, node->heap);
node->ind_row = row;
ins_node_set_new_row(node->ind_def, row);
......@@ -602,7 +542,6 @@ ulint
dict_create_index_tree_step(
/*========================*/
/* out: DB_SUCCESS or DB_OUT_OF_FILE_SPACE */
que_thr_t* thr, /* in: query thread */
ind_node_t* node) /* in: index create node */
{
dict_index_t* index;
......@@ -615,7 +554,6 @@ dict_create_index_tree_step(
#ifdef UNIV_SYNC_DEBUG
ut_ad(mutex_own(&(dict_sys->mutex)));
#endif /* UNIV_SYNC_DEBUG */
UT_NOT_USED(thr);
index = node->index;
table = node->table;
......@@ -963,7 +901,7 @@ dict_create_index_step(
if (node->state == INDEX_CREATE_INDEX_TREE) {
err = dict_create_index_tree_step(thr, node);
err = dict_create_index_tree_step(node);
if (err != DB_SUCCESS) {
......@@ -1166,11 +1104,22 @@ dict_create_add_foreigns_to_dictionary(
que_t* graph;
ulint number = start_id + 1;
ulint len;
ulint namelen;
ulint error;
char* ebuf = dict_foreign_err_buf;
ulint i;
char buf[10000];
char* sql;
char* sqlend;
/* This procedure builds an InnoDB stored procedure which will insert
the necessary rows into SYS_FOREIGN and SYS_FOREIGN_COLS. */
static const char str1[] = "PROCEDURE ADD_FOREIGN_DEFS_PROC () IS\n"
"BEGIN\n"
"INSERT INTO SYS_FOREIGN VALUES(";
static const char str2[] = ");\n";
static const char str3[] =
"INSERT INTO SYS_FOREIGN_COLS VALUES(";
static const char str4[] =
"COMMIT WORK;\n"
"END;\n";
#ifdef UNIV_SYNC_DEBUG
ut_ad(mutex_own(&(dict_sys->mutex)));
......@@ -1190,58 +1139,75 @@ dict_create_add_foreigns_to_dictionary(
return(DB_SUCCESS);
}
/* Build an InnoDB stored procedure which will insert the necessary
rows to SYS_FOREIGN and SYS_FOREIGN_COLS */
len = 0;
len += sprintf(buf,
"PROCEDURE ADD_FOREIGN_DEFS_PROC () IS\n"
"BEGIN\n");
namelen = strlen(table->name);
ut_a(namelen < MAX_TABLE_NAME_LEN);
if (foreign->id == NULL) {
/* Generate a new constraint id */
foreign->id = mem_heap_alloc(foreign->heap, namelen + 20);
ulint namelen = strlen(table->name);
char* id = mem_heap_alloc(foreign->heap, namelen + 20);
/* no overflow if number < 1e13 */
sprintf(foreign->id, "%s_ibfk_%lu", table->name, number);
number++;
sprintf(id, "%s_ibfk_%lu", table->name, number++);
foreign->id = id;
}
ut_a(strlen(foreign->id) < MAX_IDENTIFIER_LEN);
ut_a(len < (sizeof buf)
- 46 - 2 * MAX_TABLE_NAME_LEN - MAX_IDENTIFIER_LEN - 20);
len = (sizeof str1) + (sizeof str2) + (sizeof str4) - 3
+ 9/* ' and , chars */ + 10/* 32-bit integer */
+ ut_strlenq(foreign->id, '\'') * (foreign->n_fields + 1)
+ ut_strlenq(table->name, '\'')
+ ut_strlenq(foreign->referenced_table_name, '\'');
for (i = 0; i < foreign->n_fields; i++) {
len += 9/* ' and , chars */ + 10/* 32-bit integer */
+ (sizeof str3) + (sizeof str2) - 2
+ ut_strlenq(foreign->foreign_col_names[i], '\'')
+ ut_strlenq(foreign->referenced_col_names[i], '\'');
}
len += sprintf(buf + len,
"INSERT INTO SYS_FOREIGN VALUES('%s', '%s', '%s', %lu);\n",
foreign->id,
table->name,
foreign->referenced_table_name,
foreign->n_fields
+ (foreign->type << 24));
sql = sqlend = mem_alloc(len + 1);
/* INSERT INTO SYS_FOREIGN VALUES(...); */
memcpy(sqlend, str1, (sizeof str1) - 1);
sqlend += (sizeof str1) - 1;
*sqlend++ = '\'';
sqlend = ut_strcpyq(sqlend, '\'', foreign->id);
*sqlend++ = '\'', *sqlend++ = ',', *sqlend++ = '\'';
sqlend = ut_strcpyq(sqlend, '\'', table->name);
*sqlend++ = '\'', *sqlend++ = ',', *sqlend++ = '\'';
sqlend = ut_strcpyq(sqlend, '\'', foreign->referenced_table_name);
*sqlend++ = '\'', *sqlend++ = ',';
sqlend += sprintf(sqlend, "%010lu",
foreign->n_fields + (foreign->type << 24));
memcpy(sqlend, str2, (sizeof str2) - 1);
sqlend += (sizeof str2) - 1;
for (i = 0; i < foreign->n_fields; i++) {
ut_a(len < (sizeof buf)
- 51 - 2 * MAX_COLUMN_NAME_LEN
- MAX_IDENTIFIER_LEN - 20);
len += sprintf(buf + len,
"INSERT INTO SYS_FOREIGN_COLS VALUES('%s', %lu, '%s', '%s');\n",
foreign->id,
i,
foreign->foreign_col_names[i],
foreign->referenced_col_names[i]);
/* INSERT INTO SYS_FOREIGN_COLS VALUES(...); */
memcpy(sqlend, str3, (sizeof str3) - 1);
sqlend += (sizeof str3) - 1;
*sqlend++ = '\'';
sqlend = ut_strcpyq(sqlend, '\'', foreign->id);
*sqlend++ = '\''; *sqlend++ = ',';
sqlend += sprintf(sqlend, "%010lu", i);
*sqlend++ = ','; *sqlend++ = '\'';
sqlend = ut_strcpyq(sqlend, '\'',
foreign->foreign_col_names[i]);
*sqlend++ = '\''; *sqlend++ = ','; *sqlend++ = '\'';
sqlend = ut_strcpyq(sqlend, '\'',
foreign->referenced_col_names[i]);
*sqlend++ = '\'';
memcpy(sqlend, str2, (sizeof str2) - 1);
sqlend += (sizeof str2) - 1;
}
ut_a(len < (sizeof buf) - 19);
len += sprintf(buf + len,"COMMIT WORK;\nEND;\n");
memcpy(sqlend, str4, sizeof str4);
sqlend += sizeof str4;
graph = pars_sql(buf);
ut_a(sqlend == sql + len + 1);
graph = pars_sql(sql);
ut_a(graph);
mem_free(sql);
graph->trx = trx;
trx->graph = NULL;
......
This diff is collapsed.
......@@ -39,7 +39,6 @@ dict_get_first_table_name_in_db(
rec_t* rec;
byte* field;
ulint len;
char* table_name;
mtr_t mtr;
#ifdef UNIV_SYNC_DEBUG
......@@ -91,9 +90,7 @@ dict_get_first_table_name_in_db(
/* We found one */
table_name = mem_alloc(len + 1);
ut_memcpy(table_name, field, len);
table_name[len] = '\0';
char* table_name = mem_strdupl(field, len);
btr_pcur_close(&pcur);
mtr_commit(&mtr);
......@@ -122,7 +119,6 @@ dict_print(void)
rec_t* rec;
byte* field;
ulint len;
char table_name[10000];
mtr_t mtr;
mutex_enter(&(dict_sys->mutex));
......@@ -156,14 +152,14 @@ dict_print(void)
/* We found one */
ut_memcpy(table_name, field, len);
table_name[len] = '\0';
char* table_name = mem_strdupl(field, len);
btr_pcur_store_position(&pcur, &mtr);
mtr_commit(&mtr);
table = dict_table_get_low(table_name);
mem_free(table_name);
if (table == NULL) {
fprintf(stderr, "InnoDB: Failed to load table %s\n",
......@@ -205,7 +201,6 @@ dict_load_columns(
byte* field;
ulint len;
byte* buf;
char* name_buf;
char* name;
ulint mtype;
ulint prtype;
......@@ -256,12 +251,7 @@ dict_load_columns(
dict_table_get_first_index(sys_columns), 4))->name));
field = rec_get_nth_field(rec, 4, &len);
name_buf = mem_heap_alloc(heap, len + 1);
ut_memcpy(name_buf, field, len);
name_buf[len] = '\0';
name = name_buf;
name = mem_heap_strdupl(heap, field, len);
field = rec_get_nth_field(rec, 5, &len);
mtype = mach_read_from_4(field);
......@@ -304,7 +294,6 @@ dict_load_fields(
btr_pcur_t pcur;
dtuple_t* tuple;
dfield_t* dfield;
char* col_name;
ulint pos_and_prefix_len;
ulint prefix_len;
rec_t* rec;
......@@ -383,11 +372,8 @@ dict_load_fields(
field = rec_get_nth_field(rec, 4, &len);
col_name = mem_heap_alloc(heap, len + 1);
ut_memcpy(col_name, field, len);
col_name[len] = '\0';
dict_mem_index_add_field(index, col_name, 0, prefix_len);
dict_mem_index_add_field(index,
mem_heap_strdupl(heap, field, len), 0, prefix_len);
btr_pcur_move_to_next_user_rec(&pcur, &mtr);
}
......@@ -492,10 +478,7 @@ dict_load_indexes(
dict_table_get_first_index(sys_indexes), 4))->name));
field = rec_get_nth_field(rec, 4, &name_len);
name_buf = mem_heap_alloc(heap, name_len + 1);
ut_memcpy(name_buf, field, name_len);
name_buf[name_len] = '\0';
name_buf = mem_heap_strdupl(heap, field, name_len);
field = rec_get_nth_field(rec, 5, &len);
n_fields = mach_read_from_4(field);
......@@ -544,7 +527,7 @@ dict_load_indexes(
if (is_sys_table
&& ((type & DICT_CLUSTERED)
|| ((table == dict_sys->sys_tables)
&& (name_len == ut_strlen("ID_IND"))
&& (name_len == (sizeof "ID_IND") - 1)
&& (0 == ut_memcmp(name_buf, (char*)"ID_IND",
name_len))))) {
......@@ -593,7 +576,6 @@ dict_load_table(
rec_t* rec;
byte* field;
ulint len;
char* buf;
ulint space;
ulint n_cols;
ulint err;
......@@ -674,15 +656,13 @@ dict_load_table(
if (table->type == DICT_TABLE_CLUSTER_MEMBER) {
ut_error;
#if 0 /* clustered tables have not been implemented yet */
field = rec_get_nth_field(rec, 6, &len);
table->mix_id = mach_read_from_8(field);
field = rec_get_nth_field(rec, 8, &len);
buf = mem_heap_alloc(heap, len);
ut_memcpy(buf, field, len);
table->cluster_name = buf;
table->cluster_name = mem_heap_strdupl(heap, field, len);
#endif
}
if ((table->type == DICT_TABLE_CLUSTER)
......@@ -751,7 +731,6 @@ dict_load_table_on_id(
byte* field;
ulint len;
dict_table_t* table;
char* name;
mtr_t mtr;
#ifdef UNIV_SYNC_DEBUG
......@@ -814,13 +793,8 @@ dict_load_table_on_id(
/* Now we get the table name from the record */
field = rec_get_nth_field(rec, 1, &len);
name = mem_heap_alloc(heap, len + 1);
ut_memcpy(name, field, len);
name[len] = '\0';
/* Load the table definition to memory */
table = dict_load_table(name);
table = dict_load_table(mem_heap_strdupl(heap, field, len));
btr_pcur_close(&pcur);
mtr_commit(&mtr);
......@@ -867,7 +841,6 @@ dict_load_foreign_cols(
btr_pcur_t pcur;
dtuple_t* tuple;
dfield_t* dfield;
char* col_name;
rec_t* rec;
byte* field;
ulint len;
......@@ -912,21 +885,13 @@ dict_load_foreign_cols(
ut_a(i == mach_read_from_4(field));
field = rec_get_nth_field(rec, 4, &len);
col_name = mem_heap_alloc(foreign->heap, len + 1);
ut_memcpy(col_name, field, len);
col_name[len] = '\0';
foreign->foreign_col_names[i] = col_name;
foreign->foreign_col_names[i] =
mem_heap_strdupl(foreign->heap, field, len);
field = rec_get_nth_field(rec, 5, &len);
foreign->referenced_col_names[i] =
mem_heap_strdupl(foreign->heap, field, len);
col_name = mem_heap_alloc(foreign->heap, len + 1);
ut_memcpy(col_name, field, len);
col_name[len] = '\0';
foreign->referenced_col_names[i] = col_name;
btr_pcur_move_to_next_user_rec(&pcur, &mtr);
}
......@@ -1023,23 +988,15 @@ dict_load_foreign(
foreign->type = foreign->n_fields >> 24;
foreign->n_fields = foreign->n_fields & 0xFFFFFF;
foreign->id = mem_heap_alloc(foreign->heap, ut_strlen(id) + 1);
ut_memcpy(foreign->id, id, ut_strlen(id) + 1);
foreign->id = mem_heap_strdup(foreign->heap, id);
field = rec_get_nth_field(rec, 3, &len);
foreign->foreign_table_name = mem_heap_alloc(foreign->heap, 1 + len);
ut_memcpy(foreign->foreign_table_name, field, len);
foreign->foreign_table_name[len] = '\0';
foreign->foreign_table_name =
mem_heap_strdupl(foreign->heap, field, len);
field = rec_get_nth_field(rec, 4, &len);
foreign->referenced_table_name = mem_heap_alloc(foreign->heap,
1 + len);
ut_memcpy(foreign->referenced_table_name, field, len);
foreign->referenced_table_name[len] = '\0';
foreign->referenced_table_name =
mem_heap_strdupl(foreign->heap, field, len);
btr_pcur_close(&pcur);
mtr_commit(&mtr);
......@@ -1153,10 +1110,7 @@ dict_load_foreigns(
/* Now we get a foreign key constraint id */
field = rec_get_nth_field(rec, 1, &len);
id = mem_heap_alloc(heap, len + 1);
ut_memcpy(id, field, len);
id[len] = '\0';
id = mem_heap_strdupl(heap, field, len);
btr_pcur_store_position(&pcur, &mtr);
......
......@@ -49,9 +49,7 @@ dict_mem_table_create(
table->heap = heap;
str = mem_heap_alloc(heap, 1 + ut_strlen(name));
ut_strcpy(str, name);
str = mem_heap_strdup(heap, name);
table->type = DICT_TABLE_ORDINARY;
table->name = str;
......@@ -146,7 +144,6 @@ dict_mem_table_add_col(
ulint len, /* in: length */
ulint prec) /* in: precision */
{
char* str;
dict_col_t* col;
dtype_t* type;
......@@ -154,15 +151,11 @@ dict_mem_table_add_col(
ut_ad(table->magic_n == DICT_TABLE_MAGIC_N);
table->n_def++;
col = dict_table_get_nth_col(table, table->n_def - 1);
str = mem_heap_alloc(table->heap, 1 + ut_strlen(name));
ut_strcpy(str, name);
col = dict_table_get_nth_col(table, table->n_def - 1);
col->ind = table->n_def - 1;
col->name = str;
col->name = mem_heap_strdup(table->heap, name);
col->table = table;
col->ord_part = 0;
......@@ -188,7 +181,6 @@ dict_mem_index_create(
ulint type, /* in: DICT_UNIQUE, DICT_CLUSTERED, ... ORed */
ulint n_fields) /* in: number of fields */
{
char* str;
dict_index_t* index;
mem_heap_t* heap;
......@@ -199,13 +191,9 @@ dict_mem_index_create(
index->heap = heap;
str = mem_heap_alloc(heap, 1 + ut_strlen(index_name));
ut_strcpy(str, index_name);
index->type = type;
index->space = space;
index->name = str;
index->name = mem_heap_strdup(heap, index_name);
index->table_name = table_name;
index->table = NULL;
index->n_def = 0;
......
......@@ -667,7 +667,6 @@ eval_predefined(
{
que_node_t* arg1;
lint int_val;
byte* str1;
byte* data;
int func;
......@@ -681,21 +680,63 @@ eval_predefined(
} else if (func == PARS_TO_CHAR_TOKEN) {
/* Convert number to character string as a
signed decimal integer. */
ulint uint_val;
int int_len;
int_val = eval_node_get_int_val(arg1);
data = eval_node_ensure_val_buf(func_node, 11);
sprintf((char*)data, "%10li", int_val);
/* Determine the length of the string. */
if (int_val == 0) {
int_len = 1; /* the number 0 occupies 1 byte */
} else {
int_len = 0;
if (int_val < 0) {
uint_val = ((ulint) -int_val - 1) + 1;
int_len++; /* reserve space for minus sign */
} else {
uint_val = (ulint) int_val;
}
for (; uint_val > 0; int_len++) {
uint_val /= 10;
}
}
/* allocate the string */
data = eval_node_ensure_val_buf(func_node, int_len + 1);
dfield_set_len(que_node_get_val(func_node), 10);
/* add terminating NUL character */
data[int_len] = 0;
/* convert the number */
if (int_val == 0) {
data[0] = '0';
} else {
int tmp;
if (int_val < 0) {
data[0] = '-'; /* preceding minus sign */
uint_val = ((ulint) -int_val - 1) + 1;
} else {
uint_val = (ulint) int_val;
}
for (tmp = int_len; uint_val > 0; uint_val /= 10) {
data[--tmp] = '0' + (uint_val % 10);
}
}
dfield_set_len((dfield_t*) que_node_get_val(func_node),
int_len);
return;
} else if (func == PARS_TO_NUMBER_TOKEN) {
str1 = dfield_get_data(que_node_get_val(arg1));
int_val = atoi((char*)str1);
int_val = atoi((char*)
dfield_get_data(que_node_get_val(arg1)));
} else if (func == PARS_SYSDATE_TOKEN) {
int_val = (lint)ut_time();
......
......@@ -288,7 +288,6 @@ fil_node_create(
{
fil_node_t* node;
fil_space_t* space;
char* name2;
fil_system_t* system = fil_system;
ut_a(system);
......@@ -299,11 +298,7 @@ fil_node_create(
node = mem_alloc(sizeof(fil_node_t));
name2 = mem_alloc(ut_strlen(name) + 1);
ut_strcpy(name2, name);
node->name = name2;
node->name = mem_strdup(name);
node->open = FALSE;
node->size = size;
node->magic_n = FIL_NODE_MAGIC_N;
......@@ -626,7 +621,6 @@ fil_space_create(
ulint purpose)/* in: FIL_TABLESPACE, or FIL_LOG if log */
{
fil_space_t* space;
char* name2;
fil_system_t* system = fil_system;
ut_a(system);
......@@ -642,11 +636,7 @@ fil_space_create(
space = mem_alloc(sizeof(fil_space_t));
name2 = mem_alloc(ut_strlen(name) + 1);
ut_strcpy(name2, name);
space->name = name2;
space->name = mem_strdup(name);
space->id = id;
space->purpose = purpose;
space->size = 0;
......
......@@ -102,9 +102,10 @@ pages, as long as it obeys the access order rules. */
#define IBUF_POOL_SIZE_PER_MAX_SIZE 2
/* The insert buffer control structure */
ibuf_t* ibuf = NULL;
ibuf_t* ibuf = NULL;
ulint ibuf_rnd = 986058871;
static
ulint ibuf_rnd = 986058871;
ulint ibuf_flush_count = 0;
......@@ -113,9 +114,9 @@ ulint ibuf_flush_count = 0;
#define IBUF_COUNT_N_PAGES 10000
/* Buffered entry counts for file pages, used in debugging */
ulint* ibuf_counts[IBUF_COUNT_N_SPACES];
static ulint* ibuf_counts[IBUF_COUNT_N_SPACES];
ibool ibuf_counts_inited = FALSE;
static ibool ibuf_counts_inited = FALSE;
/* The start address for an insert buffer bitmap page bitmap */
#define IBUF_BITMAP PAGE_DATA
......@@ -129,15 +130,18 @@ ibool ibuf_counts_inited = FALSE;
/* 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 mutex used to block pessimistic inserts to ibuf trees */
mutex_t ibuf_pessimistic_insert_mutex;
static mutex_t ibuf_pessimistic_insert_mutex;
/* The mutex protecting the insert buffer structs */
mutex_t ibuf_mutex;
static mutex_t ibuf_mutex;
/* The mutex protecting the insert buffer bitmaps */
mutex_t ibuf_bitmap_mutex;
static mutex_t ibuf_bitmap_mutex;
/* The area in pages from which contract looks for page numbers for merge */
#define IBUF_MERGE_AREA 8
......@@ -2506,16 +2510,13 @@ ibuf_merge_or_delete_for_page(
dtuple_t* entry;
dtuple_t* search_tuple;
rec_t* ibuf_rec;
ibool closed;
buf_block_t* block;
page_t* bitmap_page;
ibuf_data_t* ibuf_data;
ibool success;
ulint n_inserts;
#ifdef UNIV_IBUF_DEBUG
ulint volume;
ulint old_bits;
ulint new_bits;
dulint max_trx_id;
#endif
ibool corruption_noticed = FALSE;
mtr_t mtr;
char err_buf[500];
......@@ -2605,12 +2606,14 @@ ibuf_merge_or_delete_for_page(
}
n_inserts = 0;
#ifdef UNIV_IBUF_DEBUG
volume = 0;
#endif
loop:
mtr_start(&mtr);
if (page) {
success = buf_page_get_known_nowait(RW_X_LATCH, page,
ibool success = buf_page_get_known_nowait(RW_X_LATCH, page,
BUF_KEEP_OLD,
IB__FILE__, __LINE__,
&mtr);
......@@ -2667,7 +2670,7 @@ ibuf_merge_or_delete_for_page(
keep the latch to the ibuf_rec page until the
insertion is finished! */
max_trx_id = page_get_max_trx_id(
dulint max_trx_id = page_get_max_trx_id(
buf_frame_align(ibuf_rec));
page_update_max_trx_id(page, max_trx_id);
......@@ -2686,9 +2689,8 @@ ibuf_merge_or_delete_for_page(
n_inserts++;
/* Delete the record from ibuf */
closed = ibuf_delete_rec(space, page_no, &pcur, search_tuple,
&mtr);
if (closed) {
if (ibuf_delete_rec(space, page_no, &pcur, search_tuple,
&mtr)) {
/* Deletion was pessimistic and mtr was committed:
we start from the beginning again */
......@@ -2717,10 +2719,9 @@ ibuf_merge_or_delete_for_page(
ibuf_bitmap_page_set_bits(bitmap_page, page_no,
IBUF_BITMAP_BUFFERED, FALSE, &mtr);
if (page) {
old_bits = ibuf_bitmap_page_get_bits(bitmap_page, page_no,
IBUF_BITMAP_FREE, &mtr);
new_bits = ibuf_index_page_calc_free(page);
ulint old_bits = ibuf_bitmap_page_get_bits(bitmap_page,
page_no, IBUF_BITMAP_FREE, &mtr);
ulint new_bits = ibuf_index_page_calc_free(page);
#ifdef UNIV_IBUF_DEBUG
/* printf("Old bits %lu new bits %lu max size %lu\n", old_bits,
new_bits,
......
......@@ -294,6 +294,7 @@ dtuple_check_typed_no_assert(
/*=========================*/
/* out: TRUE if ok */
dtuple_t* tuple); /* in: tuple */
#ifdef UNIV_DEBUG
/**************************************************************
Validates the consistency of a tuple which must be complete, i.e,
all fields must have been set. */
......@@ -303,6 +304,7 @@ dtuple_validate(
/*============*/
/* out: TRUE if ok */
dtuple_t* tuple); /* in: tuple */
#endif /* UNIV_DEBUG */
/*****************************************************************
Pretty prints a dfield value according to its data type. */
......
......@@ -299,7 +299,7 @@ dtuple_get_data_size(
ut_ad(tuple);
ut_ad(dtuple_check_typed(tuple));
ut_ad(tuple->magic_n = DATA_TUPLE_MAGIC_N);
ut_ad(tuple->magic_n == DATA_TUPLE_MAGIC_N);
n_fields = tuple->n_fields;
......@@ -355,7 +355,7 @@ dtuple_fold(
ulint fold;
ut_ad(tuple);
ut_ad(tuple->magic_n = DATA_TUPLE_MAGIC_N);
ut_ad(tuple->magic_n == DATA_TUPLE_MAGIC_N);
ut_ad(dtuple_check_typed(tuple));
fold = ut_fold_dulint(tree_id);
......
......@@ -32,20 +32,21 @@ Get the database name length in a table name. */
ulint
dict_get_db_name_len(
/*=================*/
/* out: database name length */
char* name); /* in: table name in the form dbname '/' tablename */
/* out: database name length */
const char* name); /* in: table name in the form
dbname '/' tablename */
/*************************************************************************
Accepts a specified string. Comparisons are case-insensitive. */
char*
const char*
dict_accept(
/*========*/
/* out: if string was accepted, the pointer
is moved after that, else ptr is returned */
char* ptr, /* in: scan from this */
const char* string,/* in: accept only this string as the next
non-whitespace string */
ibool* success);/* out: TRUE if accepted */
/* out: if string was accepted, the pointer
is moved after that, else ptr is returned */
const char* ptr, /* in: scan from this */
const char* string, /* in: accept only this string as the next
non-whitespace string */
ibool* success);/* out: TRUE if accepted */
/************************************************************************
Decrements the count of open MySQL handles to a table. */
......@@ -216,7 +217,7 @@ dict_foreign_parse_drop_constraints(
dict_table_t* table, /* in: table */
ulint* n, /* out: number of constraints
to drop */
char*** constraints_to_drop); /* out: id's of the
const char*** constraints_to_drop); /* out: id's of the
constraints to drop */
/**************************************************************************
Returns a table object and memoryfixes it. NOTE! This is a high-level
......@@ -321,7 +322,7 @@ dict_table_print_by_name(
/*=====================*/
char* name);
/**************************************************************************
Sprintfs to a string info on foreign keys of a table. */
Outputs info on foreign keys of a table. */
void
dict_print_info_on_foreign_keys(
......
......@@ -526,12 +526,12 @@ extern lock_sys_t* lock_sys;
#define LOCK_X 5 /* exclusive */
#define LOCK_AUTO_INC 6 /* locks the auto-inc counter of a table
in an exclusive mode */
#define LOCK_MODE_MASK 0xF /* mask used to extract mode from the
#define LOCK_MODE_MASK 0xFUL /* mask used to extract mode from the
type_mode field in a lock */
/* Lock types */
#define LOCK_TABLE 16 /* these type values should be so high that */
#define LOCK_REC 32 /* they can be ORed to the lock mode */
#define LOCK_TYPE_MASK 0xF0 /* mask used to extract lock type from the
#define LOCK_TYPE_MASK 0xF0UL /* mask used to extract lock type from the
type_mode field in a lock */
/* Waiting lock flag */
#define LOCK_WAIT 256 /* this wait bit should be so high that
......
......@@ -366,7 +366,6 @@ Writes a buffer to a log file group. */
void
log_group_write_buf(
/*================*/
ulint type, /* in: LOG_FLUSH or LOG_RECOVER */
log_group_t* group, /* in: log group */
byte* buf, /* in: buffer */
ulint len, /* in: buffer len; must be divisible
......@@ -551,7 +550,7 @@ extern log_t* log_sys;
highest bit is set to 1 if this is the
first log block in a log flush write
segment */
#define LOG_BLOCK_FLUSH_BIT_MASK 0x80000000
#define LOG_BLOCK_FLUSH_BIT_MASK 0x80000000UL
/* mask used to get the highest bit in
the preceding field */
#define LOG_BLOCK_HDR_DATA_LEN 4 /* number of bytes of log written to
......
......@@ -271,6 +271,59 @@ mem_realloc(
ulint n, /* in: desired number of bytes */
char* file_name,/* in: file name where called */
ulint line); /* in: line where called */
/**************************************************************************
Duplicates a NUL-terminated string. */
UNIV_INLINE
char*
mem_strdup(
/*=======*/
/* out, own: a copy of the string,
must be deallocated with mem_free */
const char* str); /* in: string to be copied */
/**************************************************************************
Makes a NUL-terminated copy of a nonterminated string. */
UNIV_INLINE
char*
mem_strdupl(
/*========*/
/* out, own: a copy of the string,
must be deallocated with mem_free */
const char* str, /* in: string to be copied */
ulint len); /* in: length of str, in bytes */
/**************************************************************************
Makes a NUL-terminated quoted copy of a NUL-terminated string. */
UNIV_INLINE
char*
mem_strdupq(
/*========*/
/* out, own: a quoted copy of the string,
must be deallocated with mem_free */
const char* str, /* in: string to be copied */
char q); /* in: quote character */
/**************************************************************************
Duplicates a NUL-terminated string, allocated from a memory heap. */
UNIV_INLINE
char*
mem_heap_strdup(
/*============*/
/* out, own: a copy of the string */
mem_heap_t* heap, /* in: memory heap where string is allocated */
const char* str); /* in: string to be copied */
/**************************************************************************
Makes a NUL-terminated copy of a nonterminated string,
allocated from a memory heap. */
UNIV_INLINE
char*
mem_heap_strdupl(
/*=============*/
/* out, own: a copy of the string */
mem_heap_t* heap, /* in: memory heap where string is allocated */
const char* str, /* in: string to be copied */
ulint len); /* in: length of str, in bytes */
#ifdef MEM_PERIODIC_CHECK
/**********************************************************************
Goes through the list of all allocated mem blocks, checks their magic
......
......@@ -579,3 +579,99 @@ mem_realloc(
return(mem_alloc_func(n, file_name, line));
}
/**************************************************************************
Duplicates a NUL-terminated string. */
UNIV_INLINE
char*
mem_strdup(
/*=======*/
/* out, own: a copy of the string,
must be deallocated with mem_free */
const char* str) /* in: string to be copied */
{
ulint len = strlen(str) + 1;
return(memcpy(mem_alloc(len), str, len));
}
/**************************************************************************
Makes a NUL-terminated copy of a nonterminated string. */
UNIV_INLINE
char*
mem_strdupl(
/*========*/
/* out, own: a copy of the string,
must be deallocated with mem_free */
const char* str, /* in: string to be copied */
ulint len) /* in: length of str, in bytes */
{
char* s = mem_alloc(len + 1);
s[len] = 0;
return(memcpy(s, str, len));
}
/**************************************************************************
Makes a NUL-terminated quoted copy of a NUL-terminated string. */
UNIV_INLINE
char*
mem_strdupq(
/*========*/
/* out, own: a quoted copy of the string,
must be deallocated with mem_free */
const char* str, /* in: string to be copied */
char q) /* in: quote character */
{
char* dst;
char* d;
const char* s = str;
int len = strlen(str) + 3;
/* calculate the number of quote characters in the string */
while((s = strchr(s, q)) != NULL) {
s++;
len++;
}
/* allocate the quoted string, and copy it */
d = dst = mem_alloc(len);
*d++ = q;
s = str;
while(*s) {
if ((*d++ = *s++) == q) {
*d++ = q;
}
}
*d++ = q;
*d++ = '\0';
ut_ad(len == d - dst);
return(dst);
}
/**************************************************************************
Duplicates a NUL-terminated string, allocated from a memory heap. */
UNIV_INLINE
char*
mem_heap_strdup(
/*============*/
/* out, own: a copy of the string */
mem_heap_t* heap, /* in: memory heap where string is allocated */
const char* str) /* in: string to be copied */
{
ulint len = strlen(str) + 1;
return(memcpy(mem_heap_alloc(heap, len), str, len));
}
/**************************************************************************
Makes a NUL-terminated copy of a nonterminated string,
allocated from a memory heap. */
UNIV_INLINE
char*
mem_heap_strdupl(
/*=============*/
/* out, own: a copy of the string */
mem_heap_t* heap, /* in: memory heap where string is allocated */
const char* str, /* in: string to be copied */
ulint len) /* in: length of str, in bytes */
{
char* s = mem_heap_alloc(heap, len + 1);
s[len] = 0;
return(memcpy(s, str, len));
}
......@@ -26,8 +26,7 @@ ulint
row_undo_ins(
/*=========*/
/* out: DB_SUCCESS */
undo_node_t* node, /* in: row undo node */
que_thr_t* thr); /* in: query thread */
undo_node_t* node); /* in: row undo node */
#ifndef UNIV_NONINL
......
......@@ -41,8 +41,7 @@ row_undo_search_clust_to_pcur(
/* out: TRUE if found; NOTE the node->pcur
must be closed by the caller, regardless of
the return value */
undo_node_t* node, /* in: row undo node */
que_thr_t* thr); /* in: query thread */
undo_node_t* node); /* in: row undo node */
/***************************************************************
Undoes a row operation in a table. This is a high-level function used
in SQL execution graphs. */
......
......@@ -235,21 +235,19 @@ Copies a string to a memory location, setting characters to lower case. */
void
ut_cpy_in_lower_case(
/*=================*/
char* dest, /* in: destination */
char* source, /* in: source */
ulint len); /* in: string length */
char* dest, /* in: destination */
const char* source, /* in: source */
ulint len); /* in: string length */
/****************************************************************
Compares two strings when converted to lower case. */
int
ut_cmp_in_lower_case(
/*=================*/
/* out: -1, 0, 1 if str1 < str2, str1 == str2,
str1 > str2, respectively */
char* str1, /* in: string1 */
char* str2, /* in: string2 */
ulint len); /* in: length of both strings */
/* out: -1, 0, 1 if str1 < str2, str1 == str2,
str1 > str2, respectively */
const char* str1, /* in: string1 */
const char* str2); /* in: string2 */
#ifndef UNIV_NONINL
#include "ut0byte.ic"
......
......@@ -75,6 +75,39 @@ UNIV_INLINE
int
ut_strcmp(void* str1, void* str2);
/**************************************************************************
Determine the length of a string when it is quoted with ut_strcpyq(). */
UNIV_INLINE
ulint
ut_strlenq(
/*=======*/
/* out: length of the string when quoted */
const char* str, /* in: null-terminated string */
char q); /* in: the quote character */
/**************************************************************************
Make a quoted copy of a string. */
char*
ut_strcpyq(
/*=======*/
/* out: pointer to end of dest */
char* dest, /* in: output buffer */
char q, /* in: the quote character */
const char* src); /* in: null-terminated string */
/**************************************************************************
Make a quoted copy of a fixed-length string. */
char*
ut_memcpyq(
/*=======*/
/* out: pointer to end of dest */
char* dest, /* in: output buffer */
char q, /* in: the quote character */
const char* src, /* in: string to be quoted */
ulint len); /* in: length of src */
/**************************************************************************
Catenates two strings into newly allocated memory. The memory must be freed
using mem_free. */
......
......@@ -48,3 +48,23 @@ ut_strcmp(void* str1, void* str2)
return(strcmp((char*)str1, (char*)str2));
}
/**************************************************************************
Determine the length of a string when it is quoted with ut_strcpyq(). */
UNIV_INLINE
ulint
ut_strlenq(
/*=======*/
/* out: length of the string when quoted */
const char* str, /* in: null-terminated string */
char q) /* in: the quote character */
{
ulint len;
for (len = 0; *str; len++, str++) {
if (*str == q) {
len++;
}
}
return(len);
}
......@@ -28,7 +28,9 @@ ut_sprintf(
/*=======*/
char* buf, /* in/out: buffer where to print */
const char* format, /* in: format of prints */
...); /* in: arguments to be printed */
...) /* in: arguments to be printed */
__attribute__((__format__ (__printf__, 2, 3)));
/************************************************************
Gets the high 32 bits in a ulint. That is makes a shift >> 32,
but since there seem to be compiler bugs in both gcc and Visual C++,
......
......@@ -4592,7 +4592,6 @@ lock_clust_rec_modify_check_and_lock(
dict_index_t* index, /* in: clustered index */
que_thr_t* thr) /* in: query thread */
{
trx_t* trx;
ulint err;
if (flags & BTR_NO_LOCKING_FLAG) {
......@@ -4602,8 +4601,6 @@ lock_clust_rec_modify_check_and_lock(
ut_ad(index->type & DICT_CLUSTERED);
trx = thr_get_trx(thr);
lock_mutex_enter_kernel();
ut_ad(lock_table_has(thr_get_trx(thr), index->table, LOCK_IX));
......
......@@ -1015,7 +1015,7 @@ log_io_complete(
return;
}
if ((ulint)group & 0x1) {
if ((ulint)group & 0x1UL) {
/* It was a checkpoint write */
group = (log_group_t*)((ulint)group - 1);
......@@ -1070,7 +1070,6 @@ static
void
log_group_file_header_flush(
/*========================*/
ulint type, /* in: LOG_FLUSH or LOG_RECOVER */
log_group_t* group, /* in: log group */
ulint nth_file, /* in: header to the nth file in the
log file space */
......@@ -1079,9 +1078,6 @@ log_group_file_header_flush(
{
byte* buf;
ulint dest_offset;
UT_NOT_USED(type);
#ifdef UNIV_SYNC_DEBUG
ut_ad(mutex_own(&(log_sys->mutex)));
#endif /* UNIV_SYNC_DEBUG */
......@@ -1136,7 +1132,6 @@ Writes a buffer to a log file group. */
void
log_group_write_buf(
/*================*/
ulint type, /* in: LOG_FLUSH or LOG_RECOVER */
log_group_t* group, /* in: log group */
byte* buf, /* in: buffer */
ulint len, /* in: buffer len; must be divisible
......@@ -1177,7 +1172,7 @@ log_group_write_buf(
&& write_header) {
/* We start to write a new log file instance in the group */
log_group_file_header_flush(type, group,
log_group_file_header_flush(group,
next_offset / group->file_size, start_lsn);
}
......@@ -1396,7 +1391,7 @@ log_write_up_to(
/* Do the write to the log files */
while (group) {
log_group_write_buf(LOG_FLUSH, group,
log_group_write_buf(group,
log_sys->buf + area_start,
area_end - area_start,
ut_dulint_align_down(log_sys->written_to_all_lsn,
......@@ -2137,11 +2132,11 @@ void
log_archived_file_name_gen(
/*=======================*/
char* buf, /* in: buffer where to write */
ulint id, /* in: group id */
ulint id __attribute__((unused)),
/* in: group id;
currently we only archive the first group */
ulint file_no)/* in: file number */
{
UT_NOT_USED(id); /* Currently we only archive the first group */
sprintf(buf, "%sib_arch_log_%010lu", srv_arch_dir, file_no);
}
......
......@@ -274,8 +274,7 @@ recv_truncate_group(
len = ut_dulint_minus(end_lsn, start_lsn);
log_group_write_buf(LOG_RECOVER, group, log_sys->buf, len,
start_lsn, 0);
log_group_write_buf(group, log_sys->buf, len, start_lsn, 0);
if (ut_dulint_cmp(end_lsn, finish_lsn) >= 0) {
return;
......@@ -330,8 +329,7 @@ recv_copy_group(
len = ut_dulint_minus(end_lsn, start_lsn);
log_group_write_buf(LOG_RECOVER, group, log_sys->buf, len,
start_lsn, 0);
log_group_write_buf(group, log_sys->buf, len, start_lsn, 0);
if (ut_dulint_cmp(end_lsn, recovered_lsn) >= 0) {
......@@ -523,7 +521,7 @@ recv_find_max_checkpoint(
"InnoDB: the problem may be that during an earlier attempt you managed\n"
"InnoDB: to create the InnoDB data files, but log file creation failed.\n"
"InnoDB: If that is the case, please refer to section 3.1 of\n"
"InnoDB: http://www.innodb.com/ibman.html\n");
"InnoDB: http://www.innodb.com/ibman.php\n");
return(DB_ERROR);
}
......
......@@ -196,12 +196,7 @@ mem_heap_create_block(
mem_block_set_start(block, MEM_BLOCK_HEADER_SIZE);
block->free_block = NULL;
if (init_block != NULL) {
block->init_block = TRUE;
} else {
block->init_block = FALSE;
}
block->init_block = (init_block != NULL);
ut_ad((ulint)MEM_BLOCK_HEADER_SIZE < len);
......
......@@ -95,6 +95,7 @@ mlog_parse_initial_log_record(
}
*type = (byte)((ulint)*ptr & ~MLOG_SINGLE_REC_FLAG);
ut_ad(*type <= MLOG_BIGGEST_TYPE);
ptr++;
......@@ -171,13 +172,13 @@ mlog_parse_nbytes(
}
if (type == MLOG_1BYTE) {
if (val > 0xFF) {
if (val > 0xFFUL) {
recv_sys->found_corrupt_log = TRUE;
return(NULL);
}
} else if (type == MLOG_2BYTES) {
if (val > 0xFFFF) {
if (val > 0xFFFFUL) {
recv_sys->found_corrupt_log = TRUE;
return(NULL);
......@@ -234,7 +235,7 @@ mlog_write_ulint(
mach_write_to_4(ptr, val);
}
log_ptr = mlog_open(mtr, 30);
log_ptr = mlog_open(mtr, 11 + 2 + 5);
/* If no logging is requested, we may return now */
if (log_ptr == NULL) {
......@@ -276,7 +277,7 @@ mlog_write_dulint(
mach_write_to_8(ptr, val);
log_ptr = mlog_open(mtr, 30);
log_ptr = mlog_open(mtr, 11 + 2 + 9);
/* If no logging is requested, we may return now */
if (log_ptr == NULL) {
......
......@@ -479,6 +479,7 @@ page_cur_insert_rec_write_log(
ulint i;
ut_a(rec_size < UNIV_PAGE_SIZE);
ut_ad(rec_size == rec_get_size(insert_rec));
log_ptr = mlog_open(mtr, 30 + MLOG_BUF_MARGIN);
......@@ -630,8 +631,8 @@ page_cur_parse_insert_rec(
return(NULL);
}
extra_info_yes = end_seg_len & 0x1;
end_seg_len = end_seg_len / 2;
extra_info_yes = end_seg_len & 0x1UL;
end_seg_len >>= 1;
if (end_seg_len >= UNIV_PAGE_SIZE) {
recv_sys->found_corrupt_log = TRUE;
......@@ -694,7 +695,7 @@ page_cur_parse_insert_rec(
mismatch_index = rec_get_size(cursor_rec) - end_seg_len;
}
if (mismatch_index + end_seg_len < 1024) {
if (mismatch_index + end_seg_len < sizeof buf1) {
buf = buf1;
} else {
buf = mem_alloc(mismatch_index + end_seg_len);
......@@ -726,7 +727,7 @@ page_cur_parse_insert_rec(
page_cur_rec_insert(&cursor, buf + origin_offset, mtr);
if (mismatch_index + end_seg_len >= 1024) {
if (buf != buf1) {
mem_free(buf);
}
......
......@@ -1604,7 +1604,7 @@ page_validate(
page_cur_set_before_first(page, &cur);
for (;;) {
rec = (&cur)->rec;
rec = cur.rec;
if (!page_rec_validate(rec)) {
goto func_exit;
......@@ -1793,16 +1793,13 @@ page_find_rec_with_heap_no(
ulint heap_no)/* in: heap number */
{
page_cur_t cur;
rec_t* rec;
page_cur_set_before_first(page, &cur);
for (;;) {
rec = (&cur)->rec;
if (rec_get_heap_no(rec) == heap_no) {
if (rec_get_heap_no(cur.rec) == heap_no) {
return(rec);
return(cur.rec);
}
if (page_cur_is_after_last(&cur)) {
......
......@@ -532,8 +532,8 @@ opt_search_plan_for_table(
ulint best_goodness;
ulint best_last_op = 0; /* remove warning */
ulint mix_id_pos;
que_node_t* index_plan[128];
que_node_t* best_index_plan[128];
que_node_t* index_plan[256];
que_node_t* best_index_plan[256];
plan = sel_node_get_nth_plan(sel_node, i);
......
......@@ -1745,8 +1745,6 @@ pars_sql(
sym_node_t* sym_node;
mem_heap_t* heap;
que_t* graph;
ulint len;
char* buf;
ut_ad(str);
......@@ -1758,12 +1756,8 @@ pars_sql(
#endif /* UNIV_SYNC_DEBUG */
pars_sym_tab_global = sym_tab_create(heap);
len = ut_strlen(str);
buf = mem_heap_alloc(heap, len + 1);
ut_memcpy(buf, str, len + 1);
pars_sym_tab_global->sql_string = buf;
pars_sym_tab_global->string_len = len;
pars_sym_tab_global->sql_string = mem_heap_strdup(heap, str);
pars_sym_tab_global->string_len = strlen(str);
pars_sym_tab_global->next_char_pos = 0;
yyparse();
......
......@@ -568,8 +568,7 @@ static
void
row_ins_foreign_report_add_err(
/*===========================*/
que_thr_t* thr, /* in: query thread whose run_node
is an insert node */
trx_t* trx, /* in: transaction */
dict_foreign_t* foreign, /* in: foreign key constraint */
rec_t* rec, /* in: a record in the parent table:
it does not match entry because we
......@@ -582,7 +581,7 @@ row_ins_foreign_report_add_err(
mutex_enter(&dict_foreign_err_mutex);
ut_sprintf_timestamp(buf);
sprintf(buf + strlen(buf), " Transaction:\n");
trx_print(buf + strlen(buf), thr_get_trx(thr));
trx_print(buf + strlen(buf), trx);
sprintf(buf + strlen(buf),
"Foreign key constraint fails for table %.500s:\n",
foreign->foreign_table_name);
......@@ -661,15 +660,10 @@ row_ins_foreign_check_on_constraint(
the MySQL query cache for table */
ut_a(ut_strlen(table->name) < 998);
ut_memcpy(table_name_buf, table->name, ut_strlen(table->name) + 1);
ptr = table_name_buf;
while (*ptr != '/') {
ptr++;
}
strcpy(table_name_buf, table->name);
ptr = strchr(table_name_buf, '/');
ut_a(ptr);
*ptr = '\0';
/* We call a function in ha_innodb.cc */
......@@ -1200,11 +1194,6 @@ row_ins_check_foreign_constraint(
break;
}
/* printf(
"FOREIGN: Found matching record from %s %s\n",
check_index->table_name, check_index->name);
rec_print(rec);
*/
if (check_ref) {
err = DB_SUCCESS;
......@@ -1244,7 +1233,7 @@ row_ins_check_foreign_constraint(
if (check_ref) {
err = DB_NO_REFERENCED_ROW;
row_ins_foreign_report_add_err(
thr, foreign, rec, entry);
thr_get_trx(thr), foreign, rec, entry);
} else {
err = DB_SUCCESS;
}
......@@ -1260,7 +1249,7 @@ row_ins_check_foreign_constraint(
if (check_ref) {
rec = btr_pcur_get_rec(&pcur);
row_ins_foreign_report_add_err(
thr, foreign, rec, entry);
thr_get_trx(thr), foreign, rec, entry);
err = DB_NO_REFERENCED_ROW;
} else {
err = DB_SUCCESS;
......@@ -2167,15 +2156,8 @@ row_ins_step(
error_handling:
trx->error_state = err;
if (err == DB_SUCCESS) {
/* Ok: do nothing */
} else if (err == DB_LOCK_WAIT) {
return(NULL);
} else {
/* SQL error detected */
if (err != DB_SUCCESS) {
/* err == DB_LOCK_WAIT or SQL error detected */
return(NULL);
}
......
This diff is collapsed.
......@@ -91,7 +91,6 @@ row_purge_remove_clust_if_poss_low(
/* out: TRUE if success, or if not found, or
if modified after the delete marking */
purge_node_t* node, /* in: row purge node */
que_thr_t* thr, /* in: query thread */
ulint mode) /* in: BTR_MODIFY_LEAF or BTR_MODIFY_TREE */
{
dict_index_t* index;
......@@ -101,8 +100,6 @@ row_purge_remove_clust_if_poss_low(
ulint err;
mtr_t mtr;
UT_NOT_USED(thr);
index = dict_table_get_first_index(node->table);
pcur = &(node->pcur);
......@@ -156,23 +153,20 @@ static
void
row_purge_remove_clust_if_poss(
/*===========================*/
purge_node_t* node, /* in: row purge node */
que_thr_t* thr) /* in: query thread */
purge_node_t* node) /* in: row purge node */
{
ibool success;
ulint n_tries = 0;
/* printf("Purge: Removing clustered record\n"); */
success = row_purge_remove_clust_if_poss_low(node, thr,
BTR_MODIFY_LEAF);
success = row_purge_remove_clust_if_poss_low(node, BTR_MODIFY_LEAF);
if (success) {
return;
}
retry:
success = row_purge_remove_clust_if_poss_low(node, thr,
BTR_MODIFY_TREE);
success = row_purge_remove_clust_if_poss_low(node, BTR_MODIFY_TREE);
/* The delete operation may fail if we have little
file space left: TODO: easiest to crash the database
and restart with more file space */
......@@ -196,7 +190,6 @@ row_purge_remove_sec_if_poss_low(
/*=============================*/
/* out: TRUE if success or if not found */
purge_node_t* node, /* in: row purge node */
que_thr_t* thr, /* in: query thread */
dict_index_t* index, /* in: index */
dtuple_t* entry, /* in: index entry */
ulint mode) /* in: latch mode BTR_MODIFY_LEAF or
......@@ -211,8 +204,6 @@ row_purge_remove_sec_if_poss_low(
mtr_t mtr;
mtr_t* mtr_vers;
UT_NOT_USED(thr);
log_free_check();
mtr_start(&mtr);
......@@ -284,7 +275,6 @@ void
row_purge_remove_sec_if_poss(
/*=========================*/
purge_node_t* node, /* in: row purge node */
que_thr_t* thr, /* in: query thread */
dict_index_t* index, /* in: index */
dtuple_t* entry) /* in: index entry */
{
......@@ -293,14 +283,14 @@ row_purge_remove_sec_if_poss(
/* printf("Purge: Removing secondary record\n"); */
success = row_purge_remove_sec_if_poss_low(node, thr, index, entry,
success = row_purge_remove_sec_if_poss_low(node, index, entry,
BTR_MODIFY_LEAF);
if (success) {
return;
}
retry:
success = row_purge_remove_sec_if_poss_low(node, thr, index, entry,
success = row_purge_remove_sec_if_poss_low(node, index, entry,
BTR_MODIFY_TREE);
/* The delete operation may fail if we have little
file space left: TODO: easiest to crash the database
......@@ -324,14 +314,13 @@ static
void
row_purge_del_mark(
/*===============*/
purge_node_t* node, /* in: row purge node */
que_thr_t* thr) /* in: query thread */
purge_node_t* node) /* in: row purge node */
{
mem_heap_t* heap;
dtuple_t* entry;
dict_index_t* index;
ut_ad(node && thr);
ut_ad(node);
heap = mem_heap_create(1024);
......@@ -341,14 +330,14 @@ row_purge_del_mark(
/* Build the index entry */
entry = row_build_index_entry(node->row, index, heap);
row_purge_remove_sec_if_poss(node, thr, index, entry);
row_purge_remove_sec_if_poss(node, index, entry);
node->index = dict_table_get_next_index(node->index);
}
mem_heap_free(heap);
row_purge_remove_clust_if_poss(node, thr);
row_purge_remove_clust_if_poss(node);
}
/***************************************************************
......@@ -358,8 +347,7 @@ static
void
row_purge_upd_exist_or_extern(
/*==========================*/
purge_node_t* node, /* in: row purge node */
que_thr_t* thr) /* in: query thread */
purge_node_t* node) /* in: row purge node */
{
mem_heap_t* heap;
dtuple_t* entry;
......@@ -375,7 +363,7 @@ row_purge_upd_exist_or_extern(
ulint i;
mtr_t mtr;
ut_ad(node && thr);
ut_ad(node);
if (node->rec_type == TRX_UNDO_UPD_DEL_REC) {
......@@ -392,7 +380,7 @@ row_purge_upd_exist_or_extern(
/* Build the older version of the index entry */
entry = row_build_index_entry(node->row, index, heap);
row_purge_remove_sec_if_poss(node, thr, index, entry);
row_purge_remove_sec_if_poss(node, index, entry);
}
node->index = dict_table_get_next_index(node->index);
......@@ -519,7 +507,7 @@ row_purge_parse_undo_rec(
mutex_enter(&(dict_sys->mutex));
node->table = dict_table_get_on_id_low(table_id, thr_get_trx(thr));
node->table = dict_table_get_on_id_low(table_id, trx);
mutex_exit(&(dict_sys->mutex));
......@@ -609,12 +597,12 @@ row_purge(
dict_table_get_first_index(node->table));
if (node->rec_type == TRX_UNDO_DEL_MARK_REC) {
row_purge_del_mark(node, thr);
row_purge_del_mark(node);
} else if (updated_extern
|| node->rec_type == TRX_UNDO_UPD_EXIST_REC) {
row_purge_upd_exist_or_extern(node, thr);
row_purge_upd_exist_or_extern(node);
}
if (node->found_clust) {
......
......@@ -568,7 +568,7 @@ row_get_clust_rec(
found = row_search_on_row_ref(&pcur, mode, table, ref, mtr);
clust_rec = btr_pcur_get_rec(&pcur);
clust_rec = found ? btr_pcur_get_rec(&pcur) : NULL;
mem_heap_free(heap);
......@@ -576,11 +576,6 @@ row_get_clust_rec(
*clust_index = dict_table_get_first_index(table);
if (!found) {
return(NULL);
}
return(clust_rec);
}
......
......@@ -37,8 +37,7 @@ ulint
row_undo_ins_remove_clust_rec(
/*==========================*/
/* out: DB_SUCCESS or DB_OUT_OF_FILE_SPACE */
undo_node_t* node, /* in: undo node */
que_thr_t* thr) /* in: query thread */
undo_node_t* node) /* in: undo node */
{
btr_cur_t* btr_cur;
ibool success;
......@@ -46,8 +45,6 @@ row_undo_ins_remove_clust_rec(
ulint n_tries = 0;
mtr_t mtr;
UT_NOT_USED(thr);
mtr_start(&mtr);
success = btr_pcur_restore_position(BTR_MODIFY_LEAF, &(node->pcur),
......@@ -126,8 +123,7 @@ row_undo_ins_remove_sec_low(
depending on whether we wish optimistic or
pessimistic descent down the index tree */
dict_index_t* index, /* in: index */
dtuple_t* entry, /* in: index entry to remove */
que_thr_t* thr) /* in: query thread */
dtuple_t* entry) /* in: index entry to remove */
{
btr_pcur_t pcur;
btr_cur_t* btr_cur;
......@@ -136,8 +132,6 @@ row_undo_ins_remove_sec_low(
ulint err;
mtr_t mtr;
UT_NOT_USED(thr);
log_free_check();
mtr_start(&mtr);
......@@ -148,15 +142,6 @@ row_undo_ins_remove_sec_low(
if (!found) {
/* Not found */
/* FIXME: remove printfs in the final version */
/* printf(
"--UNDO INS: Record not found from page %lu index %s\n",
buf_frame_get_page_no(btr_cur_get_rec(btr_cur)),
index->name); */
/* ibuf_print(); */
btr_pcur_close(&pcur);
mtr_commit(&mtr);
......@@ -192,15 +177,14 @@ row_undo_ins_remove_sec(
/*====================*/
/* out: DB_SUCCESS or DB_OUT_OF_FILE_SPACE */
dict_index_t* index, /* in: index */
dtuple_t* entry, /* in: index entry to insert */
que_thr_t* thr) /* in: query thread */
dtuple_t* entry) /* in: index entry to insert */
{
ulint err;
ulint n_tries = 0;
/* Try first optimistic descent to the B-tree */
err = row_undo_ins_remove_sec_low(BTR_MODIFY_LEAF, index, entry, thr);
err = row_undo_ins_remove_sec_low(BTR_MODIFY_LEAF, index, entry);
if (err == DB_SUCCESS) {
......@@ -209,7 +193,7 @@ row_undo_ins_remove_sec(
/* Try then pessimistic descent to the B-tree */
retry:
err = row_undo_ins_remove_sec_low(BTR_MODIFY_TREE, index, entry, thr);
err = row_undo_ins_remove_sec_low(BTR_MODIFY_TREE, index, entry);
/* The delete operation may fail if we have little
file space left: TODO: easiest to crash the database
......@@ -233,8 +217,7 @@ static
void
row_undo_ins_parse_undo_rec(
/*========================*/
undo_node_t* node, /* in: row undo node */
que_thr_t* thr __attribute__((unused))) /* in: query thread */
undo_node_t* node) /* in: row undo node */
{
dict_index_t* clust_index;
byte* ptr;
......@@ -244,7 +227,7 @@ row_undo_ins_parse_undo_rec(
ulint dummy;
ibool dummy_extern;
ut_ad(node && thr);
ut_ad(node);
ptr = trx_undo_rec_get_pars(node->undo_rec, &type, &dummy,
&dummy_extern, &undo_no, &table_id);
......@@ -273,22 +256,21 @@ ulint
row_undo_ins(
/*=========*/
/* out: DB_SUCCESS or DB_OUT_OF_FILE_SPACE */
undo_node_t* node, /* in: row undo node */
que_thr_t* thr) /* in: query thread */
undo_node_t* node) /* in: row undo node */
{
dtuple_t* entry;
ibool found;
ulint err;
ut_ad(node && thr);
ut_ad(node);
ut_ad(node->state == UNDO_NODE_INSERT);
row_undo_ins_parse_undo_rec(node, thr);
row_undo_ins_parse_undo_rec(node);
if (node->table == NULL) {
found = FALSE;
} else {
found = row_undo_search_clust_to_pcur(node, thr);
found = row_undo_search_clust_to_pcur(node);
}
if (!found) {
......@@ -303,7 +285,7 @@ row_undo_ins(
while (node->index != NULL) {
entry = row_build_index_entry(node->row, node->index,
node->heap);
err = row_undo_ins_remove_sec(node->index, entry, thr);
err = row_undo_ins_remove_sec(node->index, entry);
if (err != DB_SUCCESS) {
......@@ -313,7 +295,7 @@ row_undo_ins(
node->index = dict_table_get_next_index(node->index);
}
err = row_undo_ins_remove_clust_rec(node, thr);
err = row_undo_ins_remove_clust_rec(node);
return(err);
}
......@@ -95,14 +95,11 @@ row_undo_mod_clust_low(
ulint mode) /* in: BTR_MODIFY_LEAF or BTR_MODIFY_TREE */
{
big_rec_t* dummy_big_rec;
dict_index_t* index;
btr_pcur_t* pcur;
btr_cur_t* btr_cur;
ulint err;
ibool success;
index = dict_table_get_first_index(node->table);
pcur = &(node->pcur);
btr_cur = btr_pcur_get_btr_cur(pcur);
......@@ -317,13 +314,6 @@ row_undo_mod_del_mark_or_remove_sec_low(
if (!found) {
/* Not found */
/* FIXME: remove printfs in the final version */
/* printf(
"--UNDO MOD: Record not found from page %lu index %s\n",
buf_frame_get_page_no(btr_cur_get_rec(btr_cur)),
index->name); */
btr_pcur_close(&pcur);
mtr_commit(&mtr);
......@@ -421,7 +411,6 @@ row_undo_mod_del_unmark_sec_and_undo_update(
DB_OUT_OF_FILE_SPACE */
ulint mode, /* in: search mode: BTR_MODIFY_LEAF or
BTR_MODIFY_TREE */
undo_node_t* node, /* in: row undo node */
que_thr_t* thr, /* in: query thread */
dict_index_t* index, /* in: index */
dtuple_t* entry) /* in: index entry */
......@@ -430,15 +419,12 @@ row_undo_mod_del_unmark_sec_and_undo_update(
btr_pcur_t pcur;
btr_cur_t* btr_cur;
upd_t* update;
rec_t* rec;
ulint err = DB_SUCCESS;
ibool found;
big_rec_t* dummy_big_rec;
mtr_t mtr;
char err_buf[1000];
UT_NOT_USED(node);
log_free_check();
mtr_start(&mtr);
......@@ -463,15 +449,13 @@ row_undo_mod_del_unmark_sec_and_undo_update(
} else {
btr_cur = btr_pcur_get_btr_cur(&pcur);
rec = btr_cur_get_rec(btr_cur);
err = btr_cur_del_mark_set_sec_rec(BTR_NO_LOCKING_FLAG,
btr_cur, FALSE, thr, &mtr);
ut_a(err == DB_SUCCESS);
heap = mem_heap_create(100);
update = row_upd_build_sec_rec_difference_binary(index, entry,
rec, heap);
btr_cur_get_rec(btr_cur), heap);
if (upd_get_n_fields(update) == 0) {
/* Do nothing */
......@@ -566,11 +550,11 @@ row_undo_mod_del_mark_sec(
err = row_undo_mod_del_unmark_sec_and_undo_update(
BTR_MODIFY_LEAF,
node, thr, index, entry);
thr, index, entry);
if (err == DB_FAIL) {
err = row_undo_mod_del_unmark_sec_and_undo_update(
BTR_MODIFY_TREE,
node, thr, index, entry);
thr, index, entry);
}
if (err != DB_SUCCESS) {
......@@ -649,12 +633,12 @@ row_undo_mod_upd_exist_sec(
node->update, NULL);
err = row_undo_mod_del_unmark_sec_and_undo_update(
BTR_MODIFY_LEAF,
node, thr, index, entry);
thr, index, entry);
if (err == DB_FAIL) {
err =
row_undo_mod_del_unmark_sec_and_undo_update(
BTR_MODIFY_TREE,
node, thr, index, entry);
thr, index, entry);
}
if (err != DB_SUCCESS) {
......@@ -745,7 +729,7 @@ row_undo_mod(
if (node->table == NULL) {
found = FALSE;
} else {
found = row_undo_search_clust_to_pcur(node, thr);
found = row_undo_search_clust_to_pcur(node);
}
if (!found) {
......
......@@ -144,8 +144,7 @@ row_undo_search_clust_to_pcur(
/* out: TRUE if found; NOTE the node->pcur
must be closed by the caller, regardless of
the return value */
undo_node_t* node, /* in: row undo node */
que_thr_t* thr) /* in: query thread */
undo_node_t* node) /* in: row undo node */
{
dict_index_t* clust_index;
ibool found;
......@@ -153,8 +152,6 @@ row_undo_search_clust_to_pcur(
ibool ret;
rec_t* rec;
UT_NOT_USED(thr);
mtr_start(&mtr);
clust_index = dict_table_get_first_index(node->table);
......@@ -269,7 +266,7 @@ row_undo(
if (node->state == UNDO_NODE_INSERT) {
err = row_undo_ins(node, thr);
err = row_undo_ins(node);
node->state = UNDO_NODE_FETCH_NEXT;
} else {
......
......@@ -1576,7 +1576,8 @@ ulint
srv_lock_timeout_and_monitor_thread(
/*================================*/
/* out: a dummy parameter */
void* arg) /* in: a dummy parameter required by
void* arg __attribute__((unused)))
/* in: a dummy parameter required by
os_thread_create */
{
srv_slot_t* slot;
......@@ -1593,7 +1594,6 @@ srv_lock_timeout_and_monitor_thread(
printf("Lock timeout thread starts, id %lu\n",
os_thread_pf(os_thread_get_curr_id()));
#endif
UT_NOT_USED(arg);
srv_last_monitor_time = time(NULL);
last_table_monitor_time = time(NULL);
last_monitor_time = time(NULL);
......@@ -1738,7 +1738,7 @@ srv_lock_timeout_and_monitor_thread(
os_thread_exit(NULL);
#ifndef __WIN__
return(NULL);
return(NULL);
#else
return(0);
#endif
......@@ -1756,12 +1756,12 @@ ulint
srv_error_monitor_thread(
/*=====================*/
/* out: a dummy parameter */
void* arg) /* in: a dummy parameter required by
void* arg __attribute__((unused)))
/* in: a dummy parameter required by
os_thread_create */
{
ulint cnt = 0;
UT_NOT_USED(arg);
#ifdef UNIV_DEBUG_THREAD_CREATION
printf("Error monitor thread starts, id %lu\n",
os_thread_pf(os_thread_get_curr_id()));
......@@ -1801,7 +1801,7 @@ srv_error_monitor_thread(
os_thread_exit(NULL);
#ifndef __WIN__
return(NULL);
return(NULL);
#else
return(0);
#endif
......@@ -1857,7 +1857,8 @@ ulint
srv_master_thread(
/*==============*/
/* out: a dummy parameter */
void* arg) /* in: a dummy parameter required by
void* arg __attribute__((unused)))
/* in: a dummy parameter required by
os_thread_create */
{
os_event_t event;
......@@ -1876,8 +1877,6 @@ srv_master_thread(
ibool skip_sleep = FALSE;
ulint i;
UT_NOT_USED(arg);
#ifdef UNIV_DEBUG_THREAD_CREATION
printf("Master thread starts, id %lu\n",
os_thread_pf(os_thread_get_curr_id()));
......
......@@ -159,17 +159,13 @@ srv_parse_data_file_paths_and_sizes(
str++;
}
if (strlen(str) >= ut_strlen(":autoextend")
&& 0 == ut_memcmp(str, (char*)":autoextend",
ut_strlen(":autoextend"))) {
if (0 == memcmp(str, ":autoextend", (sizeof ":autoextend") - 1)) {
str += ut_strlen(":autoextend");
str += (sizeof ":autoextend") - 1;
if (strlen(str) >= ut_strlen(":max:")
&& 0 == ut_memcmp(str, (char*)":max:",
ut_strlen(":max:"))) {
if (0 == memcmp(str, ":max:", (sizeof ":max:") - 1)) {
str += ut_strlen(":max:");
str += (sizeof ":max:") - 1;
size = strtoul(str, &endp, 10);
......@@ -198,10 +194,7 @@ srv_parse_data_file_paths_and_sizes(
str += 3;
}
if (strlen(str) >= 3
&& *str == 'r'
&& *(str + 1) == 'a'
&& *(str + 2) == 'w') {
if (*str == 'r' && *(str + 1) == 'a' && *(str + 2) == 'w') {
str += 3;
}
......@@ -263,19 +256,15 @@ srv_parse_data_file_paths_and_sizes(
(*data_file_names)[i] = path;
(*data_file_sizes)[i] = size;
if (strlen(str) >= ut_strlen(":autoextend")
&& 0 == ut_memcmp(str, (char*)":autoextend",
ut_strlen(":autoextend"))) {
if (0 == memcmp(str, ":autoextend", (sizeof ":autoextend") - 1)) {
*is_auto_extending = TRUE;
str += ut_strlen(":autoextend");
str += (sizeof ":autoextend") - 1;
if (strlen(str) >= ut_strlen(":max:")
&& 0 == ut_memcmp(str, (char*)":max:",
ut_strlen(":max:"))) {
if (0 == memcmp(str, ":max:", (sizeof ":max:") - 1)) {
str += ut_strlen(":max:");
str += (sizeof ":max:") - 1;
size = strtoul(str, &endp, 10);
......@@ -309,10 +298,7 @@ srv_parse_data_file_paths_and_sizes(
(*data_file_is_raw_partition)[i] = SRV_NEW_RAW;
}
if (strlen(str) >= 3
&& *str == 'r'
&& *(str + 1) == 'a'
&& *(str + 2) == 'w') {
if (*str == 'r' && *(str + 1) == 'a' && *(str + 2) == 'w') {
str += 3;
if ((*data_file_is_raw_partition)[i] == 0) {
......@@ -454,12 +440,10 @@ srv_normalize_path_for_win(
char* str __attribute__((unused))) /* in/out: null-terminated character string */
{
#ifdef __WIN__
ulint i;
for (; *str; str++) {
for (i = 0; i < ut_strlen(str); i++) {
if (str[i] == '/') {
str[i] = '\\';
if (*str == '/') {
*str = '\\';
}
}
#endif
......@@ -528,8 +512,6 @@ ulint
open_or_create_log_file(
/*====================*/
/* out: DB_SUCCESS or error code */
ibool create_new_db, /* in: TRUE if we should create a
new database */
ibool* log_file_created, /* out: TRUE if new log file
created */
ibool log_file_has_been_opened,/* in: TRUE if a log file has been
......@@ -544,8 +526,6 @@ open_or_create_log_file(
ulint size_high;
char name[10000];
UT_NOT_USED(create_new_db);
*log_file_created = FALSE;
srv_normalize_path_for_win(srv_log_group_home_dirs[k]);
......@@ -1149,8 +1129,7 @@ NetWare. */
for (i = 0; i < srv_n_log_files; i++) {
err = open_or_create_log_file(create_new_db,
&log_file_created,
err = open_or_create_log_file(&log_file_created,
log_opened, k, i);
if (err != DB_SUCCESS) {
......
......@@ -301,8 +301,7 @@ trx_savepoint_for_mysql(
savep = mem_alloc(sizeof(trx_named_savept_t));
savep->name = mem_alloc(1 + ut_strlen(savepoint_name));
ut_memcpy(savep->name, savepoint_name, 1 + ut_strlen(savepoint_name));
savep->name = mem_strdup(savepoint_name);
savep->savept = trx_savept_take(trx);
......
......@@ -576,8 +576,7 @@ trx_sys_update_mysql_binlog_offset(
MLOG_4BYTES, mtr);
}
if (0 != ut_memcmp(sys_header + field + TRX_SYS_MYSQL_LOG_NAME,
file_name, 1 + ut_strlen(file_name))) {
if (0 != strcmp(sys_header + field + TRX_SYS_MYSQL_LOG_NAME, file_name)) {
mlog_write_string((byte*) (sys_header + field
+ TRX_SYS_MYSQL_LOG_NAME),
......
......@@ -36,9 +36,9 @@ Copies a string to a memory location, setting characters to lower case. */
void
ut_cpy_in_lower_case(
/*=================*/
char* dest, /* in: destination */
char* source,/* in: source */
ulint len) /* in: string length */
char* dest, /* in: destination */
const char* source, /* in: source */
ulint len) /* in: string length */
{
ulint i;
......@@ -53,23 +53,27 @@ Compares two strings when converted to lower case. */
int
ut_cmp_in_lower_case(
/*=================*/
/* out: -1, 0, 1 if str1 < str2, str1 == str2,
str1 > str2, respectively */
char* str1, /* in: string1 */
char* str2, /* in: string2 */
ulint len) /* in: length of both strings */
/* out: -1, 0, 1 if str1 < str2, str1 == str2,
str1 > str2, respectively */
const char* str1, /* in: string1 */
const char* str2) /* in: string2 */
{
ulint i;
for (i = 0; i < len; i++) {
if (tolower(str1[i]) < tolower(str2[i])) {
return(-1);
}
if (tolower(str1[i]) > tolower(str2[i])) {
return(1);
}
}
for (;;) {
int c1, c2;
if (!*str1) {
return(*str2 ? -1 : 0);
} else if (!*str2) {
return 1;
}
c1 = tolower(*str1++);
c2 = tolower(*str2++);
if (c1 < c2) {
return(-1);
}
if (c1 > c2) {
return(1);
}
}
return(0);
return(0);
}
......@@ -106,7 +106,7 @@ ut_malloc_low(
/* Make an intentional seg fault so that we get a stack
trace */
printf("%lu\n", *ut_mem_null_ptr);
if (*ut_mem_null_ptr) ut_mem_null_ptr = 0;
}
if (set_to_zero) {
......@@ -194,6 +194,49 @@ ut_free_all_mem(void)
}
}
/**************************************************************************
Make a quoted copy of a string. */
char*
ut_strcpyq(
/*=======*/
/* out: pointer to end of dest */
char* dest, /* in: output buffer */
char q, /* in: the quote character */
const char* src) /* in: null-terminated string */
{
while (*src) {
if ((*dest++ = *src++) == q) {
*dest++ = q;
}
}
return(dest);
}
/**************************************************************************
Make a quoted copy of a fixed-length string. */
char*
ut_memcpyq(
/*=======*/
/* out: pointer to end of dest */
char* dest, /* in: output buffer */
char q, /* in: the quote character */
const char* src, /* in: string to be quoted */
ulint len) /* in: length of src */
{
const char* srcend = src + len;
while (src < srcend) {
if ((*dest++ = *src++) == q) {
*dest++ = q;
}
}
return(dest);
}
/**************************************************************************
Catenates two strings into newly allocated memory. The memory must be freed
using mem_free. */
......@@ -215,9 +258,7 @@ ut_str_catenate(
str = mem_alloc(len1 + len2 + 1);
ut_memcpy(str, str1, len1);
ut_memcpy(str + len1, str2, len2);
str[len1 + len2] = '\0';
ut_memcpy(str + len1, str2, len2 + 1);
return(str);
}
......@@ -3298,12 +3298,9 @@ create_index(
field = form->field[j];
if (strlen(field->field_name)
== strlen(key_part->field->field_name)
&& 0 == ut_cmp_in_lower_case(
if (0 == ut_cmp_in_lower_case(
(char*)field->field_name,
(char*)key_part->field->field_name,
strlen(field->field_name))) {
(char*)key_part->field->field_name)) {
/* Found the corresponding column */
break;
......
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