List:Commits« Previous MessageNext Message »
From:Tatjana Azundris Nuernberg Date:May 2 2012 1:30pm
Subject:bzr push into mysql-trunk branch (tatjana.nuernberg:3764 to 3765)
View as plain text  
 3765 Tatjana Azundris Nuernberg	2012-05-02 [merge]
      auto-merge

    added:
      unittest/gunit/my_error-t.cc
    modified:
      include/my_sys.h
      mysys/my_error.c
      sql/log.h
      unittest/gunit/CMakeLists.txt
 3764 Marko Mäkelä	2012-05-02
      Non-functional changes.
      
      dict_mem_table_create(): Remove bogus comment about clustered tables,
      which were never implemented in InnoDB.
      
      create_table_def(): Remove unnecessary type casts.

    modified:
      storage/innobase/dict/dict0mem.cc
      storage/innobase/handler/ha_innodb.cc
      storage/innobase/include/dict0mem.h
=== modified file 'include/my_sys.h'
--- a/include/my_sys.h	2012-03-06 14:29:42 +0000
+++ b/include/my_sys.h	2012-05-02 04:50:53 +0000
@@ -653,6 +653,7 @@ extern int my_sync(File fd, myf my_flags
 extern int my_sync_dir(const char *dir_name, myf my_flags);
 extern int my_sync_dir_by_file(const char *file_name, myf my_flags);
 extern char *my_strerror(char *buf, size_t len, int errnum);
+extern const char *my_get_err_msg(int nr);
 extern void my_error(int nr,myf MyFlags, ...);
 extern void my_printf_error(uint my_err, const char *format,
                             myf MyFlags, ...)

=== modified file 'mysys/my_error.c'
--- a/mysys/my_error.c	2012-03-06 14:29:42 +0000
+++ b/mysys/my_error.c	2012-05-02 04:50:53 +0000
@@ -59,6 +59,16 @@ static struct my_err_head
 static struct my_err_head *my_errmsgs_list= &my_errmsgs_globerrs;
 
 
+/**
+  Get a string describing a system or handler error. thread-safe.
+
+  @param  buf  a buffer in which to return the error message
+  @param  len  the size of the aforementioned buffer
+  @param  nr   the error number
+
+  @retval buf  always buf. for signature compatibility with strerror(3).
+*/
+
 char *my_strerror(char *buf, size_t len, int nr)
 {
   char *msg= NULL;
@@ -108,35 +118,63 @@ char *my_strerror(char *buf, size_t len,
 }
 
 
-/*
-   Error message to user
+/**
+  @brief Get an error format string from one of the my_error_register()ed sets
+
+  @note
+    NULL values are possible even within a registered range.
 
-   SYNOPSIS
-     my_error()
-       nr	Errno
-       MyFlags	Flags
-       ...	variable list
+  @param nr Errno
 
+  @retval NULL  if no message is registered for this error number
+  @retval str   C-string
 */
 
-void my_error(int nr, myf MyFlags, ...)
+const char *my_get_err_msg(int nr)
 {
   const char *format;
   struct my_err_head *meh_p;
-  va_list args;
-  char ebuff[ERRMSGSIZE];
-  DBUG_ENTER("my_error");
-  DBUG_PRINT("my", ("nr: %d  MyFlags: %d  errno: %d", nr, MyFlags, errno));
 
-  /* Search for the error messages array, which could contain the message. */
+  /* Search for the range this error is in. */
   for (meh_p= my_errmsgs_list; meh_p; meh_p= meh_p->meh_next)
     if (nr <= meh_p->meh_last)
       break;
 
-  /* get the error message string. Default, if NULL or empty string (""). */
-  if (! (format= (meh_p && (nr >= meh_p->meh_first)) ?
-                  meh_p->get_errmsgs()[nr - meh_p->meh_first] : NULL) || ! *format)
-    (void) my_snprintf (ebuff, sizeof(ebuff), "Unknown error %d", nr);
+  /*
+    If we found the range this error number is in, get the format string.
+    If the string is empty, or a NULL pointer, or if we're out of return,
+    we return NULL.
+  */
+  if (!(format= (meh_p && (nr >= meh_p->meh_first)) ?
+                meh_p->get_errmsgs()[nr - meh_p->meh_first] : NULL) ||
+      !*format)
+    return NULL;
+
+  return format;
+}
+
+
+/**
+  Fill in and print a previously registered error message.
+
+  @note
+    Goes through the (sole) function registered in error_handler_hook
+
+  @param nr        error number
+  @param MyFlags   Flags
+  @param ...       variable list matching that error format string
+*/
+
+void my_error(int nr, myf MyFlags, ...)
+{
+  const char *format;
+  va_list args;
+  char ebuff[ERRMSGSIZE];
+  DBUG_ENTER("my_error");
+  DBUG_PRINT("my", ("nr: %d  MyFlags: %d  errno: %d", nr, MyFlags, errno));
+
+  if (!(format = my_get_err_msg(nr)))
+    (void) my_snprintf(ebuff, sizeof(ebuff), "Unknown error %d", nr);
   else
   {
     va_start(args,MyFlags);
@@ -149,15 +187,16 @@ void my_error(int nr, myf MyFlags, ...)
 }
 
 
-/*
-  Error as printf
+/**
+  Print an error message.
 
-  SYNOPSIS
-    my_printf_error()
-      error	Errno
-      format	Format string
-      MyFlags	Flags
-      ...	variable list
+  @note
+    Goes through the (sole) function registered in error_handler_hook
+
+  @param error     error number
+  @param format    format string
+  @param MyFlags   Flags
+  @param ...       variable list matching that error format string
 */
 
 void my_printf_error(uint error, const char *format, myf MyFlags, ...)
@@ -176,15 +215,16 @@ void my_printf_error(uint error, const c
   DBUG_VOID_RETURN;
 }
 
-/*
-  Error with va_list
+/**
+  Print an error message.
+
+  @note
+    Goes through the (sole) function registered in error_handler_hook
 
-  SYNOPSIS
-    my_printv_error()
-      error	Errno
-      format	Format string
-      MyFlags	Flags
-      ...	variable list
+  @param error     error number
+  @param format    format string
+  @param MyFlags   Flags
+  @param ap        variable list matching that error format string
 */
 
 void my_printv_error(uint error, const char *format, myf MyFlags, va_list ap)
@@ -199,14 +239,15 @@ void my_printv_error(uint error, const c
   DBUG_VOID_RETURN;
 }
 
-/*
-  Give message using error_handler_hook
+/**
+  Print an error message.
+
+  @note
+    Goes through the (sole) function registered in error_handler_hook
 
-  SYNOPSIS
-    my_message()
-      error	Errno
-      str	Error message
-      MyFlags	Flags
+  @param error     error number
+  @param str       error message
+  @param MyFlags   Flags
 */
 
 void my_message(uint error, const char *str, register myf MyFlags)
@@ -215,16 +256,11 @@ void my_message(uint error, const char *
 }
 
 
-/*
+/**
   Register error messages for use with my_error().
 
-  SYNOPSIS
-    my_error_register()
-    errmsgs                     array of pointers to error messages
-    first                       error number of first message in the array
-    last                        error number of last message in the array
+  @description
 
-  DESCRIPTION
     The pointer array is expected to contain addresses to NUL-terminated
     C character strings. The array contains (last - first + 1) pointers.
     NULL pointers and empty strings ("") are allowed. These will be mapped to
@@ -232,9 +268,12 @@ void my_message(uint error, const char *
     This function registers the error numbers 'first' to 'last'.
     No overlapping with previously registered error numbers is allowed.
 
-  RETURN
-    0           OK
-    != 0        Error
+  @param   errmsgs  array of pointers to error messages
+  @param   first    error number of first message in the array
+  @param   last     error number of last message in the array
+
+  @retval  0        OK
+  @retval  != 0     Error
 */
 
 int my_error_register(const char** (*get_errmsgs) (), int first, int last)
@@ -273,25 +312,24 @@ int my_error_register(const char** (*get
 }
 
 
-/*
+/**
   Unregister formerly registered error messages.
 
-  SYNOPSIS
-    my_error_unregister()
-    first                       error number of first message
-    last                        error number of last message
+  @description
 
-  DESCRIPTION
     This function unregisters the error numbers 'first' to 'last'.
     These must have been previously registered by my_error_register().
     'first' and 'last' must exactly match the registration.
     If a matching registration is present, the header is removed from the
     list and the pointer to the error messages pointers array is returned.
+    (The messages themselves are not released here as they may be static.)
     Otherwise, NULL is returned.
 
-  RETURN
-    non-NULL    OK, returns address of error messages pointers array.
-    NULL        Error, no such number range registered.
+  @param   first     error number of first message
+  @param   last      error number of last message
+
+  @retval  NULL      Error, no such number range registered.
+  @retval  non-NULL  OK, returns address of error messages pointers array.
 */
 
 const char **my_error_unregister(int first, int last)
@@ -324,6 +362,17 @@ const char **my_error_unregister(int fir
 }
 
 
+/**
+  Unregister all formerly registered error messages.
+
+  @description
+
+    This function unregisters all error numbers that previously have
+    been previously registered by my_error_register().
+    All headers are removed from the list; the messages themselves are
+    not released here as they may be static.
+*/
+
 void my_error_unregister_all(void)
 {
   struct my_err_head *cursor, *saved_next;

=== modified file 'sql/log.h'
--- a/sql/log.h	2012-04-20 22:39:38 +0000
+++ b/sql/log.h	2012-05-02 04:50:53 +0000
@@ -333,8 +333,6 @@ int check_if_log_table(size_t db_len, co
 
 class Log_to_csv_event_handler: public Log_event_handler
 {
-  friend class LOGGER;
-
 public:
   Log_to_csv_event_handler();
   ~Log_to_csv_event_handler();

=== modified file 'unittest/gunit/CMakeLists.txt'
--- a/unittest/gunit/CMakeLists.txt	2012-02-23 13:10:18 +0000
+++ b/unittest/gunit/CMakeLists.txt	2012-05-02 04:50:53 +0000
@@ -259,6 +259,7 @@ SET(SERVER_TESTS
   opt_trace
   sql_table
   get_diagnostics
+  my_error
   segfault
   join_tab_sort
 )

=== added file 'unittest/gunit/my_error-t.cc'
--- a/unittest/gunit/my_error-t.cc	1970-01-01 00:00:00 +0000
+++ b/unittest/gunit/my_error-t.cc	2012-05-02 04:50:53 +0000
@@ -0,0 +1,108 @@
+/* Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved.
+
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; version 2 of the License.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program; if not, write to the Free Software
+   Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02111-1307  USA */
+
+// First include (the generated) my_config.h, to get correct platform defines.
+#include "my_config.h"
+#include <gtest/gtest.h>
+
+#include "my_sys.h" // my_strerror()
+#include "my_base.h" // HA_ERR_KEY_NOT_FOUND
+
+namespace {
+
+TEST(MyErrorTest, MyStrErrorSystem)
+{
+  char buf[512];
+  const char *msg;
+
+  msg= my_strerror(buf, sizeof(buf) - 1, 9999);
+  EXPECT_TRUE(!strcasecmp("unknown error", msg) ||
+              !strcasecmp("unknown error 9999", msg));
+
+  // try a proper error number
+  msg= my_strerror(buf, sizeof(buf) - 1, 1);
+  EXPECT_STRCASEEQ("Operation not permitted", msg);
+}
+
+TEST(MyErrorTest, MyStrErrorHandlerPlugin)
+{
+  char buf[512];
+  const char *msg;
+
+  // try a HA error number
+  msg= my_strerror(buf, sizeof(buf) - 1, HA_ERR_KEY_NOT_FOUND);
+  EXPECT_STREQ("Didn't find key on read or update", msg);
+}
+
+TEST(MyErrorTest, MyGetErrMsgUnitialized)
+{
+  const char *msg;
+
+  msg= my_get_err_msg(HA_ERR_KEY_NOT_FOUND);
+  EXPECT_TRUE(msg == NULL);
+}
+
+const char *faux_errmsgs[]= { "alpha", "beta", NULL, "delta" };
+
+const char** get_faux_errmsgs()
+{
+  return faux_errmsgs;
+}
+
+static const int faux_error_first= 8000;
+static const int faux_error_last=  8003;
+
+TEST(MyErrorTest, MyGetErrMsgInitialized)
+{
+  const char *msg;
+
+  EXPECT_EQ(0, my_error_register(get_faux_errmsgs,
+                                 faux_error_first,
+                                 faux_error_last));
+
+  // flag error when trying to register overlapping area
+  EXPECT_NE(0, my_error_register(get_faux_errmsgs,
+                                 faux_error_first + 2,
+                                 faux_error_last + 2));
+
+  msg= my_get_err_msg(faux_error_first);
+  EXPECT_STREQ("alpha", msg);
+
+  msg= my_get_err_msg(faux_error_first + 1);
+  EXPECT_STREQ("beta", msg);
+
+  // within range. gives NULL here. higher level function will
+  // substitute a default string before printing.
+  msg= my_get_err_msg(faux_error_first + 2);
+  EXPECT_TRUE(msg == NULL);
+
+  // out of range
+  msg= my_get_err_msg(faux_error_first - 1);
+  EXPECT_TRUE(msg == NULL);
+
+  msg= my_get_err_msg(faux_error_last);
+  EXPECT_STREQ("delta", msg);
+
+  // out of range
+  msg= my_get_err_msg(faux_error_last + 1);
+  EXPECT_TRUE(msg == NULL);
+
+  EXPECT_TRUE(my_error_unregister(faux_error_first, faux_error_last) != NULL);
+
+  // flag error when trying to unregister twice
+  EXPECT_TRUE(my_error_unregister(faux_error_first, faux_error_last) == NULL);
+}
+
+}

No bundle (reason: useless for push emails).
Thread
bzr push into mysql-trunk branch (tatjana.nuernberg:3764 to 3765) Tatjana Azundris Nuernberg2 May