Bug 1067018 - Always specify throw() for nothrow placement new/delete; r=glandium
authorJim Chen <nchen@mozilla.com>
Fri, 26 Sep 2014 15:45:45 -0400
changeset 207558 64550e741f147f73c02948f55c93369d426d44b2
parent 207557 b5705fbed44fc7d87fde9e8cd870862a83f879b6
child 207559 4793e12b972083254882011f0b2bb47ff19c3ff1
push id27562
push usercbook@mozilla.com
push dateMon, 29 Sep 2014 13:45:04 +0000
treeherdermozilla-central@f57209ddc739 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersglandium
bugs1067018
milestone35.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1067018 - Always specify throw() for nothrow placement new/delete; r=glandium
build/autoconf/android.m4
build/stlport/README.mozilla
build/stlport/overrides/new
memory/mozalloc/mozalloc.h
--- a/build/autoconf/android.m4
+++ b/build/autoconf/android.m4
@@ -234,17 +234,17 @@ if test "$OS_TARGET" = "Android" -a -z "
             elif test -e "$android_ndk/sources/cxx-stl/gnu-libstdc++/libs/$ANDROID_CPU_ARCH/libstdc++.a"; then
                 # android-ndk-r5c, android-ndk-r6, android-ndk-r6b
                 STLPORT_CPPFLAGS="-I$android_ndk/sources/cxx-stl/gnu-libstdc++/include -I$android_ndk/sources/cxx-stl/gnu-libstdc++/libs/$ANDROID_CPU_ARCH/include"
                 STLPORT_LIBS="-L$android_ndk/sources/cxx-stl/gnu-libstdc++/libs/$ANDROID_CPU_ARCH/ -lstdc++"
             else
                 AC_MSG_ERROR([Couldn't find path to gnu-libstdc++ in the android ndk])
             fi
         else
-            STLPORT_CPPFLAGS="-isystem $_topsrcdir/build/stlport/stlport -isystem $android_ndk/sources/cxx-stl/system/include"
+            STLPORT_CPPFLAGS="-isystem $_topsrcdir/build/stlport/stlport -isystem $_topsrcdir/build/stlport/overrides -isystem $android_ndk/sources/cxx-stl/system/include"
             STLPORT_LIBS="$_objdir/build/stlport/libstlport_static.a -static-libstdc++"
         fi
     fi
     CXXFLAGS="$CXXFLAGS $STLPORT_CPPFLAGS"
 fi
 AC_SUBST([MOZ_ANDROID_LIBSTDCXX])
 AC_SUBST([STLPORT_LIBS])
 
--- a/build/stlport/README.mozilla
+++ b/build/stlport/README.mozilla
@@ -1,7 +1,9 @@
 This copy of STLport was taken from the Android NDK r8e.
 Android specific changes are listed in README.android.
 The libs/ directory containing prebuilt static libraries was removed.
+The overrides/ directory contains Mozilla-specific overrides to the standard
+  C++ headers found in the NDK.
 
 The following patches are applied on top:
 - android-mozilla-config.patch: Adjusts Android-specific configuration
   to the mozilla codebase use of the STL.
new file mode 100644
--- /dev/null
+++ b/build/stlport/overrides/new
@@ -0,0 +1,65 @@
+/* -*- c++ -*- */
+/*
+ * Copyright (C) 2009 The Android Open Source Project
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *  * Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ *  * Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the
+ *    distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+ * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+/*
+ * This header is taken from $ndk/sources/cxx-stl/system/include/new,
+ * and it fixes a bug in the NDK header where the nothrow versions of
+ * placement new and delete are not specified with 'throw()'. This bug
+ * causes GCC to not null-check the results from these functions.
+ */
+#ifndef __NEW__
+#define __NEW__
+
+#include <cstddef>
+
+extern "C++" {
+
+namespace std {
+    struct nothrow_t {};
+    extern const nothrow_t nothrow;
+}
+
+void* operator new(std::size_t);
+void* operator new[](std::size_t);
+void  operator delete(void*);
+void  operator delete[](void*);
+void* operator new(std::size_t, const std::nothrow_t&) throw();
+void* operator new[](std::size_t, const std::nothrow_t&) throw();
+void  operator delete(void*, const std::nothrow_t&) throw();
+void  operator delete[](void*, const std::nothrow_t&) throw();
+
+inline void* operator new(std::size_t, void* p) { return p; }
+inline void* operator new[](std::size_t, void* p) { return p; }
+
+// these next two are not really required, since exceptions are off
+inline void  operator delete(void*, void*) { }
+inline void  operator delete[](void*, void*) { }
+
+}  // extern C++
+
+#endif // __NEW__
--- a/memory/mozalloc/mozalloc.h
+++ b/memory/mozalloc/mozalloc.h
@@ -175,23 +175,30 @@ MOZALLOC_EXPORT void* moz_valloc(size_t 
  * visibility on OS X/gcc. These symbols are force-inline and not
  * exported. */
 #if defined(XP_MACOSX)
 #  define MOZALLOC_EXPORT_NEW MOZALLOC_EXPORT
 #else
 #  define MOZALLOC_EXPORT_NEW
 #endif
 
-#if defined(ANDROID) || defined(_MSC_VER)
+#if defined(ANDROID)
 /*
- * Android doesn't fully support exceptions, so its <new> header
- * has operators that don't specify throw() at all. Also include MSVC
- * to suppress build warning spam (bug 578546).
+ * It's important to always specify 'throw()' in GCC because it's used to tell
+ * GCC that 'new' may return null. That makes GCC null-check the result before
+ * potentially initializing the memory to zero.
+ * Also, the Android minimalistic headers don't include std::bad_alloc.
  */
-#define MOZALLOC_THROW_IF_HAS_EXCEPTIONS /**/
+#define MOZALLOC_THROW_IF_HAS_EXCEPTIONS throw()
+#define MOZALLOC_THROW_BAD_ALLOC_IF_HAS_EXCEPTIONS
+#elif defined(_MSC_VER)
+/*
+ * Suppress build warning spam (bug 578546).
+ */
+#define MOZALLOC_THROW_IF_HAS_EXCEPTIONS
 #define MOZALLOC_THROW_BAD_ALLOC_IF_HAS_EXCEPTIONS
 #else
 #define MOZALLOC_THROW_IF_HAS_EXCEPTIONS throw()
 #define MOZALLOC_THROW_BAD_ALLOC_IF_HAS_EXCEPTIONS throw(std::bad_alloc)
 #endif
 
 #define MOZALLOC_THROW_BAD_ALLOC MOZALLOC_THROW_BAD_ALLOC_IF_HAS_EXCEPTIONS