mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-24 13:21:05 +00:00
Bug 1553363 - Generalize the *_impl goop for allocation functions in mozglue. r=froydnj
The current situation is suboptimal, where we have the same goop repeated in multiple files, and where things kinda sorta work out fine thanks to the linker for files that would have been forbidden, except when the linker doesn't do its job, which apparently happen on mingwclang builds. This change only really covers C++ code using operator new/delete, and not things that would be using malloc/free, because it's easier. malloc/free is left for a followup. Differential Revision: https://phabricator.services.mozilla.com/D32119 --HG-- extra : moz-landing-system : lando
This commit is contained in:
parent
0946812131
commit
2abcc3d7cb
@ -4,7 +4,7 @@
|
||||
# License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
|
||||
Library('mscom-mozglue')
|
||||
FINAL_LIBRARY = 'mozglue'
|
||||
|
||||
EXPORTS.mozilla.mscom += [
|
||||
'ProcessRuntimeShared.h',
|
||||
@ -14,8 +14,6 @@ LOCAL_INCLUDES += [
|
||||
'/mozglue/build',
|
||||
]
|
||||
|
||||
DEFINES['IMPL_MFBT'] = True
|
||||
|
||||
UNIFIED_SOURCES += [
|
||||
'ProcessRuntimeShared.cpp',
|
||||
]
|
||||
|
@ -45,8 +45,6 @@ DEFINES['_GNU_SOURCE'] = True
|
||||
|
||||
DisableStlWrapping()
|
||||
|
||||
DEFINES['IMPL_MFBT'] = True
|
||||
|
||||
LOCAL_INCLUDES += [
|
||||
'!/xpcom',
|
||||
'/memory/build',
|
||||
|
@ -7,35 +7,14 @@
|
||||
|
||||
#include <stddef.h> // for size_t
|
||||
|
||||
#if defined(MOZ_MEMORY)
|
||||
// mozalloc.cpp is part of the same library as mozmemory, thus MOZ_MEMORY_IMPL
|
||||
// is needed.
|
||||
# define MOZ_MEMORY_IMPL
|
||||
# include "mozmemory_wrap.h"
|
||||
#if defined(MALLOC_H)
|
||||
# include MALLOC_H // for memalign, malloc_size, malloc_us
|
||||
#endif // if defined(MALLOC_H)
|
||||
|
||||
# if defined(XP_DARWIN)
|
||||
# include <malloc/malloc.h> // for malloc_size
|
||||
# endif
|
||||
|
||||
// See mozmemory_wrap.h for more details. This file is part of libmozglue, so
|
||||
// it needs to use _impl suffixes. However, with libmozglue growing, this is
|
||||
// becoming cumbersome, so we will likely use a malloc.h wrapper of some sort
|
||||
// and allow the use of the functions without a _impl suffix.
|
||||
# define MALLOC_DECL(name, return_type, ...) \
|
||||
MOZ_MEMORY_API return_type name##_impl(__VA_ARGS__);
|
||||
# define MALLOC_FUNCS MALLOC_FUNCS_MALLOC
|
||||
# include "malloc_decls.h"
|
||||
|
||||
MOZ_MEMORY_API char* strdup_impl(const char*);
|
||||
MOZ_MEMORY_API char* strndup_impl(const char*, size_t);
|
||||
|
||||
#else
|
||||
#if !defined(MOZ_MEMORY)
|
||||
// When jemalloc is disabled, or when building the static runtime variant,
|
||||
// we need not to use the suffixes.
|
||||
|
||||
# if defined(MALLOC_H)
|
||||
# include MALLOC_H // for memalign, malloc_size, malloc_us
|
||||
# endif // if defined(MALLOC_H)
|
||||
# include <stdlib.h> // for malloc, free
|
||||
# if defined(XP_UNIX)
|
||||
# include <unistd.h>
|
||||
@ -64,6 +43,11 @@ MOZ_MEMORY_API char* strndup_impl(const char*, size_t);
|
||||
#include "mozilla/mozalloc.h"
|
||||
#include "mozilla/mozalloc_oom.h" // for mozalloc_handle_oom
|
||||
|
||||
#if defined(MOZ_MEMORY)
|
||||
MOZ_MEMORY_API char* strdup_impl(const char*);
|
||||
MOZ_MEMORY_API char* strndup_impl(const char*, size_t);
|
||||
#endif
|
||||
|
||||
void* moz_xmalloc(size_t size) {
|
||||
void* ptr = malloc_impl(size);
|
||||
if (MOZ_UNLIKELY(!ptr && size)) {
|
||||
|
@ -8,6 +8,19 @@
|
||||
#ifndef mozilla_mozalloc_h
|
||||
#define mozilla_mozalloc_h
|
||||
|
||||
#if defined(MOZ_MEMORY) && defined(IMPL_MFBT)
|
||||
# define MOZ_MEMORY_IMPL
|
||||
# include "mozmemory_wrap.h"
|
||||
# define MALLOC_FUNCS MALLOC_FUNCS_MALLOC
|
||||
// See mozmemory_wrap.h for more details. Files that are part of libmozglue,
|
||||
// need to use _impl suffixes, which is becoming cumbersome. We'll have to use
|
||||
// something like a malloc.h wrapper and allow the use of the functions without
|
||||
// a _impl suffix. In the meanwhile, this is enough to get by for C++ code.
|
||||
# define MALLOC_DECL(name, return_type, ...) \
|
||||
MOZ_MEMORY_API return_type name##_impl(__VA_ARGS__);
|
||||
# include "malloc_decls.h"
|
||||
#endif
|
||||
|
||||
/*
|
||||
* https://bugzilla.mozilla.org/show_bug.cgi?id=427099
|
||||
*/
|
||||
|
@ -5,31 +5,15 @@
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
#include "mozilla/Types.h"
|
||||
#include "mozilla/mozalloc.h"
|
||||
#include <windows.h>
|
||||
|
||||
#if defined(MOZ_MEMORY)
|
||||
// mozalloc.cpp is part of the same library as mozmemory, thus MOZ_MEMORY_IMPL
|
||||
// is needed.
|
||||
# define MOZ_MEMORY_IMPL
|
||||
# include "mozmemory_wrap.h"
|
||||
|
||||
// See mozmemory_wrap.h for more details. This file is part of libmozglue, so
|
||||
// it needs to use _impl suffixes. However, with libmozglue growing, this is
|
||||
// becoming cumbersome, so we will likely use a malloc.h wrapper of some sort
|
||||
// and allow the use of the functions without a _impl suffix.
|
||||
# define MALLOC_DECL(name, return_type, ...) \
|
||||
MOZ_MEMORY_API return_type name##_impl(__VA_ARGS__);
|
||||
# define MALLOC_FUNCS MALLOC_FUNCS_MALLOC
|
||||
# include "malloc_decls.h"
|
||||
#else
|
||||
|
||||
#if !defined(MOZ_MEMORY)
|
||||
# include <malloc.h>
|
||||
# define malloc_impl malloc
|
||||
# define calloc_impl calloc
|
||||
# define realloc_impl realloc
|
||||
# define free_impl free
|
||||
|
||||
#endif
|
||||
|
||||
// Warning: C4273: 'HeapAlloc': inconsistent dll linkage
|
||||
|
@ -12,7 +12,6 @@ EXPORTS += [
|
||||
|
||||
if CONFIG['ZLIB_IN_MOZGLUE']:
|
||||
FINAL_LIBRARY = 'mozglue'
|
||||
DEFINES['IMPL_MFBT'] = True
|
||||
else:
|
||||
# The final library is in config/external/zlib
|
||||
FINAL_LIBRARY = 'zlib'
|
||||
|
@ -4,18 +4,6 @@
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
#ifdef MOZ_MEMORY
|
||||
# define MOZ_MEMORY_IMPL
|
||||
# include "mozmemory_wrap.h"
|
||||
# define MALLOC_FUNCS MALLOC_FUNCS_MALLOC
|
||||
// See mozmemory_wrap.h for more details. This file is part of libmozglue, so
|
||||
// it needs to use _impl suffixes.
|
||||
# define MALLOC_DECL(name, return_type, ...) \
|
||||
MOZ_MEMORY_API return_type name##_impl(__VA_ARGS__);
|
||||
# include "malloc_decls.h"
|
||||
# include "mozilla/mozalloc.h"
|
||||
#endif
|
||||
|
||||
// We need Windows 8 functions and structures to be able to verify SHA-256.
|
||||
#if defined(_WIN32_WINNT)
|
||||
# undef _WIN32_WINNT
|
||||
|
@ -4,18 +4,6 @@
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
#ifdef MOZ_MEMORY
|
||||
# define MOZ_MEMORY_IMPL
|
||||
# include "mozmemory_wrap.h"
|
||||
# define MALLOC_FUNCS MALLOC_FUNCS_MALLOC
|
||||
// See mozmemory_wrap.h for more details. This file is part of libmozglue, so
|
||||
// it needs to use _impl suffixes.
|
||||
# define MALLOC_DECL(name, return_type, ...) \
|
||||
MOZ_MEMORY_API return_type name##_impl(__VA_ARGS__);
|
||||
# include "malloc_decls.h"
|
||||
# include "mozilla/mozalloc.h"
|
||||
#endif
|
||||
|
||||
#include "UntrustedDllsHandler.h"
|
||||
|
||||
#include <windows.h>
|
||||
|
@ -3,18 +3,6 @@
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
#ifdef MOZ_MEMORY
|
||||
# define MOZ_MEMORY_IMPL
|
||||
# include "mozmemory_wrap.h"
|
||||
# define MALLOC_FUNCS MALLOC_FUNCS_MALLOC
|
||||
// See mozmemory_wrap.h for more details. This file is part of libmozglue, so
|
||||
// it needs to use _impl suffixes.
|
||||
# define MALLOC_DECL(name, return_type, ...) \
|
||||
MOZ_MEMORY_API return_type name##_impl(__VA_ARGS__);
|
||||
# include "malloc_decls.h"
|
||||
# include "mozilla/mozalloc.h"
|
||||
#endif
|
||||
|
||||
#include <windows.h>
|
||||
#include <winternl.h>
|
||||
|
||||
|
@ -78,13 +78,6 @@ if CONFIG['MOZ_WIDGET_TOOLKIT']:
|
||||
EXPORTS.mozilla.glue += [
|
||||
'WindowsDllServices.h',
|
||||
]
|
||||
USE_LIBS += [
|
||||
'mscom-mozglue',
|
||||
]
|
||||
if CONFIG['CPU_ARCH'] == 'aarch64':
|
||||
USE_LIBS += [
|
||||
'interceptor',
|
||||
]
|
||||
|
||||
EXPORTS.mozilla += [
|
||||
'arm.h',
|
||||
@ -117,7 +110,7 @@ USE_LIBS += [
|
||||
'mfbt',
|
||||
]
|
||||
|
||||
DEFINES['IMPL_MFBT'] = True
|
||||
LIBRARY_DEFINES['IMPL_MFBT'] = True
|
||||
LIBRARY_DEFINES['MOZ_HAS_MOZGLUE'] = True
|
||||
|
||||
if CONFIG['OS_TARGET'] == 'Darwin':
|
||||
|
@ -17,8 +17,6 @@ Library('linker')
|
||||
|
||||
FINAL_LIBRARY = 'mozglue'
|
||||
|
||||
DEFINES['IMPL_MFBT'] = True
|
||||
|
||||
TEST_DIRS += ['tests']
|
||||
|
||||
if CONFIG['CC_TYPE'] in ('clang', 'gcc'):
|
||||
|
@ -16,9 +16,7 @@ EXPORTS.mozilla.interceptor += [
|
||||
]
|
||||
|
||||
if CONFIG['CPU_ARCH'] == 'aarch64':
|
||||
Library('interceptor')
|
||||
|
||||
DEFINES['IMPL_MFBT'] = True
|
||||
FINAL_LIBRARY = 'mozglue'
|
||||
|
||||
UNIFIED_SOURCES += [
|
||||
'Arm64.cpp',
|
||||
|
@ -34,8 +34,6 @@ SOURCES += [
|
||||
|
||||
OS_LIBS += CONFIG['REALTIME_LIBS']
|
||||
|
||||
DEFINES['IMPL_MFBT'] = True
|
||||
|
||||
if CONFIG['OS_ARCH'] == 'WINNT':
|
||||
DIRS += [
|
||||
'interceptor',
|
||||
|
Loading…
Reference in New Issue
Block a user