List:Commits« Previous MessageNext Message »
From:Davi Arnaut Date:January 30 2009 12:32pm
Subject:bzr commit into mysql-6.0 branch (davi:2715)
View as plain text  
# At a local mysql-6.0 repository of davi

 2715 Davi Arnaut	2009-01-30
      Remove the global errbuf as this buffer is not needed anymore and
      its use can lead to problems in a threaded environment.
modified:
  include/my_global.h
  include/my_sys.h
  mysys/my_error.c
  mysys/my_init.c
  mysys/safemalloc.c
  sql/backup/kernel.cc
  sql/backup/logger.cc
  sql/sql_error.cc
  sql/sql_parse.cc
  sql/sql_table.cc
  storage/maria/ha_maria.cc
  storage/myisam/ha_myisam.cc

per-file messages:
  include/my_global.h
    Remove SC_MAXWIDTH. This is unused and irrelevant nowadays.
  include/my_sys.h
    Remove errbuf declaration and unused definitions.
  mysys/my_error.c
    Remove errbuf definition and move and adjust ERRMSGSIZE.
  mysys/my_init.c
    Declare buffer on the stack and use my_snprintf.
  mysys/safemalloc.c
    Use size explicitly. It's more than enough for the message at hand.
  sql/backup/kernel.cc
    Use MYSQL_ERRMSG_SIZE.
  sql/backup/logger.cc
    Use MYSQL_ERRMSG_SIZE.
  sql/sql_error.cc
    Use MYSQL_ERRMSG_SIZE.
  sql/sql_parse.cc
    Declare buffer on the stack. Use my_snprintf as it will result in
    less stack space being used than by a system provided sprintf --
    this allows us to put the buffer on the stack without causing much
    trouble. Also, the use of errbuff here was not thread-safe as the
    function can be entered concurrently from multiple threads.
  sql/sql_table.cc
    Use MYSQL_ERRMSG_SIZE. Extra space is not needed as my_snprintf will
    nul terminate strings.
  storage/maria/ha_maria.cc
    128 bytes is enough for the given message.
  storage/myisam/ha_myisam.cc
    Use MYSQL_ERRMSG_SIZE.
=== modified file 'include/my_global.h'
--- a/include/my_global.h	2009-01-06 10:38:47 +0000
+++ b/include/my_global.h	2009-01-30 12:32:09 +0000
@@ -757,7 +757,6 @@ typedef SOCKET_SIZE_TYPE size_socket;
 #define UNSINT32		/* unsigned int32 */
 
 	/* General constants */
-#define SC_MAXWIDTH	256	/* Max width of screen (for error messages) */
 #define FN_LEN		256	/* Max file name len */
 #define FN_HEADLEN	253	/* Max length of filepart of file name */
 #define FN_EXTLEN	20	/* Max length of extension (part of FN_LEN) */

=== modified file 'include/my_sys.h'
--- a/include/my_sys.h	2009-01-16 11:53:32 +0000
+++ b/include/my_sys.h	2009-01-30 12:32:09 +0000
@@ -43,8 +43,6 @@ extern int NEAR my_errno;		/* Last error
 #define MYSYS_PROGRAM_DONT_USE_CURSES()  { error_handler_hook = my_message_no_curses; mysys_uses_curses=0;}
 #define MY_INIT(name);		{ my_progname= name; my_init(); }
 
-#define ERRMSGSIZE	(SC_MAXWIDTH)	/* Max length of a error message */
-#define NRERRBUFFS	(2)	/* Buffers for parameters */
 #define MY_FILE_ERROR	((size_t) -1)
 
 	/* General bitmaps for my_func's */
