List:Commits« Previous MessageNext Message »
From:Tor Didriksen Date:June 20 2012 9:32am
Subject:bzr push into mysql-trunk branch (tor.didriksen:4031 to 4032) Bug#14171740
View as plain text  
 4032 Tor Didriksen	2012-06-20
      Bug#14171740 65562: STRING::SHRINK SHOULD BE A NO-OP WHEN ALLOCED=0
      
      Fixed both String implementations, and added unit tests.

    added:
      unittest/gunit/client_string-t.cc
      unittest/gunit/sql_string-t.cc
      unittest/gunit/string-tests.cc
    modified:
      client/sql_string.h
      sql/sql_string.h
      unittest/gunit/CMakeLists.txt
 4031 Alexander Barkov	2012-06-20
      Bug#14197426 parse errors in loadable UCA / LDML collations are silently ignored
           
      Problem: character set and collation errors in a running mysqld
      were erroneously sent to buffered_log, which is intended to
      be used only at earlier mysqld initialization step and should not
      be used after initialization.
      
      Fix: send character set and collation errors in a initialized
      server directly to error log instead of buffered_logs.

    modified:
      mysql-test/r/ctype_ldml.result
      mysql-test/t/ctype_ldml-master.opt
      mysql-test/t/ctype_ldml.test
      sql/mysqld.cc
=== modified file 'client/sql_string.h'
--- a/client/sql_string.h	2012-03-06 14:29:42 +0000
+++ b/client/sql_string.h	2012-06-20 09:31:36 +0000
@@ -1,7 +1,7 @@
 #ifndef CLIENT_SQL_STRING_INCLUDED
 #define CLIENT_SQL_STRING_INCLUDED
 
-/* Copyright (c) 2000, 2011, Oracle and/or its affiliates. All rights reserved.
+/* Copyright (c) 2000, 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
@@ -18,6 +18,9 @@
 
 /* This file is originally from the mysql distribution. Coded by monty */
 
+#include "m_ctype.h"
+#include "my_sys.h"
+
 class String;
 int sortcmp(const String *a,const String *b, const CHARSET_INFO *cs);
 String *copy_if_not_alloced(String *a,String *b,uint32 arg_length);
@@ -192,8 +195,12 @@ public:
   }
   bool real_alloc(uint32 arg_length);			// Empties old string
   bool realloc(uint32 arg_length);
-  inline void shrink(uint32 arg_length)		// Shrink buffer
+
+  // Shrink the buffer, but only if it is allocated on the heap.
+  inline void shrink(uint32 arg_length)
   {
+    if (!is_alloced())
+      return;
     if (arg_length < Alloced_length)
     {
       char *new_ptr;
@@ -209,7 +216,7 @@ public:
       }
     }
   }
-  bool is_alloced() { return alloced; }
+  bool is_alloced() const { return alloced; }
   inline String& operator = (const String &s)
   {
     if (&s != this)

=== modified file 'sql/sql_string.h'
--- a/sql/sql_string.h	2012-05-16 06:42:17 +0000
+++ b/sql/sql_string.h	2012-06-20 09:31:36 +0000
@@ -1,7 +1,7 @@
 #ifndef SQL_STRING_INCLUDED
 #define SQL_STRING_INCLUDED
 
-/* Copyright (c) 2000, 2011, Oracle and/or its affiliates. All rights reserved.
+/* Copyright (c) 2000, 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
@@ -322,8 +322,12 @@ public:
   }
   bool real_alloc(uint32 arg_length);			// Empties old string
   bool realloc(uint32 arg_length);
-  inline void shrink(uint32 arg_length)		// Shrink buffer
+
+  // Shrink the buffer, but only if it is allocated on the heap.
+  inline void shrink(uint32 arg_length)
   {
+    if (!is_alloced())
+      return;
     if (arg_length < Alloced_length)
     {
       char *new_ptr;
@@ -339,7 +343,7 @@ public:
       }
     }
   }
-  bool is_alloced() { return alloced; }
+  bool is_alloced() const { return alloced; }
   inline String& operator = (const String &s)
   {
     if (&s != this)

=== modified file 'unittest/gunit/CMakeLists.txt'
--- a/unittest/gunit/CMakeLists.txt	2012-05-31 15:33:21 +0000
+++ b/unittest/gunit/CMakeLists.txt	2012-06-20 09:31:36 +0000
@@ -237,6 +237,7 @@ SET(TESTS
   bounded_queue
   bounds_checked_array
   byteorder
+  client_string
   cost_estimate
   dbug
   decimal
@@ -251,6 +252,7 @@ SET(TESTS
   my_regex
   sql_list
   sql_plist
+  sql_string
   stdcxx
   thread_utils
   )

=== added file 'unittest/gunit/client_string-t.cc'
--- a/unittest/gunit/client_string-t.cc	1970-01-01 00:00:00 +0000
+++ b/unittest/gunit/client_string-t.cc	2012-06-20 09:31:36 +0000
@@ -0,0 +1,22 @@
+/* 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 "../../client/sql_string.h"
+
+#include "string-tests.cc"

=== added file 'unittest/gunit/sql_string-t.cc'
--- a/unittest/gunit/sql_string-t.cc	1970-01-01 00:00:00 +0000
+++ b/unittest/gunit/sql_string-t.cc	2012-06-20 09:31:36 +0000
@@ -0,0 +1,22 @@
+/* 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 "../../sql/sql_string.h"
+
+#include "string-tests.cc"

=== added file 'unittest/gunit/string-tests.cc'
--- a/unittest/gunit/string-tests.cc	1970-01-01 00:00:00 +0000
+++ b/unittest/gunit/string-tests.cc	2012-06-20 09:31:36 +0000
@@ -0,0 +1,39 @@
+/* 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 */
+
+/*
+  Common tests for client/sql_string and sql/sql_string.
+  TODO: Why do we have two versions of String?
+ */
+
+
+TEST(StringTest, EmptyString)
+{
+  String s;
+  const uint32 len= 0;
+  EXPECT_EQ(len, s.length());
+  EXPECT_EQ(len, s.alloced_length());
+}
+
+
+TEST(StringTest, ShrinkString)
+{
+  const uint32 len= 3;
+  char foo[len]= {'a', 'b', 0};
+  String foos(foo, len, &my_charset_bin);
+  foos.shrink(1);
+  EXPECT_EQ(len, foos.length());
+  EXPECT_STREQ("ab", foo);
+}

No bundle (reason: useless for push emails).
Thread
bzr push into mysql-trunk branch (tor.didriksen:4031 to 4032) Bug#14171740Tor Didriksen20 Jun