diff options
author | Sergei Golubchik <sergii@pisem.net> | 2013-01-31 09:48:19 +0100 |
---|---|---|
committer | Sergei Golubchik <sergii@pisem.net> | 2013-01-31 09:48:19 +0100 |
commit | ab83952f293ea46c00e421c81b81a394c9cae2b4 (patch) | |
tree | 6a3e995bd1330828a0e988d896bca218863fc74c /mysys/array.c | |
parent | 055b62f404ee0a0463ee8ff98a0e24c083b95f1d (diff) | |
parent | 5267af5e9e5e601d4f4b1ef40730da1e36d38d9d (diff) | |
download | mariadb-git-ab83952f293ea46c00e421c81b81a394c9cae2b4.tar.gz |
10.0-base merge
Diffstat (limited to 'mysys/array.c')
-rw-r--r-- | mysys/array.c | 34 |
1 files changed, 16 insertions, 18 deletions
diff --git a/mysys/array.c b/mysys/array.c index 94f1cb8de34..60f2202f5b3 100644 --- a/mysys/array.c +++ b/mysys/array.c @@ -22,15 +22,16 @@ Initiate dynamic array SYNOPSIS - init_dynamic_array2() + my_init_dynamic_array2() array Pointer to an array element_size Size of element init_buffer Initial buffer pointer init_alloc Number of initial elements alloc_increment Increment for adding new elements + my_flags Flags to my_malloc DESCRIPTION - init_dynamic_array() initiates array and allocate space for + my_init_dynamic_array2() initiates array and allocate space for init_alloc eilements. Array is usable even if space allocation failed, hence, the function never returns TRUE. @@ -40,11 +41,11 @@ FALSE Ok */ -my_bool init_dynamic_array2(DYNAMIC_ARRAY *array, uint element_size, +my_bool my_init_dynamic_array2(DYNAMIC_ARRAY *array, uint element_size, void *init_buffer, uint init_alloc, - uint alloc_increment) + uint alloc_increment, myf my_flags) { - DBUG_ENTER("init_dynamic_array2"); + DBUG_ENTER("my_init_dynamic_array2"); if (!alloc_increment) { alloc_increment=max((8192-MALLOC_OVERHEAD)/element_size,16); @@ -55,6 +56,7 @@ my_bool init_dynamic_array2(DYNAMIC_ARRAY *array, uint element_size, array->max_element=init_alloc; array->alloc_increment=alloc_increment; array->size_of_element=element_size; + array->malloc_flags= my_flags; if ((array->buffer= init_buffer)) DBUG_RETURN(FALSE); /* @@ -62,18 +64,12 @@ my_bool init_dynamic_array2(DYNAMIC_ARRAY *array, uint element_size, should not throw an error */ if (init_alloc && - !(array->buffer= (uchar*) my_malloc(element_size*init_alloc, MYF(0)))) + !(array->buffer= (uchar*) my_malloc(element_size*init_alloc, + MYF(my_flags)))) array->max_element=0; DBUG_RETURN(FALSE); } -my_bool init_dynamic_array(DYNAMIC_ARRAY *array, uint element_size, - uint init_alloc, uint alloc_increment) -{ - /* placeholder to preserve ABI */ - return my_init_dynamic_array_ci(array, element_size, init_alloc, - alloc_increment); -} /* Insert element at the end of array. Allocate memory if needed. @@ -137,7 +133,7 @@ void *alloc_dynamic(DYNAMIC_ARRAY *array) if (!(new_ptr= (char *) my_malloc((array->max_element+ array->alloc_increment) * array->size_of_element, - MYF(MY_WME)))) + MYF(array->malloc_flags | MY_WME)))) DBUG_RETURN(0); memcpy(new_ptr, array->buffer, array->elements * array->size_of_element); @@ -146,7 +142,8 @@ void *alloc_dynamic(DYNAMIC_ARRAY *array) my_realloc(array->buffer,(array->max_element+ array->alloc_increment)* array->size_of_element, - MYF(MY_WME | MY_ALLOW_ZERO_PTR)))) + MYF(MY_WME | MY_ALLOW_ZERO_PTR | + array->malloc_flags)))) DBUG_RETURN(0); array->buffer= (uchar*) new_ptr; array->max_element+=array->alloc_increment; @@ -242,14 +239,15 @@ my_bool allocate_dynamic(DYNAMIC_ARRAY *array, uint max_elements) */ if (!(new_ptr= (uchar *) my_malloc(size * array->size_of_element, - MYF(MY_WME)))) + MYF(array->malloc_flags | MY_WME)))) DBUG_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)))) + MYF(MY_WME | MY_ALLOW_ZERO_PTR | + array->malloc_flags)))) DBUG_RETURN(TRUE); array->buffer= new_ptr; array->max_element= size; @@ -347,7 +345,7 @@ void freeze_size(DYNAMIC_ARRAY *array) { array->buffer=(uchar*) my_realloc(array->buffer, elements*array->size_of_element, - MYF(MY_WME)); + MYF(MY_WME | array->malloc_flags)); array->max_element=elements; } } |