@@ -214,7 +212,6 @@ extern void my_large_free(uchar * ptr, m
 extern int errno;			/* declare errno */
 #endif
 #endif					/* #ifndef errno */
-extern char NEAR errbuff[NRERRBUFFS][ERRMSGSIZE];
 extern char *home_dir;			/* Home directory for user */
 extern const char *my_progname;		/* program-name (printed in errors) */
 extern const char *my_progname_short;	/* like above but without directory */

=== modified file 'mysys/my_error.c'
--- a/mysys/my_error.c	2008-05-29 15:44:11 +0000
+++ b/mysys/my_error.c	2009-01-30 12:32:09 +0000
@@ -19,6 +19,9 @@
 #include <stdarg.h>
 #include <m_ctype.h>
 
+/* Max length of a error message. Should be kept in sync with MYSQL_ERRMSG_SIZE. */
+#define ERRMSGSIZE      (512)
+
 /* Define some external variables for error handling */
 
 /*
@@ -30,8 +33,6 @@
   my_printf_error(ER_CODE, format, MYF(N), ...)
 */
 
-char NEAR errbuff[NRERRBUFFS][ERRMSGSIZE];
-
 /*
   Message texts are registered into a linked list of 'my_err_head' structs.
   Each struct contains (1.) an array of pointers to C character strings with
@@ -71,7 +72,7 @@ void my_error(int nr, myf MyFlags, ...)
   const char *format;
   struct my_err_head *meh_p;
   va_list args;
-  char ebuff[ERRMSGSIZE + 20];
+  char ebuff[ERRMSGSIZE];
   DBUG_ENTER("my_error");
   DBUG_PRINT("my", ("nr: %d  MyFlags: %d  errno: %d", nr, MyFlags, errno));
 
@@ -109,7 +110,7 @@ void my_error(int nr, myf MyFlags, ...)
 void my_printf_error(uint error, const char *format, myf MyFlags, ...)
 {
   va_list args;
-  char ebuff[ERRMSGSIZE+20];
+  char ebuff[ERRMSGSIZE];
   DBUG_ENTER("my_printf_error");
   DBUG_PRINT("my", ("nr: %d  MyFlags: %d  errno: %d  format: %s",
 		    error, MyFlags, errno, format));
@@ -135,7 +136,7 @@ void my_printf_error(uint error, const c
 
 void my_printv_error(uint error, const char *format, myf MyFlags, va_list ap)
 {
-  char ebuff[ERRMSGSIZE+20];
+  char ebuff[ERRMSGSIZE];
   DBUG_ENTER("my_printv_error");
   DBUG_PRINT("my", ("nr: %d  MyFlags: %d  errno: %d  format: %s",
 		    error, MyFlags, errno, format));

=== modified file 'mysys/my_init.c'
--- a/mysys/my_init.c	2009-01-16 11:49:33 +0000
+++ b/mysys/my_init.c	2009-01-30 12:32:09 +0000
@@ -158,9 +158,11 @@ void my_end(int infoflag)
   {					/* Test if some file is left open */
     if (my_file_opened | my_stream_opened)
     {
-      sprintf(errbuff[0],EE(EE_OPEN_WARNING),my_file_opened,my_stream_opened);
-      (void) my_message_no_curses(EE_OPEN_WARNING,errbuff[0],ME_BELL);
-      DBUG_PRINT("error",("%s",errbuff[0]));
+      char ebuff[512];
+      my_snprintf(ebuff, sizeof(ebuff), EE(EE_OPEN_WARNING),
+                  my_file_opened, my_stream_opened);
+      my_message_no_curses(EE_OPEN_WARNING, ebuff, ME_BELL);
+      DBUG_PRINT("error", ("%s", ebuff));
       my_print_open_files();
     }
   }

