diff options
author | unknown <serg@sergbook.mysql.com> | 2007-04-16 10:37:50 +0200 |
---|---|---|
committer | unknown <serg@sergbook.mysql.com> | 2007-04-16 10:37:50 +0200 |
commit | 7cb8a33b1af33dcd8806ec6021655a39f375d904 (patch) | |
tree | df4c92bcf5668ec88685604378ad6dc60bfcf269 /mysys/array.c | |
parent | 2e73a53e033741b09a652646d9cfa0e76c33e6a1 (diff) | |
parent | add378761542ade65340b9477ed298e9a1677b10 (diff) | |
download | mariadb-git-7cb8a33b1af33dcd8806ec6021655a39f375d904.tar.gz |
Merge bk-internal.mysql.com:/home/bk/mysql-5.1
into sergbook.mysql.com:/usr/home/serg/Abk/mysql-5.1-wl2936
client/mysql.cc:
Auto merged
include/my_global.h:
Auto merged
include/my_sys.h:
Auto merged
include/mysql.h:
Auto merged
mysql-test/r/im_utils.result:
Auto merged
mysql-test/r/variables.result:
Auto merged
mysql-test/t/ndb_dd_basic.test:
Auto merged
mysql-test/t/partition_innodb.test:
Auto merged
mysql-test/t/variables.test:
Auto merged
mysys/array.c:
Auto merged
mysys/typelib.c:
Auto merged
sql/event_queue.cc:
Auto merged
sql/ha_partition.cc:
Auto merged
sql/ha_partition.h:
Auto merged
sql/handler.cc:
Auto merged
sql/handler.h:
Auto merged
sql/item_func.cc:
Auto merged
sql/item_sum.cc:
Auto merged
sql/log.cc:
Auto merged
sql/mysql_priv.h:
Auto merged
sql/set_var.h:
Auto merged
sql/sql_base.cc:
Auto merged
sql/sql_cache.cc:
Auto merged
sql/sql_class.h:
Auto merged
sql/sql_delete.cc:
Auto merged
sql/sql_insert.cc:
Auto merged
sql/sql_lex.cc:
Auto merged
sql/sql_lex.h:
Auto merged
sql/sql_parse.cc:
Auto merged
sql/sql_partition.cc:
Auto merged
sql/sql_plugin.cc:
Auto merged
sql/sql_repl.cc:
Auto merged
sql/sql_select.cc:
Auto merged
sql/sql_show.cc:
Auto merged
sql/sql_table.cc:
Auto merged
sql/table.cc:
Auto merged
sql/table.h:
Auto merged
storage/example/ha_example.cc:
Auto merged
storage/federated/ha_federated.cc:
Auto merged
storage/heap/ha_heap.cc:
Auto merged
storage/innobase/include/trx0trx.h:
Auto merged
storage/myisam/ha_myisam.cc:
Auto merged
storage/myisammrg/ha_myisammrg.cc:
Auto merged
storage/ndb/src/mgmsrv/InitConfigFileParser.cpp:
Auto merged
include/typelib.h:
merged
mysql-test/mysql-test-run.pl:
merged
mysql-test/r/flush2.result:
merged
mysql-test/r/ndb_dd_basic.result:
merged
mysql-test/r/partition_innodb.result:
merged
mysql-test/r/ps_1general.result:
merged
mysql-test/t/ps_1general.test:
merged
sql/ha_ndbcluster.cc:
merged
sql/item_create.cc:
merged
sql/mysqld.cc:
merged
sql/rpl_utility.h:
merged
sql/set_var.cc:
merged
sql/sql_class.cc:
merged
sql/sql_yacc.yy:
merged
storage/innobase/handler/ha_innodb.cc:
merged
storage/innobase/handler/ha_innodb.h:
merged
Diffstat (limited to 'mysys/array.c')
-rw-r--r-- | mysys/array.c | 62 |
1 files changed, 59 insertions, 3 deletions
diff --git a/mysys/array.c b/mysys/array.c index 60f5b255e18..130a8f358de 100644 --- a/mysys/array.c +++ b/mysys/array.c @@ -22,9 +22,10 @@ Initiate dynamic array SYNOPSIS - init_dynamic_array() + 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 @@ -32,14 +33,15 @@ init_dynamic_array() initiates array and allocate space for init_alloc eilements. Array is usable even if space allocation failed. + Static buffers must begin immediately after the array structure. RETURN VALUE TRUE my_malloc_ci() failed FALSE Ok */ -my_bool init_dynamic_array(DYNAMIC_ARRAY *array, uint element_size, - uint init_alloc, +my_bool init_dynamic_array2(DYNAMIC_ARRAY *array, uint element_size, + void *init_buffer, uint init_alloc, uint alloc_increment CALLER_INFO_PROTO) { DBUG_ENTER("init_dynamic_array"); @@ -51,11 +53,16 @@ my_bool init_dynamic_array(DYNAMIC_ARRAY *array, uint element_size, } if (!init_alloc) + { init_alloc=alloc_increment; + init_buffer= 0; + } array->elements=0; array->max_element=init_alloc; array->alloc_increment=alloc_increment; array->size_of_element=element_size; + if ((array->buffer= init_buffer)) + DBUG_RETURN(FALSE); if (!(array->buffer=(char*) my_malloc_ci(element_size*init_alloc,MYF(MY_WME)))) { array->max_element=0; @@ -64,6 +71,14 @@ my_bool init_dynamic_array(DYNAMIC_ARRAY *array, uint element_size, DBUG_RETURN(FALSE); } +my_bool init_dynamic_array(DYNAMIC_ARRAY *array, uint element_size, + uint init_alloc, + uint alloc_increment CALLER_INFO_PROTO) +{ + /* 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. @@ -117,6 +132,21 @@ byte *alloc_dynamic(DYNAMIC_ARRAY *array) if (array->elements == array->max_element) { char *new_ptr; + if (array->buffer == (char *)(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((array->max_element+ + array->alloc_increment) * + 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,(array->max_element+ array->alloc_increment)* array->size_of_element, @@ -176,6 +206,20 @@ my_bool set_dynamic(DYNAMIC_ARRAY *array, gptr element, uint idx) char *new_ptr; size=(idx+array->alloc_increment)/array->alloc_increment; size*= array->alloc_increment; + if (array->buffer == (char *)(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)))) @@ -226,6 +270,12 @@ void get_dynamic(DYNAMIC_ARRAY *array, gptr element, uint idx) void delete_dynamic(DYNAMIC_ARRAY *array) { + /* + Just mark as empty if we are using a static buffer + */ + if (array->buffer == (char *)(array + 1)) + array->elements= 0; + else if (array->buffer) { my_free(array->buffer,MYF(MY_WME)); @@ -265,6 +315,12 @@ void freeze_size(DYNAMIC_ARRAY *array) { uint elements=max(array->elements,1); + /* + Do nothing if we are using a static buffer + */ + if (array->buffer == (char *)(array + 1)) + return; + if (array->buffer && array->max_element != elements) { array->buffer=(char*) my_realloc(array->buffer, |