Bug 551071: Suppress valgrind-reported "mismatched free()" (false alarm) of chromium objects by using mozalloc there (complements STL wrappers). Add a gross hack to prevent mozalloc macros from conflicting with methods in jscntxt.h. r=bent r=bsmedberg dependent-r=brendan
authorChris Jones <jones.chris.g@gmail.com>
Fri, 04 Jun 2010 18:16:34 -0500
changeset 43110 402192edce61ba35608025666d98a11ec44f20bf
parent 43109 f194fff90d5f8a527b46525e24c8a6f8baac85e0
child 43111 ba82b6ecb9ce7211536377aadd5754bdf37d4854
push id13623
push usercjones@mozilla.com
push dateFri, 04 Jun 2010 23:17:17 +0000
treeherdermozilla-central@402192edce61 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbent, bsmedberg
bugs551071
milestone1.9.3a5pre
first release with
nightly win64
402192edce61 / 3.7a5pre / 20100604175654 / files
nightly linux32
nightly linux64
nightly mac
nightly win32
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
releases
nightly win64
Bug 551071: Suppress valgrind-reported "mismatched free()" (false alarm) of chromium objects by using mozalloc there (complements STL wrappers). Add a gross hack to prevent mozalloc macros from conflicting with methods in jscntxt.h. r=bent r=bsmedberg dependent-r=brendan
ipc/chromium/src/base/basictypes.h
js/src/jscntxt.h
memory/mozalloc/Makefile.in
memory/mozalloc/mozalloc_undef_macro_wrappers.h
--- a/ipc/chromium/src/base/basictypes.h
+++ b/ipc/chromium/src/base/basictypes.h
@@ -387,9 +387,12 @@ inline Dest bit_cast(const Source& sourc
 //       explicit MyClass(base::LinkerInitialized x) {}
 // and invoked as
 //       static MyClass my_variable_name(base::LINKER_INITIALIZED);
 namespace base {
 enum LinkerInitialized { LINKER_INITIALIZED };
 }  // base
 
 
+#include "nscore.h"             // pick up mozalloc operator new() etc.
+
+
 #endif  // BASE_BASICTYPES_H_
--- a/js/src/jscntxt.h
+++ b/js/src/jscntxt.h
@@ -40,16 +40,23 @@
 
 #ifndef jscntxt_h___
 #define jscntxt_h___
 /*
  * JS execution context.
  */
 #include <string.h>
 
+/* Gross special case for Gecko, which defines malloc/calloc/free. */
+#ifdef mozilla_mozalloc_macro_wrappers_h
+#  define JS_UNDEFD_MOZALLOC_WRAPPERS
+/* The "anti-header" */
+#  include "mozilla/mozalloc_undef_macro_wrappers.h"
+#endif
+
 #include "jsarena.h" /* Added by JSIFY */
 #include "jsclist.h"
 #include "jslong.h"
 #include "jsatom.h"
 #include "jsdhash.h"
 #include "jsdtoa.h"
 #include "jsgc.h"
 #include "jshashtable.h"
@@ -3059,9 +3066,13 @@ NewIdArray(JSContext *cx, jsint length);
 
 }
 
 #ifdef _MSC_VER
 #pragma warning(pop)
 #pragma warning(pop)
 #endif
 
+#ifdef JS_UNDEFD_MOZALLOC_WRAPPERS
+#  include "mozilla/mozalloc_macro_wrappers.h"
+#endif
+
 #endif /* jscntxt_h___ */
--- a/memory/mozalloc/Makefile.in
+++ b/memory/mozalloc/Makefile.in
@@ -79,16 +79,17 @@ DEFINES		+= -D_GNU_SOURCE
 endif
 
 EXPORTS_NAMESPACES 	= mozilla
 EXPORTS_mozilla 	=			\
 	mozalloc.h		 		\
 	mozalloc_abort.h			\
 	mozalloc_macro_wrappers.h 		\
 	mozalloc_oom.h				\
+	mozalloc_undef_macro_wrappers.h		\
 	$(NULL)
 
 CPPSRCS 		=			\
 	mozalloc.cpp				\
 	mozalloc_abort.cpp			\
 	mozalloc_oom.cpp			\
 	$(NULL)
 
new file mode 100644
--- /dev/null
+++ b/memory/mozalloc/mozalloc_undef_macro_wrappers.h
@@ -0,0 +1,77 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
+ * vim: sw=4 ts=4 et :
+ */
+/* ***** BEGIN LICENSE BLOCK *****
+ * Version: MPL 1.1/GPL 2.0/LGPL 2.1
+ *
+ * The contents of this file are subject to the Mozilla Public License Version
+ * 1.1 (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ * http://www.mozilla.org/MPL/
+ *
+ * Software distributed under the License is distributed on an "AS IS" basis,
+ * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
+ * for the specific language governing rights and limitations under the
+ * License.
+ *
+ * The Original Code is mozilla.org code.
+ *
+ * The Initial Developer of the Original Code is
+ * Mozilla Foundation
+ * Portions created by the Initial Developer are Copyright (C) 2010
+ * the Initial Developer. All Rights Reserved.
+ *
+ * Contributor(s):
+ *  Chris Jones <jones.chris.g@gmail.com>
+ *
+ * Alternatively, the contents of this file may be used under the terms of
+ * either of the GNU General Public License Version 2 or later (the "GPL"),
+ * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
+ * in which case the provisions of the GPL or the LGPL are applicable instead
+ * of those above. If you wish to allow use of your version of this file only
+ * under the terms of either the GPL or the LGPL, and not to allow others to
+ * use your version of this file under the terms of the MPL, indicate your
+ * decision by deleting the provisions above and replace them with the notice
+ * and other provisions required by the GPL or the LGPL. If you do not delete
+ * the provisions above, a recipient may use your version of this file under
+ * the terms of any one of the MPL, the GPL or the LGPL.
+ *
+ * ***** END LICENSE BLOCK ***** */
+
+/*
+ * This header is the "anti-header" for mozalloc_macro_wrappers.h.
+ * Including it undefines all the macros defined by
+ * mozalloc_macro_wrappers.h.
+ */
+
+#ifndef mozilla_mozalloc_macro_wrappers_h
+#  error "mozalloc macro wrappers haven't been defined"
+#endif
+
+/*
+ * This allows the wrappers to be redefined by including
+ * mozalloc_macro_wrappers.h again 
+ */
+#undef mozilla_mozalloc_macro_wrappers_h
+
+#undef free
+#undef malloc
+#undef calloc
+#undef realloc
+#undef strdup
+
+#if defined(HAVE_STRNDUP)
+#  undef strndup
+#endif
+
+#if defined(HAVE_POSIX_MEMALIGN) || defined(HAVE_JEMALLOC_POSIX_MEMALIGN)
+#  undef posix_memalign
+#endif
+
+#if defined(HAVE_MEMALIGN) || defined(HAVE_JEMALLOC_MEMALIGN)
+#  undef memalign
+#endif
+
+#if defined(HAVE_VALLOC)
+#  undef valloc
+#endif