1
0
mirror of https://github.com/MariaDB/server.git synced 2025-07-27 18:02:13 +03:00

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
This commit is contained in:
monty@mysql.com/narttu.mysql.fi
2007-05-10 12:59:39 +03:00
parent 9078e630c6
commit 088e2395f1
474 changed files with 8476 additions and 8346 deletions

View File

@ -27,24 +27,31 @@
#define fseek(A,B,C) fseeko((A),(B),(C))
#endif
/* Read a chunk of bytes from a file */
/* Returns (uint) -1 if error as my_read() */
/*
Read a chunk of bytes from a FILE
uint my_fread(FILE *stream, byte *Buffer, uint Count, myf MyFlags)
/* File descriptor */
/* Buffer must be at least count bytes */
/* Max number of bytes returnd */
/* Flags on what to do on error */
SYNOPSIS
my_fread()
stream File descriptor
Buffer Buffer to read to
Count Number of bytes to read
MyFlags Flags on what to do on error
RETURN
(size_t) -1 Error
# Number of bytes read
*/
size_t my_fread(FILE *stream, uchar *Buffer, size_t Count, myf MyFlags)
{
uint readbytes;
size_t readbytes;
DBUG_ENTER("my_fread");
DBUG_PRINT("my",("stream: 0x%lx Buffer: 0x%lx Count: %u MyFlags: %d",
(long) stream, (long) Buffer, Count, MyFlags));
(long) stream, (long) Buffer, (uint) Count, MyFlags));
if ((readbytes = (uint) fread(Buffer,sizeof(char),(size_t) Count,stream))
!= Count)
if ((readbytes= fread(Buffer, sizeof(char), Count, stream)) != Count)
{
DBUG_PRINT("error",("Read only %d bytes",readbytes));
DBUG_PRINT("error",("Read only %d bytes", (int) readbytes));
if (MyFlags & (MY_WME | MY_FAE | MY_FNABP))
{
if (ferror(stream))
@ -57,7 +64,7 @@ uint my_fread(FILE *stream, byte *Buffer, uint Count, myf MyFlags)
}
my_errno=errno ? errno : -1;
if (ferror(stream) || MyFlags & (MY_NABP | MY_FNABP))
DBUG_RETURN((uint) -1); /* Return with error */
DBUG_RETURN((size_t) -1); /* Return with error */
}
if (MyFlags & (MY_NABP | MY_FNABP))
DBUG_RETURN(0); /* Read ok */
@ -66,40 +73,48 @@ uint my_fread(FILE *stream, byte *Buffer, uint Count, myf MyFlags)
/*
** Write a chunk of bytes to a stream
** Returns (uint) -1 if error as my_write()
** Does retries if interrupted
Write a chunk of bytes to a stream
my_fwrite()
stream File descriptor
Buffer Buffer to write from
Count Number of bytes to write
MyFlags Flags on what to do on error
RETURN
(size_t) -1 Error
# Number of bytes written
*/
uint my_fwrite(FILE *stream, const byte *Buffer, uint Count, myf MyFlags)
size_t my_fwrite(FILE *stream, const uchar *Buffer, size_t Count, myf MyFlags)
{
uint writenbytes=0;
off_t seekptr;
size_t writtenbytes =0;
my_off_t seekptr;
#if !defined(NO_BACKGROUND) && defined(USE_MY_STREAM)
uint errors;
#endif
DBUG_ENTER("my_fwrite");
DBUG_PRINT("my",("stream: 0x%lx Buffer: 0x%lx Count: %u MyFlags: %d",
(long) stream, (long) Buffer, Count, MyFlags));
(long) stream, (long) Buffer, (uint) Count, MyFlags));
#if !defined(NO_BACKGROUND) && defined(USE_MY_STREAM)
errors=0;
#endif
seekptr=ftell(stream);
seekptr= ftell(stream);
for (;;)
{
uint writen;
if ((writen = (uint) fwrite((char*) Buffer,sizeof(char),
(size_t) Count, stream)) != Count)
size_t written;
if ((written = (size_t) fwrite((char*) Buffer,sizeof(char),
Count, stream)) != Count)
{
DBUG_PRINT("error",("Write only %d bytes",writenbytes));
DBUG_PRINT("error",("Write only %d bytes", (int) writtenbytes));
my_errno=errno;
if (writen != (uint) -1)
if (written != (size_t) -1)
{
seekptr+=writen;
Buffer+=writen;
writenbytes+=writen;
Count-=writen;
seekptr+=written;
Buffer+=written;
writtenbytes+=written;
Count-=written;
}
#ifdef EINTR
if (errno == EINTR)
@ -131,21 +146,21 @@ uint my_fwrite(FILE *stream, const byte *Buffer, uint Count, myf MyFlags)
my_error(EE_WRITE, MYF(ME_BELL+ME_WAITTANG),
my_filename(fileno(stream)),errno);
}
writenbytes=(uint) -1; /* Return that we got error */
writtenbytes= (size_t) -1; /* Return that we got error */
break;
}
}
if (MyFlags & (MY_NABP | MY_FNABP))
writenbytes=0; /* Everything OK */
writtenbytes= 0; /* Everything OK */
else
writenbytes+=writen;
writtenbytes+= written;
break;
}
DBUG_RETURN(writenbytes);
DBUG_RETURN(writtenbytes);
} /* my_fwrite */
/* Seek to position in file */
/* ARGSUSED */
/* Seek to position in file */
my_off_t my_fseek(FILE *stream, my_off_t pos, int whence,
myf MyFlags __attribute__((unused)))
@ -158,8 +173,7 @@ my_off_t my_fseek(FILE *stream, my_off_t pos, int whence,
} /* my_seek */
/* Tell current position of file */
/* ARGSUSED */
/* Tell current position of file */
my_off_t my_ftell(FILE *stream, myf MyFlags __attribute__((unused)))
{