=== modified file 'mysys/safemalloc.c'
--- a/mysys/safemalloc.c	2008-10-20 09:16:47 +0000
+++ b/mysys/safemalloc.c	2009-01-30 12:32:09 +0000
@@ -147,7 +147,7 @@ void *_mymalloc(size_t size, const char 
       error_handler_hook=fatal_error_handler_hook;
     if (MyFlags & (MY_FAE+MY_WME))
     {
-      char buff[SC_MAXWIDTH];
+      char buff[256];
       my_errno=errno;
       sprintf(buff,"Out of memory at line %d, '%s'", lineno, filename);
       my_message(EE_OUTOFMEMORY, buff, MYF(ME_BELL+ME_WAITTANG+ME_NOREFRESH));

=== modified file 'sql/backup/kernel.cc'
--- a/sql/backup/kernel.cc	2009-01-14 10:10:00 +0000
+++ b/sql/backup/kernel.cc	2009-01-30 12:32:09 +0000
@@ -266,7 +266,7 @@ int send_error(Backup_restore_ctx &conte
 {
   if (!context.error_reported())
   {
-    char buf[ERRMSGSIZE + 20];
+    char buf[MYSQL_ERRMSG_SIZE];
     va_list args;
     va_start(args, error_code);
 

=== modified file 'sql/backup/logger.cc'
--- a/sql/backup/logger.cc	2008-12-10 15:53:06 +0000
+++ b/sql/backup/logger.cc	2009-01-30 12:32:09 +0000
@@ -33,7 +33,7 @@ namespace backup {
 int Logger::write_message(log_level::value level, int error_code,
                           const char *msg)
 {
-   char buf[ERRMSGSIZE + 30];
+   char buf[MYSQL_ERRMSG_SIZE];
    /*
      When logging to server's error log, msg will be prefixed with
      "Backup:"/"Restore:" if the operation has been initialized (i.e., after
@@ -141,7 +141,7 @@ int Logger::v_report_error(log_level::va
 int Logger::v_write_message(log_level::value level, int error_code,
                             const char *format, va_list args)
 {
-  char buf[ERRMSGSIZE + 20];
+  char buf[MYSQL_ERRMSG_SIZE];
 
   my_vsnprintf(buf, sizeof(buf), format, args);
   return write_message(level, error_code, buf);

=== modified file 'sql/sql_error.cc'
--- a/sql/sql_error.cc	2008-12-10 21:53:59 +0000
+++ b/sql/sql_error.cc	2009-01-30 12:32:09 +0000
@@ -362,7 +362,7 @@ void push_warning_printf(THD *thd, MYSQL
 			 uint code, const char *format, ...)
 {
   va_list args;
-  char    warning[ERRMSGSIZE+20];
+  char    warning[MYSQL_ERRMSG_SIZE];
   DBUG_ENTER("push_warning_printf");
   DBUG_PRINT("enter",("warning: %u", code));
 

=== modified file 'sql/sql_parse.cc'
--- a/sql/sql_parse.cc	2009-01-26 17:19:14 +0000
+++ b/sql/sql_parse.cc	2009-01-30 12:32:09 +0000
@@ -5371,9 +5371,10 @@ bool check_stack_overrun(THD *thd, long 
   if ((stack_used=used_stack(thd->thread_stack,(char*) &stack_used)) >=
       (long) (my_thread_stack_size - margin))
   {
-    sprintf(errbuff[0],ER(ER_STACK_OVERRUN_NEED_MORE),
-            stack_used,my_thread_stack_size,margin);
-    my_message(ER_STACK_OVERRUN_NEED_MORE,errbuff[0],MYF(ME_FATALERROR));
+    char ebuff[MYSQL_ERRMSG_SIZE];
+    my_snprintf(ebuff, sizeof(ebuff), ER(ER_STACK_OVERRUN_NEED_MORE),
+                stack_used, my_thread_stack_size, margin);
+    my_message(ER_STACK_OVERRUN_NEED_MORE, ebuff, MYF(ME_FATALERROR));
     return 1;
   }
 #ifndef DBUG_OFF

=== modified file 'sql/sql_table.cc'
--- a/sql/sql_table.cc	2009-01-27 02:08:48 +0000
+++ b/sql/sql_table.cc	2009-01-30 12:32:09 +0000
@@ -4495,8 +4495,8 @@ send_result_message:
     switch (result_code) {
     case HA_ADMIN_NOT_IMPLEMENTED:
       {
-	char buf[ERRMSGSIZE+20];
-	uint length=my_snprintf(buf, ERRMSGSIZE,
+	char buf[MYSQL_ERRMSG_SIZE];
+	uint length=my_snprintf(buf, sizeof(buf),
 				ER(ER_CHECK_NOT_IMPLEMENTED), operator_name);
 	protocol->store(STRING_WITH_LEN("note"), system_charset_info);
 	protocol->store(buf, length, system_charset_info);
@@ -4505,8 +4505,8 @@ send_result_message:
 
     case HA_ADMIN_NOT_BASE_TABLE:
       {
-        char buf[ERRMSGSIZE+20];
-        uint length= my_snprintf(buf, ERRMSGSIZE,
+        char buf[MYSQL_ERRMSG_SIZE];
+        uint length= my_snprintf(buf, sizeof(buf),
                                  ER(ER_BAD_TABLE_ERROR), table_name);
         protocol->store(STRING_WITH_LEN("note"), system_charset_info);
         protocol->store(buf, length, system_charset_info);
@@ -4633,11 +4633,12 @@ send_result_message:
     case HA_ADMIN_NEEDS_UPGRADE:
     case HA_ADMIN_NEEDS_ALTER:
     {
-      char buf[ERRMSGSIZE];
+      char buf[MYSQL_ERRMSG_SIZE];
       uint length;
 
       protocol->store(STRING_WITH_LEN("error"), system_charset_info);
-      length=my_snprintf(buf, ERRMSGSIZE, ER(ER_TABLE_NEEDS_UPGRADE), table->table_name);
+      length=my_snprintf(buf, sizeof(buf), ER(ER_TABLE_NEEDS_UPGRADE),
+                         table->table_name);
       protocol->store(buf, length, system_charset_info);
       fatal_error=1;
       break;
@@ -4645,8 +4646,8 @@ send_result_message:
 
     default:				// Probably HA_ADMIN_INTERNAL_ERROR
       {
-        char buf[ERRMSGSIZE+20];
-        uint length=my_snprintf(buf, ERRMSGSIZE,
+        char buf[MYSQL_ERRMSG_SIZE];
+        uint length=my_snprintf(buf, sizeof(buf),
                                 "Unknown - internal error %d during operation",
                                 result_code);
         protocol->store(STRING_WITH_LEN("error"), system_charset_info);

=== modified file 'storage/maria/ha_maria.cc'
--- a/storage/maria/ha_maria.cc	2009-01-13 15:26:20 +0000
+++ b/storage/maria/ha_maria.cc	2009-01-30 12:32:09 +0000
@@ -1457,7 +1457,7 @@ int ha_maria::preload_keys(THD * thd, HA
 
   if ((error= maria_preload(file, map, table_list->ignore_leaves)))
   {
-    char buf[ERRMSGSIZE+20];
+    char buf[128];
     const char *errmsg;
 
     switch (error) {
@@ -1468,7 +1468,7 @@ int ha_maria::preload_keys(THD * thd, HA
       errmsg= "Failed to allocate buffer";
       break;
     default:
-      my_snprintf(buf, ERRMSGSIZE,
+      my_snprintf(buf, sizeof(buf),
                   "Failed to read from index file (errno: %d)", my_errno);
       errmsg= buf;
     }

=== modified file 'storage/myisam/ha_myisam.cc'
--- a/storage/myisam/ha_myisam.cc	2009-01-19 13:16:25 +0000
+++ b/storage/myisam/ha_myisam.cc	2009-01-30 12:32:09 +0000
@@ -1134,7 +1134,7 @@ int ha_myisam::preload_keys(THD* thd, HA
   ulonglong map;
   TABLE_LIST *table_list= table->pos_in_table_list;
   my_bool ignore_leaves= table_list->ignore_leaves;
-  char buf[ERRMSGSIZE+20];
+  char buf[MYSQL_ERRMSG_SIZE];
 
   DBUG_ENTER("ha_myisam::preload_keys");
 
@@ -1162,7 +1162,7 @@ int ha_myisam::preload_keys(THD* thd, HA
       errmsg= "Failed to allocate buffer";
       break;
     default:
-      my_snprintf(buf, ERRMSGSIZE,
+      my_snprintf(buf, sizeof(buf),
                   "Failed to read from index file (errno: %d)", my_errno);
       errmsg= buf;
     }

Thread
bzr commit into mysql-6.0 branch (davi:2715) Davi Arnaut30 Jan
  • Re: bzr commit into mysql-6.0 branch (davi:2715)Konstantin Osipov2 Feb