diff options
author | Sergey Petrunya <psergey@askmonty.org> | 2010-10-10 17:18:11 +0300 |
---|---|---|
committer | Sergey Petrunya <psergey@askmonty.org> | 2010-10-10 17:18:11 +0300 |
commit | 72dd7575cd8b9372ddb79cc4c94050e4ee1e5ee1 (patch) | |
tree | 220c965bb467b020a4db171d7803586f9ed22cea /mysys | |
parent | cfbd9270243e4b429cdc26e8554bcc99690f2422 (diff) | |
parent | 00a2f36bbf22a4d8b2367724e7919c0603cf6f71 (diff) | |
download | mariadb-git-72dd7575cd8b9372ddb79cc4c94050e4ee1e5ee1.tar.gz |
Merge 5.2->5.3
- Re-commit Monty's merge, partially fixed by Igor and SergeyP,
but still broken
Diffstat (limited to 'mysys')
-rw-r--r-- | mysys/CMakeLists.txt | 2 | ||||
-rw-r--r-- | mysys/Makefile.am | 4 | ||||
-rw-r--r-- | mysys/charset.c | 4 | ||||
-rw-r--r-- | mysys/errors.c | 4 | ||||
-rw-r--r-- | mysys/mf_iocache.c | 11 | ||||
-rw-r--r-- | mysys/mf_keycache.c | 2 | ||||
-rw-r--r-- | mysys/mf_pack.c | 12 | ||||
-rw-r--r-- | mysys/mf_soundex.c | 2 | ||||
-rw-r--r-- | mysys/mf_wfile.c | 2 | ||||
-rw-r--r-- | mysys/my_alloc.c | 18 | ||||
-rw-r--r-- | mysys/my_bitmap.c | 191 | ||||
-rw-r--r-- | mysys/my_copy.c | 33 | ||||
-rw-r--r-- | mysys/my_gethwaddr.c | 2 | ||||
-rw-r--r-- | mysys/my_getopt.c | 54 | ||||
-rw-r--r-- | mysys/my_getwd.c | 10 | ||||
-rw-r--r-- | mysys/my_handler.c | 1 | ||||
-rw-r--r-- | mysys/my_malloc.c | 12 | ||||
-rw-r--r-- | mysys/my_redel.c | 37 | ||||
-rw-r--r-- | mysys/my_static.c | 1 | ||||
-rw-r--r-- | mysys/my_sync.c | 5 | ||||
-rw-r--r-- | mysys/safemalloc.c | 12 | ||||
-rw-r--r-- | mysys/stacktrace.c | 4 | ||||
-rw-r--r-- | mysys/thr_alarm.c | 9 | ||||
-rw-r--r-- | mysys/thr_lock.c | 3 |
24 files changed, 282 insertions, 153 deletions
diff --git a/mysys/CMakeLists.txt b/mysys/CMakeLists.txt index e9873fb0525..bf0c6551a11 100644 --- a/mysys/CMakeLists.txt +++ b/mysys/CMakeLists.txt @@ -49,4 +49,6 @@ SET(MYSYS_SOURCES array.c charset-def.c charset.c checksum.c default.c default_ IF(NOT SOURCE_SUBLIBS) ADD_LIBRARY(mysys ${MYSYS_SOURCES}) + + INSTALL(TARGETS mysys DESTINATION lib/opt COMPONENT runtime) # TODO: Component? ENDIF(NOT SOURCE_SUBLIBS) diff --git a/mysys/Makefile.am b/mysys/Makefile.am index 337fc86c12e..95358883f4e 100644 --- a/mysys/Makefile.am +++ b/mysys/Makefile.am @@ -147,7 +147,3 @@ test_base64$(EXEEXT): base64.c $(LIBRARIES) test_thr_mutex$(EXEEXT): test_thr_mutex.c $(LIBRARIES) $(LINK) $(FLAGS) $(srcdir)/test_thr_mutex.c $(LDADD) $(LIBS) - - -# Don't update the files from bitkeeper -%::SCCS/s.% diff --git a/mysys/charset.c b/mysys/charset.c index 7cf8a8b828d..153ef8b7e2c 100644 --- a/mysys/charset.c +++ b/mysys/charset.c @@ -406,9 +406,9 @@ static my_pthread_once_t charsets_template= MY_PTHREAD_ONCE_INIT; static void init_available_charsets(void) { char fname[FN_REFLEN + sizeof(MY_CHARSET_INDEX)]; - struct charset_info_st **cs; + struct charset_info_st **cs; - bzero(&all_charsets,sizeof(all_charsets)); + bzero((char*) &all_charsets,sizeof(all_charsets)); init_compiled_charsets(MYF(0)); /* Copy compiled charsets */ diff --git a/mysys/errors.c b/mysys/errors.c index fc63ac9d936..4c568952ee3 100644 --- a/mysys/errors.c +++ b/mysys/errors.c @@ -50,6 +50,8 @@ const char * NEAR globerrs[GLOBERRS]= "Collation '%s' is not a compiled collation and is not specified in the '%s' file", "File '%s' not found (Errcode: %d)", "File '%s' (fileno: %d) was not closed", + "Can't change ownership of the file '%s' (Errcode: %d)", + "Can't change permissions of the file '%s' (Errcode: %d)", "Can't change mode for file '%s' to 0x%lx (Error: %d)", "Can't do seek on file '%s' (Errcode: %d)", "Warning: Can't copy ownership for file '%s' (Error: %d)" @@ -93,6 +95,8 @@ void init_glob_errs() EE(EE_UNKNOWN_COLLATION)= "Collation '%s' is not a compiled collation and is not specified in the %s file"; EE(EE_FILENOTFOUND) = "File '%s' not found (Errcode: %d)"; EE(EE_FILE_NOT_CLOSED) = "File '%s' (fileno: %d) was not closed"; + EE(EE_CHANGE_OWNERSHIP) = "Can't change ownership of the file '%s' (Errcode: %d)"; + EE(EE_CHANGE_PERMISSIONS) = "Can't change permissions of the file '%s' (Errcode: %d)"; EE(EE_CANT_CHMOD) = "Can't change mode for file '%s' to 0x%lx (Error: %d)"; EE(EE_CANT_SEEK) = "Can't do seek on file '%s' (Errcode: %d)"; EE(EE_CANT_COPY_OWNERSHIP)= "Warning: Can't copy ownership for file '%s' (Error: %d)"; diff --git a/mysys/mf_iocache.c b/mysys/mf_iocache.c index 59872961523..3824669365f 100644 --- a/mysys/mf_iocache.c +++ b/mysys/mf_iocache.c @@ -1701,16 +1701,19 @@ int my_block_write(register IO_CACHE *info, const uchar *Buffer, size_t Count, #endif -int my_b_flush_io_cache(IO_CACHE *info, int need_append_buffer_lock) +int my_b_flush_io_cache(IO_CACHE *info, + int need_append_buffer_lock __attribute__((unused))) { size_t length; - my_bool append_cache; my_off_t pos_in_file; + my_bool append_cache= (info->type == SEQ_READ_APPEND); DBUG_ENTER("my_b_flush_io_cache"); DBUG_PRINT("enter", ("cache: 0x%lx", (long) info)); - if (!(append_cache = (info->type == SEQ_READ_APPEND))) - need_append_buffer_lock=0; +#ifdef THREAD + if (!append_cache) + need_append_buffer_lock= 0; +#endif if (info->type == WRITE_CACHE || append_cache) { diff --git a/mysys/mf_keycache.c b/mysys/mf_keycache.c index 4e22b3f65a2..08c160910c7 100644 --- a/mysys/mf_keycache.c +++ b/mysys/mf_keycache.c @@ -5106,7 +5106,7 @@ static SIMPLE_KEY_CACHE_CB ulonglong* dirty_part_map) { uint i= KEYCACHE_BASE_EXPR( file, filepos) % keycache->partitions; - *dirty_part_map|= 1<<i; + *dirty_part_map|= 1ULL << i; return keycache->partition_array[i]; } diff --git a/mysys/mf_pack.c b/mysys/mf_pack.c index 4f7cd90e8aa..86fd61537e7 100644 --- a/mysys/mf_pack.c +++ b/mysys/mf_pack.c @@ -52,7 +52,7 @@ void pack_dirname(char * to, const char *from) buff_length= strlen(buff); d_length= (size_t) (start-to); if ((start == to || - (buff_length == d_length && !bcmp(buff,start,d_length))) && + (buff_length == d_length && !memcmp(buff,start,d_length))) && *start != FN_LIBCHAR && *start) { /* Put current dir before */ bchange((uchar*) to, d_length, (uchar*) buff, buff_length, strlen(to)+1); @@ -70,7 +70,7 @@ void pack_dirname(char * to, const char *from) } if (length > 1 && length < d_length) { /* test if /xx/yy -> ~/yy */ - if (bcmp(to,home_dir,length) == 0 && to[length] == FN_LIBCHAR) + if (memcmp(to,home_dir,length) == 0 && to[length] == FN_LIBCHAR) { to[0]=FN_HOMELIB; /* Filename begins with ~ */ (void) strmov_overlapp(to+1,to+length); @@ -80,7 +80,7 @@ void pack_dirname(char * to, const char *from) { /* Test if cwd is ~/... */ if (length > 1 && length < buff_length) { - if (bcmp(buff,home_dir,length) == 0 && buff[length] == FN_LIBCHAR) + if (memcmp(buff,home_dir,length) == 0 && buff[length] == FN_LIBCHAR) { buff[0]=FN_HOMELIB; (void) strmov_overlapp(buff+1,buff+length); @@ -166,7 +166,7 @@ size_t cleanup_dirname(register char *to, const char *from) *pos = FN_LIBCHAR; if (*pos == FN_LIBCHAR) { - if ((size_t) (pos-start) > length && bcmp(pos-length,parent,length) == 0) + if ((size_t) (pos-start) > length && memcmp(pos-length,parent,length) == 0) { /* If .../../; skip prev */ pos-=length; if (pos != start) @@ -197,7 +197,7 @@ size_t cleanup_dirname(register char *to, const char *from) end_parentdir=pos; while (pos >= start && *pos != FN_LIBCHAR) /* remove prev dir */ pos--; - if (pos[1] == FN_HOMELIB || bcmp(pos,parent,length) == 0) + if (pos[1] == FN_HOMELIB || memcmp(pos,parent,length) == 0) { /* Don't remove ~user/ */ pos=strmov(end_parentdir+1,parent); *pos=FN_LIBCHAR; @@ -206,7 +206,7 @@ size_t cleanup_dirname(register char *to, const char *from) } } else if ((size_t) (pos-start) == length-1 && - !bcmp(start,parent+1,length-1)) + !memcmp(start,parent+1,length-1)) start=pos; /* Starts with "../" */ else if (pos-start > 0 && pos[-1] == FN_LIBCHAR) { diff --git a/mysys/mf_soundex.c b/mysys/mf_soundex.c index fe30d8c81af..3a3dab52dd6 100644 --- a/mysys/mf_soundex.c +++ b/mysys/mf_soundex.c @@ -47,7 +47,7 @@ void soundex(CHARSET_INFO * cs,register char * out_pntr, char * in_pntr, { char ch,last_ch; reg3 char * end; - register uchar *map=cs->to_upper; + register const uchar *map=cs->to_upper; if (remove_garbage) { diff --git a/mysys/mf_wfile.c b/mysys/mf_wfile.c index f98d348994e..4a4fb466600 100644 --- a/mysys/mf_wfile.c +++ b/mysys/mf_wfile.c @@ -119,6 +119,6 @@ void wf_end(WF_PACK *buffer) { DBUG_ENTER("wf_end"); if (buffer) - my_free((uchar*) buffer,MYF(0)); + my_free(buffer, MYF(0)); DBUG_VOID_RETURN; } /* wf_end */ diff --git a/mysys/my_alloc.c b/mysys/my_alloc.c index 8d3bc0c3fb2..948d3a8476d 100644 --- a/mysys/my_alloc.c +++ b/mysys/my_alloc.c @@ -153,6 +153,14 @@ void *alloc_root(MEM_ROOT *mem_root, size_t length) DBUG_ASSERT(alloc_root_inited(mem_root)); + DBUG_EXECUTE_IF("simulate_out_of_memory", + { + if (mem_root->error_handler) + (*mem_root->error_handler)(); + DBUG_SET("-d,simulate_out_of_memory"); + DBUG_RETURN((void*) 0); /* purecov: inspected */ + }); + length+=ALIGN_SIZE(sizeof(USED_MEM)); if (!(next = (USED_MEM*) my_malloc(length,MYF(MY_WME)))) { @@ -175,6 +183,14 @@ void *alloc_root(MEM_ROOT *mem_root, size_t length) DBUG_PRINT("enter",("root: 0x%lx", (long) mem_root)); DBUG_ASSERT(alloc_root_inited(mem_root)); + DBUG_EXECUTE_IF("simulate_out_of_memory", + { + /* Avoid reusing an already allocated block */ + if (mem_root->error_handler) + (*mem_root->error_handler)(); + DBUG_SET("-d,simulate_out_of_memory"); + DBUG_RETURN((void*) 0); /* purecov: inspected */ + }); length= ALIGN_SIZE(length); if ((*(prev= &mem_root->free)) != NULL) { @@ -275,7 +291,7 @@ void *multi_alloc_root(MEM_ROOT *root, ...) DBUG_RETURN((void*) start); } -#define TRASH_MEM(X) VALGRIND_MAKE_MEM_UNDEFINED(((char*)(X) + ((X)->size-(X)->left)), (X)->left) +#define TRASH_MEM(X) TRASH(((char*)(X) + ((X)->size-(X)->left)), (X)->left) /* Mark all data in blocks free for reusage */ diff --git a/mysys/my_bitmap.c b/mysys/my_bitmap.c index 137127a2fda..0c3f45be374 100644 --- a/mysys/my_bitmap.c +++ b/mysys/my_bitmap.c @@ -40,16 +40,31 @@ #include <m_string.h> #include <my_bit.h> -void create_last_word_mask(MY_BITMAP *map) + +/* Create a mask of the significant bits for the last byte (1,3,7,..255) */ + +static inline uchar last_byte_mask(uint bits) { - /* Get the number of used bits (1..8) in the last byte */ - unsigned int const used= 1U + ((map->n_bits-1U) & 0x7U); + /* Get the number of used bits-1 (0..7) in the last byte */ + unsigned int const used= (bits - 1U) & 7U; + /* Return bitmask for the significant bits */ + return ((2U << used) - 1); +} + +/* + Create a mask with the upper 'unused' bits set and the lower 'used' + bits clear. The bits within each byte is stored in big-endian order. +*/ + +static inline uchar invers_last_byte_mask(uint bits) +{ + return last_byte_mask(bits) ^ 255; +} - /* - Create a mask with the upper 'unused' bits set and the lower 'used' - bits clear. The bits within each byte is stored in big-endian order. - */ - unsigned char const mask= (~((1 << used) - 1)) & 255; + +void create_last_word_mask(MY_BITMAP *map) +{ + unsigned char const mask= invers_last_byte_mask(map->n_bits); /* The first bytes are to be set to zero since they represent real bits @@ -267,40 +282,41 @@ void bitmap_set_prefix(MY_BITMAP *map, uint prefix_size) my_bool bitmap_is_prefix(const MY_BITMAP *map, uint prefix_size) { - uint prefix_bits= prefix_size & 0x7, res; - uchar *m= (uchar*)map->bitmap; - uchar *end_prefix= m+prefix_size/8; + uint prefix_mask= last_byte_mask(prefix_size); + uchar *m= (uchar*) map->bitmap; + uchar *end_prefix= m+(prefix_size-1)/8; uchar *end; DBUG_ASSERT(m && prefix_size <= map->n_bits); - end= m+no_bytes_in_map(map); + + /* Empty prefix is always true */ + if (!prefix_size) + return 1; while (m < end_prefix) if (*m++ != 0xff) return 0; - *map->last_word_ptr&= ~map->last_word_mask; /*Clear bits*/ - res= 0; - if (prefix_bits && *m++ != (1 << prefix_bits)-1) - goto ret; + end= ((uchar*) map->bitmap) + no_bytes_in_map(map) - 1; + if (m == end) + return ((*m & last_byte_mask(map->n_bits)) == prefix_mask); - while (m < end) - if (*m++ != 0) - goto ret; - res= 1; -ret: - return res; -} + if (*m != prefix_mask) + return 0; + while (++m < end) + if (*m != 0) + return 0; + return ((*m & last_byte_mask(map->n_bits)) == 0); +} my_bool bitmap_is_set_all(const MY_BITMAP *map) { my_bitmap_map *data_ptr= map->bitmap; my_bitmap_map *end= map->last_word_ptr; - *map->last_word_ptr |= map->last_word_mask; - for (; data_ptr <= end; data_ptr++) + for (; data_ptr < end; data_ptr++) if (*data_ptr != 0xFFFFFFFF) return FALSE; - return TRUE; + return (*data_ptr | map->last_word_mask) == 0xFFFFFFFF; } @@ -308,13 +324,11 @@ my_bool bitmap_is_clear_all(const MY_BITMAP *map) { my_bitmap_map *data_ptr= map->bitmap; my_bitmap_map *end; - if (*map->last_word_ptr & ~map->last_word_mask) - return FALSE; end= map->last_word_ptr; for (; data_ptr < end; data_ptr++) if (*data_ptr) return FALSE; - return TRUE; + return (*data_ptr & ~map->last_word_mask) == 0; } /* Return TRUE if map1 is a subset of map2 */ @@ -327,14 +341,13 @@ my_bool bitmap_is_subset(const MY_BITMAP *map1, const MY_BITMAP *map2) map1->n_bits==map2->n_bits); end= map1->last_word_ptr; - *map1->last_word_ptr &= ~map1->last_word_mask; - *map2->last_word_ptr &= ~map2->last_word_mask; - while (m1 <= end) + while (m1 < end) { if ((*m1++) & ~(*m2++)) return 0; } - return 1; + /* here both maps have the same number of bits - see assert above */ + return ((*m1 & ~*m2 & ~map1->last_word_mask) ? 0 : 1); } /* True if bitmaps has any common bits */ @@ -347,14 +360,13 @@ my_bool bitmap_is_overlapping(const MY_BITMAP *map1, const MY_BITMAP *map2) map1->n_bits==map2->n_bits); end= map1->last_word_ptr; - *map1->last_word_ptr &= ~map1->last_word_mask; - *map2->last_word_ptr &= ~map2->last_word_mask; - while (m1 <= end) + while (m1 < end) { if ((*m1++) & (*m2++)) return 1; } - return 0; + /* here both maps have the same number of bits - see assert above */ + return ((*m1 & *m2 & ~map1->last_word_mask) ? 1 : 0); } @@ -366,18 +378,35 @@ void bitmap_intersect(MY_BITMAP *map, const MY_BITMAP *map2) DBUG_ASSERT(map->bitmap && map2->bitmap); end= to+min(len,len2); - *map2->last_word_ptr&= ~map2->last_word_mask; /*Clear last bits in map2*/ while (to < end) *to++ &= *from++; - if (len2 < len) + if (len2 <= len) { - end+=len-len2; + to[-1]&= ~map2->last_word_mask; /* Clear last not relevant bits */ + end+= len-len2; while (to < end) - *to++=0; + *to++= 0; } } +/* True if union of bitmaps have all bits set */ + +my_bool bitmap_union_is_set_all(const MY_BITMAP *map1, const MY_BITMAP *map2) +{ + my_bitmap_map *m1= map1->bitmap, *m2= map2->bitmap, *end; + + DBUG_ASSERT(map1->bitmap && map2->bitmap && + map1->n_bits==map2->n_bits); + end= map1->last_word_ptr; + while ( m1 < end) + if ((*m1++ | *m2++) != 0xFFFFFFFF) + return FALSE; + /* here both maps have the same number of bits - see assert above */ + return ((*m1 | *m2 | map1->last_word_mask) != 0xFFFFFFFF); +} + + /* Set/clear all bits above a bit. @@ -461,14 +490,13 @@ void bitmap_invert(MY_BITMAP *map) uint bitmap_bits_set(const MY_BITMAP *map) { uchar *m= (uchar*)map->bitmap; - uchar *end= m + no_bytes_in_map(map); + uchar *end= m + no_bytes_in_map(map) - 1; uint res= 0; DBUG_ASSERT(map->bitmap); - *map->last_word_ptr&= ~map->last_word_mask; /*Reset last bits to zero*/ while (m < end) res+= my_count_bits_ushort(*m++); - return res; + return res + my_count_bits_ushort(*m & last_byte_mask(map->n_bits)); } @@ -492,27 +520,30 @@ uint bitmap_get_first_set(const MY_BITMAP *map) DBUG_ASSERT(map->bitmap); data_ptr= map->bitmap; - *map->last_word_ptr &= ~map->last_word_mask; - for (i=0; data_ptr <= end; data_ptr++, i++) - { + for (i=0; data_ptr < end; data_ptr++, i++) if (*data_ptr) + goto found; + if (!(*data_ptr & ~map->last_word_mask)) + return MY_BIT_NONE; + +found: + { + byte_ptr= (uchar*)data_ptr; + for (j=0; ; j++, byte_ptr++) { - byte_ptr= (uchar*)data_ptr; - for (j=0; ; j++, byte_ptr++) + if (*byte_ptr) { - if (*byte_ptr) + for (k=0; ; k++) { - for (k=0; ; k++) - { - if (*byte_ptr & (1 << k)) - return (i*32) + (j*8) + k; - } + if (*byte_ptr & (1 << k)) + return (i*32) + (j*8) + k; } } } } - return MY_BIT_NONE; + DBUG_ASSERT(0); + return MY_BIT_NONE; /* Impossible */ } @@ -526,25 +557,29 @@ uint bitmap_get_first(const MY_BITMAP *map) data_ptr= map->bitmap; *map->last_word_ptr|= map->last_word_mask; - for (i=0; data_ptr <= end; data_ptr++, i++) - { + for (i=0; data_ptr < end; data_ptr++, i++) if (*data_ptr != 0xFFFFFFFF) + goto found; + if ((*data_ptr | map->last_word_mask) == 0xFFFFFFFF) + return MY_BIT_NONE; + +found: + { + byte_ptr= (uchar*)data_ptr; + for (j=0; ; j++, byte_ptr++) { - byte_ptr= (uchar*)data_ptr; - for (j=0; ; j++, byte_ptr++) - { - if (*byte_ptr != 0xFF) + if (*byte_ptr != 0xFF) + { + for (k=0; ; k++) { - for (k=0; ; k++) - { - if (!(*byte_ptr & (1 << k))) - return (i*32) + (j*8) + k; - } + if (!(*byte_ptr & (1 << k))) + return (i*32) + (j*8) + k; } } } } - return MY_BIT_NONE; + DBUG_ASSERT(0); + return MY_BIT_NONE; /* Impossible */ } @@ -759,7 +794,7 @@ uint get_rand_bit(uint bitsize) return (rand() % bitsize); } -bool test_set_get_clear_bit(MY_BITMAP *map, uint bitsize) +my_bool test_set_get_clear_bit(MY_BITMAP *map, uint bitsize) { uint i, test_bit; uint no_loops= bitsize > 128 ? 128 : bitsize; @@ -782,7 +817,7 @@ error2: return TRUE; } -bool test_flip_bit(MY_BITMAP *map, uint bitsize) +my_bool test_flip_bit(MY_BITMAP *map, uint bitsize) { uint i, test_bit; uint no_loops= bitsize > 128 ? 128 : bitsize; @@ -805,13 +840,13 @@ error2: return TRUE; } -bool test_operators(MY_BITMAP *map __attribute__((unused)), +my_bool test_operators(MY_BITMAP *map __attribute__((unused)), uint bitsize __attribute__((unused))) { return FALSE; } -bool test_get_all_bits(MY_BITMAP *map, uint bitsize) +my_bool test_get_all_bits(MY_BITMAP *map, uint bitsize) { uint i; bitmap_set_all(map); @@ -853,7 +888,7 @@ error6: return TRUE; } -bool test_compare_operators(MY_BITMAP *map, uint bitsize) +my_bool test_compare_operators(MY_BITMAP *map, uint bitsize) { uint i, j, test_bit1, test_bit2, test_bit3,test_bit4; uint no_loops= bitsize > 128 ? 128 : bitsize; @@ -959,7 +994,7 @@ error5: return TRUE; } -bool test_count_bits_set(MY_BITMAP *map, uint bitsize) +my_bool test_count_bits_set(MY_BITMAP *map, uint bitsize) { uint i, bit_count=0, test_bit; uint no_loops= bitsize > 128 ? 128 : bitsize; @@ -985,7 +1020,7 @@ error2: return TRUE; } -bool test_get_first_bit(MY_BITMAP *map, uint bitsize) +my_bool test_get_first_bit(MY_BITMAP *map, uint bitsize) { uint i, test_bit; uint no_loops= bitsize > 128 ? 128 : bitsize; @@ -1010,7 +1045,7 @@ error2: return TRUE; } -bool test_get_next_bit(MY_BITMAP *map, uint bitsize) +my_bool test_get_next_bit(MY_BITMAP *map, uint bitsize) { uint i, j, test_bit; uint no_loops= bitsize > 128 ? 128 : bitsize; @@ -1029,7 +1064,7 @@ error1: return TRUE; } -bool test_prefix(MY_BITMAP *map, uint bitsize) +my_bool test_prefix(MY_BITMAP *map, uint bitsize) { uint i, j, test_bit; uint no_loops= bitsize > 128 ? 128 : bitsize; @@ -1064,7 +1099,7 @@ error3: } -bool do_test(uint bitsize) +my_bool do_test(uint bitsize) { MY_BITMAP map; my_bitmap_map buf[1024]; diff --git a/mysys/my_copy.c b/mysys/my_copy.c index adc891358d4..e1c549f4676 100644 --- a/mysys/my_copy.c +++ b/mysys/my_copy.c @@ -17,6 +17,7 @@ #include "mysys_err.h" #include <my_dir.h> /* for stat */ #include <m_string.h> +#include "mysys_err.h" #if defined(HAVE_UTIME_H) #include <utime.h> #elif defined(HAVE_SYS_UTIME_H) @@ -57,7 +58,7 @@ int my_copy(const char *from, const char *to, myf MyFlags) File from_file,to_file; uchar buff[IO_SIZE]; MY_STAT stat_buff,new_stat_buff; - int res; + my_bool file_created= 0; DBUG_ENTER("my_copy"); DBUG_PRINT("my",("from %s to %s MyFlags %d", from, to, MyFlags)); @@ -82,6 +83,7 @@ int my_copy(const char *from, const char *to, myf MyFlags) MyFlags)) < 0) goto err; + file_created= 1; while ((Count=my_read(from_file, buff, sizeof(buff), MyFlags)) != 0) { if (Count == (uint) -1 || @@ -99,15 +101,30 @@ int my_copy(const char *from, const char *to, myf MyFlags) if (my_close(from_file,MyFlags) | my_close(to_file,MyFlags)) DBUG_RETURN(-1); /* Error on close */ + from_file=to_file= -1; /* Files are closed */ + /* Copy modes if possible */ if (MyFlags & MY_HOLD_ORIGINAL_MODES && !new_file_stat) DBUG_RETURN(0); /* File copyed but not stat */ - res= chmod(to, stat_buff.st_mode & 07777); /* Copy modes */ + /* Copy modes */ + if (chmod(to, stat_buff.st_mode & 07777)) + { + my_errno= errno; + if (MyFlags & MY_WME) + my_error(EE_CHANGE_PERMISSIONS, MYF(ME_BELL+ME_WAITTANG), to, errno); + if (MyFlags & MY_FAE) + goto err; + } #if !defined(__WIN__) && !defined(__NETWARE__) + /* Copy ownership */ if (chown(to, stat_buff.st_uid,stat_buff.st_gid)) { - my_error(EE_CANT_COPY_OWNERSHIP, MYF(ME_JUST_WARNING), to); + my_errno= errno; + if (MyFlags & MY_WME) + my_error(EE_CANT_COPY_OWNERSHIP, MYF(ME_JUST_WARNING), to, errno); + if (MyFlags & MY_FAE) + goto err; } #endif #if !defined(VMS) && !defined(__ZTC__) @@ -124,11 +141,11 @@ int my_copy(const char *from, const char *to, myf MyFlags) err: if (from_file >= 0) VOID(my_close(from_file,MyFlags)); - if (to_file >= 0) - { - VOID(my_close(to_file, MyFlags)); - /* attempt to delete the to-file we've partially written */ + if (to_file >= 0) VOID(my_close(to_file, MyFlags)); + + /* attempt to delete the to-file we've partially written */ + if (file_created) VOID(my_delete(to, MyFlags)); - } + DBUG_RETURN(-1); } /* my_copy */ diff --git a/mysys/my_gethwaddr.c b/mysys/my_gethwaddr.c index c7f138c7337..00e0e90f1e4 100644 --- a/mysys/my_gethwaddr.c +++ b/mysys/my_gethwaddr.c @@ -47,7 +47,7 @@ my_bool my_gethwaddr(uchar *to) uchar *buf, *next, *end, *addr; struct if_msghdr *ifm; struct sockaddr_dl *sdl; - int i, res=1, mib[6]={CTL_NET, AF_ROUTE, 0, AF_LINK, NET_RT_IFLIST, 0}; + int res=1, mib[6]={CTL_NET, AF_ROUTE, 0, AF_LINK, NET_RT_IFLIST, 0}; if (sysctl(mib, 6, NULL, &len, NULL, 0) == -1) goto err; diff --git a/mysys/my_getopt.c b/mysys/my_getopt.c index 1c5aa3735ec..d4e548611de 100644 --- a/mysys/my_getopt.c +++ b/mysys/my_getopt.c @@ -22,7 +22,7 @@ #include <errno.h> #include <m_string.h> -typedef void (*init_func_p)(const struct my_option *option, uchar* *variable, +typedef void (*init_func_p)(const struct my_option *option, void *variable, longlong value); static void default_reporter(enum loglevel level, const char *format, ...); @@ -30,7 +30,7 @@ my_error_reporter my_getopt_error_reporter= &default_reporter; static int findopt(char *optpat, uint length, const struct my_option **opt_res, - char **ffname); + const char **ffname); my_bool getopt_compare_strings(const char *s, const char *t, uint length); @@ -40,11 +40,12 @@ static ulonglong getopt_ull(char *arg, const struct my_option *optp, static double getopt_double(char *arg, const struct my_option *optp, int *err); static void init_variables(const struct my_option *options, init_func_p init_one_value); -static void init_one_value(const struct my_option *opt, uchar* *, longlong); -static void fini_one_value(const struct my_option *option, uchar* *variable, +static void init_one_value(const struct my_option *option, void *variable, longlong value); -static int setval(const struct my_option *opts, uchar **value, char *argument, - my_bool set_maximum_value); +static void fini_one_value(const struct my_option *option, void *variable, + longlong value); +static int setval(const struct my_option *opts, void *value, char *argument, + my_bool set_maximum_value); static char *check_struct_option(char *cur_arg, char *key_name); /* @@ -100,10 +101,9 @@ static void default_reporter(enum loglevel level, one. Call function 'get_one_option()' once for each option. */ -static uchar** (*getopt_get_addr)(const char *, uint, const struct my_option *, int *); +static my_getopt_value getopt_get_addr; -void my_getopt_register_get_addr(uchar** (*func_addr)(const char *, uint, - const struct my_option *, int *)) +void my_getopt_register_get_addr(my_getopt_value func_addr) { getopt_get_addr= func_addr; } @@ -115,10 +115,10 @@ int handle_options(int *argc, char ***argv, uint opt_found, argvpos= 0, length; my_bool end_of_options= 0, must_be_var, set_maximum_value, option_is_loose; - char **pos, **pos_end, *optend, *UNINIT_VAR(prev_found), - *opt_str, key_name[FN_REFLEN]; + char **pos, **pos_end, *optend, *opt_str, key_name[FN_REFLEN]; + const char *prev_found; const struct my_option *optp; - uchar* *value; + void *value; int error, i; LINT_INIT(opt_found); @@ -172,7 +172,7 @@ int handle_options(int *argc, char ***argv, "%s: Option '--set-variable' is deprecated. " "Use --variable-name=value instead.", my_progname); - + must_be_var= 1; if (cur_arg[13] == '=') { @@ -377,7 +377,7 @@ int handle_options(int *argc, char ***argv, optp->value; if (error) return error; - + if (optp->arg_type == NO_ARG) { if (optend && (optp->var_type & GET_TYPE_MASK) != GET_BOOL) @@ -405,8 +405,8 @@ int handle_options(int *argc, char ***argv, else { my_getopt_error_reporter(WARNING_LEVEL, - "%s: ignoring option '--%s' due to \ -invalid value '%s'", + "%s: ignoring option '--%s' due to " + "invalid value '%s'", my_progname, optp->name, optend); continue; } @@ -610,7 +610,7 @@ static char *check_struct_option(char *cur_arg, char *key_name) Will set the option value to given value */ -static int setval(const struct my_option *opts, uchar* *value, char *argument, +static int setval(const struct my_option *opts, void *value, char *argument, my_bool set_maximum_value) { int err= 0; @@ -618,8 +618,7 @@ static int setval(const struct my_option *opts, uchar* *value, char *argument, if (value && argument) { - uchar* *result_pos= ((set_maximum_value) ? - opts->u_max_value : value); + void *result_pos= ((set_maximum_value) ? opts->u_max_value : value); if (!result_pos) return EXIT_NO_PTR_TO_VARIABLE; @@ -712,10 +711,10 @@ static int setval(const struct my_option *opts, uchar* *value, char *argument, static int findopt(char *optpat, uint length, const struct my_option **opt_res, - char **ffname) + const char **ffname) { uint count; - struct my_option *opt= (struct my_option *) *opt_res; + const struct my_option *opt= *opt_res; for (count= 0; opt->name; opt++) { @@ -726,8 +725,9 @@ static int findopt(char *optpat, uint length, return 1; if (!count) { + /* We only need to know one prev */ count= 1; - *ffname= (char *) opt->name; /* We only need to know one prev */ + *ffname= opt->name; } else if (strcmp(*ffname, opt->name)) { @@ -994,7 +994,7 @@ static double getopt_double(char *arg, const struct my_option *optp, int *err) value Pointer to variable */ -static void init_one_value(const struct my_option *option, uchar* *variable, +static void init_one_value(const struct my_option *option, void *variable, longlong value) { DBUG_ENTER("init_one_value"); @@ -1068,7 +1068,7 @@ static void init_one_value(const struct my_option *option, uchar* *variable, value Pointer to variable */ -static void fini_one_value(const struct my_option *option, uchar* *variable, +static void fini_one_value(const struct my_option *option, void *variable, longlong value __attribute__ ((unused))) { DBUG_ENTER("fini_one_value"); @@ -1109,7 +1109,7 @@ static void init_variables(const struct my_option *options, DBUG_ENTER("init_variables"); for (; options->name; options++) { - uchar* *variable; + void *variable; DBUG_PRINT("options", ("name: '%s'", options->name)); /* We must set u_max_value first as for some variables @@ -1224,7 +1224,7 @@ void my_print_variables(const struct my_option *options) printf("--------------------------------- -----------------------------\n"); for (optp= options; optp->id; optp++) { - uchar* *value= (optp->var_type & GET_ASK_ADDR ? + void *value= (optp->var_type & GET_ASK_ADDR ? (*getopt_get_addr)("", 0, optp, 0) : optp->value); if (value) { @@ -1272,7 +1272,7 @@ void my_print_variables(const struct my_option *options) printf("%s\n", llstr(*((longlong*) value), buff)); break; case GET_ULL: - longlong2str(*((ulonglong*) value), buff, 10); + longlong10_to_str(*((ulonglong*) value), buff, 10); printf("%s\n", buff); break; case GET_DOUBLE: diff --git a/mysys/my_getwd.c b/mysys/my_getwd.c index e6b867e2753..a18c296a7e1 100644 --- a/mysys/my_getwd.c +++ b/mysys/my_getwd.c @@ -51,7 +51,7 @@ int my_getwd(char * buf, size_t size, myf MyFlags) (long) buf, (uint) size, MyFlags)); if (size < 1) - return(-1); + DBUG_RETURN(-1); if (curr_dir[0]) /* Current pos is saved here */ VOID(strmake(buf,&curr_dir[0],size-1)); @@ -59,12 +59,12 @@ int my_getwd(char * buf, size_t size, myf MyFlags) { #if defined(HAVE_GETCWD) if (size < 2) - return(-1); + DBUG_RETURN(-1); if (!getcwd(buf,(uint) (size-2)) && MyFlags & MY_WME) { my_errno=errno; my_error(EE_GETWD,MYF(ME_BELL+ME_WAITTANG),errno); - return(-1); + DBUG_RETURN(-1); } #elif defined(HAVE_GETWD) { @@ -74,12 +74,12 @@ int my_getwd(char * buf, size_t size, myf MyFlags) } #elif defined(VMS) if (size < 2) - return(-1); + DBUG_RETURN(-1); if (!getcwd(buf,size-2,1) && MyFlags & MY_WME) { my_errno=errno; my_error(EE_GETWD,MYF(ME_BELL+ME_WAITTANG),errno); - return(-1); + DBUG_RETURN(-1); } intern_filename(buf,buf); #else diff --git a/mysys/my_handler.c b/mysys/my_handler.c index 7c13149cb27..efee04194f7 100644 --- a/mysys/my_handler.c +++ b/mysys/my_handler.c @@ -277,7 +277,6 @@ int ha_key_cmp(register HA_KEYSEG *keyseg, register const uchar *a, return ((keyseg->flag & HA_REVERSE_SORT) ? -flag : flag); a+=a_length; b+=b_length; - break; } break; case HA_KEYTYPE_INT8: diff --git a/mysys/my_malloc.c b/mysys/my_malloc.c index 12af5603a93..330ef07ed30 100644 --- a/mysys/my_malloc.c +++ b/mysys/my_malloc.c @@ -34,13 +34,23 @@ void *my_malloc(size_t size, myf my_flags) if (!size) size=1; /* Safety */ - if ((point = (char*)malloc(size)) == NULL) + + point= (char *) malloc(size); + DBUG_EXECUTE_IF("simulate_out_of_memory", + { + free(point); + point= NULL; + }); + + if (point == NULL) { my_errno=errno; if (my_flags & MY_FAE) error_handler_hook=fatal_error_handler_hook; if (my_flags & (MY_FAE+MY_WME)) my_error(EE_OUTOFMEMORY, MYF(ME_BELL+ME_WAITTANG+ME_NOREFRESH),size); + DBUG_EXECUTE_IF("simulate_out_of_memory", + DBUG_SET("-d,simulate_out_of_memory");); if (my_flags & MY_FAE) exit(1); } diff --git a/mysys/my_redel.c b/mysys/my_redel.c index 598a728393d..cf0986a7821 100644 --- a/mysys/my_redel.c +++ b/mysys/my_redel.c @@ -71,14 +71,28 @@ end: } /* my_redel */ - /* Copy stat from one file to another */ - /* Return -1 if can't get stat, 1 if wrong type of file */ +/** + Copy stat from one file to another + @fn my_copystat() + @param from Copy stat from this file + @param to Copy stat to this file + @param MyFlags Flags: + MY_WME Give error if something goes wrong + MY_FAE Abort operation if something goes wrong + If MY_FAE is not given, we don't return -1 for + errors from chown (which normally require root + privilege) + + @return 0 ok + -1 if can't get stat, + 1 if wrong type of file +*/ int my_copystat(const char *from, const char *to, int MyFlags) { struct stat statbuf; - if (stat((char*) from, &statbuf)) + if (stat(from, &statbuf)) { my_errno=errno; if (MyFlags & (MY_FAE+MY_WME)) @@ -87,7 +101,15 @@ int my_copystat(const char *from, const char *to, int MyFlags) } if ((statbuf.st_mode & S_IFMT) != S_IFREG) return 1; - VOID(chmod(to, statbuf.st_mode & 07777)); /* Copy modes */ + + /* Copy modes */ + if (chmod(to, statbuf.st_mode & 07777)) + { + my_errno= errno; + if (MyFlags & (MY_FAE+MY_WME)) + my_error(EE_CHANGE_PERMISSIONS, MYF(ME_BELL+ME_WAITTANG), from, errno); + return -1; + } #if !defined(__WIN__) && !defined(__NETWARE__) if (statbuf.st_nlink > 1 && MyFlags & MY_LINK_WARNING) @@ -95,9 +117,14 @@ int my_copystat(const char *from, const char *to, int MyFlags) if (MyFlags & MY_LINK_WARNING) my_error(EE_LINK_WARNING,MYF(ME_BELL+ME_WAITTANG),from,statbuf.st_nlink); } + /* Copy ownership */ if (chown(to, statbuf.st_uid, statbuf.st_gid)) { - my_error(EE_CANT_COPY_OWNERSHIP, MYF(ME_JUST_WARNING), to); + my_errno= errno; + if (MyFlags & MY_WME) + my_error(EE_CHANGE_OWNERSHIP, MYF(ME_BELL+ME_WAITTANG), from, errno); + if (MyFlags & MY_FAE) + return -1; } #endif /* !__WIN__ && !__NETWARE__ */ diff --git a/mysys/my_static.c b/mysys/my_static.c index 0ef5656b76f..08653d03d21 100644 --- a/mysys/my_static.c +++ b/mysys/my_static.c @@ -119,6 +119,7 @@ ulonglong query_performance_frequency, query_performance_offset; /* How to disable options */ my_bool NEAR my_disable_locking=0; +my_bool NEAR my_disable_sync=0; my_bool NEAR my_disable_async_io=0; my_bool NEAR my_disable_flush_key_blocks=0; my_bool NEAR my_disable_symlinks=0; diff --git a/mysys/my_sync.c b/mysys/my_sync.c index 967a6ae6c78..a2b615a8661 100644 --- a/mysys/my_sync.c +++ b/mysys/my_sync.c @@ -48,6 +48,9 @@ int my_sync(File fd, myf my_flags) DBUG_ENTER("my_sync"); DBUG_PRINT("my",("fd: %d my_flags: %d", fd, my_flags)); + if (my_disable_sync) + DBUG_RETURN(0); + statistic_increment(my_sync_count,&THR_LOCK_open); do { @@ -65,6 +68,8 @@ int my_sync(File fd, myf my_flags) res= fdatasync(fd); #elif defined(HAVE_FSYNC) res= fsync(fd); + if (res == -1 && errno == ENOLCK) + res= 0; /* Result Bug in Old FreeBSD */ #elif defined(__WIN__) res= _commit(fd); #else diff --git a/mysys/safemalloc.c b/mysys/safemalloc.c index d6cd3896b08..0d0ae2dabe5 100644 --- a/mysys/safemalloc.c +++ b/mysys/safemalloc.c @@ -139,6 +139,11 @@ void *_mymalloc(size_t size, const char *filename, uint lineno, myf MyFlags) size + /* size requested */ 4 + /* overrun mark */ sf_malloc_endhunc); + DBUG_EXECUTE_IF("simulate_out_of_memory", + { + free(irem); + irem= NULL; + }); } /* Check if there isn't anymore memory avaiable */ if (!irem) @@ -159,6 +164,8 @@ void *_mymalloc(size_t size, const char *filename, uint lineno, myf MyFlags) } DBUG_PRINT("error",("Out of memory, in use: %ld at line %d, '%s'", (ulong) sf_malloc_max_memory,lineno, filename)); + DBUG_EXECUTE_IF("simulate_out_of_memory", + DBUG_SET("-d,simulate_out_of_memory");); if (MyFlags & MY_FAE) exit(1); DBUG_RETURN ((void*) 0); @@ -190,9 +197,12 @@ void *_mymalloc(size_t size, const char *filename, uint lineno, myf MyFlags) sf_malloc_count++; pthread_mutex_unlock(&THR_LOCK_malloc); + MEM_CHECK_ADDRESSABLE(data, size); /* Set the memory to the aribtrary wierd value */ if ((MyFlags & MY_ZEROFILL) || !sf_malloc_quick) bfill(data, size, (char) (MyFlags & MY_ZEROFILL ? 0 : ALLOC_VAL)); + if (!(MyFlags & MY_ZEROFILL)) + MEM_UNDEFINED(data, size); /* Return a pointer to the real data */ DBUG_PRINT("exit",("ptr: %p", data)); if (sf_min_adress > data) @@ -312,7 +322,9 @@ void _myfree(void *ptr, const char *filename, uint lineno, myf myflags) if (!sf_malloc_quick) bfill(ptr, irem->datasize, (pchar) FREE_VAL); #endif + MEM_NOACCESS(ptr, irem->datasize); *((uint32*) ((char*) ptr- sizeof(uint32)))= ~MAGICKEY; + MEM_NOACCESS((char*) ptr - sizeof(uint32), sizeof(uint32)); /* Actually free the memory */ free((char*) irem); DBUG_VOID_RETURN; diff --git a/mysys/stacktrace.c b/mysys/stacktrace.c index 75fda93b56e..7bac8017324 100644 --- a/mysys/stacktrace.c +++ b/mysys/stacktrace.c @@ -86,7 +86,9 @@ void my_print_stacktrace(uchar* stack_bottom __attribute__((unused)), #if BACKTRACE_DEMANGLE -char __attribute__ ((weak)) *my_demangle(const char *mangled_name, int *status) +char __attribute__ ((weak)) * +my_demangle(const char *mangled_name __attribute__((unused)), + int *status __attribute__((unused))) { return NULL; } diff --git a/mysys/thr_alarm.c b/mysys/thr_alarm.c index 680ec985aeb..f7ff20c9b23 100644 --- a/mysys/thr_alarm.c +++ b/mysys/thr_alarm.c @@ -285,7 +285,7 @@ sig_handler process_alarm(int sig __attribute__((unused))) #if defined(MAIN) && !defined(__bsdi__) printf("thread_alarm in process_alarm\n"); fflush(stdout); #endif -#ifdef DONT_REMEMBER_SIGNAL +#ifdef SIGNAL_HANDLER_RESET_ON_DELIVERY my_sigset(thr_client_alarm, process_alarm); /* int. thread system calls */ #endif return; @@ -304,7 +304,7 @@ sig_handler process_alarm(int sig __attribute__((unused))) #endif process_alarm_part2(sig); #ifndef USE_ALARM_THREAD -#if defined(DONT_REMEMBER_SIGNAL) && !defined(USE_ONE_SIGNAL_HAND) +#if defined(SIGNAL_HANDLER_RESET_ON_DELIVERY) && !defined(USE_ONE_SIGNAL_HAND) my_sigset(THR_SERVER_ALARM,process_alarm); #endif pthread_mutex_unlock(&LOCK_alarm); @@ -507,12 +507,12 @@ void thr_alarm_info(ALARM_INFO *info) */ -static sig_handler thread_alarm(int sig) +static sig_handler thread_alarm(int sig __attribute__((unused))) { #ifdef MAIN printf("thread_alarm\n"); fflush(stdout); #endif -#ifdef DONT_REMEMBER_SIGNAL +#ifdef SIGNAL_HANDLER_RESET_ON_DELIVERY my_sigset(sig,thread_alarm); /* int. thread system calls */ #endif } @@ -776,6 +776,7 @@ static void *test_thread(void *arg) return 0; } + static void *signal_hand(void *arg __attribute__((unused))) { sigset_t set; diff --git a/mysys/thr_lock.c b/mysys/thr_lock.c index c830c4ed0cc..b8aa9e5fcc0 100644 --- a/mysys/thr_lock.c +++ b/mysys/thr_lock.c @@ -131,8 +131,7 @@ static int check_lock(struct st_lock_list *list, const char* lock_type, { THR_LOCK_DATA *data,**prev; uint count=0; - THR_LOCK_OWNER *first_owner; - LINT_INIT(first_owner); + THR_LOCK_OWNER *UNINIT_VAR(first_owner); prev= &list->data; if (list->data) |