21 #include "thr_malloc.h"
22 #include "sql_class.h"
29 extern "C" void sql_alloc_error_handler(
void);
31 void init_sql_alloc(
MEM_ROOT *mem_root, uint block_size, uint pre_alloc)
33 init_alloc_root(mem_root, block_size, pre_alloc);
34 mem_root->error_handler=sql_alloc_error_handler;
38 void *sql_alloc(
size_t Size)
41 return alloc_root(root,Size);
45 void *sql_calloc(
size_t size)
48 if ((ptr=sql_alloc(size)))
54 char *sql_strdup(
const char *str)
56 size_t len= strlen(str)+1;
58 if ((pos= (
char*) sql_alloc(len)))
64 char *sql_strmake(
const char *str,
size_t len)
67 if ((pos= (
char*) sql_alloc(len+1)))
76 void* sql_memdup(
const void *ptr,
size_t len)
79 if ((pos= sql_alloc(len)))
85 char *sql_strmake_with_convert(
const char *str,
size_t arg_length,
87 size_t max_res_length,
91 size_t new_length= to_cs->mbmaxlen*arg_length;
94 set_if_smaller(new_length, max_res_length);
95 if (!(pos= (
char*) sql_alloc(new_length+1)))
98 if ((from_cs == &my_charset_bin) || (to_cs == &my_charset_bin))
101 new_length= min(arg_length, max_res_length);
102 memcpy(pos, str, new_length);
107 new_length= copy_and_convert((
char*) pos, new_length, to_cs, str,
108 arg_length, from_cs, &dummy_errors);
111 *result_length= new_length;