List:Commits« Previous MessageNext Message »
From:Bjorn Munch Date:November 4 2011 2:28pm
Subject:bzr push into mysql-trunk-mtr branch (bjorn.munch:3132 to 3133)
View as plain text  
 3133 Bjorn Munch	2011-11-04 [merge]
      merge trunk => trunk-mtr

    removed:
      BUILD/compile-alpha-debug
      BUILD/compile-darwin-mwcc
      BUILD/compile-irix-mips64-mipspro
      BUILD/compile-pentium-icc
      BUILD/compile-pentium-icc-valgrind-max
      BUILD/compile-pentium-icc-yassl
      BUILD/compile-pentium-pgcc
      mysys/my_new.cc
    added:
      mysys/my_isnan.c
      unittest/gunit/stdcxx-t.cc
    renamed:
      mysys/psi_noop.cc => mysys/psi_noop.c
      sql/udf_example.c => sql/udf_example.cc
    modified:
      BUILD/SETUP.sh
      BUILD/build_mccge.sh
      BUILD/compile-dist
      BUILD/compile-solaris-amd64
      BUILD/compile-solaris-amd64-forte
      BUILD/compile-solaris-amd64-forte-debug
      BUILD/compile-solaris-sparc
      BUILD/compile-solaris-sparc-debug
      BUILD/compile-solaris-sparc-forte
      BUILD/compile-solaris-sparc-purify
      VERSION
      client/CMakeLists.txt
      client/mysql.cc
      client/mysql_upgrade.c
      client/mysqlbinlog.cc
      client/mysqldump.c
      client/mysqltest.cc
      client/sql_string.cc
      cmake/build_configurations/mysql_release.cmake
      cmake/configure.pl
      cmake/info_macros.cmake.in
      cmake/os/Windows.cmake
      cmake/readline.cmake
      config.h.cmake
      configure.cmake
      dbug/dbug.c
      include/m_string.h
      include/my_global.h
      include/my_pthread.h
      include/mysql.h
      include/mysql/psi/mysql_thread.h
      include/mysql/psi/psi.h
      include/mysql/psi/psi_abi_v1.h
      include/mysql_com.h
      include/waiting_threads.h
      libmysql/libmysql.c
      libmysqld/lib_sql.cc
      mysql-test/mysql-test-run.pl
      mysql-test/r/case.result
      mysql-test/r/udf.result
      mysql-test/t/case.test
      mysql-test/t/disabled.def
      mysql-test/t/mysql_plugin.test
      mysql-test/t/udf.test
      mysys/CMakeLists.txt
      mysys/array.c
      mysys/default.c
      mysys/lf_alloc-pin.c
      mysys/lf_dynarray.c
      mysys/mf_format.c
      mysys/mf_iocache.c
      mysys/my_alloc.c
      mysys/my_bitmap.c
      mysys/my_compare.c
      mysys/my_compress.c
      mysys/my_file.c
      mysys/stacktrace.c
      mysys/waiting_threads.c
      sql-common/client.c
      sql-common/client_plugin.c
      sql-common/my_time.c
      sql/CMakeLists.txt
      sql/binlog.cc
      sql/debug_sync.cc
      sql/field.cc
      sql/field.h
      sql/filesort.cc
      sql/ha_partition.cc
      sql/handler.cc
      sql/handler.h
      sql/item.cc
      sql/item_buff.cc
      sql/item_cmpfunc.cc
      sql/item_func.cc
      sql/item_func.h
      sql/item_strfunc.cc
      sql/item_strfunc.h
      sql/item_sum.cc
      sql/item_timefunc.cc
      sql/item_timefunc.h
      sql/key.cc
      sql/log.cc
      sql/log_event.cc
      sql/log_event.h
      sql/log_event_old.cc
      sql/mdl.cc
      sql/mdl.h
      sql/mysqld.cc
      sql/net_serv.cc
      sql/opt_range.cc
      sql/opt_range.h
      sql/opt_trace.cc
      sql/opt_trace.h
      sql/protocol.cc
      sql/rpl_mi.cc
      sql/rpl_record.cc
      sql/rpl_rli.cc
      sql/rpl_slave.cc
      sql/rpl_utility.cc
      sql/rpl_utility.h
      sql/set_var.cc
      sql/set_var.h
      sql/sp_head.cc
      sql/spatial.h
      sql/sql_acl.cc
      sql/sql_analyse.cc
      sql/sql_cache.cc
      sql/sql_class.cc
      sql/sql_client.cc
      sql/sql_connect.cc
      sql/sql_const.h
      sql/sql_error.cc
      sql/sql_join_cache.cc
      sql/sql_load.cc
      sql/sql_parse.cc
      sql/sql_partition.cc
      sql/sql_plugin.cc
      sql/sql_plugin.h
      sql/sql_prepare.cc
      sql/sql_profile.cc
      sql/sql_select.cc
      sql/sql_select.h
      sql/sql_show.cc
      sql/sql_string.cc
      sql/sql_table.cc
      sql/sql_table.h
      sql/sql_yacc.yy
      sql/thr_malloc.cc
      sql/tztime.cc
      sql/udf_example.def
      sql/unireg.cc
      storage/csv/ha_tina.cc
      storage/federated/ha_federated.cc
      storage/heap/hp_create.c
      storage/heap/hp_static.c
      storage/heap/hp_test2.c
      storage/innobase/sync/sync0rw.c
      storage/myisam/ha_myisam.cc
      storage/myisam/mi_cache.c
      storage/myisam/mi_check.c
      storage/myisam/mi_create.c
      storage/myisam/mi_dynrec.c
      storage/myisam/mi_extra.c
      storage/myisam/mi_open.c
      storage/myisam/mi_packrec.c
      storage/myisam/mi_static.c
      storage/myisam/myisamlog.c
      storage/myisam/myisampack.c
      storage/myisam/rt_mbr.c
      storage/myisam/sort.c
      storage/myisammrg/ha_myisammrg.cc
      strings/ctype-big5.c
      strings/ctype-bin.c
      strings/ctype-gbk.c
      strings/ctype-mb.c
      strings/ctype-simple.c
      strings/ctype-tis620.c
      strings/ctype-uca.c
      strings/ctype-ucs2.c
      strings/ctype-utf8.c
      strings/ctype.c
      strings/decimal.c
      strings/dtoa.c
      strings/my_vsnprintf.c
      support-files/mysql.spec.sh
      tests/mysql_client_test.c
      unittest/gunit/CMakeLists.txt
      unittest/gunit/gunit_test_main.cc
      unittest/gunit/item-t.cc
      unittest/mysys/lf-t.c
      unittest/mysys/my_atomic-t.c
      unittest/mysys/thr_template.c
      unittest/mysys/waiting_threads-t.c
      vio/viosocket.c
      win/create_def_file.js
      mysys/psi_noop.c
      sql/udf_example.cc
 3132 Bjorn Munch	2011-11-03 [merge]
      null upmerge

=== modified file 'BUILD/SETUP.sh'
--- a/BUILD/SETUP.sh	2011-06-30 15:50:45 +0000
+++ b/BUILD/SETUP.sh	2011-10-11 04:27:52 +0000
@@ -151,7 +151,7 @@ debug_cflags="$debug_cflags -DSAFE_MUTEX
 error_inject="--with-error-inject "
 #
 # Base C++ flags for all builds
-base_cxxflags="-felide-constructors -fno-exceptions -fno-rtti"
+base_cxxflags="-felide-constructors"
 #
 # Flags for optimizing builds.
 # Be as fast as we can be without losing our ability to backtrace.
@@ -215,7 +215,7 @@ if test -z "$CC" ; then
 fi
 
 if test -z "$CXX" ; then
-  CXX=gcc
+  CXX=g++
 fi
 
 # If ccache (a compiler cache which reduces build time)

=== modified file 'BUILD/build_mccge.sh'
--- a/BUILD/build_mccge.sh	2011-06-30 15:50:45 +0000
+++ b/BUILD/build_mccge.sh	2011-10-11 04:27:52 +0000
@@ -431,7 +431,7 @@ extended_usage()
 
     In all cases it is possible to override the definition of CC and CXX
     by calling the script as follows:
-    CC="/usr/local/bin/gcc" CXX="/usr/local/bin/gcc" BUILD/build_mccge.sh
+    CC="/usr/local/bin/gcc" CXX="/usr/local/bin/g++" BUILD/build_mccge.sh
 
   Feedback profiler on gcc
   ------------------------
@@ -1368,10 +1368,10 @@ set_icc_special_options()
 set_cc_and_cxx_for_gcc()
 {
   if test "x$CC" = "x" ; then
-    CC="gcc -static-libgcc -fno-exceptions"
+    CC="gcc -static-libgcc"
   fi
   if test "x$CXX" = "x" ; then
-    CXX="gcc -static-libgcc -fno-exceptions"
+    CXX="g++ -static-libgcc"
   fi
 }
 
@@ -1388,10 +1388,10 @@ set_cc_and_cxx_for_icc()
 set_cc_and_cxx_for_open64()
 {
   if test "x$CC" = "x" ; then
-    CC="opencc -static-libgcc -fno-exceptions"
+    CC="opencc -static-libgcc"
   fi
   if test "x$CXX" = "x" ; then
-    CXX="openCC -static-libgcc -fno-exceptions"
+    CXX="openCC -static-libgcc"
   fi
 }
 
@@ -1689,7 +1689,6 @@ set_solaris_configs()
     fi
     if test "x$cpu_base_type" = "xx86" ; then
       compiler_flags="$compiler_flags -nofstore"
-      base_cxx_flags="$base_cxx_flags -features=no%except"
       if test "x$fast_flag" = "xyes" ; then
         compiler_flags="$compiler_flags -xregs=frameptr"
         compiler_flags="$compiler_flags -xO4"
@@ -1705,7 +1704,6 @@ set_solaris_configs()
 #Using SPARC cpu with SunStudio (Forte) compiler
       ASFLAGS="$ASFLAGS -xarch=sparc"
       LDFLAGS="$LDFLAGS -xarch=sparc"
-      base_cxxflags="$base_cxxflags -noex"
       base_cflags="$base_cflags -xstrconst"
       compiler_flags="$compiler_flags -xarch=sparc"
       if test "x$fast_flag" = "xyes" ; then

=== removed file 'BUILD/compile-alpha-debug'
--- a/BUILD/compile-alpha-debug	2010-12-28 23:47:05 +0000
+++ b/BUILD/compile-alpha-debug	1970-01-01 00:00:00 +0000
@@ -1,27 +0,0 @@
-#! /bin/sh
-
-# Copyright (C) 2000, 2005 MySQL AB
-# 
-# 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., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
-
-/bin/rm -f */.deps/*.P */*.o
-make -k maintainer-clean
-/bin/rm -f */.deps/*.P */*.o
-/bin/rm -f */.deps/*.P config.cache storage/innobase/config.cache mysql-*.tar.gz
-
-path=`dirname $0`
-. "$path/autorun.sh"
-
-CFLAGS=-O1 CC=gcc CXX=gcc CXXFLAGS="-O1 -felide-constructors -fno-exceptions -fno-rtti" ./configure --prefix=/usr/local/mysql --with-debug --with-extra-charsets=complex  --without-extra-tools
-make

=== removed file 'BUILD/compile-darwin-mwcc'
--- a/BUILD/compile-darwin-mwcc	2010-12-28 23:47:05 +0000
+++ b/BUILD/compile-darwin-mwcc	1970-01-01 00:00:00 +0000
@@ -1,65 +0,0 @@
-#! /bin/sh
-
-# Copyright (C) 2005 MySQL AB
-# 
-# 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., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
-
-path=`dirname $0`
-. "$path/SETUP.sh"
-
-c_warnings=""
-cxx_warnings=""
-fast_cflags="-O3"
-base_cxxflags="-fno-handle-exceptions"
-
-# FIXME do we need to link static, not to depend on CodeWarrior libs?
-
-if [ x$MODE = x ] ; then
-  echo "You need to give an argument, 'standard', 'max', 'debug' or 'debug-max'"
-  echo "Like: MODE=standard BUILD/compile-darwin-codewarrior"
-  exit 1
-else
-  case $MODE in
-    standard|pro-gpl)
-      # FIXME pro/pro-gpl different libedit/readline
-      extra_flags="$ppc_cflags $fast_cflags"
-      ;;
-    pro)
-      # FIXME pro/pro-gpl different libedit/readline
-      extra_flags="$ppc_cflags $fast_cflags"
-      extra_configs="--with-libedit"
-      ;;
-    max)
-      extra_flags="$ppc_cflags $fast_cflags"
-      extra_configs="$max_configs"
-      ;;
-    debug)
-      extra_flags="$ppc_cflags $debug_cflags"
-      extra_configs="$debug_configs"
-      ;;
-    debug-max)
-      extra_flags="$ppc_cflags $debug_cflags"
-      extra_configs="$debug_configs $max_configs"
-      ;;
-    *)
-      echo "You need to give an argument, 'standard', 'max', 'debug' or 'debug-max'"
-      echo "Like: MODE=standard BUILD/compile-darwin-codewarrior"
-      exit 1
-      ;;
-  esac
-fi
-
-extra_configs="$extra_configs --with-darwin-mwcc"
-
-. "$path/FINISH.sh"

=== modified file 'BUILD/compile-dist'
--- a/BUILD/compile-dist	2011-06-30 15:50:45 +0000
+++ b/BUILD/compile-dist	2011-10-11 04:27:52 +0000
@@ -44,11 +44,11 @@ fi
 # Default to gcc for CC and CXX
 if test -z "$CXX" ; then
   export CXX
-  CXX=gcc
+  CXX=g++
   # Set some required compile options
   if test -z "$CXXFLAGS" ; then
     export CXXFLAGS
-    CXXFLAGS="-felide-constructors -fno-exceptions -fno-rtti"
+    CXXFLAGS="-felide-constructors"
   fi
 fi
 

=== removed file 'BUILD/compile-irix-mips64-mipspro'
--- a/BUILD/compile-irix-mips64-mipspro	2010-12-28 23:47:05 +0000
+++ b/BUILD/compile-irix-mips64-mipspro	1970-01-01 00:00:00 +0000
@@ -1,94 +0,0 @@
-#!/bin/sh
-
-# Copyright (C) 2004, 2005 MySQL AB
-# 
-# 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., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
-
-if [ ! -f "sql/mysqld.cc" ]; then
-  echo "You must run this script from the MySQL top-level directory."
-  exit 1
-fi
-
-cflags="-64 -mips4"
-config_args=
-if [ "$#" != 0 ]; then
-  case "$1" in
-    --help)
-      echo "Usage: $0 [options]"
-      echo "Options:" 
-      echo "--help                print this message"
-      echo "-32                   build 32-bit binary"
-      echo "-64                   build 64-bit binary [default]"
-      exit 0
-      ;;
-    -64)
-      echo "Building 64-bit binary"
-      ;;
-    -32)
-      echo "Building 32-bit binary"
-      cflags=""
-      ;;
-    *)
-      config_args="$config_args $1"; shift
-      ;;
-  esac
-else
-  echo "Building 64-bit binary"
-fi
-
-set -x
-make maintainer-clean
-
-path=`dirname $0`
-. "$path/autorun.sh"
-
-# C options:
-# -apo          - auto-parallize for multiprocessors (implies -mp)
-# -mp           - generate multiprocessor code
-# These two common optimization options apparently use 'sproc' model of
-# threading, which is not compatible with PTHREADS: don't add them unless you
-# know what you're doing.
-#
-# -c99          - enable C features standardized in C99, such as long long,
-#                 strtoll, stroull etc.
-#                 This option is vital to compile MySQL.
-# -woff         - turn off some warnings 
-# -64           - generate 64 bit object (implies -mips4)
-# -mips4        - produce code for MIPS R10000, MIPS R12000 and further 64 bit
-#                 processors
-# -OPT:Olimit=0 - no limits exists to size of function for compiler to optimize
-#                 it
-nowarn="-woff 1064,1188,1460,1552,1681,1682,3303"
-cflags="$cflags $nowarn -O3 -c99 -OPT:Olimit=0"
-
-# C++ only options:
-# -LANG:exceptions=OFF            - don't generate exception handling code
-#                                   MySQL doesn't use exceptions.
-# -LANG:std=OFF                   - don't link standard C++ library, such as
-#                                   <iostream>, <complex>, etc. 
-# -LANG:libc_in_namespace_std=OFF - libstdc functions can be  
-#                                   declared in namespace 'std', when included
-#                                   into C++ code. Switch this feature off.
-#                                   This option is vital to compile MySQL
-
-cxxflags="$cflags -LANG:exceptions=OFF -LANG:std=OFF"
-cxxflags="$cxxflags -LANG:libc_in_namespace_std=OFF"
-
-CC=cc CXX=CC CFLAGS="$cflags" CXXFLAGS="$cxxflags" \
-./configure --prefix=/usr/local/mysql --disable-shared \
-            --with-extra-charsets=complex --enable-thread-safe-client \
-            --without-extra-tools --disable-dependency-tracking \
-            $config_args
-
-make 

=== removed file 'BUILD/compile-pentium-icc'
--- a/BUILD/compile-pentium-icc	2010-12-28 18:57:23 +0000
+++ b/BUILD/compile-pentium-icc	1970-01-01 00:00:00 +0000
@@ -1,39 +0,0 @@
-#! /bin/sh
-
-# Copyright (C) 2005 MySQL AB
-# 
-# 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., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
-
-path=`dirname $0`
-. "$path/SETUP.sh"
-
-# Note that we can't use ccache with icc as the generated .deps file will
-# then contain wrong information
-CC=icc
-CXX=icpc
-CXXLD="$CXX -static-libcxa"
-export CC CXX CXXLD
-
-c_warnings=""
-cxx_warnings=""
-extra_flags="$fast_cflags -unroll2 -ip -mp -restrict"
-
-# Use -no-ipo if you get this error
-# IPO link: can not find "-lstdc++_shared"
-# icpc: error: problem during multi-file optimization compilation (code 1)
-extra_flags="$extra_flags -no-ipo"
-base_cxxflags="-fno-exceptions -fno-rtti"
-extra_configs="$pentium_configs $static_link"
-
-. "$path/FINISH.sh"

=== removed file 'BUILD/compile-pentium-icc-valgrind-max'
--- a/BUILD/compile-pentium-icc-valgrind-max	2011-06-30 15:50:45 +0000
+++ b/BUILD/compile-pentium-icc-valgrind-max	1970-01-01 00:00:00 +0000
@@ -1,49 +0,0 @@
-#! /bin/sh
-
-# Copyright (c) 2005, 2010, 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 02110-1301  USA
-
-path=`dirname $0`
-. "$path/SETUP.sh"
-
-# Note that we can't use ccache with icc as the generated .deps file will
-# then contain wrong information
-CC=icc
-CXX=icpc
-export CC CXX
-
-extra_flags="$pentium_cflags $debug_cflags $valgrind_flags"
-
-# Disable following warnings as these are generated by header files:
-# 161   unrecognized pragma
-# 444   destructor for base class xxx is not virtual
-# 279   controlling expression is constant
-# 810   conversion from ulonglong to ulong with cast
-# 981   operands are evaluated in unspecified order
-# 1292  warning for unknown 'attribute' options
-# 1469  "xxx" clobber ignored
-# 1572  floating-point equality and inequality comparisons are unreliable
-
-# In C++
-# 869    parameter "xxx" was never referenced
-#        (Problem with virtual functions)
-# 874   support for placement delete is disabled
-
-c_warnings="-Wall -Wcheck -wd161,444,279,810,981,1292,1469,1572"
-cxx_warnings="$c_warnings -wd869,874"
-base_cxxflags="-fno-exceptions -fno-rtti"
-extra_configs="$pentium_configs $debug_configs $valgrind_configs"
-
-. "$path/FINISH.sh"

=== removed file 'BUILD/compile-pentium-icc-yassl'
--- a/BUILD/compile-pentium-icc-yassl	2010-12-28 18:57:23 +0000
+++ b/BUILD/compile-pentium-icc-yassl	1970-01-01 00:00:00 +0000
@@ -1,39 +0,0 @@
-#! /bin/sh
-
-# Copyright (C) 2005 MySQL AB
-# 
-# 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., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
-
-path=`dirname $0`
-. "$path/SETUP.sh"
-
-# Note that we can't use ccache with icc as the generated .deps file will
-# then contain wrong information
-CC=icc
-CXX=icpc
-CXXLD="$CXX -static-libcxa"
-export CC CXX CXXLD
-
-c_warnings=""
-cxx_warnings=""
-extra_flags="$fast_cflags -unroll2 -ip -mp -restrict"
-
-# Use -no-ipo if you get this error
-# IPO link: can not find "-lstdc++_shared"
-# icpc: error: problem during multi-file optimization compilation (code 1)
-extra_flags="$extra_flags -no-ipo"
-base_cxxflags="-fno-exceptions -fno-rtti"
-extra_configs="$pentium_configs $static_link --with-yassl"
-
-. "$path/FINISH.sh"

=== removed file 'BUILD/compile-pentium-pgcc'
--- a/BUILD/compile-pentium-pgcc	2010-12-28 23:47:05 +0000
+++ b/BUILD/compile-pentium-pgcc	1970-01-01 00:00:00 +0000
@@ -1,33 +0,0 @@
-#! /bin/sh
-
-# Copyright (C) 2000, 2005 MySQL AB
-# 
-# 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., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
-
-AM_MAKEFLAGS="-j 2"
-gmake -k maintainer-clean || true
-/bin/rm -f */.deps/*.P config.cache
- 
-path=`dirname $0`
-. "$path/autorun.sh"
- 
-export PATH=/usr/local/pgcc/bin:$PATH
-CFLAGS="-Wimplicit -Wreturn-type -Wid-clash-51 -Wswitch -Wtrigraphs -Wcomment -W -Wchar-subscripts -Wformat -Wimplicit-function-dec -Wimplicit-int -Wparentheses -Wsign-compare -Wwrite-strings -Wunused  -O6 -mpentiumpro -fomit-frame-pointer -mstack-align-double" CXX=gcc CXXFLAGS="-Wimplicit -Wreturn-type -Wid-clash-51 -Wswitch -Wtrigraphs -Wcomment -W -Wchar-subscripts -Wformat -Wimplicit-function-dec -Wimplicit-int -Wparentheses -Wsign-compare -Wwrite-strings -Woverloaded-virtual -Wextern-inline -Wsign-promo -Wreorder -Wctor-dtor-privacy -Wnon-virtual-dtor -felide-constructors -fno-exceptions -fno-rtti -O6 -fomit-frame-pointer -mpentiumpro -mstack-align-double" ./configure --prefix=/usr/local/mysql --enable-assembler --with-extra-charsets=complex --enable-thread-safe-client --with-mysqld-ldflags=-all-static  --with-client-ldflags=-all-static
- 
-gmake -j 4
- 
-mkdir -p tmp
-nm --numeric-sort sql/mysqld  > tmp/mysqld.sym
-objdump -d sql/mysqld > tmp/mysqld.S
-strip sql/mysqld

=== modified file 'BUILD/compile-solaris-amd64'
--- a/BUILD/compile-solaris-amd64	2010-12-28 23:47:05 +0000
+++ b/BUILD/compile-solaris-amd64	2011-10-11 04:27:52 +0000
@@ -40,7 +40,7 @@ compiler_flags="-g -O3 -fno-omit-frame-p
 
 export CC CXX CFLAGS CXXFLAGS LDFLAGS LIBS
 CC="gcc"
-CXX="gcc"
+CXX="g++"
 CFLAGS="$warning_flags $compiler_flags"
 CXXFLAGS="" 
 LDFLAGS="-O3 -g -static-libgcc"

=== modified file 'BUILD/compile-solaris-amd64-forte'
--- a/BUILD/compile-solaris-amd64-forte	2011-06-30 15:37:13 +0000
+++ b/BUILD/compile-solaris-amd64-forte	2011-10-11 04:27:52 +0000
@@ -38,7 +38,7 @@ ASFLAGS="$EXTRA_64_BIT"
 CC=cc-5.0
 CFLAGS="-Xa -xstrconst $STD"
 CXX=CC
-CXXFLAGS="-noex $STD"
+CXXFLAGS="$STD"
 LIBS=-lmtmalloc
 ./configure \
     --prefix=/usr/local/mysql \

=== modified file 'BUILD/compile-solaris-amd64-forte-debug'
--- a/BUILD/compile-solaris-amd64-forte-debug	2011-06-30 15:37:13 +0000
+++ b/BUILD/compile-solaris-amd64-forte-debug	2011-10-11 04:27:52 +0000
@@ -40,7 +40,7 @@ ASFLAGS="$EXTRA_64_BIT"
 CC=cc-5.0
 CFLAGS="-Xa -xstrconst $STD"
 CXX=CC
-CXXFLAGS="-noex $STD"
+CXXFLAGS="$STD"
 ./configure \
     --prefix=/usr/local/mysql \
     --localstatedir=/usr/local/mysql/data \

=== modified file 'BUILD/compile-solaris-sparc'
--- a/BUILD/compile-solaris-sparc	2011-06-30 15:37:13 +0000
+++ b/BUILD/compile-solaris-sparc	2011-10-11 04:27:52 +0000
@@ -25,6 +25,6 @@ PATH=$PATH:/usr/ccs/bin:/usr/local/bin
 path=`dirname $0`
 . "$path/autorun.sh"
 
-CFLAGS="-g -Wimplicit -Wreturn-type -Wswitch -Wtrigraphs -Wcomment -W -Wchar-subscripts -Wformat -Wparentheses -Wsign-compare -Wwrite-strings -Wunused  -O3 -fno-omit-frame-pointer -mcpu=v8 -Wa,-xarch=v8plusa" CXX=gcc CXXFLAGS="-Wimplicit -Wreturn-type -Wswitch -Wtrigraphs -Wcomment -W -Wchar-subscripts -Wformat -Wparentheses -Wsign-compare -Wwrite-strings -Woverloaded-virtual -Wsign-promo -Wreorder -Wctor-dtor-privacy -Wnon-virtual-dtor -felide-constructors -fno-exceptions -fno-rtti  -O3 -fno-omit-frame-pointer -mcpu=v8 -Wa,-xarch=v8plusa -g" LIBS="-lmtmalloc" ./configure --prefix=/usr/local/mysql --enable-assembler --with-extra-charsets=complex --enable-thread-safe-client
+CFLAGS="-g -Wimplicit -Wreturn-type -Wswitch -Wtrigraphs -Wcomment -W -Wchar-subscripts -Wformat -Wparentheses -Wsign-compare -Wwrite-strings -Wunused  -O3 -fno-omit-frame-pointer -mcpu=v8 -Wa,-xarch=v8plusa" CXX=g++ CXXFLAGS="-Wimplicit -Wreturn-type -Wswitch -Wtrigraphs -Wcomment -W -Wchar-subscripts -Wformat -Wparentheses -Wsign-compare -Wwrite-strings -Woverloaded-virtual -Wsign-promo -Wreorder -Wctor-dtor-privacy -Wnon-virtual-dtor -felide-constructors -O3 -fno-omit-frame-pointer -mcpu=v8 -Wa,-xarch=v8plusa -g" LIBS="-lmtmalloc" ./configure --prefix=/usr/local/mysql --enable-assembler --with-extra-charsets=complex --enable-thread-safe-client
 
 make -j 4

=== modified file 'BUILD/compile-solaris-sparc-debug'
--- a/BUILD/compile-solaris-sparc-debug	2010-12-28 23:47:05 +0000
+++ b/BUILD/compile-solaris-sparc-debug	2011-10-11 04:27:52 +0000
@@ -21,6 +21,6 @@ make -k clean || true
 path=`dirname $0`
 . "$path/autorun.sh"
  
-CFLAGS="-g -Wimplicit -Wreturn-type -Wswitch -Wtrigraphs -Wcomment -W -Wchar-subscripts -Wformat -Wparentheses -Wsign-compare -Wwrite-strings -Wunused  -O3 -fno-omit-frame-pointer" CXX=gcc CXXFLAGS="-g -Wimplicit -Wreturn-type -Wswitch -Wtrigraphs -Wcomment -W -Wchar-subscripts -Wformat -Wparentheses -Wsign-compare -Wwrite-strings -Woverloaded-virtual -Wsign-promo -Wreorder -Wctor-dtor-privacy -Wnon-virtual-dtor -felide-constructors -fno-exceptions -fno-rtti  -O3 -fno-omit-frame-pointer" ./configure --prefix=/usr/local/mysql --enable-assembler --with-extra-charsets=complex --enable-thread-safe-client --with-debug
+CFLAGS="-g -Wimplicit -Wreturn-type -Wswitch -Wtrigraphs -Wcomment -W -Wchar-subscripts -Wformat -Wparentheses -Wsign-compare -Wwrite-strings -Wunused  -O3 -fno-omit-frame-pointer" CXX=g++ CXXFLAGS="-g -Wimplicit -Wreturn-type -Wswitch -Wtrigraphs -Wcomment -W -Wchar-subscripts -Wformat -Wparentheses -Wsign-compare -Wwrite-strings -Woverloaded-virtual -Wsign-promo -Wreorder -Wctor-dtor-privacy -Wnon-virtual-dtor -felide-constructors -O3 -fno-omit-frame-pointer" ./configure --prefix=/usr/local/mysql --enable-assembler --with-extra-charsets=complex --enable-thread-safe-client --with-debug
 
 make -j 4

=== modified file 'BUILD/compile-solaris-sparc-forte'
--- a/BUILD/compile-solaris-sparc-forte	2011-06-30 15:37:13 +0000
+++ b/BUILD/compile-solaris-sparc-forte	2011-10-11 04:27:52 +0000
@@ -45,7 +45,7 @@ EXTRA="-fast"			# Remove comment to targ
 
 STD="-mt -D_FORTEC_ $EXTRA $EXTRA_64_BIT"
 CC=cc-5.0 CFLAGS="-Xa -xstrconst $STD" \
-CXX=CC CXXFLAGS="-noex $STD" LIBS="-lmtmalloc" \
+CXX=CC CXXFLAGS="$STD" LIBS="-lmtmalloc" \
 ./configure --prefix=/usr/local/mysql --enable-assembler --with-extra-charsets=complex --enable-thread-safe-client --prefix=$PREFIX
 
 make -j 4

=== modified file 'BUILD/compile-solaris-sparc-purify'
--- a/BUILD/compile-solaris-sparc-purify	2010-12-28 23:47:05 +0000
+++ b/BUILD/compile-solaris-sparc-purify	2011-10-11 04:27:52 +0000
@@ -52,7 +52,7 @@ make -k maintainer-clean || true
 path=`dirname $0`
 . "$path/autorun.sh"
 
-CFLAGS="-g -Wimplicit -Wreturn-type -Wswitch -Wtrigraphs -Wcomment -W -Wchar-subscripts -Wformat -Wimplicit-int -Wparentheses -Wsign-compare -Wwrite-strings -Wunused  -DHAVE_purify -DEXTRA_DEBUG -O2" CXX=gcc CXXLD=g++ CXXFLAGS="-g -Wimplicit -Wreturn-type -Wswitch -Wtrigraphs -Wcomment -W -Wchar-subscripts -Wformat -Wparentheses -Wsign-compare -Wwrite-strings -Woverloaded-virtual -Wsign-promo -Wreorder -Wctor-dtor-privacy -Wnon-virtual-dtor -felide-constructors -fno-exceptions -fno-rtti  -DHAVE_purify -DEXTRA_DEBUG -O2" ./configure --prefix=/usr/local/mysql --enable-assembler --with-extra-charsets=complex --enable-thread-safe-client --with-embedded-server --with-innodb $EXTRA_CONFIG_FLAGS
+CFLAGS="-g -Wimplicit -Wreturn-type -Wswitch -Wtrigraphs -Wcomment -W -Wchar-subscripts -Wformat -Wimplicit-int -Wparentheses -Wsign-compare -Wwrite-strings -Wunused  -DHAVE_purify -DEXTRA_DEBUG -O2" CXX=g++ CXXLD=g++ CXXFLAGS="-g -Wimplicit -Wreturn-type -Wswitch -Wtrigraphs -Wcomment -W -Wchar-subscripts -Wformat -Wparentheses -Wsign-compare -Wwrite-strings -Woverloaded-virtual -Wsign-promo -Wreorder -Wctor-dtor-privacy -Wnon-virtual-dtor -felide-constructors -DHAVE_purify -DEXTRA_DEBUG -O2" ./configure --prefix=/usr/local/mysql --enable-assembler --with-extra-charsets=complex --enable-thread-safe-client --with-embedded-server --with-innodb $EXTRA_CONFIG_FLAGS
 
 make -j 4
 

=== modified file 'VERSION'
--- a/VERSION	2011-10-27 06:17:58 +0000
+++ b/VERSION	2011-11-03 19:40:03 +0000
@@ -1,4 +1,4 @@
 MYSQL_VERSION_MAJOR=5
 MYSQL_VERSION_MINOR=6
 MYSQL_VERSION_PATCH=4
-MYSQL_VERSION_EXTRA=-m6
+MYSQL_VERSION_EXTRA=-m7

=== modified file 'client/CMakeLists.txt'
--- a/client/CMakeLists.txt	2011-09-23 10:55:10 +0000
+++ b/client/CMakeLists.txt	2011-10-11 04:27:52 +0000
@@ -72,7 +72,14 @@ IF(WIN32)
   MYSQL_ADD_EXECUTABLE(echo echo.c)
 ENDIF(WIN32)
 
-SET_TARGET_PROPERTIES (mysqlcheck mysqldump mysqlimport mysql_upgrade mysqlshow mysqlslap mysql_plugin 
+SET_TARGET_PROPERTIES (
+  mysql_plugin 
+  mysql_upgrade
+  mysqlcheck
+  mysqldump
+  mysqlimport
+  mysqlshow
+  mysqlslap
 PROPERTIES HAS_CXX TRUE)
 
 ADD_DEFINITIONS(-DHAVE_DLOPEN)

=== modified file 'client/mysql.cc'
--- a/client/mysql.cc	2011-09-28 11:38:46 +0000
+++ b/client/mysql.cc	2011-10-13 07:26:28 +0000
@@ -41,6 +41,11 @@
 #include <signal.h>
 #include <violite.h>
 
+#include <algorithm>
+
+using std::min;
+using std::max;
+
 #if defined(USE_LIBEDIT_INTERFACE) && defined(HAVE_LOCALE_H)
 #include <locale.h>
 #endif
@@ -3499,9 +3504,9 @@ print_table_data(MYSQL_RES *result)
   {
     uint length= column_names ? field->name_length : 0;
     if (quick)
-      length=max(length,field->length);
+      length= max<size_t>(length, field->length);
     else
-      length=max(length,field->max_length);
+      length= max<size_t>(length, field->max_length);
     if (length < 4 && !IS_NOT_NULL(field->flags))
       length=4;					// Room for "NULL"
     field->max_length=length;
@@ -3521,8 +3526,8 @@ print_table_data(MYSQL_RES *result)
                                                   field->name,
                                                   field->name + name_length);
       uint display_length= field->max_length + name_length - numcells;
-      tee_fprintf(PAGER, " %-*s |",(int) min(display_length,
-                                            MAX_COLUMN_LENGTH),
+      tee_fprintf(PAGER, " %-*s |",
+                  min<int>(display_length, MAX_COLUMN_LENGTH),
                   field->name);
       num_flag[off]= IS_NUM(field->type);
     }
@@ -3611,9 +3616,9 @@ static int get_field_disp_length(MYSQL_F
   uint length= column_names ? field->name_length : 0;
 
   if (quick)
-    length= max(length, field->length);
+    length= max<uint>(length, field->length);
   else
-    length= max(length, field->max_length);
+    length= max<uint>(length, field->max_length);
 
   if (length < 4 && !IS_NOT_NULL(field->flags))
     length= 4;				/* Room for "NULL" */

=== modified file 'client/mysql_upgrade.c'
--- a/client/mysql_upgrade.c	2011-07-22 08:10:35 +0000
+++ b/client/mysql_upgrade.c	2011-08-29 12:08:58 +0000
@@ -549,7 +549,7 @@ static int extract_variable_from_show(DY
   if ((value_end= strchr(value_start, '\n')) == NULL)
     return 1; /* Unexpected result */
 
-  strncpy(value, value_start, min(FN_REFLEN, value_end-value_start));
+  strncpy(value, value_start, MY_MIN(FN_REFLEN, value_end - value_start));
   return 0;
 }
 

=== modified file 'client/mysqlbinlog.cc'
--- a/client/mysqlbinlog.cc	2011-07-11 16:21:46 +0000
+++ b/client/mysqlbinlog.cc	2011-08-29 12:08:58 +0000
@@ -41,7 +41,12 @@
 #include "sql_common.h"
 #include <welcome_copyright_notice.h> // ORACLE_WELCOME_COPYRIGHT_NOTICE
 
-#define BIN_LOG_HEADER_SIZE	4
+#include <algorithm>
+
+using std::min;
+using std::max;
+
+#define BIN_LOG_HEADER_SIZE	4U
 #define PROBE_HEADER_LEN	(EVENT_LEN_OFFSET+4)
 
 
@@ -2076,7 +2081,7 @@ static Exit_status dump_local_log_entrie
       my_off_t length,tmp;
       for (length= start_position_mot ; length > 0 ; length-=tmp)
       {
-	tmp=min(length,sizeof(buff));
+	tmp= min<size_t>(length, sizeof(buff));
 	if (my_b_read(file, buff, (uint) tmp))
         {
           error("Failed reading from file.");

=== modified file 'client/mysqldump.c'
--- a/client/mysqldump.c	2011-10-13 14:01:50 +0000
+++ b/client/mysqldump.c	2011-10-28 12:45:35 +0000
@@ -849,7 +849,7 @@ get_one_option(int optid, const struct m
                                     &err_ptr, &err_len);
       if (err_len)
       {
-        strmake(buff, err_ptr, min(sizeof(buff) - 1, err_len));
+        strmake(buff, err_ptr, MY_MIN(sizeof(buff) - 1, err_len));
         fprintf(stderr, "Invalid mode to --compatible: %s\n", buff);
         exit(1);
       }
@@ -4672,7 +4672,7 @@ static ulong find_set(TYPELIB *lib, cons
 
       for (; pos != end && *pos != ','; pos++) ;
       var_len= (uint) (pos - start);
-      strmake(buff, start, min(sizeof(buff) - 1, var_len));
+      strmake(buff, start, MY_MIN(sizeof(buff) - 1, var_len));
       find= find_type(buff, lib, FIND_TYPE_BASIC);
       if (!find)
       {

=== modified file 'client/mysqltest.cc'
--- a/client/mysqltest.cc	2011-10-19 07:29:57 +0000
+++ b/client/mysqltest.cc	2011-10-28 12:45:35 +0000
@@ -47,6 +47,11 @@
 
 #include <welcome_copyright_notice.h> // ORACLE_WELCOME_COPYRIGHT_NOTICE
 
+#include <algorithm>
+
+using std::min;
+using std::max;
+
 #ifdef __WIN__
 #include <crtdbg.h>
 #define SIGNAL_FMT "exception 0x%x"
@@ -6052,9 +6057,9 @@ int read_line(char *buf, int size)
       }
       else if ((c == '{' &&
                 (!my_strnncoll_simple(charset_info, (const uchar*) "while", 5,
-                                      (uchar*) buf, min(5, p - buf), 0) ||
+                                      (uchar*) buf, min<my_ptrdiff_t>(5, p - buf), 0) ||
                  !my_strnncoll_simple(charset_info, (const uchar*) "if", 2,
-                                      (uchar*) buf, min(2, p - buf), 0))))
+                                      (uchar*) buf, min<my_ptrdiff_t>(2, p - buf), 0))))
       {
         /* Only if and while commands can be terminated by { */
         *p++= c;

=== modified file 'client/sql_string.cc'
--- a/client/sql_string.cc	2011-11-01 06:53:43 +0000
+++ b/client/sql_string.cc	2011-11-03 16:03:34 +0000
@@ -25,6 +25,11 @@
 
 #include "sql_string.h"
 
+#include <algorithm>
+
+using std::min;
+using std::max;
+
 /*****************************************************************************
 ** String functions
 *****************************************************************************/

=== modified file 'cmake/build_configurations/mysql_release.cmake'
--- a/cmake/build_configurations/mysql_release.cmake	2011-08-17 09:22:05 +0000
+++ b/cmake/build_configurations/mysql_release.cmake	2011-10-11 14:52:17 +0000
@@ -148,12 +148,12 @@ IF(UNIX)
 
   # Default GCC flags
   IF(CMAKE_COMPILER_IS_GNUCC)
-    SET(COMMON_C_FLAGS               "-g -static-libgcc -fno-omit-frame-pointer -fno-strict-aliasing")
+    SET(COMMON_C_FLAGS               "-g -fabi-version=2 -fno-omit-frame-pointer -fno-strict-aliasing")
     SET(CMAKE_C_FLAGS_DEBUG          "-O ${COMMON_C_FLAGS}")
     SET(CMAKE_C_FLAGS_RELWITHDEBINFO "-O3 ${COMMON_C_FLAGS}")
   ENDIF()
   IF(CMAKE_COMPILER_IS_GNUCXX)
-    SET(COMMON_CXX_FLAGS               "-g -static-libgcc -fno-omit-frame-pointer -fno-strict-aliasing")
+    SET(COMMON_CXX_FLAGS               "-g -fabi-version=2 -fno-omit-frame-pointer -fno-strict-aliasing")
     SET(CMAKE_CXX_FLAGS_DEBUG          "-O ${COMMON_CXX_FLAGS}")
     SET(CMAKE_CXX_FLAGS_RELWITHDEBINFO "-O3 ${COMMON_CXX_FLAGS}")
   ENDIF()
@@ -178,7 +178,7 @@ IF(UNIX)
   IF(CMAKE_SYSTEM_NAME MATCHES "Linux")
     IF(CMAKE_C_COMPILER_ID MATCHES "Intel")
       SET(COMMON_C_FLAGS                 "-static-intel -static-libgcc -g -mp -restrict")
-      SET(COMMON_CXX_FLAGS               "-static-intel -static-libgcc -g -mp -restrict -fno-exceptions -fno-rtti")
+      SET(COMMON_CXX_FLAGS               "-static-intel -static-libgcc -g -mp -restrict")
       IF(CMAKE_SYSTEM_PROCESSOR MATCHES "ia64")
         SET(COMMON_C_FLAGS               "${COMMON_C_FLAGS} -no-ftz -no-prefetch")
         SET(COMMON_CXX_FLAGS             "${COMMON_CXX_FLAGS} -no-ftz -no-prefetch")
@@ -193,9 +193,8 @@ IF(UNIX)
 
   # OSX flags
   IF(APPLE)
-    SET(COMMON_C_FLAGS                 "-g -fno-common -fno-strict-aliasing")
-    # XXX: why are we using -felide-constructors on OSX?
-    SET(COMMON_CXX_FLAGS               "-g -fno-common -felide-constructors -fno-strict-aliasing")
+    SET(COMMON_C_FLAGS                 "-g -fno-strict-aliasing")
+    SET(COMMON_CXX_FLAGS               "-g -fno-strict-aliasing")
     SET(CMAKE_C_FLAGS_DEBUG            "-O ${COMMON_C_FLAGS}")
     SET(CMAKE_CXX_FLAGS_DEBUG          "-O ${COMMON_CXX_FLAGS}")
     SET(CMAKE_C_FLAGS_RELWITHDEBINFO   "-Os ${COMMON_C_FLAGS}")
@@ -211,7 +210,7 @@ IF(UNIX)
     IF(CMAKE_C_COMPILER_ID MATCHES "SunPro")
       IF(CMAKE_SYSTEM_PROCESSOR MATCHES "i386")
         SET(COMMON_C_FLAGS                   "-g -mt -fsimple=1 -ftrap=%none -nofstore -xbuiltin=%all -xlibmil -xlibmopt -xtarget=generic")
-        SET(COMMON_CXX_FLAGS                 "-g0 -mt -fsimple=1 -ftrap=%none -nofstore -xbuiltin=%all -features=no%except -xlibmil -xlibmopt -xtarget=generic")
+        SET(COMMON_CXX_FLAGS                 "-g0 -mt -fsimple=1 -ftrap=%none -nofstore -xbuiltin=%all -xlibmil -xlibmopt -xtarget=generic -library=stlport4")
         SET(CMAKE_C_FLAGS_DEBUG              "-xO1 ${COMMON_C_FLAGS}")
         SET(CMAKE_CXX_FLAGS_DEBUG            "-xO1 ${COMMON_CXX_FLAGS}")
         IF(32BIT)
@@ -224,7 +223,7 @@ IF(UNIX)
       ELSE() 
         # Assume !x86 is SPARC
         SET(COMMON_C_FLAGS                 "-g -Xa -xstrconst -mt")
-        SET(COMMON_CXX_FLAGS               "-g0 -noex -mt")
+        SET(COMMON_CXX_FLAGS               "-g0 -mt -library=stlport4")
         IF(32BIT)
           SET(COMMON_C_FLAGS               "${COMMON_C_FLAGS} -xarch=sparc")
           SET(COMMON_CXX_FLAGS             "${COMMON_CXX_FLAGS} -xarch=sparc")

=== modified file 'cmake/configure.pl'
--- a/cmake/configure.pl	2011-06-30 15:50:45 +0000
+++ b/cmake/configure.pl	2011-10-17 10:28:01 +0000
@@ -55,10 +55,10 @@ sub set_installdir
 }
 
 # CMake understands CC and CXX env.variables correctly, if they  contain 1 or 2 tokens
-# e.g CXX=gcc and CXX="ccache gcc" are ok. However it could have a problem if there
-# (recognizing gcc) with more tokens ,e.g CXX="ccache gcc --pipe".
+# e.g CXX=g++ and CXX="ccache g++" are ok. However it could have a problem if there
+# (recognizing g++) with more tokens ,e.g CXX="ccache g++ --pipe".
 # The problem is simply fixed by splitting compiler and flags, e.g
-# CXX="ccache gcc --pipe" => CXX=ccache gcc CXXFLAGS=--pipe
+# CXX="ccache g++ --pipe" => CXX=ccache g++ CXXFLAGS=--pipe
 
 sub check_compiler
 {
@@ -86,6 +86,19 @@ sub check_compiler
 check_compiler("CC", "CFLAGS");
 check_compiler("CXX", "CXXFLAGS");
 
+if(defined $ENV{"CXX"} and $ENV{"CXX"} =~ m/gcc/)
+{
+  my $old_cxx= $ENV{"CXX"};
+  $ENV{"CXX"} =~ s/gcc/g++/;    
+  print("configure.pl : switching CXX compiler from $old_cxx to $ENV{CXX}\n");
+}
+
+if(defined $ENV{"CXXFLAGS"} and $ENV{"CXXFLAGS"} =~ "-fno-exceptions")
+{
+  $ENV{"CXXFLAGS"} =~ s/-fno-exceptions//;
+  print("configure.pl : stripping off -fno-exceptions CXXFLAGS=$ENV{CXXFLAGS}\n");
+}
+
 foreach my $option (@ARGV)
 {
   if (substr ($option, 0, 2) eq "--")

=== modified file 'cmake/info_macros.cmake.in'
--- a/cmake/info_macros.cmake.in	2011-02-11 14:55:25 +0000
+++ b/cmake/info_macros.cmake.in	2011-10-11 04:27:52 +0000
@@ -44,13 +44,20 @@ SET(CMAKE_SYSTEM_PROCESSOR "@CMAKE_SYSTE
 MACRO(CREATE_INFO_SRC target_dir)
   SET(INFO_SRC "${target_dir}/INFO_SRC")
 
-  IF(EXISTS ${CMAKE_SOURCE_DIR}/.bzr)
+  IF(BZR_EXECUTABLE AND EXISTS ${CMAKE_SOURCE_DIR}/.bzr)
     # Sources are in a BZR repository: Always update.
+    # Add a timeout in case BZR hangs forever ...
     EXECUTE_PROCESS(
       COMMAND ${BZR_EXECUTABLE} version-info ${CMAKE_SOURCE_DIR}
       OUTPUT_VARIABLE VERSION_INFO
       RESULT_VARIABLE RESULT
+      ERROR_VARIABLE ERROR
+      TIMEOUT 10
     )
+    IF(NOT RESULT EQUAL 0)
+      MESSAGE(STATUS "Error from ${BZR_EXECUTABLE}: ${ERROR}")
+      SET(BZR_EXECUTABLE)
+    ENDIF()
     FILE(WRITE ${INFO_SRC} "${VERSION_INFO}\n")
     # to debug, add: FILE(APPEND ${INFO_SRC} "\nResult ${RESULT}\n")
     # For better readability ...

=== modified file 'cmake/os/Windows.cmake'
--- a/cmake/os/Windows.cmake	2011-06-30 15:50:45 +0000
+++ b/cmake/os/Windows.cmake	2011-10-17 10:28:01 +0000
@@ -72,19 +72,21 @@ IF(MSVC)
   ENDFOREACH()
   
   # Force static runtime libraries
+  # Choose C++ exception handling:
+  #   If /EH is not specified, the compiler will catch structured and
+  #   C++ exceptions, but will not destroy C++ objects that will go out of
+  #   scope as a result of the exception.
+  #   /EHsc catches C++ exceptions only and tells the compiler to assume that
+  #   extern C functions never throw a C++ exception.
   FOREACH(flag 
    CMAKE_C_FLAGS_RELEASE CMAKE_C_FLAGS_RELWITHDEBINFO 
    CMAKE_C_FLAGS_DEBUG CMAKE_C_FLAGS_DEBUG_INIT 
    CMAKE_CXX_FLAGS_RELEASE  CMAKE_CXX_FLAGS_RELWITHDEBINFO
    CMAKE_CXX_FLAGS_DEBUG  CMAKE_CXX_FLAGS_DEBUG_INIT)
    STRING(REPLACE "/MD"  "/MT" "${flag}" "${${flag}}")
+   SET("${flag}" "${${flag}} /EHsc")
   ENDFOREACH()
   
-  # Remove support for exceptions
-  FOREACH(flag CMAKE_CXX_FLAGS CMAKE_CXX_FLAGS_INIT)
-   STRING(REPLACE "/EHsc" ""   "${flag}" "${${flag}}") 
-  ENDFOREACH()
- 
   # Fix CMake's predefined huge stack size
   FOREACH(type EXE SHARED MODULE)
    STRING(REGEX REPLACE "/STACK:([^ ]+)" "" CMAKE_${type}_LINKER_FLAGS "${CMAKE_${type}_LINKER_FLAGS}")

=== modified file 'cmake/readline.cmake'
--- a/cmake/readline.cmake	2011-06-30 15:46:53 +0000
+++ b/cmake/readline.cmake	2011-10-11 04:27:52 +0000
@@ -95,6 +95,15 @@ MACRO (FIND_CURSES)
    SET(CURSES_LIBRARY "curses" CACHE INTERNAL "" FORCE)
    SET(CURSES_CURSES_LIBRARY "curses" CACHE INTERNAL "" FORCE)
  ENDIF()
+ IF(CMAKE_SYSTEM_NAME MATCHES "SunOS")
+   # CMake generates /lib/64/libcurses.so -R/lib/64
+   # The result is we cannot find
+   # /opt/studio12u2/lib/stlport4/v9/libstlport.so.1
+   # at runtime
+   SET(CURSES_LIBRARY "curses" CACHE INTERNAL "" FORCE)
+   SET(CURSES_CURSES_LIBRARY "curses" CACHE INTERNAL "" FORCE)
+   MESSAGE(STATUS "CURSES_LIBRARY ${CURSES_LIBRARY}")
+ ENDIF()
 
  IF(CMAKE_SYSTEM_NAME MATCHES "Linux")
    # -Wl,--as-needed breaks linking with -lcurses, e.g on Fedora 

=== modified file 'config.h.cmake'
--- a/config.h.cmake	2011-09-21 11:01:41 +0000
+++ b/config.h.cmake	2011-11-04 12:59:47 +0000
@@ -136,7 +136,6 @@
 #cmakedefine HAVE_CLOCK_GETTIME 1
 #cmakedefine HAVE_CRYPT 1
 #cmakedefine HAVE_CUSERID 1
-#cmakedefine HAVE_CXX_NEW 1
 #cmakedefine HAVE_DIRECTIO 1
 #cmakedefine HAVE_DLERROR 1
 #cmakedefine HAVE_DLOPEN 1
@@ -377,7 +376,7 @@
 
 #cmakedefine HAVE_MBSTATE_T
 
-#define MAX_INDEXES 64
+#define MAX_INDEXES 64U
 
 #cmakedefine QSORT_TYPE_IS_VOID 1
 #cmakedefine RETQSORTTYPE @RETQSORTTYPE@
@@ -395,8 +394,9 @@
 #cmakedefine WORDS_BIGENDIAN 1 
 #endif
 
-/* Define to `__inline__' or `__inline' if that's what the C compiler calls
-   it, or to nothing if 'inline' is not supported under any name.  */
+/*
+  Define to `__inline__' or `__inline' if that's what the C compiler calls it.
+*/
 #cmakedefine C_HAS_inline 1
 #if !(C_HAS_inline)
 #ifndef __cplusplus

=== modified file 'configure.cmake'
--- a/configure.cmake	2011-09-21 11:01:41 +0000
+++ b/configure.cmake	2011-11-04 12:59:47 +0000
@@ -65,12 +65,55 @@ IF(CMAKE_COMPILER_IS_GNUCC)
   SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall")
 ENDIF()
 
+# The default C++ library for SunPro is really old, and not standards compliant.
+# http://developers.sun.com/solaris/articles/cmp_stlport_libCstd.html
+# Use stlport rather than Rogue Wave.
+IF(CMAKE_SYSTEM_NAME MATCHES "SunOS")
+  IF(CMAKE_CXX_COMPILER_ID MATCHES "SunPro")
+    SET(CMAKE_CXX_FLAGS
+      "${CMAKE_CXX_FLAGS} -library=stlport4")
+  ENDIF()
+ENDIF()
+
+MACRO(DIRNAME IN OUT)
+  GET_FILENAME_COMPONENT(${OUT} ${IN} PATH)
+ENDMACRO()
+
+IF(CMAKE_SYSTEM_NAME MATCHES "SunOS" AND CMAKE_C_COMPILER_ID MATCHES "SunPro")
+  DIRNAME(${CMAKE_CXX_COMPILER} CXX_PATH)
+  SET(STLPORT_SUFFIX "lib/stlport4")
+  IF(CMAKE_CXX_FLAGS MATCHES "-m64")
+    SET(STLPORT_SUFFIX "lib/stlport4/v9")
+  ENDIF()
+
+  FIND_LIBRARY(STL_LIBRARY_NAME
+    NAMES "stlport"
+    PATHS ${CXX_PATH}/../${STLPORT_SUFFIX}
+  )
+  MESSAGE(STATUS "STL_LIBRARY_NAME ${STL_LIBRARY_NAME}")
+  IF(STL_LIBRARY_NAME)
+    DIRNAME(${STL_LIBRARY_NAME} STLPORT_PATH)
+    # We re-distribute libstlport.so which is a symlink to libstlport.so.1
+    # There is no 'readlink' on solaris, sigh ..., so we use perl to find it:
+    SET(PERLSCRIPT
+      "my $link= $ARGV[0]; use Cwd qw(abs_path); my $file = abs_path($link); print $file;")
+    EXECUTE_PROCESS(
+      COMMAND perl -e "${PERLSCRIPT}" ${STL_LIBRARY_NAME}
+      RESULT_VARIABLE result
+      OUTPUT_VARIABLE real_library
+    )
+    MESSAGE(STATUS "INSTALL ${STL_LIBRARY_NAME} ${real_library}")
+    INSTALL(FILES ${STL_LIBRARY_NAME} ${real_library}
+            DESTINATION ${INSTALL_LIBDIR} COMPONENT Development)
+    # Using the $ORIGIN token with the -R option to locate the libraries
+    # on a path relative to the executable:
+    SET(CMAKE_CXX_LINK_FLAGS
+      "${CMAKE_CXX_LINK_FLAGS} -R'\$ORIGIN/../lib' -R${STLPORT_PATH}")
+    MESSAGE(STATUS "CMAKE_CXX_LINK_FLAGS ${CMAKE_CXX_LINK_FLAGS}")
+  ENDIF()
+ENDIF()
 
 IF(CMAKE_COMPILER_IS_GNUCXX)
-  # MySQL "canonical" GCC flags. At least -fno-rtti flag affects
-  # ABI and cannot be simply removed. 
-  SET(CMAKE_CXX_FLAGS 
-    "${CMAKE_CXX_FLAGS} -fno-exceptions -fno-rtti")
   IF (CMAKE_EXE_LINKER_FLAGS MATCHES " -static " 
      OR CMAKE_EXE_LINKER_FLAGS MATCHES " -static$")
      SET(HAVE_DLOPEN FALSE CACHE "Disable dlopen due to -static flag" FORCE)
@@ -769,7 +812,9 @@ IF(NOT HAVE_FCNTL_NONBLOCK)
 ENDIF()
 
 #
-# Test for how the C compiler does inline, if at all
+# Test for how the C compiler does inline.
+# If both of these tests fail, then there is probably something wrong
+# in the environment (flags and/or compiling and/or linking).
 #
 CHECK_C_SOURCE_COMPILES("
 static inline int foo(){return 0;}
@@ -783,6 +828,12 @@ IF(NOT C_HAS_inline)
   SET(C_INLINE __inline)
 ENDIF()
 
+IF(NOT C_HAS_inline AND NOT C_HAS___inline)
+  MESSAGE(FATAL_ERROR "It seems like ${CMAKE_C_COMPILER} does not support "
+    "inline or __inline. Please verify compiler and flags. "
+    "See CMakeFiles/CMakeError.log for why the test failed to compile/link.")
+ENDIF()
+
 IF(NOT CMAKE_CROSSCOMPILING AND NOT MSVC)
   STRING(TOLOWER ${CMAKE_SYSTEM_PROCESSOR}  processor)
   IF(processor MATCHES "86" OR processor MATCHES "amd64" OR processor MATCHES "x64")
@@ -886,16 +937,6 @@ CHECK_C_SOURCE_COMPILES("
 
 
 CHECK_CXX_SOURCE_COMPILES("
-    #include <new>
-    int main()
-    {
-      char *c = new char;
-      return 0;
-    }"
-    HAVE_CXX_NEW
-)
-
-CHECK_CXX_SOURCE_COMPILES("
     #undef inline
     #if !defined(SCO) && !defined(__osf__) && !defined(_REENTRANT)
     #define _REENTRANT

=== modified file 'dbug/dbug.c'
--- a/dbug/dbug.c	2011-08-25 10:54:34 +0000
+++ b/dbug/dbug.c	2011-08-29 12:08:58 +0000
@@ -1323,7 +1323,7 @@ void _db_dump_(uint _line_, const char *
     if (TRACING)
     {
       Indent(cs, cs->level + 1);
-      pos= min(max(cs->level-cs->stack->sub_level,0)*INDENT,80);
+      pos= MY_MIN(MY_MAX(cs->level-cs->stack->sub_level,0)*INDENT,80);
     }
     else
     {
@@ -1743,7 +1743,7 @@ static void Indent(CODE_STATE *cs, int i
 {
   REGISTER int count;
 
-  indent= max(indent-1-cs->stack->sub_level,0)*INDENT;
+  indent= MY_MAX(indent-1-cs->stack->sub_level,0)*INDENT;
   for (count= 0; count < indent ; count++)
   {
     if ((count % INDENT) == 0)

=== modified file 'include/m_string.h'
--- a/include/m_string.h	2011-09-21 11:01:41 +0000
+++ b/include/m_string.h	2011-09-26 12:42:12 +0000
@@ -145,7 +145,7 @@ size_t my_gcvt(double x, my_gcvt_arg_typ
   (DBL_DIG + 2) significant digits + sign + "." + ("e-NNN" or
   MAX_DECPT_FOR_F_FORMAT zeros for cases when |x|<1 and the 'f' format is used).
 */
-#define MY_GCVT_MAX_FIELD_WIDTH (DBL_DIG + 4 + max(5, MAX_DECPT_FOR_F_FORMAT)) \
+#define MY_GCVT_MAX_FIELD_WIDTH (DBL_DIG + 4 + MY_MAX(5, MAX_DECPT_FOR_F_FORMAT)) \
 
 extern char *llstr(longlong value,char *buff);
 extern char *ullstr(longlong value,char *buff);

=== modified file 'include/my_global.h'
--- a/include/my_global.h	2011-09-23 10:55:10 +0000
+++ b/include/my_global.h	2011-10-11 04:27:52 +0000
@@ -14,10 +14,10 @@
    along with this program; if not, write to the Free Software
    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301  USA */
 
-/* This is the include file that should be included 'first' in every C file. */
+#ifndef MY_GLOBAL_INCLUDED
+#define MY_GLOBAL_INCLUDED
 
-#ifndef _global_h
-#define _global_h
+/* This is the include file that should be included 'first' in every C file. */
 
 /* Client library users on Windows need this macro defined here. */
 #if !defined(__WIN__) && defined(_WIN32)
@@ -302,12 +302,6 @@ C_MODE_END
 #undef HAVE_INITGROUPS
 #endif
 
-/* gcc/egcs issues */
-
-#if defined(__GNUC) && defined(__EXCEPTIONS)
-#error "Please add -fno-exceptions to CXXFLAGS and reconfigure/recompile"
-#endif
-
 #if defined(_lint) && !defined(lint)
 #define lint
 #endif
@@ -485,17 +479,6 @@ typedef unsigned short ushort;
 
 #include <my_compiler.h>
 
-/*
-  Wen using the embedded library, users might run into link problems,
-  duplicate declaration of __cxa_pure_virtual, solved by declaring it a
-  weak symbol.
-*/
-#if defined(USE_MYSYS_NEW) && ! defined(DONT_DECLARE_CXA_PURE_VIRTUAL)
-C_MODE_START
-int __cxa_pure_virtual () __attribute__ ((weak));
-C_MODE_END
-#endif
-
 /* The DBUG_ON flag always takes precedence over default DBUG_OFF */
 #if defined(DBUG_ON) && defined(DBUG_OFF)
 #undef DBUG_OFF
@@ -792,9 +775,13 @@ inline unsigned long long my_double2ulon
 #endif /* HAVE_FINITE */
 #endif /* isfinite */
 
+#include <math.h>
 #ifndef HAVE_ISNAN
 #define isnan(x) ((x) != (x))
 #endif
+C_MODE_START
+extern double my_double_isnan(double x);
+C_MODE_END
 
 #ifdef HAVE_ISINF
 /* Check if C compiler is affected by GCC bug #39228 */
@@ -1383,10 +1370,8 @@ do { doubleget_union _tmp; \
 #define MY_INT64_NUM_DECIMAL_DIGITS 21U
 
 /* Define some useful general macros (should be done after all headers). */
-#if !defined(max)
-#define max(a, b)	((a) > (b) ? (a) : (b))
-#define min(a, b)	((a) < (b) ? (a) : (b))
-#endif  
+#define MY_MAX(a, b)	((a) > (b) ? (a) : (b))
+#define MY_MIN(a, b)	((a) < (b) ? (a) : (b))
 
 /*
   Only Linux is known to need an explicit sync of the directory to make sure a
@@ -1496,4 +1481,4 @@ enum loglevel {
 };
 
 
-#endif /* my_global_h */
+#endif  // MY_GLOBAL_INCLUDED

=== modified file 'include/my_pthread.h'
--- a/include/my_pthread.h	2011-10-06 14:33:18 +0000
+++ b/include/my_pthread.h	2011-10-17 10:28:01 +0000
@@ -517,34 +517,33 @@ void safe_mutex_end(FILE *file);
 
 	/* Wrappers if safe mutex is actually used */
 #ifdef SAFE_MUTEX
-#undef pthread_mutex_init
-#undef pthread_mutex_lock
-#undef pthread_mutex_unlock
-#undef pthread_mutex_destroy
-#undef pthread_mutex_wait
-#undef pthread_mutex_timedwait
-#undef pthread_mutex_t
-#undef pthread_cond_wait
-#undef pthread_cond_timedwait
-#undef pthread_mutex_trylock
-#define pthread_mutex_init(A,B) safe_mutex_init((A),(B),__FILE__,__LINE__)
-#define pthread_mutex_lock(A) safe_mutex_lock((A), FALSE, __FILE__, __LINE__)
-#define pthread_mutex_unlock(A) safe_mutex_unlock((A),__FILE__,__LINE__)
-#define pthread_mutex_destroy(A) safe_mutex_destroy((A),__FILE__,__LINE__)
-#define pthread_cond_wait(A,B) safe_cond_wait((A),(B),__FILE__,__LINE__)
-#define pthread_cond_timedwait(A,B,C) safe_cond_timedwait((A),(B),(C),__FILE__,__LINE__)
-#define pthread_mutex_trylock(A) safe_mutex_lock((A), TRUE, __FILE__, __LINE__)
-#define pthread_mutex_t safe_mutex_t
 #define safe_mutex_assert_owner(mp) \
           DBUG_ASSERT((mp)->count > 0 && \
                       pthread_equal(pthread_self(), (mp)->thread))
 #define safe_mutex_assert_not_owner(mp) \
           DBUG_ASSERT(! (mp)->count || \
                       ! pthread_equal(pthread_self(), (mp)->thread))
+
+#define my_cond_timedwait(A,B,C) safe_cond_timedwait((A),(B),(C),__FILE__,__LINE__)
+#define my_cond_wait(A,B) safe_cond_wait((A), (B), __FILE__, __LINE__)
+
+#elif defined(MY_PTHREAD_FASTMUTEX)
+
+#define safe_mutex_assert_owner(mp) do {} while (0)
+#define safe_mutex_assert_not_owner(mp) do {} while (0)
+
+#define my_cond_timedwait(A,B,C) pthread_cond_timedwait((A), &(B)->mutex, (C))
+#define my_cond_wait(A,B) pthread_cond_wait((A), &(B)->mutex)
+
 #else
+
 #define safe_mutex_assert_owner(mp) do {} while (0)
 #define safe_mutex_assert_not_owner(mp) do {} while (0)
-#endif /* SAFE_MUTEX */
+
+#define my_cond_timedwait(A,B,C) pthread_cond_timedwait((A),(B),(C))
+#define my_cond_wait(A,B) pthread_cond_wait((A), (B))
+
+#endif /* !SAFE_MUTEX && ! MY_PTHREAD_FASTMUTEX */
 
 #if defined(MY_PTHREAD_FASTMUTEX) && !defined(SAFE_MUTEX)
 typedef struct st_my_pthread_fastmutex_t
@@ -559,24 +558,6 @@ int my_pthread_fastmutex_init(my_pthread
                               const pthread_mutexattr_t *attr);
 int my_pthread_fastmutex_lock(my_pthread_fastmutex_t *mp);
 
-#undef pthread_mutex_init
-#undef pthread_mutex_lock
-#undef pthread_mutex_unlock
-#undef pthread_mutex_destroy
-#undef pthread_mutex_wait
-#undef pthread_mutex_timedwait
-#undef pthread_mutex_t
-#undef pthread_cond_wait
-#undef pthread_cond_timedwait
-#undef pthread_mutex_trylock
-#define pthread_mutex_init(A,B) my_pthread_fastmutex_init((A),(B))
-#define pthread_mutex_lock(A) my_pthread_fastmutex_lock(A)
-#define pthread_mutex_unlock(A) pthread_mutex_unlock(&(A)->mutex)
-#define pthread_mutex_destroy(A) pthread_mutex_destroy(&(A)->mutex)
-#define pthread_cond_wait(A,B) pthread_cond_wait((A),&(B)->mutex)
-#define pthread_cond_timedwait(A,B,C) pthread_cond_timedwait((A),&(B)->mutex,(C))
-#define pthread_mutex_trylock(A) pthread_mutex_trylock(&(A)->mutex)
-#define pthread_mutex_t my_pthread_fastmutex_t
 #endif /* defined(MY_PTHREAD_FASTMUTEX) && !defined(SAFE_MUTEX) */
 
 	/* READ-WRITE thread locking */

=== modified file 'include/mysql.h'
--- a/include/mysql.h	2011-08-19 13:24:24 +0000
+++ b/include/mysql.h	2011-10-11 04:27:52 +0000
@@ -42,7 +42,7 @@
 extern "C" {
 #endif
 
-#ifndef _global_h				/* If not standard header */
+#ifndef MY_GLOBAL_INCLUDED                /* If not standard header */
 #ifndef MYSQL_ABI_CHECK
 #include <sys/types.h>
 #endif
@@ -66,7 +66,7 @@ typedef char my_bool;
 typedef int my_socket;
 #endif /* __WIN__ */
 #endif /* my_socket_defined */
-#endif /* _global_h */
+#endif /* MY_GLOBAL_INCLUDED */
 
 #include "mysql_version.h"
 #include "mysql_com.h"
@@ -118,7 +118,7 @@ typedef struct st_mysql_field {
 typedef char **MYSQL_ROW;		/* return data as array of strings */
 typedef unsigned int MYSQL_FIELD_OFFSET; /* offset to current field */
 
-#ifndef _global_h
+#ifndef MY_GLOBAL_INCLUDED
 #if defined(NO_CLIENT_LONG_LONG)
 typedef unsigned long my_ulonglong;
 #elif defined (__WIN__)

=== modified file 'include/mysql/psi/mysql_thread.h'
--- a/include/mysql/psi/mysql_thread.h	2011-07-05 08:15:52 +0000
+++ b/include/mysql/psi/mysql_thread.h	2011-10-17 10:28:01 +0000
@@ -69,7 +69,13 @@
 struct st_mysql_mutex
 {
   /** The real mutex. */
+#ifdef SAFE_MUTEX
+  safe_mutex_t m_mutex;
+#elif defined(MY_PTHREAD_FASTMUTEX)
+  my_pthread_fastmutex_t m_mutex;
+#else
   pthread_mutex_t m_mutex;
+#endif
   /**
     The instrumentation hook.
     Note that this hook is not conditionally defined,
@@ -610,6 +616,8 @@ static inline int inline_mysql_mutex_ini
 #endif
 #ifdef SAFE_MUTEX
   return safe_mutex_init(&that->m_mutex, attr, src_file, src_line);
+#elif defined(MY_PTHREAD_FASTMUTEX)
+  return my_pthread_fastmutex_init(&that->m_mutex, attr);
 #else
   return pthread_mutex_init(&that->m_mutex, attr);
 #endif
@@ -628,6 +636,8 @@ static inline int inline_mysql_mutex_des
 #endif
 #ifdef SAFE_MUTEX
   return safe_mutex_destroy(&that->m_mutex, src_file, src_line);
+#elif defined(MY_PTHREAD_FASTMUTEX)
+  return pthread_mutex_destroy(&that->m_mutex.mutex);
 #else
   return pthread_mutex_destroy(&that->m_mutex);
 #endif
@@ -650,6 +660,8 @@ static inline int inline_mysql_mutex_loc
     PSI_CALL(start_mutex_wait)(locker, src_file, src_line);
 #ifdef SAFE_MUTEX
     result= safe_mutex_lock(&that->m_mutex, FALSE, src_file, src_line);
+#elif defined(MY_PTHREAD_FASTMUTEX)
+    result= my_pthread_fastmutex_lock(&that->m_mutex);
 #else
     result= pthread_mutex_lock(&that->m_mutex);
 #endif
@@ -660,6 +672,8 @@ static inline int inline_mysql_mutex_loc
 
 #ifdef SAFE_MUTEX
   result= safe_mutex_lock(&that->m_mutex, FALSE, src_file, src_line);
+#elif defined(MY_PTHREAD_FASTMUTEX)
+  result= my_pthread_fastmutex_lock(&that->m_mutex);
 #else
   result= pthread_mutex_lock(&that->m_mutex);
 #endif
@@ -683,6 +697,8 @@ static inline int inline_mysql_mutex_try
     PSI_CALL(start_mutex_wait)(locker, src_file, src_line);
 #ifdef SAFE_MUTEX
     result= safe_mutex_lock(&that->m_mutex, TRUE, src_file, src_line);
+#elif defined(MY_PTHREAD_FASTMUTEX)
+    result= pthread_mutex_trylock(&that->m_mutex.mutex);
 #else
     result= pthread_mutex_trylock(&that->m_mutex);
 #endif
@@ -693,6 +709,8 @@ static inline int inline_mysql_mutex_try
 
 #ifdef SAFE_MUTEX
   result= safe_mutex_lock(&that->m_mutex, TRUE, src_file, src_line);
+#elif defined(MY_PTHREAD_FASTMUTEX)
+  result= pthread_mutex_trylock(&that->m_mutex.mutex);
 #else
   result= pthread_mutex_trylock(&that->m_mutex);
 #endif
@@ -712,6 +730,8 @@ static inline int inline_mysql_mutex_unl
 #endif
 #ifdef SAFE_MUTEX
   result= safe_mutex_unlock(&that->m_mutex, src_file, src_line);
+#elif defined(MY_PTHREAD_FASTMUTEX)
+  result= pthread_mutex_unlock(&that->m_mutex.mutex);
 #else
   result= pthread_mutex_unlock(&that->m_mutex);
 #endif
@@ -1033,13 +1053,13 @@ static inline int inline_mysql_cond_wait
   if (likely(locker != NULL))
   {
     PSI_CALL(start_cond_wait)(locker, src_file, src_line);
-    result= pthread_cond_wait(&that->m_cond, &mutex->m_mutex);
+    result= my_cond_wait(&that->m_cond, &mutex->m_mutex);
     PSI_CALL(end_cond_wait)(locker, result);
     return result;
   }
 #endif
 
-  result= pthread_cond_wait(&that->m_cond, &mutex->m_mutex);
+  result= my_cond_wait(&that->m_cond, &mutex->m_mutex);
   return result;
 }
 
@@ -1061,13 +1081,13 @@ static inline int inline_mysql_cond_time
   if (likely(locker != NULL))
   {
     PSI_CALL(start_cond_wait)(locker, src_file, src_line);
-    result= pthread_cond_timedwait(&that->m_cond, &mutex->m_mutex, abstime);
+    result= my_cond_timedwait(&that->m_cond, &mutex->m_mutex, abstime);
     PSI_CALL(end_cond_wait)(locker, result);
     return result;
   }
 #endif
 
-  result= pthread_cond_timedwait(&that->m_cond, &mutex->m_mutex, abstime);
+  result= my_cond_timedwait(&that->m_cond, &mutex->m_mutex, abstime);
   return result;
 }
 

=== modified file 'include/mysql/psi/psi.h'
--- a/include/mysql/psi/psi.h	2011-11-02 23:29:01 +0000
+++ b/include/mysql/psi/psi.h	2011-11-03 16:03:34 +0000
@@ -16,7 +16,7 @@
 #ifndef MYSQL_PERFORMANCE_SCHEMA_INTERFACE_H
 #define MYSQL_PERFORMANCE_SCHEMA_INTERFACE_H
 
-#ifndef _global_h
+#ifndef MY_GLOBAL_INCLUDED
 /*
   Make sure a .c or .cc file contains an include to my_global.h first.
   When this include is missing, all the #ifdef HAVE_XXX have no effect,

=== modified file 'include/mysql/psi/psi_abi_v1.h'
--- a/include/mysql/psi/psi_abi_v1.h	2010-07-08 17:05:50 +0000
+++ b/include/mysql/psi/psi_abi_v1.h	2011-10-11 04:27:52 +0000
@@ -21,6 +21,6 @@
 */
 #define USE_PSI_1
 #define HAVE_PSI_INTERFACE
-#define _global_h
+#define MY_GLOBAL_INCLUDED
 #include "mysql/psi/psi.h"
 

=== modified file 'include/mysql_com.h'
--- a/include/mysql_com.h	2011-11-01 16:33:58 +0000
+++ b/include/mysql_com.h	2011-11-03 16:03:34 +0000
@@ -459,7 +459,7 @@ my_bool	net_write_command(NET *net,unsig
 my_bool net_write_packet(NET *net, const unsigned char *packet, size_t length);
 unsigned long my_net_read(NET *net);
 
-#ifdef _global_h
+#ifdef MY_GLOBAL_INCLUDED
 void my_net_set_write_timeout(NET *net, uint timeout);
 void my_net_set_read_timeout(NET *net, uint timeout);
 #endif
@@ -552,7 +552,7 @@ const char *mysql_errno_to_sqlstate(unsi
 my_bool my_thread_init(void);
 void my_thread_end(void);
 
-#ifdef _global_h
+#ifdef MY_GLOBAL_INCLUDED
 ulong STDCALL net_field_length(uchar **packet);
 my_ulonglong net_field_length_ll(uchar **packet);
 uchar *net_store_length(uchar *pkg, ulonglong length);

=== modified file 'include/waiting_threads.h'
--- a/include/waiting_threads.h	2011-06-30 15:50:45 +0000
+++ b/include/waiting_threads.h	2011-10-11 04:27:52 +0000
@@ -120,7 +120,7 @@ void wt_end(void);
 void wt_thd_lazy_init(WT_THD *, const ulong *, const ulong *, const ulong *, const ulong *);
 void wt_thd_destroy(WT_THD *);
 int wt_thd_will_wait_for(WT_THD *, WT_THD *, const WT_RESOURCE_ID *);
-int wt_thd_cond_timedwait(WT_THD *, pthread_mutex_t *);
+int wt_thd_cond_timedwait(WT_THD *, mysql_mutex_t *);
 void wt_thd_release(WT_THD *, const WT_RESOURCE_ID *);
 #define wt_thd_release_all(THD) wt_thd_release((THD), 0)
 my_bool wt_resource_id_memcmp(const void *, const void *);

=== modified file 'libmysql/libmysql.c'
--- a/libmysql/libmysql.c	2011-07-04 00:25:46 +0000
+++ b/libmysql/libmysql.c	2011-08-29 12:08:58 +0000
@@ -1109,7 +1109,7 @@ void my_net_local_init(NET *net)
   my_net_set_read_timeout(net, CLIENT_NET_READ_TIMEOUT);
   my_net_set_write_timeout(net, CLIENT_NET_WRITE_TIMEOUT);
   net->retry_count=  1;
-  net->max_packet_size= max(net_buffer_length, max_allowed_packet);
+  net->max_packet_size= MY_MAX(net_buffer_length, max_allowed_packet);
 }
 
 /*
@@ -3197,7 +3197,7 @@ static void fetch_string_with_conversion
       copy_length= end - start;
       /* We've got some data beyond offset: copy up to buffer_length bytes */
       if (param->buffer_length)
-        memcpy(buffer, start, min(copy_length, param->buffer_length));
+        memcpy(buffer, start, MY_MIN(copy_length, param->buffer_length));
     }
     else
       copy_length= 0;
@@ -3423,7 +3423,7 @@ static void fetch_float_with_conversion(
     size_t len;
     if (field->decimals >= NOT_FIXED_DEC)
       len= my_gcvt(value, type,
-                   (int) min(sizeof(buff)-1, param->buffer_length),
+                   (int) MY_MIN(sizeof(buff)-1, param->buffer_length),
                    buff, NULL);
     else
       len= my_fcvt(value, (int) field->decimals, buff, NULL);
@@ -3733,7 +3733,7 @@ static void fetch_result_bin(MYSQL_BIND
                              uchar **row)
 {
   ulong length= net_field_length(row);
-  ulong copy_length= min(length, param->buffer_length);
+  ulong copy_length= MY_MIN(length, param->buffer_length);
   memcpy(param->buffer, (char *)*row, copy_length);
   *param->length= length;
   *param->error= copy_length < length;
@@ -3745,7 +3745,7 @@ static void fetch_result_str(MYSQL_BIND
                              uchar **row)
 {
   ulong length= net_field_length(row);
-  ulong copy_length= min(length, param->buffer_length);
+  ulong copy_length= MY_MIN(length, param->buffer_length);
   memcpy(param->buffer, (char *)*row, copy_length);
   /* Add an end null if there is room in the buffer */
   if (copy_length != param->buffer_length)

=== modified file 'libmysqld/lib_sql.cc'
--- a/libmysqld/lib_sql.cc	2011-10-06 11:06:34 +0000
+++ b/libmysqld/lib_sql.cc	2011-10-13 07:26:28 +0000
@@ -37,6 +37,11 @@ C_MODE_START
 #include "errmsg.h"
 #include "embedded_priv.h"
 
+#include <algorithm>
+
+using std::min;
+using std::max;
+
 extern unsigned int mysql_server_last_errno;
 extern char mysql_server_last_error[MYSQL_ERRMSG_SIZE];
 static my_bool emb_read_query_result(MYSQL *mysql);
@@ -888,7 +893,7 @@ write_eof_packet(THD *thd, uint server_s
     is cleared between substatements, and mysqltest gets confused
   */
   thd->cur_data->embedded_info->warning_count=
-    (thd->spcont ? 0 : min(statement_warn_count, 65535));
+    (thd->spcont ? 0 : min(statement_warn_count, 65535U));
   return FALSE;
 }
 

=== modified file 'mysql-test/mysql-test-run.pl'
--- a/mysql-test/mysql-test-run.pl	2011-10-14 15:13:18 +0000
+++ b/mysql-test/mysql-test-run.pl	2011-11-04 09:18:36 +0000
@@ -1998,7 +1998,8 @@ sub executable_setup () {
   $exe_mysql=          mtr_exe_exists("$path_client_bindir/mysql");
   $exe_mysql_plugin=   mtr_exe_exists("$path_client_bindir/mysql_plugin");
 
-  $exe_mysql_embedded= mtr_exe_maybe_exists("$basedir/libmysqld/examples/mysql_embedded");
+  $exe_mysql_embedded= mtr_exe_maybe_exists("$basedir/libmysqld/examples/mysql_embedded",
+                                            "$bindir/bin/mysql_embedded");
 
   if ( ! $opt_skip_ndbcluster )
   {

=== modified file 'mysql-test/r/case.result'
--- a/mysql-test/r/case.result	2011-07-19 15:11:15 +0000
+++ b/mysql-test/r/case.result	2011-11-03 10:15:06 +0000
@@ -220,3 +220,7 @@ a	d
 3	11120436154190595086
 drop table t1, t2;
 End of 5.0 tests
+CREATE TABLE t1(a YEAR);
+SELECT 1 FROM t1 WHERE a=1 AND CASE 1 WHEN a THEN 1 ELSE 1 END;
+1
+DROP TABLE t1;

=== modified file 'mysql-test/r/udf.result'
--- a/mysql-test/r/udf.result	2011-07-19 15:11:15 +0000
+++ b/mysql-test/r/udf.result	2011-10-11 04:27:52 +0000
@@ -499,3 +499,26 @@ UNLOCK TABLES;
 # Reaping: CREATE FUNCTION metaphon ...
 DROP FUNCTION metaphon;
 DROP FUNCTION reverse_lookup;
+#
+# WL#5825 Using C++ Standard Library with MySQL code
+#
+CREATE AGGREGATE FUNCTION my_median
+RETURNS INTEGER SONAME "UDF_EXAMPLE_LIB";
+SELECT my_median(1);
+my_median(1)
+1
+CREATE TABLE t1(a INT, b INT);
+SELECT a, my_median(b) from t1 group by a;
+a	my_median(b)
+INSERT INTO t1 values
+(1, 1), (1, 2), (1, 200),
+(2, 1), (2, 200), (2, 200), (2, 1000),
+(3, 1), (3, 1), (3, 100), (3, 100), (3, 42)
+;
+SELECT a, my_median(b) from t1 GROUP BY a;
+a	my_median(b)
+1	2
+2	200
+3	42
+DROP FUNCTION my_median;
+DROP TABLE t1;

=== modified file 'mysql-test/t/case.test'
--- a/mysql-test/t/case.test	2010-08-19 11:55:35 +0000
+++ b/mysql-test/t/case.test	2011-11-03 10:15:06 +0000
@@ -173,3 +173,12 @@ select t1.a, (case t1.a when 0 then 0 el
 drop table t1, t2;
 
 --echo End of 5.0 tests
+
+#
+# Bug #11764313 57135: CRASH IN ITEM_FUNC_CASE::FIND_ITEM WITH CASE WHEN
+# ELSE CLAUSE
+#
+
+CREATE TABLE t1(a YEAR);
+SELECT 1 FROM t1 WHERE a=1 AND CASE 1 WHEN a THEN 1 ELSE 1 END;
+DROP TABLE t1;

=== modified file 'mysql-test/t/disabled.def'
--- a/mysql-test/t/disabled.def	2011-08-03 18:22:00 +0000
+++ b/mysql-test/t/disabled.def	2011-11-04 09:18:36 +0000
@@ -16,4 +16,3 @@ alter_table-big          : Bug#11748731
 create-big               : Bug#11748731 2010-11-15 mattiasj was not tested
 archive-big              : Bug#11817185 2011-03-10 Anitha Disabled since this leads to timeout on Solaris Sparc
 log_tables-big           : Bug#11756699 2010-11-15 mattiasj report already exists
-mysql_embedded           : Bug#12561297 2011-05-14 Anitha Dependent on PB2 changes - eventum#41836

=== modified file 'mysql-test/t/mysql_plugin.test'
--- a/mysql-test/t/mysql_plugin.test	2011-10-18 12:33:26 +0000
+++ b/mysql-test/t/mysql_plugin.test	2011-11-04 13:11:50 +0000
@@ -142,8 +142,11 @@ EOF
 --echo # Simulate loading a plugin libary with multiple entry points.
 --echo # This will test the DISABLE to ensure all rows are removed.
 --echo #
+--replace_regex /\.dll/.so/
 eval INSERT INTO mysql.plugin VALUES ('wicky', '$DAEMONEXAMPLE'); 
+--replace_regex /\.dll/.so/
 eval INSERT INTO mysql.plugin VALUES ('wacky', '$DAEMONEXAMPLE'); 
+--replace_regex /\.dll/.so/
 eval INSERT INTO mysql.plugin VALUES ('wonky', '$DAEMONEXAMPLE'); 
 
 --echo #

=== modified file 'mysql-test/t/udf.test'
--- a/mysql-test/t/udf.test	2011-02-09 10:19:05 +0000
+++ b/mysql-test/t/udf.test	2011-10-11 04:27:52 +0000
@@ -603,3 +603,24 @@ connection default;
 --reap
 DROP FUNCTION metaphon;
 DROP FUNCTION reverse_lookup;
+
+--echo #
+--echo # WL#5825 Using C++ Standard Library with MySQL code
+--echo #
+
+--replace_result $UDF_EXAMPLE_LIB UDF_EXAMPLE_LIB
+eval CREATE AGGREGATE FUNCTION my_median
+RETURNS INTEGER SONAME "$UDF_EXAMPLE_LIB";
+
+SELECT my_median(1);
+CREATE TABLE t1(a INT, b INT);
+SELECT a, my_median(b) from t1 group by a;
+INSERT INTO t1 values
+(1, 1), (1, 2), (1, 200),
+(2, 1), (2, 200), (2, 200), (2, 1000),
+(3, 1), (3, 1), (3, 100), (3, 100), (3, 42)
+;
+SELECT a, my_median(b) from t1 GROUP BY a;
+
+DROP FUNCTION my_median;
+DROP TABLE t1;

=== modified file 'mysys/CMakeLists.txt'
--- a/mysys/CMakeLists.txt	2011-07-05 08:15:52 +0000
+++ b/mysys/CMakeLists.txt	2011-10-11 04:27:52 +0000
@@ -25,6 +25,7 @@ SET(MYSYS_SOURCES  array.c charset-def.c
 				my_compress.c my_copy.c  my_create.c my_delete.c
 				my_div.c my_error.c my_file.c my_fopen.c my_fstream.c 
 				my_gethwaddr.c my_getopt.c my_getsystime.c my_getwd.c my_compare.c my_init.c
+				my_isnan.c
 				my_lib.c my_lock.c my_malloc.c my_mess.c
 				my_mkdir.c my_mmap.c my_once.c my_open.c my_pread.c my_pthread.c
 				my_quick.c my_read.c my_redel.c my_rename.c my_seek.c my_sleep.c
@@ -34,7 +35,7 @@ SET(MYSYS_SOURCES  array.c charset-def.c
 				thr_rwlock.c tree.c typelib.c base64.c my_memmem.c my_getpagesize.c
 				lf_alloc-pin.c lf_dynarray.c lf_hash.c
 				my_atomic.c my_getncpus.c
-				my_rdtsc.c waiting_threads.c psi_noop.cc)
+				my_rdtsc.c waiting_threads.c psi_noop.c)
 
 IF (WIN32)
  SET (MYSYS_SOURCES ${MYSYS_SOURCES} my_winthread.c my_wincond.c my_winerr.c my_winfile.c my_windac.c my_conio.c)
@@ -44,12 +45,6 @@ IF(HAVE_ALARM)
  SET(MYSYS_SOURCES ${MYSYS_SOURCES} my_alarm.c)
 ENDIF()
 
-IF(NOT HAVE_CXX_NEW)
- # gcc as C++ compiler  does not have new/delete
- SET(MYSYS_SOURCES ${MYSYS_SOURCES} my_new.cc)
- ADD_DEFINITIONS( -DUSE_MYSYS_NEW)
-ENDIF()
-
 IF(CMAKE_SYSTEM_NAME MATCHES "SunOS" AND CMAKE_C_COMPILER_ID MATCHES "SunPro")
   # Inline assembly template for rdtsc
   SET_SOURCE_FILES_PROPERTIES(my_rdtsc.c

=== modified file 'mysys/array.c'
--- a/mysys/array.c	2011-07-19 15:11:15 +0000
+++ b/mysys/array.c	2011-08-29 12:08:58 +0000
@@ -47,7 +47,7 @@ my_bool init_dynamic_array2(DYNAMIC_ARRA
   DBUG_ENTER("init_dynamic_array");
   if (!alloc_increment)
   {
-    alloc_increment=max((8192-MALLOC_OVERHEAD)/element_size,16);
+    alloc_increment=MY_MAX((8192-MALLOC_OVERHEAD)/element_size,16);
     if (init_alloc > 8 && alloc_increment > init_alloc * 2)
       alloc_increment=init_alloc*2;
   }
@@ -340,7 +340,7 @@ void delete_dynamic_element(DYNAMIC_ARRA
 
 void freeze_size(DYNAMIC_ARRAY *array)
 {
-  uint elements=max(array->elements,1);
+  uint elements=MY_MAX(array->elements,1);
 
   /*
     Do nothing if we are using a static buffer

=== modified file 'mysys/default.c'
--- a/mysys/default.c	2011-06-30 15:50:45 +0000
+++ b/mysys/default.c	2011-08-29 12:08:58 +0000
@@ -901,7 +901,7 @@ static int search_default_file_with_ext(
       for ( ; my_isspace(&my_charset_latin1,end[-1]) ; end--) ;
       end[0]=0;
 
-      strmake(curr_gr, ptr, min((size_t) (end-ptr)+1, sizeof(curr_gr)-1));
+      strmake(curr_gr, ptr, MY_MIN((size_t) (end-ptr)+1, sizeof(curr_gr)-1));
 
       /* signal that a new group is found */
       opt_handler(handler_ctx, curr_gr, NULL);

=== modified file 'mysys/lf_alloc-pin.c'
--- a/mysys/lf_alloc-pin.c	2011-07-07 19:06:44 +0000
+++ b/mysys/lf_alloc-pin.c	2011-08-29 12:08:58 +0000
@@ -284,7 +284,7 @@ struct st_harvester {
 static int harvest_pins(LF_PINS *el, struct st_harvester *hv)
 {
   int i;
-  LF_PINS *el_end= el+min(hv->npins, LF_DYNARRAY_LEVEL_LENGTH);
+  LF_PINS *el_end= el + MY_MIN(hv->npins, LF_DYNARRAY_LEVEL_LENGTH);
   for (; el < el_end; el++)
   {
     for (i= 0; i < LF_PINBOX_PINS; i++)

=== modified file 'mysys/lf_dynarray.c'
--- a/mysys/lf_dynarray.c	2011-06-30 15:50:45 +0000
+++ b/mysys/lf_dynarray.c	2011-08-29 12:08:58 +0000
@@ -124,8 +124,8 @@ void *_lf_dynarray_lvalue(LF_DYNARRAY *a
   {
     uchar *alloc, *data;
     alloc= my_malloc(LF_DYNARRAY_LEVEL_LENGTH * array->size_of_element +
-                    max(array->size_of_element, sizeof(void *)),
-                    MYF(MY_WME|MY_ZEROFILL));
+                     MY_MAX(array->size_of_element, sizeof(void *)),
+                     MYF(MY_WME|MY_ZEROFILL));
     if (unlikely(!alloc))
       return(NULL);
     /* reserve the space for free() address */

=== modified file 'mysys/mf_format.c'
--- a/mysys/mf_format.c	2011-06-30 15:50:45 +0000
+++ b/mysys/mf_format.c	2011-08-29 12:08:58 +0000
@@ -85,7 +85,7 @@ char * fn_format(char * to, const char *
     tmp_length= strlength(startpos);
     DBUG_PRINT("error",("dev: '%s'  ext: '%s'  length: %u",dev,ext,
                         (uint) length));
-    (void) strmake(to,startpos,min(tmp_length,FN_REFLEN-1));
+    (void) strmake(to, startpos, MY_MIN(tmp_length, FN_REFLEN-1));
   }
   else
   {

=== modified file 'mysys/mf_iocache.c'
--- a/mysys/mf_iocache.c	2011-06-30 15:50:45 +0000
+++ b/mysys/mf_iocache.c	2011-08-29 12:08:58 +0000
@@ -1128,7 +1128,7 @@ static void copy_to_read_buffer(IO_CACHE
   */
   while (write_length)
   {
-    size_t copy_length= min(write_length, write_cache->buffer_length);
+    size_t copy_length= MY_MIN(write_length, write_cache->buffer_length);
     int  __attribute__((unused)) rc;
 
     rc= lock_io_cache(write_cache, write_cache->pos_in_file);
@@ -1286,7 +1286,7 @@ read_append_buffer:
       TODO: figure out if the assert below is needed or correct.
     */
     DBUG_ASSERT(pos_in_file == info->end_of_file);
-    copy_len=min(Count, len_in_buff);
+    copy_len= MY_MIN(Count, len_in_buff);
     memcpy(Buffer, info->append_read_pos, copy_len);
     info->append_read_pos += copy_len;
     Count -= copy_len;
@@ -1395,7 +1395,7 @@ int _my_b_async_read(register IO_CACHE *
     }
 #endif
 	/* Copy found bytes to buffer */
-    length=min(Count,read_length);
+    length= MY_MIN(Count, read_length);
     memcpy(Buffer,info->read_pos,(size_t) length);
     Buffer+=length;
     Count-=length;
@@ -1429,7 +1429,7 @@ int _my_b_async_read(register IO_CACHE *
       if ((read_length=mysql_file_read(info->file,info->request_pos,
 			               read_length, info->myflags)) == (size_t) -1)
         return info->error= -1;
-      use_length=min(Count,read_length);
+      use_length= MY_MIN(Count, read_length);
       memcpy(Buffer,info->request_pos,(size_t) use_length);
       info->read_pos=info->request_pos+Count;
       info->read_end=info->request_pos+read_length;

=== modified file 'mysys/my_alloc.c'
--- a/mysys/my_alloc.c	2011-07-19 15:11:15 +0000
+++ b/mysys/my_alloc.c	2011-08-29 12:08:58 +0000
@@ -219,7 +219,7 @@ void *alloc_root(MEM_ROOT *mem_root, siz
   {						/* Time to alloc new block */
     block_size= mem_root->block_size * (mem_root->block_num >> 2);
     get_size= length+ALIGN_SIZE(sizeof(USED_MEM));
-    get_size= max(get_size, block_size);
+    get_size= MY_MAX(get_size, block_size);
 
     if (!(next = (USED_MEM*) my_malloc(get_size,MYF(MY_WME | ME_FATALERROR))))
     {

=== modified file 'mysys/my_bitmap.c'
--- a/mysys/my_bitmap.c	2011-07-04 00:25:46 +0000
+++ b/mysys/my_bitmap.c	2011-08-29 12:08:58 +0000
@@ -416,7 +416,7 @@ void bitmap_intersect(MY_BITMAP *map, co
 
   DBUG_ASSERT(map->bitmap && map2->bitmap);
 
-  end= to+min(len,len2);
+  end= to + MY_MIN(len, len2);
   for (; to < end; to++, from++)
     *to &= *from;
 

=== modified file 'mysys/my_compare.c'
--- a/mysys/my_compare.c	2011-03-29 12:56:34 +0000
+++ b/mysys/my_compare.c	2011-06-01 13:47:36 +0000
@@ -36,7 +36,7 @@ int ha_compare_text(const CHARSET_INFO *
 static int compare_bin(uchar *a, uint a_length, uchar *b, uint b_length,
                        my_bool part_key, my_bool skip_end_space)
 {
-  uint length= min(a_length,b_length);
+  uint length= MY_MIN(a_length, b_length);
   uchar *end= a+ length;
   int flag;
 
@@ -164,7 +164,7 @@ int ha_key_cmp(register HA_KEYSEG *keyse
         continue;                               /* To next key part */
       }
     }
-    end= a+ min(keyseg->length,key_length);
+    end= a + MY_MIN(keyseg->length, key_length);
     next_key_length=key_length-keyseg->length;
 
     switch ((enum ha_base_keytype) keyseg->type) {

=== modified file 'mysys/my_compress.c'
--- a/mysys/my_compress.c	2011-06-30 15:46:53 +0000
+++ b/mysys/my_compress.c	2011-08-29 12:08:58 +0000
@@ -244,7 +244,7 @@ int unpackfrm(uchar **unpack_data, size_
 
    if (ver != 1)
      DBUG_RETURN(1);
-   if (!(data= my_malloc(max(orglen, complen), MYF(MY_WME))))
+   if (!(data= my_malloc(MY_MAX(orglen, complen), MYF(MY_WME))))
      DBUG_RETURN(2);
    memcpy(data, pack_data + BLOB_HEADER, complen);
 

=== modified file 'mysys/my_file.c'
--- a/mysys/my_file.c	2011-06-30 15:50:45 +0000
+++ b/mysys/my_file.c	2011-08-29 12:08:58 +0000
@@ -98,7 +98,7 @@ uint my_set_max_open_files(uint files)
   DBUG_PRINT("enter",("files: %u  my_file_limit: %u", files, my_file_limit));
 
   files+= MY_FILE_MIN;
-  files= set_max_open_files(min(files, OS_FILE_LIMIT));
+  files= set_max_open_files(MY_MIN(files, OS_FILE_LIMIT));
   if (files <= MY_NFILE)
     DBUG_RETURN(files);
 
@@ -108,9 +108,9 @@ uint my_set_max_open_files(uint files)
 
   /* Copy any initialized files */
   memcpy((char*) tmp, (char*) my_file_info,
-         sizeof(*tmp) * min(my_file_limit, files));
+         sizeof(*tmp) * MY_MIN(my_file_limit, files));
   memset((tmp + my_file_limit), 0, 
-        max((int) (files- my_file_limit), 0)*sizeof(*tmp));
+        MY_MAX((int) (files - my_file_limit), 0) * sizeof(*tmp));
   my_free_open_file_info();			/* Free if already allocated */
   my_file_info= tmp;
   my_file_limit= files;

=== added file 'mysys/my_isnan.c'
--- a/mysys/my_isnan.c	1970-01-01 00:00:00 +0000
+++ b/mysys/my_isnan.c	2011-10-11 04:27:52 +0000
@@ -0,0 +1,27 @@
+/* Copyright (c) 2011, 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 */
+
+#include "my_global.h"
+
+#ifdef __WIN__
+#include <float.h>
+#endif
+
+#include <math.h>
+
+double my_double_isnan(double x)
+{
+  return isnan(x);
+}

=== removed file 'mysys/my_new.cc'
--- a/mysys/my_new.cc	2011-06-30 15:50:45 +0000
+++ b/mysys/my_new.cc	1970-01-01 00:00:00 +0000
@@ -1,58 +0,0 @@
-/* Copyright (c) 2000, 2010, 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 02110-1301  USA */
-
-/*
-  This is a replacement of new/delete operators to be used when compiling
-  with gcc 3.0.x to avoid including libstdc++
-*/
-
-#include "mysys_priv.h"
-
-#ifdef USE_MYSYS_NEW
-
-void *operator new (size_t sz)
-{
-  return (void *) malloc (sz ? sz : 1);
-}
-
-void *operator new[] (size_t sz)
-{
-  return (void *) malloc (sz ? sz : 1);
-}
-
-void operator delete (void *ptr)
-{
-  if (ptr)
-    free(ptr);
-}
-
-void operator delete[] (void *ptr) throw ()
-{
-  if (ptr)
-    free(ptr);
-}
-
-C_MODE_START
-
-int __cxa_pure_virtual()
-{
-  assert(! "Aborted: pure virtual method called.");
-  return 0;
-}
-
-C_MODE_END
-
-#endif /* USE_MYSYS_NEW */
-

=== renamed file 'mysys/psi_noop.cc' => 'mysys/psi_noop.c'
--- a/mysys/psi_noop.cc	2011-08-25 07:53:21 +0000
+++ b/mysys/psi_noop.c	2011-10-11 04:27:52 +0000
@@ -25,213 +25,235 @@
 #include "my_sys.h"
 #include "mysql/psi/psi.h"
 
+typedef struct PSI_cond PSI_cond;
+typedef struct PSI_cond_locker PSI_cond_locker;
+typedef struct PSI_file PSI_file;
+typedef struct PSI_file_locker PSI_file_locker;
+typedef struct PSI_idle_locker PSI_idle_locker;
+typedef struct PSI_mutex PSI_mutex;
+typedef struct PSI_mutex_locker PSI_mutex_locker;
+typedef struct PSI_rwlock PSI_rwlock;
+typedef struct PSI_rwlock_locker PSI_rwlock_locker;
+typedef struct PSI_socket PSI_socket;
+typedef struct PSI_socket_locker PSI_socket_locker;
+typedef struct PSI_statement_locker PSI_statement_locker;
+typedef struct PSI_table PSI_table;
+typedef struct PSI_table_locker PSI_table_locker;
+typedef struct PSI_table_share PSI_table_share;
+typedef struct PSI_thread PSI_thread;
+
 C_MODE_START
 
-static void register_mutex_noop(const char *category,
-                                PSI_mutex_info *info,
-                                int count)
+#define NNN __attribute__((unused))
+
+static void register_mutex_noop(const char *category NNN,
+                                PSI_mutex_info *info NNN,
+                                int count NNN)
 {
   return;
 }
 
-static void register_rwlock_noop(const char *category,
-                                 PSI_rwlock_info *info,
-                                 int count)
+static void register_rwlock_noop(const char *category NNN,
+                                 PSI_rwlock_info *info NNN,
+                                 int count NNN)
 {
   return;
 }
 
-static void register_cond_noop(const char *category,
-                               PSI_cond_info *info,
-                               int count)
+static void register_cond_noop(const char *category NNN,
+                               PSI_cond_info *info NNN,
+                               int count NNN)
 {
   return;
 }
 
-static void register_thread_noop(const char *category,
-                                 PSI_thread_info *info,
-                                 int count)
+static void register_thread_noop(const char *category NNN,
+                                 PSI_thread_info *info NNN,
+                                 int count NNN)
 {
   return;
 }
 
-static void register_file_noop(const char *category,
-                               PSI_file_info *info,
-                               int count)
+static void register_file_noop(const char *category NNN,
+                               PSI_file_info *info NNN,
+                               int count NNN)
 {
   return;
 }
 
-static void register_stage_noop(const char *category,
-                                PSI_stage_info **info_array,
-                                int count)
+static void register_stage_noop(const char *category NNN,
+                                PSI_stage_info **info_array NNN,
+                                int count NNN)
 {
   return;
 }
 
-static void register_statement_noop(const char *category,
-                                    PSI_statement_info *info,
-                                    int count)
+static void register_statement_noop(const char *category NNN,
+                                    PSI_statement_info *info NNN,
+                                    int count NNN)
 {
   return;
 }
 
-static void register_socket_noop(const char *category,
-                                 PSI_socket_info *info,
-                                 int count)
+static void register_socket_noop(const char *category NNN,
+                                 PSI_socket_info *info NNN,
+                                 int count NNN)
 {
   return;
 }
 
 static PSI_mutex*
-init_mutex_noop(PSI_mutex_key key, const void *identity)
+init_mutex_noop(PSI_mutex_key key NNN, const void *identity NNN)
 {
   return NULL;
 }
 
-static void destroy_mutex_noop(PSI_mutex* mutex)
+static void destroy_mutex_noop(PSI_mutex* mutex NNN)
 {
   return;
 }
 
 static PSI_rwlock*
-init_rwlock_noop(PSI_rwlock_key key, const void *identity)
+init_rwlock_noop(PSI_rwlock_key key NNN, const void *identity NNN)
 {
   return NULL;
 }
 
-static void destroy_rwlock_noop(PSI_rwlock* rwlock)
+static void destroy_rwlock_noop(PSI_rwlock* rwlock NNN)
 {
   return;
 }
 
 static PSI_cond*
-init_cond_noop(PSI_cond_key key, const void *identity)
+init_cond_noop(PSI_cond_key key NNN, const void *identity NNN)
 {
   return NULL;
 }
 
-static void destroy_cond_noop(PSI_cond* cond)
+static void destroy_cond_noop(PSI_cond* cond NNN)
 {
   return;
 }
 
 static PSI_socket*
-init_socket_noop(PSI_socket_key key, const my_socket *fd)
+init_socket_noop(PSI_socket_key key NNN, const my_socket *fd NNN)
 {
   return NULL;
 }
 
-static void destroy_socket_noop(PSI_socket* socket)
+static void destroy_socket_noop(PSI_socket* socket NNN)
 {
   return;
 }
 
 static PSI_table_share*
-get_table_share_noop(my_bool temporary, TABLE_SHARE *share)
+get_table_share_noop(my_bool temporary NNN, struct TABLE_SHARE *share NNN)
 {
   return NULL;
 }
 
-static void release_table_share_noop(PSI_table_share* share)
+static void release_table_share_noop(PSI_table_share* share NNN)
 {
   return;
 }
 
 static void
-drop_table_share_noop(const char *schema_name, int schema_name_length,
-                      const char *table_name, int table_name_length)
+drop_table_share_noop(const char *schema_name NNN, int schema_name_length NNN,
+                      const char *table_name NNN, int table_name_length NNN)
 {
   return;
 }
 
 static PSI_table*
-open_table_noop(PSI_table_share *share, const void *identity)
+open_table_noop(PSI_table_share *share NNN, const void *identity NNN)
 {
   return NULL;
 }
 
-static void unbind_table_noop(PSI_table *table)
+static void unbind_table_noop(PSI_table *table NNN)
 {
   return;
 }
 
-static void rebind_table_noop(PSI_table *table)
+static void rebind_table_noop(PSI_table *table NNN)
 {
   return;
 }
 
-static void close_table_noop(PSI_table *table)
+static void close_table_noop(PSI_table *table NNN)
 {
   return;
 }
 
-static void create_file_noop(PSI_file_key key, const char *name, File file)
+static void create_file_noop(PSI_file_key key NNN,
+                             const char *name NNN, File file NNN)
 {
   return;
 }
 
-static int spawn_thread_noop(PSI_thread_key key,
-                             pthread_t *thread, const pthread_attr_t *attr,
-                             void *(*start_routine)(void*), void *arg)
+static int spawn_thread_noop(PSI_thread_key key NNN,
+                             pthread_t *thread NNN,
+                             const pthread_attr_t *attr NNN,
+                             void *(*start_routine)(void*) NNN, void *arg NNN)
 {
   return pthread_create(thread, attr, start_routine, arg);
 }
 
 static PSI_thread*
-new_thread_noop(PSI_thread_key key, const void *identity, ulong thread_id)
+new_thread_noop(PSI_thread_key key NNN,
+                const void *identity NNN, ulong thread_id NNN)
 {
   return NULL;
 }
 
-static void set_thread_id_noop(PSI_thread *thread, unsigned long id)
+static void set_thread_id_noop(PSI_thread *thread NNN, unsigned long id NNN)
 {
   return;
 }
 
 static PSI_thread*
-get_thread_noop(void)
+get_thread_noop(void NNN)
 {
   return NULL;
 }
 
-static void set_thread_user_noop(const char *user, int user_len)
+static void set_thread_user_noop(const char *user NNN, int user_len NNN)
 {
   return;
 }
 
-static void set_thread_user_host_noop(const char *user, int user_len,
-                                    const char *host, int host_len)
+static void set_thread_user_host_noop(const char *user NNN, int user_len NNN,
+                                      const char *host NNN, int host_len NNN)
 {
   return;
 }
 
-static void set_thread_db_noop(const char* db, int db_len)
+static void set_thread_db_noop(const char* db NNN, int db_len NNN)
 {
   return;
 }
 
-static void set_thread_command_noop(int command)
+static void set_thread_command_noop(int command NNN)
 {
   return;
 }
 
-static void set_thread_start_time_noop(time_t start_time)
+static void set_thread_start_time_noop(time_t start_time NNN)
 {
   return;
 }
 
-static void set_thread_state_noop(const char* state)
+static void set_thread_state_noop(const char* state NNN)
 {
   return;
 }
 
-static void set_thread_info_noop(const char* info, int info_len)
+static void set_thread_info_noop(const char* info NNN, int info_len NNN)
 {
   return;
 }
 
-static void set_thread_noop(PSI_thread* thread)
+static void set_thread_noop(PSI_thread* thread NNN)
 {
   return;
 }
@@ -241,210 +263,224 @@ static void delete_current_thread_noop(v
   return;
 }
 
-static void delete_thread_noop(PSI_thread *thread)
+static void delete_thread_noop(PSI_thread *thread NNN)
 {
   return;
 }
 
 static PSI_mutex_locker*
-get_thread_mutex_locker_noop(PSI_mutex_locker_state *state,
-                             PSI_mutex *mutex, PSI_mutex_operation op)
+get_thread_mutex_locker_noop(PSI_mutex_locker_state *state NNN,
+                             PSI_mutex *mutex NNN,
+                             enum PSI_mutex_operation op NNN)
 {
   return NULL;
 }
 
 static PSI_rwlock_locker*
-get_thread_rwlock_locker_noop(PSI_rwlock_locker_state *state,
-                              PSI_rwlock *rwlock, PSI_rwlock_operation op)
+get_thread_rwlock_locker_noop(PSI_rwlock_locker_state *state NNN,
+                              PSI_rwlock *rwlock NNN,
+                              enum PSI_rwlock_operation op NNN)
 {
   return NULL;
 }
 
 static PSI_cond_locker*
-get_thread_cond_locker_noop(PSI_cond_locker_state *state,
-                            PSI_cond *cond, PSI_mutex *mutex,
-                            PSI_cond_operation op)
+get_thread_cond_locker_noop(PSI_cond_locker_state *state NNN,
+                            PSI_cond *cond NNN, PSI_mutex *mutex NNN,
+                            enum PSI_cond_operation op NNN)
 {
   return NULL;
 }
 
 static PSI_table_locker*
-get_thread_table_io_locker_noop(PSI_table_locker_state *state,
-                                PSI_table *table, PSI_table_io_operation op, uint index)
+get_thread_table_io_locker_noop(PSI_table_locker_state *state NNN,
+                                PSI_table *table NNN,
+                                enum PSI_table_io_operation op NNN,
+                                uint index NNN)
 {
   return NULL;
 }
 
 static PSI_table_locker*
-get_thread_table_lock_locker_noop(PSI_table_locker_state *state,
-                                  PSI_table *table, PSI_table_lock_operation op, ulong op_flags)
+get_thread_table_lock_locker_noop(PSI_table_locker_state *state NNN,
+                                  PSI_table *table NNN,
+                                  enum PSI_table_lock_operation op NNN,
+                                  ulong op_flags NNN)
 {
   return NULL;
 }
 
 static PSI_file_locker*
-get_thread_file_name_locker_noop(PSI_file_locker_state *state,
-                                 PSI_file_key key,
-                                 PSI_file_operation op,
-                                 const char *name, const void *identity)
+get_thread_file_name_locker_noop(PSI_file_locker_state *state NNN,
+                                 PSI_file_key key NNN,
+                                 enum PSI_file_operation op NNN,
+                                 const char *name NNN, const void *identity NNN)
 {
   return NULL;
 }
 
 static PSI_file_locker*
-get_thread_file_stream_locker_noop(PSI_file_locker_state *state,
-                                   PSI_file *file, PSI_file_operation op)
+get_thread_file_stream_locker_noop(PSI_file_locker_state *state NNN,
+                                   PSI_file *file NNN,
+                                   enum PSI_file_operation op NNN)
 {
   return NULL;
 }
 
 
 static PSI_file_locker*
-get_thread_file_descriptor_locker_noop(PSI_file_locker_state *state,
-                                       File file, PSI_file_operation op)
+get_thread_file_descriptor_locker_noop(PSI_file_locker_state *state NNN,
+                                       File file NNN,
+                                       enum PSI_file_operation op NNN)
 {
   return NULL;
 }
 
 static PSI_socket_locker*
-get_thread_socket_locker_noop(PSI_socket_locker_state *state,
-                              PSI_socket *socket, PSI_socket_operation op)
+get_thread_socket_locker_noop(PSI_socket_locker_state *state NNN,
+                              PSI_socket *socket NNN,
+                              enum PSI_socket_operation op NNN)
 {
   return NULL;
 }
 
-static void unlock_mutex_noop(PSI_mutex *mutex)
+static void unlock_mutex_noop(PSI_mutex *mutex NNN)
 {
   return;
 }
 
-static void unlock_rwlock_noop(PSI_rwlock *rwlock)
+static void unlock_rwlock_noop(PSI_rwlock *rwlock NNN)
 {
   return;
 }
 
-static void signal_cond_noop(PSI_cond* cond)
+static void signal_cond_noop(PSI_cond* cond NNN)
 {
   return;
 }
 
-static void broadcast_cond_noop(PSI_cond* cond)
+static void broadcast_cond_noop(PSI_cond* cond NNN)
 {
   return;
 }
 
 static PSI_idle_locker*
-start_idle_wait_noop(PSI_idle_locker_state* state,
-                     const char *src_file, uint src_line)
+start_idle_wait_noop(PSI_idle_locker_state* state NNN,
+                     const char *src_file NNN, uint src_line NNN)
 {
   return NULL;
 }
 
-static void end_idle_wait_noop(PSI_idle_locker* locker)
+static void end_idle_wait_noop(PSI_idle_locker* locker NNN)
 {
   return;
 }
 
-static void start_mutex_wait_noop(PSI_mutex_locker* locker,
-                                  const char *src_file, uint src_line)
+static void start_mutex_wait_noop(PSI_mutex_locker* locker NNN,
+                                  const char *src_file NNN, uint src_line NNN)
 {
   return;
 }
 
-static void end_mutex_wait_noop(PSI_mutex_locker* locker, int rc)
+static void end_mutex_wait_noop(PSI_mutex_locker* locker NNN, int rc NNN)
 {
   return;
 }
 
 
-static void start_rwlock_rdwait_noop(PSI_rwlock_locker* locker,
-                                     const char *src_file, uint src_line)
+static void start_rwlock_rdwait_noop(PSI_rwlock_locker* locker NNN,
+                                     const char *src_file NNN,
+                                     uint src_line NNN)
 {
   return;
 }
 
-static void end_rwlock_rdwait_noop(PSI_rwlock_locker* locker, int rc)
+static void end_rwlock_rdwait_noop(PSI_rwlock_locker* locker NNN, int rc NNN)
 {
   return;
 }
 
-static void start_rwlock_wrwait_noop(PSI_rwlock_locker* locker,
-                                     const char *src_file, uint src_line)
+static void start_rwlock_wrwait_noop(PSI_rwlock_locker* locker NNN,
+                                     const char *src_file NNN,
+                                     uint src_line NNN)
 {
   return;
 }
 
-static void end_rwlock_wrwait_noop(PSI_rwlock_locker* locker, int rc)
+static void end_rwlock_wrwait_noop(PSI_rwlock_locker* locker NNN, int rc NNN)
 {
   return;
 }
 
-static void start_cond_wait_noop(PSI_cond_locker* locker,
-                                 const char *src_file, uint src_line)
+static void start_cond_wait_noop(PSI_cond_locker* locker NNN,
+                                 const char *src_file NNN, uint src_line NNN)
 {
   return;
 }
 
-static void end_cond_wait_noop(PSI_cond_locker* locker, int rc)
+static void end_cond_wait_noop(PSI_cond_locker* locker NNN, int rc NNN)
 {
   return;
 }
 
-static void start_table_io_wait_noop(PSI_table_locker* locker,
-                                     const char *src_file, uint src_line)
+static void start_table_io_wait_noop(PSI_table_locker* locker NNN,
+                                     const char *src_file NNN,
+                                     uint src_line NNN)
 {
   return;
 }
 
-static void end_table_io_wait_noop(PSI_table_locker* locker)
+static void end_table_io_wait_noop(PSI_table_locker* locker NNN)
 {
   return;
 }
 
-static void start_table_lock_wait_noop(PSI_table_locker* locker,
-                                       const char *src_file, uint src_line)
+static void start_table_lock_wait_noop(PSI_table_locker* locker NNN,
+                                       const char *src_file NNN,
+                                       uint src_line NNN)
 {
   return;
 }
 
-static void end_table_lock_wait_noop(PSI_table_locker* locker)
+static void end_table_lock_wait_noop(PSI_table_locker* locker NNN)
 {
   return;
 }
 
-static PSI_file* start_file_open_wait_noop(PSI_file_locker *locker,
-                                           const char *src_file,
-                                           uint src_line)
+static PSI_file* start_file_open_wait_noop(PSI_file_locker *locker NNN,
+                                           const char *src_file NNN,
+                                           uint src_line NNN)
 {
   return NULL;
 }
 
-static void end_file_open_wait_noop(PSI_file_locker *locker)
+static void end_file_open_wait_noop(PSI_file_locker *locker NNN)
 {
   return;
 }
 
 static void end_file_open_wait_and_bind_to_descriptor_noop
-  (PSI_file_locker *locker, File file)
+  (PSI_file_locker *locker NNN, File file NNN)
 {
   return;
 }
 
-static void start_file_wait_noop(PSI_file_locker *locker,
-                                 size_t count,
-                                 const char *src_file,
-                                 uint src_line)
+static void start_file_wait_noop(PSI_file_locker *locker NNN,
+                                 size_t count NNN,
+                                 const char *src_file NNN,
+                                 uint src_line NNN)
 {
   return;
 }
 
-static void end_file_wait_noop(PSI_file_locker *locker,
-                               size_t count)
+static void end_file_wait_noop(PSI_file_locker *locker NNN,
+                               size_t count NNN)
 {
   return;
 }
 
-static void start_stage_noop(PSI_stage_key key, const char *src_file, int src_line)
+static void start_stage_noop(PSI_stage_key key NNN,
+                             const char *src_file NNN, int src_line NNN)
 {
   return;
 }
@@ -455,158 +491,161 @@ static void end_stage_noop()
 }
 
 static PSI_statement_locker*
-get_thread_statement_locker_noop(PSI_statement_locker_state *state,
-                                 PSI_statement_key key)
+get_thread_statement_locker_noop(PSI_statement_locker_state *state NNN,
+                                 PSI_statement_key key NNN)
 {
   return NULL;
 }
 
 static PSI_statement_locker*
-refine_statement_noop(PSI_statement_locker *locker,
-                      PSI_statement_key key)
+refine_statement_noop(PSI_statement_locker *locker NNN,
+                      PSI_statement_key key NNN)
 {
   return NULL;
 }
 
-static void start_statement_noop(PSI_statement_locker *locker,
-                                 const char *db, uint db_len,
-                                 const char *src_file, uint src_line)
+static void start_statement_noop(PSI_statement_locker *locker NNN,
+                                 const char *db NNN, uint db_len NNN,
+                                 const char *src_file NNN, uint src_line NNN)
 {
   return;
 }
 
-static void set_statement_text_noop(PSI_statement_locker *locker,
-                                    const char *text, uint text_len)
+static void set_statement_text_noop(PSI_statement_locker *locker NNN,
+                                    const char *text NNN, uint text_len NNN)
 {
   return;
 }
 
-static void set_statement_lock_time_noop(PSI_statement_locker *locker,
-                                         ulonglong count)
+static void set_statement_lock_time_noop(PSI_statement_locker *locker NNN,
+                                         ulonglong count NNN)
 {
   return;
 }
 
-static void set_statement_rows_sent_noop(PSI_statement_locker *locker,
-                                         ulonglong count)
+static void set_statement_rows_sent_noop(PSI_statement_locker *locker NNN,
+                                         ulonglong count NNN)
 {
   return;
 }
 
-static void set_statement_rows_examined_noop(PSI_statement_locker *locker,
-                                             ulonglong count)
+static void set_statement_rows_examined_noop(PSI_statement_locker *locker NNN,
+                                             ulonglong count NNN)
 {
   return;
 }
 
-static void inc_statement_created_tmp_disk_tables_noop(PSI_statement_locker *locker,
-                                                       ulong count)
+static void inc_statement_created_tmp_disk_tables_noop(PSI_statement_locker *locker NNN,
+                                                       ulong count NNN)
 {
   return;
 }
 
-static void inc_statement_created_tmp_tables_noop(PSI_statement_locker *locker,
-                                                  ulong count)
+static void inc_statement_created_tmp_tables_noop(PSI_statement_locker *locker NNN,
+                                                  ulong count NNN)
 {
   return;
 }
 
-static void inc_statement_select_full_join_noop(PSI_statement_locker *locker,
-                                                ulong count)
+static void inc_statement_select_full_join_noop(PSI_statement_locker *locker NNN,
+                                                ulong count NNN)
 {
   return;
 }
 
-static void inc_statement_select_full_range_join_noop(PSI_statement_locker *locker,
-                                                      ulong count)
+static void inc_statement_select_full_range_join_noop(PSI_statement_locker *locker NNN,
+                                                      ulong count NNN)
 {
   return;
 }
 
-static void inc_statement_select_range_noop(PSI_statement_locker *locker,
-                                            ulong count)
+static void inc_statement_select_range_noop(PSI_statement_locker *locker NNN,
+                                            ulong count NNN)
 {
   return;
 }
 
-static void inc_statement_select_range_check_noop(PSI_statement_locker *locker,
-                                                  ulong count)
+static void inc_statement_select_range_check_noop(PSI_statement_locker *locker NNN,
+                                                  ulong count NNN)
 {
   return;
 }
 
-static void inc_statement_select_scan_noop(PSI_statement_locker *locker,
-                                           ulong count)
+static void inc_statement_select_scan_noop(PSI_statement_locker *locker NNN,
+                                           ulong count NNN)
 {
   return;
 }
 
-static void inc_statement_sort_merge_passes_noop(PSI_statement_locker *locker,
-                                                 ulong count)
+static void inc_statement_sort_merge_passes_noop(PSI_statement_locker *locker NNN,
+                                                 ulong count NNN)
 {
   return;
 }
 
-static void inc_statement_sort_range_noop(PSI_statement_locker *locker,
-                                          ulong count)
+static void inc_statement_sort_range_noop(PSI_statement_locker *locker NNN,
+                                          ulong count NNN)
 {
   return;
 }
 
-static void inc_statement_sort_rows_noop(PSI_statement_locker *locker,
-                                         ulong count)
+static void inc_statement_sort_rows_noop(PSI_statement_locker *locker NNN,
+                                         ulong count NNN)
 {
   return;
 }
 
-static void inc_statement_sort_scan_noop(PSI_statement_locker *locker,
-                                         ulong count)
+static void inc_statement_sort_scan_noop(PSI_statement_locker *locker NNN,
+                                         ulong count NNN)
 {
   return;
 }
 
-static void set_statement_no_index_used_noop(PSI_statement_locker *locker)
+static void set_statement_no_index_used_noop(PSI_statement_locker *locker NNN)
 {
   return;
 }
 
-static void set_statement_no_good_index_used_noop(PSI_statement_locker *locker)
+static void set_statement_no_good_index_used_noop(PSI_statement_locker *locker NNN)
 {
   return;
 }
 
-static void end_statement_noop(PSI_statement_locker *locker, void *stmt_da)
+static void end_statement_noop(PSI_statement_locker *locker NNN,
+                               void *stmt_da NNN)
 {
   return;
 }
 
-static void start_socket_wait_noop(PSI_socket_locker *locker,
-                                   size_t count,
-                                   const char *src_socket,
-                                   uint src_line)
+static void start_socket_wait_noop(PSI_socket_locker *locker NNN,
+                                   size_t count NNN,
+                                   const char *src_socket NNN,
+                                   uint src_line NNN)
 {
   return;
 }
 
-static void end_socket_wait_noop(PSI_socket_locker *locker, size_t count)
+static void end_socket_wait_noop(PSI_socket_locker *locker NNN,
+                                 size_t count NNN)
 {
   return;
 }
 
-static void set_socket_state_noop(PSI_socket *socket, PSI_socket_state state)
+static void set_socket_state_noop(PSI_socket *socket NNN,
+                                  enum PSI_socket_state state NNN)
 {
   return;
 }
 
-static void set_socket_info_noop(PSI_socket *socket,
-                                 const my_socket *fd,
-                                 const struct sockaddr *addr,
-                                 socklen_t addr_len)
+static void set_socket_info_noop(PSI_socket *socket NNN,
+                                 const my_socket *fd NNN,
+                                 const struct sockaddr *addr NNN,
+                                 socklen_t addr_len NNN)
 {
   return;
 }
 
-static void set_socket_thread_owner_noop(PSI_socket *socket)
+static void set_socket_thread_owner_noop(PSI_socket *socket NNN)
 {
   return;
 }

=== modified file 'mysys/stacktrace.c'
--- a/mysys/stacktrace.c	2011-06-30 15:46:53 +0000
+++ b/mysys/stacktrace.c	2011-08-29 12:08:58 +0000
@@ -93,7 +93,7 @@ static int safe_print_str(const char *ad
   /* Read up to the maximum number of bytes. */
   while (total)
   {
-    count= min(sizeof(buf), total);
+    count= MY_MIN(sizeof(buf), total);
 
     if ((nbytes= pread(fd, buf, count, offset)) < 0)
     {
@@ -321,7 +321,7 @@ void my_print_stacktrace(uchar* stack_bo
 
   if (!stack_bottom || (uchar*) stack_bottom > (uchar*) &fp)
   {
-    ulong tmp= min(0x10000,thread_stack);
+    ulong tmp= MY_MIN(0x10000, thread_stack);
     /* Assume that the stack starts at the previous even 65K */
     stack_bottom= (uchar*) (((ulong) &fp + tmp) &
 			  ~(ulong) 0xFFFF);

=== modified file 'mysys/waiting_threads.c'
--- a/mysys/waiting_threads.c	2011-06-30 15:50:45 +0000
+++ b/mysys/waiting_threads.c	2011-10-11 04:27:52 +0000
@@ -356,7 +356,7 @@ struct st_wt_resource {
   uint            waiter_count;
   enum { ACTIVE, FREE } state;
 #ifndef DBUG_OFF
-  pthread_mutex_t  *cond_mutex; /* a mutex for the 'cond' below */
+  mysql_mutex_t  *cond_mutex; /* a mutex for the 'cond' below */
 #endif
   /*
     before the 'lock' all elements are mutable, after (and including) -
@@ -395,8 +395,8 @@ struct st_wt_resource {
     the contention is expected to be low.
   */
   struct {
-    pthread_cond_t   cond;
-    pthread_mutex_t  mutex;
+    mysql_cond_t   cond;
+    mysql_mutex_t  mutex;
     uint readers: 16;
     uint pending_writers: 15;
     uint write_locked: 1;
@@ -404,55 +404,55 @@ struct st_wt_resource {
 #else
   rw_lock_t lock;
 #endif
-  pthread_cond_t   cond; /* the corresponding mutex is provided by the caller */
+  mysql_cond_t     cond; /* the corresponding mutex is provided by the caller */
   DYNAMIC_ARRAY    owners;
 };
 
 #ifdef  WT_RWLOCKS_USE_MUTEXES
 static void rc_rwlock_init(WT_RESOURCE *rc)
 {
-  pthread_cond_init(&rc->lock.cond, 0);
-  pthread_mutex_init(&rc->lock.mutex, MY_MUTEX_INIT_FAST);
+  mysql_cond_init(0, &rc->lock.cond, 0);
+  mysql_mutex_init(0, &rc->lock.mutex, MY_MUTEX_INIT_FAST);
 }
 static void rc_rwlock_destroy(WT_RESOURCE *rc)
 {
   DBUG_ASSERT(rc->lock.write_locked == 0);
   DBUG_ASSERT(rc->lock.readers == 0);
-  pthread_cond_destroy(&rc->lock.cond);
-  pthread_mutex_destroy(&rc->lock.mutex);
+  mysql_cond_destroy(&rc->lock.cond);
+  mysql_mutex_destroy(&rc->lock.mutex);
 }
 static void rc_rdlock(WT_RESOURCE *rc)
 {
   DBUG_PRINT("wt", ("TRYLOCK resid=%ld for READ", (ulong)rc->id.value));
-  pthread_mutex_lock(&rc->lock.mutex);
+  mysql_mutex_lock(&rc->lock.mutex);
   while (rc->lock.write_locked)
-    pthread_cond_wait(&rc->lock.cond, &rc->lock.mutex);
+    mysql_cond_wait(&rc->lock.cond, &rc->lock.mutex);
   rc->lock.readers++;
-  pthread_mutex_unlock(&rc->lock.mutex);
+  mysql_mutex_unlock(&rc->lock.mutex);
   DBUG_PRINT("wt", ("LOCK resid=%ld for READ", (ulong)rc->id.value));
 }
 static void rc_wrlock(WT_RESOURCE *rc)
 {
   DBUG_PRINT("wt", ("TRYLOCK resid=%ld for WRITE", (ulong)rc->id.value));
-  pthread_mutex_lock(&rc->lock.mutex);
+  mysql_mutex_lock(&rc->lock.mutex);
   while (rc->lock.write_locked || rc->lock.readers)
-    pthread_cond_wait(&rc->lock.cond, &rc->lock.mutex);
+    mysql_cond_wait(&rc->lock.cond, &rc->lock.mutex);
   rc->lock.write_locked= 1;
-  pthread_mutex_unlock(&rc->lock.mutex);
+  mysql_mutex_unlock(&rc->lock.mutex);
   DBUG_PRINT("wt", ("LOCK resid=%ld for WRITE", (ulong)rc->id.value));
 }
 static void rc_unlock(WT_RESOURCE *rc)
 {
   DBUG_PRINT("wt", ("UNLOCK resid=%ld", (ulong)rc->id.value));
-  pthread_mutex_lock(&rc->lock.mutex);
+  mysql_mutex_lock(&rc->lock.mutex);
   if (rc->lock.write_locked)
   {
     rc->lock.write_locked= 0;
-    pthread_cond_broadcast(&rc->lock.cond);
+    mysql_cond_broadcast(&rc->lock.cond);
   }
   else if (--rc->lock.readers == 0)
-    pthread_cond_broadcast(&rc->lock.cond);
-  pthread_mutex_unlock(&rc->lock.mutex);
+    mysql_cond_broadcast(&rc->lock.cond);
+  mysql_mutex_unlock(&rc->lock.mutex);
 }
 #else
 static void rc_rwlock_init(WT_RESOURCE *rc)
@@ -501,7 +501,7 @@ static void wt_resource_init(uchar *arg)
 
   memset(rc, 0, sizeof(*rc));
   rc_rwlock_init(rc);
-  pthread_cond_init(&rc->cond, 0);
+  mysql_cond_init(0, &rc->cond, 0);
   my_init_dynamic_array(&rc->owners, sizeof(WT_THD *), 0, 5);
   DBUG_VOID_RETURN;
 }
@@ -519,7 +519,7 @@ static void wt_resource_destroy(uchar *a
 
   DBUG_ASSERT(rc->owners.elements == 0);
   rc_rwlock_destroy(rc);
-  pthread_cond_destroy(&rc->cond);
+  mysql_cond_destroy(&rc->cond);
   delete_dynamic(&rc->owners);
   DBUG_VOID_RETURN;
 }
@@ -898,7 +898,7 @@ static int deadlock(WT_THD *thd, WT_THD
   {
     DBUG_PRINT("wt", ("killing %s", arg.victim->name));
     arg.victim->killed= 1;
-    pthread_cond_broadcast(&arg.victim->waiting_for->cond);
+    mysql_cond_broadcast(&arg.victim->waiting_for->cond);
     rc_unlock(arg.victim->waiting_for);
     ret= WT_OK;
   }
@@ -1136,7 +1136,7 @@ retry:
 
   @return one of WT_TIMEOUT, WT_DEADLOCK, WT_OK
 */
-int wt_thd_cond_timedwait(WT_THD *thd, pthread_mutex_t *mutex)
+int wt_thd_cond_timedwait(WT_THD *thd, mysql_mutex_t *mutex)
 {
   int ret= WT_TIMEOUT;
   struct timespec timeout;
@@ -1150,7 +1150,7 @@ int wt_thd_cond_timedwait(WT_THD *thd, p
     DBUG_ASSERT(rc->cond_mutex == mutex);
   else
     rc->cond_mutex= mutex;
-  safe_mutex_assert_owner(mutex);
+  mysql_mutex_assert_owner(mutex);
 #endif
 
   before= starttime= my_getsystime();
@@ -1177,7 +1177,7 @@ int wt_thd_cond_timedwait(WT_THD *thd, p
 
   set_timespec_time_nsec(timeout, starttime, (*thd->timeout_short)*1000ULL);
   if (ret == WT_TIMEOUT && !thd->killed)
-    ret= pthread_cond_timedwait(&rc->cond, mutex, &timeout);
+    ret= mysql_cond_timedwait(&rc->cond, mutex, &timeout);
   if (ret == WT_TIMEOUT && !thd->killed)
   {
     int r= deadlock(thd, thd, 0, *thd->deadlock_search_depth_long);
@@ -1189,7 +1189,7 @@ int wt_thd_cond_timedwait(WT_THD *thd, p
     {
       set_timespec_time_nsec(timeout, starttime, (*thd->timeout_long)*1000ULL);
       if (!thd->killed)
-        ret= pthread_cond_timedwait(&rc->cond, mutex, &timeout);
+        ret= mysql_cond_timedwait(&rc->cond, mutex, &timeout);
     }
   }
   after= my_getsystime();
@@ -1235,10 +1235,10 @@ void wt_thd_release(WT_THD *thd, const W
       delete_dynamic_element(&rc->owners, j);
       if (rc->owners.elements == 0)
       {
-        pthread_cond_broadcast(&rc->cond);
+        mysql_cond_broadcast(&rc->cond);
 #ifndef DBUG_OFF
         if (rc->cond_mutex)
-          safe_mutex_assert_owner(rc->cond_mutex);
+          mysql_mutex_assert_owner(rc->cond_mutex);
 #endif
       }
       unlock_lock_and_free_resource(thd, rc);

=== modified file 'sql-common/client.c'
--- a/sql-common/client.c	2011-08-19 15:18:57 +0000
+++ b/sql-common/client.c	2011-08-29 12:08:58 +0000
@@ -644,7 +644,7 @@ cli_safe_read(MYSQL *mysql)
       }
 
       (void) strmake(net->last_error,(char*) pos,
-		     min((uint) len,(uint) sizeof(net->last_error)-1));
+		     MY_MIN((uint) len,(uint) sizeof(net->last_error)-1));
     }
     else
       set_mysql_error(mysql, CR_UNKNOWN_ERROR, unknown_sqlstate);

=== modified file 'sql-common/client_plugin.c'
--- a/sql-common/client_plugin.c	2011-06-30 15:50:45 +0000
+++ b/sql-common/client_plugin.c	2011-10-11 04:27:52 +0000
@@ -63,7 +63,7 @@ static uint plugin_version[MYSQL_CLIENT_
   loading the same plugin twice in parallel.
 */
 struct st_client_plugin_int *plugin_list[MYSQL_CLIENT_MAX_PLUGINS];
-static pthread_mutex_t LOCK_load_client_plugin;
+static mysql_mutex_t LOCK_load_client_plugin;
 
 static int is_not_initialized(MYSQL *mysql, const char *name)
 {
@@ -159,7 +159,7 @@ add_plugin(MYSQL *mysql, struct st_mysql
     goto err2;
   }
 
-  safe_mutex_assert_owner(&LOCK_load_client_plugin);
+  mysql_mutex_assert_owner(&LOCK_load_client_plugin);
 
   p->next= plugin_list[plugin->type];
   plugin_list[plugin->type]= p;
@@ -234,19 +234,19 @@ int mysql_client_plugin_init()
 
   memset(&mysql, 0, sizeof(mysql)); /* dummy mysql for set_mysql_extended_error */
 
-  pthread_mutex_init(&LOCK_load_client_plugin, MY_MUTEX_INIT_SLOW);
+  mysql_mutex_init(0, &LOCK_load_client_plugin, MY_MUTEX_INIT_SLOW);
   init_alloc_root(&mem_root, 128, 128);
 
   memset(&plugin_list, 0, sizeof(plugin_list));
 
   initialized= 1;
 
-  pthread_mutex_lock(&LOCK_load_client_plugin);
+  mysql_mutex_lock(&LOCK_load_client_plugin);
 
   for (builtin= mysql_client_builtins; *builtin; builtin++)
     add_plugin(&mysql, *builtin, 0, 0, 0);
 
-  pthread_mutex_unlock(&LOCK_load_client_plugin);
+  mysql_mutex_unlock(&LOCK_load_client_plugin);
 
   load_env_plugins(&mysql);
 
@@ -278,7 +278,7 @@ void mysql_client_plugin_deinit()
   memset(&plugin_list, 0, sizeof(plugin_list));
   initialized= 0;
   free_root(&mem_root, MYF(0));
-  pthread_mutex_destroy(&LOCK_load_client_plugin);
+  mysql_mutex_destroy(&LOCK_load_client_plugin);
 }
 
 /************* public facing functions, for client consumption *********/
@@ -291,7 +291,7 @@ mysql_client_register_plugin(MYSQL *mysq
   if (is_not_initialized(mysql, plugin->name))
     return NULL;
 
-  pthread_mutex_lock(&LOCK_load_client_plugin);
+  mysql_mutex_lock(&LOCK_load_client_plugin);
 
   /* make sure the plugin wasn't loaded meanwhile */
   if (find_plugin(plugin->name, plugin->type))
@@ -304,7 +304,7 @@ mysql_client_register_plugin(MYSQL *mysq
   else
     plugin= add_plugin(mysql, plugin, 0, 0, 0);
 
-  pthread_mutex_unlock(&LOCK_load_client_plugin);
+  mysql_mutex_unlock(&LOCK_load_client_plugin);
   return plugin;
 }
 
@@ -329,7 +329,7 @@ mysql_load_plugin_v(MYSQL *mysql, const
     DBUG_RETURN (NULL);
   }
 
-  pthread_mutex_lock(&LOCK_load_client_plugin);
+  mysql_mutex_lock(&LOCK_load_client_plugin);
 
   /* make sure the plugin wasn't loaded meanwhile */
   if (type >= 0 && find_plugin(name, type))
@@ -403,13 +403,13 @@ have_plugin:
 
   plugin= add_plugin(mysql, plugin, dlhandle, argc, args);
 
-  pthread_mutex_unlock(&LOCK_load_client_plugin);
+  mysql_mutex_unlock(&LOCK_load_client_plugin);
 
   DBUG_PRINT ("leave", ("plugin loaded ok"));
   DBUG_RETURN (plugin);
 
 err:
-  pthread_mutex_unlock(&LOCK_load_client_plugin);
+  mysql_mutex_unlock(&LOCK_load_client_plugin);
   DBUG_PRINT ("leave", ("plugin load error : %s", errmsg));
   set_mysql_extended_error(mysql, CR_AUTH_PLUGIN_CANNOT_LOAD, unknown_sqlstate,
                            ER(CR_AUTH_PLUGIN_CANNOT_LOAD), name, errmsg);

=== modified file 'sql-common/my_time.c'
--- a/sql-common/my_time.c	2011-11-01 13:54:56 +0000
+++ b/sql-common/my_time.c	2011-11-03 16:03:34 +0000
@@ -249,7 +249,7 @@ str_to_datetime(const char *str, uint le
     2003-03-03 20:00:20 AM
     20:00:20.000000 AM 03-03-2000
   */
-  i= max((uint) format_position[0], (uint) format_position[1]);
+  i= MY_MAX((uint) format_position[0], (uint) format_position[1]);
   set_if_bigger(i, (uint) format_position[2]);
   allow_space= ((1 << i) | (1 << format_position[6]));
   allow_space&= (1 | 2 | 4 | 8);

=== modified file 'sql/CMakeLists.txt'
--- a/sql/CMakeLists.txt	2011-10-13 12:33:08 +0000
+++ b/sql/CMakeLists.txt	2011-10-28 12:45:35 +0000
@@ -294,6 +294,7 @@ IF(WITH_MYSQLD_LDFLAGS)
   SET_TARGET_PROPERTIES(mysqld PROPERTIES LINK_FLAGS 
      "${MYSQLD_LINK_FLAGS} ${WITH_MYSQLD_LDFLAGS}")
 ENDIF()
+
 IF(DEBUG_EXTNAME)
   INSTALL_DEBUG_TARGET(mysqld 
     DESTINATION ${INSTALL_SBINDIR} 
@@ -350,7 +351,7 @@ ADD_CUSTOM_TARGET(
 SET_TARGET_PROPERTIES(GenServerSource PROPERTIES EXCLUDE_FROM_ALL TRUE)
 
 IF(WIN32 OR HAVE_DLOPEN AND NOT DISABLE_SHARED)
-  ADD_LIBRARY(udf_example MODULE udf_example.c)
+  ADD_LIBRARY(udf_example MODULE udf_example.cc)
   SET_TARGET_PROPERTIES(udf_example PROPERTIES PREFIX "")
   # udf_example depends on strings 
   IF(WIN32)

=== modified file 'sql/binlog.cc'
--- a/sql/binlog.cc	2011-10-27 19:28:15 +0000
+++ b/sql/binlog.cc	2011-11-03 16:03:34 +0000
@@ -25,6 +25,9 @@
 #include "rpl_info_factory.h"
 #include "debug_sync.h"
 
+using std::max;
+using std::min;
+
 #define MY_OFF_T_UNDEF (~(my_off_t)0UL)
 #define FLAGSTR(V,F) ((V)&(F)?#F" ":"")
 
@@ -1404,7 +1407,7 @@ bool show_binlog_events(THD *thd, MYSQL_
     LEX_MASTER_INFO *lex_mi= &thd->lex->mi;
     SELECT_LEX_UNIT *unit= &thd->lex->unit;
     ha_rows event_count, limit_start, limit_end;
-    my_off_t pos = max(BIN_LOG_HEADER_SIZE, lex_mi->pos); // user-friendly
+    my_off_t pos = max<my_off_t>(BIN_LOG_HEADER_SIZE, lex_mi->pos); // user-friendly
     char search_file_name[FN_REFLEN], *name;
     const char *log_file_name = lex_mi->log_file_name;
     mysql_mutex_t *log_lock = binary_log->get_log_lock();

=== modified file 'sql/debug_sync.cc'
--- a/sql/debug_sync.cc	2011-07-28 10:54:44 +0000
+++ b/sql/debug_sync.cc	2011-08-29 12:08:58 +0000
@@ -329,6 +329,9 @@
 #include "sql_priv.h"
 #include "sql_parse.h"
 
+using std::max;
+using std::min;
+
 /*
   Action to perform at a synchronization point.
   NOTE: This structure is moved around in memory by realloc(), qsort(),

=== modified file 'sql/field.cc'
--- a/sql/field.cc	2011-08-19 13:04:28 +0000
+++ b/sql/field.cc	2011-08-29 12:08:58 +0000
@@ -39,6 +39,9 @@
 #include <m_ctype.h>
 #include <errno.h>
 
+using std::max;
+using std::min;
+
 // Maximum allowed exponent value for converting string to decimal
 #define MAX_EXPONENT 1024
 
@@ -52,7 +55,7 @@ const char field_separator=',';
 #define LONGLONG_TO_STRING_CONVERSION_BUFFER_SIZE 128
 #define DECIMAL_TO_STRING_CONVERSION_BUFFER_SIZE 128
 #define BLOB_PACK_LENGTH_TO_MAX_LENGH(arg) \
-((ulong) ((LL(1) << min(arg, 4) * 8) - LL(1)))
+((ulong) ((LL(1) << MY_MIN(arg, 4) * 8) - LL(1)))
 
 #define ASSERT_COLUMN_MARKED_FOR_READ DBUG_ASSERT(!table || (!table->read_set || bitmap_is_set(table->read_set, field_index)))
 #define ASSERT_COLUMN_MARKED_FOR_WRITE DBUG_ASSERT(!table || (!table->write_set || bitmap_is_set(table->write_set, field_index)))
@@ -1056,7 +1059,7 @@ static void push_numerical_conversion_wa
                                               const char* field_name="UNKNOWN",
                                               ulong row_num=0)
 {
-    char buf[max(max(DOUBLE_TO_STRING_CONVERSION_BUFFER_SIZE,
+    char buf[MY_MAX(MY_MAX(DOUBLE_TO_STRING_CONVERSION_BUFFER_SIZE,
       LONGLONG_TO_STRING_CONVERSION_BUFFER_SIZE), 
       DECIMAL_TO_STRING_CONVERSION_BUFFER_SIZE)];
 
@@ -2517,7 +2520,7 @@ Field *Field_new_decimal::create_from_it
   {
     signed int overflow;
 
-    dec= min(dec, DECIMAL_MAX_SCALE);
+    dec= min<int>(dec, DECIMAL_MAX_SCALE);
 
     /*
       If the value still overflows the field with the corrected dec,
@@ -8722,7 +8725,7 @@ String *Field_bit::val_str(String *val_b
 {
   ASSERT_COLUMN_MARKED_FOR_READ;
   char buff[sizeof(longlong)];
-  uint length= min(pack_length(), sizeof(longlong));
+  uint length= min<uint>(pack_length(), sizeof(longlong));
   ulonglong bits= val_int();
   mi_int8store(buff,bits);
 
@@ -9498,7 +9501,7 @@ bool Create_field::init(THD *thd, char *
       DBUG_ASSERT(MAX_DATETIME_COMPRESSED_WIDTH < UINT_MAX);
       if (length != UINT_MAX)  /* avoid overflow; is safe because of min() */
         length= ((length+1)/2)*2;
-      length= min(length, MAX_DATETIME_COMPRESSED_WIDTH);
+      length= min<ulong>(length, MAX_DATETIME_COMPRESSED_WIDTH);
     }
     flags|= ZEROFILL_FLAG | UNSIGNED_FLAG;
     /*

=== modified file 'sql/field.h'
--- a/sql/field.h	2011-08-16 19:33:03 +0000
+++ b/sql/field.h	2011-10-11 04:27:52 +0000
@@ -81,7 +81,11 @@ public:
   static void *operator new(size_t size, MEM_ROOT *mem_root) throw () {
     return alloc_root(mem_root, size);
   }
-  static void operator delete(void *ptr_arg, size_t size) { TRASH(ptr_arg, size); }
+  static void operator delete(void *ptr, MEM_ROOT *mem_root)
+  { DBUG_ASSERT(false); /* never called */ }
+
+  static void operator delete(void *ptr_arg, size_t size) throw()
+  { TRASH(ptr_arg, size); }
 
   uchar		*ptr;			// Position to field in record
   /**

=== modified file 'sql/filesort.cc'
--- a/sql/filesort.cc	2011-10-13 13:22:45 +0000
+++ b/sql/filesort.cc	2011-10-28 12:45:35 +0000
@@ -37,6 +37,10 @@
 #include "debug_sync.h"
 #include "opt_trace.h"
 
+#include <algorithm>
+using std::max;
+using std::min;
+
 	/* functions defined in this file */
 
 static void make_char_array(FILESORT_INFO *info, uint fields, uint length);
@@ -272,11 +276,11 @@ ha_rows filesort(THD *thd, TABLE *table,
     DBUG_PRINT("info", ("filesort PQ is not applicable"));
 
     const ulong min_sort_memory=
-      max(MIN_SORT_MEMORY, param.sort_length*MERGEBUFF2);
+      max(MIN_SORT_MEMORY, param.sort_length * MERGEBUFF2);
     while (memory_available >= min_sort_memory)
     {
-      ulong keys= memory_available / (param.rec_length + sizeof(char*));
-      param.max_keys_per_buffer= (uint) min(num_rows, keys);
+      ha_rows keys= memory_available / (param.rec_length + sizeof(char*));
+      param.max_keys_per_buffer= static_cast<uint>(min(num_rows, keys));
       make_char_array(&table_sort, param.max_keys_per_buffer, param.rec_length);
       if (table_sort.sort_keys)
         break;

=== modified file 'sql/ha_partition.cc'
--- a/sql/ha_partition.cc	2011-10-07 08:30:01 +0000
+++ b/sql/ha_partition.cc	2011-10-13 07:26:28 +0000
@@ -62,6 +62,9 @@
 
 #include "debug_sync.h"
 
+using std::min;
+using std::max;
+
 #define PAR_FILE_ENGINE_OFFSET 12
 static const char *ha_par_ext= ".par";
 
@@ -6489,7 +6492,7 @@ const key_map *ha_partition::keys_to_use
   DBUG_RETURN(m_file[0]->keys_to_use_for_scanning());
 }
 
-#define MAX_PARTS_FOR_OPTIMIZER_CALLS 10
+#define MAX_PARTS_FOR_OPTIMIZER_CALLS 10U
 /*
   Prepare start variables for estimating optimizer costs.
 
@@ -6503,7 +6506,8 @@ void ha_partition::partitions_optimizer_
 {
   *first= bitmap_get_first_set(&(m_part_info->read_partitions));
   *num_used_parts= bitmap_bits_set(&(m_part_info->read_partitions));
-  *check_min_num= min(MAX_PARTS_FOR_OPTIMIZER_CALLS, *num_used_parts);
+  *check_min_num= min<uint>(MAX_PARTS_FOR_OPTIMIZER_CALLS,
+                            *num_used_parts);
 }
 
 

=== modified file 'sql/handler.cc'
--- a/sql/handler.cc	2011-10-21 14:59:52 +0000
+++ b/sql/handler.cc	2011-10-28 12:45:35 +0000
@@ -42,6 +42,9 @@
 #include "ha_partition.h"
 #endif
 
+using std::min;
+using std::max;
+
 // This is a temporary backporting fix.
 #ifndef HAVE_LOG2
 /*
@@ -5339,9 +5342,9 @@ bool DsMrr_impl::get_disk_sweep_mrr_cost
   else
   {
     cost->zero();
-    *buffer_size= max(*buffer_size, 
-                      (size_t)(1.2*rows_in_last_step) * elem_size + 
-                      h->ref_length + table->key_info[keynr].key_length);
+    *buffer_size= max<ulong>(*buffer_size,
+                             (size_t)(1.2*rows_in_last_step) * elem_size +
+                             h->ref_length + table->key_info[keynr].key_length);
   }
 
   COST_VECT last_step_cost;

=== modified file 'sql/handler.h'
--- a/sql/handler.h	2011-10-21 14:59:52 +0000
+++ b/sql/handler.h	2011-10-28 12:45:35 +0000
@@ -21,6 +21,8 @@
 
 /* Definitions for parameters to do with handler-routines */
 
+#include "my_pthread.h"
+#include <algorithm>
 #include "sql_const.h"
 #include "mysqld.h"                             /* server_id */
 #include "sql_plugin.h"        /* plugin_ref, st_plugin_int, plugin */
@@ -288,7 +290,7 @@
 #define HA_LEX_CREATE_TABLE_LIKE 4
 #define HA_OPTION_NO_CHECKSUM	(1L << 17)
 #define HA_OPTION_NO_DELAY_KEY_WRITE (1L << 18)
-#define HA_MAX_REC_LENGTH	65535
+#define HA_MAX_REC_LENGTH	65535U
 
 /* Table caching type */
 #define HA_CACHE_TBL_NONTRANSACT 0
@@ -1102,7 +1104,7 @@ public:
     if (io_count_sum != 0.0)
       avg_io_cost= (io_count * avg_io_cost + 
                     add_io_cnt * add_avg_cost) / io_count_sum;
-    DBUG_ASSERT(!isnan(avg_io_cost));
+    DBUG_ASSERT(!my_double_isnan(avg_io_cost));
     io_count= io_count_sum;
   }
 
@@ -1985,15 +1987,30 @@ public:
   { return (HA_ERR_WRONG_COMMAND); }
 
   uint max_record_length() const
-  { return min(HA_MAX_REC_LENGTH, max_supported_record_length()); }
+  {
+    using std::min;
+    return min(HA_MAX_REC_LENGTH, max_supported_record_length());
+  }
   uint max_keys() const
-  { return min(MAX_KEY, max_supported_keys()); }
+  {
+    using std::min;
+    return min(MAX_KEY, max_supported_keys());
+  }
   uint max_key_parts() const
-  { return min(MAX_REF_PARTS, max_supported_key_parts()); }
+  {
+    using std::min;
+    return min(MAX_REF_PARTS, max_supported_key_parts());
+  }
   uint max_key_length() const
-  { return min(MAX_KEY_LENGTH, max_supported_key_length()); }
+  {
+    using std::min;
+    return min(MAX_KEY_LENGTH, max_supported_key_length());
+  }
   uint max_key_part_length() const
-  { return min(MAX_KEY_LENGTH, max_supported_key_part_length()); }
+  {
+    using std::min;
+    return min(MAX_KEY_LENGTH, max_supported_key_part_length());
+  }
 
   virtual uint max_supported_record_length() const { return HA_MAX_REC_LENGTH; }
   virtual uint max_supported_keys() const { return 0; }

=== modified file 'sql/item.cc'
--- a/sql/item.cc	2011-10-13 12:33:08 +0000
+++ b/sql/item.cc	2011-10-28 12:45:35 +0000
@@ -40,6 +40,9 @@
 #include "log_event.h"                 // append_query_string
 #include "sql_test.h"                  // print_where
 
+using std::min;
+using std::max;
+
 const String my_null_string("NULL", 4, default_charset_info);
 
 /****************************************************************************/
@@ -88,8 +91,8 @@ void
 Hybrid_type_traits_decimal::fix_length_and_dec(Item *item, Item *arg) const
 {
   item->decimals= arg->decimals;
-  item->max_length= min(arg->max_length + DECIMAL_LONGLONG_DIGITS,
-                        DECIMAL_MAX_STR_LENGTH);
+  item->max_length= min<uint32>(arg->max_length + DECIMAL_LONGLONG_DIGITS,
+                                DECIMAL_MAX_STR_LENGTH);
 }
 
 
@@ -487,9 +490,9 @@ uint Item::decimal_precision() const
     uint prec= 
       my_decimal_length_to_precision(max_char_length(), decimals,
                                      unsigned_flag);
-    return min(prec, DECIMAL_MAX_PRECISION);
+    return min<uint>(prec, DECIMAL_MAX_PRECISION);
   }
-  return min(max_char_length(), DECIMAL_MAX_PRECISION);
+  return min<uint>(max_char_length(), DECIMAL_MAX_PRECISION);
 }
 
 
@@ -792,7 +795,7 @@ void Item::set_name(const char *str, uin
 				   &res_length);
   }
   else
-    name= sql_strmake(str, (name_length= min(length,MAX_ALIAS_NAME)));
+    name= sql_strmake(str, (name_length= min<size_t>(length, MAX_ALIAS_NAME)));
 }
 
 
@@ -5877,7 +5880,7 @@ longlong Item_hex_string::val_int()
   // following assert is redundant, because fixed=1 assigned in constructor
   DBUG_ASSERT(fixed == 1);
   char *end=(char*) str_value.ptr()+str_value.length(),
-       *ptr=end-min(str_value.length(),sizeof(longlong));
+       *ptr= end - min<size_t>(str_value.length(), sizeof(longlong));
 
   ulonglong value=0;
   for (; ptr != end ; ptr++)
@@ -5932,7 +5935,7 @@ warn:
 void Item_hex_string::print(String *str, enum_query_type query_type)
 {
   char *end= (char*) str_value.ptr() + str_value.length(),
-       *ptr= end - min(str_value.length(), sizeof(longlong));
+       *ptr= end - min<size_t>(str_value.length(), sizeof(longlong));
   str->append("0x");
   for (; ptr != end ; ptr++)
   {
@@ -8385,14 +8388,14 @@ bool Item_type_holder::join_types(THD *t
     /* fix variable decimals which always is NOT_FIXED_DEC */
     if (Field::result_merge_type(fld_type) == INT_RESULT)
       item_decimals= 0;
-    decimals= max(decimals, item_decimals);
+    decimals= max<int>(decimals, item_decimals);
   }
   if (Field::result_merge_type(fld_type) == DECIMAL_RESULT)
   {
-    decimals= min(max(decimals, item->decimals), DECIMAL_MAX_SCALE);
+    decimals= min<int>(max(decimals, item->decimals), DECIMAL_MAX_SCALE);
     int item_int_part= item->decimal_int_part();
     int item_prec = max(prev_decimal_int_part, item_int_part) + decimals;
-    int precision= min(item_prec, DECIMAL_MAX_PRECISION);
+    int precision= min<uint>(item_prec, DECIMAL_MAX_PRECISION);
     unsigned_flag&= item->unsigned_flag;
     max_length= my_decimal_precision_to_length_no_truncation(precision,
                                                              decimals,

=== modified file 'sql/item_buff.cc'
--- a/sql/item_buff.cc	2011-09-26 13:48:06 +0000
+++ b/sql/item_buff.cc	2011-10-13 07:26:28 +0000
@@ -30,6 +30,9 @@
 #include "sql_class.h"          // THD
 #include "set_var.h"            // Cached_item, Cached_item_field, ...
 
+using std::min;
+using std::max;
+
 /**
   Create right type of Cached_item for an item.
 */
@@ -71,7 +74,7 @@ Cached_item::~Cached_item() {}
 
 Cached_item_str::Cached_item_str(THD *thd, Item *arg)
   :item(arg),
-   value_max_length(min(arg->max_length, thd->variables.max_sort_length)),
+   value_max_length(min<uint32>(arg->max_length, thd->variables.max_sort_length)),
    value(value_max_length)
 {}
 

=== modified file 'sql/item_cmpfunc.cc'
--- a/sql/item_cmpfunc.cc	2011-10-27 07:03:49 +0000
+++ b/sql/item_cmpfunc.cc	2011-11-03 16:03:34 +0000
@@ -27,6 +27,10 @@
 #include "sql_parse.h"                          // check_stack_overrun
 #include "sql_time.h"                  // make_truncated_value_warning
 
+#include <algorithm>
+using std::min;
+using std::max;
+
 static bool convert_constant_item(THD *, Item_field *, Item **);
 static longlong
 get_year_value(THD *thd, Item ***item_arg, Item **cache_arg,
@@ -2610,7 +2614,7 @@ uint Item_func_ifnull::decimal_precision
   int arg1_int_part= args[1]->decimal_int_part();
   int max_int_part= max(arg0_int_part, arg1_int_part);
   int precision= max_int_part + decimals;
-  return min(precision, DECIMAL_MAX_PRECISION);
+  return min<uint>(precision, DECIMAL_MAX_PRECISION);
 }
 
 
@@ -2805,7 +2809,7 @@ uint Item_func_if::decimal_precision() c
   int arg1_prec= args[1]->decimal_int_part();
   int arg2_prec= args[2]->decimal_int_part();
   int precision=max(arg1_prec,arg2_prec) + decimals;
-  return min(precision, DECIMAL_MAX_PRECISION);
+  return min<uint>(precision, DECIMAL_MAX_PRECISION);
 }
 
 
@@ -3254,6 +3258,15 @@ void Item_func_case::fix_length_and_dec(
           return;
       }
     }
+    /*
+      Set cmp_context of all WHEN arguments. This prevents
+      Item_field::equal_fields_propagator() from transforming a
+      zerofill argument into a string constant. Such a change would
+      require rebuilding cmp_items.
+    */
+    for (i= 0; i < ncases; i+= 2)
+      args[i]->cmp_context= item_cmp_type(left_result_type,
+                                          args[i]->result_type());
   }
 
   if (else_expr_num == -1 || args[else_expr_num]->maybe_null)
@@ -3290,7 +3303,7 @@ uint Item_func_case::decimal_precision()
 
   if (else_expr_num != -1) 
     set_if_bigger(max_int_part, args[else_expr_num]->decimal_int_part());
-  return min(max_int_part + decimals, DECIMAL_MAX_PRECISION);
+  return min<uint>(max_int_part + decimals, DECIMAL_MAX_PRECISION);
 }
 
 
@@ -5348,8 +5361,8 @@ void Item_func_like::turboBM_compute_bad
 
 bool Item_func_like::turboBM_matches(const char* text, int text_len) const
 {
-  register int bcShift;
-  register int turboShift;
+  int bcShift;
+  int turboShift;
   int shift = pattern_len;
   int j     = 0;
   int u     = 0;
@@ -5363,7 +5376,7 @@ bool Item_func_like::turboBM_matches(con
   {
     while (j <= tlmpl)
     {
-      register int i= plm1;
+      int i= plm1;
       while (i >= 0 && pattern[i] == text[i + j])
       {
 	i--;
@@ -5373,7 +5386,7 @@ bool Item_func_like::turboBM_matches(con
       if (i < 0)
 	return 1;
 
-      register const int v = plm1 - i;
+      const int v = plm1 - i;
       turboShift = u - v;
       bcShift    = bmBc[(uint) (uchar) text[i + j]] - plm1 + i;
       shift      = max(turboShift, bcShift);
@@ -5394,7 +5407,7 @@ bool Item_func_like::turboBM_matches(con
   {
     while (j <= tlmpl)
     {
-      register int i = plm1;
+      int i = plm1;
       while (i >= 0 && likeconv(cs,pattern[i]) == likeconv(cs,text[i + j]))
       {
 	i--;
@@ -5404,7 +5417,7 @@ bool Item_func_like::turboBM_matches(con
       if (i < 0)
 	return 1;
 
-      register const int v = plm1 - i;
+      const int v = plm1 - i;
       turboShift = u - v;
       bcShift    = bmBc[(uint) likeconv(cs, text[i + j])] - plm1 + i;
       shift      = max(turboShift, bcShift);

=== modified file 'sql/item_func.cc'
--- a/sql/item_func.cc	2011-09-08 12:48:08 +0000
+++ b/sql/item_func.cc	2011-10-13 07:26:28 +0000
@@ -50,6 +50,9 @@
 #include <mysql/plugin.h>
 #include <mysql/service_thd_wait.h>
 
+using std::min;
+using std::max;
+
 #ifdef NO_EMBEDDED_ACCESS_CHECKS
 #define sp_restore_security_context(A,B) while (0) {}
 #endif
@@ -1491,7 +1494,7 @@ void Item_func_mul::result_precision()
     unsigned_flag= args[0]->unsigned_flag & args[1]->unsigned_flag;
   decimals= min(args[0]->decimals + args[1]->decimals, DECIMAL_MAX_SCALE);
   uint est_prec = args[0]->decimal_precision() + args[1]->decimal_precision();
-  uint precision= min(est_prec, DECIMAL_MAX_PRECISION);
+  uint precision= min<uint>(est_prec, DECIMAL_MAX_PRECISION);
   max_length= my_decimal_precision_to_length_no_truncation(precision, decimals,
                                                            unsigned_flag);
 }
@@ -1543,16 +1546,16 @@ my_decimal *Item_func_div::decimal_op(my
 
 void Item_func_div::result_precision()
 {
-  uint precision=min(args[0]->decimal_precision() + 
-                     args[1]->decimals + prec_increment,
-                     DECIMAL_MAX_PRECISION);
+  uint precision= min<uint>(args[0]->decimal_precision() +
+                            args[1]->decimals + prec_increment,
+                            DECIMAL_MAX_PRECISION);
 
   /* Integer operations keep unsigned_flag if one of arguments is unsigned */
   if (result_type() == INT_RESULT)
     unsigned_flag= args[0]->unsigned_flag | args[1]->unsigned_flag;
   else
     unsigned_flag= args[0]->unsigned_flag & args[1]->unsigned_flag;
-  decimals= min(args[0]->decimals + prec_increment, DECIMAL_MAX_SCALE);
+  decimals= min<uint>(args[0]->decimals + prec_increment, DECIMAL_MAX_SCALE);
   max_length= my_decimal_precision_to_length_no_truncation(precision, decimals,
                                                            unsigned_flag);
 }
@@ -2430,7 +2433,7 @@ my_decimal *Item_func_round::decimal_op(
   my_decimal val, *value= args[0]->val_decimal(&val);
   longlong dec= args[1]->val_int();
   if (dec >= 0 || args[1]->unsigned_flag)
-    dec= min((ulonglong) dec, decimals);
+    dec= min<ulonglong>(dec, decimals);
   else if (dec < INT_MIN)
     dec= INT_MIN;
     
@@ -3318,7 +3321,7 @@ udf_handler::fix_fields(THD *thd, Item_r
       free_udf(u_d);
       DBUG_RETURN(TRUE);
     }
-    func->max_length=min(initid.max_length,MAX_BLOB_WIDTH);
+    func->max_length= min<size_t>(initid.max_length, MAX_BLOB_WIDTH);
     func->maybe_null=initid.maybe_null;
     const_item_cache=initid.const_item;
     /* 
@@ -3327,7 +3330,7 @@ udf_handler::fix_fields(THD *thd, Item_r
     */  
     if (!const_item_cache && !used_tables_cache)
       used_tables_cache= RAND_TABLE_BIT;
-    func->decimals=min(initid.decimals,NOT_FIXED_DEC);
+    func->decimals= min<uint>(initid.decimals, NOT_FIXED_DEC);
   }
   initialized=1;
   if (error)

=== modified file 'sql/item_func.h'
--- a/sql/item_func.h	2011-07-04 00:25:46 +0000
+++ b/sql/item_func.h	2011-08-29 12:08:58 +0000
@@ -507,8 +507,8 @@ public:
   const char *func_name() const { return "cast_as_unsigned"; }
   void fix_length_and_dec()
   {
-    fix_char_length(min(args[0]->max_char_length(),
-                        DECIMAL_MAX_PRECISION + 2));
+    fix_char_length(std::min<uint32>(args[0]->max_char_length(),
+                                     DECIMAL_MAX_PRECISION + 2));
     unsigned_flag=1;
   }
   longlong val_int();

=== modified file 'sql/item_strfunc.cc'
--- a/sql/item_strfunc.cc	2011-09-23 10:19:37 +0000
+++ b/sql/item_strfunc.cc	2011-09-26 12:42:12 +0000
@@ -55,6 +55,9 @@ C_MODE_START
 #include "../mysys/my_static.h"			// For soundex_map
 C_MODE_END
 
+using std::min;
+using std::max;
+
 /**
    @todo Remove this. It is not safe to use a shared String object.
  */
@@ -3617,7 +3620,7 @@ void Item_func_export_set::fix_length_an
   uint32 sep_length= (arg_count > 3 ? args[3]->max_char_length() : 1);
 
   if (agg_arg_charsets_for_string_result(collation,
-                                         args + 1, min(4, arg_count) - 1))
+                                         args + 1, min(4U, arg_count) - 1))
     return;
   fix_char_length(length * 64 + sep_length * 63);
 }
@@ -4039,7 +4042,7 @@ String *Item_func_uuid::val_str(String *
       /*
         -1 so we won't make tv= uuid_time for nanoseq >= (tv - uuid_time)
       */
-      ulong delta= min(nanoseq, (ulong) (tv - uuid_time -1));
+      ulong delta= min<ulong>(nanoseq, (ulong) (tv - uuid_time -1));
       tv-= delta;
       nanoseq-= delta;
     }

=== modified file 'sql/item_strfunc.h'
--- a/sql/item_strfunc.h	2011-09-22 10:42:10 +0000
+++ b/sql/item_strfunc.h	2011-10-11 04:27:52 +0000
@@ -801,9 +801,9 @@ public:
   void fix_length_and_dec()
   {
     collation.set(args[0]->collation);
-    ulonglong max_result_length= (ulonglong) args[0]->max_length * 2 +
+    ulong max_result_length= (ulong) args[0]->max_length * 2 +
                                   2 * collation.collation->mbmaxlen;
-    max_length= (uint32) min(max_result_length, MAX_BLOB_WIDTH);
+    max_length= std::min<ulong>(max_result_length, MAX_BLOB_WIDTH);
   }
 };
 

=== modified file 'sql/item_sum.cc'
--- a/sql/item_sum.cc	2011-10-12 13:58:31 +0000
+++ b/sql/item_sum.cc	2011-10-13 07:26:28 +0000
@@ -24,6 +24,9 @@
 #include "sql_priv.h"
 #include "sql_select.h"
 
+using std::min;
+using std::max;
+
 /**
   Calculate the affordable RAM limit for structures like TREE or Unique
   used in Item_sum_*
@@ -1526,7 +1529,7 @@ void Item_sum_avg::fix_length_and_dec()
   if (hybrid_type == DECIMAL_RESULT)
   {
     int precision= args[0]->decimal_precision() + prec_increment;
-    decimals= min(args[0]->decimals + prec_increment, DECIMAL_MAX_SCALE);
+    decimals= min<uint>(args[0]->decimals + prec_increment, DECIMAL_MAX_SCALE);
     max_length= my_decimal_precision_to_length_no_truncation(precision,
                                                              decimals,
                                                              unsigned_flag);
@@ -1535,7 +1538,7 @@ void Item_sum_avg::fix_length_and_dec()
     dec_bin_size= my_decimal_get_binary_size(f_precision, f_scale);
   }
   else {
-    decimals= min(args[0]->decimals + prec_increment, NOT_FIXED_DEC);
+    decimals= min<uint>(args[0]->decimals + prec_increment, NOT_FIXED_DEC);
     max_length= args[0]->max_length + prec_increment;
   }
 }
@@ -1738,7 +1741,7 @@ void Item_sum_variance::fix_length_and_d
   case DECIMAL_RESULT:
   {
     int precision= args[0]->decimal_precision()*2 + prec_increment;
-    decimals= min(args[0]->decimals + prec_increment, DECIMAL_MAX_SCALE);
+    decimals= min<uint>(args[0]->decimals + prec_increment, DECIMAL_MAX_SCALE);
     max_length= my_decimal_precision_to_length_no_truncation(precision,
                                                              decimals,
                                                              unsigned_flag);
@@ -3399,7 +3402,7 @@ bool Item_func_group_concat::setup(THD *
       syntax of this function). If there is no ORDER BY clause, we don't
       create this tree.
     */
-    init_tree(tree, (uint) min(thd->variables.max_heap_table_size,
+    init_tree(tree,  min<uint>(thd->variables.max_heap_table_size,
                                thd->variables.sortbuff_size/16), 0,
               tree_key_length, 
               group_concat_key_cmp_with_order , 0, NULL, (void*) this);

=== modified file 'sql/item_timefunc.cc'
--- a/sql/item_timefunc.cc	2011-09-21 11:01:41 +0000
+++ b/sql/item_timefunc.cc	2011-09-26 12:42:12 +0000
@@ -50,6 +50,9 @@
 #include <m_ctype.h>
 #include <time.h>
 
+using std::min;
+using std::max;
+
 /** Day number for Dec 31st, 9999. */
 #define MAX_DAY_NUMBER 3652424L
 
@@ -614,7 +617,7 @@ static bool extract_date_time(DATE_TIME_
 err:
   {
     char buff[128];
-    strmake(buff, val_begin, min(length, sizeof(buff)-1));
+    strmake(buff, val_begin, min<size_t>(length, sizeof(buff)-1));
     push_warning_printf(current_thd, Sql_condition::WARN_LEVEL_WARN,
                         ER_WRONG_VALUE_FOR_TYPE, ER(ER_WRONG_VALUE_FOR_TYPE),
                         date_time_type, buff, "str_to_date");
@@ -1913,8 +1916,8 @@ void Item_func_date_format::fix_length_a
   else
   {
     fixed_length=0;
-    max_length=min(arg1->max_length, MAX_BLOB_WIDTH) * 10 *
-                   collation.collation->mbmaxlen;
+    max_length= min<uint32>(arg1->max_length, MAX_BLOB_WIDTH) * 10 *
+      collation.collation->mbmaxlen;
     set_if_smaller(max_length,MAX_BLOB_WIDTH);
   }
   maybe_null=1;					// If wrong date
@@ -3515,7 +3518,7 @@ null_date:
   if (val && (fuzzy_date & TIME_NO_ZERO_DATE))
   {
     char buff[128];
-    strmake(buff, val->ptr(), min(val->length(), sizeof(buff)-1));
+    strmake(buff, val->ptr(), min<size_t>(val->length(), sizeof(buff)-1));
     push_warning_printf(current_thd, Sql_condition::WARN_LEVEL_WARN,
                         ER_WRONG_VALUE_FOR_TYPE, ER(ER_WRONG_VALUE_FOR_TYPE),
                         "datetime", buff, "str_to_date");

=== modified file 'sql/item_timefunc.h'
--- a/sql/item_timefunc.h	2011-07-04 00:25:46 +0000
+++ b/sql/item_timefunc.h	2011-10-11 04:27:52 +0000
@@ -19,6 +19,8 @@
 
 /* Function items used by mysql */
 
+#include <algorithm>
+
 class MY_LOCALE;
 
 enum date_time_format_types 
@@ -96,6 +98,7 @@ public:
 
   bool intro_version(uchar *int_arg)
   {
+    using std::max;
     int *input_version= (int*)int_arg;
     /* This function was introduced in 5.5 */
     int output_version= max(*input_version, 50500);

=== modified file 'sql/key.cc'
--- a/sql/key.cc	2011-06-30 15:50:45 +0000
+++ b/sql/key.cc	2011-08-29 12:08:58 +0000
@@ -21,6 +21,9 @@
 #include "key.h"                                // key_rec_cmp
 #include "field.h"                              // Field
 
+using std::min;
+using std::max;
+
 /*
   Search after a key that starts with 'field'
 
@@ -128,13 +131,13 @@ void key_copy(uchar *to_key, uchar *from
         key_part->key_part_flag & HA_VAR_LENGTH_PART)
     {
       key_length-= HA_KEY_BLOB_LENGTH;
-      length= min(key_length, key_part->length);
+      length= min<uint>(key_length, key_part->length);
       key_part->field->get_key_image(to_key, length, Field::itRAW);
       to_key+= HA_KEY_BLOB_LENGTH;
     }
     else
     {
-      length= min(key_length, key_part->length);
+      length= min<uint>(key_length, key_part->length);
       Field *field= key_part->field;
       const CHARSET_INFO *cs= field->charset();
       uint bytes= field->get_key_image(to_key, length, Field::itRAW);
@@ -241,7 +244,7 @@ void key_restore(uchar *to_record, uchar
       my_ptrdiff_t ptrdiff= to_record - field->table->record[0];
       field->move_field_offset(ptrdiff);
       key_length-= HA_KEY_BLOB_LENGTH;
-      length= min(key_length, key_part->length);
+      length= min<uint>(key_length, key_part->length);
       old_map= dbug_tmp_use_all_columns(field->table, field->table->write_set);
       field->set_key_image(from_key, length);
       dbug_tmp_restore_column_map(field->table->write_set, old_map);
@@ -250,7 +253,7 @@ void key_restore(uchar *to_record, uchar
     }
     else
     {
-      length= min(key_length, key_part->length);
+      length= min<uint>(key_length, key_part->length);
       /* skip the byte with 'uneven' bits, if used */
       memcpy(to_record + key_part->offset, from_key + used_uneven_bits
              , (size_t) length - used_uneven_bits);
@@ -403,7 +406,7 @@ void key_unpack(String *to,TABLE *table,
           tmp.length(charpos);
       }
       if (key_part->length < field->pack_length())
-	tmp.length(min(tmp.length(),key_part->length));
+	tmp.length(min<uint32>(tmp.length(),key_part->length));
       ErrConvString err(&tmp);
       to->append(err.ptr());
     }

=== modified file 'sql/log.cc'
--- a/sql/log.cc	2011-11-01 08:47:32 +0000
+++ b/sql/log.cc	2011-11-03 16:03:34 +0000
@@ -44,6 +44,9 @@
 #include "message.h"
 #endif
 
+using std::min;
+using std::max;
+
 /* max size of the log message */
 #define MAX_LOG_BUFFER_SIZE 1024
 #define MAX_TIME_SIZE 32
@@ -618,11 +621,11 @@ bool Log_to_csv_event_handler::
     t.neg= 0;
 
     /* fill in query_time field */
-    calc_time_from_sec(&t, (long) min(query_time, (longlong) TIME_MAX_VALUE_SECONDS), 0);
+    calc_time_from_sec(&t, min<long>(query_time, (longlong) TIME_MAX_VALUE_SECONDS), 0);
     if (table->field[SQLT_FIELD_QUERY_TIME]->store_time(&t, MYSQL_TIMESTAMP_TIME))
       goto err;
     /* lock_time */
-    calc_time_from_sec(&t, (long) min(lock_time, (longlong) TIME_MAX_VALUE_SECONDS), 0);
+    calc_time_from_sec(&t, min<long>(lock_time, (longlong) TIME_MAX_VALUE_SECONDS), 0);
     if (table->field[SQLT_FIELD_LOCK_TIME]->store_time(&t, MYSQL_TIMESTAMP_TIME))
       goto err;
     /* rows_sent */
@@ -2019,7 +2022,7 @@ const char *MYSQL_LOG::generate_name(con
   {
     char *p= fn_ext(log_name);
     uint length= (uint) (p - log_name);
-    strmake(buff, log_name, min(length, FN_REFLEN-1));
+    strmake(buff, log_name, min<size_t>(length, FN_REFLEN-1));
     return (const char*)buff;
   }
   return log_name;

=== modified file 'sql/log_event.cc'
--- a/sql/log_event.cc	2011-10-14 01:25:12 +0000
+++ b/sql/log_event.cc	2011-10-28 12:45:35 +0000
@@ -49,6 +49,8 @@
 #include <my_bitmap.h>
 #include "rpl_utility.h"
 
+using std::min;
+using std::max;
 
 /**
   BINLOG_CHECKSUM variable.
@@ -1237,8 +1239,8 @@ Log_event* Log_event::read_log_event(IO_
     of 13 bytes, whereas LOG_EVENT_MINIMAL_HEADER_LEN is 19 bytes (it's
     "minimal" over the set {MySQL >=4.0}).
   */
-  uint header_size= min(description_event->common_header_len,
-                        LOG_EVENT_MINIMAL_HEADER_LEN);
+  uint header_size= min<uint>(description_event->common_header_len,
+                              LOG_EVENT_MINIMAL_HEADER_LEN);
 
   LOCK_MUTEX;
   DBUG_PRINT("info", ("my_b_tell: %lu", (ulong) my_b_tell(file)));
@@ -1263,8 +1265,10 @@ failed my_b_read"));
   uint max_allowed_packet= thd ? thd->variables.max_allowed_packet : ~(ulong)0;
 #endif
 
-  if (data_len > max(max_allowed_packet,
-                     opt_binlog_rows_event_max_size + MAX_LOG_EVENT_HEADER))
+  ulong const max_size=
+    max<ulong>(max_allowed_packet,
+               opt_binlog_rows_event_max_size + MAX_LOG_EVENT_HEADER);
+  if (data_len > max_size)
   {
     error = "Event too big";
     goto err;
@@ -3562,7 +3566,7 @@ Query_log_event::Query_log_event(const c
       be even bigger, but this will suffice to catch most corruption
       errors that can lead to a crash.
     */
-    if (status_vars_len > min(data_len, MAX_SIZE_LOG_EVENT_STATUS))
+    if (status_vars_len > min<ulong>(data_len, MAX_SIZE_LOG_EVENT_STATUS))
     {
       DBUG_PRINT("info", ("status_vars_len (%u) > data_len (%lu); query= 0",
                           status_vars_len, data_len));
@@ -6965,7 +6969,7 @@ bool User_var_log_event::write(IO_CACHE*
   char buf[UV_NAME_LEN_SIZE];
   char buf1[UV_VAL_IS_NULL + UV_VAL_TYPE_SIZE + 
 	    UV_CHARSET_NUMBER_SIZE + UV_VAL_LEN_SIZE];
-  uchar buf2[max(8, DECIMAL_MAX_FIELD_SIZE + 2)], *pos= buf2;
+  uchar buf2[MY_MAX(8, DECIMAL_MAX_FIELD_SIZE + 2)], *pos= buf2;
   uint unsigned_len= 0;
   uint buf1_length;
   ulong event_length;
@@ -8586,7 +8590,7 @@ int Rows_log_event::do_add_row_data(ucha
     trigger false warnings.
    */
 #ifndef HAVE_purify
-  DBUG_DUMP("row_data", row_data, min(length, 32));
+  DBUG_DUMP("row_data", row_data, min<size_t>(length, 32));
 #endif
 
   DBUG_ASSERT(m_rows_buf <= m_rows_cur);

=== modified file 'sql/log_event.h'
--- a/sql/log_event.h	2011-08-19 13:04:28 +0000
+++ b/sql/log_event.h	2011-08-29 12:08:58 +0000
@@ -217,8 +217,8 @@ struct sql_ex_info
 
  ****************************************************************************/
 
-#define LOG_EVENT_HEADER_LEN 19     /* the fixed header length */
-#define OLD_HEADER_LEN       13     /* the fixed header length in 3.23 */
+#define LOG_EVENT_HEADER_LEN 19U    /* the fixed header length */
+#define OLD_HEADER_LEN       13U    /* the fixed header length in 3.23 */
 /*
    Fixed header length, where 4.x and 5.0 agree. That is, 5.0 may have a longer
    header (it will for sure when we have the unique event's ID), but at least
@@ -226,7 +226,7 @@ struct sql_ex_info
    event's ID, LOG_EVENT_HEADER_LEN will be something like 26, but
    LOG_EVENT_MINIMAL_HEADER_LEN will remain 19.
 */
-#define LOG_EVENT_MINIMAL_HEADER_LEN 19
+#define LOG_EVENT_MINIMAL_HEADER_LEN 19U
 
 /* event-specific post-header sizes */
 // where 3.23, 4.x and 5.0 agree
@@ -275,19 +275,19 @@ struct sql_ex_info
   packet (i.e. a query) sent from client to master;
   First, an auxiliary log_event status vars estimation:
 */
-#define MAX_SIZE_LOG_EVENT_STATUS (1 + 4          /* type, flags2 */   + \
-                                   1 + 8          /* type, sql_mode */ + \
-                                   1 + 1 + 255    /* type, length, catalog */ + \
-                                   1 + 4          /* type, auto_increment */ + \
-                                   1 + 6          /* type, charset */ + \
-                                   1 + 1 + 255    /* type, length, time_zone */ + \
-                                   1 + 2          /* type, lc_time_names_number */ + \
-                                   1 + 2          /* type, charset_database_number */ + \
-                                   1 + 8          /* type, table_map_for_update */ + \
-                                   1 + 4          /* type, master_data_written */ + \
-                                                  /* type, db_1, db_2, ... */  \
-                                   1 + (MAX_DBS_IN_EVENT_MTS * (1 + NAME_LEN)) + \
-                                   1 + 16 + 1 + 60/* type, user_len, user, host_len, host */)
+#define MAX_SIZE_LOG_EVENT_STATUS (1U + 4          /* type, flags2 */   + \
+                                   1U + 8          /* type, sql_mode */ + \
+                                   1U + 1 + 255    /* type, length, catalog */ + \
+                                   1U + 4          /* type, auto_increment */ + \
+                                   1U + 6          /* type, charset */ + \
+                                   1U + 1 + 255    /* type, length, time_zone */ + \
+                                   1U + 2          /* type, lc_time_names_number */ + \
+                                   1U + 2          /* type, charset_database_number */ + \
+                                   1U + 8          /* type, table_map_for_update */ + \
+                                   1U + 4          /* type, master_data_written */ + \
+                                                   /* type, db_1, db_2, ... */  \
+                                   1U + (MAX_DBS_IN_EVENT_MTS * (1 + NAME_LEN)) + \
+                                   1U + 16 + 1 + 60/* type, user_len, user, host_len, host */)
 #define MAX_LOG_EVENT_HEADER   ( /* in order of Query_log_event::write */ \
   LOG_EVENT_HEADER_LEN + /* write_header */ \
   QUERY_HEADER_LEN     + /* write_data */   \

=== modified file 'sql/log_event_old.cc'
--- a/sql/log_event_old.cc	2011-06-30 15:50:45 +0000
+++ b/sql/log_event_old.cc	2011-08-29 12:08:58 +0000
@@ -32,6 +32,11 @@
 #include "rpl_record_old.h"
 #include "transaction.h"
 
+#include <algorithm>
+
+using std::min;
+using std::max;
+
 #if !defined(MYSQL_CLIENT) && defined(HAVE_REPLICATION)
 
 // Old implementation of do_apply_event()
@@ -1414,7 +1419,7 @@ int Old_rows_log_event::do_add_row_data(
     trigger false warnings.
    */
 #ifndef HAVE_purify
-  DBUG_DUMP("row_data", row_data, min(length, 32));
+  DBUG_DUMP("row_data", row_data, min<size_t>(length, 32));
 #endif
 
   DBUG_ASSERT(m_rows_buf <= m_rows_cur);

=== modified file 'sql/mdl.cc'
--- a/sql/mdl.cc	2011-07-21 16:27:14 +0000
+++ b/sql/mdl.cc	2011-10-11 04:27:52 +0000
@@ -849,9 +849,9 @@ inline MDL_lock *MDL_lock::create(const
     case MDL_key::GLOBAL:
     case MDL_key::SCHEMA:
     case MDL_key::COMMIT:
-      return new MDL_scoped_lock(mdl_key);
+      return new (std::nothrow) MDL_scoped_lock(mdl_key);
     default:
-      return new MDL_object_lock(mdl_key);
+      return new (std::nothrow) MDL_object_lock(mdl_key);
   }
 }
 
@@ -876,7 +876,8 @@ MDL_ticket *MDL_ticket::create(MDL_conte
 #endif
                                )
 {
-  return new MDL_ticket(ctx_arg, type_arg
+  return new (std::nothrow)
+             MDL_ticket(ctx_arg, type_arg
 #ifndef DBUG_OFF
                         , duration_arg
 #endif

=== modified file 'sql/mdl.h'
--- a/sql/mdl.h	2011-07-21 16:27:14 +0000
+++ b/sql/mdl.h	2011-10-11 04:27:52 +0000
@@ -29,6 +29,8 @@
 #include <m_string.h>
 #include <mysql_com.h>
 
+#include <algorithm>
+
 class THD;
 
 class MDL_context;
@@ -348,6 +350,7 @@ public:
       character set is utf-8, we can safely assume that no
       character starts with a zero byte.
     */
+    using std::min;
     return memcmp(m_ptr, rhs->m_ptr, min(m_length, rhs->m_length));
   }
 

=== modified file 'sql/mysqld.cc'
--- a/sql/mysqld.cc	2011-11-02 23:29:01 +0000
+++ b/sql/mysqld.cc	2011-11-03 16:03:34 +0000
@@ -14,6 +14,11 @@
    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301  USA */
 
 #include "my_global.h"                          /* NO_EMBEDDED_ACCESS_CHECKS */
+
+#include <vector>
+#include <algorithm>
+#include <functional>
+
 #include "sql_priv.h"
 #include "unireg.h"
 #include <signal.h>
@@ -97,6 +102,10 @@
 #include <poll.h>
 #endif
 
+using std::min;
+using std::max;
+using std::vector;
+
 #define mysqld_charset &my_charset_latin1
 
 /* We have HAVE_purify below as this speeds up the shutdown of MySQL */
@@ -1037,7 +1046,7 @@ uint connection_count= 0;
 pthread_handler_t signal_hand(void *arg);
 static int mysql_init_variables(void);
 static int get_options(int *argc_ptr, char ***argv_ptr);
-static bool add_terminator(DYNAMIC_ARRAY *options);
+static void add_terminator(vector<my_option> *options);
 extern "C" my_bool mysqld_get_one_option(int, const struct my_option *, char *);
 static void set_server_version(void);
 static int init_thread_environment();
@@ -2616,7 +2625,7 @@ the thread stack. Please read http://dev
     fprintf(stderr, "\nTrying to get some variables.\n"
                     "Some pointers may be invalid and cause the dump to abort.\n");
     fprintf(stderr, "Query (%p): ", thd->query());
-    my_safe_print_str(thd->query(), min(1024, thd->query_length()));
+    my_safe_print_str(thd->query(), min(1024U, thd->query_length()));
     fprintf(stderr, "Connection ID (thread ID): %lu\n", (ulong) thd->thread_id);
     fprintf(stderr, "Status: %s\n", kreason);
 #ifdef OPTIMIZER_TRACE
@@ -3577,7 +3586,7 @@ int init_common_variables()
       can't get max_connections*5 but still got no less than was
       requested (value of wanted_files).
     */
-    max_open_files= max(max(wanted_files, max_connections*5),
+    max_open_files= max(max<ulong>(wanted_files, max_connections*5),
                         open_files_limit);
     files= my_set_max_open_files(max_open_files);
 
@@ -3589,17 +3598,17 @@ int init_common_variables()
           If we have requested too much file handles than we bring
           max_connections in supported bounds.
         */
-        max_connections= (ulong) min(files-10-TABLE_OPEN_CACHE_MIN*2,
-                                     max_connections);
+        max_connections= min<ulong>(files - 10 - TABLE_OPEN_CACHE_MIN * 2,
+                                    max_connections);
         /*
           Decrease table_cache_size according to max_connections, but
           not below TABLE_OPEN_CACHE_MIN.  Outer min() ensures that we
           never increase table_cache_size automatically (that could
           happen if max_connections is decreased above).
         */
-        table_cache_size= (ulong) min(max((files-10-max_connections)/2,
-                                          TABLE_OPEN_CACHE_MIN),
-                                      table_cache_size);
+        table_cache_size= min<ulong>(max<ulong>((files-10-max_connections)/2,
+                                                TABLE_OPEN_CACHE_MIN),
+                                     table_cache_size);
   DBUG_PRINT("warning",
        ("Changed limits: max_open_files: %u  max_connections: %ld  table_cache: %ld",
         files, max_connections, table_cache_size));
@@ -4744,14 +4753,14 @@ int mysqld_main(int argc, char **argv)
     before to-be-instrumented objects of the server are initialized.
   */
   int ho_error;
-  DYNAMIC_ARRAY all_early_options;
+  vector<my_option> all_early_options;
+  all_early_options.reserve(100);
 
   my_getopt_register_get_addr(NULL);
   /* Skip unknown options so that they may be processed later */
   my_getopt_skip_unknown= TRUE;
 
   /* prepare all_early_options array */
-  my_init_dynamic_array(&all_early_options, sizeof(my_option), 100, 25);
   sys_var_add_options(&all_early_options, sys_var::PARSE_EARLY);
   add_terminator(&all_early_options);
 
@@ -4764,8 +4773,10 @@ int mysqld_main(int argc, char **argv)
   my_charset_error_reporter= buffered_option_error_reporter;
 
   ho_error= handle_options(&remaining_argc, &remaining_argv,
-                           (my_option*)(all_early_options.buffer), NULL);
-  delete_dynamic(&all_early_options);
+                           &all_early_options[0], NULL);
+  // Swap with an empty vector, i.e. delete elements and free allocated space.
+  vector<my_option>().swap(all_early_options);
+
   if (ho_error == 0)
   {
     /* Add back the program name handle_options removes */
@@ -5613,7 +5624,7 @@ void handle_connections_sockets()
   MYSQL_SOCKET pfs_fds[2]; // for performance schema
 #else
   fd_set readFDs,clientFDs;
-  uint max_used_connection= (uint)(max(mysql_socket_getfd(ip_sock), mysql_socket_getfd(unix_sock))+1);
+  uint max_used_connection= max<uint>(mysql_socket_getfd(ip_sock), mysql_socket_getfd(unix_sock)) + 1;
 #endif
 
   DBUG_ENTER("handle_connections_sockets");
@@ -6199,7 +6210,7 @@ error:
   Handle start options
 ******************************************************************************/
 
-DYNAMIC_ARRAY all_options;
+vector<my_option> all_options;
 
 /**
   System variables are automatically command-line options (few
@@ -7232,10 +7243,11 @@ SHOW_VAR status_vars[]= {
   {NullS, NullS, SHOW_LONG}
 };
 
-bool add_terminator(DYNAMIC_ARRAY *options)
+void add_terminator(vector<my_option> *options)
 {
-  my_option empty_element= {0, 0, 0, 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0};
-  return insert_dynamic(options, &empty_element);
+  my_option empty_element=
+    {0, 0, 0, 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0};
+  options->push_back(empty_element);
 }
 
 #ifndef EMBEDDED_LIBRARY
@@ -7248,10 +7260,10 @@ static void print_version(void)
 }
 
 /** Compares two options' names, treats - and _ the same */
-static int option_cmp(my_option *a, my_option *b)
+static bool operator<(const my_option &a, const my_option &b)
 {
-  const char *sa= a->name;
-  const char *sb= b->name;
+  const char *sa= a.name;
+  const char *sb= b.name;
   for (; *sa || *sb; sa++, sb++)
   {
     if (*sa < *sb)
@@ -7259,18 +7271,18 @@ static int option_cmp(my_option *a, my_o
       if (*sa == '-' && *sb == '_')
         continue;
       else
-        return -1;
+        return true;
     }
     if (*sa > *sb)
     {
       if (*sa == '_' && *sb == '-')
         continue;
       else
-        return 1;
+        return false;
     }
   }
-  DBUG_ASSERT(a->name == b->name);
-  return 0;
+  DBUG_ASSERT(a.name == b.name);
+  return false;
 }
 
 static void print_help()
@@ -7278,17 +7290,17 @@ static void print_help()
   MEM_ROOT mem_root;
   init_alloc_root(&mem_root, 4096, 4096);
 
-  pop_dynamic(&all_options);
+  all_options.pop_back();
   sys_var_add_options(&all_options, sys_var::PARSE_EARLY);
   add_plugin_options(&all_options, &mem_root);
-  sort_dynamic(&all_options, (qsort_cmp) option_cmp);
+  std::sort(all_options.begin(), all_options.end(), std::less<my_option>());
   add_terminator(&all_options);
 
-  my_print_help((my_option*) all_options.buffer);
-  my_print_variables((my_option*) all_options.buffer);
+  my_print_help(&all_options[0]);
+  my_print_variables(&all_options[0]);
 
   free_root(&mem_root, MYF(0));
-  delete_dynamic(&all_options);
+  vector<my_option>().swap(all_options);  // Deletes the vector contents.
 }
 
 static void usage(void)
@@ -7906,25 +7918,23 @@ static int get_options(int *argc_ptr, ch
   my_getopt_error_reporter= option_error_reporter;
 
   /* prepare all_options array */
-  my_init_dynamic_array(&all_options, sizeof(my_option),
-                        array_elements(my_long_options),
-                        array_elements(my_long_options)/4);
+  all_options.reserve(array_elements(my_long_options));
   for (my_option *opt= my_long_options;
        opt < my_long_options + array_elements(my_long_options) - 1;
        opt++)
-    insert_dynamic(&all_options, opt);
+    all_options.push_back(*opt);
   sys_var_add_options(&all_options, sys_var::PARSE_NORMAL);
   add_terminator(&all_options);
 
   /* Skip unknown options so that they may be processed later by plugins */
   my_getopt_skip_unknown= TRUE;
 
-  if ((ho_error= handle_options(argc_ptr, argv_ptr, (my_option*)(all_options.buffer),
+  if ((ho_error= handle_options(argc_ptr, argv_ptr, &all_options[0],
                                 mysqld_get_one_option)))
     return ho_error;
 
   if (!opt_help)
-    delete_dynamic(&all_options);
+    vector<my_option>().swap(all_options);  // Deletes the vector contents.
 
   /* Add back the program name handle_options removes */
   (*argc_ptr)++;

=== modified file 'sql/net_serv.cc'
--- a/sql/net_serv.cc	2011-11-01 16:33:58 +0000
+++ b/sql/net_serv.cc	2011-11-03 16:03:34 +0000
@@ -45,6 +45,11 @@
 #include <errno.h>
 #include "probes_mysql.h"
 
+#include <algorithm>
+
+using std::min;
+using std::max;
+
 #ifdef EMBEDDED_LIBRARY
 #undef MYSQL_SERVER
 #undef MYSQL_CLIENT

=== modified file 'sql/opt_range.cc'
--- a/sql/opt_range.cc	2011-10-27 08:43:56 +0000
+++ b/sql/opt_range.cc	2011-10-28 12:45:35 +0000
@@ -115,6 +115,9 @@
 #include "sql_select.h"
 #include "opt_trace.h"
 
+using std::min;
+using std::max;
+
 #ifndef EXTRA_DEBUG
 #define test_rb_tree(A,B) {}
 #define test_use_count(A) {}
@@ -1049,7 +1052,7 @@ SEL_TREE::SEL_TREE(SEL_TREE *arg, RANGE_
 {
   keys_map= arg->keys_map;
   type= arg->type;
-  for (int idx= 0; idx < MAX_KEY; idx++)
+  for (uint idx= 0; idx < MAX_KEY; idx++)
   {
     if ((keys[idx]= arg->keys[idx]))
       keys[idx]->increment_use_count(1);
@@ -8621,7 +8624,7 @@ walk_up_n_right:
   }
 
   seq->param->range_count++;
-  seq->param->max_key_part=max(seq->param->max_key_part,key_tree->part);
+  seq->param->max_key_part=max<uint>(seq->param->max_key_part,key_tree->part);
 
   return 0;
 }
@@ -11448,7 +11451,7 @@ void cost_group_min_max(TABLE* table, KE
       p_overlap= (blocks_per_group * (keys_per_subgroup - 1)) / keys_per_group;
       p_overlap= min(p_overlap, 1.0);
     }
-    io_cost= (double) min(num_groups * (1 + p_overlap), num_blocks);
+    io_cost= min<double>(num_groups * (1 + p_overlap), num_blocks);
   }
   else
     io_cost= (keys_per_group > keys_per_block) ?

=== modified file 'sql/opt_range.h'
--- a/sql/opt_range.h	2011-07-28 12:53:50 +0000
+++ b/sql/opt_range.h	2011-10-11 04:27:52 +0000
@@ -30,6 +30,8 @@
 #include "sql_class.h"                          // set_var.h: THD
 #include "set_var.h"                            /* Item */
 
+#include <algorithm>
+
 class JOIN;
 class Item_sum;
 
@@ -92,6 +94,7 @@ class QUICK_RANGE :public Sql_alloc {
   */
   void make_min_endpoint(key_range *kr, uint prefix_length, 
                          key_part_map keypart_map) {
+    using std::min;
     make_min_endpoint(kr);
     kr->length= min(kr->length, prefix_length);
     kr->keypart_map&= keypart_map;
@@ -130,6 +133,7 @@ class QUICK_RANGE :public Sql_alloc {
   */
   void make_max_endpoint(key_range *kr, uint prefix_length, 
                          key_part_map keypart_map) {
+    using std::min;
     make_max_endpoint(kr);
     kr->length= min(kr->length, prefix_length);
     kr->keypart_map&= keypart_map;

=== modified file 'sql/opt_trace.cc'
--- a/sql/opt_trace.cc	2011-10-05 13:16:38 +0000
+++ b/sql/opt_trace.cc	2011-10-13 07:26:28 +0000
@@ -960,7 +960,7 @@ bool Opt_trace_context::start(bool suppo
   DBUG_EXECUTE_IF("no_new_opt_trace_stmt", DBUG_ASSERT(0););
 
   if (pimpl == NULL)
-    pimpl= new Opt_trace_context_impl(); // OOM-unsafe new.
+    pimpl= new (std::nothrow) Opt_trace_context_impl();
 
   /*
     If tracing is disabled by some caller, then don't change settings (offset
@@ -1003,11 +1003,10 @@ bool Opt_trace_context::start(bool suppo
   }
   {
     /*
-      OOM-unsafe "new".
       We don't allocate it in THD's MEM_ROOT as it must survive until a next
       statement (SELECT) reads the trace.
     */
-    Opt_trace_stmt *stmt= new Opt_trace_stmt(this);
+    Opt_trace_stmt *stmt= new (std::nothrow) Opt_trace_stmt(this);
 
     DBUG_PRINT("opt",("new stmt %p support_I_S %d", stmt, support_I_S_arg));
 

=== modified file 'sql/opt_trace.h'
--- a/sql/opt_trace.h	2011-10-21 11:13:05 +0000
+++ b/sql/opt_trace.h	2011-10-28 12:45:35 +0000
@@ -315,15 +315,11 @@ class set_var_base;
   Note that the debug binary may crash if OOM (OOM can cause syntax
   errors...).
   @todo @c new error handling. In released and pushbuild2 builds, @c
-  my_new.cc:new is used, which is broken (BUG#11822322). In builds with g++,
-  the standard @c new doesn't work either (it throws an exception but as we
-  use -fno-exceptions we cannot catch it and it kills the program).
-  As we don't support exceptions, we need new(nothrow) in order to be able to
-  handle OOM.
-  But "nothrow" is in the standard C++ library, which we don't link with.
-  So we have two calls to "new" (one to create Opt_trace_context_impl, one to
-  create Opt_trace_stmt), which may crash. When we have nothrow we should
-  change them to new(nothrow).
+  my_new.cc:new has traditionally been used, which was broken (BUG#11822322).
+  In builds with g++, the standard @c new doesn't work either
+  (it throws an exception but as we do not catch it, it will kill the program).
+  As we don't support exceptions, we need new(std::nothrow) in order to be
+  able to handle OOM.
 
   @section TRACE_SECURITY Description of trace-induced security checks.
 

=== modified file 'sql/protocol.cc'
--- a/sql/protocol.cc	2011-07-28 10:36:01 +0000
+++ b/sql/protocol.cc	2011-08-29 12:08:58 +0000
@@ -26,6 +26,9 @@
 #include "sql_class.h"                          // THD
 #include <stdarg.h>
 
+using std::min;
+using std::max;
+
 static const unsigned int PACKET_BUFFER_EXTRA_ALLOC= 1024;
 /* Declared non-static only because of the embedded library. */
 bool net_send_error_packet(THD *, uint, const char *, const char *);
@@ -230,7 +233,7 @@ net_send_ok(THD *thd,
     pos+=2;
 
     /* We can only return up to 65535 warnings in two bytes */
-    uint tmp= min(statement_warn_count, 65535);
+    uint tmp= min(statement_warn_count, 65535U);
     int2store(pos, tmp);
     pos+= 2;
   }
@@ -326,7 +329,7 @@ static bool write_eof_packet(THD *thd, N
       Don't send warn count during SP execution, as the warn_list
       is cleared between substatements, and mysqltest gets confused
     */
-    uint tmp= min(statement_warn_count, 65535);
+    uint tmp= min(statement_warn_count, 65535U);
     buff[0]= 254;
     int2store(buff+1, tmp);
     /*

=== modified file 'sql/rpl_mi.cc'
--- a/sql/rpl_mi.cc	2011-10-13 14:01:50 +0000
+++ b/sql/rpl_mi.cc	2011-10-28 12:45:35 +0000
@@ -20,6 +20,9 @@
 #include "rpl_mi.h"
 #include "rpl_slave.h"                          // SLAVE_MAX_HEARTBEAT_PERIOD
 
+using std::min;
+using std::max;
+
 #ifdef HAVE_REPLICATION
 
 enum {
@@ -186,8 +189,8 @@ void Master_info::init_master_log_pos()
     if CHANGE MASTER did not specify it.  (no data loss in conversion
     as hb period has a max)
   */
-  heartbeat_period= (float) min(SLAVE_MAX_HEARTBEAT_PERIOD,
-                                (slave_net_timeout/2.0));
+  heartbeat_period= min<float>(SLAVE_MAX_HEARTBEAT_PERIOD,
+                               (slave_net_timeout/2.0));
   DBUG_ASSERT(heartbeat_period > (float) 0.001
               || heartbeat_period == 0);
 

=== modified file 'sql/rpl_record.cc'
--- a/sql/rpl_record.cc	2011-07-28 10:54:44 +0000
+++ b/sql/rpl_record.cc	2011-08-29 12:08:58 +0000
@@ -21,6 +21,9 @@
 #include "rpl_utility.h"
 #include "rpl_rli.h"
 
+using std::min;
+using std::max;
+
 /**
    Pack a record of data for a table into a format suitable for
    transfer via the binary log.
@@ -392,7 +395,7 @@ unpack_row(Relay_log_info const *rli,
   /*
     throw away master's extra fields
   */
-  uint max_cols= min(tabledef->size(), cols->n_bits);
+  uint max_cols= min<ulong>(tabledef->size(), cols->n_bits);
   for (; i < max_cols; i++)
   {
     if (bitmap_is_set(cols, i))

=== modified file 'sql/rpl_rli.cc'
--- a/sql/rpl_rli.cc	2011-10-13 14:01:50 +0000
+++ b/sql/rpl_rli.cc	2011-10-28 12:45:35 +0000
@@ -31,6 +31,9 @@
 #include <mysql/plugin.h>
 #include <mysql/service_thd_wait.h>
 
+using std::min;
+using std::max;
+
 /*
   Please every time you add a new field to the relay log info, update
   what follows. For now, this is just used to get the number of
@@ -572,7 +575,7 @@ int Relay_log_info::wait_for_pos(THD* th
   ulong log_name_extension;
   char log_name_tmp[FN_REFLEN]; //make a char[] from String
 
-  strmake(log_name_tmp, log_name->ptr(), min(log_name->length(), FN_REFLEN-1));
+  strmake(log_name_tmp, log_name->ptr(), min<uint32>(log_name->length(), FN_REFLEN-1));
 
   char *p= fn_ext(log_name_tmp);
   char *p_end;
@@ -582,7 +585,7 @@ int Relay_log_info::wait_for_pos(THD* th
     goto err;
   }
   // Convert 0-3 to 4
-  log_pos= max(log_pos, BIN_LOG_HEADER_SIZE);
+  log_pos= max<ulong>(log_pos, BIN_LOG_HEADER_SIZE);
   /* p points to '.' */
   log_name_extension= strtoul(++p, &p_end, 10);
   /*

=== modified file 'sql/rpl_slave.cc'
--- a/sql/rpl_slave.cc	2011-10-20 13:06:58 +0000
+++ b/sql/rpl_slave.cc	2011-11-04 12:59:47 +0000
@@ -59,6 +59,9 @@
 #include "rpl_tblmap.h"
 #include "debug_sync.h"
 
+using std::min;
+using std::max;
+
 #define FLAGSTR(V,F) ((V)&(F)?#F" ":"")
 
 #define MAX_SLAVE_RETRY_PAUSE 5
@@ -337,6 +340,8 @@ int init_slave()
   /* If server id is not set, start_slave_thread() will say it */
   if (active_mi->host[0] && !opt_skip_slave_start)
   {
+    /* same as in start_slave() cache the global var value into rli's member */
+    active_mi->rli->opt_slave_parallel_workers= opt_mts_slave_parallel_workers;
     if (start_slave_threads(1 /* need mutex */,
                             0 /* no wait for start*/,
                             active_mi,
@@ -407,8 +412,8 @@ int init_recovery(Master_info* mi, const
   group_master_log_name= const_cast<char *>(rli->get_group_master_log_name());
   if (!error && group_master_log_name[0])
   {
-    mi->set_master_log_pos(max(BIN_LOG_HEADER_SIZE,
-                           rli->get_group_master_log_pos()));
+    mi->set_master_log_pos(max<ulonglong>(BIN_LOG_HEADER_SIZE,
+                                               rli->get_group_master_log_pos()));
     mi->set_master_log_name(rli->get_group_master_log_name());
 
     sql_print_warning("Recovery from master pos %ld and file %s.",
@@ -2324,7 +2329,7 @@ bool show_master_info(THD* thd, Master_i
         special marker to say "consider we have caught up".
       */
       protocol->store((longlong)(mi->rli->last_master_timestamp ?
-                                 max(0, time_diff) : 0));
+                                 max(0L, time_diff) : 0));
     }
     else
     {
@@ -3220,7 +3225,7 @@ static int exec_relay_log_event(THD* thd
             exec_res= 0;
             rli->cleanup_context(thd, 1);
             /* chance for concurrent connection to get more locks */
-            slave_sleep(thd, min(rli->trans_retries, MAX_SLAVE_RETRY_PAUSE),
+            slave_sleep(thd, min<ulong>(rli->trans_retries, MAX_SLAVE_RETRY_PAUSE),
                         sql_slave_killed, rli);
             mysql_mutex_lock(&rli->data_lock); // because of SHOW STATUS
             rli->trans_retries++;
@@ -6013,8 +6018,8 @@ static IO_CACHE *reopen_relay_log(Relay_
     relay_log_pos       Current log pos
     pending             Number of bytes already processed from the event
   */
-  rli->set_event_relay_log_pos(max(rli->get_event_relay_log_pos(),
-                                   BIN_LOG_HEADER_SIZE));
+  rli->set_event_relay_log_pos(max<ulonglong>(rli->get_event_relay_log_pos(),
+                                              BIN_LOG_HEADER_SIZE));
   my_b_seek(cur_log,rli->get_event_relay_log_pos());
   DBUG_RETURN(cur_log);
 }
@@ -7098,8 +7103,8 @@ bool change_master(THD* thd, Master_info
   if (lex_mi->heartbeat_opt != LEX_MASTER_INFO::LEX_MI_UNCHANGED)
     mi->heartbeat_period = lex_mi->heartbeat_period;
   else
-    mi->heartbeat_period= (float) min(SLAVE_MAX_HEARTBEAT_PERIOD,
-                                      (slave_net_timeout/2.0));
+    mi->heartbeat_period= min<float>(SLAVE_MAX_HEARTBEAT_PERIOD,
+                                     (slave_net_timeout/2.0));
   mi->received_heartbeats= LL(0); // counter lives until master is CHANGEd
   /*
     reset the last time server_id list if the current CHANGE MASTER 
@@ -7203,8 +7208,8 @@ bool change_master(THD* thd, Master_info
        of replication is not 100% clear, so we guard against problems using
        max().
       */
-     mi->set_master_log_pos(max(BIN_LOG_HEADER_SIZE,
-                           mi->rli->get_group_master_log_pos()));
+     mi->set_master_log_pos(max<ulonglong>(BIN_LOG_HEADER_SIZE,
+                                           mi->rli->get_group_master_log_pos()));
      mi->set_master_log_name(mi->rli->get_group_master_log_name());
   }
   /*

=== modified file 'sql/rpl_utility.cc'
--- a/sql/rpl_utility.cc	2011-06-30 15:50:45 +0000
+++ b/sql/rpl_utility.cc	2011-08-29 12:08:58 +0000
@@ -20,6 +20,11 @@
 #include "rpl_rli.h"
 #include "sql_select.h"
 
+#include <algorithm>
+
+using std::min;
+using std::max;
+
 /**
    Function to compare two size_t integers for their relative
    order. Used below.
@@ -780,7 +785,7 @@ table_def::compatible_with(THD *thd, Rel
   /*
     We only check the initial columns for the tables.
   */
-  uint const cols_to_check= min(table->s->fields, size());
+  uint const cols_to_check= min<ulong>(table->s->fields, size());
   TABLE *tmp_table= NULL;
 
   for (uint col= 0 ; col < cols_to_check ; ++col)

=== modified file 'sql/rpl_utility.h'
--- a/sql/rpl_utility.h	2011-06-30 15:50:45 +0000
+++ b/sql/rpl_utility.h	2011-08-29 12:08:58 +0000
@@ -268,7 +268,7 @@ CPP_UNNAMED_NS_END
   do {                                             \
     char buf[256];                                 \
     uint i;                                        \
-    for (i = 0 ; i < min(sizeof(buf) - 1, (BS)->n_bits) ; i++) \
+    for (i = 0 ; i < MY_MIN(sizeof(buf) - 1, (BS)->n_bits) ; i++) \
       buf[i] = bitmap_is_set((BS), i) ? '1' : '0'; \
     buf[i] = '\0';                                 \
     DBUG_PRINT((N), ((FRM), buf));                 \

=== modified file 'sql/set_var.cc'
--- a/sql/set_var.cc	2011-08-17 14:07:07 +0000
+++ b/sql/set_var.cc	2011-10-11 04:27:52 +0000
@@ -77,10 +77,8 @@ error:
   DBUG_RETURN(1);
 }
 
-int sys_var_add_options(DYNAMIC_ARRAY *long_options, int parse_flags)
+int sys_var_add_options(std::vector<my_option> *long_options, int parse_flags)
 {
-  uint saved_elements= long_options->elements;
-
   DBUG_ENTER("sys_var_add_options");
 
   for (sys_var *var=all_sys_vars.first; var; var= var->next)
@@ -93,7 +91,6 @@ int sys_var_add_options(DYNAMIC_ARRAY *l
 
 error:
   fprintf(stderr, "failed to initialize System variables");
-  long_options->elements= saved_elements;
   DBUG_RETURN(1);
 }
 

=== modified file 'sql/set_var.h'
--- a/sql/set_var.h	2011-08-17 14:07:07 +0000
+++ b/sql/set_var.h	2011-10-11 04:27:52 +0000
@@ -21,6 +21,7 @@
 */
 
 #include <my_getopt.h>
+#include <vector>
 
 class sys_var;
 class set_var;
@@ -127,10 +128,10 @@ public:
     }
     return true; // keep gcc happy
   }
-  bool register_option(DYNAMIC_ARRAY *array, int parse_flags)
+  bool register_option(std::vector<my_option> *array, int parse_flags)
   {
     return (option.id != -1) && (m_parse_flag & parse_flags) &&
-           insert_dynamic(array, &option);
+      (array->push_back(option), false);
   }
 
 private:
@@ -331,7 +332,7 @@ extern sys_var *Sys_autocommit_ptr;
 const CHARSET_INFO *get_old_charset_by_name(const char *old_name);
 
 int sys_var_init();
-int sys_var_add_options(DYNAMIC_ARRAY *long_options, int parse_flags);
+int sys_var_add_options(std::vector<my_option> *long_options, int parse_flags);
 void sys_var_end(void);
 
 #endif

=== modified file 'sql/sp_head.cc'
--- a/sql/sp_head.cc	2011-10-31 11:52:20 +0000
+++ b/sql/sp_head.cc	2011-11-03 16:03:34 +0000
@@ -39,6 +39,11 @@
 #include "transaction.h"       // trans_commit_stmt
 #include "opt_trace.h"         // opt_trace_disable_etc
 
+#include <algorithm>
+
+using std::min;
+using std::max;
+
 /*
   Sufficient max length of printed destinations and frame offsets (all uints).
 */
@@ -2589,8 +2594,7 @@ sp_head::show_create_routine(THD *thd, i
     */
 
     Item_empty_string *stmt_fld=
-      new Item_empty_string(col3_caption,
-                            max(m_defstr.length, 1024));
+      new Item_empty_string(col3_caption, max<size_t>(m_defstr.length, 1024U));
 
     stmt_fld->maybe_null= TRUE;
 
@@ -2790,7 +2794,7 @@ sp_head::show_routine_code(THD *thd)
   field_list.push_back(new Item_uint("Pos", 9));
   // 1024 is for not to confuse old clients
   field_list.push_back(new Item_empty_string("Instruction",
-                                             max(buffer.length(), 1024)));
+                                             max(buffer.length(), 1024U)));
   if (protocol->send_result_set_metadata(&field_list, Protocol::SEND_NUM_ROWS |
                                          Protocol::SEND_EOF))
     DBUG_RETURN(1);

=== modified file 'sql/spatial.h'
--- a/sql/spatial.h	2011-06-30 15:50:45 +0000
+++ b/sql/spatial.h	2011-10-11 04:27:52 +0000
@@ -23,6 +23,8 @@
 
 #include "gcalc_tools.h"
 
+#include <algorithm>
+
 const uint SRID_SIZE= 4;
 const uint SIZEOF_STORED_DOUBLE= 8;
 const uint POINT_DATA_SIZE= SIZEOF_STORED_DOUBLE*2; 
@@ -185,6 +187,8 @@ struct MBR
     if (d != mbr->dimension() || d <= 0 || contains(mbr) || within(mbr))
       return 0;
 
+    using std::min;
+    using std::max;
     MBR intersection(max(xmin, mbr->xmin), max(ymin, mbr->ymin),
                      min(xmax, mbr->xmax), min(ymax, mbr->ymax));
 

=== modified file 'sql/sql_acl.cc'
--- a/sql/sql_acl.cc	2011-10-27 08:43:56 +0000
+++ b/sql/sql_acl.cc	2011-10-28 12:45:35 +0000
@@ -50,6 +50,9 @@
 #include "hostname.h"
 #include "sql_db.h"
 
+using std::min;
+using std::max;
+
 bool mysql_user_table_is_in_short_password_format= false;
 
 static const
@@ -1271,7 +1274,7 @@ static ulong get_sort(uint count,...)
         chars= 128;                             // Marker that chars existed
       }
     }
-    sort= (sort << 8) + (wild_pos ? min(wild_pos, 127) : chars);
+    sort= (sort << 8) + (wild_pos ? min(wild_pos, 127U) : chars);
   }
   va_end(args);
   return sort;

=== modified file 'sql/sql_analyse.cc'
--- a/sql/sql_analyse.cc	2011-07-04 00:25:46 +0000
+++ b/sql/sql_analyse.cc	2011-08-29 12:08:58 +0000
@@ -30,6 +30,9 @@
 #include "sql_analyse.h"
 #include <m_ctype.h>
 
+using std::min;
+using std::max;
+
 #define MAX_TREEMEM	  8192
 #define MAX_TREE_ELEMENTS 256
 
@@ -277,16 +280,16 @@ bool get_ev_num_info(EV_NUM_INFO *ev_inf
   {
     if (((longlong) info->ullval) < 0)
       return 0; // Impossible to store as a negative number
-    ev_info->llval =  -(longlong) max((ulonglong) -ev_info->llval, 
-				      info->ullval);
-    ev_info->min_dval = (double) -max(-ev_info->min_dval, info->dval);
+    ev_info->llval =  - max<longlong>((ulonglong) -ev_info->llval, 
+                                           info->ullval);
+    ev_info->min_dval = - max<double>(-ev_info->min_dval, info->dval);
   }
   else		// ulonglong is as big as bigint in MySQL
   {
     if ((check_ulonglong(num, info->integers) == DECIMAL_NUM))
       return 0;
-    ev_info->ullval = (ulonglong) max(ev_info->ullval, info->ullval);
-    ev_info->max_dval =  (double) max(ev_info->max_dval, info->dval);
+    ev_info->ullval = max<ulonglong>(ev_info->ullval, info->ullval);
+    ev_info->max_dval = max<double>(ev_info->max_dval, info->dval);
   }
   return 1;
 } // get_ev_num_info
@@ -1177,7 +1180,7 @@ bool analyse::change_columns(List<Item>
   func_items[8] = new Item_proc_string("Std", 255);
   func_items[8]->maybe_null = 1;
   func_items[9] = new Item_proc_string("Optimal_fieldtype",
-				       max(64, output_str_length));
+				       max(64U, output_str_length));
 
   for (uint i = 0; i < array_elements(func_items); i++)
     field_list.push_back(func_items[i]);

=== modified file 'sql/sql_cache.cc'
--- a/sql/sql_cache.cc	2011-10-05 13:16:38 +0000
+++ b/sql/sql_cache.cc	2011-10-13 07:26:28 +0000
@@ -348,6 +348,9 @@ TODO list:
 #include "emb_qcache.h"
 #endif
 
+using std::min;
+using std::max;
+
 #if !defined(EXTRA_DBUG) && !defined(DBUG_OFF)
 #define RW_WLOCK(M) {DBUG_PRINT("lock", ("rwlock wlock 0x%lx",(ulong)(M))); \
   if (!mysql_rwlock_wrlock(M)) DBUG_PRINT("lock", ("rwlock wlock ok")); \
@@ -3136,11 +3139,11 @@ void Query_cache::unlink_table(Query_cac
 *****************************************************************************/
 
 Query_cache_block *
-Query_cache::allocate_block(ulong len, my_bool not_less, ulong min)
+Query_cache::allocate_block(ulong len, my_bool not_less, ulong minimum)
 {
   DBUG_ENTER("Query_cache::allocate_block");
   DBUG_PRINT("qcache", ("len %lu, not less %d, min %lu",
-             len, not_less,min));
+             len, not_less, minimum));
 
   if (len >= min(query_cache_size, query_cache_limit))
   {
@@ -3153,7 +3156,7 @@ Query_cache::allocate_block(ulong len, m
   Query_cache_block *block;
   do
   {
-    block= get_free_block(len, not_less, min);
+    block= get_free_block(len, not_less, minimum);
   }
   while (block == 0 && !free_old_query());
 

=== modified file 'sql/sql_class.cc'
--- a/sql/sql_class.cc	2011-11-01 16:33:58 +0000
+++ b/sql/sql_class.cc	2011-11-03 16:03:34 +0000
@@ -60,6 +60,9 @@
 
 #include <mysql/psi/mysql_statement.h>
 
+using std::min;
+using std::max;
+
 /*
   The following is used to initialise Table_ident with a internal
   table name

=== modified file 'sql/sql_client.cc'
--- a/sql/sql_client.cc	2011-06-30 15:50:45 +0000
+++ b/sql/sql_client.cc	2011-08-29 12:08:58 +0000
@@ -20,6 +20,11 @@
 #include "sql_priv.h"
 #include "sql_class.h"                          // system_variables
 
+#include <algorithm>
+
+using std::min;
+using std::max;
+
 /*
   Function called by my_net_init() to set some check variables
 */
@@ -35,8 +40,8 @@ void my_net_local_init(NET *net)
                            (uint)global_system_variables.net_write_timeout);
 
   net->retry_count=  (uint) global_system_variables.net_retry_count;
-  net->max_packet_size= max(global_system_variables.net_buffer_length,
-			    global_system_variables.max_allowed_packet);
+  net->max_packet_size= max<size_t>(global_system_variables.net_buffer_length,
+                                    global_system_variables.max_allowed_packet);
 #endif
 }
 }

=== modified file 'sql/sql_connect.cc'
--- a/sql/sql_connect.cc	2011-07-08 21:31:33 +0000
+++ b/sql/sql_connect.cc	2011-08-29 12:08:58 +0000
@@ -35,6 +35,11 @@
 #include "sql_acl.h"  // acl_getroot, NO_ACCESS, SUPER_ACL
 #include "sql_callback.h"
 
+#include <algorithm>
+
+using std::min;
+using std::max;
+
 #if defined(HAVE_OPENSSL) && !defined(EMBEDDED_LIBRARY)
 /*
   Without SSL the handshake consists of one packet. This packet
@@ -483,8 +488,8 @@ static int check_connection(THD *thd)
       if (thd->main_security_ctx.host)
       {
         if (thd->main_security_ctx.host != my_localhost)
-          thd->main_security_ctx.host[min(strlen(thd->main_security_ctx.host),
-                                          HOSTNAME_LENGTH)]= 0;
+          thd->main_security_ctx.host[min<size_t>(strlen(thd->main_security_ctx.host),
+                                                  HOSTNAME_LENGTH)]= 0;
         thd->main_security_ctx.host_or_ip= thd->main_security_ctx.host;
       }
       if (connect_errors > max_connect_errors)

=== modified file 'sql/sql_const.h'
--- a/sql/sql_const.h	2011-10-31 08:11:22 +0000
+++ b/sql/sql_const.h	2011-11-03 16:03:34 +0000
@@ -30,8 +30,8 @@
 #define MAX_FIELD_NAME 34			/* Max colum name length +2 */
 #define MAX_SYS_VAR_LENGTH 32
 #define MAX_KEY MAX_INDEXES                     /* Max used keys */
-#define MAX_REF_PARTS 16			/* Max parts used as ref */
-#define MAX_KEY_LENGTH 3072			/* max possible key */
+#define MAX_REF_PARTS 16U			/* Max parts used as ref */
+#define MAX_KEY_LENGTH 3072U			/* max possible key */
 #if SIZEOF_OFF_T > 4
 #define MAX_REFLENGTH 8				/* Max length for record ref */
 #else

=== modified file 'sql/sql_error.cc'
--- a/sql/sql_error.cc	2011-10-14 15:38:24 +0000
+++ b/sql/sql_error.cc	2011-10-28 12:45:35 +0000
@@ -46,6 +46,9 @@ This file contains the implementation of
 #include "sql_error.h"
 #include "sp_rcontext.h"
 
+using std::min;
+using std::max;
+
 /*
   Design notes about Sql_condition::m_message_text.
 

=== modified file 'sql/sql_join_cache.cc'
--- a/sql/sql_join_cache.cc	2011-10-26 13:23:01 +0000
+++ b/sql/sql_join_cache.cc	2011-11-03 16:03:34 +0000
@@ -27,6 +27,10 @@
 #include "sql_select.h"
 #include "key.h"
 
+#include <algorithm>
+using std::max;
+using std::min;
+
 
 /*****************************************************************************
  *  Join cache module
@@ -419,7 +423,7 @@ void JOIN_CACHE::set_constants()
   uint len= length + fields*sizeof(uint)+blobs*sizeof(uchar *) +
             (prev_cache ? prev_cache->get_size_of_rec_offset() : 0) +
             sizeof(ulong);
-  buff_size= max(join->thd->variables.join_buff_size, 2*len);
+  buff_size= max<size_t>(join->thd->variables.join_buff_size, 2*len);
   size_of_rec_ofs= offset_size(buff_size);
   size_of_rec_len= blobs ? size_of_rec_ofs : offset_size(len); 
   size_of_fld_ofs= size_of_rec_len;
@@ -2596,7 +2600,7 @@ int JOIN_CACHE_BKA_UNIQUE::init()
   pack_length+= get_size_of_rec_offset(); 
  
   /* Calculate the minimal possible value of size_of_key_ofs greater than 1 */
-  uint max_size_of_key_ofs= max(2, get_size_of_rec_offset());  
+  uint max_size_of_key_ofs= max(2U, get_size_of_rec_offset());  
   for (size_of_key_ofs= 2;
        size_of_key_ofs <= max_size_of_key_ofs;
        size_of_key_ofs+= 2)

=== modified file 'sql/sql_load.cc'
--- a/sql/sql_load.cc	2011-07-28 10:54:44 +0000
+++ b/sql/sql_load.cc	2011-08-29 12:08:58 +0000
@@ -39,6 +39,11 @@
 #include "sp_head.h"
 #include "sql_trigger.h"
 
+#include <algorithm>
+
+using std::min;
+using std::max;
+
 class XML_TAG {
 public:
   int level;

=== modified file 'sql/sql_parse.cc'
--- a/sql/sql_parse.cc	2011-11-02 18:11:26 +0000
+++ b/sql/sql_parse.cc	2011-11-03 16:03:34 +0000
@@ -98,6 +98,10 @@
 #include "opt_explain.h"
 #include "sql_rewrite.h"
 
+#include <algorithm>
+using std::max;
+using std::min;
+
 #define FLAGSTR(V,F) ((V)&(F)?#F" ":"")
 
 /**
@@ -5425,7 +5429,7 @@ bool check_stack_overrun(THD *thd, long
       Do not use stack for the message buffer to ensure correct
       behaviour in cases we have close to no stack left.
     */
-    char* ebuff= new char[MYSQL_ERRMSG_SIZE];
+    char* ebuff= new (std::nothrow) char[MYSQL_ERRMSG_SIZE];
     if (ebuff) {
       my_snprintf(ebuff, MYSQL_ERRMSG_SIZE, ER(ER_STACK_OVERRUN_NEED_MORE),
                   stack_used, my_thread_stack_size, margin);
@@ -6785,7 +6789,7 @@ bool check_simple_select()
     char command[80];
     Lex_input_stream *lip= & thd->m_parser_state->m_lip;
     strmake(command, lip->yylval->symbol.str,
-	    min(lip->yylval->symbol.length, sizeof(command)-1));
+	    min<size_t>(lip->yylval->symbol.length, sizeof(command)-1));
     my_error(ER_CANT_USE_OPTION_HERE, MYF(0), command);
     return 1;
   }

=== modified file 'sql/sql_partition.cc'
--- a/sql/sql_partition.cc	2011-07-28 10:54:44 +0000
+++ b/sql/sql_partition.cc	2011-08-29 12:08:58 +0000
@@ -68,6 +68,10 @@
 #include "opt_range.h"                  // store_key_image_to_rec
 #include "sql_analyse.h"                // append_escaped
 
+#include <algorithm>
+using std::max;
+using std::min;
+
 #ifdef WITH_PARTITION_STORAGE_ENGINE
 #include "ha_partition.h"
 

=== modified file 'sql/sql_plugin.cc'
--- a/sql/sql_plugin.cc	2011-10-27 08:43:56 +0000
+++ b/sql/sql_plugin.cc	2011-10-28 12:45:35 +0000
@@ -33,6 +33,12 @@
 #include "sql_audit.h"
 #include <mysql/plugin_auth.h>
 #include "lock.h"                               // MYSQL_LOCK_IGNORE_TIMEOUT
+
+#include <algorithm>
+
+using std::min;
+using std::max;
+
 #define REPORT_TO_LOG  1
 #define REPORT_TO_USER 2
 
@@ -566,7 +572,7 @@ static st_plugin_dl *plugin_dl_add(const
     for (i=0;
          (old=(struct st_mysql_plugin *)(ptr+i*sizeof_st_plugin))->info;
          i++)
-      memcpy(cur+i, old, min(sizeof(cur[i]), sizeof_st_plugin));
+      memcpy(cur+i, old, min<size_t>(sizeof(cur[i]), sizeof_st_plugin));
 
     sym= cur;
   }
@@ -3547,7 +3553,7 @@ err:
 ****************************************************************************/
 
 
-void add_plugin_options(DYNAMIC_ARRAY *options, MEM_ROOT *mem_root)
+void add_plugin_options(std::vector<my_option> *options, MEM_ROOT *mem_root)
 {
   struct st_plugin_int *p;
   my_option *opt;
@@ -3565,7 +3571,7 @@ void add_plugin_options(DYNAMIC_ARRAY *o
     /* Only options with a non-NULL comment are displayed in help text */
     for (;opt->name; opt++)
       if (opt->comment)
-        insert_dynamic(options, opt);
+        options->push_back(*opt);
   }
 }
 

=== modified file 'sql/sql_plugin.h'
--- a/sql/sql_plugin.h	2011-08-18 08:31:08 +0000
+++ b/sql/sql_plugin.h	2011-10-17 10:28:01 +0000
@@ -17,6 +17,7 @@
 #define _sql_plugin_h
 
 #include <my_global.h>
+#include <vector>
 
 /**
   the following #define adds server-only members to enum_mysql_show_type,
@@ -32,6 +33,7 @@
 
 #include "m_string.h"                       /* LEX_STRING */
 #include "my_alloc.h"                       /* MEM_ROOT */
+#include "my_getopt.h"                      /* my_option */
 
 class sys_var;
 enum SHOW_COMP_OPTION { SHOW_OPTION_YES, SHOW_OPTION_NO, SHOW_OPTION_DISABLED};
@@ -139,7 +141,7 @@ extern const LEX_STRING plugin_type_name
 
 extern int plugin_init(int *argc, char **argv, int init_flags);
 extern void plugin_shutdown(void);
-void add_plugin_options(DYNAMIC_ARRAY *options, MEM_ROOT *mem_root);
+void add_plugin_options(std::vector<my_option> *options, MEM_ROOT *mem_root);
 extern bool plugin_is_ready(const LEX_STRING *name, int type);
 #define my_plugin_lock_by_name(A,B,C) plugin_lock_by_name(A,B,C)
 #define my_plugin_lock_by_name_ci(A,B,C) plugin_lock_by_name(A,B,C)

=== modified file 'sql/sql_prepare.cc'
--- a/sql/sql_prepare.cc	2011-09-08 12:48:08 +0000
+++ b/sql/sql_prepare.cc	2011-10-13 07:26:28 +0000
@@ -116,6 +116,10 @@ When one supplies long data for a placeh
 #include "lock.h"                               // MYSQL_OPEN_FORCE_SHARED_MDL
 #include "opt_trace.h"                          // Opt_trace_object
 
+#include <algorithm>
+using std::max;
+using std::min;
+
 /**
   A result class used to send cursor rows using the binary protocol.
 */
@@ -341,7 +345,7 @@ static bool send_prep_stmt(Prepared_stat
   int2store(buff+5, columns);
   int2store(buff+7, stmt->param_count);
   buff[9]= 0;                                   // Guard against a 4.1 client
-  tmp= min(stmt->thd->get_stmt_da()->current_statement_warn_count(), 65535);
+  tmp= min(stmt->thd->get_stmt_da()->current_statement_warn_count(), 65535UL);
   int2store(buff+10, tmp);
 
   /*

=== modified file 'sql/sql_profile.cc'
--- a/sql/sql_profile.cc	2011-07-20 07:19:42 +0000
+++ b/sql/sql_profile.cc	2011-08-29 12:08:58 +0000
@@ -36,11 +36,16 @@
 #include "sql_show.h"                     // schema_table_store_record
 #include "sql_class.h"                    // THD
 
+#include <algorithm>
+
+using std::min;
+using std::max;
+
 #define TIME_FLOAT_DIGITS 9
 /** two vals encoded: (dec*100)+len */
 #define TIME_I_S_DECIMAL_SIZE (TIME_FLOAT_DIGITS*100)+(TIME_FLOAT_DIGITS-3)
 
-#define MAX_QUERY_LENGTH 300
+#define MAX_QUERY_LENGTH 300U
 
 /**
   Connects Information_Schema and Profiling.

=== modified file 'sql/sql_select.cc'
--- a/sql/sql_select.cc	2011-10-31 08:11:22 +0000
+++ b/sql/sql_select.cc	2011-11-03 16:03:34 +0000
@@ -53,6 +53,11 @@
 
 #define PREV_BITS(type,A)	((type) (((type) 1 << (A)) -1))
 
+#include <algorithm>
+using std::max;
+using std::min;
+
+
 const char *join_type_str[]={ "UNKNOWN","system","const","eq_ref","ref",
 			      "ALL","range","index","fulltext",
 			      "ref_or_null","unique_subquery","index_subquery",
@@ -6809,7 +6814,7 @@ update_ref_and_keys(THD *thd, Key_use_ar
   uint	and_level,i,found_eq_constant;
   KEY_FIELD *key_fields, *end, *field;
   uint sz;
-  uint m= max(select_lex->max_equal_elems,1);
+  uint m= max(select_lex->max_equal_elems, 1U);
   
   /* 
     We use the same piece of memory to store both  KEY_FIELD 
@@ -7003,7 +7008,7 @@ static void optimize_keyuse(JOIN *join,
       if (map == 1)			// Only one table
       {
 	TABLE *tmp_table=join->all_tables[tablenr];
-	keyuse->ref_table_rows= max(tmp_table->file->stats.records, 100);
+	keyuse->ref_table_rows= max<ha_rows>(tmp_table->file->stats.records, 100);
       }
     }
     /*
@@ -9614,7 +9619,7 @@ void calc_used_field_length(THD *thd, JO
   {
     uint blob_length=(uint) (join_tab->table->file->stats.mean_rec_length-
 			     (join_tab->table->s->reclength- rec_length));
-    rec_length+=(uint) max(4,blob_length);
+    rec_length+= max<uint>(4U, blob_length);
   }
   /**
     @todo why don't we count the rowids that we might need to store

=== modified file 'sql/sql_select.h'
--- a/sql/sql_select.h	2011-10-26 13:23:01 +0000
+++ b/sql/sql_select.h	2011-11-03 16:03:34 +0000
@@ -960,7 +960,8 @@ protected:
   /* Shall calculate how much space is remaining in the join buffer */ 
   virtual ulong rem_space() 
   { 
-    return max(buff_size-(end_pos-buff)-aux_buff_size,0);
+    using std::max;
+    return max(buff_size-(end_pos-buff)-aux_buff_size, 0UL);
   }
 
   /* Shall skip record from the join buffer if its match flag is on */
@@ -1444,7 +1445,8 @@ protected:
   */ 
   ulong rem_space() 
   { 
-    return max(last_key_entry-end_pos-aux_buff_size,0);
+    using std::max;
+    return max(last_key_entry-end_pos-aux_buff_size, 0UL);
   }
 
   /* 

=== modified file 'sql/sql_show.cc'
--- a/sql/sql_show.cc	2011-10-06 11:06:34 +0000
+++ b/sql/sql_show.cc	2011-10-13 07:26:28 +0000
@@ -56,6 +56,10 @@
 #include "datadict.h"   // dd_frm_type()
 #include "opt_trace.h"     // Optimizer trace information schema tables
 
+#include <algorithm>
+using std::max;
+using std::min;
+
 #define STR_OR_NIL(S) ((S) ? (S) : "<nil>")
 
 #ifdef WITH_PARTITION_STORAGE_ENGINE
@@ -942,7 +946,7 @@ mysqld_show_create(THD *thd, TABLE_LIST
   {
     field_list.push_back(new Item_empty_string("View",NAME_CHAR_LEN));
     field_list.push_back(new Item_empty_string("Create View",
-                                               max(buffer.length(),1024)));
+                                               max(buffer.length(), 1024U)));
     field_list.push_back(new Item_empty_string("character_set_client",
                                                MY_CS_NAME_SIZE));
     field_list.push_back(new Item_empty_string("collation_connection",
@@ -953,7 +957,7 @@ mysqld_show_create(THD *thd, TABLE_LIST
     field_list.push_back(new Item_empty_string("Table",NAME_CHAR_LEN));
     // 1024 is for not to confuse old clients
     field_list.push_back(new Item_empty_string("Create Table",
-                                               max(buffer.length(),1024)));
+                                               max(buffer.length(), 1024U)));
   }
 
   if (protocol->send_result_set_metadata(&field_list,
@@ -2067,7 +2071,7 @@ void mysqld_list_processes(THD *thd,cons
         /* Lock THD mutex that protects its data when looking at it. */
         if (tmp->query())
         {
-          uint length= min(max_query_length, tmp->query_length());
+          uint length= min<uint>(max_query_length, tmp->query_length());
           char *q= thd->strmake(tmp->query(),length);
           /* Safety: in case strmake failed, we set length to 0. */
           thd_info->query_string=
@@ -2190,9 +2194,9 @@ int fill_schema_processlist(THD* thd, TA
       mysql_mutex_lock(&tmp->LOCK_thd_data);
       if (tmp->query())
       {
-        table->field[7]->store(tmp->query(),
-                               min(PROCESS_LIST_INFO_WIDTH,
-                                   tmp->query_length()), cs);
+        size_t const width=
+          min<size_t>(PROCESS_LIST_INFO_WIDTH, tmp->query_length());
+        table->field[7]->store(tmp->query(), width, cs);
         table->field[7]->set_notnull();
       }
       mysql_mutex_unlock(&tmp->LOCK_thd_data);
@@ -8071,7 +8075,7 @@ static bool show_create_trigger_impl(THD
 
     Item_empty_string *stmt_fld=
       new Item_empty_string("SQL Original Statement",
-                            max(trg_sql_original_stmt.length, 1024));
+                            max<size_t>(trg_sql_original_stmt.length, 1024));
 
     stmt_fld->maybe_null= TRUE;
 

=== modified file 'sql/sql_string.cc'
--- a/sql/sql_string.cc	2011-10-31 09:13:54 +0000
+++ b/sql/sql_string.cc	2011-11-03 16:03:34 +0000
@@ -23,6 +23,11 @@
 
 #include "sql_string.h"
 
+#include <algorithm>
+
+using std::min;
+using std::max;
+
 /*****************************************************************************
 ** String functions
 *****************************************************************************/

=== modified file 'sql/sql_table.cc'
--- a/sql/sql_table.cc	2011-11-01 06:53:43 +0000
+++ b/sql/sql_table.cc	2011-11-03 16:03:34 +0000
@@ -58,6 +58,10 @@
 #include <io.h>
 #endif
 
+#include <algorithm>
+using std::max;
+using std::min;
+
 const char *primary_key_name="PRIMARY";
 
 static bool check_if_keyname_exists(const char *name,KEY *start, KEY *end);

=== modified file 'sql/sql_table.h'
--- a/sql/sql_table.h	2011-07-28 08:55:05 +0000
+++ b/sql/sql_table.h	2011-10-11 04:27:52 +0000
@@ -17,7 +17,8 @@
 #define SQL_TABLE_INCLUDED
 
 #include "my_global.h"                          /* my_bool */
-#include "my_sys.h"                             // pthread_mutex_t
+#include "my_pthread.h"
+#include "m_ctype.h"                            /* CHARSET_INFO */
 
 class Alter_info;
 class Create_field;

=== modified file 'sql/sql_yacc.yy'
--- a/sql/sql_yacc.yy	2011-10-14 15:38:24 +0000
+++ b/sql/sql_yacc.yy	2011-10-28 12:45:35 +0000
@@ -71,6 +71,9 @@
 #pragma warning (disable : 4065)
 #endif
 
+using std::min;
+using std::max;
+
 int yylex(void *yylval, void *yythd);
 
 #define yyoverflow(A,B,C,D,E,F)               \
@@ -2125,7 +2128,7 @@ master_file_def:
                from 0" (4 in fact), unspecified means "don't change the position
                (keep the preceding value)").
             */
-            Lex->mi.pos = max(BIN_LOG_HEADER_SIZE, Lex->mi.pos);
+            Lex->mi.pos = max<ulonglong>(BIN_LOG_HEADER_SIZE, Lex->mi.pos);
           }
         | RELAY_LOG_FILE_SYM EQ TEXT_STRING_sys
           {
@@ -2135,7 +2138,8 @@ master_file_def:
           {
             Lex->mi.relay_log_pos = $3;
             /* Adjust if < BIN_LOG_HEADER_SIZE (same comment as Lex->mi.pos) */
-            Lex->mi.relay_log_pos = max(BIN_LOG_HEADER_SIZE, Lex->mi.relay_log_pos);
+            Lex->mi.relay_log_pos = max<ulong>(BIN_LOG_HEADER_SIZE,
+                                               Lex->mi.relay_log_pos);
           }
         ;
 

=== modified file 'sql/thr_malloc.cc'
--- a/sql/thr_malloc.cc	2011-06-30 15:50:45 +0000
+++ b/sql/thr_malloc.cc	2011-08-29 12:08:58 +0000
@@ -21,6 +21,11 @@
 #include "thr_malloc.h"
 #include "sql_class.h"
 
+#include <algorithm>
+
+using std::min;
+using std::max;
+
 extern "C" void sql_alloc_error_handler(void);
 
 void init_sql_alloc(MEM_ROOT *mem_root, uint block_size, uint pre_alloc)

=== modified file 'sql/tztime.cc'
--- a/sql/tztime.cc	2011-06-30 15:50:45 +0000
+++ b/sql/tztime.cc	2011-10-11 04:27:52 +0000
@@ -25,6 +25,8 @@
 */
 
 #include <my_global.h>
+#include <algorithm>
+
 #if !defined(TZINFO2SQL) && !defined(TESTTIME)
 #include "sql_priv.h"
 #include "unireg.h"
@@ -42,8 +44,8 @@
 #include <m_string.h>
 #include <my_dir.h>
 #include <mysql/psi/mysql_file.h>
-#include "lock.h"                               // MYSQL_LOCK_IGNORE_FLUSH,
-                                                // MYSQL_LOCK_IGNORE_TIMEOUT
+
+using std::min;
 
 /*
   Now we don't use abbreviations in server but we will do this in future.
@@ -171,7 +173,7 @@ tz_load(const char *name, TIME_ZONE_INFO
       uchar buf[sizeof(struct tzhead) + sizeof(my_time_t) * TZ_MAX_TIMES +
                 TZ_MAX_TIMES + sizeof(TRAN_TYPE_INFO) * TZ_MAX_TYPES +
 #ifdef ABBR_ARE_USED
-               max(TZ_MAX_CHARS + 1, (2 * (MY_TZNAME_MAX + 1))) +
+               MY_MAX(TZ_MAX_CHARS + 1, (2 * (MY_TZNAME_MAX + 1))) +
 #endif
                sizeof(LS_INFO) * TZ_MAX_LEAPS];
     } u;
@@ -1857,7 +1859,7 @@ tz_load_from_open_tables(const String *t
   uchar types[TZ_MAX_TIMES];
   TRAN_TYPE_INFO ttis[TZ_MAX_TYPES];
 #ifdef ABBR_ARE_USED
-  char chars[max(TZ_MAX_CHARS + 1, (2 * (MY_TZNAME_MAX + 1)))];
+  char chars[MY_MAX(TZ_MAX_CHARS + 1, (2 * (MY_TZNAME_MAX + 1)))];
 #endif
   /* 
     Used as a temporary tz_info until we decide that we actually want to

=== renamed file 'sql/udf_example.c' => 'sql/udf_example.cc'
--- a/sql/udf_example.c	2011-10-10 06:59:58 +0000
+++ b/sql/udf_example.cc	2011-10-13 07:26:28 +0000
@@ -111,21 +111,13 @@
 **
 */
 
-#ifdef STANDARD
-/* STANDARD is defined, don't use any mysql functions */
-#include <stdlib.h>
-#include <stdio.h>
-#include <string.h>
-#ifdef __WIN__
-typedef unsigned __int64 ulonglong;	/* Microsofts 64 bit types */
-typedef __int64 longlong;
-#else
-typedef unsigned long long ulonglong;
-typedef long long longlong;
-#endif /*__WIN__*/
-#else
 #include <my_global.h>
 #include <my_sys.h>
+
+#include <new>
+#include <vector>
+#include <algorithm>
+
 #if defined(MYSQL_SERVER)
 #include <m_string.h>		/* To get strmov() */
 #else
@@ -133,7 +125,7 @@ typedef long long longlong;
 #include <string.h>
 #define strmov(a,b) stpcpy(a,b)
 #endif
-#endif
+
 #include <mysql.h>
 #include <ctype.h>
 
@@ -150,6 +142,7 @@ static pthread_mutex_t LOCK_hostname;
 
 /* These must be right or mysqld will not find the symbol! */
 
+C_MODE_START;
 my_bool metaphon_init(UDF_INIT *initid, UDF_ARGS *args, char *message);
 void metaphon_deinit(UDF_INIT *initid);
 char *metaphon(UDF_INIT *initid, UDF_ARGS *args, char *result,
@@ -173,7 +166,7 @@ double avgcost( UDF_INIT* initid, UDF_AR
 my_bool is_const_init(UDF_INIT *initid, UDF_ARGS *args, char *message);
 char *is_const(UDF_INIT *initid, UDF_ARGS *args, char *result, unsigned long
                *length, char *is_null, char *error);
-
+C_MODE_END;
 
 /*************************************************************************
 ** Example of init function
@@ -696,6 +689,7 @@ longlong sequence(UDF_INIT *initid __att
 #include <netdb.h>
 #endif
 
+C_MODE_START;
 my_bool lookup_init(UDF_INIT *initid, UDF_ARGS *args, char *message);
 void lookup_deinit(UDF_INIT *initid);
 char *lookup(UDF_INIT *initid, UDF_ARGS *args, char *result,
@@ -704,6 +698,7 @@ my_bool reverse_lookup_init(UDF_INIT *in
 void reverse_lookup_deinit(UDF_INIT *initid);
 char *reverse_lookup(UDF_INIT *initid, UDF_ARGS *args, char *result,
 		     unsigned long *length, char *null_value, char *error);
+C_MODE_END;
 
 
 /****************************************************************************
@@ -939,7 +934,7 @@ avgcost_init( UDF_INIT* initid, UDF_ARGS
   initid->decimals	= 4;		/* We want 4 decimals in the result */
   initid->max_length	= 20;		/* 6 digits + . + 10 decimals */
 
-  if (!(data = (struct avgcost_data*) malloc(sizeof(struct avgcost_data))))
+  if (!(data = new (std::nothrow) avgcost_data))
   {
     strmov(message,"Couldn't allocate memory");
     return 1;
@@ -955,7 +950,9 @@ avgcost_init( UDF_INIT* initid, UDF_ARGS
 void
 avgcost_deinit( UDF_INIT* initid )
 {
-  free(initid->ptr);
+  void *void_ptr= initid->ptr;
+  avgcost_data *data= static_cast<avgcost_data*>(void_ptr);
+  delete data;
 }
 
 
@@ -1110,6 +1107,7 @@ char * is_const(UDF_INIT *initid, UDF_AR
 
 
 
+extern "C"
 my_bool check_const_len_init(UDF_INIT *initid, UDF_ARGS *args, char *message)
 {
   if (args->arg_count != 1)
@@ -1133,6 +1131,7 @@ my_bool check_const_len_init(UDF_INIT *i
   return 0;
 }
 
+extern "C"
 char * check_const_len(UDF_INIT *initid, UDF_ARGS *args __attribute__((unused)),
                 char *result, unsigned long *length,
                 char *is_null, char *error __attribute__((unused)))
@@ -1144,4 +1143,79 @@ char * check_const_len(UDF_INIT *initid,
 }
 
 
+C_MODE_START;
+my_bool  my_median_init  (UDF_INIT *initid, UDF_ARGS *args, char *message);
+void     my_median_deinit(UDF_INIT* initid);
+void     my_median_add   (UDF_INIT* initid, UDF_ARGS* args,
+                          char* is_null, char *error);
+void     my_median_clear (UDF_INIT* initid, UDF_ARGS* args,
+                          char* is_null, char *error);
+longlong my_median       (UDF_INIT* initid, UDF_ARGS* args,
+                          char* is_null, char *error);
+C_MODE_END;
+
+struct My_median_data
+{
+  std::vector<longlong> vec;
+};
+
+
+my_bool  my_median_init  (UDF_INIT *initid, UDF_ARGS *args, char *message)
+{
+  My_median_data *data= new (std::nothrow) My_median_data;
+  if (!data)
+  {
+    strmov(message,"Could not allocate memory");
+    return true;
+  }
+  initid->ptr= static_cast<char*>(static_cast<void*>(data));
+  return false;
+}
+
+void my_median_deinit(UDF_INIT* initid)
+{
+  My_median_data *data=
+    static_cast<My_median_data*>(static_cast<void*>(initid->ptr));
+  delete data;
+}
+
+void my_median_add(UDF_INIT* initid, UDF_ARGS* args,
+                   char* is_null __attribute__((unused)),
+                   char* message __attribute__((unused)))
+{
+  My_median_data *data=
+    static_cast<My_median_data*>(static_cast<void*>(initid->ptr));
+  if (args->args[0])
+  {
+    void *arg0= args->args[0];
+    longlong number= *(static_cast<longlong*>(arg0));
+    data->vec.push_back(number);
+  }
+}
+
+void my_median_clear(UDF_INIT* initid, UDF_ARGS* args,
+                     char* is_null __attribute__((unused)),
+                     char* message __attribute__((unused)))
+{
+  My_median_data *data=
+    static_cast<My_median_data*>(static_cast<void*>(initid->ptr));
+  data->vec.clear();
+}
+
+longlong my_median(UDF_INIT* initid, UDF_ARGS* args,
+                   char* is_null,
+                   char* message __attribute__((unused)))
+{
+  My_median_data *data=
+    static_cast<My_median_data*>(static_cast<void*>(initid->ptr));
+  if (data->vec.size() == 0)
+  {
+    *is_null= 1;
+    return 0;
+  }
+  const size_t ix= data->vec.size() / 2;
+  std::nth_element(data->vec.begin(), data->vec.begin() + ix, data->vec.end());
+  return data->vec[ix];
+}
+
 #endif /* HAVE_DLOPEN */

=== modified file 'sql/udf_example.def'
--- a/sql/udf_example.def	2007-10-29 14:01:40 +0000
+++ b/sql/udf_example.def	2011-10-11 04:27:52 +0000
@@ -25,3 +25,8 @@ EXPORTS
   is_const_init
   check_const_len
   check_const_len_init
+  my_median_init
+  my_median_deinit
+  my_median_add
+  my_median_clear
+  my_median

=== modified file 'sql/unireg.cc'
--- a/sql/unireg.cc	2011-07-28 10:54:44 +0000
+++ b/sql/unireg.cc	2011-08-29 12:08:58 +0000
@@ -31,6 +31,11 @@
 #include <m_ctype.h>
 #include <assert.h>
 
+#include <algorithm>
+
+using std::min;
+using std::max;
+
 #define FCOMP			17		/* Bytes for a packed field */
 
 static uchar * pack_screens(List<Create_field> &create_fields,
@@ -603,7 +608,7 @@ static uchar *pack_screens(List<Create_f
     }
     cfield->row=(uint8) row;
     cfield->col=(uint8) (length+1);
-    cfield->sc_length=(uint8) min(cfield->length,cols-(length+2));
+    cfield->sc_length= min<uint8>(cfield->length, cols - (length + 2));
   }
   length=(uint) (pos-start_screen);
   int2store(start_screen,length);
@@ -839,7 +844,7 @@ static bool pack_header(uchar *forminfo,
     DBUG_RETURN(1);
   }
   /* Hack to avoid bugs with small static rows in MySQL */
-  reclength=max(file->min_record_length(table_options),reclength);
+  reclength= max<size_t>(file->min_record_length(table_options), reclength);
   if (info_length+(ulong) create_fields.elements*FCOMP+288+
       n_length+int_length+com_length > 65535L || int_count > 255)
   {

=== modified file 'storage/csv/ha_tina.cc'
--- a/storage/csv/ha_tina.cc	2011-09-21 11:01:41 +0000
+++ b/storage/csv/ha_tina.cc	2011-09-26 12:42:12 +0000
@@ -49,6 +49,10 @@ TODO:
 #include "ha_tina.h"
 #include "probes_mysql.h"
 
+#include <algorithm>
+
+using std::min;
+using std::max;
 
 /*
   uchar + uchar + ulonglong + ulonglong + ulonglong + ulonglong + uchar
@@ -1313,8 +1317,7 @@ bool ha_tina::get_write_pos(my_off_t *en
   if (closest_hole == chain_ptr) /* no more chains */
     *end_pos= file_buff->end();
   else
-    *end_pos= min(file_buff->end(),
-                  closest_hole->begin);
+    *end_pos= min(file_buff->end(), closest_hole->begin);
   return (closest_hole != chain_ptr) && (*end_pos == closest_hole->begin);
 }
 

=== modified file 'storage/federated/ha_federated.cc'
--- a/storage/federated/ha_federated.cc	2011-09-21 11:01:41 +0000
+++ b/storage/federated/ha_federated.cc	2011-09-26 12:42:12 +0000
@@ -386,6 +386,11 @@
 
 #include <mysql/plugin.h>
 
+#include <algorithm>
+
+using std::min;
+using std::max;
+
 /* Variables for federated share methods */
 static HASH federated_open_tables;              // To track open tables
 mysql_mutex_t federated_mutex;                // To init the hash
@@ -572,8 +577,8 @@ static int parse_url_error(FEDERATED_SHA
   size_t buf_len;
   DBUG_ENTER("ha_federated parse_url_error");
 
-  buf_len= min(table->s->connect_string.length,
-               FEDERATED_QUERY_BUFFER_SIZE-1);
+  buf_len= min<size_t>(table->s->connect_string.length,
+                       FEDERATED_QUERY_BUFFER_SIZE-1);
   strmake(buf, table->s->connect_string.str, buf_len);
   my_error(error_num, MYF(0), buf);
   DBUG_RETURN(error_num);

=== modified file 'storage/heap/hp_create.c'
--- a/storage/heap/hp_create.c	2011-09-27 12:17:43 +0000
+++ b/storage/heap/hp_create.c	2011-10-13 07:26:28 +0000
@@ -233,7 +233,7 @@ static void init_block(HP_BLOCK *block,
 {
   uint i,recbuffer,records_in_block;
 
-  max_records= max(min_records,max_records);
+  max_records= MY_MAX(min_records, max_records);
   if (!max_records)
     max_records= 1000;			/* As good as quess as anything */
   recbuffer= (uint) (reclength + sizeof(uchar**) - 1) & ~(sizeof(uchar**) - 1);

=== modified file 'storage/heap/hp_static.c'
--- a/storage/heap/hp_static.c	2011-06-30 15:50:45 +0000
+++ b/storage/heap/hp_static.c	2011-10-11 04:27:52 +0000
@@ -18,7 +18,7 @@
   a shared library
 */
 
-#ifndef _global_h
+#ifndef MY_GLOBAL_INCLUDED
 #include "heapdef.h"
 #endif
 

=== modified file 'storage/heap/hp_test2.c'
--- a/storage/heap/hp_test2.c	2011-06-30 15:50:45 +0000
+++ b/storage/heap/hp_test2.c	2011-08-29 12:08:58 +0000
@@ -132,7 +132,9 @@ int main(int argc, char *argv[])
 
   for (i=0 ; i < recant ; i++)
   {
-    n1=rnd(1000); n2=rnd(100); n3=rnd(min(recant*5,MAX_RECORDS));
+    n1= rnd(1000);
+    n2= rnd(100);
+    n3= rnd(MY_MIN(recant * 5, MAX_RECORDS));
     make_record(record,n1,n2,n3,"Pos",write_count);
 
     if (heap_write(file,record))
@@ -208,7 +210,9 @@ int main(int argc, char *argv[])
   printf("- Update\n");
   for (i=0 ; i < write_count/10 ; i++)
   {
-    n1=rnd(1000); n2=rnd(100); n3=rnd(min(recant*2,MAX_RECORDS));
+    n1= rnd(1000);
+    n2= rnd(100);
+    n3= rnd(MY_MIN(recant * 2, MAX_RECORDS));
     make_record(record2, n1, n2, n3, "XXX", update);
     if (rnd(2) == 1)
     {

=== modified file 'storage/innobase/sync/sync0rw.c'
--- a/storage/innobase/sync/sync0rw.c	2011-10-19 11:42:46 +0000
+++ b/storage/innobase/sync/sync0rw.c	2011-11-04 06:05:42 +0000
@@ -315,14 +315,19 @@ rw_lock_free_func(
 /*==============*/
 	rw_lock_t*	lock)	/*!< in: rw-lock */
 {
+#ifndef INNODB_RW_LOCKS_USE_ATOMICS
+	mutex_t*	mutex;
+#endif /* !INNODB_RW_LOCKS_USE_ATOMICS */
+
 	ut_ad(rw_lock_validate(lock));
 	ut_a(lock->lock_word == X_LOCK_DECR);
 
+	mutex_enter(&rw_lock_list_mutex);
+
 #ifndef INNODB_RW_LOCKS_USE_ATOMICS
-	mutex_free(rw_lock_get_mutex(lock));
-#endif /* INNODB_RW_LOCKS_USE_ATOMICS */
+	mutex = rw_lock_get_mutex(lock);
+#endif /* !INNODB_RW_LOCKS_USE_ATOMICS */
 
-	mutex_enter(&rw_lock_list_mutex);
 	os_event_free(lock->event);
 
 	os_event_free(lock->wait_ex_event);
@@ -337,6 +342,12 @@ rw_lock_free_func(
 	mutex_exit(&rw_lock_list_mutex);
 
 	ut_d(lock->magic_n = 0);
+
+#ifndef INNODB_RW_LOCKS_USE_ATOMICS
+	/* We have merely removed the rw_lock from the list, the memory
+	has not been freed. Therefore the pointer to mutex is valid. */
+	mutex_free(mutex);
+#endif /* !INNODB_RW_LOCKS_USE_ATOMICS */
 }
 
 #ifdef UNIV_DEBUG

=== modified file 'storage/myisam/ha_myisam.cc'
--- a/storage/myisam/ha_myisam.cc	2011-10-21 05:42:01 +0000
+++ b/storage/myisam/ha_myisam.cc	2011-10-28 12:45:35 +0000
@@ -30,6 +30,11 @@
 #include "sql_table.h"                          // tablename_to_filename
 #include "sql_class.h"                          // THD
 
+#include <algorithm>
+
+using std::min;
+using std::max;
+
 ulonglong myisam_recover_options;
 static ulong opt_myisam_block_size;
 

=== modified file 'storage/myisam/mi_cache.c'
--- a/storage/myisam/mi_cache.c	2011-06-30 15:50:45 +0000
+++ b/storage/myisam/mi_cache.c	2011-08-29 12:08:58 +0000
@@ -61,7 +61,7 @@ int _mi_read_cache(IO_CACHE *info, uchar
       (my_off_t) (info->read_end - info->request_pos))
   {
     in_buff_pos=info->request_pos+(uint) offset;
-    in_buff_length= min(length, (size_t) (info->read_end-in_buff_pos));
+    in_buff_length= MY_MIN(length, (size_t) (info->read_end-in_buff_pos));
     memcpy(buff,info->request_pos+(uint) offset,(size_t) in_buff_length);
     if (!(length-=in_buff_length))
       DBUG_RETURN(0);

=== modified file 'storage/myisam/mi_check.c'
--- a/storage/myisam/mi_check.c	2011-09-16 12:24:08 +0000
+++ b/storage/myisam/mi_check.c	2011-09-26 12:42:12 +0000
@@ -2171,7 +2171,7 @@ int filecopy(MI_CHECK *param, File to,Fi
   ulong buff_length;
   DBUG_ENTER("filecopy");
 
-  buff_length=(ulong) min(param->write_buffer_length,length);
+  buff_length=(ulong) MY_MIN(param->write_buffer_length,length);
   if (!(buff=my_malloc(buff_length,MYF(0))))
   {
     buff=tmp_buff; buff_length=IO_SIZE;
@@ -2325,7 +2325,7 @@ int mi_repair_by_sort(MI_CHECK *param, r
   init_alloc_root(&sort_param.wordroot, FTPARSER_MEMROOT_ALLOC_SIZE, 0);
 
   if (share->data_file_type == DYNAMIC_RECORD)
-    length=max(share->base.min_pack_length+1,share->base.min_block_length);
+    length= MY_MAX(share->base.min_pack_length + 1, share->base.min_block_length);
   else if (share->data_file_type == COMPRESSED_RECORD)
     length=share->base.min_block_length;
   else
@@ -2414,7 +2414,7 @@ int mi_repair_by_sort(MI_CHECK *param, r
           (see _create_index_by_sort)
         */
         sort_info.max_records= 10 *
-                               max(param->sort_buffer_length, MIN_SORT_BUFFER) /
+                               MY_MAX(param->sort_buffer_length, MIN_SORT_BUFFER) /
                                sort_param.key_length;
       }
 
@@ -2771,7 +2771,7 @@ int mi_repair_parallel(MI_CHECK *param,
     mysql_file_seek(param->read_cache.file, 0L, MY_SEEK_END, MYF(0));
 
   if (share->data_file_type == DYNAMIC_RECORD)
-    rec_length=max(share->base.min_pack_length+1,share->base.min_block_length);
+    rec_length= MY_MAX(share->base.min_pack_length + 1, share->base.min_block_length);
   else if (share->data_file_type == COMPRESSED_RECORD)
     rec_length=share->base.min_block_length;
   else
@@ -4323,7 +4323,7 @@ int recreate_table(MI_CHECK *param, MI_I
 
   (void) mi_close(*org_info);
   memset(&create_info, 0, sizeof(create_info));
-  create_info.max_rows=max(max_records,share.base.records);
+  create_info.max_rows= MY_MAX(max_records, share.base.records);
   create_info.reloc_rows=share.base.reloc;
   create_info.old_options=(share.options |
 			   (unpack ? HA_OPTION_TEMP_COMPRESS_RECORD : 0));

=== modified file 'storage/myisam/mi_create.c'
--- a/storage/myisam/mi_create.c	2011-07-04 00:25:46 +0000
+++ b/storage/myisam/mi_create.c	2011-08-29 12:08:58 +0000
@@ -435,8 +435,8 @@ int mi_create(const char *name,uint keys
     block_length= (keydef->block_length ? 
                    my_round_up_to_next_power(keydef->block_length) :
                    myisam_block_size);
-    block_length= max(block_length, MI_MIN_KEY_BLOCK_LENGTH);
-    block_length= min(block_length, MI_MAX_KEY_BLOCK_LENGTH);
+    block_length= MY_MAX(block_length, MI_MIN_KEY_BLOCK_LENGTH);
+    block_length= MY_MIN(block_length, MI_MAX_KEY_BLOCK_LENGTH);
 
     keydef->block_length= (uint16) MI_BLOCK_SIZE(length-real_length_diff,
                                                  pointer,MI_MAX_KEYPTR_SIZE,
@@ -525,7 +525,7 @@ int mi_create(const char *name,uint keys
     got from MYI file header (see also myisampack.c:save_state)
   */
   share.base.key_reflength=
-    mi_get_pointer_length(max(ci->key_file_length,tmp),3);
+    mi_get_pointer_length(MY_MAX(ci->key_file_length, tmp), 3);
   share.base.keys= share.state.header.keys= keys;
   share.state.header.uniques= uniques;
   share.state.header.fulltext_keys= fulltext_keys;
@@ -558,7 +558,7 @@ int mi_create(const char *name,uint keys
   share.base.min_block_length=
     (share.base.pack_reclength+3 < MI_EXTEND_BLOCK_LENGTH &&
      ! share.base.blobs) ?
-    max(share.base.pack_reclength,MI_MIN_BLOCK_LENGTH) :
+    MY_MAX(share.base.pack_reclength, MI_MIN_BLOCK_LENGTH) :
     MI_EXTEND_BLOCK_LENGTH;
   if (! (flags & HA_DONT_TOUCH_DATA))
     share.state.create_time= (long) time((time_t*) 0);

=== modified file 'storage/myisam/mi_dynrec.c'
--- a/storage/myisam/mi_dynrec.c	2011-06-30 15:50:45 +0000
+++ b/storage/myisam/mi_dynrec.c	2011-08-29 12:08:58 +0000
@@ -864,7 +864,7 @@ static int update_dynamic_record(MI_INFO
 	uint tmp=MY_ALIGN(reclength - length + 3 +
 			  test(reclength >= 65520L),MI_DYN_ALIGN_SIZE);
 	/* Don't create a block bigger than MI_MAX_BLOCK_LENGTH */
-	tmp= min(length+tmp, MI_MAX_BLOCK_LENGTH)-length;
+	tmp= MY_MIN(length+tmp, MI_MAX_BLOCK_LENGTH)-length;
 	/* Check if we can extend this block */
 	if (block_info.filepos + block_info.block_len ==
 	    info->state->data_file_length &&

=== modified file 'storage/myisam/mi_extra.c'
--- a/storage/myisam/mi_extra.c	2011-06-30 15:50:45 +0000
+++ b/storage/myisam/mi_extra.c	2011-08-29 12:08:58 +0000
@@ -99,8 +99,8 @@ int mi_extra(MI_INFO *info, enum ha_extr
       cache_size= (extra_arg ? *(ulong*) extra_arg :
 		   my_default_record_cache_size);
       if (!(init_io_cache(&info->rec_cache,info->dfile,
-			 (uint) min(info->state->data_file_length+1,
-				    cache_size),
+			 (uint) MY_MIN(info->state->data_file_length + 1,
+                                       cache_size),
 			  READ_CACHE,0L,(pbool) (info->lock_type != F_UNLCK),
 			  MYF(share->write_flag & MY_WAIT_IF_FULL))))
       {

=== modified file 'storage/myisam/mi_open.c'
--- a/storage/myisam/mi_open.c	2011-06-30 15:50:45 +0000
+++ b/storage/myisam/mi_open.c	2011-08-29 12:08:58 +0000
@@ -304,7 +304,7 @@ MI_INFO *mi_open(const char *name, int m
     strmov(share->index_file_name,  index_name);
     strmov(share->data_file_name,   data_name);
 
-    share->blocksize=min(IO_SIZE,myisam_block_size);
+    share->blocksize= MY_MIN(IO_SIZE, myisam_block_size);
     {
       HA_KEYSEG *pos=share->keyparts;
       uint32 ftkey_nr= 1;
@@ -477,7 +477,7 @@ MI_INFO *mi_open(const char *name, int m
     share->base.margin_key_file_length=(share->base.max_key_file_length -
 					(keys ? MI_INDEX_BLOCK_MARGIN *
 					 share->blocksize * keys : 0));
-    share->blocksize=min(IO_SIZE,myisam_block_size);
+    share->blocksize= MY_MIN(IO_SIZE, myisam_block_size);
     share->data_file_type=STATIC_RECORD;
     if (share->options & HA_OPTION_COMPRESS_RECORD)
     {
@@ -688,10 +688,10 @@ uchar *mi_alloc_rec_buff(MI_INFO *info,
     if (length == (ulong) -1)
     {
       if (info->s->options & HA_OPTION_COMPRESS_RECORD)
-        length= max(info->s->base.pack_reclength, info->s->max_pack_length);
+        length= MY_MAX(info->s->base.pack_reclength, info->s->max_pack_length);
       else
         length= info->s->base.pack_reclength;
-      length= max(length, info->s->base.max_key_length);
+      length= MY_MAX(length, info->s->base.max_key_length);
       /* Avoid unnecessary realloc */
       if (newptr && length == old_length)
 	return newptr;

=== modified file 'storage/myisam/mi_packrec.c'
--- a/storage/myisam/mi_packrec.c	2011-06-30 15:50:45 +0000
+++ b/storage/myisam/mi_packrec.c	2011-08-29 12:08:58 +0000
@@ -684,7 +684,7 @@ static uint find_longest_bitstream(uint1
       return OFFSET_TABLE_SIZE;
     }
     length2= find_longest_bitstream(next, end) + 1;
-    length=max(length,length2);
+    length= MY_MAX(length, length2);
   }
   return length;
 }
@@ -1398,7 +1398,7 @@ uint _mi_pack_get_block_info(MI_INFO *my
   info->filepos=filepos+head_length;
   if (file > 0)
   {
-    info->offset=min(info->rec_len, ref_length - head_length);
+    info->offset= MY_MIN(info->rec_len, ref_length - head_length);
     memcpy(*rec_buff_p, header + head_length, info->offset);
   }
   return 0;

=== modified file 'storage/myisam/mi_static.c'
--- a/storage/myisam/mi_static.c	2011-06-30 15:50:45 +0000
+++ b/storage/myisam/mi_static.c	2011-10-11 04:27:52 +0000
@@ -18,7 +18,7 @@
   a shared library
 */
 
-#ifndef _global_h
+#ifndef MY_GLOBAL_INCLUDED
 #include "myisamdef.h"
 #endif
 

=== modified file 'storage/myisam/myisamlog.c'
--- a/storage/myisam/myisamlog.c	2011-06-30 15:50:45 +0000
+++ b/storage/myisam/myisamlog.c	2011-08-29 12:08:58 +0000
@@ -90,7 +90,7 @@ int main(int argc, char **argv)
   log_filename=myisam_log_filename;
   get_options(&argc,&argv);
   /* Number of MyISAM files we can have open at one time */
-  max_files= (my_set_max_open_files(min(max_files,8))-6)/2;
+  max_files= (my_set_max_open_files(MY_MIN(max_files, 8)) - 6) / 2;
   if (update)
     printf("Trying to %s MyISAM files according to log '%s'\n",
 	   (recover ? "recover" : "update"),log_filename);

=== modified file 'storage/myisam/myisampack.c'
--- a/storage/myisam/myisampack.c	2011-06-30 15:50:45 +0000
+++ b/storage/myisam/myisampack.c	2011-08-29 12:08:58 +0000
@@ -1269,8 +1269,8 @@ static void check_counts(HUFF_COUNTS *hu
     {
       if (huff_counts->field_length > 2 &&
 	  huff_counts->empty_fields + (records - huff_counts->empty_fields)*
-	  (1+max_bit(max(huff_counts->max_pre_space,
-			 huff_counts->max_end_space))) <
+	  (1+max_bit(MY_MAX(huff_counts->max_pre_space,
+                            huff_counts->max_end_space))) <
 	  records * max_bit(huff_counts->field_length))
       {
 	huff_counts->pack_type |= PACK_TYPE_SPACE_FIELDS;
@@ -3030,7 +3030,7 @@ static int save_state_mrg(File file,PACK
   if (mrg->src_file_has_indexes_disabled)
   {
     isam_file->s->state.state.key_file_length=
-      max(isam_file->s->state.state.key_file_length, new_length);
+      MY_MAX(isam_file->s->state.state.key_file_length, new_length);
   }
   state.dellink= HA_OFFSET_ERROR;
   state.version=(ulong) time((time_t*) 0);

=== modified file 'storage/myisam/rt_mbr.c'
--- a/storage/myisam/rt_mbr.c	2007-10-05 10:43:15 +0000
+++ b/storage/myisam/rt_mbr.c	2011-06-01 13:47:36 +0000
@@ -325,8 +325,8 @@ int rtree_d_mbr(HA_KEYSEG *keyseg, uchar
   bmin = korr_func(b); \
   amax = korr_func(a+len); \
   bmax = korr_func(b+len); \
-  amin = min(amin, bmin); \
-  amax = max(amax, bmax); \
+  amin = MY_MIN(amin, bmin); \
+  amax = MY_MAX(amax, bmax); \
   store_func(c, amin); \
   store_func(c+len, amax); \
 }
@@ -338,8 +338,8 @@ int rtree_d_mbr(HA_KEYSEG *keyseg, uchar
   get_func(bmin, b); \
   get_func(amax, a+len); \
   get_func(bmax, b+len); \
-  amin = min(amin, bmin); \
-  amax = max(amax, bmax); \
+  amin = MY_MIN(amin, bmin); \
+  amax = MY_MAX(amax, bmax); \
   store_func(c, amin); \
   store_func(c+len, amax); \
 }
@@ -417,8 +417,8 @@ int rtree_combine_rect(HA_KEYSEG *keyseg
   bmin = korr_func(b); \
   amax = korr_func(a+len); \
   bmax = korr_func(b+len); \
-  amin = max(amin, bmin); \
-  amax = min(amax, bmax); \
+  amin = MY_MAX(amin, bmin); \
+  amax = MY_MIN(amax, bmax); \
   if (amin >= amax) \
     return 0; \
   res *= amax - amin; \
@@ -431,8 +431,8 @@ int rtree_combine_rect(HA_KEYSEG *keyseg
   get_func(bmin, b); \
   get_func(amax, a+len); \
   get_func(bmax, b+len); \
-  amin = max(amin, bmin); \
-  amax = min(amax, bmax); \
+  amin = MY_MAX(amin, bmin); \
+  amax = MY_MIN(amax, bmax); \
   if (amin >= amax)  \
     return 0; \
   res *= amax - amin; \
@@ -508,7 +508,7 @@ double rtree_overlapping_area(HA_KEYSEG
    amax = korr_func(a+len); \
    bmax = korr_func(b+len); \
    a_area *= (((double)amax) - ((double)amin)); \
-   loc_ab_area *= ((double)max(amax, bmax) - (double)min(amin, bmin)); \
+   loc_ab_area *= ((double)MY_MAX(amax, bmax) - (double)MY_MIN(amin, bmin)); \
 }
 
 #define RT_AREA_INC_GET(type, get_func, len)\
@@ -519,7 +519,7 @@ double rtree_overlapping_area(HA_KEYSEG
    get_func(amax, a+len); \
    get_func(bmax, b+len); \
    a_area *= (((double)amax) - ((double)amin)); \
-   loc_ab_area *= ((double)max(amax, bmax) - (double)min(amin, bmin)); \
+   loc_ab_area *= ((double)MY_MAX(amax, bmax) - (double)MY_MIN(amin, bmin)); \
 }
 
 /*
@@ -604,7 +604,7 @@ safe_end:
    amax = korr_func(a+len); \
    bmax = korr_func(b+len); \
    a_perim+= (((double)amax) - ((double)amin)); \
-   *ab_perim+= ((double)max(amax, bmax) - (double)min(amin, bmin)); \
+   *ab_perim+= ((double)MY_MAX(amax, bmax) - (double)MY_MIN(amin, bmin)); \
 }
 
 #define RT_PERIM_INC_GET(type, get_func, len)\
@@ -615,7 +615,7 @@ safe_end:
    get_func(amax, a+len); \
    get_func(bmax, b+len); \
    a_perim+= (((double)amax) - ((double)amin)); \
-   *ab_perim+= ((double)max(amax, bmax) - (double)min(amin, bmin)); \
+   *ab_perim+= ((double)MY_MAX(amax, bmax) - (double)MY_MIN(amin, bmin)); \
 }
 
 /*

=== modified file 'storage/myisam/sort.c'
--- a/storage/myisam/sort.c	2011-06-30 15:50:45 +0000
+++ b/storage/myisam/sort.c	2011-08-29 12:08:58 +0000
@@ -129,7 +129,7 @@ int _create_index_by_sort(MI_SORT_PARAM
   sort_keys= (uchar **) NULL; error= 1;
   maxbuffer=1;
 
-  memavl= max(sortbuff_size, MIN_SORT_BUFFER);
+  memavl= MY_MAX(sortbuff_size, MIN_SORT_BUFFER);
   records=	info->sort_info->max_records;
   sort_length=	info->key_length;
   LINT_INIT(keys);
@@ -344,7 +344,7 @@ pthread_handler_t thr_find_all_keys(void
     memset(&sort_param->unique, 0, sizeof(sort_param->unique));
     sort_keys= (uchar **) NULL;
 
-    memavl=       max(sort_param->sortbuff_size, MIN_SORT_BUFFER);
+    memavl=       MY_MAX(sort_param->sortbuff_size, MIN_SORT_BUFFER);
     idx=          (uint)sort_param->sort_info->max_records;
     sort_length=  sort_param->key_length;
     maxbuffer=    1;
@@ -813,7 +813,7 @@ static uint read_to_buffer(IO_CACHE *fro
   register uint count;
   uint length;
 
-  if ((count=(uint) min((ha_rows) buffpek->max_keys,buffpek->count)))
+  if ((count=(uint) MY_MIN((ha_rows) buffpek->max_keys,buffpek->count)))
   {
     if (mysql_file_pread(fromfile->file, (uchar*) buffpek->base,
                          (length= sort_length*count),
@@ -835,7 +835,7 @@ static uint read_to_buffer_varlen(IO_CAC
   uint idx;
   uchar *buffp;
 
-  if ((count=(uint) min((ha_rows) buffpek->max_keys,buffpek->count)))
+  if ((count=(uint) MY_MIN((ha_rows) buffpek->max_keys, buffpek->count)))
   {
     buffp = buffpek->base;
 

=== modified file 'storage/myisammrg/ha_myisammrg.cc'
--- a/storage/myisammrg/ha_myisammrg.cc	2011-09-21 11:01:41 +0000
+++ b/storage/myisammrg/ha_myisammrg.cc	2011-09-26 12:42:12 +0000
@@ -101,6 +101,11 @@
 #include "sql_class.h"                          // THD
 #include "debug_sync.h"
 
+#include <algorithm>
+
+using std::min;
+using std::max;
+
 static handler *myisammrg_create_handler(handlerton *hton,
                                          TABLE_SHARE *table,
                                          MEM_ROOT *mem_root)

=== modified file 'strings/ctype-big5.c'
--- a/strings/ctype-big5.c	2011-06-30 15:50:45 +0000
+++ b/strings/ctype-big5.c	2011-08-29 12:08:58 +0000
@@ -877,7 +877,7 @@ static int my_strnncoll_big5(const CHARS
                              const uchar *b, size_t b_length,
                              my_bool b_is_prefix)
 {
-  size_t length= min(a_length, b_length);
+  size_t length= MY_MIN(a_length, b_length);
   int res= my_strnncoll_big5_internal(&a, &b, length);
   return res ? res : (int)((b_is_prefix ? length : a_length) - b_length);
 }
@@ -890,7 +890,7 @@ static int my_strnncollsp_big5(const CHA
 			       const uchar *b, size_t b_length,
                                my_bool diff_if_only_endspace_difference)
 {
-  size_t length= min(a_length, b_length);
+  size_t length= MY_MIN(a_length, b_length);
   int res= my_strnncoll_big5_internal(&a, &b, length);
 
 #ifndef VARCHAR_WITH_DIFF_ENDSPACE_ARE_DIFFERENT_FOR_UNIQUE

=== modified file 'strings/ctype-bin.c'
--- a/strings/ctype-bin.c	2011-06-30 15:50:45 +0000
+++ b/strings/ctype-bin.c	2011-08-29 12:08:58 +0000
@@ -79,7 +79,7 @@ static int my_strnncoll_binary(const CHA
                                const uchar *t, size_t tlen,
                                my_bool t_is_prefix)
 {
-  size_t len=min(slen,tlen);
+  size_t len= MY_MIN(slen,tlen);
   int cmp= memcmp(s,t,len);
   return cmp ? cmp : (int)((t_is_prefix ? len : slen) - tlen);
 }
@@ -132,7 +132,7 @@ static int my_strnncoll_8bit_bin(const C
                                  const uchar *t, size_t tlen,
                                  my_bool t_is_prefix)
 {
-  size_t len=min(slen,tlen);
+  size_t len=MY_MIN(slen,tlen);
   int cmp= memcmp(s,t,len);
   return cmp ? cmp : (int)((t_is_prefix ? len : slen) - tlen);
 }
@@ -177,7 +177,7 @@ static int my_strnncollsp_8bit_bin(const
   diff_if_only_endspace_difference= 0;
 #endif
 
-  end= a + (length= min(a_length, b_length));
+  end= a + (length= MY_MIN(a_length, b_length));
   while (a < end)
   {
     if (*a++ != *b++)

=== modified file 'strings/ctype-gbk.c'
--- a/strings/ctype-gbk.c	2011-06-30 15:50:45 +0000
+++ b/strings/ctype-gbk.c	2011-08-29 12:08:58 +0000
@@ -3480,7 +3480,7 @@ int my_strnncoll_gbk(const CHARSET_INFO
                      const uchar *b, size_t b_length,
                      my_bool b_is_prefix)
 {
-  size_t length= min(a_length, b_length);
+  size_t length= MY_MIN(a_length, b_length);
   int res= my_strnncoll_gbk_internal(&a, &b, length);
   return res ? res : (int) ((b_is_prefix ? length : a_length) - b_length);
 }
@@ -3491,7 +3491,7 @@ static int my_strnncollsp_gbk(const CHAR
 			      const uchar *b, size_t b_length,
                               my_bool diff_if_only_endspace_difference)
 {
-  size_t length= min(a_length, b_length);
+  size_t length= MY_MIN(a_length, b_length);
   int res= my_strnncoll_gbk_internal(&a, &b, length);
 
 #ifndef VARCHAR_WITH_DIFF_ENDSPACE_ARE_DIFFERENT_FOR_UNIQUE

=== modified file 'strings/ctype-mb.c'
--- a/strings/ctype-mb.c	2011-06-30 15:50:45 +0000
+++ b/strings/ctype-mb.c	2011-08-29 12:08:58 +0000
@@ -473,7 +473,7 @@ my_strnncoll_mb_bin(const CHARSET_INFO *
                     const uchar *t, size_t tlen,
                     my_bool t_is_prefix)
 {
-  size_t len=min(slen,tlen);
+  size_t len= MY_MIN(slen,tlen);
   int cmp= memcmp(s,t,len);
   return cmp ? cmp : (int) ((t_is_prefix ? len : slen) - tlen);
 }
@@ -518,7 +518,7 @@ my_strnncollsp_mb_bin(const CHARSET_INFO
   diff_if_only_endspace_difference= 0;
 #endif
   
-  end= a + (length= min(a_length, b_length));
+  end= a + (length= MY_MIN(a_length, b_length));
   while (a < end)
   {
     if (*a++ != *b++)

=== modified file 'strings/ctype-simple.c'
--- a/strings/ctype-simple.c	2011-06-30 15:50:45 +0000
+++ b/strings/ctype-simple.c	2011-08-29 12:08:58 +0000
@@ -79,7 +79,7 @@ my_strnxfrm_simple(const CHARSET_INFO *c
   uchar *map= cs->sort_order;
   uchar *d0= dst;
   uint frmlen;
-  if ((frmlen= min(dstlen, nweights)) > srclen)
+  if ((frmlen= MY_MIN(dstlen, nweights)) > srclen)
     frmlen= srclen;
   if (dst != src)
   {
@@ -161,7 +161,7 @@ int my_strnncollsp_simple(const CHARSET_
   diff_if_only_endspace_difference= 0;
 #endif
 
-  end= a + (length= min(a_length, b_length));
+  end= a + (length= MY_MIN(a_length, b_length));
   while (a < end)
   {
     if (map[*a++] != map[*b++])
@@ -766,7 +766,7 @@ size_t my_long10_to_str_8bit(const CHARS
     val= new_val;
   }
   
-  len= min(len, (size_t) (e-p));
+  len= MY_MIN(len, (size_t) (e-p));
   memcpy(dst, p, len);
   return len+sign;
 }
@@ -821,7 +821,7 @@ size_t my_longlong10_to_str_8bit(const C
     long_val= quo;
   }
   
-  len= min(len, (size_t) (e-p));
+  len= MY_MIN(len, (size_t) (e-p));
 cnv:
   memcpy(dst, p, len);
   return len+sign;
@@ -1053,7 +1053,7 @@ size_t my_well_formed_len_8bit(const CHA
 {
   size_t nbytes= (size_t) (end-start);
   *error= 0;
-  return min(nbytes, nchars);
+  return MY_MIN(nbytes, nchars);
 }
 
 
@@ -1715,7 +1715,7 @@ uint my_strxfrm_flag_normalize(uint flag
       uint src_bit= 1 << i;
       if (flag_lev & src_bit)
       {
-        uint dst_bit= 1 << min(i, maximum);
+        uint dst_bit= 1 << MY_MIN(i, maximum);
         flags|= dst_bit;
         flags|= (flag_dsc & dst_bit) << MY_STRXFRM_DESC_SHIFT;
         flags|= (flag_rev & dst_bit) << MY_STRXFRM_REVERSE_SHIFT;
@@ -1797,7 +1797,7 @@ my_strxfrm_pad_desc_and_reverse(const CH
 {
   if (nweights && frmend < strend && (flags & MY_STRXFRM_PAD_WITH_SPACE))
   {
-    uint fill_length= min((uint) (strend - frmend), nweights * cs->mbminlen);
+    uint fill_length= MY_MIN((uint) (strend - frmend), nweights * cs->mbminlen);
     cs->cset->fill(cs, (char*) frmend, fill_length, cs->pad_char);
     frmend+= fill_length;
   }

=== modified file 'strings/ctype-tis620.c'
--- a/strings/ctype-tis620.c	2011-06-30 15:50:45 +0000
+++ b/strings/ctype-tis620.c	2011-08-29 12:08:58 +0000
@@ -581,7 +581,7 @@ int my_strnncollsp_tis620(const CHARSET_
   a_length= thai2sortable(a, a_length);
   b_length= thai2sortable(b, b_length);
   
-  end= a + (length= min(a_length, b_length));
+  end= a + (length= MY_MIN(a_length, b_length));
   while (a < end)
   {
     if (*a++ != *b++)
@@ -638,7 +638,7 @@ my_strnxfrm_tis620(const CHARSET_INFO *c
                    const uchar *src, size_t srclen, uint flags)
 {
   size_t len, dstlen0= dstlen;
-  len= (uint) (strmake((char*) dst, (char*) src, min(dstlen, srclen)) -
+  len= (uint) (strmake((char*) dst, (char*) src, MY_MIN(dstlen, srclen)) -
 	               (char*) dst);
   len= thai2sortable(dst, len);
   set_if_smaller(dstlen, nweights);

=== modified file 'strings/ctype-uca.c'
--- a/strings/ctype-uca.c	2011-09-21 11:16:48 +0000
+++ b/strings/ctype-uca.c	2011-09-26 12:42:12 +0000
@@ -20283,7 +20283,7 @@ my_strnxfrm_uca(const CHARSET_INFO *cs,
   
   if (dst < de && nweights && (flags & MY_STRXFRM_PAD_WITH_SPACE))
   {
-    uint space_count= min((uint) (de - dst) / 2, nweights);
+    uint space_count= MY_MIN((uint) (de - dst) / 2, nweights);
     s_res= my_space_weight(cs);
     for (; space_count ; space_count--)
     {
@@ -20645,7 +20645,7 @@ static void my_coll_lexem_print_error(MY
 {
   char tail[30];
   size_t len= lexem->end - lexem->prev;
-  strmake (tail, lexem->prev, (size_t) min(len, sizeof(tail)-1));
+  strmake (tail, lexem->prev, (size_t) MY_MIN(len, sizeof(tail)-1));
   errstr[errsize-1]= '\0';
   my_snprintf(errstr, errsize - 1,
               "%s at '%s'", txt[0] ? txt : "Syntax error", tail);

=== modified file 'strings/ctype-ucs2.c'
--- a/strings/ctype-ucs2.c	2011-06-30 15:50:45 +0000
+++ b/strings/ctype-ucs2.c	2011-08-29 12:08:58 +0000
@@ -57,7 +57,7 @@ my_bincmp(const uchar *s, const uchar *s
           const uchar *t, const uchar *te)
 {
   int slen= (int) (se - s), tlen= (int) (te - t);
-  int len= min(slen, tlen);
+  int len= MY_MIN(slen, tlen);
   int cmp= memcmp(s, t, len);
   return cmp ? cmp : slen - tlen;
 }
@@ -2649,7 +2649,7 @@ my_strnncollsp_utf32_bin(const CHARSET_I
   se= s + slen;
   te= t + tlen;
 
-  for (minlen= min(slen, tlen); minlen; minlen-= 4)
+  for (minlen= MY_MIN(slen, tlen); minlen; minlen-= 4)
   {
     my_wc_t s_wc= my_utf32_get(s);
     my_wc_t t_wc= my_utf32_get(t);
@@ -3109,7 +3109,7 @@ static int my_strnncollsp_ucs2(const CHA
   se= s + slen;
   te= t + tlen;
 
-  for (minlen= min(slen, tlen); minlen; minlen-= 2)
+  for (minlen= MY_MIN(slen, tlen); minlen; minlen-= 2)
   {
     int s_wc = uni_plane->page[s[0]] ? (int) uni_plane->page[s[0]][s[1]].sort :
                                        (((int) s[0]) << 8) + (int) s[1];
@@ -3186,7 +3186,7 @@ size_t my_well_formed_len_ucs2(const CHA
   size_t nbytes= ((size_t) (e-b)) & ~(size_t) 1;
   *error= 0;
   nchars*= 2;
-  return min(nbytes, nchars);
+  return MY_MIN(nbytes, nchars);
 }
 
 
@@ -3262,7 +3262,7 @@ static int my_strnncollsp_ucs2_bin(const
   se= s + slen;
   te= t + tlen;
 
-  for (minlen= min(slen, tlen); minlen; minlen-= 2)
+  for (minlen= MY_MIN(slen, tlen); minlen; minlen-= 2)
   {
     int s_wc= s[0] * 256 + s[1];
     int t_wc= t[0] * 256 + t[1];

=== modified file 'strings/ctype-utf8.c'
--- a/strings/ctype-utf8.c	2011-06-30 15:50:45 +0000
+++ b/strings/ctype-utf8.c	2011-08-29 12:08:58 +0000
@@ -5082,7 +5082,7 @@ static inline int bincmp(const uchar *s,
                          const uchar *t, const uchar *te)
 {
   int slen= (int) (se-s), tlen= (int) (te-t);
-  int len=min(slen,tlen);
+  int len= MY_MIN(slen,tlen);
   int cmp= memcmp(s,t,len);
   return cmp ? cmp : slen-tlen;
 }
@@ -7539,7 +7539,7 @@ bincmp_utf8mb4(const uchar *s, const uch
                const uchar *t, const uchar *te)
 {
   int slen= (int) (se - s), tlen= (int) (te - t);
-  int len= min(slen, tlen);
+  int len= MY_MIN(slen, tlen);
   int cmp= memcmp(s, t, len);
   return cmp ? cmp : slen - tlen;
 }

=== modified file 'strings/ctype.c'
--- a/strings/ctype.c	2011-06-30 15:50:45 +0000
+++ b/strings/ctype.c	2011-08-29 12:08:58 +0000
@@ -1035,7 +1035,7 @@ my_convert(char *to, uint32 to_length, c
     return my_convert_internal(to, to_length, to_cs,
                                from, from_length, from_cs, errors);
 
-  length= length2= min(to_length, from_length);
+  length= length2= MY_MIN(to_length, from_length);
 
 #if defined(__i386__)
   /*

=== modified file 'strings/decimal.c'
--- a/strings/decimal.c	2011-08-29 10:28:51 +0000
+++ b/strings/decimal.c	2011-08-29 12:08:58 +0000
@@ -404,7 +404,7 @@ int decimal2string(const decimal_t *from
     for (; frac>0; frac-=DIG_PER_DEC1)
     {
       dec1 x=*buf++;
-      for (i=min(frac, DIG_PER_DEC1); i; i--)
+      for (i= MY_MIN(frac, DIG_PER_DEC1); i; i--)
       {
         dec1 y=x/DIG_MASK;
         *s1++='0'+(uchar)y;
@@ -427,7 +427,7 @@ int decimal2string(const decimal_t *from
     for (buf=buf0+ROUND_UP(intg); intg>0; intg-=DIG_PER_DEC1)
     {
       dec1 x=*--buf;
-      for (i=min(intg, DIG_PER_DEC1); i; i--)
+      for (i= MY_MIN(intg, DIG_PER_DEC1); i; i--)
       {
         dec1 y=x/10;
         *--s='0'+(uchar)(x-y*10);
@@ -1515,8 +1515,8 @@ decimal_round(const decimal_t *from, dec
 
   if (to != from || intg1>intg0)
   {
-    dec1 *p0= buf0+intg0+max(frac1, frac0);
-    dec1 *p1= buf1+intg1+max(frac1, frac0);
+    dec1 *p0= buf0 + intg0 + MY_MAX(frac1, frac0);
+    dec1 *p1= buf1 + intg1 + MY_MAX(frac1, frac0);
 
     while (buf0 < p0)
       *(--p1) = *(--p0);
@@ -1527,7 +1527,7 @@ decimal_round(const decimal_t *from, dec
     buf0=to->buf;
     buf1=to->buf;
     to->sign=from->sign;
-    to->intg=min(intg0, len)*DIG_PER_DEC1;
+    to->intg= MY_MIN(intg0, len) * DIG_PER_DEC1;
   }
 
   if (frac0 > frac1)
@@ -1629,7 +1629,7 @@ decimal_round(const decimal_t *from, dec
         scale=frac0*DIG_PER_DEC1;
         error=E_DEC_TRUNCATED; /* XXX */
       }
-      for (buf1=to->buf+intg0+max(frac0,0); buf1 > to->buf; buf1--)
+      for (buf1=to->buf + intg0 + MY_MAX(frac0, 0); buf1 > to->buf; buf1--)
       {
         buf1[0]=buf1[-1];
       }
@@ -1648,7 +1648,7 @@ decimal_round(const decimal_t *from, dec
         /* making 'zero' with the proper scale */
         dec1 *p0= to->buf + frac0 + 1;
         to->intg=1;
-        to->frac= max(scale, 0);
+        to->frac= MY_MAX(scale, 0);
         to->sign= 0;
         for (buf1= to->buf; buf1<p0; buf1++)
           *buf1= 0;
@@ -1697,11 +1697,11 @@ int decimal_result_size(decimal_t *from1
 {
   switch (op) {
   case '-':
-    return ROUND_UP(max(from1->intg, from2->intg)) +
-           ROUND_UP(max(from1->frac, from2->frac));
+    return ROUND_UP(MY_MAX(from1->intg, from2->intg)) +
+           ROUND_UP(MY_MAX(from1->frac, from2->frac));
   case '+':
-    return ROUND_UP(max(from1->intg, from2->intg)+1) +
-           ROUND_UP(max(from1->frac, from2->frac));
+    return ROUND_UP(MY_MAX(from1->intg, from2->intg)+1) +
+           ROUND_UP(MY_MAX(from1->frac, from2->frac));
   case '*':
     return ROUND_UP(from1->intg+from2->intg)+
            ROUND_UP(from1->frac)+ROUND_UP(from2->frac);
@@ -1716,7 +1716,7 @@ static int do_add(const decimal_t *from1
 {
   int intg1=ROUND_UP(from1->intg), intg2=ROUND_UP(from2->intg),
       frac1=ROUND_UP(from1->frac), frac2=ROUND_UP(from2->frac),
-      frac0=max(frac1, frac2), intg0=max(intg1, intg2), error;
+      frac0= MY_MAX(frac1, frac2), intg0= MY_MAX(intg1, intg2), error;
   dec1 *buf1, *buf2, *buf0, *stop, *stop2, x, carry;
 
   sanity(to);
@@ -1741,7 +1741,7 @@ static int do_add(const decimal_t *from1
   buf0=to->buf+intg0+frac0;
 
   to->sign=from1->sign;
-  to->frac=max(from1->frac, from2->frac);
+  to->frac= MY_MAX(from1->frac, from2->frac);
   to->intg=intg0*DIG_PER_DEC1;
   if (unlikely(error))
   {
@@ -1798,7 +1798,7 @@ static int do_sub(const decimal_t *from1
 {
   int intg1=ROUND_UP(from1->intg), intg2=ROUND_UP(from2->intg),
       frac1=ROUND_UP(from1->frac), frac2=ROUND_UP(from2->frac);
-  int frac0=max(frac1, frac2), error;
+  int frac0= MY_MAX(frac1, frac2), error;
   dec1 *buf1, *buf2, *buf0, *stop1, *stop2, *start1, *start2, carry=0;
 
   /* let carry:=1 if from2 > from1 */
@@ -1873,7 +1873,7 @@ static int do_sub(const decimal_t *from1
   FIX_INTG_FRAC_ERROR(to->len, intg1, frac0, error);
   buf0=to->buf+intg1+frac0;
 
-  to->frac=max(from1->frac, from2->frac);
+  to->frac= MY_MAX(from1->frac, from2->frac);
   to->intg=intg1*DIG_PER_DEC1;
   if (unlikely(error))
   {
@@ -2175,7 +2175,7 @@ static int do_div_mod(const decimal_t *f
          intg=intg2
     */
     to->sign=from1->sign;
-    to->frac=max(from1->frac, from2->frac);
+    to->frac= MY_MAX(from1->frac, from2->frac);
     frac0=0;
   }
   else
@@ -2342,7 +2342,7 @@ static int do_div_mod(const decimal_t *f
       }
       DBUG_ASSERT(intg0 <= ROUND_UP(from2->intg));
       stop1=start1+frac0+intg0;
-      to->intg=min(intg0*DIG_PER_DEC1, from2->intg);
+      to->intg= MY_MIN(intg0 * DIG_PER_DEC1, from2->intg);
     }
     if (unlikely(intg0+frac0 > to->len))
     {

=== modified file 'strings/dtoa.c'
--- a/strings/dtoa.c	2011-09-21 11:55:14 +0000
+++ b/strings/dtoa.c	2011-09-26 12:42:12 +0000
@@ -133,7 +133,7 @@ size_t my_fcvt(double x, int precision,
     if (len <= decpt)
       *dst++= '.';
     
-    for (i= precision - max(0, (len - decpt)); i > 0; i--)
+    for (i= precision - MY_MAX(0, (len - decpt)); i > 0; i--)
       *dst++= '0';
   }
   
@@ -222,7 +222,7 @@ size_t my_gcvt(double x, my_gcvt_arg_typ
   if (x < 0.)
     width--;
 
-  res= dtoa(x, 4, type == MY_GCVT_ARG_DOUBLE ? width : min(width, FLT_DIG),
+  res= dtoa(x, 4, type == MY_GCVT_ARG_DOUBLE ? width : MY_MIN(width, FLT_DIG),
             &decpt, &sign, &end, buf, sizeof(buf));
   if (decpt == DTOA_OVERFLOW)
   {

=== modified file 'strings/my_vsnprintf.c'
--- a/strings/my_vsnprintf.c	2011-06-30 15:50:45 +0000
+++ b/strings/my_vsnprintf.c	2011-08-29 12:08:58 +0000
@@ -231,7 +231,7 @@ static char *process_dbl_arg(char *to, c
     width= FLT_DIG; /* width not set, use default */
   else if (width >= NOT_FIXED_DEC)
     width= NOT_FIXED_DEC - 1; /* max.precision for my_fcvt() */
-  width= min(width, (size_t)(end-to) - 1);
+  width= MY_MIN(width, (size_t)(end-to) - 1);
   
   if (arg_type == 'f')
     to+= my_fcvt(par, (int)width , to, NULL);
@@ -280,7 +280,7 @@ static char *process_int_arg(char *to, c
   /* If %#d syntax was used, we have to pre-zero/pre-space the string */
   if (store_start == buff)
   {
-    length= min(length, to_length);
+    length= MY_MIN(length, to_length);
     if (res_length < length)
     {
       size_t diff= (length- res_length);
@@ -344,7 +344,7 @@ start:
     DBUG_ASSERT(*fmt == '$' && print_arr[idx].length < MAX_ARGS);
     args_arr[print_arr[idx].length].arg_type= 'd';
     print_arr[idx].flags|= LENGTH_ARG;
-    arg_count= max(arg_count, print_arr[idx].length + 1);
+    arg_count= MY_MAX(arg_count, print_arr[idx].length + 1);
     fmt++;
   }
   else
@@ -362,7 +362,7 @@ start:
       DBUG_ASSERT(*fmt == '$' && print_arr[idx].width < MAX_ARGS);
       args_arr[print_arr[idx].width].arg_type= 'd';
       print_arr[idx].flags|= WIDTH_ARG;
-      arg_count= max(arg_count, print_arr[idx].width + 1);
+      arg_count= MY_MAX(arg_count, print_arr[idx].width + 1);
       fmt++;
     }
     else
@@ -490,7 +490,7 @@ start:
       if (to == end)
         break;
 
-      length= min(end - to , print_arr[i].end - print_arr[i].begin);
+      length= MY_MIN(end - to , print_arr[i].end - print_arr[i].begin);
       if (to + length < end)
         length++;
       to= strnmov(to, print_arr[i].begin, length);
@@ -510,7 +510,7 @@ start:
     fmt= get_width(fmt, &arg_index);
     DBUG_ASSERT(*fmt == '$');
     fmt++;
-    arg_count= max(arg_count, arg_index);
+    arg_count= MY_MAX(arg_count, arg_index);
     goto start;
   }
 

=== modified file 'support-files/mysql.spec.sh'
--- a/support-files/mysql.spec.sh	2011-10-19 11:42:46 +0000
+++ b/support-files/mysql.spec.sh	2011-10-28 12:45:35 +0000
@@ -404,11 +404,6 @@ touch optional-files-devel
 # name, finally a default.  RPM_OPT_FLAGS is assumed to be a part of the
 # default RPM build environment.
 #
-# We set CXX=gcc by default to support so-called 'generic' binaries, where we
-# do not have a dependancy on libgcc/libstdc++.  This only works while we do
-# not require C++ features such as exceptions, and may need to be removed at
-# a later date.
-#
 
 # This is a hack, $RPM_OPT_FLAGS on ia64 hosts contains flags which break
 # the compile in cmd-line-utils/readline - needs investigation, but for now
@@ -419,9 +414,9 @@ RPM_OPT_FLAGS=
 
 export PATH=${MYSQL_BUILD_PATH:-$PATH}
 export CC=${MYSQL_BUILD_CC:-${CC:-gcc}}
-export CXX=${MYSQL_BUILD_CXX:-${CXX:-gcc}}
+export CXX=${MYSQL_BUILD_CXX:-${CXX:-g++}}
 export CFLAGS=${MYSQL_BUILD_CFLAGS:-${CFLAGS:-$RPM_OPT_FLAGS}}
-export CXXFLAGS=${MYSQL_BUILD_CXXFLAGS:-${CXXFLAGS:-$RPM_OPT_FLAGS -felide-constructors -fno-exceptions -fno-rtti}}
+export CXXFLAGS=${MYSQL_BUILD_CXXFLAGS:-${CXXFLAGS:-$RPM_OPT_FLAGS -felide-constructors}}
 export LDFLAGS=${MYSQL_BUILD_LDFLAGS:-${LDFLAGS:-}}
 export CMAKE=${MYSQL_BUILD_CMAKE:-${CMAKE:-cmake}}
 export MAKE_JFLAG=${MYSQL_BUILD_MAKE_JFLAG:-}
@@ -1166,6 +1161,12 @@ echo "====="
 
 - Add mysql_plugin man page.
 
+* Tue Aug 30 2011 Tor Didriksen <tor.didriksen@stripped>
+
+- Set CXX=g++ by default to add a dependency on libgcc/libstdc++.
+  Also, remove the use of the -fno-exceptions and -fno-rtti flags.
+  TODO: update distro_buildreq/distro_requires
+
 * Tue Aug 30 2011 Joerg Bruehe <joerg.bruehe@stripped>
 
 - Add the manual page for "mysql_plugin" to the server package.

=== modified file 'tests/mysql_client_test.c'
--- a/tests/mysql_client_test.c	2011-10-06 12:15:21 +0000
+++ b/tests/mysql_client_test.c	2011-10-13 07:26:28 +0000
@@ -625,7 +625,7 @@ static int my_process_stmt_result(MYSQL_
     return row_count;
   }
 
-  field_count= min(mysql_num_fields(result), MAX_RES_FIELDS);
+  field_count= MY_MIN(mysql_num_fields(result), MAX_RES_FIELDS);
 
   memset(buffer, 0, sizeof(buffer));
   memset(length, 0, sizeof(length));

=== modified file 'unittest/gunit/CMakeLists.txt'
--- a/unittest/gunit/CMakeLists.txt	2011-10-13 12:33:08 +0000
+++ b/unittest/gunit/CMakeLists.txt	2011-10-28 12:45:35 +0000
@@ -24,22 +24,6 @@ ELSE()
   SET(HAVE_CMAKE_2_8 1)
 ENDIF() 
 
-IF(CMAKE_COMPILER_IS_GNUCXX)
-  # MySQL is often compiled/linked with gcc rather than g++
-  # (to avoid dependencies on libstdc++.so)
-  # This does not work for googletest binaries.
-  # If we are building with ccache, we need to change arg1.
-  IF(CMAKE_CXX_COMPILER_ARG1)
-    IF(${CMAKE_CXX_COMPILER_ARG1} MATCHES "gcc")
-      SET(CMAKE_CXX_COMPILER_ARG1 "g++")
-    ENDIF()
-  # If we are building with gcc, substitute gcc with g++
-  ELSEIF(${CMAKE_CXX_COMPILER} MATCHES ".*/gcc")
-    STRING(REGEX REPLACE "/gcc$" "/g++" PATH_TO_GCC ${CMAKE_CXX_COMPILER})
-    CMAKE_FORCE_CXX_COMPILER(${PATH_TO_GCC} "GNU g++")
-  ENDIF()
-ENDIF()
-
 IF(MSVC)
   # Restore exception handling flags to avoid tons of warnings when using STL.
   ADD_DEFINITIONS(/EHcs)
@@ -218,8 +202,6 @@ MESSAGE(STATUS "GTEST_LIBRARIES:${GTEST_
 
 # Add some defines.
 ADD_DEFINITIONS(-DMYSQL_SERVER)
-# We use -fno-rtti with gcc, so disable RTTI in gtest as well.
-ADD_DEFINITIONS(-DGTEST_HAS_RTTI=0)
 # /opt/studio12/SUNWspro/bin/CC complains about
 #   iterator_traits is not a member of std
 IF (CMAKE_CXX_COMPILER_ID STREQUAL "SunPro")
@@ -240,6 +222,7 @@ SET(TESTS
   sql_list
   sql_plist
   thread_utils
+  stdcxx
   )
 
 # Add tests (link them with gunit library and the server libraries) 

=== modified file 'unittest/gunit/gunit_test_main.cc'
--- a/unittest/gunit/gunit_test_main.cc	2011-06-30 15:50:45 +0000
+++ b/unittest/gunit/gunit_test_main.cc	2011-10-11 04:27:52 +0000
@@ -18,7 +18,6 @@
 #include "my_config.h"
 #include <gtest/gtest.h>
 
-#include "mdl.h"                                // SHOULD BE my_sys.h
 #include "my_getopt.h"
 
 #include <stdlib.h>

=== modified file 'unittest/gunit/item-t.cc'
--- a/unittest/gunit/item-t.cc	2011-05-25 14:19:53 +0000
+++ b/unittest/gunit/item-t.cc	2011-10-11 04:27:52 +0000
@@ -341,6 +341,16 @@ TEST_F(ItemTest, OutOfMemory)
 #endif
 }
 
+
+// We never use dynamic_cast, but we expect it to work.
+TEST_F(ItemTest, DynamicCast)
+{
+  Item *item= new Item_int(42);
+  const Item_int *null_item= NULL;
+  EXPECT_NE(null_item, dynamic_cast<Item_int*>(item));
+}
+
+
 TEST_F(ItemTest, ItemFuncXor)
 {
   const uint length= 1U;

=== added file 'unittest/gunit/stdcxx-t.cc'
--- a/unittest/gunit/stdcxx-t.cc	1970-01-01 00:00:00 +0000
+++ b/unittest/gunit/stdcxx-t.cc	2011-10-17 12:50:40 +0000
@@ -0,0 +1,107 @@
+/* Copyright (c) 2011, 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; either version 2 of the License, or
+   (at your option) any later version.
+
+   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 Street, Fifth Floor, Boston, MA 02110-1301 USA.
+*/
+
+// First include (the generated) my_config.h, to get correct platform defines,
+// then gtest.h (before any other MySQL headers), to avoid min() macros etc ...
+#include "my_config.h"
+#include <gtest/gtest.h>
+
+#if defined(__GNUC__)
+#include <tr1/unordered_map>
+#elif defined(__WIN__)
+#include <hash_map>
+#elif  defined(__SUNPRO_CC)
+#include <hash_map>
+#else 
+#error "Don't know how to implement hash_map"
+#endif
+
+
+template<typename K, typename T>
+struct MyHashMap
+{
+#if defined(__GNUC__)
+  typedef std::tr1::unordered_map<K, T> Type;
+#elif defined(__WIN__)
+  typedef stdext::hash_map<K, T> Type;
+#elif defined(__SUNPRO_CC)
+  typedef std::hash_map<K, T> Type;
+#endif
+};
+
+
+TEST(STDfeatures, HashMap)
+{
+  MyHashMap<int, int>::Type intmap;
+  for (int ix= 0; ix < 10; ++ix)
+  {
+    intmap[ix]= ix * ix;
+  }
+  int t= intmap[0];
+  EXPECT_EQ(0, t);
+  EXPECT_TRUE(0 == intmap.count(42));
+  EXPECT_TRUE(intmap.end() == intmap.find(42));
+}
+
+#if defined(TARGET_OS_LINUX)
+
+#include <malloc.h>
+
+namespace {
+
+void *nop_malloc_hook(size_t size, const void *caller)
+{
+  return NULL;
+}
+
+TEST(StdCxxNoThrow, NoThrow)
+{
+  typeof(__malloc_hook) old_malloc_hook= __malloc_hook;
+
+  __malloc_hook= nop_malloc_hook;
+
+  const int *pnull= NULL;
+  int *ptr= new (std::nothrow) int;
+  __malloc_hook= old_malloc_hook;
+
+  EXPECT_EQ(pnull, ptr);
+}
+
+TEST(StdCxxExceptionInNew, NewThrowsException)
+{
+  typeof(__malloc_hook) old_malloc_hook= __malloc_hook;
+
+  __malloc_hook= nop_malloc_hook;
+
+  bool thrown= false;
+  try
+  {
+    int *ptr= new int;
+    *ptr= 0;
+  }
+  catch (std::bad_alloc &e)
+  {
+    thrown= true;
+  }
+  __malloc_hook= old_malloc_hook;
+
+  EXPECT_TRUE(thrown);
+}
+
+}
+
+#endif // TARGET_OS_LINUX

=== modified file 'unittest/mysys/lf-t.c'
--- a/unittest/mysys/lf-t.c	2011-07-07 11:22:43 +0000
+++ b/unittest/mysys/lf-t.c	2011-10-11 04:27:52 +0000
@@ -48,9 +48,9 @@ pthread_handler_t test_lf_pinbox(void *a
     pins= lf_pinbox_get_pins(&lf_allocator.pinbox);
   }
   lf_pinbox_put_pins(pins);
-  pthread_mutex_lock(&mutex);
-  if (!--running_threads) pthread_cond_signal(&cond);
-  pthread_mutex_unlock(&mutex);
+  mysql_mutex_lock(&mutex);
+  if (!--running_threads) mysql_cond_signal(&cond);
+  mysql_mutex_unlock(&mutex);
 
   if (with_my_thread_init)
     my_thread_end();
@@ -94,7 +94,7 @@ pthread_handler_t test_lf_alloc(void *ar
     lf_alloc_free(pins, node2);
   }
   lf_alloc_put_pins(pins);
-  pthread_mutex_lock(&mutex);
+  mysql_mutex_lock(&mutex);
   bad+= y;
 
   if (--N == 0)
@@ -105,8 +105,8 @@ pthread_handler_t test_lf_alloc(void *ar
     bad|= lf_allocator.mallocs - lf_alloc_pool_count(&lf_allocator);
 #endif
   }
-  if (!--running_threads) pthread_cond_signal(&cond);
-  pthread_mutex_unlock(&mutex);
+  if (!--running_threads) mysql_cond_signal(&cond);
+  mysql_mutex_unlock(&mutex);
 
   if (with_my_thread_init)
     my_thread_end();
@@ -148,7 +148,7 @@ pthread_handler_t test_lf_hash(void *arg
     }
   }
   lf_hash_put_pins(pins);
-  pthread_mutex_lock(&mutex);
+  mysql_mutex_lock(&mutex);
   bad+= sum;
   inserts+= ins;
 
@@ -159,8 +159,8 @@ pthread_handler_t test_lf_hash(void *arg
          lf_hash.size, inserts);
     bad|= lf_hash.count;
   }
-  if (!--running_threads) pthread_cond_signal(&cond);
-  pthread_mutex_unlock(&mutex);
+  if (!--running_threads) mysql_cond_signal(&cond);
+  mysql_mutex_unlock(&mutex);
   if (with_my_thread_init)
     my_thread_end();
   return 0;

=== modified file 'unittest/mysys/my_atomic-t.c'
--- a/unittest/mysys/my_atomic-t.c	2011-10-03 07:31:55 +0000
+++ b/unittest/mysys/my_atomic-t.c	2011-10-13 07:26:28 +0000
@@ -35,9 +35,9 @@ pthread_handler_t test_atomic_add(void *
     my_atomic_add32(&bad, -x);
     my_atomic_rwlock_wrunlock(&rwl);
   }
-  pthread_mutex_lock(&mutex);
-  if (!--running_threads) pthread_cond_signal(&cond);
-  pthread_mutex_unlock(&mutex);
+  mysql_mutex_lock(&mutex);
+  if (!--running_threads) mysql_cond_signal(&cond);
+  mysql_mutex_unlock(&mutex);
   return 0;
 }
 
@@ -58,13 +58,13 @@ pthread_handler_t test_atomic_add64(void
     my_atomic_add64(&a64, -x);
     my_atomic_rwlock_wrunlock(&rwl);
   }
-  pthread_mutex_lock(&mutex);
+  mysql_mutex_lock(&mutex);
   if (!--running_threads)
   {
     bad= (a64 != 0);
-    pthread_cond_signal(&cond);
+    mysql_cond_signal(&cond);
   }
-  pthread_mutex_unlock(&mutex);
+  mysql_mutex_unlock(&mutex);
   return 0;
 }
 
@@ -108,9 +108,9 @@ pthread_handler_t test_atomic_fas(void *
   my_atomic_add32(&bad, -x);
   my_atomic_rwlock_wrunlock(&rwl);
 
-  pthread_mutex_lock(&mutex);
-  if (!--running_threads) pthread_cond_signal(&cond);
-  pthread_mutex_unlock(&mutex);
+  mysql_mutex_lock(&mutex);
+  if (!--running_threads) mysql_cond_signal(&cond);
+  mysql_mutex_unlock(&mutex);
   return 0;
 }
 
@@ -140,9 +140,9 @@ pthread_handler_t test_atomic_cas(void *
       my_atomic_rwlock_wrunlock(&rwl);
     } while (!ok) ;
   }
-  pthread_mutex_lock(&mutex);
-  if (!--running_threads) pthread_cond_signal(&cond);
-  pthread_mutex_unlock(&mutex);
+  mysql_mutex_lock(&mutex);
+  if (!--running_threads) mysql_cond_signal(&cond);
+  mysql_mutex_unlock(&mutex);
   return 0;
 }
 

=== modified file 'unittest/mysys/thr_template.c'
--- a/unittest/mysys/thr_template.c	2011-06-30 15:46:53 +0000
+++ b/unittest/mysys/thr_template.c	2011-10-11 04:27:52 +0000
@@ -21,8 +21,8 @@
 
 volatile uint32 bad;
 pthread_attr_t thr_attr;
-pthread_mutex_t mutex;
-pthread_cond_t cond;
+mysql_mutex_t mutex;
+mysql_cond_t cond;
 uint running_threads;
 
 void do_tests();
@@ -43,10 +43,10 @@ void test_concurrently(const char *test,
       abort();
     }
   }
-  pthread_mutex_lock(&mutex);
+  mysql_mutex_lock(&mutex);
   while (running_threads)
-    pthread_cond_wait(&cond, &mutex);
-  pthread_mutex_unlock(&mutex);
+    mysql_cond_wait(&cond, &mutex);
+  mysql_mutex_unlock(&mutex);
 
   now= my_getsystime()-now;
   ok(!bad, "tested %s in %g secs (%d)", test, ((double)now)/1e7, bad);
@@ -59,8 +59,8 @@ int main(int argc __attribute__((unused)
   if (argv[1] && *argv[1])
     DBUG_SET_INITIAL(argv[1]);
 
-  pthread_mutex_init(&mutex, 0);
-  pthread_cond_init(&cond, 0);
+  mysql_mutex_init(0, &mutex, 0);
+  mysql_cond_init(0, &cond, 0);
   pthread_attr_init(&thr_attr);
   pthread_attr_setdetachstate(&thr_attr,PTHREAD_CREATE_DETACHED);
 
@@ -84,8 +84,8 @@ int main(int argc __attribute__((unused)
     (BUG#22320).
   */
   sleep(2);
-  pthread_mutex_destroy(&mutex);
-  pthread_cond_destroy(&cond);
+  mysql_mutex_destroy(&mutex);
+  mysql_cond_destroy(&cond);
   pthread_attr_destroy(&thr_attr);
   my_end(0);
   return exit_status();

=== modified file 'unittest/mysys/waiting_threads-t.c'
--- a/unittest/mysys/waiting_threads-t.c	2011-06-30 15:50:45 +0000
+++ b/unittest/mysys/waiting_threads-t.c	2011-10-11 04:27:52 +0000
@@ -74,12 +74,12 @@ static double my_rnd(struct my_rnd_struc
 
 struct test_wt_thd {
   WT_THD thd;
-  pthread_mutex_t lock;
+  mysql_mutex_t lock;
 } thds[THREADS];
 
 uint i, cnt;
-pthread_mutex_t lock;
-pthread_cond_t thread_sync;
+mysql_mutex_t lock;
+mysql_cond_t thread_sync;
 
 ulong wt_timeout_short=100, wt_deadlock_search_depth_short=4;
 ulong wt_timeout_long=10000, wt_deadlock_search_depth_long=15;
@@ -104,7 +104,7 @@ pthread_handler_t test_wt(void *arg)
 
   my_thread_init();
 
-  pthread_mutex_lock(&mutex);
+  mysql_mutex_lock(&mutex);
   id= cnt++;
   wt_thd_lazy_init(& thds[id].thd,
                    & wt_deadlock_search_depth_short, & wt_timeout_short,
@@ -112,11 +112,11 @@ pthread_handler_t test_wt(void *arg)
 
   /* now, wait for everybody to be ready to run */
   if (cnt >= THREADS)
-    pthread_cond_broadcast(&thread_sync);
+    mysql_cond_broadcast(&thread_sync);
   else
     while (cnt < THREADS)
-      pthread_cond_wait(&thread_sync, &mutex);
-  pthread_mutex_unlock(&mutex);
+      mysql_cond_wait(&thread_sync, &mutex);
+  mysql_mutex_unlock(&mutex);
 
   my_rnd_init(&rand, (ulong)(intptr)&m, id);
   if (kill_strategy == YOUNGEST)
@@ -149,25 +149,25 @@ retry:
       if (kill_strategy == RANDOM)
         thds[id].thd.weight= rnd();
 
-      pthread_mutex_lock(& thds[i].lock);
+      mysql_mutex_lock(& thds[i].lock);
       res= wt_thd_will_wait_for(& thds[id].thd, & thds[i].thd, &resid);
-      pthread_mutex_unlock(& thds[i].lock);
+      mysql_mutex_unlock(& thds[i].lock);
     }
 
     if (!res)
     {
-      pthread_mutex_lock(&lock);
+      mysql_mutex_lock(&lock);
       res= wt_thd_cond_timedwait(& thds[id].thd, &lock);
-      pthread_mutex_unlock(&lock);
+      mysql_mutex_unlock(&lock);
     }
 
     if (res)
     {
-      pthread_mutex_lock(& thds[id].lock);
-      pthread_mutex_lock(&lock);
+      mysql_mutex_lock(& thds[id].lock);
+      mysql_mutex_lock(&lock);
       wt_thd_release_all(& thds[id].thd);
-      pthread_mutex_unlock(&lock);
-      pthread_mutex_unlock(& thds[id].lock);
+      mysql_mutex_unlock(&lock);
+      mysql_mutex_unlock(& thds[id].lock);
       if (kill_strategy == LOCKS)
         thds[id].thd.weight= 0;
       if (kill_strategy == YOUNGEST)
@@ -177,24 +177,24 @@ retry:
       thds[id].thd.weight++;
   }
 
-  pthread_mutex_lock(&mutex);
+  mysql_mutex_lock(&mutex);
   /* wait for everybody to finish */
   if (!--cnt)
-    pthread_cond_broadcast(&thread_sync);
+    mysql_cond_broadcast(&thread_sync);
   else
     while (cnt)
-      pthread_cond_wait(&thread_sync, &mutex);
+      mysql_cond_wait(&thread_sync, &mutex);
 
-  pthread_mutex_lock(& thds[id].lock);
-  pthread_mutex_lock(&lock);
+  mysql_mutex_lock(& thds[id].lock);
+  mysql_mutex_lock(&lock);
   wt_thd_release_all(& thds[id].thd);
-  pthread_mutex_unlock(&lock);
-  pthread_mutex_unlock(& thds[id].lock);
+  mysql_mutex_unlock(&lock);
+  mysql_mutex_unlock(& thds[id].lock);
   wt_thd_destroy(& thds[id].thd);
 
   if (!--running_threads) /* now, signal when everybody is done with deinit */
-    pthread_cond_signal(&cond);
-  pthread_mutex_unlock(&mutex);
+    mysql_cond_signal(&cond);
+  mysql_mutex_unlock(&mutex);
   DBUG_PRINT("wt", ("exiting"));
   my_thread_end();
   return 0;
@@ -247,11 +247,11 @@ void do_tests()
   bad= my_atomic_initialize();
   ok(!bad, "my_atomic_initialize() returned %d", bad);
 
-  pthread_cond_init(&thread_sync, 0);
-  pthread_mutex_init(&lock, 0);
+  mysql_cond_init(0, &thread_sync, 0);
+  mysql_mutex_init(0, &lock, 0);
   wt_init();
   for (cnt=0; cnt < THREADS; cnt++)
-    pthread_mutex_init(& thds[cnt].lock, 0);
+    mysql_mutex_init(0, & thds[cnt].lock, 0);
   {
     WT_RESOURCE_ID resid[4];
     for (i=0; i < array_elements(resid); i++)
@@ -276,16 +276,16 @@ void do_tests()
     ok_wait(0,2,0);
     ok_wait(0,3,0);
 
-    pthread_mutex_lock(&lock);
+    mysql_mutex_lock(&lock);
     bad= wt_thd_cond_timedwait(& thds[0].thd, &lock);
-    pthread_mutex_unlock(&lock);
+    mysql_mutex_unlock(&lock);
     ok(bad == WT_TIMEOUT, "timeout test returned %d", bad);
 
     ok_wait(0,1,0);
     ok_wait(1,2,1);
     ok_deadlock(2,0,2);
 
-    pthread_mutex_lock(&lock);
+    mysql_mutex_lock(&lock);
     ok(wt_thd_cond_timedwait(& thds[0].thd, &lock) == WT_TIMEOUT, "as always");
     ok(wt_thd_cond_timedwait(& thds[1].thd, &lock) == WT_TIMEOUT, "as always");
     wt_thd_release_all(& thds[0].thd);
@@ -298,7 +298,7 @@ void do_tests()
       wt_thd_release_all(& thds[i].thd);
       wt_thd_destroy(& thds[i].thd);
     }
-    pthread_mutex_unlock(&lock);
+    mysql_mutex_unlock(&lock);
   }
 
   wt_deadlock_search_depth_short=6;
@@ -332,9 +332,9 @@ void do_tests()
 
   DBUG_PRINT("wt", ("================= cleanup ==================="));
   for (cnt=0; cnt < THREADS; cnt++)
-    pthread_mutex_destroy(& thds[cnt].lock);
+    mysql_mutex_destroy(& thds[cnt].lock);
   wt_end();
-  pthread_mutex_destroy(&lock);
-  pthread_cond_destroy(&thread_sync);
+  mysql_mutex_destroy(&lock);
+  mysql_cond_destroy(&thread_sync);
   DBUG_VOID_RETURN;
 }

=== modified file 'vio/viosocket.c'
--- a/vio/viosocket.c	2011-08-17 20:31:46 +0000
+++ b/vio/viosocket.c	2011-08-29 12:08:58 +0000
@@ -143,7 +143,7 @@ size_t vio_read_buff(Vio *vio, uchar* bu
 
   if (vio->read_pos < vio->read_end)
   {
-    rc= min((size_t) (vio->read_end - vio->read_pos), size);
+    rc= MY_MIN((size_t) (vio->read_end - vio->read_pos), size);
     memcpy(buf, vio->read_pos, rc);
     vio->read_pos+= rc;
     /*

=== modified file 'win/create_def_file.js'
--- a/win/create_def_file.js	2011-06-30 15:46:53 +0000
+++ b/win/create_def_file.js	2011-10-11 04:27:52 +0000
@@ -169,6 +169,10 @@ function ScrubSymbol(symbol)
 function IsCompilerDefinedSymbol(symbol)
 {
     return ((symbol.indexOf("__real@") != -1) ||
+    (symbol.indexOf("_CTA2?") != -1) ||        // std::bad_alloc
+    (symbol.indexOf("_CTA3?") != -1) ||        // std::length_error
+    (symbol.indexOf("_TI2?") != -1) ||         // std::bad_alloc
+    (symbol.indexOf("_TI3?") != -1) ||         // std::length_error
     (symbol.indexOf("_RTC_") != -1) || 
     (symbol.indexOf("??_C@_") != -1) ||
     (symbol.indexOf("??_R") != -1) ||

No bundle (reason: useless for push emails).
Thread
bzr push into mysql-trunk-mtr branch (bjorn.munch:3132 to 3133) Bjorn Munch7 Nov