mirror of
https://github.com/MariaDB/server.git
synced 2025-07-30 16:24:05 +03:00
Moved a lot of old bug fixes and safe cleanups from Maria 5.1 tree to 5.1
- Reserver namespace and place in frm for TABLE_CHECKSUM and PAGE_CHECKSUM create options - Added syncing of directory when creating .frm files - Portability fixes - Added missing cast that could cause bugs - Code cleanups - Made some bit functions inline - Moved things out of myisam.h to my_handler.h to make them more accessable - Renamed some myisam variables and defines to make them more globaly usable (as they are used outside of MyISAM) - Fixed bugs in error conditions - Use compiler time asserts instead of run time - Fixed indentation HA_EXTRA_PREPARE_FOR_DELETE -> HA_EXTRA_PREPARE_FOR_DROP as the old name was wrong (Added a define for old value to ensure we don't break any old code) Added HA_EXTRA_PREPARE_FOR_RENAME as a signal for rename (before we used a DROP signal which is wrong) - Initialize error messages early to get better errors when mysqld or an engine fails to start - Fix windows bug that query_performance_frequency was not initialized if registry code failed - thread_stack -> my_thread_stack_size
This commit is contained in:
@ -63,7 +63,8 @@ my_bool init_dynamic_array2(DYNAMIC_ARRAY *array, uint element_size,
|
||||
array->size_of_element=element_size;
|
||||
if ((array->buffer= init_buffer))
|
||||
DBUG_RETURN(FALSE);
|
||||
if (!(array->buffer=(uchar*) my_malloc_ci(element_size*init_alloc,MYF(MY_WME))))
|
||||
if (!(array->buffer=(uchar*) my_malloc_ci(element_size*init_alloc,
|
||||
MYF(MY_WME))))
|
||||
{
|
||||
array->max_element=0;
|
||||
DBUG_RETURN(TRUE);
|
||||
@ -179,7 +180,7 @@ uchar *pop_dynamic(DYNAMIC_ARRAY *array)
|
||||
}
|
||||
|
||||
/*
|
||||
Replace elemnent in array with given element and index
|
||||
Replace element in array with given element and index
|
||||
|
||||
SYNOPSIS
|
||||
set_dynamic()
|
||||
@ -200,42 +201,69 @@ my_bool set_dynamic(DYNAMIC_ARRAY *array, uchar* element, uint idx)
|
||||
{
|
||||
if (idx >= array->elements)
|
||||
{
|
||||
if (idx >= array->max_element)
|
||||
{
|
||||
uint size;
|
||||
char *new_ptr;
|
||||
size=(idx+array->alloc_increment)/array->alloc_increment;
|
||||
size*= array->alloc_increment;
|
||||
if (array->buffer == (uchar *)(array + 1))
|
||||
{
|
||||
/*
|
||||
In this senerio, the buffer is statically preallocated,
|
||||
so we have to create an all-new malloc since we overflowed
|
||||
*/
|
||||
if (!(new_ptr= (char *) my_malloc(size *
|
||||
array->size_of_element,
|
||||
MYF(MY_WME))))
|
||||
return 0;
|
||||
memcpy(new_ptr, array->buffer,
|
||||
array->elements * array->size_of_element);
|
||||
}
|
||||
else
|
||||
if (!(new_ptr=(char*) my_realloc(array->buffer,size*
|
||||
array->size_of_element,
|
||||
MYF(MY_WME | MY_ALLOW_ZERO_PTR))))
|
||||
return TRUE;
|
||||
array->buffer= (uchar*) new_ptr;
|
||||
array->max_element=size;
|
||||
}
|
||||
if (idx >= array->max_element && allocate_dynamic(array, idx))
|
||||
return TRUE;
|
||||
bzero((uchar*) (array->buffer+array->elements*array->size_of_element),
|
||||
(idx - array->elements)*array->size_of_element);
|
||||
(idx - array->elements)*array->size_of_element);
|
||||
array->elements=idx+1;
|
||||
}
|
||||
memcpy(array->buffer+(idx * array->size_of_element),element,
|
||||
(size_t) array->size_of_element);
|
||||
(size_t) array->size_of_element);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
Ensure that dynamic array has enough elements
|
||||
|
||||
SYNOPSIS
|
||||
allocate_dynamic()
|
||||
array
|
||||
max_elements Numbers of elements that is needed
|
||||
|
||||
NOTES
|
||||
Any new allocated element are NOT initialized
|
||||
|
||||
RETURN VALUE
|
||||
FALSE Ok
|
||||
TRUE Allocation of new memory failed
|
||||
*/
|
||||
|
||||
my_bool allocate_dynamic(DYNAMIC_ARRAY *array, uint max_elements)
|
||||
{
|
||||
if (max_elements >= array->max_element)
|
||||
{
|
||||
uint size;
|
||||
uchar *new_ptr;
|
||||
size= (max_elements + array->alloc_increment)/array->alloc_increment;
|
||||
size*= array->alloc_increment;
|
||||
if (array->buffer == (uchar *)(array + 1))
|
||||
{
|
||||
/*
|
||||
In this senerio, the buffer is statically preallocated,
|
||||
so we have to create an all-new malloc since we overflowed
|
||||
*/
|
||||
if (!(new_ptr= (uchar *) my_malloc(size *
|
||||
array->size_of_element,
|
||||
MYF(MY_WME))))
|
||||
return 0;
|
||||
memcpy(new_ptr, array->buffer,
|
||||
array->elements * array->size_of_element);
|
||||
}
|
||||
else
|
||||
|
||||
|
||||
if (!(new_ptr= (uchar*) my_realloc(array->buffer,size*
|
||||
array->size_of_element,
|
||||
MYF(MY_WME | MY_ALLOW_ZERO_PTR))))
|
||||
return TRUE;
|
||||
array->buffer= new_ptr;
|
||||
array->max_element= size;
|
||||
}
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
Get an element from array by given index
|
||||
|
||||
|
Reference in New Issue
Block a user