From 8430c62d482e28f0d68a864ca6ecfc55d6c1d97d Mon Sep 17 00:00:00 2001 From: Vladimir Vukicevic Date: Thu, 20 Aug 2009 18:46:34 -0700 Subject: [PATCH] b=511568; WinCE shunt not overriding std::nothrow operator new; r=blassey --- build/wince/shunt/include/mozce_shunt.h | 50 +++++++++++++++++++++++-- build/wince/shunt/memory.cpp | 20 +--------- build/wince/shunt/mozce_shunt.def.in | 6 +++ 3 files changed, 54 insertions(+), 22 deletions(-) diff --git a/build/wince/shunt/include/mozce_shunt.h b/build/wince/shunt/include/mozce_shunt.h index 25c1b233731f..2dee7e9be6aa 100644 --- a/build/wince/shunt/include/mozce_shunt.h +++ b/build/wince/shunt/include/mozce_shunt.h @@ -54,11 +54,53 @@ typedef unsigned short wchar_t; #ifdef MOZ_MEMORY #ifdef __cplusplus + +// define these so we don't include from either VC or +// the CE5 SDK #define _NEW_ -void * operator new(size_t _Size); -void operator delete(void * ptr); -void *operator new[](size_t size); -void operator delete[](void *ptr); +#define _INC_NEW + +#ifndef __NOTHROW_T_DEFINED +#define __NOTHROW_T_DEFINED +namespace std { + struct nothrow_t {}; + extern const nothrow_t nothrow; +}; +#endif + +// grab malloc and free prototypes +#include "jemalloc.h" + +// Normal and nothrow versions of operator new, none of which +// actually throw for us. These are both inline and exported +// from the shunt. +inline void *operator new(size_t size) throw() { + return (void*) malloc(size); +} +inline void *operator new(size_t size, const std::nothrow_t&) throw() { + return (void*) malloc(size); +} +inline void operator delete(void *ptr) throw() { + free(ptr); +} +inline void *operator new[](size_t size) throw() { + return (void*) malloc(size); +} +inline void *operator new[](size_t size, const std::nothrow_t&) throw() { + return (void*) malloc(size); +} +inline void operator delete[](void *ptr) throw() { + return free(ptr); +} + +// Placement new. Just inline, not exported (which doesn't work for +// some reason, but it's a noop in any case) +inline void *operator new(size_t, void *p) { + return p; +} +inline void *operator new[](size_t, void *p) { + return p; +} extern "C" { #endif diff --git a/build/wince/shunt/memory.cpp b/build/wince/shunt/memory.cpp index 0c2086a278ad..c91bee22c794 100644 --- a/build/wince/shunt/memory.cpp +++ b/build/wince/shunt/memory.cpp @@ -40,25 +40,9 @@ #include #ifdef MOZ_MEMORY -void * operator new(size_t _Size) -{ - void *p = malloc(_Size); - return (p); -} -void operator delete(void * ptr) -{ - free(ptr); -} -void *operator new[](size_t size) -{ - void* p = malloc(size); - return (p); -} -void operator delete[](void *ptr) -{ - free(ptr); -} +// declare the nothrow object +const std::nothrow_t std::nothrow; char* _strndup(const char *src, size_t len) { diff --git a/build/wince/shunt/mozce_shunt.def.in b/build/wince/shunt/mozce_shunt.def.in index f5c98391d888..5968921c2249 100644 --- a/build/wince/shunt/mozce_shunt.def.in +++ b/build/wince/shunt/mozce_shunt.def.in @@ -24,12 +24,18 @@ strftime time #ifdef MOZ_MEMORY +;; std::nothrow object +?nothrow@std@@3Unothrow_t@1@B ;; operator new ??2@YAPAXI@Z +;; operator new nothrow +??2@YAPAXIABUnothrow_t@std@@@Z ;; operator delete ??3@YAXPAX@Z ;; operator new[] ??_U@YAPAXI@Z +;; operator new[] nothrow +??_U@YAPAXIABUnothrow_t@std@@@Z ;; operator delete[] ??_V@YAXPAX@Z malloc