diff options
author | monty@mysql.com/narttu.mysql.fi <> | 2007-05-10 12:59:39 +0300 |
---|---|---|
committer | monty@mysql.com/narttu.mysql.fi <> | 2007-05-10 12:59:39 +0300 |
commit | 088e2395f1833f16c2ea3f7405f604165b4aa2cc (patch) | |
tree | 6480cbef09e9dec2fa347b1899963ab3658d692f /vio | |
parent | 9078e630c64a313301cd13ce71d0854fbcf2fd0b (diff) | |
download | mariadb-git-088e2395f1833f16c2ea3f7405f604165b4aa2cc.tar.gz |
WL#3817: Simplify string / memory area types and make things more consistent (first part)
The following type conversions was done:
- Changed byte to uchar
- Changed gptr to uchar*
- Change my_string to char *
- Change my_size_t to size_t
- Change size_s to size_t
Removed declaration of byte, gptr, my_string, my_size_t and size_s.
Following function parameter changes was done:
- All string functions in mysys/strings was changed to use size_t
instead of uint for string lengths.
- All read()/write() functions changed to use size_t (including vio).
- All protocoll functions changed to use size_t instead of uint
- Functions that used a pointer to a string length was changed to use size_t*
- Changed malloc(), free() and related functions from using gptr to use void *
as this requires fewer casts in the code and is more in line with how the
standard functions work.
- Added extra length argument to dirname_part() to return the length of the
created string.
- Changed (at least) following functions to take uchar* as argument:
- db_dump()
- my_net_write()
- net_write_command()
- net_store_data()
- DBUG_DUMP()
- decimal2bin() & bin2decimal()
- Changed my_compress() and my_uncompress() to use size_t. Changed one
argument to my_uncompress() from a pointer to a value as we only return
one value (makes function easier to use).
- Changed type of 'pack_data' argument to packfrm() to avoid casts.
- Changed in readfrm() and writefrom(), ha_discover and handler::discover()
the type for argument 'frmdata' to uchar** to avoid casts.
- Changed most Field functions to use uchar* instead of char* (reduced a lot of
casts).
- Changed field->val_xxx(xxx, new_ptr) to take const pointers.
Other changes:
- Removed a lot of not needed casts
- Added a few new cast required by other changes
- Added some cast to my_multi_malloc() arguments for safety (as string lengths
needs to be uint, not size_t).
- Fixed all calls to hash-get-key functions to use size_t*. (Needed to be done
explicitely as this conflict was often hided by casting the function to
hash_get_key).
- Changed some buffers to memory regions to uchar* to avoid casts.
- Changed some string lengths from uint to size_t.
- Changed field->ptr to be uchar* instead of char*. This allowed us to
get rid of a lot of casts.
- Some changes from true -> TRUE, false -> FALSE, unsigned char -> uchar
- Include zlib.h in some files as we needed declaration of crc32()
- Changed MY_FILE_ERROR to be (size_t) -1.
- Changed many variables to hold the result of my_read() / my_write() to be
size_t. This was needed to properly detect errors (which are
returned as (size_t) -1).
- Removed some very old VMS code
- Changed packfrm()/unpackfrm() to not be depending on uint size
(portability fix)
- Removed windows specific code to restore cursor position as this
causes slowdown on windows and we should not mix read() and pread()
calls anyway as this is not thread safe. Updated function comment to
reflect this. Changed function that depended on original behavior of
my_pwrite() to itself restore the cursor position (one such case).
- Added some missing checking of return value of malloc().
- Changed definition of MOD_PAD_CHAR_TO_FULL_LENGTH to avoid 'long' overflow.
- Changed type of table_def::m_size from my_size_t to ulong to reflect that
m_size is the number of elements in the array, not a string/memory
length.
- Moved THD::max_row_length() to table.cc (as it's not depending on THD).
Inlined max_row_length_blob() into this function.
- More function comments
- Fixed some compiler warnings when compiled without partitions.
- Removed setting of LEX_STRING() arguments in declaration (portability fix).
- Some trivial indentation/variable name changes.
- Some trivial code simplifications:
- Replaced some calls to alloc_root + memcpy to use
strmake_root()/strdup_root().
- Changed some calls from memdup() to strmake() (Safety fix)
- Simpler loops in client-simple.c
Diffstat (limited to 'vio')
-rw-r--r-- | vio/test-ssl.c | 26 | ||||
-rw-r--r-- | vio/test-sslclient.c | 6 | ||||
-rw-r--r-- | vio/test-sslserver.c | 8 | ||||
-rw-r--r-- | vio/vio.c | 4 | ||||
-rw-r--r-- | vio/vio_priv.h | 4 | ||||
-rw-r--r-- | vio/viosocket.c | 95 | ||||
-rw-r--r-- | vio/viossl.c | 26 | ||||
-rw-r--r-- | vio/viosslfactories.c | 2 | ||||
-rw-r--r-- | vio/viotest-ssl.c | 26 |
9 files changed, 100 insertions, 97 deletions
diff --git a/vio/test-ssl.c b/vio/test-ssl.c index 76833e25949..855dc5fbb3e 100644 --- a/vio/test-ssl.c +++ b/vio/test-ssl.c @@ -106,8 +106,8 @@ main(int argc, char** argv) child_pid = fork(); if (child_pid==-1) { - my_free((gptr)ssl_acceptor,MYF(0)); - my_free((gptr)ssl_connector,MYF(0)); + my_free((uchar*)ssl_acceptor,MYF(0)); + my_free((uchar*)ssl_connector,MYF(0)); fatal_error("fork"); } if (child_pid==0) @@ -116,28 +116,28 @@ main(int argc, char** argv) char xbuf[100]; int r = vio_read(client_vio,xbuf, sizeof(xbuf)); if (r<=0) { - my_free((gptr)ssl_acceptor,MYF(0)); - my_free((gptr)ssl_connector,MYF(0)); + my_free((uchar*)ssl_acceptor,MYF(0)); + my_free((uchar*)ssl_connector,MYF(0)); fatal_error("client:SSL_read"); } xbuf[r] = 0; printf("client:got %s\n", xbuf); - my_free((gptr)client_vio,MYF(0)); - my_free((gptr)ssl_acceptor,MYF(0)); - my_free((gptr)ssl_connector,MYF(0)); + my_free((uchar*)client_vio,MYF(0)); + my_free((uchar*)ssl_acceptor,MYF(0)); + my_free((uchar*)ssl_connector,MYF(0)); } else { const char* s = "Huhuhuh"; - int r = vio_write(server_vio,(gptr)s, strlen(s)); + int r = vio_write(server_vio,(uchar*)s, strlen(s)); if (r<=0) { - my_free((gptr)ssl_acceptor,MYF(0)); - my_free((gptr)ssl_connector,MYF(0)); + my_free((uchar*)ssl_acceptor,MYF(0)); + my_free((uchar*)ssl_connector,MYF(0)); fatal_error("server:SSL_write"); } - my_free((gptr)server_vio,MYF(0)); - my_free((gptr)ssl_acceptor,MYF(0)); - my_free((gptr)ssl_connector,MYF(0)); + my_free((uchar*)server_vio,MYF(0)); + my_free((uchar*)ssl_acceptor,MYF(0)); + my_free((uchar*)ssl_connector,MYF(0)); } return 0; } diff --git a/vio/test-sslclient.c b/vio/test-sslclient.c index c8e14721375..e1b8461397b 100644 --- a/vio/test-sslclient.c +++ b/vio/test-sslclient.c @@ -84,13 +84,13 @@ main( int argc __attribute__((unused)), sslconnect(ssl_connector,client_vio,60L); err = vio_read(client_vio,xbuf, sizeof(xbuf)); if (err<=0) { - my_free((gptr)ssl_connector,MYF(0)); + my_free((uchar*)ssl_connector,MYF(0)); fatal_error("client:SSL_read"); } xbuf[err] = 0; printf("client:got %s\n", xbuf); - my_free((gptr)client_vio,MYF(0)); - my_free((gptr)ssl_connector,MYF(0)); + my_free((uchar*)client_vio,MYF(0)); + my_free((uchar*)ssl_connector,MYF(0)); return 0; } #else /* HAVE_OPENSSL */ diff --git a/vio/test-sslserver.c b/vio/test-sslserver.c index 59456db1fd4..f55b5bae53a 100644 --- a/vio/test-sslserver.c +++ b/vio/test-sslserver.c @@ -59,9 +59,9 @@ do_ssl_stuff( TH_ARGS* args) /* ----------------------------------------------- */ /* TCP connection is ready. Do server side SSL. */ - err = write(server_vio->sd,(gptr)s, strlen(s)); + err = write(server_vio->sd,(uchar*)s, strlen(s)); sslaccept(args->ssl_acceptor,server_vio,60L); - err = server_vio->write(server_vio,(gptr)s, strlen(s)); + err = server_vio->write(server_vio,(uchar*)s, strlen(s)); DBUG_VOID_RETURN; } @@ -139,12 +139,12 @@ main(int argc __attribute__((unused)), char** argv) #if 0 if (err<=0) { - my_free((gptr)ssl_acceptor,MYF(0)); + my_free((uchar*)ssl_acceptor,MYF(0)); fatal_error("server:SSL_write"); } #endif /* 0 */ - my_free((gptr)ssl_acceptor,MYF(0)); + my_free((uchar*)ssl_acceptor,MYF(0)); return 0; } #else /* HAVE_OPENSSL */ diff --git a/vio/vio.c b/vio/vio.c index 5db54d58a79..e088687098b 100644 --- a/vio/vio.c +++ b/vio/vio.c @@ -228,8 +228,8 @@ void vio_delete(Vio* vio) if (vio->type != VIO_CLOSED) vio->vioclose(vio); - my_free((gptr) vio->read_buffer, MYF(MY_ALLOW_ZERO_PTR)); - my_free((gptr) vio,MYF(0)); + my_free((uchar*) vio->read_buffer, MYF(MY_ALLOW_ZERO_PTR)); + my_free((uchar*) vio,MYF(0)); } diff --git a/vio/vio_priv.h b/vio/vio_priv.h index 4a272e519a3..0a91c134666 100644 --- a/vio/vio_priv.h +++ b/vio/vio_priv.h @@ -27,8 +27,8 @@ void vio_ignore_timeout(Vio *vio, uint which, uint timeout); #ifdef HAVE_OPENSSL #include "my_net.h" /* needed because of struct in_addr */ -int vio_ssl_read(Vio *vio,gptr buf, int size); -int vio_ssl_write(Vio *vio,const gptr buf,int size); +size_t vio_ssl_read(Vio *vio,uchar* buf, size_t size); +size_t vio_ssl_write(Vio *vio,const uchar* buf, size_t size); /* When the workday is over... */ int vio_ssl_close(Vio *vio); diff --git a/vio/viosocket.c b/vio/viosocket.c index d3a479edac3..9afb1ec4bbf 100644 --- a/vio/viosocket.c +++ b/vio/viosocket.c @@ -28,12 +28,12 @@ int vio_errno(Vio *vio __attribute__((unused))) } -int vio_read(Vio * vio, gptr buf, int size) +size_t vio_read(Vio * vio, uchar* buf, size_t size) { - int r; + size_t r; DBUG_ENTER("vio_read"); - DBUG_PRINT("enter", ("sd: %d buf: 0x%lx size: %d", vio->sd, (long) buf, - size)); + DBUG_PRINT("enter", ("sd: %d buf: 0x%lx size: %u", vio->sd, (long) buf, + (uint) size)); /* Ensure nobody uses vio_read_buff and vio_read simultaneously */ DBUG_ASSERT(vio->read_end == vio->read_pos); @@ -44,12 +44,12 @@ int vio_read(Vio * vio, gptr buf, int size) r = read(vio->sd, buf, size); #endif /* __WIN__ */ #ifndef DBUG_OFF - if (r < 0) + if (r == (size_t) -1) { DBUG_PRINT("vio_error", ("Got error %d during read",errno)); } #endif /* DBUG_OFF */ - DBUG_PRINT("exit", ("%d", r)); + DBUG_PRINT("exit", ("%ld", (long) r)); DBUG_RETURN(r); } @@ -59,17 +59,17 @@ int vio_read(Vio * vio, gptr buf, int size) reduce number of syscalls. */ -int vio_read_buff(Vio *vio, gptr buf, int size) +size_t vio_read_buff(Vio *vio, uchar* buf, size_t size) { - int rc; + size_t rc; #define VIO_UNBUFFERED_READ_MIN_SIZE 2048 DBUG_ENTER("vio_read_buff"); - DBUG_PRINT("enter", ("sd: %d buf: 0x%lx size: %d", vio->sd, (long) buf, - size)); + DBUG_PRINT("enter", ("sd: %d buf: 0x%lx size: %u", vio->sd, (long) buf, + (uint) size)); if (vio->read_pos < vio->read_end) { - rc= min(vio->read_end - vio->read_pos, size); + rc= min((size_t) (vio->read_end - vio->read_pos), size); memcpy(buf, vio->read_pos, rc); vio->read_pos+= rc; /* @@ -81,7 +81,7 @@ int vio_read_buff(Vio *vio, gptr buf, int size) else if (size < VIO_UNBUFFERED_READ_MIN_SIZE) { rc= vio_read(vio, vio->read_buffer, VIO_READ_BUFFER_SIZE); - if (rc > 0) + if (rc != 0 && rc != (size_t) -1) { if (rc > size) { @@ -99,24 +99,24 @@ int vio_read_buff(Vio *vio, gptr buf, int size) } -int vio_write(Vio * vio, const gptr buf, int size) +size_t vio_write(Vio * vio, const uchar* buf, size_t size) { - int r; + size_t r; DBUG_ENTER("vio_write"); - DBUG_PRINT("enter", ("sd: %d buf: 0x%lx size: %d", vio->sd, (long) buf, - size)); + DBUG_PRINT("enter", ("sd: %d buf: 0x%lx size: %u", vio->sd, (long) buf, + (uint) size)); #ifdef __WIN__ r = send(vio->sd, buf, size,0); #else r = write(vio->sd, buf, size); #endif /* __WIN__ */ #ifndef DBUG_OFF - if (r < 0) + if (r == (size_t) -1) { DBUG_PRINT("vio_error", ("Got error on write: %d",socket_errno)); } #endif /* DBUG_OFF */ - DBUG_PRINT("exit", ("%d", r)); + DBUG_PRINT("exit", ("%u", (uint) r)); DBUG_RETURN(r); } @@ -405,33 +405,33 @@ void vio_timeout(Vio *vio, uint which, uint timeout) #ifdef __WIN__ -int vio_read_pipe(Vio * vio, gptr buf, int size) +size_t vio_read_pipe(Vio * vio, uchar* buf, size_t size) { DWORD length; DBUG_ENTER("vio_read_pipe"); - DBUG_PRINT("enter", ("sd: %d buf: 0x%lx size: %d", vio->sd, (long) buf, - size)); + DBUG_PRINT("enter", ("sd: %d buf: 0x%lx size: %u", vio->sd, (long) buf, + (uint) size)); if (!ReadFile(vio->hPipe, buf, size, &length, NULL)) DBUG_RETURN(-1); DBUG_PRINT("exit", ("%d", length)); - DBUG_RETURN(length); + DBUG_RETURN((size_t) length); } -int vio_write_pipe(Vio * vio, const gptr buf, int size) +size_t vio_write_pipe(Vio * vio, const uchar* buf, size_t size) { DWORD length; DBUG_ENTER("vio_write_pipe"); - DBUG_PRINT("enter", ("sd: %d buf: 0x%lx size: %d", vio->sd, (long) buf, - size)); + DBUG_PRINT("enter", ("sd: %d buf: 0x%lx size: %u", vio->sd, (long) buf, + (uint) size)); if (!WriteFile(vio->hPipe, (char*) buf, size, &length, NULL)) DBUG_RETURN(-1); DBUG_PRINT("exit", ("%d", length)); - DBUG_RETURN(length); + DBUG_RETURN((size_t) length); } int vio_close_pipe(Vio * vio) @@ -463,12 +463,11 @@ void vio_ignore_timeout(Vio *vio __attribute__((unused)), #ifdef HAVE_SMEM -int vio_read_shared_memory(Vio * vio, gptr buf, int size) +size_t vio_read_shared_memory(Vio * vio, uchar* buf, size_t size) { - int length; - int remain_local; + size_t length; + size_t remain_local; char *current_postion; - DBUG_ENTER("vio_read_shared_memory"); DBUG_PRINT("enter", ("sd: %d buf: 0x%lx size: %d", vio->sd, (long) buf, size)); @@ -485,7 +484,8 @@ int vio_read_shared_memory(Vio * vio, gptr buf, int size) /* WaitForMultipleObjects can return next values: WAIT_OBJECT_0+0 - event from vio->event_server_wrote - WAIT_OBJECT_0+1 - event from vio->event_conn_closed. We can't read anything + WAIT_OBJECT_0+1 - event from vio->event_conn_closed. We can't read + anything WAIT_ABANDONED_0 and WAIT_TIMEOUT - fail. We can't read anything */ if (WaitForMultipleObjects(2, (HANDLE*)&events,FALSE, @@ -514,23 +514,23 @@ int vio_read_shared_memory(Vio * vio, gptr buf, int size) remain_local-=length; if (!vio->shared_memory_remain) - if (!SetEvent(vio->event_client_read)) DBUG_RETURN(-1); + { + if (!SetEvent(vio->event_client_read)) + DBUG_RETURN(-1); + } } while (remain_local); length = size; - DBUG_PRINT("exit", ("%d", length)); + DBUG_PRINT("exit", ("%lu", (ulong) length)); DBUG_RETURN(length); } -int vio_write_shared_memory(Vio * vio, const gptr buf, int size) +size_t vio_write_shared_memory(Vio * vio, const uchar* buf, size_t size) { - int length; - uint remain; + size_t length, remain, sz; HANDLE pos; - int sz; - char *current_postion; - + const uchar *current_postion; DBUG_ENTER("vio_write_shared_memory"); DBUG_PRINT("enter", ("sd: %d buf: 0x%lx size: %d", vio->sd, (long) buf, size)); @@ -539,24 +539,27 @@ int vio_write_shared_memory(Vio * vio, const gptr buf, int size) current_postion = buf; while (remain != 0) { - if (WaitForSingleObject(vio->event_server_read, vio->net->write_timeout*1000) - != WAIT_OBJECT_0) + if (WaitForSingleObject(vio->event_server_read, + vio->net->write_timeout*1000) != + WAIT_OBJECT_0) { - DBUG_RETURN(-1); - }; + DBUG_RETURN((size_t) -1); + } - sz = remain > shared_memory_buffer_length ? shared_memory_buffer_length: remain; + sz= (remain > shared_memory_buffer_length ? shared_memory_buffer_length : + remain); int4store(vio->handle_map,sz); pos = vio->handle_map + 4; memcpy(pos,current_postion,sz); remain-=sz; current_postion+=sz; - if (!SetEvent(vio->event_client_wrote)) DBUG_RETURN(-1); + if (!SetEvent(vio->event_client_wrote)) + DBUG_RETURN((size_t) -1); } length = size; - DBUG_PRINT("exit", ("%d", length)); + DBUG_PRINT("exit", ("%lu", (ulong) length)); DBUG_RETURN(length); } diff --git a/vio/viossl.c b/vio/viossl.c index 5e4203a3fb5..32cfecdb9c8 100644 --- a/vio/viossl.c +++ b/vio/viossl.c @@ -82,35 +82,36 @@ report_errors(SSL* ssl) } -int vio_ssl_read(Vio *vio, gptr buf, int size) +size_t vio_ssl_read(Vio *vio, uchar* buf, size_t size) { - int r; + size_t r; DBUG_ENTER("vio_ssl_read"); - DBUG_PRINT("enter", ("sd: %d buf: 0x%lx size: %d ssl: 0x%lx", - vio->sd, (long) buf, size, (long) vio->ssl_arg)); + DBUG_PRINT("enter", ("sd: %d buf: 0x%lx size: %u ssl: 0x%lx", + vio->sd, (long) buf, (uint) size, (long) vio->ssl_arg)); r= SSL_read((SSL*) vio->ssl_arg, buf, size); #ifndef DBUG_OFF - if (r < 0) + if (r == (size_t) -1) report_errors((SSL*) vio->ssl_arg); #endif - DBUG_PRINT("exit", ("%d", r)); + DBUG_PRINT("exit", ("%u", (uint) r)); DBUG_RETURN(r); } -int vio_ssl_write(Vio *vio, const gptr buf, int size) +size_t vio_ssl_write(Vio *vio, const uchar* buf, size_t size) { - int r; + size_t r; DBUG_ENTER("vio_ssl_write"); - DBUG_PRINT("enter", ("sd: %d buf: 0x%lx size: %d", vio->sd, (long) buf, size)); + DBUG_PRINT("enter", ("sd: %d buf: 0x%lx size: %u", vio->sd, + (long) buf, (uint) size)); r= SSL_write((SSL*) vio->ssl_arg, buf, size); #ifndef DBUG_OFF - if (r < 0) + if (r == (size_t) -1) report_errors((SSL*) vio->ssl_arg); #endif - DBUG_PRINT("exit", ("%d", r)); + DBUG_PRINT("exit", ("%u", (uint) r)); DBUG_RETURN(r); } @@ -123,8 +124,7 @@ int vio_ssl_close(Vio *vio) if (ssl) { - switch ((r= SSL_shutdown(ssl))) - { + switch ((r= SSL_shutdown(ssl))) { case 1: /* Shutdown successful */ break; diff --git a/vio/viosslfactories.c b/vio/viosslfactories.c index d26d4147c9f..d7e4f380bc1 100644 --- a/vio/viosslfactories.c +++ b/vio/viosslfactories.c @@ -378,6 +378,6 @@ new_VioSSLAcceptorFd(const char *key_file, const char *cert_file, void free_vio_ssl_acceptor_fd(struct st_VioSSLFd *fd) { SSL_CTX_free(fd->ssl_context); - my_free((gptr) fd, MYF(0)); + my_free((uchar*) fd, MYF(0)); } #endif /* HAVE_OPENSSL */ diff --git a/vio/viotest-ssl.c b/vio/viotest-ssl.c index 81d119ff207..b8abbac4ed6 100644 --- a/vio/viotest-ssl.c +++ b/vio/viotest-ssl.c @@ -106,8 +106,8 @@ int main(int argc, char **argv) child_pid = fork(); if (child_pid==-1) { - my_free((gptr)ssl_acceptor,MYF(0)); - my_free((gptr)ssl_connector,MYF(0)); + my_free((uchar*)ssl_acceptor,MYF(0)); + my_free((uchar*)ssl_connector,MYF(0)); fatal_error("fork"); } if (child_pid==0) @@ -116,29 +116,29 @@ int main(int argc, char **argv) char xbuf[100]; int r = vio_ssl_read(client_vio,xbuf, sizeof(xbuf)); if (r<=0) { - my_free((gptr)ssl_acceptor,MYF(0)); - my_free((gptr)ssl_connector,MYF(0)); + my_free((uchar*)ssl_acceptor,MYF(0)); + my_free((uchar*)ssl_connector,MYF(0)); fatal_error("client:SSL_read"); } xbuf[r] = 0; printf("client:got %s\n", xbuf); - my_free((gptr)client_vio,MYF(0)); - my_free((gptr)ssl_acceptor,MYF(0)); - my_free((gptr)ssl_connector,MYF(0)); + my_free((uchar*)client_vio,MYF(0)); + my_free((uchar*)ssl_acceptor,MYF(0)); + my_free((uchar*)ssl_connector,MYF(0)); sleep(1); } else { const char* s = "Huhuhuh"; - int r = vio_ssl_write(server_vio,(gptr)s, strlen(s)); + int r = vio_ssl_write(server_vio,(uchar*)s, strlen(s)); if (r<=0) { - my_free((gptr)ssl_acceptor,MYF(0)); - my_free((gptr)ssl_connector,MYF(0)); + my_free((uchar*)ssl_acceptor,MYF(0)); + my_free((uchar*)ssl_connector,MYF(0)); fatal_error("server:SSL_write"); } - my_free((gptr)server_vio,MYF(0)); - my_free((gptr)ssl_acceptor,MYF(0)); - my_free((gptr)ssl_connector,MYF(0)); + my_free((uchar*)server_vio,MYF(0)); + my_free((uchar*)ssl_acceptor,MYF(0)); + my_free((uchar*)ssl_connector,MYF(0)); sleep(1); } return 0; |