From 90371480b5e8eab4f79a43faa216dec42ddafbb4 Mon Sep 17 00:00:00 2001 From: Ras-al-Ghul Date: Thu, 17 Mar 2016 01:05:54 +0530 Subject: tdf#98602 Duplicate code in onlineupdate/ Converted libmar into static library and removed duplicate code. Change-Id: I51c58ae9a6a1f1128422b4a79491d0cd62e6ced6 Reviewed-on: https://gerrit.libreoffice.org/23312 Tested-by: Jenkins Reviewed-by: Markus Mohrhard Tested-by: Markus Mohrhard Reviewed-by: Jan Holesovsky --- onlineupdate/Executable_mar.mk | 8 +- onlineupdate/Executable_updater.mk | 12 +- onlineupdate/Module_onlineupdate.mk | 1 + onlineupdate/StaticLibrary_libmar.mk | 23 + .../source/libmar/inc/mozilla/Assertions.h | 503 --------- .../source/libmar/inc/mozilla/Attributes.h | 481 --------- onlineupdate/source/libmar/inc/mozilla/Compiler.h | 110 -- onlineupdate/source/libmar/inc/mozilla/Likely.h | 23 - onlineupdate/source/libmar/inc/mozilla/MacroArgs.h | 105 -- .../source/libmar/inc/mozilla/TypeTraits.h | 1116 -------------------- onlineupdate/source/libmar/inc/mozilla/Types.h | 134 --- .../source/libmar/inc/mozilla/nsTraceRefcnt.h | 67 -- onlineupdate/source/libmar/sign/mar_sign.c | 6 +- onlineupdate/source/libmar/src/mar.h | 198 ---- onlineupdate/source/libmar/src/mar_cmdline.h | 110 -- onlineupdate/source/libmar/src/mar_create.c | 6 +- onlineupdate/source/libmar/src/mar_extract.c | 4 +- onlineupdate/source/libmar/src/mar_private.h | 79 -- onlineupdate/source/libmar/src/mar_read.c | 4 +- onlineupdate/source/libmar/tool/mar.c | 4 +- onlineupdate/source/libmar/verify/mar_verify.c | 4 +- .../source/update/inc/mozilla/Assertions.h | 503 --------- .../source/update/inc/mozilla/Attributes.h | 481 --------- onlineupdate/source/update/inc/mozilla/Char16.h | 239 ----- onlineupdate/source/update/inc/mozilla/Compiler.h | 110 -- onlineupdate/source/update/inc/mozilla/Likely.h | 23 - onlineupdate/source/update/inc/mozilla/MacroArgs.h | 105 -- onlineupdate/source/update/inc/mozilla/Move.h | 238 ----- onlineupdate/source/update/inc/mozilla/Pair.h | 219 ---- .../source/update/inc/mozilla/TypeTraits.h | 1116 -------------------- onlineupdate/source/update/inc/mozilla/Types.h | 134 --- onlineupdate/source/update/inc/mozilla/UniquePtr.h | 659 ------------ .../source/update/inc/mozilla/nsTraceRefcnt.h | 67 -- onlineupdate/source/update/inc/nsAutoRef.h | 670 ------------ onlineupdate/source/update/inc/nsWindowsHelpers.h | 153 --- onlineupdate/source/update/src/Makefile.in | 13 - onlineupdate/source/update/src/mar.h | 198 ---- onlineupdate/source/update/src/mar_cmdline.h | 110 -- onlineupdate/source/update/src/mar_create.c | 398 ------- onlineupdate/source/update/src/mar_extract.c | 85 -- onlineupdate/source/update/src/mar_private.h | 79 -- onlineupdate/source/update/src/mar_read.c | 572 ---------- onlineupdate/source/update/updater/archivereader.h | 2 +- onlineupdate/source/update/updater/updater.cxx | 4 +- 44 files changed, 49 insertions(+), 9127 deletions(-) create mode 100644 onlineupdate/StaticLibrary_libmar.mk delete mode 100644 onlineupdate/source/libmar/inc/mozilla/Assertions.h delete mode 100644 onlineupdate/source/libmar/inc/mozilla/Attributes.h delete mode 100644 onlineupdate/source/libmar/inc/mozilla/Compiler.h delete mode 100644 onlineupdate/source/libmar/inc/mozilla/Likely.h delete mode 100644 onlineupdate/source/libmar/inc/mozilla/MacroArgs.h delete mode 100644 onlineupdate/source/libmar/inc/mozilla/TypeTraits.h delete mode 100644 onlineupdate/source/libmar/inc/mozilla/Types.h delete mode 100644 onlineupdate/source/libmar/inc/mozilla/nsTraceRefcnt.h delete mode 100644 onlineupdate/source/libmar/src/mar.h delete mode 100644 onlineupdate/source/libmar/src/mar_cmdline.h delete mode 100644 onlineupdate/source/libmar/src/mar_private.h delete mode 100644 onlineupdate/source/update/inc/mozilla/Assertions.h delete mode 100644 onlineupdate/source/update/inc/mozilla/Attributes.h delete mode 100644 onlineupdate/source/update/inc/mozilla/Char16.h delete mode 100644 onlineupdate/source/update/inc/mozilla/Compiler.h delete mode 100644 onlineupdate/source/update/inc/mozilla/Likely.h delete mode 100644 onlineupdate/source/update/inc/mozilla/MacroArgs.h delete mode 100644 onlineupdate/source/update/inc/mozilla/Move.h delete mode 100644 onlineupdate/source/update/inc/mozilla/Pair.h delete mode 100644 onlineupdate/source/update/inc/mozilla/TypeTraits.h delete mode 100644 onlineupdate/source/update/inc/mozilla/Types.h delete mode 100644 onlineupdate/source/update/inc/mozilla/UniquePtr.h delete mode 100644 onlineupdate/source/update/inc/mozilla/nsTraceRefcnt.h delete mode 100644 onlineupdate/source/update/inc/nsAutoRef.h delete mode 100644 onlineupdate/source/update/inc/nsWindowsHelpers.h delete mode 100644 onlineupdate/source/update/src/Makefile.in delete mode 100644 onlineupdate/source/update/src/mar.h delete mode 100644 onlineupdate/source/update/src/mar_cmdline.h delete mode 100644 onlineupdate/source/update/src/mar_create.c delete mode 100644 onlineupdate/source/update/src/mar_extract.c delete mode 100644 onlineupdate/source/update/src/mar_private.h delete mode 100644 onlineupdate/source/update/src/mar_read.c (limited to 'onlineupdate') diff --git a/onlineupdate/Executable_mar.mk b/onlineupdate/Executable_mar.mk index c2dccafc38b8..e42369754732 100644 --- a/onlineupdate/Executable_mar.mk +++ b/onlineupdate/Executable_mar.mk @@ -10,13 +10,16 @@ $(eval $(call gb_Executable_Executable,mar)) $(eval $(call gb_Executable_set_include,mar,\ - -I$(SRCDIR)/onlineupdate/source/libmar/inc/ \ -I$(SRCDIR)/onlineupdate/source/libmar/src/ \ -I$(SRCDIR)/onlineupdate/source/libmar/verify/ \ -I$(SRCDIR)/onlineupdate/source/libmar/sign/ \ $$(INCLUDE) \ )) +$(eval $(call gb_Executable_use_static_libraries,mar,\ + libmar \ +)) + ifeq ($(OS),WNT) $(eval $(call gb_Executable_add_libs,mar,\ ws2_32.lib \ @@ -30,9 +33,6 @@ $(eval $(call gb_Executable_add_defs,mar,-DMAR_NSS)) endif $(eval $(call gb_Executable_add_cobjects,mar,\ - onlineupdate/source/libmar/src/mar_create \ - onlineupdate/source/libmar/src/mar_extract \ - onlineupdate/source/libmar/src/mar_read \ onlineupdate/source/libmar/sign/nss_secutil \ onlineupdate/source/libmar/sign/mar_sign \ onlineupdate/source/libmar/verify/cryptox \ diff --git a/onlineupdate/Executable_updater.mk b/onlineupdate/Executable_updater.mk index 7420f1fce073..9542130f6f29 100644 --- a/onlineupdate/Executable_updater.mk +++ b/onlineupdate/Executable_updater.mk @@ -10,13 +10,15 @@ $(eval $(call gb_Executable_Executable,updater)) $(eval $(call gb_Executable_set_include,updater,\ - -I$(SRCDIR)/onlineupdate/source/update/src \ - -I$(SRCDIR)/onlineupdate/source/update/inc \ -I$(SRCDIR)/onlineupdate/source/update/common \ -I$(SRCDIR)/onlineupdate/source/update/updater/xpcom/glue \ $$(INCLUDE) \ )) +$(eval $(call gb_Executable_use_static_libraries,updater,\ + libmar \ +)) + ifeq ($(OS),WNT) $(eval $(call gb_Executable_add_libs,updater,\ Ws2_32.lib \ @@ -58,10 +60,4 @@ $(eval $(call gb_Executable_add_exception_objects,updater,\ onlineupdate/source/update/common/updatelogging \ )) -$(eval $(call gb_Executable_add_cobjects,updater,\ - onlineupdate/source/update/src/mar_create \ - onlineupdate/source/update/src/mar_extract \ - onlineupdate/source/update/src/mar_read \ -)) - # vim:set shiftwidth=4 tabstop=4 noexpandtab: */ diff --git a/onlineupdate/Module_onlineupdate.mk b/onlineupdate/Module_onlineupdate.mk index 113c03179815..2611faa595e7 100644 --- a/onlineupdate/Module_onlineupdate.mk +++ b/onlineupdate/Module_onlineupdate.mk @@ -12,6 +12,7 @@ $(eval $(call gb_Module_Module,onlineupdate)) ifneq ($(ENABLE_ONLINE_UPDATE_MAR),) $(eval $(call gb_Module_add_targets,onlineupdate,\ + StaticLibrary_libmar \ Executable_mar \ Executable_updater \ )) diff --git a/onlineupdate/StaticLibrary_libmar.mk b/onlineupdate/StaticLibrary_libmar.mk new file mode 100644 index 000000000000..3c85b739bc3c --- /dev/null +++ b/onlineupdate/StaticLibrary_libmar.mk @@ -0,0 +1,23 @@ +# -*- Mode: makefile-gmake; tab-width: 4; indent-tabs-mode: t -*- +# +# This file is part of the LibreOffice project. +# +# This Source Code Form is subject to the terms of the Mozilla Public +# 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/. +# + +$(eval $(call gb_StaticLibrary_StaticLibrary,libmar)) + +$(eval $(call gb_StaticLibrary_set_include,libmar,\ + -I$(SRCDIR)/onlineupdate/source/libmar/src/ \ + $$(INCLUDE) \ +)) + +$(eval $(call gb_StaticLibrary_add_cobjects,libmar,\ + onlineupdate/source/libmar/src/mar_create \ + onlineupdate/source/libmar/src/mar_extract \ + onlineupdate/source/libmar/src/mar_read \ +)) + +# vim:set shiftwidth=4 tabstop=4 noexpandtab: */ diff --git a/onlineupdate/source/libmar/inc/mozilla/Assertions.h b/onlineupdate/source/libmar/inc/mozilla/Assertions.h deleted file mode 100644 index 5669091bbb8e..000000000000 --- a/onlineupdate/source/libmar/inc/mozilla/Assertions.h +++ /dev/null @@ -1,503 +0,0 @@ -/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* vim: set ts=8 sts=2 et sw=2 tw=80: */ -/* This Source Code Form is subject to the terms of the Mozilla Public - * 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/. */ - -/* Implementations of runtime and static assertion macros for C and C++. */ - -#ifndef mozilla_Assertions_h -#define mozilla_Assertions_h - -#if defined(MOZILLA_INTERNAL_API) && defined(__cplusplus) -#define MOZ_DUMP_ASSERTION_STACK -#endif - -#include "mozilla/Attributes.h" -#include "mozilla/Compiler.h" -#include "mozilla/Likely.h" -#include "mozilla/MacroArgs.h" -#ifdef MOZ_DUMP_ASSERTION_STACK -#include "nsTraceRefcnt.h" -#endif - -#include -#include -#include -#ifdef _WIN32 - /* - * TerminateProcess and GetCurrentProcess are defined in , which - * further depends on . We hardcode these few definitions manually - * because those headers clutter the global namespace with a significant - * number of undesired macros and symbols. - */ -# ifdef __cplusplus -extern "C" { -# endif -__declspec(dllimport) int __stdcall -TerminateProcess(void* hProcess, unsigned int uExitCode); -__declspec(dllimport) void* __stdcall GetCurrentProcess(void); -# ifdef __cplusplus -} -# endif -#else -# include -#endif -#ifdef ANDROID -# include -#endif - -/* - * MOZ_STATIC_ASSERT may be used to assert a condition *at compile time* in C. - * In C++11, static_assert is provided by the compiler to the same effect. - * This can be useful when you make certain assumptions about what must hold for - * optimal, or even correct, behavior. For example, you might assert that the - * size of a struct is a multiple of the target architecture's word size: - * - * struct S { ... }; - * // C - * MOZ_STATIC_ASSERT(sizeof(S) % sizeof(size_t) == 0, - * "S should be a multiple of word size for efficiency"); - * // C++11 - * static_assert(sizeof(S) % sizeof(size_t) == 0, - * "S should be a multiple of word size for efficiency"); - * - * This macro can be used in any location where both an extern declaration and a - * typedef could be used. - */ -#ifndef __cplusplus - /* - * Some of the definitions below create an otherwise-unused typedef. This - * triggers compiler warnings with some versions of gcc, so mark the typedefs - * as permissibly-unused to disable the warnings. - */ -# if defined(__GNUC__) -# define MOZ_STATIC_ASSERT_UNUSED_ATTRIBUTE __attribute__((unused)) -# else -# define MOZ_STATIC_ASSERT_UNUSED_ATTRIBUTE /* nothing */ -# endif -# define MOZ_STATIC_ASSERT_GLUE1(x, y) x##y -# define MOZ_STATIC_ASSERT_GLUE(x, y) MOZ_STATIC_ASSERT_GLUE1(x, y) -# if defined(__SUNPRO_CC) - /* - * The Sun Studio C++ compiler is buggy when declaring, inside a function, - * another extern'd function with an array argument whose length contains a - * sizeof, triggering the error message "sizeof expression not accepted as - * size of array parameter". This bug (6688515, not public yet) would hit - * defining moz_static_assert as a function, so we always define an extern - * array for Sun Studio. - * - * We include the line number in the symbol name in a best-effort attempt - * to avoid conflicts (see below). - */ -# define MOZ_STATIC_ASSERT(cond, reason) \ - extern char MOZ_STATIC_ASSERT_GLUE(moz_static_assert, __LINE__)[(cond) ? 1 : -1] -# elif defined(__COUNTER__) - /* - * If there was no preferred alternative, use a compiler-agnostic version. - * - * Note that the non-__COUNTER__ version has a bug in C++: it can't be used - * in both |extern "C"| and normal C++ in the same translation unit. (Alas - * |extern "C"| isn't allowed in a function.) The only affected compiler - * we really care about is gcc 4.2. For that compiler and others like it, - * we include the line number in the function name to do the best we can to - * avoid conflicts. These should be rare: a conflict would require use of - * MOZ_STATIC_ASSERT on the same line in separate files in the same - * translation unit, *and* the uses would have to be in code with - * different linkage, *and* the first observed use must be in C++-linkage - * code. - */ -# define MOZ_STATIC_ASSERT(cond, reason) \ - typedef int MOZ_STATIC_ASSERT_GLUE(moz_static_assert, __COUNTER__)[(cond) ? 1 : -1] MOZ_STATIC_ASSERT_UNUSED_ATTRIBUTE -# else -# define MOZ_STATIC_ASSERT(cond, reason) \ - extern void MOZ_STATIC_ASSERT_GLUE(moz_static_assert, __LINE__)(int arg[(cond) ? 1 : -1]) MOZ_STATIC_ASSERT_UNUSED_ATTRIBUTE -# endif - -#define MOZ_STATIC_ASSERT_IF(cond, expr, reason) MOZ_STATIC_ASSERT(!(cond) || (expr), reason) -#else -#define MOZ_STATIC_ASSERT_IF(cond, expr, reason) static_assert(!(cond) || (expr), reason) -#endif - -#ifdef __cplusplus -extern "C" { -#endif - -/* - * Prints |aStr| as an assertion failure (using aFilename and aLine as the - * location of the assertion) to the standard debug-output channel. - * - * Usually you should use MOZ_ASSERT or MOZ_CRASH instead of this method. This - * method is primarily for internal use in this header, and only secondarily - * for use in implementing release-build assertions. - */ -static MOZ_COLD MOZ_ALWAYS_INLINE void -MOZ_ReportAssertionFailure(const char* aStr, const char* aFilename, int aLine) - MOZ_PRETEND_NORETURN_FOR_STATIC_ANALYSIS -{ -#ifdef ANDROID - __android_log_print(ANDROID_LOG_FATAL, "MOZ_Assert", - "Assertion failure: %s, at %s:%d\n", - aStr, aFilename, aLine); -#else - fprintf(stderr, "Assertion failure: %s, at %s:%d\n", aStr, aFilename, aLine); -#if defined (MOZ_DUMP_ASSERTION_STACK) && !defined(MOZILLA_XPCOMRT_API) - nsTraceRefcnt::WalkTheStack(stderr); -#endif - fflush(stderr); -#endif -} - -static MOZ_COLD MOZ_ALWAYS_INLINE void -MOZ_ReportCrash(const char* aStr, const char* aFilename, int aLine) - MOZ_PRETEND_NORETURN_FOR_STATIC_ANALYSIS -{ -#ifdef ANDROID - __android_log_print(ANDROID_LOG_FATAL, "MOZ_CRASH", - "Hit MOZ_CRASH(%s) at %s:%d\n", aStr, aFilename, aLine); -#else - fprintf(stderr, "Hit MOZ_CRASH(%s) at %s:%d\n", aStr, aFilename, aLine); -#if defined(MOZ_DUMP_ASSERTION_STACK) && !defined(MOZILLA_XPCOMRT_API) - nsTraceRefcnt::WalkTheStack(stderr); -#endif - fflush(stderr); -#endif -} - -/** - * MOZ_REALLY_CRASH is used in the implementation of MOZ_CRASH(). You should - * call MOZ_CRASH instead. - */ -#if defined(_MSC_VER) - /* - * On MSVC use the __debugbreak compiler intrinsic, which produces an inline - * (not nested in a system function) breakpoint. This distinctively invokes - * Breakpad without requiring system library symbols on all stack-processing - * machines, as a nested breakpoint would require. - * - * We use TerminateProcess with the exit code aborting would generate - * because we don't want to invoke atexit handlers, destructors, library - * unload handlers, and so on when our process might be in a compromised - * state. - * - * We don't use abort() because it'd cause Windows to annoyingly pop up the - * process error dialog multiple times. See bug 345118 and bug 426163. - * - * We follow TerminateProcess() with a call to MOZ_NoReturn() so that the - * compiler doesn't hassle us to provide a return statement after a - * MOZ_REALLY_CRASH() call. - * - * (Technically these are Windows requirements, not MSVC requirements. But - * practically you need MSVC for debugging, and we only ship builds created - * by MSVC, so doing it this way reduces complexity.) - */ - -__declspec(noreturn) __inline void MOZ_NoReturn() {} - -# ifdef __cplusplus -# define MOZ_REALLY_CRASH() \ - do { \ - ::__debugbreak(); \ - *((volatile int*) NULL) = __LINE__; \ - ::TerminateProcess(::GetCurrentProcess(), 3); \ - ::MOZ_NoReturn(); \ - } while (0) -# else -# define MOZ_REALLY_CRASH() \ - do { \ - __debugbreak(); \ - *((volatile int*) NULL) = __LINE__; \ - TerminateProcess(GetCurrentProcess(), 3); \ - MOZ_NoReturn(); \ - } while (0) -# endif -#else -# ifdef __cplusplus -# define MOZ_REALLY_CRASH() \ - do { \ - *((volatile int*) NULL) = __LINE__; \ - ::abort(); \ - } while (0) -# else -# define MOZ_REALLY_CRASH() \ - do { \ - *((volatile int*) NULL) = __LINE__; \ - abort(); \ - } while (0) -# endif -#endif - -/* - * MOZ_CRASH([explanation-string]) crashes the program, plain and simple, in a - * Breakpad-compatible way, in both debug and release builds. - * - * MOZ_CRASH is a good solution for "handling" failure cases when you're - * unwilling or unable to handle them more cleanly -- for OOM, for likely memory - * corruption, and so on. It's also a good solution if you need safe behavior - * in release builds as well as debug builds. But if the failure is one that - * should be debugged and fixed, MOZ_ASSERT is generally preferable. - * - * The optional explanation-string, if provided, must be a string literal - * explaining why we're crashing. This argument is intended for use with - * MOZ_CRASH() calls whose rationale is non-obvious; don't use it if it's - * obvious why we're crashing. - * - * If we're a DEBUG build and we crash at a MOZ_CRASH which provides an - * explanation-string, we print the string to stderr. Otherwise, we don't - * print anything; this is because we want MOZ_CRASH to be 100% safe in release - * builds, and it's hard to print to stderr safely when memory might have been - * corrupted. - */ -#ifndef DEBUG -# define MOZ_CRASH(...) MOZ_REALLY_CRASH() -#else -# define MOZ_CRASH(...) \ - do { \ - MOZ_ReportCrash("" __VA_ARGS__, __FILE__, __LINE__); \ - MOZ_REALLY_CRASH(); \ - } while (0) -#endif - -#ifdef __cplusplus -} /* extern "C" */ -#endif - -/* - * MOZ_ASSERT(expr [, explanation-string]) asserts that |expr| must be truthy in - * debug builds. If it is, execution continues. Otherwise, an error message - * including the expression and the explanation-string (if provided) is printed, - * an attempt is made to invoke any existing debugger, and execution halts. - * MOZ_ASSERT is fatal: no recovery is possible. Do not assert a condition - * which can correctly be falsy. - * - * The optional explanation-string, if provided, must be a string literal - * explaining the assertion. It is intended for use with assertions whose - * correctness or rationale is non-obvious, and for assertions where the "real" - * condition being tested is best described prosaically. Don't provide an - * explanation if it's not actually helpful. - * - * // No explanation needed: pointer arguments often must not be NULL. - * MOZ_ASSERT(arg); - * - * // An explanation can be helpful to explain exactly how we know an - * // assertion is valid. - * MOZ_ASSERT(state == WAITING_FOR_RESPONSE, - * "given that and , we must have..."); - * - * // Or it might disambiguate multiple identical (save for their location) - * // assertions of the same expression. - * MOZ_ASSERT(getSlot(PRIMITIVE_THIS_SLOT).isUndefined(), - * "we already set [[PrimitiveThis]] for this Boolean object"); - * MOZ_ASSERT(getSlot(PRIMITIVE_THIS_SLOT).isUndefined(), - * "we already set [[PrimitiveThis]] for this String object"); - * - * MOZ_ASSERT has no effect in non-debug builds. It is designed to catch bugs - * *only* during debugging, not "in the field". If you want the latter, use - * MOZ_RELEASE_ASSERT, which applies to non-debug builds as well. - * - * MOZ_DIAGNOSTIC_ASSERT works like MOZ_RELEASE_ASSERT in Nightly/Aurora and - * MOZ_ASSERT in Beta/Release - use this when a condition is potentially rare - * enough to require real user testing to hit, but is not security-sensitive. - * This can cause user pain, so use it sparingly. If a MOZ_DIAGNOSTIC_ASSERT - * is firing, it should promptly be converted to a MOZ_ASSERT while the failure - * is being investigated, rather than letting users suffer. - */ - -/* - * Implement MOZ_VALIDATE_ASSERT_CONDITION_TYPE, which is used to guard against - * accidentally passing something unintended in lieu of an assertion condition. - */ - -#ifdef __cplusplus -# include "mozilla/TypeTraits.h" -namespace mozilla { -namespace detail { - -template -struct IsFunction -{ - static const bool value = false; -}; - -template -struct IsFunction -{ - static const bool value = true; -}; - -template -struct AssertionConditionType -{ - typedef typename RemoveReference::Type ValueT; - static_assert(!IsArray::value, - "Expected boolean assertion condition, got an array or a " - "string!"); - static_assert(!IsFunction::value, - "Expected boolean assertion condition, got a function! Did " - "you intend to call that function?"); - static_assert(!IsFloatingPoint::value, - "It's often a bad idea to assert that a floating-point number " - "is nonzero, because such assertions tend to intermittently " - "fail. Shouldn't your code gracefully handle this case instead " - "of asserting? Anyway, if you really want to do that, write an " - "explicit boolean condition, like !!x or x!=0."); - - static const bool isValid = true; -}; - -} // namespace detail -} // namespace mozilla -# define MOZ_VALIDATE_ASSERT_CONDITION_TYPE(x) \ - static_assert(mozilla::detail::AssertionConditionType::isValid, \ - "invalid assertion condition") -#else -# define MOZ_VALIDATE_ASSERT_CONDITION_TYPE(x) -#endif - -/* First the single-argument form. */ -#define MOZ_ASSERT_HELPER1(expr) \ - do { \ - MOZ_VALIDATE_ASSERT_CONDITION_TYPE(expr); \ - if (MOZ_UNLIKELY(!(expr))) { \ - MOZ_ReportAssertionFailure(#expr, __FILE__, __LINE__); \ - MOZ_REALLY_CRASH(); \ - } \ - } while (0) -/* Now the two-argument form. */ -#define MOZ_ASSERT_HELPER2(expr, explain) \ - do { \ - MOZ_VALIDATE_ASSERT_CONDITION_TYPE(expr); \ - if (MOZ_UNLIKELY(!(expr))) { \ - MOZ_ReportAssertionFailure(#expr " (" explain ")", __FILE__, __LINE__); \ - MOZ_REALLY_CRASH(); \ - } \ - } while (0) - -#define MOZ_RELEASE_ASSERT_GLUE(a, b) a b -#define MOZ_RELEASE_ASSERT(...) \ - MOZ_RELEASE_ASSERT_GLUE( \ - MOZ_PASTE_PREFIX_AND_ARG_COUNT(MOZ_ASSERT_HELPER, __VA_ARGS__), \ - (__VA_ARGS__)) - -#ifdef DEBUG -# define MOZ_ASSERT(...) MOZ_RELEASE_ASSERT(__VA_ARGS__) -#else -# define MOZ_ASSERT(...) do { } while (0) -#endif /* DEBUG */ - -#ifdef RELEASE_BUILD -# define MOZ_DIAGNOSTIC_ASSERT MOZ_ASSERT -#else -# define MOZ_DIAGNOSTIC_ASSERT MOZ_RELEASE_ASSERT -#endif - -/* - * MOZ_ASSERT_IF(cond1, cond2) is equivalent to MOZ_ASSERT(cond2) if cond1 is - * true. - * - * MOZ_ASSERT_IF(isPrime(num), num == 2 || isOdd(num)); - * - * As with MOZ_ASSERT, MOZ_ASSERT_IF has effect only in debug builds. It is - * designed to catch bugs during debugging, not "in the field". - */ -#ifdef DEBUG -# define MOZ_ASSERT_IF(cond, expr) \ - do { \ - if (cond) { \ - MOZ_ASSERT(expr); \ - } \ - } while (0) -#else -# define MOZ_ASSERT_IF(cond, expr) do { } while (0) -#endif - -/* - * MOZ_ASSUME_UNREACHABLE_MARKER() expands to an expression which states that - * it is undefined behavior for execution to reach this point. No guarantees - * are made about what will happen if this is reached at runtime. Most code - * should use MOZ_MAKE_COMPILER_ASSUME_IS_UNREACHABLE because it has extra - * asserts. - */ -#if defined(__clang__) || defined(__GNUC__) -# define MOZ_ASSUME_UNREACHABLE_MARKER() __builtin_unreachable() -#elif defined(_MSC_VER) -# define MOZ_ASSUME_UNREACHABLE_MARKER() __assume(0) -#else -# ifdef __cplusplus -# define MOZ_ASSUME_UNREACHABLE_MARKER() ::abort() -# else -# define MOZ_ASSUME_UNREACHABLE_MARKER() abort() -# endif -#endif - -/* - * MOZ_MAKE_COMPILER_ASSUME_IS_UNREACHABLE([reason]) tells the compiler that it - * can assume that the macro call cannot be reached during execution. This lets - * the compiler generate better-optimized code under some circumstances, at the - * expense of the program's behavior being undefined if control reaches the - * MOZ_MAKE_COMPILER_ASSUME_IS_UNREACHABLE. - * - * In Gecko, you probably should not use this macro outside of performance- or - * size-critical code, because it's unsafe. If you don't care about code size - * or performance, you should probably use MOZ_ASSERT or MOZ_CRASH. - * - * SpiderMonkey is a different beast, and there it's acceptable to use - * MOZ_MAKE_COMPILER_ASSUME_IS_UNREACHABLE more widely. - * - * Note that MOZ_MAKE_COMPILER_ASSUME_IS_UNREACHABLE is noreturn, so it's valid - * not to return a value following a MOZ_MAKE_COMPILER_ASSUME_IS_UNREACHABLE - * call. - * - * Example usage: - * - * enum ValueType { - * VALUE_STRING, - * VALUE_INT, - * VALUE_FLOAT - * }; - * - * int ptrToInt(ValueType type, void* value) { - * { - * // We know for sure that type is either INT or FLOAT, and we want this - * // code to run as quickly as possible. - * switch (type) { - * case VALUE_INT: - * return *(int*) value; - * case VALUE_FLOAT: - * return (int) *(float*) value; - * default: - * MOZ_MAKE_COMPILER_ASSUME_IS_UNREACHABLE("Unexpected ValueType"); - * } - * } - */ - -/* - * Unconditional assert in debug builds for (assumed) unreachable code paths - * that have a safe return without crashing in release builds. - */ -#define MOZ_ASSERT_UNREACHABLE(reason) \ - MOZ_ASSERT(false, "MOZ_ASSERT_UNREACHABLE: " reason) - -#define MOZ_MAKE_COMPILER_ASSUME_IS_UNREACHABLE(reason) \ - do { \ - MOZ_ASSERT_UNREACHABLE(reason); \ - MOZ_ASSUME_UNREACHABLE_MARKER(); \ - } while (0) - -/* - * MOZ_ALWAYS_TRUE(expr) and MOZ_ALWAYS_FALSE(expr) always evaluate the provided - * expression, in debug builds and in release builds both. Then, in debug - * builds only, the value of the expression is asserted either true or false - * using MOZ_ASSERT. - */ -#ifdef DEBUG -# define MOZ_ALWAYS_TRUE(expr) MOZ_ASSERT((expr)) -# define MOZ_ALWAYS_FALSE(expr) MOZ_ASSERT(!(expr)) -#else -# define MOZ_ALWAYS_TRUE(expr) ((void)(expr)) -# define MOZ_ALWAYS_FALSE(expr) ((void)(expr)) -#endif - -#undef MOZ_DUMP_ASSERTION_STACK - -#endif /* mozilla_Assertions_h */ diff --git a/onlineupdate/source/libmar/inc/mozilla/Attributes.h b/onlineupdate/source/libmar/inc/mozilla/Attributes.h deleted file mode 100644 index 1eac3a802bd5..000000000000 --- a/onlineupdate/source/libmar/inc/mozilla/Attributes.h +++ /dev/null @@ -1,481 +0,0 @@ -/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* vim: set ts=8 sts=2 et sw=2 tw=80: */ -/* This Source Code Form is subject to the terms of the Mozilla Public - * 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/. */ - -/* Implementations of various class and method modifier attributes. */ - -#ifndef mozilla_Attributes_h -#define mozilla_Attributes_h - -#include "mozilla/Compiler.h" - -/* - * MOZ_ALWAYS_INLINE is a macro which expands to tell the compiler that the - * method decorated with it must be inlined, even if the compiler thinks - * otherwise. This is only a (much) stronger version of the inline hint: - * compilers are not guaranteed to respect it (although they're much more likely - * to do so). - * - * The MOZ_ALWAYS_INLINE_EVEN_DEBUG macro is yet stronger. It tells the - * compiler to inline even in DEBUG builds. It should be used very rarely. - */ -#if defined(_MSC_VER) -# define MOZ_ALWAYS_INLINE_EVEN_DEBUG __forceinline -#elif defined(__GNUC__) -# define MOZ_ALWAYS_INLINE_EVEN_DEBUG __attribute__((always_inline)) inline -#else -# define MOZ_ALWAYS_INLINE_EVEN_DEBUG inline -#endif - -#if !defined(DEBUG) -# define MOZ_ALWAYS_INLINE MOZ_ALWAYS_INLINE_EVEN_DEBUG -#elif defined(_MSC_VER) && !defined(__cplusplus) -# define MOZ_ALWAYS_INLINE __inline -#else -# define MOZ_ALWAYS_INLINE inline -#endif - -#if defined(_MSC_VER) -/* - * g++ requires -std=c++0x or -std=gnu++0x to support C++11 functionality - * without warnings (functionality used by the macros below). These modes are - * detectable by checking whether __GXX_EXPERIMENTAL_CXX0X__ is defined or, more - * standardly, by checking whether __cplusplus has a C++11 or greater value. - * Current versions of g++ do not correctly set __cplusplus, so we check both - * for forward compatibility. - * - * Even though some versions of MSVC support explicit conversion operators, we - * don't indicate support for them here, due to - * http://stackoverflow.com/questions/20498142/visual-studio-2013-explicit-keyword-bug - */ -# define MOZ_HAVE_NEVER_INLINE __declspec(noinline) -# define MOZ_HAVE_NORETURN __declspec(noreturn) -# ifdef __clang__ - /* clang-cl probably supports constexpr and explicit conversions. */ -# if __has_extension(cxx_constexpr) -# define MOZ_HAVE_CXX11_CONSTEXPR -# endif -# if __has_extension(cxx_explicit_conversions) -# define MOZ_HAVE_EXPLICIT_CONVERSION -# endif -# endif -#elif defined(__clang__) - /* - * Per Clang documentation, "Note that marketing version numbers should not - * be used to check for language features, as different vendors use different - * numbering schemes. Instead, use the feature checking macros." - */ -# ifndef __has_extension -# define __has_extension __has_feature /* compatibility, for older versions of clang */ -# endif -# if __has_extension(cxx_constexpr) -# define MOZ_HAVE_CXX11_CONSTEXPR -# endif -# if __has_extension(cxx_explicit_conversions) -# define MOZ_HAVE_EXPLICIT_CONVERSION -# endif -# if __has_attribute(noinline) -# define MOZ_HAVE_NEVER_INLINE __attribute__((noinline)) -# endif -# if __has_attribute(noreturn) -# define MOZ_HAVE_NORETURN __attribute__((noreturn)) -# endif -#elif defined(__GNUC__) -# if defined(__GXX_EXPERIMENTAL_CXX0X__) || (defined(__cplusplus) && __cplusplus >= 201103L) -# define MOZ_HAVE_CXX11_CONSTEXPR -# if MOZ_GCC_VERSION_AT_LEAST(4, 8, 0) -# define MOZ_HAVE_CXX11_CONSTEXPR_IN_TEMPLATES -# endif -# define MOZ_HAVE_EXPLICIT_CONVERSION -# endif -# define MOZ_HAVE_NEVER_INLINE __attribute__((noinline)) -# define MOZ_HAVE_NORETURN __attribute__((noreturn)) -#endif - -/* - * When built with clang analyzer (a.k.a scan-build), define MOZ_HAVE_NORETURN - * to mark some false positives - */ -#ifdef __clang_analyzer__ -# if __has_extension(attribute_analyzer_noreturn) -# define MOZ_HAVE_ANALYZER_NORETURN __attribute__((analyzer_noreturn)) -# endif -#endif - -/* - * The MOZ_CONSTEXPR specifier declares that a C++11 compiler can evaluate a - * function at compile time. A constexpr function cannot examine any values - * except its arguments and can have no side effects except its return value. - * The MOZ_CONSTEXPR_VAR specifier tells a C++11 compiler that a variable's - * value may be computed at compile time. It should be preferred to just - * marking variables as MOZ_CONSTEXPR because if the compiler does not support - * constexpr it will fall back to making the variable const, and some compilers - * do not accept variables being marked both const and constexpr. - */ -#ifdef MOZ_HAVE_CXX11_CONSTEXPR -# define MOZ_CONSTEXPR constexpr -# define MOZ_CONSTEXPR_VAR constexpr -# ifdef MOZ_HAVE_CXX11_CONSTEXPR_IN_TEMPLATES -# define MOZ_CONSTEXPR_TMPL constexpr -# else -# define MOZ_CONSTEXPR_TMPL -# endif -#else -# define MOZ_CONSTEXPR /* no support */ -# define MOZ_CONSTEXPR_VAR const -# define MOZ_CONSTEXPR_TMPL -#endif - -/* - * MOZ_EXPLICIT_CONVERSION is a specifier on a type conversion - * overloaded operator that declares that a C++11 compiler should restrict - * this operator to allow only explicit type conversions, disallowing - * implicit conversions. - * - * Example: - * - * template - * class Ptr - * { - * T* mPtr; - * MOZ_EXPLICIT_CONVERSION operator bool() const - * { - * return mPtr != nullptr; - * } - * }; - * - */ -#ifdef MOZ_HAVE_EXPLICIT_CONVERSION -# define MOZ_EXPLICIT_CONVERSION explicit -#else -# define MOZ_EXPLICIT_CONVERSION /* no support */ -#endif - -/* - * MOZ_NEVER_INLINE is a macro which expands to tell the compiler that the - * method decorated with it must never be inlined, even if the compiler would - * otherwise choose to inline the method. Compilers aren't absolutely - * guaranteed to support this, but most do. - */ -#if defined(MOZ_HAVE_NEVER_INLINE) -# define MOZ_NEVER_INLINE MOZ_HAVE_NEVER_INLINE -#else -# define MOZ_NEVER_INLINE /* no support */ -#endif - -/* - * MOZ_NORETURN, specified at the start of a function declaration, indicates - * that the given function does not return. (The function definition does not - * need to be annotated.) - * - * MOZ_NORETURN void abort(const char* msg); - * - * This modifier permits the compiler to optimize code assuming a call to such a - * function will never return. It also enables the compiler to avoid spurious - * warnings about not initializing variables, or about any other seemingly-dodgy - * operations performed after the function returns. - * - * This modifier does not affect the corresponding function's linking behavior. - */ -#if defined(MOZ_HAVE_NORETURN) -# define MOZ_NORETURN MOZ_HAVE_NORETURN -#else -# define MOZ_NORETURN /* no support */ -#endif - -/** - * MOZ_COLD tells the compiler that a function is "cold", meaning infrequently - * executed. This may lead it to optimize for size more aggressively than speed, - * or to allocate the body of the function in a distant part of the text segment - * to help keep it from taking up unnecessary icache when it isn't in use. - * - * Place this attribute at the very beginning of a function definition. For - * example, write - * - * MOZ_COLD int foo(); - * - * or - * - * MOZ_COLD int foo() { return 42; } - */ -#if defined(__GNUC__) || defined(__clang__) -# define MOZ_COLD __attribute__ ((cold)) -#else -# define MOZ_COLD -#endif - -/** - * MOZ_NONNULL tells the compiler that some of the arguments to a function are - * known to be non-null. The arguments are a list of 1-based argument indexes - * identifying arguments which are known to be non-null. - * - * Place this attribute at the very beginning of a function definition. For - * example, write - * - * MOZ_NONNULL(1, 2) int foo(char *p, char *q); - */ -#if defined(__GNUC__) || defined(__clang__) -# define MOZ_NONNULL(...) __attribute__ ((nonnull(__VA_ARGS__))) -#else -# define MOZ_NONNULL(...) -#endif - -/* - * MOZ_PRETEND_NORETURN_FOR_STATIC_ANALYSIS, specified at the end of a function - * declaration, indicates that for the purposes of static analysis, this - * function does not return. (The function definition does not need to be - * annotated.) - * - * MOZ_ReportCrash(const char* s, const char* file, int ln) - * MOZ_PRETEND_NORETURN_FOR_STATIC_ANALYSIS - * - * Some static analyzers, like scan-build from clang, can use this information - * to eliminate false positives. From the upstream documentation of scan-build: - * "This attribute is useful for annotating assertion handlers that actually - * can return, but for the purpose of using the analyzer we want to pretend - * that such functions do not return." - * - */ -#if defined(MOZ_HAVE_ANALYZER_NORETURN) -# define MOZ_PRETEND_NORETURN_FOR_STATIC_ANALYSIS MOZ_HAVE_ANALYZER_NORETURN -#else -# define MOZ_PRETEND_NORETURN_FOR_STATIC_ANALYSIS /* no support */ -#endif - -/* - * MOZ_ASAN_BLACKLIST is a macro to tell AddressSanitizer (a compile-time - * instrumentation shipped with Clang and GCC) to not instrument the annotated - * function. Furthermore, it will prevent the compiler from inlining the - * function because inlining currently breaks the blacklisting mechanism of - * AddressSanitizer. - */ -#if defined(__has_feature) -# if __has_feature(address_sanitizer) -# define MOZ_HAVE_ASAN_BLACKLIST -# endif -#elif defined(__GNUC__) -# if defined(__SANITIZE_ADDRESS__) -# define MOZ_HAVE_ASAN_BLACKLIST -# endif -#endif - -#if defined(MOZ_HAVE_ASAN_BLACKLIST) -# define MOZ_ASAN_BLACKLIST MOZ_NEVER_INLINE __attribute__((no_sanitize_address)) -#else -# define MOZ_ASAN_BLACKLIST /* nothing */ -#endif - -/* - * MOZ_TSAN_BLACKLIST is a macro to tell ThreadSanitizer (a compile-time - * instrumentation shipped with Clang) to not instrument the annotated function. - * Furthermore, it will prevent the compiler from inlining the function because - * inlining currently breaks the blacklisting mechanism of ThreadSanitizer. - */ -#if defined(__has_feature) -# if __has_feature(thread_sanitizer) -# define MOZ_TSAN_BLACKLIST MOZ_NEVER_INLINE __attribute__((no_sanitize_thread)) -# else -# define MOZ_TSAN_BLACKLIST /* nothing */ -# endif -#else -# define MOZ_TSAN_BLACKLIST /* nothing */ -#endif - -/** - * MOZ_ALLOCATOR tells the compiler that the function it marks returns either a - * "fresh", "pointer-free" block of memory, or nullptr. "Fresh" means that the - * block is not pointed to by any other reachable pointer in the program. - * "Pointer-free" means that the block contains no pointers to any valid object - * in the program. It may be initialized with other (non-pointer) values. - * - * Placing this attribute on appropriate functions helps GCC analyze pointer - * aliasing more accurately in their callers. - * - * GCC warns if a caller ignores the value returned by a function marked with - * MOZ_ALLOCATOR: it is hard to imagine cases where dropping the value returned - * by a function that meets the criteria above would be intentional. - * - * Place this attribute after the argument list and 'this' qualifiers of a - * function definition. For example, write - * - * void *my_allocator(size_t) MOZ_ALLOCATOR; - * - * or - * - * void *my_allocator(size_t bytes) MOZ_ALLOCATOR { ... } - */ -#if defined(__GNUC__) || defined(__clang__) -# define MOZ_ALLOCATOR __attribute__ ((malloc, warn_unused_result)) -#else -# define MOZ_ALLOCATOR -#endif - -/** - * MOZ_WARN_UNUSED_RESULT tells the compiler to emit a warning if a function's - * return value is not used by the caller. - * - * Place this attribute at the very beginning of a function definition. For - * example, write - * - * MOZ_WARN_UNUSED_RESULT int foo(); - * - * or - * - * MOZ_WARN_UNUSED_RESULT int foo() { return 42; } - */ -#if defined(__GNUC__) || defined(__clang__) -# define MOZ_WARN_UNUSED_RESULT __attribute__ ((warn_unused_result)) -#else -# define MOZ_WARN_UNUSED_RESULT -#endif - -#ifdef __cplusplus - -/* - * The following macros are attributes that support the static analysis plugin - * included with Mozilla, and will be implemented (when such support is enabled) - * as C++11 attributes. Since such attributes are legal pretty much everywhere - * and have subtly different semantics depending on their placement, the - * following is a guide on where to place the attributes. - * - * Attributes that apply to a struct or class precede the name of the class: - * (Note that this is different from the placement of final for classes!) - * - * class MOZ_CLASS_ATTRIBUTE SomeClass {}; - * - * Attributes that apply to functions follow the parentheses and const - * qualifiers but precede final, override and the function body: - * - * void DeclaredFunction() MOZ_FUNCTION_ATTRIBUTE; - * void SomeFunction() MOZ_FUNCTION_ATTRIBUTE {} - * void PureFunction() const MOZ_FUNCTION_ATTRIBUTE = 0; - * void OverriddenFunction() MOZ_FUNCTION_ATTIRBUTE override; - * - * Attributes that apply to variables or parameters follow the variable's name: - * - * int variable MOZ_VARIABLE_ATTRIBUTE; - * - * Attributes that apply to types follow the type name: - * - * typedef int MOZ_TYPE_ATTRIBUTE MagicInt; - * int MOZ_TYPE_ATTRIBUTE someVariable; - * int* MOZ_TYPE_ATTRIBUTE magicPtrInt; - * int MOZ_TYPE_ATTRIBUTE* ptrToMagicInt; - * - * Attributes that apply to statements precede the statement: - * - * MOZ_IF_ATTRIBUTE if (x == 0) - * MOZ_DO_ATTRIBUTE do { } while (0); - * - * Attributes that apply to labels precede the label: - * - * MOZ_LABEL_ATTRIBUTE target: - * goto target; - * MOZ_CASE_ATTRIBUTE case 5: - * MOZ_DEFAULT_ATTRIBUTE default: - * - * The static analyses that are performed by the plugin are as follows: - * - * MOZ_MUST_OVERRIDE: Applies to all C++ member functions. All immediate - * subclasses must provide an exact override of this method; if a subclass - * does not override this method, the compiler will emit an error. This - * attribute is not limited to virtual methods, so if it is applied to a - * nonvirtual method and the subclass does not provide an equivalent - * definition, the compiler will emit an error. - * MOZ_STACK_CLASS: Applies to all classes. Any class with this annotation is - * expected to live on the stack, so it is a compile-time error to use it, or - * an array of such objects, as a global or static variable, or as the type of - * a new expression (unless placement new is being used). If a member of - * another class uses this class, or if another class inherits from this - * class, then it is considered to be a stack class as well, although this - * attribute need not be provided in such cases. - * MOZ_NONHEAP_CLASS: Applies to all classes. Any class with this annotation is - * expected to live on the stack or in static storage, so it is a compile-time - * error to use it, or an array of such objects, as the type of a new - * expression (unless placement new is being used). If a member of another - * class uses this class, or if another class inherits from this class, then - * it is considered to be a non-heap class as well, although this attribute - * need not be provided in such cases. - * MOZ_ONLY_USED_TO_AVOID_STATIC_CONSTRUCTORS: Applies to all classes that are - * intended to prevent introducing static initializers. This attribute - * currently makes it a compile-time error to instantiate these classes - * anywhere other than at the global scope, or as a static member of a class. - * MOZ_TRIVIAL_CTOR_DTOR: Applies to all classes that must have both a trivial - * constructor and a trivial destructor. Setting this attribute on a class - * makes it a compile-time error for that class to get a non-trivial - * constructor or destructor for any reason. - * MOZ_HEAP_ALLOCATOR: Applies to any function. This indicates that the return - * value is allocated on the heap, and will as a result check such allocations - * during MOZ_STACK_CLASS and MOZ_NONHEAP_CLASS annotation checking. - * MOZ_IMPLICIT: Applies to constructors. Implicit conversion constructors - * are disallowed by default unless they are marked as MOZ_IMPLICIT. This - * attribute must be used for constructors which intend to provide implicit - * conversions. - * MOZ_NO_ARITHMETIC_EXPR_IN_ARGUMENT: Applies to functions. Makes it a compile - * time error to pass arithmetic expressions on variables to the function. - * MOZ_OWNING_REF: Applies to declarations of pointer types. This attribute - * tells the compiler that the raw pointer is a strong reference, and that - * property is somehow enforced by the code. This can make the compiler - * ignore these pointers when validating the usage of pointers otherwise. - * MOZ_NON_OWNING_REF: Applies to declarations of pointer types. This attribute - * tells the compiler that the raw pointer is a weak reference, and that - * property is somehow enforced by the code. This can make the compiler - * ignore these pointers when validating the usage of pointers otherwise. - * MOZ_UNSAFE_REF: Applies to declarations of pointer types. This attribute - * should be used for non-owning references that can be unsafe, and their - * safety needs to be validated through code inspection. The string argument - * passed to this macro documents the safety conditions. - * MOZ_NO_ADDREF_RELEASE_ON_RETURN: Applies to function declarations. Makes it - * a compile time error to call AddRef or Release on the return value of a - * function. This is intended to be used with operator->() of our smart - * pointer classes to ensure that the refcount of an object wrapped in a - * smart pointer is not manipulated directly. - */ -#ifdef MOZ_CLANG_PLUGIN -# define MOZ_MUST_OVERRIDE __attribute__((annotate("moz_must_override"))) -# define MOZ_STACK_CLASS __attribute__((annotate("moz_stack_class"))) -# define MOZ_NONHEAP_CLASS __attribute__((annotate("moz_nonheap_class"))) -# define MOZ_TRIVIAL_CTOR_DTOR __attribute__((annotate("moz_trivial_ctor_dtor"))) -# ifdef DEBUG - /* in debug builds, these classes do have non-trivial constructors. */ -# define MOZ_ONLY_USED_TO_AVOID_STATIC_CONSTRUCTORS __attribute__((annotate("moz_global_class"))) -# else -# define MOZ_ONLY_USED_TO_AVOID_STATIC_CONSTRUCTORS __attribute__((annotate("moz_global_class"))) \ - MOZ_TRIVIAL_CTOR_DTOR -# endif -# define MOZ_IMPLICIT __attribute__((annotate("moz_implicit"))) -# define MOZ_NO_ARITHMETIC_EXPR_IN_ARGUMENT __attribute__((annotate("moz_no_arith_expr_in_arg"))) -# define MOZ_OWNING_REF __attribute__((annotate("moz_strong_ref"))) -# define MOZ_NON_OWNING_REF __attribute__((annotate("moz_weak_ref"))) -# define MOZ_UNSAFE_REF(reason) __attribute__((annotate("moz_strong_ref"))) -# define MOZ_NO_ADDREF_RELEASE_ON_RETURN __attribute__((annotate("moz_no_addref_release_on_return"))) -/* - * It turns out that clang doesn't like void func() __attribute__ {} without a - * warning, so use pragmas to disable the warning. This code won't work on GCC - * anyways, so the warning is safe to ignore. - */ -# define MOZ_HEAP_ALLOCATOR \ - _Pragma("clang diagnostic push") \ - _Pragma("clang diagnostic ignored \"-Wgcc-compat\"") \ - __attribute__((annotate("moz_heap_allocator"))) \ - _Pragma("clang diagnostic pop") -#else -# define MOZ_MUST_OVERRIDE /* nothing */ -# define MOZ_STACK_CLASS /* nothing */ -# define MOZ_NONHEAP_CLASS /* nothing */ -# define MOZ_TRIVIAL_CTOR_DTOR /* nothing */ -# define MOZ_ONLY_USED_TO_AVOID_STATIC_CONSTRUCTORS /* nothing */ -# define MOZ_IMPLICIT /* nothing */ -# define MOZ_NO_ARITHMETIC_EXPR_IN_ARGUMENT /* nothing */ -# define MOZ_HEAP_ALLOCATOR /* nothing */ -# define MOZ_OWNING_REF /* nothing */ -# define MOZ_NON_OWNING_REF /* nothing */ -# define MOZ_UNSAFE_REF(reason) /* nothing */ -# define MOZ_NO_ADDREF_RELEASE_ON_RETURN /* nothing */ -#endif /* MOZ_CLANG_PLUGIN */ - -#endif /* __cplusplus */ - -#endif /* mozilla_Attributes_h */ diff --git a/onlineupdate/source/libmar/inc/mozilla/Compiler.h b/onlineupdate/source/libmar/inc/mozilla/Compiler.h deleted file mode 100644 index 6d6fcbbb19f5..000000000000 --- a/onlineupdate/source/libmar/inc/mozilla/Compiler.h +++ /dev/null @@ -1,110 +0,0 @@ -/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* vim: set ts=8 sts=2 et sw=2 tw=80: */ -/* This Source Code Form is subject to the terms of the Mozilla Public - * 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/. */ - -/* Various compiler checks. */ - -#ifndef mozilla_Compiler_h -#define mozilla_Compiler_h - -#define MOZ_IS_GCC 0 -#define MOS_IS_MSVC 0 - -#if !defined(__clang__) && defined(__GNUC__) - -# undef MOZ_IS_GCC -# define MOZ_IS_GCC 1 - /* - * This macro should simplify gcc version checking. For example, to check - * for gcc 4.7.1 or later, check `#if MOZ_GCC_VERSION_AT_LEAST(4, 7, 1)`. - */ -# define MOZ_GCC_VERSION_AT_LEAST(major, minor, patchlevel) \ - ((__GNUC__ * 10000 + __GNUC_MINOR__ * 100 + __GNUC_PATCHLEVEL__) \ - >= ((major) * 10000 + (minor) * 100 + (patchlevel))) -# if !MOZ_GCC_VERSION_AT_LEAST(4, 7, 0) -# error "mfbt (and Gecko) require at least gcc 4.7 to build." -# endif - -#elif defined(_MSC_VER) - -# undef MOZ_IS_MSVC -# define MOZ_IS_MSVC 1 - -#endif - -/* - * The situation with standard libraries is a lot worse than with compilers, - * particularly as clang and gcc could end up using one of three or so standard - * libraries, and they may not be up-to-snuff with newer C++11 versions. To - * detect the library, we're going to include cstddef (which is a small header - * which will be transitively included by everybody else at some point) to grab - * the version macros and deduce macros from there. - */ -#ifdef __cplusplus -# include -# ifdef _STLPORT_MAJOR -# define MOZ_USING_STLPORT 1 -# define MOZ_STLPORT_VERSION_AT_LEAST(major, minor, patch) \ - (_STLPORT_VERSION >= ((major) << 8 | (minor) << 4 | (patch))) -# elif defined(_LIBCPP_VERSION) - /* - * libc++, unfortunately, doesn't appear to have useful versioning macros. - * Hopefully, the recommendations of N3694 with respect to standard libraries - * will get applied instead and we won't need to worry about version numbers - * here. - */ -# define MOZ_USING_LIBCXX 1 -# elif defined(__GLIBCXX__) -# define MOZ_USING_LIBSTDCXX 1 - /* - * libstdc++ is also annoying and doesn't give us useful versioning macros - * for the library. If we're using gcc, then assume that libstdc++ matches - * the compiler version. If we're using clang, we're going to have to fake - * major/minor combinations by looking for newly-defined config macros. - */ -# if MOZ_IS_GCC -# define MOZ_LIBSTDCXX_VERSION_AT_LEAST(major, minor, patch) \ - MOZ_GCC_VERSION_AT_LEAST(major, minor, patch) -# elif defined(_GLIBCXX_THROW_OR_ABORT) -# define MOZ_LIBSTDCXX_VERSION_AT_LEAST(major, minor, patch) \ - ((major) < 4 || ((major) == 4 && (minor) <= 8)) -# elif defined(_GLIBCXX_NOEXCEPT) -# define MOZ_LIBSTDCXX_VERSION_AT_LEAST(major, minor, patch) \ - ((major) < 4 || ((major) == 4 && (minor) <= 7)) -# elif defined(_GLIBCXX_USE_DEPRECATED) -# define MOZ_LIBSTDCXX_VERSION_AT_LEAST(major, minor, patch) \ - ((major) < 4 || ((major) == 4 && (minor) <= 6)) -# elif defined(_GLIBCXX_PSEUDO_VISIBILITY) -# define MOZ_LIBSTDCXX_VERSION_AT_LEAST(major, minor, patch) \ - ((major) < 4 || ((major) == 4 && (minor) <= 5)) -# elif defined(_GLIBCXX_BEGIN_EXTERN_C) -# define MOZ_LIBSTDCXX_VERSION_AT_LEAST(major, minor, patch) \ - ((major) < 4 || ((major) == 4 && (minor) <= 4)) -# elif defined(_GLIBCXX_VISIBILITY_ATTR) -# define MOZ_LIBSTDCXX_VERSION_AT_LEAST(major, minor, patch) \ - ((major) < 4 || ((major) == 4 && (minor) <= 3)) -# elif defined(_GLIBCXX_VISIBILITY) -# define MOZ_LIBSTDCXX_VERSION_AT_LEAST(major, minor, patch) \ - ((major) < 4 || ((major) == 4 && (minor) <= 2)) -# else -# error "Your version of libstdc++ is unknown to us and is likely too old." -# endif -# endif - - // Flesh out the defines for everyone else -# ifndef MOZ_USING_STLPORT -# define MOZ_USING_STLPORT 0 -# define MOZ_STLPORT_VERSION_AT_LEAST(major, minor, patch) 0 -# endif -# ifndef MOZ_USING_LIBCXX -# define MOZ_USING_LIBCXX 0 -# endif -# ifndef MOZ_USING_LIBSTDCXX -# define MOZ_USING_LIBSTDCXX 0 -# define MOZ_LIBSTDCXX_VERSION_AT_LEAST(major, minor, patch) 0 -# endif -#endif /* __cplusplus */ - -#endif /* mozilla_Compiler_h */ diff --git a/onlineupdate/source/libmar/inc/mozilla/Likely.h b/onlineupdate/source/libmar/inc/mozilla/Likely.h deleted file mode 100644 index 4f2160929544..000000000000 --- a/onlineupdate/source/libmar/inc/mozilla/Likely.h +++ /dev/null @@ -1,23 +0,0 @@ -/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* vim: set ts=8 sts=2 et sw=2 tw=80: */ -/* This Source Code Form is subject to the terms of the Mozilla Public - * 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/. */ - -/* - * MOZ_LIKELY and MOZ_UNLIKELY macros to hint to the compiler how a - * boolean predicate should be branch-predicted. - */ - -#ifndef mozilla_Likely_h -#define mozilla_Likely_h - -#if defined(__clang__) || defined(__GNUC__) -# define MOZ_LIKELY(x) (__builtin_expect(!!(x), 1)) -# define MOZ_UNLIKELY(x) (__builtin_expect(!!(x), 0)) -#else -# define MOZ_LIKELY(x) (!!(x)) -# define MOZ_UNLIKELY(x) (!!(x)) -#endif - -#endif /* mozilla_Likely_h */ diff --git a/onlineupdate/source/libmar/inc/mozilla/MacroArgs.h b/onlineupdate/source/libmar/inc/mozilla/MacroArgs.h deleted file mode 100644 index c8b733821035..000000000000 --- a/onlineupdate/source/libmar/inc/mozilla/MacroArgs.h +++ /dev/null @@ -1,105 +0,0 @@ -/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* vim: set ts=8 sts=2 et sw=2 tw=80: */ -/* This Source Code Form is subject to the terms of the Mozilla Public - * 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/. */ - -/* - * Implements various macros meant to ease the use of variadic macros. - */ - -#ifndef mozilla_MacroArgs_h -#define mozilla_MacroArgs_h - -/* - * MOZ_PASTE_PREFIX_AND_ARG_COUNT(aPrefix, ...) counts the number of variadic - * arguments and prefixes it with |aPrefix|. For example: - * - * MOZ_PASTE_PREFIX_AND_ARG_COUNT(, foo, 42) expands to 2 - * MOZ_PASTE_PREFIX_AND_ARG_COUNT(A, foo, 42, bar) expands to A3 - * - * You must pass in between 1 and 50 (inclusive) variadic arguments, past - * |aPrefix|. It is not legal to do - * - * MOZ_PASTE_PREFIX_AND_ARG_COUNT(prefix) - * - * (that is, pass in 0 variadic arguments). To ensure that a compile-time - * error occurs when these constraints are violated, use the - * MOZ_STATIC_ASSERT_VALID_ARG_COUNT macro with the same variaidc arguments - * wherever this macro is used. - * - * Passing (__VA_ARGS__, ) rather than simply calling - * MOZ_MACROARGS_ARG_COUNT_HELPER2(__VA_ARGS__, ) very - * carefully tiptoes around a MSVC bug where it improperly expands __VA_ARGS__ - * as a single token in argument lists. For details, see: - * - * http://connect.microsoft.com/VisualStudio/feedback/details/380090/variadic-macro-replacement - * http://cplusplus.co.il/2010/07/17/variadic-macro-to-count-number-of-arguments/#comment-644 - */ -#define MOZ_PASTE_PREFIX_AND_ARG_COUNT(aPrefix, ...) \ - MOZ_MACROARGS_ARG_COUNT_HELPER((__VA_ARGS__, \ - aPrefix##50, aPrefix##49, aPrefix##48, aPrefix##47, aPrefix##46, \ - aPrefix##45, aPrefix##44, aPrefix##43, aPrefix##42, aPrefix##41, \ - aPrefix##40, aPrefix##39, aPrefix##38, aPrefix##37, aPrefix##36, \ - aPrefix##35, aPrefix##34, aPrefix##33, aPrefix##32, aPrefix##31, \ - aPrefix##30, aPrefix##29, aPrefix##28, aPrefix##27, aPrefix##26, \ - aPrefix##25, aPrefix##24, aPrefix##23, aPrefix##22, aPrefix##21, \ - aPrefix##20, aPrefix##19, aPrefix##18, aPrefix##17, aPrefix##16, \ - aPrefix##15, aPrefix##14, aPrefix##13, aPrefix##12, aPrefix##11, \ - aPrefix##10, aPrefix##9, aPrefix##8, aPrefix##7, aPrefix##6, \ - aPrefix##5, aPrefix##4, aPrefix##3, aPrefix##2, aPrefix##1, aPrefix##0)) - -#define MOZ_MACROARGS_ARG_COUNT_HELPER(aArgs) \ - MOZ_MACROARGS_ARG_COUNT_HELPER2 aArgs - -#define MOZ_MACROARGS_ARG_COUNT_HELPER2( \ - a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, \ - a11, a12, a13, a14, a15, a16, a17, a18, a19, a20, \ - a21, a22, a23, a24, a25, a26, a27, a28, a29, a30, \ - a31, a32, a33, a34, a35, a36, a37, a38, a39, a40, \ - a41, a42, a43, a44, a45, a46, a47, a48, a49, a50, \ - a51, ...) a51 - -/* - * MOZ_STATIC_ASSERT_VALID_ARG_COUNT ensures that a compile-time error occurs - * when the argument count constraints of MOZ_PASTE_PREFIX_AND_ARG_COUNT are - * violated. Use this macro wherever MOZ_PASTE_PREFIX_AND_ARG_COUNT is used - * and pass it the same variadic arguments. - * - * This macro employs a few dirty tricks to function. To detect the zero - * argument case, |(__VA_ARGS__)| is stringified, sizeof-ed, and compared to - * what it should be in the absence of arguments. - * - * Detecting too many arguments is a little trickier. With a valid argument - * count and a prefix of 1, MOZ_PASTE_PREFIX_AND_ARG_COUNT expands to e.g. 14. - * With a prefix of 0.0, it expands to e.g. 0.04. If there are too many - * arguments, it expands to the first argument over the limit. If this - * exceeding argument is a number, the assertion will fail as there is no - * number than can simultaneously be both > 10 and == 0. If the exceeding - * argument is not a number, a compile-time error should still occur due to - * the operations performed on it. - */ -#define MOZ_MACROARGS_STRINGIFY_HELPER(x) #x -#define MOZ_STATIC_ASSERT_VALID_ARG_COUNT(...) \ - static_assert( \ - sizeof(MOZ_MACROARGS_STRINGIFY_HELPER((__VA_ARGS__))) != sizeof("()") && \ - (MOZ_PASTE_PREFIX_AND_ARG_COUNT(1, __VA_ARGS__)) > 10 && \ - (int)(MOZ_PASTE_PREFIX_AND_ARG_COUNT(0.0, __VA_ARGS__)) == 0, \ - "MOZ_STATIC_ASSERT_VALID_ARG_COUNT requires 1 to 50 arguments") /* ; */ - -/* - * MOZ_ARGS_AFTER_N expands to its arguments excluding the first |N| - * arguments. For example: - * - * MOZ_ARGS_AFTER_2(a, b, c, d) expands to: c, d - */ -#define MOZ_ARGS_AFTER_1(a1, ...) __VA_ARGS__ -#define MOZ_ARGS_AFTER_2(a1, a2, ...) __VA_ARGS__ - -/* - * MOZ_ARG_N expands to its |N|th argument. - */ -#define MOZ_ARG_1(a1, ...) a1 -#define MOZ_ARG_2(a1, a2, ...) a2 - -#endif /* mozilla_MacroArgs_h */ diff --git a/onlineupdate/source/libmar/inc/mozilla/TypeTraits.h b/onlineupdate/source/libmar/inc/mozilla/TypeTraits.h deleted file mode 100644 index 47c7945a6a2d..000000000000 --- a/onlineupdate/source/libmar/inc/mozilla/TypeTraits.h +++ /dev/null @@ -1,1116 +0,0 @@ -/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* vim: set ts=8 sts=2 et sw=2 tw=80: */ -/* This Source Code Form is subject to the terms of the Mozilla Public - * 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/. */ - -/* Template-based metaprogramming and type-testing facilities. */ - -#ifndef mozilla_TypeTraits_h -#define mozilla_TypeTraits_h - -#include "mozilla/Types.h" - -/* - * These traits are approximate copies of the traits and semantics from C++11's - * header. Don't add traits not in that header! When all - * platforms provide that header, we can convert all users and remove this one. - */ - -#include - -namespace mozilla { - -/* Forward declarations. */ - -template struct RemoveCV; - -/* 20.9.3 Helper classes [meta.help] */ - -/** - * Helper class used as a base for various type traits, exposed publicly - * because exposes it as well. - */ -template -struct IntegralConstant -{ - static const T value = Value; - typedef T ValueType; - typedef IntegralConstant Type; -}; - -/** Convenient aliases. */ -typedef IntegralConstant TrueType; -typedef IntegralConstant FalseType; - -/* 20.9.4 Unary type traits [meta.unary] */ - -/* 20.9.4.1 Primary type categories [meta.unary.cat] */ - -namespace detail { - -template -struct IsVoidHelper : FalseType {}; - -template<> -struct IsVoidHelper : TrueType {}; - -} // namespace detail - -/** - * IsVoid determines whether a type is void. - * - * mozilla::IsVoid::value is false; - * mozilla::IsVoid::value is true; - * mozilla::IsVoid::value is false; - * mozilla::IsVoid::value is true. - */ -template -struct IsVoid : detail::IsVoidHelper::Type> {}; - -namespace detail { - -template -struct IsIntegralHelper : FalseType {}; - -template<> struct IsIntegralHelper : TrueType {}; -template<> struct IsIntegralHelper : TrueType {}; -template<> struct IsIntegralHelper : TrueType {}; -template<> struct IsIntegralHelper : TrueType {}; -template<> struct IsIntegralHelper : TrueType {}; -template<> struct IsIntegralHelper : TrueType {}; -template<> struct IsIntegralHelper : TrueType {}; -template<> struct IsIntegralHelper : TrueType {}; -template<> struct IsIntegralHelper : TrueType {}; -template<> struct IsIntegralHelper : TrueType {}; -template<> struct IsIntegralHelper : TrueType {}; -template<> struct IsIntegralHelper : TrueType {}; -template<> struct IsIntegralHelper : TrueType {}; -#ifdef MOZ_CHAR16_IS_NOT_WCHAR -template<> struct IsIntegralHelper : TrueType {}; -#endif - -} /* namespace detail */ - -/** - * IsIntegral determines whether a type is an integral type. - * - * mozilla::IsIntegral::value is true; - * mozilla::IsIntegral::value is true; - * mozilla::IsIntegral::value is true; - * mozilla::IsIntegral::value is false; - * mozilla::IsIntegral::value is false; - * - * Note that the behavior of IsIntegral on char16_t and char32_t is - * unspecified. - */ -template -struct IsIntegral : detail::IsIntegralHelper::Type> -{}; - -template -struct IsSame; - -namespace detail { - -template -struct IsFloatingPointHelper - : IntegralConstant::value || - IsSame::value || - IsSame::value> -{}; - -} // namespace detail - -/** - * IsFloatingPoint determines whether a type is a floating point type (float, - * double, long double). - * - * mozilla::IsFloatingPoint::value is false; - * mozilla::IsFloatingPoint::value is true; - * mozilla::IsFloatingPoint::value is true; - * mozilla::IsFloatingPoint::value is false. - */ -template -struct IsFloatingPoint - : detail::IsFloatingPointHelper::Type> -{}; - -namespace detail { - -template -struct IsArrayHelper : FalseType {}; - -template -struct IsArrayHelper : TrueType {}; - -template -struct IsArrayHelper : TrueType {}; - -} // namespace detail - -/** - * IsArray determines whether a type is an array type, of known or unknown - * length. - * - * mozilla::IsArray::value is false; - * mozilla::IsArray::value is true; - * mozilla::IsArray::value is true. - */ -template -struct IsArray : detail::IsArrayHelper::Type> -{}; - -namespace detail { - -template -struct IsPointerHelper : FalseType {}; - -template -struct IsPointerHelper : TrueType {}; - -} // namespace detail - -/** - * IsPointer determines whether a type is a possibly-CV-qualified pointer type - * (but not a pointer-to-member type). - * - * mozilla::IsPointer::value is true; - * mozilla::IsPointer::value is true; - * mozilla::IsPointer::value is true; - * mozilla::IsPointer::value is true; - * mozilla::IsPointer::value is true; - * mozilla::IsPointer::value is true; - * mozilla::IsPointer::value is true; - * mozilla::IsPointer::value is false; - * mozilla::IsPointer::value is false. - * mozilla::IsPointer::value is false - */ -template -struct IsPointer : detail::IsPointerHelper::Type> -{}; - -/** - * IsLvalueReference determines whether a type is an lvalue reference. - * - * mozilla::IsLvalueReference::value is false; - * mozilla::IsLvalueReference::value is false; - * mozilla::IsLvalueReference::value is false; - * mozilla::IsLvalueReference::value is false; - * mozilla::IsLvalueReference::value is false; - * mozilla::IsLvalueReference::value is true; - * mozilla::IsLvalueReference::value is false. - */ -template -struct IsLvalueReference : FalseType {}; - -template -struct IsLvalueReference : TrueType {}; - -/** - * IsRvalueReference determines whether a type is an rvalue reference. - * - * mozilla::IsRvalueReference::value is false; - * mozilla::IsRvalueReference::value is false; - * mozilla::IsRvalueReference::value is false; - * mozilla::IsRvalueReference::value is false; - * mozilla::IsRvalueReference::value is false; - * mozilla::IsRvalueReference::value is false; - * mozilla::IsRvalueReference::value is true. - */ -template -struct IsRvalueReference : FalseType {}; - -template -struct IsRvalueReference : TrueType {}; - -namespace detail { - -// __is_enum is a supported extension across all of our supported compilers. -template -struct IsEnumHelper - : IntegralConstant -{}; - -} // namespace detail - -/** - * IsEnum determines whether a type is an enum type. - * - * mozilla::IsEnum::value is true; - * mozilla::IsEnum::value is false; - * mozilla::IsEnum::value is false; - */ -template -struct IsEnum - : detail::IsEnumHelper::Type> -{}; - -namespace detail { - -// __is_class is a supported extension across all of our supported compilers: -// http://llvm.org/releases/3.0/docs/ClangReleaseNotes.html -// http://gcc.gnu.org/onlinedocs/gcc-4.4.7/gcc/Type-Traits.html#Type-Traits -// http://msdn.microsoft.com/en-us/library/ms177194%28v=vs.100%29.aspx -template -struct IsClassHelper - : IntegralConstant -{}; - -} // namespace detail - -/** - * IsClass determines whether a type is a class type (but not a union). - * - * struct S {}; - * union U {}; - * mozilla::IsClass::value is false; - * mozilla::IsClass::value is true; - * mozilla::IsClass::value is false; - */ -template -struct IsClass - : detail::IsClassHelper::Type> -{}; - -/* 20.9.4.2 Composite type traits [meta.unary.comp] */ - -/** - * IsReference determines whether a type is an lvalue or rvalue reference. - * - * mozilla::IsReference::value is false; - * mozilla::IsReference::value is false; - * mozilla::IsReference::value is true; - * mozilla::IsReference::value is false; - * mozilla::IsReference::value is true; - * mozilla::IsReference::value is false; - * mozilla::IsReference::value is false; - * mozilla::IsReference::value is true; - * mozilla::IsReference::value is true; - * mozilla::IsReference::value is true. - */ -template -struct IsReference - : IntegralConstant::value || IsRvalueReference::value> -{}; - -/** - * IsArithmetic determines whether a type is arithmetic. A type is arithmetic - * iff it is an integral type or a floating point type. - * - * mozilla::IsArithmetic::value is true; - * mozilla::IsArithmetic::value is true; - * mozilla::IsArithmetic::value is false. - */ -template -struct IsArithmetic - : IntegralConstant::value || IsFloatingPoint::value> -{}; - -/* 20.9.4.3 Type properties [meta.unary.prop] */ - -/** - * IsConst determines whether a type is const or not. - * - * mozilla::IsConst::value is false; - * mozilla::IsConst::value is true; - * mozilla::IsConst::value is false. - */ -template -struct IsConst : FalseType {}; - -template -struct IsConst : TrueType {}; - -/** - * IsVolatile determines whether a type is volatile or not. - * - * mozilla::IsVolatile::value is false; - * mozilla::IsVolatile::value is true; - * mozilla::IsVolatile::value is false. - */ -template -struct IsVolatile : FalseType {}; - -template -struct IsVolatile : TrueType {}; - -/** - * Traits class for identifying POD types. Until C++11 there's no automatic - * way to detect PODs, so for the moment this is done manually. Users may - * define specializations of this class that inherit from mozilla::TrueType and - * mozilla::FalseType (or equivalently mozilla::IntegralConstant, or conveniently from mozilla::IsPod for composite types) as needed to - * ensure correct IsPod behavior. - */ -template -struct IsPod : public FalseType {}; - -template<> struct IsPod : TrueType {}; -template<> struct IsPod : TrueType {}; -template<> struct IsPod : TrueType {}; -template<> struct IsPod : TrueType {}; -template<> struct IsPod : TrueType {}; -template<> struct IsPod : TrueType {}; -template<> struct IsPod : TrueType {}; -template<> struct IsPod : TrueType {}; -template<> struct IsPod : TrueType {}; -template<> struct IsPod : TrueType {}; -template<> struct IsPod : TrueType {}; -template<> struct IsPod : TrueType {}; -template<> struct IsPod : TrueType {}; -template<> struct IsPod : TrueType {}; -template<> struct IsPod : TrueType {}; -#ifdef MOZ_CHAR16_IS_NOT_WCHAR -template<> struct IsPod : TrueType {}; -#endif -template struct IsPod : TrueType {}; - -namespace detail { - -// __is_empty is a supported extension across all of our supported compilers: -// http://llvm.org/releases/3.0/docs/ClangReleaseNotes.html -// http://gcc.gnu.org/onlinedocs/gcc-4.4.7/gcc/Type-Traits.html#Type-Traits -// http://msdn.microsoft.com/en-us/library/ms177194%28v=vs.100%29.aspx -template -struct IsEmptyHelper - : IntegralConstant::value && __is_empty(T)> -{}; - -} // namespace detail - -/** - * IsEmpty determines whether a type is a class (but not a union) that is empty. - * - * A class is empty iff it and all its base classes have no non-static data - * members (except bit-fields of length 0) and no virtual member functions, and - * no base class is empty or a virtual base class. - * - * Intuitively, empty classes don't have any data that has to be stored in - * instances of those classes. (The size of the class must still be non-zero, - * because distinct array elements of any type must have different addresses. - * However, if the Empty Base Optimization is implemented by the compiler [most - * compilers implement it, and in certain cases C++11 requires it], the size of - * a class inheriting from an empty |Base| class need not be inflated by - * |sizeof(Base)|.) And intuitively, non-empty classes have data members and/or - * vtable pointers that must be stored in each instance for proper behavior. - * - * static_assert(!mozilla::IsEmpty::value, "not a class => not empty"); - * union U1 { int x; }; - * static_assert(!mozilla::IsEmpty::value, "not a class => not empty"); - * struct E1 {}; - * struct E2 { int : 0 }; - * struct E3 : E1 {}; - * struct E4 : E2 {}; - * static_assert(mozilla::IsEmpty::value && - * mozilla::IsEmpty::value && - * mozilla::IsEmpty::value && - * mozilla::IsEmpty::value, - * "all empty"); - * union U2 { E1 e1; }; - * static_assert(!mozilla::IsEmpty::value, "not a class => not empty"); - * struct NE1 { int x; }; - * struct NE2 : virtual E1 {}; - * struct NE3 : E2 { virtual ~NE3() {} }; - * struct NE4 { virtual void f() {} }; - * static_assert(!mozilla::IsEmpty::value && - * !mozilla::IsEmpty::value && - * !mozilla::IsEmpty::value && - * !mozilla::IsEmpty::value, - * "all empty"); - */ -template -struct IsEmpty : detail::IsEmptyHelper::Type> -{}; - - -namespace detail { - -template::value, - bool = IsIntegral::value, - typename NoCV = typename RemoveCV::Type> -struct IsSignedHelper; - -// Floating point is signed. -template -struct IsSignedHelper : TrueType {}; - -// Integral is conditionally signed. -template -struct IsSignedHelper - : IntegralConstant -{}; - -// Non-floating point, non-integral is not signed. -template -struct IsSignedHelper : FalseType {}; - -} // namespace detail - -/** - * IsSigned determines whether a type is a signed arithmetic type. |char| is - * considered a signed type if it has the same representation as |signed char|. - * - * mozilla::IsSigned::value is true; - * mozilla::IsSigned::value is false; - * mozilla::IsSigned::value is false; - * mozilla::IsSigned::value is true. - */ -template -struct IsSigned : detail::IsSignedHelper {}; - -namespace detail { - -template::value, - bool = IsIntegral::value, - typename NoCV = typename RemoveCV::Type> -struct IsUnsignedHelper; - -// Floating point is not unsigned. -template -struct IsUnsignedHelper : FalseType {}; - -// Integral is conditionally unsigned. -template -struct IsUnsignedHelper - : IntegralConstant::value || bool(NoCV(1) < NoCV(-1)))> -{}; - -// Non-floating point, non-integral is not unsigned. -template -struct IsUnsignedHelper : FalseType {}; - -} // namespace detail - -/** - * IsUnsigned determines whether a type is an unsigned arithmetic type. - * - * mozilla::IsUnsigned::value is false; - * mozilla::IsUnsigned::value is true; - * mozilla::IsUnsigned::value is true; - * mozilla::IsUnsigned::value is false. - */ -template -struct IsUnsigned : detail::IsUnsignedHelper {}; - -/* 20.9.5 Type property queries [meta.unary.prop.query] */ - -/* 20.9.6 Relationships between types [meta.rel] */ - -/** - * IsSame tests whether two types are the same type. - * - * mozilla::IsSame::value is true; - * mozilla::IsSame::value is true; - * mozilla::IsSame::value is false; - * mozilla::IsSame::value is true; - * mozilla::IsSame::value is false; - * mozilla::IsSame::value is true. - */ -template -struct IsSame : FalseType {}; - -template -struct IsSame : TrueType {}; - -namespace detail { - -#if defined(__GNUC__) || defined(__clang__) || defined(_MSC_VER) - -template -struct BaseOfTester : IntegralConstant {}; - -#else - -// The trickery used to implement IsBaseOf here makes it possible to use it for -// the cases of private and multiple inheritance. This code was inspired by the -// sample code here: -// -// http://stackoverflow.com/questions/2910979/how-is-base-of-works -template -struct BaseOfHelper -{ -public: - operator Base*() const; - operator Derived*(); -}; - -template -struct BaseOfTester -{ -private: - template - static char test(Derived*, T); - static int test(Base*, int); - -public: - static const bool value = - sizeof(test(BaseOfHelper(), int())) == sizeof(char); -}; - -template -struct BaseOfTester -{ -private: - template - static char test(Derived*, T); - static int test(Base*, int); - -public: - static const bool value = - sizeof(test(BaseOfHelper(), int())) == sizeof(char); -}; - -template -struct BaseOfTester : FalseType {}; - -template -struct BaseOfTester : TrueType {}; - -template -struct BaseOfTester : TrueType {}; - -#endif - -} /* namespace detail */ - -/* - * IsBaseOf allows to know whether a given class is derived from another. - * - * Consider the following class definitions: - * - * class A {}; - * class B : public A {}; - * class C {}; - * - * mozilla::IsBaseOf::value is true; - * mozilla::IsBaseOf::value is false; - */ -template -struct IsBaseOf - : IntegralConstant::value> -{}; - -namespace detail { - -template -struct ConvertibleTester -{ -private: - static From create(); - - template - static char test(To to); - - template - static int test(...); - -public: - static const bool value = - sizeof(test(create())) == sizeof(char); -}; - -} // namespace detail - -/** - * IsConvertible determines whether a value of type From will implicitly convert - * to a value of type To. For example: - * - * struct A {}; - * struct B : public A {}; - * struct C {}; - * - * mozilla::IsConvertible::value is true; - * mozilla::IsConvertible::value is true; - * mozilla::IsConvertible::value is true; - * mozilla::IsConvertible::value is true; - * mozilla::IsConvertible::value is false; - * mozilla::IsConvertible::value is false; - * mozilla::IsConvertible::value is false; - * mozilla::IsConvertible::value is false. - * - * For obscure reasons, you can't use IsConvertible when the types being tested - * are related through private inheritance, and you'll get a compile error if - * you try. Just don't do it! - * - * Note - we need special handling for void, which ConvertibleTester doesn't - * handle. The void handling here doesn't handle const/volatile void correctly, - * which could be easily fixed if the need arises. - */ -template -struct IsConvertible - : IntegralConstant::value> -{}; - -template -struct IsConvertible - : IntegralConstant::value> -{}; - -template -struct IsConvertible - : IntegralConstant::value> -{}; - -template<> -struct IsConvertible - : TrueType -{}; - -/* 20.9.7 Transformations between types [meta.trans] */ - -/* 20.9.7.1 Const-volatile modifications [meta.trans.cv] */ - -/** - * RemoveConst removes top-level const qualifications on a type. - * - * mozilla::RemoveConst::Type is int; - * mozilla::RemoveConst::Type is int; - * mozilla::RemoveConst::Type is const int*; - * mozilla::RemoveConst::Type is int*. - */ -template -struct RemoveConst -{ - typedef T Type; -}; - -template -struct RemoveConst -{ - typedef T Type; -}; - -/** - * RemoveVolatile removes top-level volatile qualifications on a type. - * - * mozilla::RemoveVolatile::Type is int; - * mozilla::RemoveVolatile::Type is int; - * mozilla::RemoveVolatile::Type is volatile int*; - * mozilla::RemoveVolatile::Type is int*. - */ -template -struct RemoveVolatile -{ - typedef T Type; -}; - -template -struct RemoveVolatile -{ - typedef T Type; -}; - -/** - * RemoveCV removes top-level const and volatile qualifications on a type. - * - * mozilla::RemoveCV::Type is int; - * mozilla::RemoveCV::Type is int; - * mozilla::RemoveCV::Type is int; - * mozilla::RemoveCV::Type is int*. - */ -template -struct RemoveCV -{ - typedef typename RemoveConst::Type>::Type Type; -}; - -/* 20.9.7.2 Reference modifications [meta.trans.ref] */ - -/** - * Converts reference types to the underlying types. - * - * mozilla::RemoveReference::Type is T; - * mozilla::RemoveReference::Type is T; - * mozilla::RemoveReference::Type is T; - */ - -template -struct RemoveReference -{ - typedef T Type; -}; - -template -struct RemoveReference -{ - typedef T Type; -}; - -template -struct RemoveReference -{ - typedef T Type; -}; - -template -struct Conditional; - -namespace detail { - -enum Voidness { TIsVoid, TIsNotVoid }; - -template::value ? TIsVoid : TIsNotVoid> -struct AddLvalueReferenceHelper; - -template -struct AddLvalueReferenceHelper -{ - typedef void Type; -}; - -template -struct AddLvalueReferenceHelper -{ - typedef T& Type; -}; - -} // namespace detail - -/** - * AddLvalueReference adds an lvalue & reference to T if one isn't already - * present. (Note: adding an lvalue reference to an rvalue && reference in - * essence replaces the && with a &&, per C+11 reference collapsing rules. For - * example, int&& would become int&.) - * - * The final computed type will only *not* be an lvalue reference if T is void. - * - * mozilla::AddLvalueReference::Type is int&; - * mozilla::AddLvalueRference::Type is volatile int&; - * mozilla::AddLvalueReference::Type is void*&; - * mozilla::AddLvalueReference::Type is void; - * mozilla::AddLvalueReference::Type is struct S&. - */ -template -struct AddLvalueReference - : detail::AddLvalueReferenceHelper -{}; - -namespace detail { - -template::value ? TIsVoid : TIsNotVoid> -struct AddRvalueReferenceHelper; - -template -struct AddRvalueReferenceHelper -{ - typedef void Type; -}; - -template -struct AddRvalueReferenceHelper -{ - typedef T&& Type; -}; - -} // namespace detail - -/** - * AddRvalueReference adds an rvalue && reference to T if one isn't already - * present. (Note: adding an rvalue reference to an lvalue & reference in - * essence keeps the &, per C+11 reference collapsing rules. For example, - * int& would remain int&.) - * - * The final computed type will only *not* be a reference if T is void. - * - * mozilla::AddRvalueReference::Type is int&&; - * mozilla::AddRvalueRference::Type is volatile int&; - * mozilla::AddRvalueRference::Type is const int&&; - * mozilla::AddRvalueReference::Type is void*&&; - * mozilla::AddRvalueReference::Type is void; - * mozilla::AddRvalueReference::Type is struct S&. - */ -template -struct AddRvalueReference - : detail::AddRvalueReferenceHelper -{}; - -/* 20.2.4 Function template declval [declval] */ - -/** - * DeclVal simplifies the definition of expressions which occur as unevaluated - * operands. It converts T to a reference type, making it possible to use in - * decltype expressions even if T does not have a default constructor, e.g.: - * decltype(DeclVal().foo()) - */ -template -typename AddRvalueReference::Type DeclVal(); - -/* 20.9.7.3 Sign modifications [meta.trans.sign] */ - -template -struct EnableIf; - -namespace detail { - -template -struct WithC : Conditional -{}; - -template -struct WithV : Conditional -{}; - - -template -struct WithCV : WithC::Type> -{}; - -template -struct CorrespondingSigned; - -template<> -struct CorrespondingSigned { typedef signed char Type; }; -template<> -struct CorrespondingSigned { typedef signed char Type; }; -template<> -struct CorrespondingSigned { typedef short Type; }; -template<> -struct CorrespondingSigned { typedef int Type; }; -template<> -struct CorrespondingSigned { typedef long Type; }; -template<> -struct CorrespondingSigned { typedef long long Type; }; - -template::Type, - bool IsSignedIntegerType = IsSigned::value && - !IsSame::value> -struct MakeSigned; - -template -struct MakeSigned -{ - typedef T Type; -}; - -template -struct MakeSigned - : WithCV::value, IsVolatile::value, - typename CorrespondingSigned::Type> -{}; - -} // namespace detail - -/** - * MakeSigned produces the corresponding signed integer type for a given - * integral type T, with the const/volatile qualifiers of T. T must be a - * possibly-const/volatile-qualified integral type that isn't bool. - * - * If T is already a signed integer type (not including char!), then T is - * produced. - * - * Otherwise, if T is an unsigned integer type, the signed variety of T, with - * T's const/volatile qualifiers, is produced. - * - * Otherwise, the integral type of the same size as T, with the lowest rank, - * with T's const/volatile qualifiers, is produced. (This basically only acts - * to produce signed char when T = char.) - * - * mozilla::MakeSigned::Type is signed long; - * mozilla::MakeSigned::Type is volatile int; - * mozilla::MakeSigned::Type is const signed short; - * mozilla::MakeSigned::Type is const signed char; - * mozilla::MakeSigned is an error; - * mozilla::MakeSigned is an error. - */ -template -struct MakeSigned - : EnableIf::value && - !IsSame::Type>::value, - typename detail::MakeSigned - >::Type -{}; - -namespace detail { - -template -struct CorrespondingUnsigned; - -template<> -struct CorrespondingUnsigned { typedef unsigned char Type; }; -template<> -struct CorrespondingUnsigned { typedef unsigned char Type; }; -template<> -struct CorrespondingUnsigned { typedef unsigned short Type; }; -template<> -struct CorrespondingUnsigned { typedef unsigned int Type; }; -template<> -struct CorrespondingUnsigned { typedef unsigned long Type; }; -template<> -struct CorrespondingUnsigned { typedef unsigned long long Type; }; - - -template::Type, - bool IsUnsignedIntegerType = IsUnsigned::value && - !IsSame::value> -struct MakeUnsigned; - -template -struct MakeUnsigned -{ - typedef T Type; -}; - -template -struct MakeUnsigned - : WithCV::value, IsVolatile::value, - typename CorrespondingUnsigned::Type> -{}; - -} // namespace detail - -/** - * MakeUnsigned produces the corresponding unsigned integer type for a given - * integral type T, with the const/volatile qualifiers of T. T must be a - * possibly-const/volatile-qualified integral type that isn't bool. - * - * If T is already an unsigned integer type (not including char!), then T is - * produced. - * - * Otherwise, if T is an signed integer type, the unsigned variety of T, with - * T's const/volatile qualifiers, is produced. - * - * Otherwise, the unsigned integral type of the same size as T, with the lowest - * rank, with T's const/volatile qualifiers, is produced. (This basically only - * acts to produce unsigned char when T = char.) - * - * mozilla::MakeUnsigned::Type is unsigned long; - * mozilla::MakeUnsigned::Type is volatile unsigned int; - * mozilla::MakeUnsigned::Type is const unsigned short; - * mozilla::MakeUnsigned::Type is const unsigned char; - * mozilla::MakeUnsigned is an error; - * mozilla::MakeUnsigned is an error. - */ -template -struct MakeUnsigned - : EnableIf::value && - !IsSame::Type>::value, - typename detail::MakeUnsigned - >::Type -{}; - -/* 20.9.7.4 Array modifications [meta.trans.arr] */ - -/** - * RemoveExtent produces either the type of the elements of the array T, or T - * itself. - * - * mozilla::RemoveExtent::Type is int; - * mozilla::RemoveExtent::Type is const int; - * mozilla::RemoveExtent::Type is volatile int; - * mozilla::RemoveExtent::Type is long[17]. - */ -template -struct RemoveExtent -{ - typedef T Type; -}; - -template -struct RemoveExtent -{ - typedef T Type; -}; - -template -struct RemoveExtent -{ - typedef T Type; -}; - -/* 20.9.7.5 Pointer modifications [meta.trans.ptr] */ - -namespace detail { - -template -struct RemovePointerHelper -{ - typedef T Type; -}; - -template -struct RemovePointerHelper -{ - typedef Pointee Type; -}; - -} // namespac detail - -/** - * Produces the pointed-to type if a pointer is provided, else returns the input - * type. Note that this does not dereference pointer-to-member pointers. - * - * struct S { bool m; void f(); }; - * mozilla::RemovePointer::Type is int; - * mozilla::RemovePointer::Type is int; - * mozilla::RemovePointer::Type is int; - * mozilla::RemovePointer::Type is int; - * mozilla::RemovePointer::Type is const long; - * mozilla::RemovePointer::Type is void; - * mozilla::RemovePointer::Type is void (S::*)(); - * mozilla::RemovePointer::Type is void(); - * mozilla::RemovePointer::Type is bool S::*. - */ -template -struct RemovePointer - : detail::RemovePointerHelper::Type> -{}; - -/* 20.9.7.6 Other transformations [meta.trans.other] */ - -/** - * EnableIf is a struct containing a typedef of T if and only if B is true. - * - * mozilla::EnableIf::Type is int; - * mozilla::EnableIf::Type is a compile-time error. - * - * Use this template to implement SFINAE-style (Substitution Failure Is not An - * Error) requirements. For example, you might use it to impose a restriction - * on a template parameter: - * - * template - * class PodVector // vector optimized to store POD (memcpy-able) types - * { - * EnableIf::value, T>::Type* vector; - * size_t length; - * ... - * }; - */ -template -struct EnableIf -{}; - -template -struct EnableIf -{ - typedef T Type; -}; - -/** - * Conditional selects a class between two, depending on a given boolean value. - * - * mozilla::Conditional::Type is A; - * mozilla::Conditional::Type is B; - */ -template -struct Conditional -{ - typedef A Type; -}; - -template -struct Conditional -{ - typedef B Type; -}; - -} /* namespace mozilla */ - -#endif /* mozilla_TypeTraits_h */ diff --git a/onlineupdate/source/libmar/inc/mozilla/Types.h b/onlineupdate/source/libmar/inc/mozilla/Types.h deleted file mode 100644 index 9d1e34b6d1d6..000000000000 --- a/onlineupdate/source/libmar/inc/mozilla/Types.h +++ /dev/null @@ -1,134 +0,0 @@ -/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* vim: set ts=8 sts=2 et sw=2 tw=80: */ -/* This Source Code Form is subject to the terms of the Mozilla Public - * 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/. */ - -/* mfbt foundational types and macros. */ - -#ifndef mozilla_Types_h -#define mozilla_Types_h - -/* - * This header must be valid C and C++, includable by code embedding either - * SpiderMonkey or Gecko. - */ - -/* Expose all types and size_t. */ -#include -#include - -/* Implement compiler and linker macros needed for APIs. */ - -/* - * MOZ_EXPORT is used to declare and define a symbol or type which is externally - * visible to users of the current library. It encapsulates various decorations - * needed to properly export the method's symbol. - * - * api.h: - * extern MOZ_EXPORT int MeaningOfLife(void); - * extern MOZ_EXPORT int LuggageCombination; - * - * api.c: - * int MeaningOfLife(void) { return 42; } - * int LuggageCombination = 12345; - * - * If you are merely sharing a method across files, just use plain |extern|. - * These macros are designed for use by library interfaces -- not for normal - * methods or data used cross-file. - */ -#if defined(_WIN32) -# define MOZ_EXPORT __declspec(dllexport) -#else /* Unix */ -# ifdef HAVE_VISIBILITY_ATTRIBUTE -# define MOZ_EXPORT __attribute__((visibility("default"))) -# elif defined(__SUNPRO_C) || defined(__SUNPRO_CC) -# define MOZ_EXPORT __global -# else -# define MOZ_EXPORT /* nothing */ -# endif -#endif - - -/* - * Whereas implementers use MOZ_EXPORT to declare and define library symbols, - * users use MOZ_IMPORT_API and MOZ_IMPORT_DATA to access them. Most often the - * implementer of the library will expose an API macro which expands to either - * the export or import version of the macro, depending upon the compilation - * mode. - */ -#ifdef _WIN32 -# if defined(__MWERKS__) -# define MOZ_IMPORT_API /* nothing */ -# else -# define MOZ_IMPORT_API __declspec(dllimport) -# endif -#else -# define MOZ_IMPORT_API MOZ_EXPORT -#endif - -#if defined(_WIN32) && !defined(__MWERKS__) -# define MOZ_IMPORT_DATA __declspec(dllimport) -#else -# define MOZ_IMPORT_DATA MOZ_EXPORT -#endif - -/* - * Consistent with the above comment, the MFBT_API and MFBT_DATA macros expose - * export mfbt declarations when building mfbt, and they expose import mfbt - * declarations when using mfbt. - */ -#if defined(IMPL_MFBT) -# define MFBT_API MOZ_EXPORT -# define MFBT_DATA MOZ_EXPORT -#else - /* - * On linux mozglue is linked in the program and we link libxul.so with - * -z,defs. Normally that causes the linker to reject undefined references in - * libxul.so, but as a loophole it allows undefined references to weak - * symbols. We add the weak attribute to the import version of the MFBT API - * macros to exploit this. - */ -# if defined(MOZ_GLUE_IN_PROGRAM) && !defined(MOZILLA_XPCOMRT_API) -# define MFBT_API __attribute__((weak)) MOZ_IMPORT_API -# define MFBT_DATA __attribute__((weak)) MOZ_IMPORT_DATA -# else -# define MFBT_API MOZ_IMPORT_API -# define MFBT_DATA MOZ_IMPORT_DATA -# endif -#endif - -/* - * C symbols in C++ code must be declared immediately within |extern "C"| - * blocks. However, in C code, they need not be declared specially. This - * difference is abstracted behind the MOZ_BEGIN_EXTERN_C and MOZ_END_EXTERN_C - * macros, so that the user need not know whether he is being used in C or C++ - * code. - * - * MOZ_BEGIN_EXTERN_C - * - * extern MOZ_EXPORT int MostRandomNumber(void); - * ...other declarations... - * - * MOZ_END_EXTERN_C - * - * This said, it is preferable to just use |extern "C"| in C++ header files for - * its greater clarity. - */ -#ifdef __cplusplus -# define MOZ_BEGIN_EXTERN_C extern "C" { -# define MOZ_END_EXTERN_C } -#else -# define MOZ_BEGIN_EXTERN_C -# define MOZ_END_EXTERN_C -#endif - -/* - * GCC's typeof is available when decltype is not. - */ -#if defined(__GNUC__) && defined(__cplusplus) && \ - !defined(__GXX_EXPERIMENTAL_CXX0X__) && __cplusplus < 201103L -# define decltype __typeof__ -#endif - -#endif /* mozilla_Types_h */ diff --git a/onlineupdate/source/libmar/inc/mozilla/nsTraceRefcnt.h b/onlineupdate/source/libmar/inc/mozilla/nsTraceRefcnt.h deleted file mode 100644 index c5b1de7e806a..000000000000 --- a/onlineupdate/source/libmar/inc/mozilla/nsTraceRefcnt.h +++ /dev/null @@ -1,67 +0,0 @@ -/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* vim: set ts=8 sts=2 et sw=2 tw=80: */ -/* This Source Code Form is subject to the terms of the Mozilla Public - * 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/. */ -#ifndef nsTraceRefcnt_h___ -#define nsTraceRefcnt_h___ - -#include // for FILE -#include "nscore.h" - -class nsTraceRefcnt -{ -public: - static void Shutdown(); - - enum StatisticsType { - ALL_STATS, - NEW_STATS - }; - - static nsresult DumpStatistics(StatisticsType aType = ALL_STATS, - FILE* aOut = 0); - - static void ResetStatistics(); - - static void DemangleSymbol(const char* aSymbol, char* aBuffer, int aBufLen); - - static void WalkTheStack(FILE* aStream); - - /** - * This is a variant of |WalkTheStack| that uses |CodeAddressService| to cache - * the results of |NS_DescribeCodeAddress|. If |WalkTheStackCached| is being - * called frequently, it will be a few orders of magnitude faster than - * |WalkTheStack|. However, the cache uses a lot of memory, which can cause - * OOM crashes. Therefore, this should only be used for things like refcount - * logging which walk the stack extremely frequently. - */ - static void WalkTheStackCached(FILE* aStream); - - /** - * Tell nsTraceRefcnt whether refcounting, allocation, and destruction - * activity is legal. This is used to trigger assertions for any such - * activity that occurs because of static constructors or destructors. - */ - static void SetActivityIsLegal(bool aLegal); -}; - -#define NS_TRACE_REFCNT_CONTRACTID "@mozilla.org/xpcom/trace-refcnt;1" -#define NS_TRACE_REFCNT_CID \ -{ /* e3e7511e-a395-4924-94b1-d527861cded4 */ \ - 0xe3e7511e, \ - 0xa395, \ - 0x4924, \ - {0x94, 0xb1, 0xd5, 0x27, 0x86, 0x1c, 0xde, 0xd4} \ -} \ - -//////////////////////////////////////////////////////////////////////////////// -// And now for that utility that you've all been asking for... - -extern "C" void -NS_MeanAndStdDev(double aNumberOfValues, - double aSumOfValues, double aSumOfSquaredValues, - double* aMeanResult, double* aStdDevResult); - -//////////////////////////////////////////////////////////////////////////////// -#endif diff --git a/onlineupdate/source/libmar/sign/mar_sign.c b/onlineupdate/source/libmar/sign/mar_sign.c index e14d16945747..ecca5f25f9a6 100644 --- a/onlineupdate/source/libmar/sign/mar_sign.c +++ b/onlineupdate/source/libmar/sign/mar_sign.c @@ -13,9 +13,9 @@ #include #include #include -#include "mar_private.h" -#include "mar_cmdline.h" -#include "mar.h" +#include +#include +#include #include "cryptox.h" #ifndef _WIN32 #include diff --git a/onlineupdate/source/libmar/src/mar.h b/onlineupdate/source/libmar/src/mar.h deleted file mode 100644 index 0e21efb920a5..000000000000 --- a/onlineupdate/source/libmar/src/mar.h +++ /dev/null @@ -1,198 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* vim:set ts=2 sw=2 sts=2 et cindent: */ -/* This Source Code Form is subject to the terms of the Mozilla Public - * 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/. */ - -#ifndef MAR_H__ -#define MAR_H__ - -#include "mozilla/Assertions.h" -#include - -#ifdef __cplusplus -extern "C" { -#endif - -/* We have a MAX_SIGNATURES limit so that an invalid MAR will never - * waste too much of either updater's or signmar's time. - * It is also used at various places internally and will affect memory usage. - * If you want to increase this value above 9 then you need to adjust parsing - * code in tool/mar.c. -*/ -#define MAX_SIGNATURES 8 -#ifdef __cplusplus -static_assert(MAX_SIGNATURES <= 9, "too many signatures"); -#else -MOZ_STATIC_ASSERT(MAX_SIGNATURES <= 9, "too many signatures"); -#endif - -struct ProductInformationBlock { - const char *MARChannelID; - const char *productVersion; -}; - -/** - * The MAR item data structure. - */ -typedef struct MarItem_ { - struct MarItem_ *next; /* private field */ - uint32_t offset; /* offset into archive */ - uint32_t length; /* length of data in bytes */ - uint32_t flags; /* contains file mode bits */ - char name[1]; /* file path */ -} MarItem; - -#define TABLESIZE 256 - -struct MarFile_ { - FILE *fp; - MarItem *item_table[TABLESIZE]; -}; - -typedef struct MarFile_ MarFile; - -/** - * Signature of callback function passed to mar_enum_items. - * @param mar The MAR file being visited. - * @param item The MAR item being visited. - * @param data The data parameter passed by the caller of mar_enum_items. - * @return A non-zero value to stop enumerating. - */ -typedef int (* MarItemCallback)(MarFile *mar, const MarItem *item, void *data); - -/** - * Open a MAR file for reading. - * @param path Specifies the path to the MAR file to open. This path must - * be compatible with fopen. - * @return NULL if an error occurs. - */ -MarFile *mar_open(const char *path); - -#ifdef _WIN32 -MarFile *mar_wopen(const wchar_t *path); -#endif - -/** - * Close a MAR file that was opened using mar_open. - * @param mar The MarFile object to close. - */ -void mar_close(MarFile *mar); - -/** - * Find an item in the MAR file by name. - * @param mar The MarFile object to query. - * @param item The name of the item to query. - * @return A const reference to a MAR item or NULL if not found. - */ -const MarItem *mar_find_item(MarFile *mar, const char *item); - -/** - * Enumerate all MAR items via callback function. - * @param mar The MAR file to enumerate. - * @param callback The function to call for each MAR item. - * @param data A caller specified value that is passed along to the - * callback function. - * @return 0 if the enumeration ran to completion. Otherwise, any - * non-zero return value from the callback is returned. - */ -int mar_enum_items(MarFile *mar, MarItemCallback callback, void *data); - -/** - * Read from MAR item at given offset up to bufsize bytes. - * @param mar The MAR file to read. - * @param item The MAR item to read. - * @param offset The byte offset relative to the start of the item. - * @param buf A pointer to a buffer to copy the data into. - * @param bufsize The length of the buffer to copy the data into. - * @return The number of bytes written or a negative value if an - * error occurs. - */ -int mar_read(MarFile *mar, const MarItem *item, int offset, char *buf, - int bufsize); - -/** - * Create a MAR file from a set of files. - * @param dest The path to the file to create. This path must be - * compatible with fopen. - * @param numfiles The number of files to store in the archive. - * @param files The list of null-terminated file paths. Each file - * path must be compatible with fopen. - * @param infoBlock The information to store in the product information block. - * @return A non-zero value if an error occurs. - */ -int mar_create(const char *dest, - int numfiles, - char **files, - struct ProductInformationBlock *infoBlock); - -/** - * Extract a MAR file to the current working directory. - * @param path The path to the MAR file to extract. This path must be - * compatible with fopen. - * @return A non-zero value if an error occurs. - */ -int mar_extract(const char *path); - -#define MAR_MAX_CERT_SIZE (16*1024) // Way larger than necessary - -/* Read the entire file (not a MAR file) into a newly-allocated buffer. - * This function does not write to stderr. Instead, the caller should - * write whatever error messages it sees fit. The caller must free the returned - * buffer using free(). - * - * @param filePath The path to the file that should be read. - * @param maxSize The maximum valid file size. - * @param data On success, *data will point to a newly-allocated buffer - * with the file's contents in it. - * @param size On success, *size will be the size of the created buffer. - * - * @return 0 on success, -1 on error - */ -int mar_read_entire_file(const char * filePath, - uint32_t maxSize, - /*out*/ const uint8_t * *data, - /*out*/ uint32_t *size); - -/** - * Verifies a MAR file by verifying each signature with the corresponding - * certificate. That is, the first signature will be verified using the first - * certificate given, the second signature will be verified using the second - * certificate given, etc. The signature count must exactly match the number of - * certificates given, and all signature verifications must succeed. - * We do not check that the certificate was issued by any trusted authority. - * We assume it to be self-signed. We do not check whether the certificate - * is valid for this usage. - * - * @param mar The already opened MAR file. - * @param certData Pointer to the first element in an array of certificate - * file data. - * @param certDataSizes Pointer to the first element in an array for size of - * the cert data. - * @param certCount The number of elements in certData and certDataSizes - * @return 0 on success - * a negative number if there was an error - * a positive number if the signature does not verify - */ -int mar_verify_signatures(MarFile *mar, - const uint8_t * const *certData, - const uint32_t *certDataSizes, - uint32_t certCount); - -/** - * Reads the product info block from the MAR file's additional block section. - * The caller is responsible for freeing the fields in infoBlock - * if the return is successful. - * - * @param infoBlock Out parameter for where to store the result to - * @return 0 on success, -1 on failure -*/ -int -mar_read_product_info_block(MarFile *mar, - struct ProductInformationBlock *infoBlock); - -#ifdef __cplusplus -} -#endif - -#endif /* MAR_H__ */ diff --git a/onlineupdate/source/libmar/src/mar_cmdline.h b/onlineupdate/source/libmar/src/mar_cmdline.h deleted file mode 100644 index ef6867f06fc3..000000000000 --- a/onlineupdate/source/libmar/src/mar_cmdline.h +++ /dev/null @@ -1,110 +0,0 @@ -/* This Source Code Form is subject to the terms of the Mozilla Public - * 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/. */ - -#ifndef MAR_CMDLINE_H__ -#define MAR_CMDLINE_H__ - -/* We use NSPR here just to import the definition of uint32_t */ - -#ifdef __cplusplus -extern "C" { -#endif - -struct ProductInformationBlock; - -/** - * Determines MAR file information. - * - * @param path The path of the MAR file to check. - * @param hasSignatureBlock Optional out parameter specifying if the MAR - * file has a signature block or not. - * @param numSignatures Optional out parameter for storing the number - * of signatures in the MAR file. - * @param hasAdditionalBlocks Optional out parameter specifying if the MAR - * file has additional blocks or not. - * @param offsetAdditionalBlocks Optional out parameter for the offset to the - * first additional block. Value is only valid if - * hasAdditionalBlocks is not equal to 0. - * @param numAdditionalBlocks Optional out parameter for the number of - * additional blocks. Value is only valid if - * has_additional_blocks is not equal to 0. - * @return 0 on success and non-zero on failure. - */ -int get_mar_file_info(const char *path, - int *hasSignatureBlock, - uint32_t *numSignatures, - int *hasAdditionalBlocks, - uint32_t *offsetAdditionalBlocks, - uint32_t *numAdditionalBlocks); - -/** - * Reads the product info block from the MAR file's additional block section. - * The caller is responsible for freeing the fields in infoBlock - * if the return is successful. - * - * @param infoBlock Out parameter for where to store the result to - * @return 0 on success, -1 on failure -*/ -int -read_product_info_block(char *path, - struct ProductInformationBlock *infoBlock); - -/** - * Refreshes the product information block with the new information. - * The input MAR must not be signed or the function call will fail. - * - * @param path The path to the MAR file whose product info block - * should be refreshed. - * @param infoBlock Out parameter for where to store the result to - * @return 0 on success, -1 on failure -*/ -int -refresh_product_info_block(const char *path, - struct ProductInformationBlock *infoBlock); - -/** - * Writes out a copy of the MAR at src but with the signature block stripped. - * - * @param src The path of the source MAR file - * @param dest The path of the MAR file to write out that - has no signature block - * @return 0 on success - * -1 on error -*/ -int -strip_signature_block(const char *src, const char * dest); - -/** - * Extracts a signature from a MAR file, base64 encodes it, and writes it out - * - * @param src The path of the source MAR file - * @param sigIndex The index of the signature to extract - * @param dest The path of file to write the signature to - * @return 0 on success - * -1 on error -*/ -int -extract_signature(const char *src, uint32_t sigIndex, const char * dest); - -/** - * Imports a base64 encoded signature into a MAR file - * - * @param src The path of the source MAR file - * @param sigIndex The index of the signature to import - * @param base64SigFile A file which contains the signature to import - * @param dest The path of the destination MAR file with replaced signature - * @return 0 on success - * -1 on error -*/ -int -import_signature(const char *src, - uint32_t sigIndex, - const char * base64SigFile, - const char *dest); - -#ifdef __cplusplus -} -#endif - -#endif /* MAR_CMDLINE_H__ */ diff --git a/onlineupdate/source/libmar/src/mar_create.c b/onlineupdate/source/libmar/src/mar_create.c index 4e4e2b4058c2..660c82511354 100644 --- a/onlineupdate/source/libmar/src/mar_create.c +++ b/onlineupdate/source/libmar/src/mar_create.c @@ -9,9 +9,9 @@ #include #include #include -#include "mar_private.h" -#include "mar_cmdline.h" -#include "mar.h" +#include +#include +#include #ifdef _WIN32 #include diff --git a/onlineupdate/source/libmar/src/mar_extract.c b/onlineupdate/source/libmar/src/mar_extract.c index 75cbd645f296..11e570242fd0 100644 --- a/onlineupdate/source/libmar/src/mar_extract.c +++ b/onlineupdate/source/libmar/src/mar_extract.c @@ -9,8 +9,8 @@ #include #include #include -#include "mar_private.h" -#include "mar.h" +#include +#include #ifdef _WIN32 #include diff --git a/onlineupdate/source/libmar/src/mar_private.h b/onlineupdate/source/libmar/src/mar_private.h deleted file mode 100644 index a770998da6fe..000000000000 --- a/onlineupdate/source/libmar/src/mar_private.h +++ /dev/null @@ -1,79 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* vim:set ts=2 sw=2 sts=2 et cindent: */ -/* This Source Code Form is subject to the terms of the Mozilla Public - * 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/. */ - -#ifndef MAR_PRIVATE_H__ -#define MAR_PRIVATE_H__ - -#include "limits.h" -#include "mozilla/Assertions.h" -#include - -#define BLOCKSIZE 4096 -#define ROUND_UP(n, incr) (((n) / (incr) + 1) * (incr)) - -#define MAR_ID "MAR1" -#define MAR_ID_SIZE 4 - -/* The signature block comes directly after the header block - which is 16 bytes */ -#define SIGNATURE_BLOCK_OFFSET 16 - -/* Make sure the file is less than 500MB. We do this to protect against - invalid MAR files. */ -#define MAX_SIZE_OF_MAR_FILE ((int64_t)524288000) - -/* Existing code makes assumptions that the file size is - smaller than LONG_MAX. */ -MOZ_STATIC_ASSERT(MAX_SIZE_OF_MAR_FILE < ((int64_t)LONG_MAX), - "max mar file size is too big"); - -/* We store at most the size up to the signature block + 4 - bytes per BLOCKSIZE bytes */ -MOZ_STATIC_ASSERT(sizeof(BLOCKSIZE) < \ - (SIGNATURE_BLOCK_OFFSET + sizeof(uint32_t)), - "BLOCKSIZE is too big"); - -/* The maximum size of any signature supported by current and future - implementations of the signmar program. */ -#define MAX_SIGNATURE_LENGTH 2048 - -/* Each additional block has a unique ID. - The product information block has an ID of 1. */ -#define PRODUCT_INFO_BLOCK_ID 1 - -#define MAR_ITEM_SIZE(namelen) (3*sizeof(uint32_t) + (namelen) + 1) - -/* Product Information Block (PIB) constants */ -#define PIB_MAX_MAR_CHANNEL_ID_SIZE 63 -#define PIB_MAX_PRODUCT_VERSION_SIZE 31 - -/* The mar program is compiled as a host bin so we don't have access to NSPR at - runtime. For that reason we use ntohl, htonl, and define HOST_TO_NETWORK64 - instead of the NSPR equivalents. */ -#ifdef _WIN32 -#include -#define ftello _ftelli64 -#define fseeko _fseeki64 -#else -#define _FILE_OFFSET_BITS 64 -#include -#include -#endif - -#include - -#define HOST_TO_NETWORK64(x) ( \ - ((((uint64_t) x) & 0xFF) << 56) | \ - ((((uint64_t) x) >> 8) & 0xFF) << 48) | \ - (((((uint64_t) x) >> 16) & 0xFF) << 40) | \ - (((((uint64_t) x) >> 24) & 0xFF) << 32) | \ - (((((uint64_t) x) >> 32) & 0xFF) << 24) | \ - (((((uint64_t) x) >> 40) & 0xFF) << 16) | \ - (((((uint64_t) x) >> 48) & 0xFF) << 8) | \ - (((uint64_t) x) >> 56) -#define NETWORK_TO_HOST64 HOST_TO_NETWORK64 - -#endif /* MAR_PRIVATE_H__ */ diff --git a/onlineupdate/source/libmar/src/mar_read.c b/onlineupdate/source/libmar/src/mar_read.c index 0ed8c6be6ea9..8ce3cfe0fc13 100644 --- a/onlineupdate/source/libmar/src/mar_read.c +++ b/onlineupdate/source/libmar/src/mar_read.c @@ -8,8 +8,8 @@ #include #include #include -#include "mar_private.h" -#include "mar.h" +#include +#include #ifdef _WIN32 #include diff --git a/onlineupdate/source/libmar/tool/mar.c b/onlineupdate/source/libmar/tool/mar.c index dadb8d25b98a..dba07ac10467 100644 --- a/onlineupdate/source/libmar/tool/mar.c +++ b/onlineupdate/source/libmar/tool/mar.c @@ -7,8 +7,8 @@ #include #include #include -#include "mar.h" -#include "mar_cmdline.h" +#include +#include #ifdef _WIN32 #include diff --git a/onlineupdate/source/libmar/verify/mar_verify.c b/onlineupdate/source/libmar/verify/mar_verify.c index 74eb36935102..bfe3b52768d3 100644 --- a/onlineupdate/source/libmar/verify/mar_verify.c +++ b/onlineupdate/source/libmar/verify/mar_verify.c @@ -14,8 +14,8 @@ #include #include #include -#include "mar_private.h" -#include "mar.h" +#include +#include #include "cryptox.h" int diff --git a/onlineupdate/source/update/inc/mozilla/Assertions.h b/onlineupdate/source/update/inc/mozilla/Assertions.h deleted file mode 100644 index 5669091bbb8e..000000000000 --- a/onlineupdate/source/update/inc/mozilla/Assertions.h +++ /dev/null @@ -1,503 +0,0 @@ -/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* vim: set ts=8 sts=2 et sw=2 tw=80: */ -/* This Source Code Form is subject to the terms of the Mozilla Public - * 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/. */ - -/* Implementations of runtime and static assertion macros for C and C++. */ - -#ifndef mozilla_Assertions_h -#define mozilla_Assertions_h - -#if defined(MOZILLA_INTERNAL_API) && defined(__cplusplus) -#define MOZ_DUMP_ASSERTION_STACK -#endif - -#include "mozilla/Attributes.h" -#include "mozilla/Compiler.h" -#include "mozilla/Likely.h" -#include "mozilla/MacroArgs.h" -#ifdef MOZ_DUMP_ASSERTION_STACK -#include "nsTraceRefcnt.h" -#endif - -#include -#include -#include -#ifdef _WIN32 - /* - * TerminateProcess and GetCurrentProcess are defined in , which - * further depends on . We hardcode these few definitions manually - * because those headers clutter the global namespace with a significant - * number of undesired macros and symbols. - */ -# ifdef __cplusplus -extern "C" { -# endif -__declspec(dllimport) int __stdcall -TerminateProcess(void* hProcess, unsigned int uExitCode); -__declspec(dllimport) void* __stdcall GetCurrentProcess(void); -# ifdef __cplusplus -} -# endif -#else -# include -#endif -#ifdef ANDROID -# include -#endif - -/* - * MOZ_STATIC_ASSERT may be used to assert a condition *at compile time* in C. - * In C++11, static_assert is provided by the compiler to the same effect. - * This can be useful when you make certain assumptions about what must hold for - * optimal, or even correct, behavior. For example, you might assert that the - * size of a struct is a multiple of the target architecture's word size: - * - * struct S { ... }; - * // C - * MOZ_STATIC_ASSERT(sizeof(S) % sizeof(size_t) == 0, - * "S should be a multiple of word size for efficiency"); - * // C++11 - * static_assert(sizeof(S) % sizeof(size_t) == 0, - * "S should be a multiple of word size for efficiency"); - * - * This macro can be used in any location where both an extern declaration and a - * typedef could be used. - */ -#ifndef __cplusplus - /* - * Some of the definitions below create an otherwise-unused typedef. This - * triggers compiler warnings with some versions of gcc, so mark the typedefs - * as permissibly-unused to disable the warnings. - */ -# if defined(__GNUC__) -# define MOZ_STATIC_ASSERT_UNUSED_ATTRIBUTE __attribute__((unused)) -# else -# define MOZ_STATIC_ASSERT_UNUSED_ATTRIBUTE /* nothing */ -# endif -# define MOZ_STATIC_ASSERT_GLUE1(x, y) x##y -# define MOZ_STATIC_ASSERT_GLUE(x, y) MOZ_STATIC_ASSERT_GLUE1(x, y) -# if defined(__SUNPRO_CC) - /* - * The Sun Studio C++ compiler is buggy when declaring, inside a function, - * another extern'd function with an array argument whose length contains a - * sizeof, triggering the error message "sizeof expression not accepted as - * size of array parameter". This bug (6688515, not public yet) would hit - * defining moz_static_assert as a function, so we always define an extern - * array for Sun Studio. - * - * We include the line number in the symbol name in a best-effort attempt - * to avoid conflicts (see below). - */ -# define MOZ_STATIC_ASSERT(cond, reason) \ - extern char MOZ_STATIC_ASSERT_GLUE(moz_static_assert, __LINE__)[(cond) ? 1 : -1] -# elif defined(__COUNTER__) - /* - * If there was no preferred alternative, use a compiler-agnostic version. - * - * Note that the non-__COUNTER__ version has a bug in C++: it can't be used - * in both |extern "C"| and normal C++ in the same translation unit. (Alas - * |extern "C"| isn't allowed in a function.) The only affected compiler - * we really care about is gcc 4.2. For that compiler and others like it, - * we include the line number in the function name to do the best we can to - * avoid conflicts. These should be rare: a conflict would require use of - * MOZ_STATIC_ASSERT on the same line in separate files in the same - * translation unit, *and* the uses would have to be in code with - * different linkage, *and* the first observed use must be in C++-linkage - * code. - */ -# define MOZ_STATIC_ASSERT(cond, reason) \ - typedef int MOZ_STATIC_ASSERT_GLUE(moz_static_assert, __COUNTER__)[(cond) ? 1 : -1] MOZ_STATIC_ASSERT_UNUSED_ATTRIBUTE -# else -# define MOZ_STATIC_ASSERT(cond, reason) \ - extern void MOZ_STATIC_ASSERT_GLUE(moz_static_assert, __LINE__)(int arg[(cond) ? 1 : -1]) MOZ_STATIC_ASSERT_UNUSED_ATTRIBUTE -# endif - -#define MOZ_STATIC_ASSERT_IF(cond, expr, reason) MOZ_STATIC_ASSERT(!(cond) || (expr), reason) -#else -#define MOZ_STATIC_ASSERT_IF(cond, expr, reason) static_assert(!(cond) || (expr), reason) -#endif - -#ifdef __cplusplus -extern "C" { -#endif - -/* - * Prints |aStr| as an assertion failure (using aFilename and aLine as the - * location of the assertion) to the standard debug-output channel. - * - * Usually you should use MOZ_ASSERT or MOZ_CRASH instead of this method. This - * method is primarily for internal use in this header, and only secondarily - * for use in implementing release-build assertions. - */ -static MOZ_COLD MOZ_ALWAYS_INLINE void -MOZ_ReportAssertionFailure(const char* aStr, const char* aFilename, int aLine) - MOZ_PRETEND_NORETURN_FOR_STATIC_ANALYSIS -{ -#ifdef ANDROID - __android_log_print(ANDROID_LOG_FATAL, "MOZ_Assert", - "Assertion failure: %s, at %s:%d\n", - aStr, aFilename, aLine); -#else - fprintf(stderr, "Assertion failure: %s, at %s:%d\n", aStr, aFilename, aLine); -#if defined (MOZ_DUMP_ASSERTION_STACK) && !defined(MOZILLA_XPCOMRT_API) - nsTraceRefcnt::WalkTheStack(stderr); -#endif - fflush(stderr); -#endif -} - -static MOZ_COLD MOZ_ALWAYS_INLINE void -MOZ_ReportCrash(const char* aStr, const char* aFilename, int aLine) - MOZ_PRETEND_NORETURN_FOR_STATIC_ANALYSIS -{ -#ifdef ANDROID - __android_log_print(ANDROID_LOG_FATAL, "MOZ_CRASH", - "Hit MOZ_CRASH(%s) at %s:%d\n", aStr, aFilename, aLine); -#else - fprintf(stderr, "Hit MOZ_CRASH(%s) at %s:%d\n", aStr, aFilename, aLine); -#if defined(MOZ_DUMP_ASSERTION_STACK) && !defined(MOZILLA_XPCOMRT_API) - nsTraceRefcnt::WalkTheStack(stderr); -#endif - fflush(stderr); -#endif -} - -/** - * MOZ_REALLY_CRASH is used in the implementation of MOZ_CRASH(). You should - * call MOZ_CRASH instead. - */ -#if defined(_MSC_VER) - /* - * On MSVC use the __debugbreak compiler intrinsic, which produces an inline - * (not nested in a system function) breakpoint. This distinctively invokes - * Breakpad without requiring system library symbols on all stack-processing - * machines, as a nested breakpoint would require. - * - * We use TerminateProcess with the exit code aborting would generate - * because we don't want to invoke atexit handlers, destructors, library - * unload handlers, and so on when our process might be in a compromised - * state. - * - * We don't use abort() because it'd cause Windows to annoyingly pop up the - * process error dialog multiple times. See bug 345118 and bug 426163. - * - * We follow TerminateProcess() with a call to MOZ_NoReturn() so that the - * compiler doesn't hassle us to provide a return statement after a - * MOZ_REALLY_CRASH() call. - * - * (Technically these are Windows requirements, not MSVC requirements. But - * practically you need MSVC for debugging, and we only ship builds created - * by MSVC, so doing it this way reduces complexity.) - */ - -__declspec(noreturn) __inline void MOZ_NoReturn() {} - -# ifdef __cplusplus -# define MOZ_REALLY_CRASH() \ - do { \ - ::__debugbreak(); \ - *((volatile int*) NULL) = __LINE__; \ - ::TerminateProcess(::GetCurrentProcess(), 3); \ - ::MOZ_NoReturn(); \ - } while (0) -# else -# define MOZ_REALLY_CRASH() \ - do { \ - __debugbreak(); \ - *((volatile int*) NULL) = __LINE__; \ - TerminateProcess(GetCurrentProcess(), 3); \ - MOZ_NoReturn(); \ - } while (0) -# endif -#else -# ifdef __cplusplus -# define MOZ_REALLY_CRASH() \ - do { \ - *((volatile int*) NULL) = __LINE__; \ - ::abort(); \ - } while (0) -# else -# define MOZ_REALLY_CRASH() \ - do { \ - *((volatile int*) NULL) = __LINE__; \ - abort(); \ - } while (0) -# endif -#endif - -/* - * MOZ_CRASH([explanation-string]) crashes the program, plain and simple, in a - * Breakpad-compatible way, in both debug and release builds. - * - * MOZ_CRASH is a good solution for "handling" failure cases when you're - * unwilling or unable to handle them more cleanly -- for OOM, for likely memory - * corruption, and so on. It's also a good solution if you need safe behavior - * in release builds as well as debug builds. But if the failure is one that - * should be debugged and fixed, MOZ_ASSERT is generally preferable. - * - * The optional explanation-string, if provided, must be a string literal - * explaining why we're crashing. This argument is intended for use with - * MOZ_CRASH() calls whose rationale is non-obvious; don't use it if it's - * obvious why we're crashing. - * - * If we're a DEBUG build and we crash at a MOZ_CRASH which provides an - * explanation-string, we print the string to stderr. Otherwise, we don't - * print anything; this is because we want MOZ_CRASH to be 100% safe in release - * builds, and it's hard to print to stderr safely when memory might have been - * corrupted. - */ -#ifndef DEBUG -# define MOZ_CRASH(...) MOZ_REALLY_CRASH() -#else -# define MOZ_CRASH(...) \ - do { \ - MOZ_ReportCrash("" __VA_ARGS__, __FILE__, __LINE__); \ - MOZ_REALLY_CRASH(); \ - } while (0) -#endif - -#ifdef __cplusplus -} /* extern "C" */ -#endif - -/* - * MOZ_ASSERT(expr [, explanation-string]) asserts that |expr| must be truthy in - * debug builds. If it is, execution continues. Otherwise, an error message - * including the expression and the explanation-string (if provided) is printed, - * an attempt is made to invoke any existing debugger, and execution halts. - * MOZ_ASSERT is fatal: no recovery is possible. Do not assert a condition - * which can correctly be falsy. - * - * The optional explanation-string, if provided, must be a string literal - * explaining the assertion. It is intended for use with assertions whose - * correctness or rationale is non-obvious, and for assertions where the "real" - * condition being tested is best described prosaically. Don't provide an - * explanation if it's not actually helpful. - * - * // No explanation needed: pointer arguments often must not be NULL. - * MOZ_ASSERT(arg); - * - * // An explanation can be helpful to explain exactly how we know an - * // assertion is valid. - * MOZ_ASSERT(state == WAITING_FOR_RESPONSE, - * "given that and , we must have..."); - * - * // Or it might disambiguate multiple identical (save for their location) - * // assertions of the same expression. - * MOZ_ASSERT(getSlot(PRIMITIVE_THIS_SLOT).isUndefined(), - * "we already set [[PrimitiveThis]] for this Boolean object"); - * MOZ_ASSERT(getSlot(PRIMITIVE_THIS_SLOT).isUndefined(), - * "we already set [[PrimitiveThis]] for this String object"); - * - * MOZ_ASSERT has no effect in non-debug builds. It is designed to catch bugs - * *only* during debugging, not "in the field". If you want the latter, use - * MOZ_RELEASE_ASSERT, which applies to non-debug builds as well. - * - * MOZ_DIAGNOSTIC_ASSERT works like MOZ_RELEASE_ASSERT in Nightly/Aurora and - * MOZ_ASSERT in Beta/Release - use this when a condition is potentially rare - * enough to require real user testing to hit, but is not security-sensitive. - * This can cause user pain, so use it sparingly. If a MOZ_DIAGNOSTIC_ASSERT - * is firing, it should promptly be converted to a MOZ_ASSERT while the failure - * is being investigated, rather than letting users suffer. - */ - -/* - * Implement MOZ_VALIDATE_ASSERT_CONDITION_TYPE, which is used to guard against - * accidentally passing something unintended in lieu of an assertion condition. - */ - -#ifdef __cplusplus -# include "mozilla/TypeTraits.h" -namespace mozilla { -namespace detail { - -template -struct IsFunction -{ - static const bool value = false; -}; - -template -struct IsFunction -{ - static const bool value = true; -}; - -template -struct AssertionConditionType -{ - typedef typename RemoveReference::Type ValueT; - static_assert(!IsArray::value, - "Expected boolean assertion condition, got an array or a " - "string!"); - static_assert(!IsFunction::value, - "Expected boolean assertion condition, got a function! Did " - "you intend to call that function?"); - static_assert(!IsFloatingPoint::value, - "It's often a bad idea to assert that a floating-point number " - "is nonzero, because such assertions tend to intermittently " - "fail. Shouldn't your code gracefully handle this case instead " - "of asserting? Anyway, if you really want to do that, write an " - "explicit boolean condition, like !!x or x!=0."); - - static const bool isValid = true; -}; - -} // namespace detail -} // namespace mozilla -# define MOZ_VALIDATE_ASSERT_CONDITION_TYPE(x) \ - static_assert(mozilla::detail::AssertionConditionType::isValid, \ - "invalid assertion condition") -#else -# define MOZ_VALIDATE_ASSERT_CONDITION_TYPE(x) -#endif - -/* First the single-argument form. */ -#define MOZ_ASSERT_HELPER1(expr) \ - do { \ - MOZ_VALIDATE_ASSERT_CONDITION_TYPE(expr); \ - if (MOZ_UNLIKELY(!(expr))) { \ - MOZ_ReportAssertionFailure(#expr, __FILE__, __LINE__); \ - MOZ_REALLY_CRASH(); \ - } \ - } while (0) -/* Now the two-argument form. */ -#define MOZ_ASSERT_HELPER2(expr, explain) \ - do { \ - MOZ_VALIDATE_ASSERT_CONDITION_TYPE(expr); \ - if (MOZ_UNLIKELY(!(expr))) { \ - MOZ_ReportAssertionFailure(#expr " (" explain ")", __FILE__, __LINE__); \ - MOZ_REALLY_CRASH(); \ - } \ - } while (0) - -#define MOZ_RELEASE_ASSERT_GLUE(a, b) a b -#define MOZ_RELEASE_ASSERT(...) \ - MOZ_RELEASE_ASSERT_GLUE( \ - MOZ_PASTE_PREFIX_AND_ARG_COUNT(MOZ_ASSERT_HELPER, __VA_ARGS__), \ - (__VA_ARGS__)) - -#ifdef DEBUG -# define MOZ_ASSERT(...) MOZ_RELEASE_ASSERT(__VA_ARGS__) -#else -# define MOZ_ASSERT(...) do { } while (0) -#endif /* DEBUG */ - -#ifdef RELEASE_BUILD -# define MOZ_DIAGNOSTIC_ASSERT MOZ_ASSERT -#else -# define MOZ_DIAGNOSTIC_ASSERT MOZ_RELEASE_ASSERT -#endif - -/* - * MOZ_ASSERT_IF(cond1, cond2) is equivalent to MOZ_ASSERT(cond2) if cond1 is - * true. - * - * MOZ_ASSERT_IF(isPrime(num), num == 2 || isOdd(num)); - * - * As with MOZ_ASSERT, MOZ_ASSERT_IF has effect only in debug builds. It is - * designed to catch bugs during debugging, not "in the field". - */ -#ifdef DEBUG -# define MOZ_ASSERT_IF(cond, expr) \ - do { \ - if (cond) { \ - MOZ_ASSERT(expr); \ - } \ - } while (0) -#else -# define MOZ_ASSERT_IF(cond, expr) do { } while (0) -#endif - -/* - * MOZ_ASSUME_UNREACHABLE_MARKER() expands to an expression which states that - * it is undefined behavior for execution to reach this point. No guarantees - * are made about what will happen if this is reached at runtime. Most code - * should use MOZ_MAKE_COMPILER_ASSUME_IS_UNREACHABLE because it has extra - * asserts. - */ -#if defined(__clang__) || defined(__GNUC__) -# define MOZ_ASSUME_UNREACHABLE_MARKER() __builtin_unreachable() -#elif defined(_MSC_VER) -# define MOZ_ASSUME_UNREACHABLE_MARKER() __assume(0) -#else -# ifdef __cplusplus -# define MOZ_ASSUME_UNREACHABLE_MARKER() ::abort() -# else -# define MOZ_ASSUME_UNREACHABLE_MARKER() abort() -# endif -#endif - -/* - * MOZ_MAKE_COMPILER_ASSUME_IS_UNREACHABLE([reason]) tells the compiler that it - * can assume that the macro call cannot be reached during execution. This lets - * the compiler generate better-optimized code under some circumstances, at the - * expense of the program's behavior being undefined if control reaches the - * MOZ_MAKE_COMPILER_ASSUME_IS_UNREACHABLE. - * - * In Gecko, you probably should not use this macro outside of performance- or - * size-critical code, because it's unsafe. If you don't care about code size - * or performance, you should probably use MOZ_ASSERT or MOZ_CRASH. - * - * SpiderMonkey is a different beast, and there it's acceptable to use - * MOZ_MAKE_COMPILER_ASSUME_IS_UNREACHABLE more widely. - * - * Note that MOZ_MAKE_COMPILER_ASSUME_IS_UNREACHABLE is noreturn, so it's valid - * not to return a value following a MOZ_MAKE_COMPILER_ASSUME_IS_UNREACHABLE - * call. - * - * Example usage: - * - * enum ValueType { - * VALUE_STRING, - * VALUE_INT, - * VALUE_FLOAT - * }; - * - * int ptrToInt(ValueType type, void* value) { - * { - * // We know for sure that type is either INT or FLOAT, and we want this - * // code to run as quickly as possible. - * switch (type) { - * case VALUE_INT: - * return *(int*) value; - * case VALUE_FLOAT: - * return (int) *(float*) value; - * default: - * MOZ_MAKE_COMPILER_ASSUME_IS_UNREACHABLE("Unexpected ValueType"); - * } - * } - */ - -/* - * Unconditional assert in debug builds for (assumed) unreachable code paths - * that have a safe return without crashing in release builds. - */ -#define MOZ_ASSERT_UNREACHABLE(reason) \ - MOZ_ASSERT(false, "MOZ_ASSERT_UNREACHABLE: " reason) - -#define MOZ_MAKE_COMPILER_ASSUME_IS_UNREACHABLE(reason) \ - do { \ - MOZ_ASSERT_UNREACHABLE(reason); \ - MOZ_ASSUME_UNREACHABLE_MARKER(); \ - } while (0) - -/* - * MOZ_ALWAYS_TRUE(expr) and MOZ_ALWAYS_FALSE(expr) always evaluate the provided - * expression, in debug builds and in release builds both. Then, in debug - * builds only, the value of the expression is asserted either true or false - * using MOZ_ASSERT. - */ -#ifdef DEBUG -# define MOZ_ALWAYS_TRUE(expr) MOZ_ASSERT((expr)) -# define MOZ_ALWAYS_FALSE(expr) MOZ_ASSERT(!(expr)) -#else -# define MOZ_ALWAYS_TRUE(expr) ((void)(expr)) -# define MOZ_ALWAYS_FALSE(expr) ((void)(expr)) -#endif - -#undef MOZ_DUMP_ASSERTION_STACK - -#endif /* mozilla_Assertions_h */ diff --git a/onlineupdate/source/update/inc/mozilla/Attributes.h b/onlineupdate/source/update/inc/mozilla/Attributes.h deleted file mode 100644 index 1eac3a802bd5..000000000000 --- a/onlineupdate/source/update/inc/mozilla/Attributes.h +++ /dev/null @@ -1,481 +0,0 @@ -/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* vim: set ts=8 sts=2 et sw=2 tw=80: */ -/* This Source Code Form is subject to the terms of the Mozilla Public - * 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/. */ - -/* Implementations of various class and method modifier attributes. */ - -#ifndef mozilla_Attributes_h -#define mozilla_Attributes_h - -#include "mozilla/Compiler.h" - -/* - * MOZ_ALWAYS_INLINE is a macro which expands to tell the compiler that the - * method decorated with it must be inlined, even if the compiler thinks - * otherwise. This is only a (much) stronger version of the inline hint: - * compilers are not guaranteed to respect it (although they're much more likely - * to do so). - * - * The MOZ_ALWAYS_INLINE_EVEN_DEBUG macro is yet stronger. It tells the - * compiler to inline even in DEBUG builds. It should be used very rarely. - */ -#if defined(_MSC_VER) -# define MOZ_ALWAYS_INLINE_EVEN_DEBUG __forceinline -#elif defined(__GNUC__) -# define MOZ_ALWAYS_INLINE_EVEN_DEBUG __attribute__((always_inline)) inline -#else -# define MOZ_ALWAYS_INLINE_EVEN_DEBUG inline -#endif - -#if !defined(DEBUG) -# define MOZ_ALWAYS_INLINE MOZ_ALWAYS_INLINE_EVEN_DEBUG -#elif defined(_MSC_VER) && !defined(__cplusplus) -# define MOZ_ALWAYS_INLINE __inline -#else -# define MOZ_ALWAYS_INLINE inline -#endif - -#if defined(_MSC_VER) -/* - * g++ requires -std=c++0x or -std=gnu++0x to support C++11 functionality - * without warnings (functionality used by the macros below). These modes are - * detectable by checking whether __GXX_EXPERIMENTAL_CXX0X__ is defined or, more - * standardly, by checking whether __cplusplus has a C++11 or greater value. - * Current versions of g++ do not correctly set __cplusplus, so we check both - * for forward compatibility. - * - * Even though some versions of MSVC support explicit conversion operators, we - * don't indicate support for them here, due to - * http://stackoverflow.com/questions/20498142/visual-studio-2013-explicit-keyword-bug - */ -# define MOZ_HAVE_NEVER_INLINE __declspec(noinline) -# define MOZ_HAVE_NORETURN __declspec(noreturn) -# ifdef __clang__ - /* clang-cl probably supports constexpr and explicit conversions. */ -# if __has_extension(cxx_constexpr) -# define MOZ_HAVE_CXX11_CONSTEXPR -# endif -# if __has_extension(cxx_explicit_conversions) -# define MOZ_HAVE_EXPLICIT_CONVERSION -# endif -# endif -#elif defined(__clang__) - /* - * Per Clang documentation, "Note that marketing version numbers should not - * be used to check for language features, as different vendors use different - * numbering schemes. Instead, use the feature checking macros." - */ -# ifndef __has_extension -# define __has_extension __has_feature /* compatibility, for older versions of clang */ -# endif -# if __has_extension(cxx_constexpr) -# define MOZ_HAVE_CXX11_CONSTEXPR -# endif -# if __has_extension(cxx_explicit_conversions) -# define MOZ_HAVE_EXPLICIT_CONVERSION -# endif -# if __has_attribute(noinline) -# define MOZ_HAVE_NEVER_INLINE __attribute__((noinline)) -# endif -# if __has_attribute(noreturn) -# define MOZ_HAVE_NORETURN __attribute__((noreturn)) -# endif -#elif defined(__GNUC__) -# if defined(__GXX_EXPERIMENTAL_CXX0X__) || (defined(__cplusplus) && __cplusplus >= 201103L) -# define MOZ_HAVE_CXX11_CONSTEXPR -# if MOZ_GCC_VERSION_AT_LEAST(4, 8, 0) -# define MOZ_HAVE_CXX11_CONSTEXPR_IN_TEMPLATES -# endif -# define MOZ_HAVE_EXPLICIT_CONVERSION -# endif -# define MOZ_HAVE_NEVER_INLINE __attribute__((noinline)) -# define MOZ_HAVE_NORETURN __attribute__((noreturn)) -#endif - -/* - * When built with clang analyzer (a.k.a scan-build), define MOZ_HAVE_NORETURN - * to mark some false positives - */ -#ifdef __clang_analyzer__ -# if __has_extension(attribute_analyzer_noreturn) -# define MOZ_HAVE_ANALYZER_NORETURN __attribute__((analyzer_noreturn)) -# endif -#endif - -/* - * The MOZ_CONSTEXPR specifier declares that a C++11 compiler can evaluate a - * function at compile time. A constexpr function cannot examine any values - * except its arguments and can have no side effects except its return value. - * The MOZ_CONSTEXPR_VAR specifier tells a C++11 compiler that a variable's - * value may be computed at compile time. It should be preferred to just - * marking variables as MOZ_CONSTEXPR because if the compiler does not support - * constexpr it will fall back to making the variable const, and some compilers - * do not accept variables being marked both const and constexpr. - */ -#ifdef MOZ_HAVE_CXX11_CONSTEXPR -# define MOZ_CONSTEXPR constexpr -# define MOZ_CONSTEXPR_VAR constexpr -# ifdef MOZ_HAVE_CXX11_CONSTEXPR_IN_TEMPLATES -# define MOZ_CONSTEXPR_TMPL constexpr -# else -# define MOZ_CONSTEXPR_TMPL -# endif -#else -# define MOZ_CONSTEXPR /* no support */ -# define MOZ_CONSTEXPR_VAR const -# define MOZ_CONSTEXPR_TMPL -#endif - -/* - * MOZ_EXPLICIT_CONVERSION is a specifier on a type conversion - * overloaded operator that declares that a C++11 compiler should restrict - * this operator to allow only explicit type conversions, disallowing - * implicit conversions. - * - * Example: - * - * template - * class Ptr - * { - * T* mPtr; - * MOZ_EXPLICIT_CONVERSION operator bool() const - * { - * return mPtr != nullptr; - * } - * }; - * - */ -#ifdef MOZ_HAVE_EXPLICIT_CONVERSION -# define MOZ_EXPLICIT_CONVERSION explicit -#else -# define MOZ_EXPLICIT_CONVERSION /* no support */ -#endif - -/* - * MOZ_NEVER_INLINE is a macro which expands to tell the compiler that the - * method decorated with it must never be inlined, even if the compiler would - * otherwise choose to inline the method. Compilers aren't absolutely - * guaranteed to support this, but most do. - */ -#if defined(MOZ_HAVE_NEVER_INLINE) -# define MOZ_NEVER_INLINE MOZ_HAVE_NEVER_INLINE -#else -# define MOZ_NEVER_INLINE /* no support */ -#endif - -/* - * MOZ_NORETURN, specified at the start of a function declaration, indicates - * that the given function does not return. (The function definition does not - * need to be annotated.) - * - * MOZ_NORETURN void abort(const char* msg); - * - * This modifier permits the compiler to optimize code assuming a call to such a - * function will never return. It also enables the compiler to avoid spurious - * warnings about not initializing variables, or about any other seemingly-dodgy - * operations performed after the function returns. - * - * This modifier does not affect the corresponding function's linking behavior. - */ -#if defined(MOZ_HAVE_NORETURN) -# define MOZ_NORETURN MOZ_HAVE_NORETURN -#else -# define MOZ_NORETURN /* no support */ -#endif - -/** - * MOZ_COLD tells the compiler that a function is "cold", meaning infrequently - * executed. This may lead it to optimize for size more aggressively than speed, - * or to allocate the body of the function in a distant part of the text segment - * to help keep it from taking up unnecessary icache when it isn't in use. - * - * Place this attribute at the very beginning of a function definition. For - * example, write - * - * MOZ_COLD int foo(); - * - * or - * - * MOZ_COLD int foo() { return 42; } - */ -#if defined(__GNUC__) || defined(__clang__) -# define MOZ_COLD __attribute__ ((cold)) -#else -# define MOZ_COLD -#endif - -/** - * MOZ_NONNULL tells the compiler that some of the arguments to a function are - * known to be non-null. The arguments are a list of 1-based argument indexes - * identifying arguments which are known to be non-null. - * - * Place this attribute at the very beginning of a function definition. For - * example, write - * - * MOZ_NONNULL(1, 2) int foo(char *p, char *q); - */ -#if defined(__GNUC__) || defined(__clang__) -# define MOZ_NONNULL(...) __attribute__ ((nonnull(__VA_ARGS__))) -#else -# define MOZ_NONNULL(...) -#endif - -/* - * MOZ_PRETEND_NORETURN_FOR_STATIC_ANALYSIS, specified at the end of a function - * declaration, indicates that for the purposes of static analysis, this - * function does not return. (The function definition does not need to be - * annotated.) - * - * MOZ_ReportCrash(const char* s, const char* file, int ln) - * MOZ_PRETEND_NORETURN_FOR_STATIC_ANALYSIS - * - * Some static analyzers, like scan-build from clang, can use this information - * to eliminate false positives. From the upstream documentation of scan-build: - * "This attribute is useful for annotating assertion handlers that actually - * can return, but for the purpose of using the analyzer we want to pretend - * that such functions do not return." - * - */ -#if defined(MOZ_HAVE_ANALYZER_NORETURN) -# define MOZ_PRETEND_NORETURN_FOR_STATIC_ANALYSIS MOZ_HAVE_ANALYZER_NORETURN -#else -# define MOZ_PRETEND_NORETURN_FOR_STATIC_ANALYSIS /* no support */ -#endif - -/* - * MOZ_ASAN_BLACKLIST is a macro to tell AddressSanitizer (a compile-time - * instrumentation shipped with Clang and GCC) to not instrument the annotated - * function. Furthermore, it will prevent the compiler from inlining the - * function because inlining currently breaks the blacklisting mechanism of - * AddressSanitizer. - */ -#if defined(__has_feature) -# if __has_feature(address_sanitizer) -# define MOZ_HAVE_ASAN_BLACKLIST -# endif -#elif defined(__GNUC__) -# if defined(__SANITIZE_ADDRESS__) -# define MOZ_HAVE_ASAN_BLACKLIST -# endif -#endif - -#if defined(MOZ_HAVE_ASAN_BLACKLIST) -# define MOZ_ASAN_BLACKLIST MOZ_NEVER_INLINE __attribute__((no_sanitize_address)) -#else -# define MOZ_ASAN_BLACKLIST /* nothing */ -#endif - -/* - * MOZ_TSAN_BLACKLIST is a macro to tell ThreadSanitizer (a compile-time - * instrumentation shipped with Clang) to not instrument the annotated function. - * Furthermore, it will prevent the compiler from inlining the function because - * inlining currently breaks the blacklisting mechanism of ThreadSanitizer. - */ -#if defined(__has_feature) -# if __has_feature(thread_sanitizer) -# define MOZ_TSAN_BLACKLIST MOZ_NEVER_INLINE __attribute__((no_sanitize_thread)) -# else -# define MOZ_TSAN_BLACKLIST /* nothing */ -# endif -#else -# define MOZ_TSAN_BLACKLIST /* nothing */ -#endif - -/** - * MOZ_ALLOCATOR tells the compiler that the function it marks returns either a - * "fresh", "pointer-free" block of memory, or nullptr. "Fresh" means that the - * block is not pointed to by any other reachable pointer in the program. - * "Pointer-free" means that the block contains no pointers to any valid object - * in the program. It may be initialized with other (non-pointer) values. - * - * Placing this attribute on appropriate functions helps GCC analyze pointer - * aliasing more accurately in their callers. - * - * GCC warns if a caller ignores the value returned by a function marked with - * MOZ_ALLOCATOR: it is hard to imagine cases where dropping the value returned - * by a function that meets the criteria above would be intentional. - * - * Place this attribute after the argument list and 'this' qualifiers of a - * function definition. For example, write - * - * void *my_allocator(size_t) MOZ_ALLOCATOR; - * - * or - * - * void *my_allocator(size_t bytes) MOZ_ALLOCATOR { ... } - */ -#if defined(__GNUC__) || defined(__clang__) -# define MOZ_ALLOCATOR __attribute__ ((malloc, warn_unused_result)) -#else -# define MOZ_ALLOCATOR -#endif - -/** - * MOZ_WARN_UNUSED_RESULT tells the compiler to emit a warning if a function's - * return value is not used by the caller. - * - * Place this attribute at the very beginning of a function definition. For - * example, write - * - * MOZ_WARN_UNUSED_RESULT int foo(); - * - * or - * - * MOZ_WARN_UNUSED_RESULT int foo() { return 42; } - */ -#if defined(__GNUC__) || defined(__clang__) -# define MOZ_WARN_UNUSED_RESULT __attribute__ ((warn_unused_result)) -#else -# define MOZ_WARN_UNUSED_RESULT -#endif - -#ifdef __cplusplus - -/* - * The following macros are attributes that support the static analysis plugin - * included with Mozilla, and will be implemented (when such support is enabled) - * as C++11 attributes. Since such attributes are legal pretty much everywhere - * and have subtly different semantics depending on their placement, the - * following is a guide on where to place the attributes. - * - * Attributes that apply to a struct or class precede the name of the class: - * (Note that this is different from the placement of final for classes!) - * - * class MOZ_CLASS_ATTRIBUTE SomeClass {}; - * - * Attributes that apply to functions follow the parentheses and const - * qualifiers but precede final, override and the function body: - * - * void DeclaredFunction() MOZ_FUNCTION_ATTRIBUTE; - * void SomeFunction() MOZ_FUNCTION_ATTRIBUTE {} - * void PureFunction() const MOZ_FUNCTION_ATTRIBUTE = 0; - * void OverriddenFunction() MOZ_FUNCTION_ATTIRBUTE override; - * - * Attributes that apply to variables or parameters follow the variable's name: - * - * int variable MOZ_VARIABLE_ATTRIBUTE; - * - * Attributes that apply to types follow the type name: - * - * typedef int MOZ_TYPE_ATTRIBUTE MagicInt; - * int MOZ_TYPE_ATTRIBUTE someVariable; - * int* MOZ_TYPE_ATTRIBUTE magicPtrInt; - * int MOZ_TYPE_ATTRIBUTE* ptrToMagicInt; - * - * Attributes that apply to statements precede the statement: - * - * MOZ_IF_ATTRIBUTE if (x == 0) - * MOZ_DO_ATTRIBUTE do { } while (0); - * - * Attributes that apply to labels precede the label: - * - * MOZ_LABEL_ATTRIBUTE target: - * goto target; - * MOZ_CASE_ATTRIBUTE case 5: - * MOZ_DEFAULT_ATTRIBUTE default: - * - * The static analyses that are performed by the plugin are as follows: - * - * MOZ_MUST_OVERRIDE: Applies to all C++ member functions. All immediate - * subclasses must provide an exact override of this method; if a subclass - * does not override this method, the compiler will emit an error. This - * attribute is not limited to virtual methods, so if it is applied to a - * nonvirtual method and the subclass does not provide an equivalent - * definition, the compiler will emit an error. - * MOZ_STACK_CLASS: Applies to all classes. Any class with this annotation is - * expected to live on the stack, so it is a compile-time error to use it, or - * an array of such objects, as a global or static variable, or as the type of - * a new expression (unless placement new is being used). If a member of - * another class uses this class, or if another class inherits from this - * class, then it is considered to be a stack class as well, although this - * attribute need not be provided in such cases. - * MOZ_NONHEAP_CLASS: Applies to all classes. Any class with this annotation is - * expected to live on the stack or in static storage, so it is a compile-time - * error to use it, or an array of such objects, as the type of a new - * expression (unless placement new is being used). If a member of another - * class uses this class, or if another class inherits from this class, then - * it is considered to be a non-heap class as well, although this attribute - * need not be provided in such cases. - * MOZ_ONLY_USED_TO_AVOID_STATIC_CONSTRUCTORS: Applies to all classes that are - * intended to prevent introducing static initializers. This attribute - * currently makes it a compile-time error to instantiate these classes - * anywhere other than at the global scope, or as a static member of a class. - * MOZ_TRIVIAL_CTOR_DTOR: Applies to all classes that must have both a trivial - * constructor and a trivial destructor. Setting this attribute on a class - * makes it a compile-time error for that class to get a non-trivial - * constructor or destructor for any reason. - * MOZ_HEAP_ALLOCATOR: Applies to any function. This indicates that the return - * value is allocated on the heap, and will as a result check such allocations - * during MOZ_STACK_CLASS and MOZ_NONHEAP_CLASS annotation checking. - * MOZ_IMPLICIT: Applies to constructors. Implicit conversion constructors - * are disallowed by default unless they are marked as MOZ_IMPLICIT. This - * attribute must be used for constructors which intend to provide implicit - * conversions. - * MOZ_NO_ARITHMETIC_EXPR_IN_ARGUMENT: Applies to functions. Makes it a compile - * time error to pass arithmetic expressions on variables to the function. - * MOZ_OWNING_REF: Applies to declarations of pointer types. This attribute - * tells the compiler that the raw pointer is a strong reference, and that - * property is somehow enforced by the code. This can make the compiler - * ignore these pointers when validating the usage of pointers otherwise. - * MOZ_NON_OWNING_REF: Applies to declarations of pointer types. This attribute - * tells the compiler that the raw pointer is a weak reference, and that - * property is somehow enforced by the code. This can make the compiler - * ignore these pointers when validating the usage of pointers otherwise. - * MOZ_UNSAFE_REF: Applies to declarations of pointer types. This attribute - * should be used for non-owning references that can be unsafe, and their - * safety needs to be validated through code inspection. The string argument - * passed to this macro documents the safety conditions. - * MOZ_NO_ADDREF_RELEASE_ON_RETURN: Applies to function declarations. Makes it - * a compile time error to call AddRef or Release on the return value of a - * function. This is intended to be used with operator->() of our smart - * pointer classes to ensure that the refcount of an object wrapped in a - * smart pointer is not manipulated directly. - */ -#ifdef MOZ_CLANG_PLUGIN -# define MOZ_MUST_OVERRIDE __attribute__((annotate("moz_must_override"))) -# define MOZ_STACK_CLASS __attribute__((annotate("moz_stack_class"))) -# define MOZ_NONHEAP_CLASS __attribute__((annotate("moz_nonheap_class"))) -# define MOZ_TRIVIAL_CTOR_DTOR __attribute__((annotate("moz_trivial_ctor_dtor"))) -# ifdef DEBUG - /* in debug builds, these classes do have non-trivial constructors. */ -# define MOZ_ONLY_USED_TO_AVOID_STATIC_CONSTRUCTORS __attribute__((annotate("moz_global_class"))) -# else -# define MOZ_ONLY_USED_TO_AVOID_STATIC_CONSTRUCTORS __attribute__((annotate("moz_global_class"))) \ - MOZ_TRIVIAL_CTOR_DTOR -# endif -# define MOZ_IMPLICIT __attribute__((annotate("moz_implicit"))) -# define MOZ_NO_ARITHMETIC_EXPR_IN_ARGUMENT __attribute__((annotate("moz_no_arith_expr_in_arg"))) -# define MOZ_OWNING_REF __attribute__((annotate("moz_strong_ref"))) -# define MOZ_NON_OWNING_REF __attribute__((annotate("moz_weak_ref"))) -# define MOZ_UNSAFE_REF(reason) __attribute__((annotate("moz_strong_ref"))) -# define MOZ_NO_ADDREF_RELEASE_ON_RETURN __attribute__((annotate("moz_no_addref_release_on_return"))) -/* - * It turns out that clang doesn't like void func() __attribute__ {} without a - * warning, so use pragmas to disable the warning. This code won't work on GCC - * anyways, so the warning is safe to ignore. - */ -# define MOZ_HEAP_ALLOCATOR \ - _Pragma("clang diagnostic push") \ - _Pragma("clang diagnostic ignored \"-Wgcc-compat\"") \ - __attribute__((annotate("moz_heap_allocator"))) \ - _Pragma("clang diagnostic pop") -#else -# define MOZ_MUST_OVERRIDE /* nothing */ -# define MOZ_STACK_CLASS /* nothing */ -# define MOZ_NONHEAP_CLASS /* nothing */ -# define MOZ_TRIVIAL_CTOR_DTOR /* nothing */ -# define MOZ_ONLY_USED_TO_AVOID_STATIC_CONSTRUCTORS /* nothing */ -# define MOZ_IMPLICIT /* nothing */ -# define MOZ_NO_ARITHMETIC_EXPR_IN_ARGUMENT /* nothing */ -# define MOZ_HEAP_ALLOCATOR /* nothing */ -# define MOZ_OWNING_REF /* nothing */ -# define MOZ_NON_OWNING_REF /* nothing */ -# define MOZ_UNSAFE_REF(reason) /* nothing */ -# define MOZ_NO_ADDREF_RELEASE_ON_RETURN /* nothing */ -#endif /* MOZ_CLANG_PLUGIN */ - -#endif /* __cplusplus */ - -#endif /* mozilla_Attributes_h */ diff --git a/onlineupdate/source/update/inc/mozilla/Char16.h b/onlineupdate/source/update/inc/mozilla/Char16.h deleted file mode 100644 index f07494f7f47f..000000000000 --- a/onlineupdate/source/update/inc/mozilla/Char16.h +++ /dev/null @@ -1,239 +0,0 @@ -/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* vim: set ts=8 sts=2 et sw=2 tw=80: */ -/* This Source Code Form is subject to the terms of the Mozilla Public - * 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/. */ - -/* Implements a UTF-16 character type. */ - -#ifndef mozilla_Char16_h -#define mozilla_Char16_h - -#ifdef __cplusplus - -/* - * C++11 introduces a char16_t type and support for UTF-16 string and character - * literals. C++11's char16_t is a distinct builtin type. Technically, char16_t - * is a 16-bit code unit of a Unicode code point, not a "character". - */ - -#if defined(_MSC_VER) && _MSC_VER < 1900 - /* - * C++11 says char16_t is a distinct builtin type, but Windows's yvals.h - * typedefs char16_t as an unsigned short prior to MSVC 2015, which - * implemented C++11's distinct char16_t type. We would like to alias - * char16_t to Windows's 16-bit wchar_t so we can declare UTF-16 literals as - * constant expressions (and pass char16_t pointers to Windows APIs). We - * #define _CHAR16T here in order to prevent yvals.h from overriding our - * char16_t typedefs, which we set to wchar_t for C++ code. - * - * In addition, #defining _CHAR16T will prevent yvals.h from defining a - * char32_t type, so we have to undo that damage here and provide our own, - * which is identical to the yvals.h type. - */ -# define MOZ_UTF16_HELPER(s) L##s -# define _CHAR16T -typedef wchar_t char16_t; -typedef unsigned int char32_t; -#else - /* C++11 has a builtin char16_t type. */ -# define MOZ_UTF16_HELPER(s) u##s - /** - * This macro is used to distinguish when char16_t would be a distinct - * typedef from wchar_t. - */ -# define MOZ_CHAR16_IS_NOT_WCHAR -# ifdef WIN32 -# define MOZ_USE_CHAR16_WRAPPER -# endif -#endif - -#ifdef MOZ_USE_CHAR16_WRAPPER -# include - /** - * Win32 API extensively uses wchar_t, which is represented by a separated - * builtin type than char16_t per spec. It's not the case for MSVC prior to - * MSVC 2015, but other compilers follow the spec. We want to mix wchar_t and - * char16_t on Windows builds. This class is supposed to make it easier. It - * stores char16_t const pointer, but provides implicit casts for wchar_t as - * well. On other platforms, we simply use - * |typedef const char16_t* char16ptr_t|. Here, we want to make the class as - * similar to this typedef, including providing some casts that are allowed - * by the typedef. - */ -class char16ptr_t -{ -private: - const char16_t* mPtr; - static_assert(sizeof(char16_t) == sizeof(wchar_t), - "char16_t and wchar_t sizes differ"); - -public: - char16ptr_t(const char16_t* aPtr) : mPtr(aPtr) {} - char16ptr_t(const wchar_t* aPtr) : - mPtr(reinterpret_cast(aPtr)) - {} - - /* Without this, nullptr assignment would be ambiguous. */ - constexpr char16ptr_t(decltype(nullptr)) : mPtr(nullptr) {} - - operator const char16_t*() const - { - return mPtr; - } - operator const wchar_t*() const - { - return reinterpret_cast(mPtr); - } - operator const void*() const - { - return mPtr; - } - operator bool() const - { - return mPtr != nullptr; - } - operator std::wstring() const - { - return std::wstring(static_cast(*this)); - } - - /* Explicit cast operators to allow things like (char16_t*)str. */ - explicit operator char16_t*() const - { - return const_cast(mPtr); - } - explicit operator wchar_t*() const - { - return const_cast(static_cast(*this)); - } - explicit operator int() const - { - return reinterpret_cast(mPtr); - } - explicit operator unsigned int() const - { - return reinterpret_cast(mPtr); - } - explicit operator long() const - { - return reinterpret_cast(mPtr); - } - explicit operator unsigned long() const - { - return reinterpret_cast(mPtr); - } - explicit operator long long() const - { - return reinterpret_cast(mPtr); - } - explicit operator unsigned long long() const - { - return reinterpret_cast(mPtr); - } - - /** - * Some Windows API calls accept BYTE* but require that data actually be - * WCHAR*. Supporting this requires explicit operators to support the - * requisite explicit casts. - */ - explicit operator const char*() const - { - return reinterpret_cast(mPtr); - } - explicit operator const unsigned char*() const - { - return reinterpret_cast(mPtr); - } - explicit operator unsigned char*() const - { - return - const_cast(reinterpret_cast(mPtr)); - } - explicit operator void*() const - { - return const_cast(mPtr); - } - - /* Some operators used on pointers. */ - char16_t operator[](size_t aIndex) const - { - return mPtr[aIndex]; - } - bool operator==(const char16ptr_t& aOther) const - { - return mPtr == aOther.mPtr; - } - bool operator==(decltype(nullptr)) const - { - return mPtr == nullptr; - } - bool operator!=(const char16ptr_t& aOther) const - { - return mPtr != aOther.mPtr; - } - bool operator!=(decltype(nullptr)) const - { - return mPtr != nullptr; - } - char16ptr_t operator+(int aValue) const - { - return char16ptr_t(mPtr + aValue); - } - char16ptr_t operator+(unsigned int aValue) const - { - return char16ptr_t(mPtr + aValue); - } - char16ptr_t operator+(long aValue) const - { - return char16ptr_t(mPtr + aValue); - } - char16ptr_t operator+(unsigned long aValue) const - { - return char16ptr_t(mPtr + aValue); - } - char16ptr_t operator+(long long aValue) const - { - return char16ptr_t(mPtr + aValue); - } - char16ptr_t operator+(unsigned long long aValue) const - { - return char16ptr_t(mPtr + aValue); - } - ptrdiff_t operator-(const char16ptr_t& aOther) const - { - return mPtr - aOther.mPtr; - } -}; - -inline decltype((char*)0-(char*)0) -operator-(const char16_t* aX, const char16ptr_t aY) -{ - return aX - static_cast(aY); -} - -#else - -typedef const char16_t* char16ptr_t; - -#endif - -/* - * Macro arguments used in concatenation or stringification won't be expanded. - * Therefore, in order for |MOZ_UTF16(FOO)| to work as expected (which is to - * expand |FOO| before doing whatever |MOZ_UTF16| needs to do to it) a helper - * macro, |MOZ_UTF16_HELPER| needs to be inserted in between to allow the macro - * argument to expand. See "3.10.6 Separate Expansion of Macro Arguments" of the - * CPP manual for a more accurate and precise explanation. - */ -#define MOZ_UTF16(s) MOZ_UTF16_HELPER(s) - -static_assert(sizeof(char16_t) == 2, "Is char16_t type 16 bits?"); -static_assert(char16_t(-1) > char16_t(0), "Is char16_t type unsigned?"); -static_assert(sizeof(MOZ_UTF16('A')) == 2, "Is char literal 16 bits?"); -static_assert(sizeof(MOZ_UTF16("")[0]) == 2, "Is string char 16 bits?"); - -#endif - -#endif /* mozilla_Char16_h */ - diff --git a/onlineupdate/source/update/inc/mozilla/Compiler.h b/onlineupdate/source/update/inc/mozilla/Compiler.h deleted file mode 100644 index 6d6fcbbb19f5..000000000000 --- a/onlineupdate/source/update/inc/mozilla/Compiler.h +++ /dev/null @@ -1,110 +0,0 @@ -/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* vim: set ts=8 sts=2 et sw=2 tw=80: */ -/* This Source Code Form is subject to the terms of the Mozilla Public - * 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/. */ - -/* Various compiler checks. */ - -#ifndef mozilla_Compiler_h -#define mozilla_Compiler_h - -#define MOZ_IS_GCC 0 -#define MOS_IS_MSVC 0 - -#if !defined(__clang__) && defined(__GNUC__) - -# undef MOZ_IS_GCC -# define MOZ_IS_GCC 1 - /* - * This macro should simplify gcc version checking. For example, to check - * for gcc 4.7.1 or later, check `#if MOZ_GCC_VERSION_AT_LEAST(4, 7, 1)`. - */ -# define MOZ_GCC_VERSION_AT_LEAST(major, minor, patchlevel) \ - ((__GNUC__ * 10000 + __GNUC_MINOR__ * 100 + __GNUC_PATCHLEVEL__) \ - >= ((major) * 10000 + (minor) * 100 + (patchlevel))) -# if !MOZ_GCC_VERSION_AT_LEAST(4, 7, 0) -# error "mfbt (and Gecko) require at least gcc 4.7 to build." -# endif - -#elif defined(_MSC_VER) - -# undef MOZ_IS_MSVC -# define MOZ_IS_MSVC 1 - -#endif - -/* - * The situation with standard libraries is a lot worse than with compilers, - * particularly as clang and gcc could end up using one of three or so standard - * libraries, and they may not be up-to-snuff with newer C++11 versions. To - * detect the library, we're going to include cstddef (which is a small header - * which will be transitively included by everybody else at some point) to grab - * the version macros and deduce macros from there. - */ -#ifdef __cplusplus -# include -# ifdef _STLPORT_MAJOR -# define MOZ_USING_STLPORT 1 -# define MOZ_STLPORT_VERSION_AT_LEAST(major, minor, patch) \ - (_STLPORT_VERSION >= ((major) << 8 | (minor) << 4 | (patch))) -# elif defined(_LIBCPP_VERSION) - /* - * libc++, unfortunately, doesn't appear to have useful versioning macros. - * Hopefully, the recommendations of N3694 with respect to standard libraries - * will get applied instead and we won't need to worry about version numbers - * here. - */ -# define MOZ_USING_LIBCXX 1 -# elif defined(__GLIBCXX__) -# define MOZ_USING_LIBSTDCXX 1 - /* - * libstdc++ is also annoying and doesn't give us useful versioning macros - * for the library. If we're using gcc, then assume that libstdc++ matches - * the compiler version. If we're using clang, we're going to have to fake - * major/minor combinations by looking for newly-defined config macros. - */ -# if MOZ_IS_GCC -# define MOZ_LIBSTDCXX_VERSION_AT_LEAST(major, minor, patch) \ - MOZ_GCC_VERSION_AT_LEAST(major, minor, patch) -# elif defined(_GLIBCXX_THROW_OR_ABORT) -# define MOZ_LIBSTDCXX_VERSION_AT_LEAST(major, minor, patch) \ - ((major) < 4 || ((major) == 4 && (minor) <= 8)) -# elif defined(_GLIBCXX_NOEXCEPT) -# define MOZ_LIBSTDCXX_VERSION_AT_LEAST(major, minor, patch) \ - ((major) < 4 || ((major) == 4 && (minor) <= 7)) -# elif defined(_GLIBCXX_USE_DEPRECATED) -# define MOZ_LIBSTDCXX_VERSION_AT_LEAST(major, minor, patch) \ - ((major) < 4 || ((major) == 4 && (minor) <= 6)) -# elif defined(_GLIBCXX_PSEUDO_VISIBILITY) -# define MOZ_LIBSTDCXX_VERSION_AT_LEAST(major, minor, patch) \ - ((major) < 4 || ((major) == 4 && (minor) <= 5)) -# elif defined(_GLIBCXX_BEGIN_EXTERN_C) -# define MOZ_LIBSTDCXX_VERSION_AT_LEAST(major, minor, patch) \ - ((major) < 4 || ((major) == 4 && (minor) <= 4)) -# elif defined(_GLIBCXX_VISIBILITY_ATTR) -# define MOZ_LIBSTDCXX_VERSION_AT_LEAST(major, minor, patch) \ - ((major) < 4 || ((major) == 4 && (minor) <= 3)) -# elif defined(_GLIBCXX_VISIBILITY) -# define MOZ_LIBSTDCXX_VERSION_AT_LEAST(major, minor, patch) \ - ((major) < 4 || ((major) == 4 && (minor) <= 2)) -# else -# error "Your version of libstdc++ is unknown to us and is likely too old." -# endif -# endif - - // Flesh out the defines for everyone else -# ifndef MOZ_USING_STLPORT -# define MOZ_USING_STLPORT 0 -# define MOZ_STLPORT_VERSION_AT_LEAST(major, minor, patch) 0 -# endif -# ifndef MOZ_USING_LIBCXX -# define MOZ_USING_LIBCXX 0 -# endif -# ifndef MOZ_USING_LIBSTDCXX -# define MOZ_USING_LIBSTDCXX 0 -# define MOZ_LIBSTDCXX_VERSION_AT_LEAST(major, minor, patch) 0 -# endif -#endif /* __cplusplus */ - -#endif /* mozilla_Compiler_h */ diff --git a/onlineupdate/source/update/inc/mozilla/Likely.h b/onlineupdate/source/update/inc/mozilla/Likely.h deleted file mode 100644 index 4f2160929544..000000000000 --- a/onlineupdate/source/update/inc/mozilla/Likely.h +++ /dev/null @@ -1,23 +0,0 @@ -/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* vim: set ts=8 sts=2 et sw=2 tw=80: */ -/* This Source Code Form is subject to the terms of the Mozilla Public - * 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/. */ - -/* - * MOZ_LIKELY and MOZ_UNLIKELY macros to hint to the compiler how a - * boolean predicate should be branch-predicted. - */ - -#ifndef mozilla_Likely_h -#define mozilla_Likely_h - -#if defined(__clang__) || defined(__GNUC__) -# define MOZ_LIKELY(x) (__builtin_expect(!!(x), 1)) -# define MOZ_UNLIKELY(x) (__builtin_expect(!!(x), 0)) -#else -# define MOZ_LIKELY(x) (!!(x)) -# define MOZ_UNLIKELY(x) (!!(x)) -#endif - -#endif /* mozilla_Likely_h */ diff --git a/onlineupdate/source/update/inc/mozilla/MacroArgs.h b/onlineupdate/source/update/inc/mozilla/MacroArgs.h deleted file mode 100644 index c8b733821035..000000000000 --- a/onlineupdate/source/update/inc/mozilla/MacroArgs.h +++ /dev/null @@ -1,105 +0,0 @@ -/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* vim: set ts=8 sts=2 et sw=2 tw=80: */ -/* This Source Code Form is subject to the terms of the Mozilla Public - * 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/. */ - -/* - * Implements various macros meant to ease the use of variadic macros. - */ - -#ifndef mozilla_MacroArgs_h -#define mozilla_MacroArgs_h - -/* - * MOZ_PASTE_PREFIX_AND_ARG_COUNT(aPrefix, ...) counts the number of variadic - * arguments and prefixes it with |aPrefix|. For example: - * - * MOZ_PASTE_PREFIX_AND_ARG_COUNT(, foo, 42) expands to 2 - * MOZ_PASTE_PREFIX_AND_ARG_COUNT(A, foo, 42, bar) expands to A3 - * - * You must pass in between 1 and 50 (inclusive) variadic arguments, past - * |aPrefix|. It is not legal to do - * - * MOZ_PASTE_PREFIX_AND_ARG_COUNT(prefix) - * - * (that is, pass in 0 variadic arguments). To ensure that a compile-time - * error occurs when these constraints are violated, use the - * MOZ_STATIC_ASSERT_VALID_ARG_COUNT macro with the same variaidc arguments - * wherever this macro is used. - * - * Passing (__VA_ARGS__, ) rather than simply calling - * MOZ_MACROARGS_ARG_COUNT_HELPER2(__VA_ARGS__, ) very - * carefully tiptoes around a MSVC bug where it improperly expands __VA_ARGS__ - * as a single token in argument lists. For details, see: - * - * http://connect.microsoft.com/VisualStudio/feedback/details/380090/variadic-macro-replacement - * http://cplusplus.co.il/2010/07/17/variadic-macro-to-count-number-of-arguments/#comment-644 - */ -#define MOZ_PASTE_PREFIX_AND_ARG_COUNT(aPrefix, ...) \ - MOZ_MACROARGS_ARG_COUNT_HELPER((__VA_ARGS__, \ - aPrefix##50, aPrefix##49, aPrefix##48, aPrefix##47, aPrefix##46, \ - aPrefix##45, aPrefix##44, aPrefix##43, aPrefix##42, aPrefix##41, \ - aPrefix##40, aPrefix##39, aPrefix##38, aPrefix##37, aPrefix##36, \ - aPrefix##35, aPrefix##34, aPrefix##33, aPrefix##32, aPrefix##31, \ - aPrefix##30, aPrefix##29, aPrefix##28, aPrefix##27, aPrefix##26, \ - aPrefix##25, aPrefix##24, aPrefix##23, aPrefix##22, aPrefix##21, \ - aPrefix##20, aPrefix##19, aPrefix##18, aPrefix##17, aPrefix##16, \ - aPrefix##15, aPrefix##14, aPrefix##13, aPrefix##12, aPrefix##11, \ - aPrefix##10, aPrefix##9, aPrefix##8, aPrefix##7, aPrefix##6, \ - aPrefix##5, aPrefix##4, aPrefix##3, aPrefix##2, aPrefix##1, aPrefix##0)) - -#define MOZ_MACROARGS_ARG_COUNT_HELPER(aArgs) \ - MOZ_MACROARGS_ARG_COUNT_HELPER2 aArgs - -#define MOZ_MACROARGS_ARG_COUNT_HELPER2( \ - a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, \ - a11, a12, a13, a14, a15, a16, a17, a18, a19, a20, \ - a21, a22, a23, a24, a25, a26, a27, a28, a29, a30, \ - a31, a32, a33, a34, a35, a36, a37, a38, a39, a40, \ - a41, a42, a43, a44, a45, a46, a47, a48, a49, a50, \ - a51, ...) a51 - -/* - * MOZ_STATIC_ASSERT_VALID_ARG_COUNT ensures that a compile-time error occurs - * when the argument count constraints of MOZ_PASTE_PREFIX_AND_ARG_COUNT are - * violated. Use this macro wherever MOZ_PASTE_PREFIX_AND_ARG_COUNT is used - * and pass it the same variadic arguments. - * - * This macro employs a few dirty tricks to function. To detect the zero - * argument case, |(__VA_ARGS__)| is stringified, sizeof-ed, and compared to - * what it should be in the absence of arguments. - * - * Detecting too many arguments is a little trickier. With a valid argument - * count and a prefix of 1, MOZ_PASTE_PREFIX_AND_ARG_COUNT expands to e.g. 14. - * With a prefix of 0.0, it expands to e.g. 0.04. If there are too many - * arguments, it expands to the first argument over the limit. If this - * exceeding argument is a number, the assertion will fail as there is no - * number than can simultaneously be both > 10 and == 0. If the exceeding - * argument is not a number, a compile-time error should still occur due to - * the operations performed on it. - */ -#define MOZ_MACROARGS_STRINGIFY_HELPER(x) #x -#define MOZ_STATIC_ASSERT_VALID_ARG_COUNT(...) \ - static_assert( \ - sizeof(MOZ_MACROARGS_STRINGIFY_HELPER((__VA_ARGS__))) != sizeof("()") && \ - (MOZ_PASTE_PREFIX_AND_ARG_COUNT(1, __VA_ARGS__)) > 10 && \ - (int)(MOZ_PASTE_PREFIX_AND_ARG_COUNT(0.0, __VA_ARGS__)) == 0, \ - "MOZ_STATIC_ASSERT_VALID_ARG_COUNT requires 1 to 50 arguments") /* ; */ - -/* - * MOZ_ARGS_AFTER_N expands to its arguments excluding the first |N| - * arguments. For example: - * - * MOZ_ARGS_AFTER_2(a, b, c, d) expands to: c, d - */ -#define MOZ_ARGS_AFTER_1(a1, ...) __VA_ARGS__ -#define MOZ_ARGS_AFTER_2(a1, a2, ...) __VA_ARGS__ - -/* - * MOZ_ARG_N expands to its |N|th argument. - */ -#define MOZ_ARG_1(a1, ...) a1 -#define MOZ_ARG_2(a1, a2, ...) a2 - -#endif /* mozilla_MacroArgs_h */ diff --git a/onlineupdate/source/update/inc/mozilla/Move.h b/onlineupdate/source/update/inc/mozilla/Move.h deleted file mode 100644 index f6d0bfc1ca38..000000000000 --- a/onlineupdate/source/update/inc/mozilla/Move.h +++ /dev/null @@ -1,238 +0,0 @@ -/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* vim: set ts=8 sts=2 et sw=2 tw=80: */ -/* This Source Code Form is subject to the terms of the Mozilla Public - * 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/. */ - -/* C++11-style, but C++98-usable, "move references" implementation. */ - -#ifndef mozilla_Move_h -#define mozilla_Move_h - -#include "mozilla/TypeTraits.h" - -namespace mozilla { - -/* - * "Move" References - * - * Some types can be copied much more efficiently if we know the original's - * value need not be preserved --- that is, if we are doing a "move", not a - * "copy". For example, if we have: - * - * Vector u; - * Vector v(u); - * - * the constructor for v must apply a copy constructor to each element of u --- - * taking time linear in the length of u. However, if we know we will not need u - * any more once v has been initialized, then we could initialize v very - * efficiently simply by stealing u's dynamically allocated buffer and giving it - * to v --- a constant-time operation, regardless of the size of u. - * - * Moves often appear in container implementations. For example, when we append - * to a vector, we may need to resize its buffer. This entails moving each of - * its extant elements from the old, smaller buffer to the new, larger buffer. - * But once the elements have been migrated, we're just going to throw away the - * old buffer; we don't care if they still have their values. So if the vector's - * element type can implement "move" more efficiently than "copy", the vector - * resizing should by all means use a "move" operation. Hash tables should also - * use moves when resizing their internal array as entries are added and - * removed. - * - * The details of the optimization, and whether it's worth applying, vary - * from one type to the next: copying an 'int' is as cheap as moving it, so - * there's no benefit in distinguishing 'int' moves from copies. And while - * some constructor calls for complex types are moves, many really have to - * be copies, and can't be optimized this way. So we need: - * - * 1) a way for a type (like Vector) to announce that it can be moved more - * efficiently than it can be copied, and provide an implementation of that - * move operation; and - * - * 2) a way for a particular invocation of a copy constructor to say that it's - * really a move, not a copy, and that the value of the original isn't - * important afterwards (although it must still be safe to destroy). - * - * If a constructor has a single argument of type 'T&&' (an 'rvalue reference - * to T'), that indicates that it is a 'move constructor'. That's 1). It should - * move, not copy, its argument into the object being constructed. It may leave - * the original in any safely-destructible state. - * - * If a constructor's argument is an rvalue, as in 'C(f(x))' or 'C(x + y)', as - * opposed to an lvalue, as in 'C(x)', then overload resolution will prefer the - * move constructor, if there is one. The 'mozilla::Move' function, defined in - * this file, is an identity function you can use in a constructor invocation to - * make any argument into an rvalue, like this: C(Move(x)). That's 2). (You - * could use any function that works, but 'Move' indicates your intention - * clearly.) - * - * Where we might define a copy constructor for a class C like this: - * - * C(const C& rhs) { ... copy rhs to this ... } - * - * we would declare a move constructor like this: - * - * C(C&& rhs) { .. move rhs to this ... } - * - * And where we might perform a copy like this: - * - * C c2(c1); - * - * we would perform a move like this: - * - * C c2(Move(c1)); - * - * Note that 'T&&' implicitly converts to 'T&'. So you can pass a 'T&&' to an - * ordinary copy constructor for a type that doesn't support a special move - * constructor, and you'll just get a copy. This means that templates can use - * Move whenever they know they won't use the original value any more, even if - * they're not sure whether the type at hand has a specialized move constructor. - * If it doesn't, the 'T&&' will just convert to a 'T&', and the ordinary copy - * constructor will apply. - * - * A class with a move constructor can also provide a move assignment operator. - * A generic definition would run this's destructor, and then apply the move - * constructor to *this's memory. A typical definition: - * - * C& operator=(C&& rhs) { - * MOZ_ASSERT(&rhs != this, "self-moves are prohibited"); - * this->~C(); - * new(this) C(Move(rhs)); - * return *this; - * } - * - * With that in place, one can write move assignments like this: - * - * c2 = Move(c1); - * - * This destroys c2, moves c1's value to c2, and leaves c1 in an undefined but - * destructible state. - * - * As we say, a move must leave the original in a "destructible" state. The - * original's destructor will still be called, so if a move doesn't - * actually steal all its resources, that's fine. We require only that the - * move destination must take on the original's value; and that destructing - * the original must not break the move destination. - * - * (Opinions differ on whether move assignment operators should deal with move - * assignment of an object onto itself. It seems wise to either handle that - * case, or assert that it does not occur.) - * - * Forwarding: - * - * Sometimes we want copy construction or assignment if we're passed an ordinary - * value, but move construction if passed an rvalue reference. For example, if - * our constructor takes two arguments and either could usefully be a move, it - * seems silly to write out all four combinations: - * - * C::C(X& x, Y& y) : x(x), y(y) { } - * C::C(X& x, Y&& y) : x(x), y(Move(y)) { } - * C::C(X&& x, Y& y) : x(Move(x)), y(y) { } - * C::C(X&& x, Y&& y) : x(Move(x)), y(Move(y)) { } - * - * To avoid this, C++11 has tweaks to make it possible to write what you mean. - * The four constructor overloads above can be written as one constructor - * template like so[0]: - * - * template - * C::C(XArg&& x, YArg&& y) : x(Forward(x)), y(Forward(y)) { } - * - * ("'Don't Repeat Yourself'? What's that?") - * - * This takes advantage of two new rules in C++11: - * - * - First, when a function template takes an argument that is an rvalue - * reference to a template argument (like 'XArg&& x' and 'YArg&& y' above), - * then when the argument is applied to an lvalue, the template argument - * resolves to 'T&'; and when it is applied to an rvalue, the template - * argument resolves to 'T'. Thus, in a call to C::C like: - * - * X foo(int); - * Y yy; - * - * C(foo(5), yy) - * - * XArg would resolve to 'X', and YArg would resolve to 'Y&'. - * - * - Second, Whereas C++ used to forbid references to references, C++11 defines - * 'collapsing rules': 'T& &', 'T&& &', and 'T& &&' (that is, any combination - * involving an lvalue reference) now collapse to simply 'T&'; and 'T&& &&' - * collapses to 'T&&'. - * - * Thus, in the call above, 'XArg&&' is 'X&&'; and 'YArg&&' is 'Y& &&', which - * collapses to 'Y&'. Because the arguments are declared as rvalue references - * to template arguments, the lvalue-ness "shines through" where present. - * - * Then, the 'Forward' function --- you must invoke 'Forward' with its type - * argument --- returns an lvalue reference or an rvalue reference to its - * argument, depending on what T is. In our unified constructor definition, that - * means that we'll invoke either the copy or move constructors for x and y, - * depending on what we gave C's constructor. In our call, we'll move 'foo()' - * into 'x', but copy 'yy' into 'y'. - * - * This header file defines Move and Forward in the mozilla namespace. It's up - * to individual containers to annotate moves as such, by calling Move; and it's - * up to individual types to define move constructors and assignment operators - * when valuable. - * - * (C++11 says that the header file should define 'std::move' and - * 'std::forward', which are just like our 'Move' and 'Forward'; but those - * definitions aren't available in that header on all our platforms, so we - * define them ourselves here.) - * - * 0. This pattern is known as "perfect forwarding". Interestingly, it is not - * actually perfect, and it can't forward all possible argument expressions! - * There is a C++11 issue: you can't form a reference to a bit-field. As a - * workaround, assign the bit-field to a local variable and use that: - * - * // C is as above - * struct S { int x : 1; } s; - * C(s.x, 0); // BAD: s.x is a reference to a bit-field, can't form those - * int tmp = s.x; - * C(tmp, 0); // OK: tmp not a bit-field - */ - -/** - * Identical to std::Move(); this is necessary until our stlport supports - * std::move(). - */ -template -inline typename RemoveReference::Type&& -Move(T&& aX) -{ - return static_cast::Type&&>(aX); -} - -/** - * These two overloads are identical to std::forward(); they are necessary until - * our stlport supports std::forward(). - */ -template -inline T&& -Forward(typename RemoveReference::Type& aX) -{ - return static_cast(aX); -} - -template -inline T&& -Forward(typename RemoveReference::Type&& aX) -{ - static_assert(!IsLvalueReference::value, - "misuse of Forward detected! try the other overload"); - return static_cast(aX); -} - -/** Swap |aX| and |aY| using move-construction if possible. */ -template -inline void -Swap(T& aX, T& aY) -{ - T tmp(Move(aX)); - aX = Move(aY); - aY = Move(tmp); -} - -} // namespace mozilla - -#endif /* mozilla_Move_h */ diff --git a/onlineupdate/source/update/inc/mozilla/Pair.h b/onlineupdate/source/update/inc/mozilla/Pair.h deleted file mode 100644 index ad7b86a29c62..000000000000 --- a/onlineupdate/source/update/inc/mozilla/Pair.h +++ /dev/null @@ -1,219 +0,0 @@ -/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* vim: set ts=8 sts=2 et sw=2 tw=80: */ -/* This Source Code Form is subject to the terms of the Mozilla Public - * 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/. */ - -/* A class holding a pair of objects that tries to conserve storage space. */ - -#ifndef mozilla_Pair_h -#define mozilla_Pair_h - -#include "mozilla/Attributes.h" -#include "mozilla/Move.h" -#include "mozilla/TypeTraits.h" - -namespace mozilla { - -namespace detail { - -enum StorageType { AsBase, AsMember }; - -// Optimize storage using the Empty Base Optimization -- that empty base classes -// don't take up space -- to optimize size when one or the other class is -// stateless and can be used as a base class. -// -// The extra conditions on storage for B are necessary so that PairHelper won't -// ambiguously inherit from either A or B, such that one or the other base class -// would be inaccessible. -template::value ? detail::AsBase : detail::AsMember, - detail::StorageType = - IsEmpty::value && !IsBaseOf::value && !IsBaseOf::value - ? detail::AsBase - : detail::AsMember> -struct PairHelper; - -template -struct PairHelper -{ -protected: - template - PairHelper(AArg&& aA, BArg&& aB) - : mFirstA(Forward(aA)), - mSecondB(Forward(aB)) - {} - - A& first() { return mFirstA; } - const A& first() const { return mFirstA; } - B& second() { return mSecondB; } - const B& second() const { return mSecondB; } - - void swap(PairHelper& aOther) - { - Swap(mFirstA, aOther.mFirstA); - Swap(mSecondB, aOther.mSecondB); - } - -private: - A mFirstA; - B mSecondB; -}; - -template -struct PairHelper : private B -{ -protected: - template - PairHelper(AArg&& aA, BArg&& aB) - : B(Forward(aB)), - mFirstA(Forward(aA)) - {} - - A& first() { return mFirstA; } - const A& first() const { return mFirstA; } - B& second() { return *this; } - const B& second() const { return *this; } - - void swap(PairHelper& aOther) - { - Swap(mFirstA, aOther.mFirstA); - Swap(static_cast(*this), static_cast(aOther)); - } - -private: - A mFirstA; -}; - -template -struct PairHelper : private A -{ -protected: - template - PairHelper(AArg&& aA, BArg&& aB) - : A(Forward(aA)), - mSecondB(Forward(aB)) - {} - - A& first() { return *this; } - const A& first() const { return *this; } - B& second() { return mSecondB; } - const B& second() const { return mSecondB; } - - void swap(PairHelper& aOther) - { - Swap(static_cast(*this), static_cast(aOther)); - Swap(mSecondB, aOther.mSecondB); - } - -private: - B mSecondB; -}; - -template -struct PairHelper : private A, private B -{ -protected: - template - PairHelper(AArg&& aA, BArg&& aB) - : A(Forward(aA)), - B(Forward(aB)) - {} - - A& first() { return static_cast(*this); } - const A& first() const { return static_cast(*this); } - B& second() { return static_cast(*this); } - const B& second() const { return static_cast(*this); } - - void swap(PairHelper& aOther) - { - Swap(static_cast(*this), static_cast(aOther)); - Swap(static_cast(*this), static_cast(aOther)); - } -}; - -} // namespace detail - -/** - * Pair is the logical concatenation of an instance of A with an instance B. - * Space is conserved when possible. Neither A nor B may be a final class. - * - * It's typically clearer to have individual A and B member fields. Except if - * you want the space-conserving qualities of Pair, you're probably better off - * not using this! - * - * No guarantees are provided about the memory layout of A and B, the order of - * initialization or destruction of A and B, and so on. (This is approximately - * required to optimize space usage.) The first/second names are merely - * conceptual! - */ -template -struct Pair - : private detail::PairHelper -{ - typedef typename detail::PairHelper Base; - -public: - template - Pair(AArg&& aA, BArg&& aB) - : Base(Forward(aA), Forward(aB)) - {} - - Pair(Pair&& aOther) - : Base(Move(aOther.first()), Move(aOther.second())) - { } - - Pair(const Pair& aOther) = default; - - Pair& operator=(Pair&& aOther) - { - MOZ_ASSERT(this != &aOther, "Self-moves are prohibited"); - - first() = Move(aOther.first()); - second() = Move(aOther.second()); - - return *this; - } - - Pair& operator=(const Pair& aOther) = default; - - /** The A instance. */ - using Base::first; - /** The B instance. */ - using Base::second; - - /** Swap this pair with another pair. */ - void swap(Pair& aOther) { Base::swap(aOther); } -}; - -template -void -Swap(Pair& aX, Pair& aY) -{ - aX.swap(aY); -} - -/** - * MakePair allows you to construct a Pair instance using type inference. A call - * like this: - * - * MakePair(Foo(), Bar()) - * - * will return a Pair. - */ -template -Pair::Type>::Type, - typename RemoveCV::Type>::Type> -MakePair(A&& aA, B&& aB) -{ - return - Pair::Type>::Type, - typename RemoveCV::Type>::Type>( - Forward(aA), - Forward(aB)); -} - -} // namespace mozilla - -#endif /* mozilla_Pair_h */ diff --git a/onlineupdate/source/update/inc/mozilla/TypeTraits.h b/onlineupdate/source/update/inc/mozilla/TypeTraits.h deleted file mode 100644 index 47c7945a6a2d..000000000000 --- a/onlineupdate/source/update/inc/mozilla/TypeTraits.h +++ /dev/null @@ -1,1116 +0,0 @@ -/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* vim: set ts=8 sts=2 et sw=2 tw=80: */ -/* This Source Code Form is subject to the terms of the Mozilla Public - * 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/. */ - -/* Template-based metaprogramming and type-testing facilities. */ - -#ifndef mozilla_TypeTraits_h -#define mozilla_TypeTraits_h - -#include "mozilla/Types.h" - -/* - * These traits are approximate copies of the traits and semantics from C++11's - * header. Don't add traits not in that header! When all - * platforms provide that header, we can convert all users and remove this one. - */ - -#include - -namespace mozilla { - -/* Forward declarations. */ - -template struct RemoveCV; - -/* 20.9.3 Helper classes [meta.help] */ - -/** - * Helper class used as a base for various type traits, exposed publicly - * because exposes it as well. - */ -template -struct IntegralConstant -{ - static const T value = Value; - typedef T ValueType; - typedef IntegralConstant Type; -}; - -/** Convenient aliases. */ -typedef IntegralConstant TrueType; -typedef IntegralConstant FalseType; - -/* 20.9.4 Unary type traits [meta.unary] */ - -/* 20.9.4.1 Primary type categories [meta.unary.cat] */ - -namespace detail { - -template -struct IsVoidHelper : FalseType {}; - -template<> -struct IsVoidHelper : TrueType {}; - -} // namespace detail - -/** - * IsVoid determines whether a type is void. - * - * mozilla::IsVoid::value is false; - * mozilla::IsVoid::value is true; - * mozilla::IsVoid::value is false; - * mozilla::IsVoid::value is true. - */ -template -struct IsVoid : detail::IsVoidHelper::Type> {}; - -namespace detail { - -template -struct IsIntegralHelper : FalseType {}; - -template<> struct IsIntegralHelper : TrueType {}; -template<> struct IsIntegralHelper : TrueType {}; -template<> struct IsIntegralHelper : TrueType {}; -template<> struct IsIntegralHelper : TrueType {}; -template<> struct IsIntegralHelper : TrueType {}; -template<> struct IsIntegralHelper : TrueType {}; -template<> struct IsIntegralHelper : TrueType {}; -template<> struct IsIntegralHelper : TrueType {}; -template<> struct IsIntegralHelper : TrueType {}; -template<> struct IsIntegralHelper : TrueType {}; -template<> struct IsIntegralHelper : TrueType {}; -template<> struct IsIntegralHelper : TrueType {}; -template<> struct IsIntegralHelper : TrueType {}; -#ifdef MOZ_CHAR16_IS_NOT_WCHAR -template<> struct IsIntegralHelper : TrueType {}; -#endif - -} /* namespace detail */ - -/** - * IsIntegral determines whether a type is an integral type. - * - * mozilla::IsIntegral::value is true; - * mozilla::IsIntegral::value is true; - * mozilla::IsIntegral::value is true; - * mozilla::IsIntegral::value is false; - * mozilla::IsIntegral::value is false; - * - * Note that the behavior of IsIntegral on char16_t and char32_t is - * unspecified. - */ -template -struct IsIntegral : detail::IsIntegralHelper::Type> -{}; - -template -struct IsSame; - -namespace detail { - -template -struct IsFloatingPointHelper - : IntegralConstant::value || - IsSame::value || - IsSame::value> -{}; - -} // namespace detail - -/** - * IsFloatingPoint determines whether a type is a floating point type (float, - * double, long double). - * - * mozilla::IsFloatingPoint::value is false; - * mozilla::IsFloatingPoint::value is true; - * mozilla::IsFloatingPoint::value is true; - * mozilla::IsFloatingPoint::value is false. - */ -template -struct IsFloatingPoint - : detail::IsFloatingPointHelper::Type> -{}; - -namespace detail { - -template -struct IsArrayHelper : FalseType {}; - -template -struct IsArrayHelper : TrueType {}; - -template -struct IsArrayHelper : TrueType {}; - -} // namespace detail - -/** - * IsArray determines whether a type is an array type, of known or unknown - * length. - * - * mozilla::IsArray::value is false; - * mozilla::IsArray::value is true; - * mozilla::IsArray::value is true. - */ -template -struct IsArray : detail::IsArrayHelper::Type> -{}; - -namespace detail { - -template -struct IsPointerHelper : FalseType {}; - -template -struct IsPointerHelper : TrueType {}; - -} // namespace detail - -/** - * IsPointer determines whether a type is a possibly-CV-qualified pointer type - * (but not a pointer-to-member type). - * - * mozilla::IsPointer::value is true; - * mozilla::IsPointer::value is true; - * mozilla::IsPointer::value is true; - * mozilla::IsPointer::value is true; - * mozilla::IsPointer::value is true; - * mozilla::IsPointer::value is true; - * mozilla::IsPointer::value is true; - * mozilla::IsPointer::value is false; - * mozilla::IsPointer::value is false. - * mozilla::IsPointer::value is false - */ -template -struct IsPointer : detail::IsPointerHelper::Type> -{}; - -/** - * IsLvalueReference determines whether a type is an lvalue reference. - * - * mozilla::IsLvalueReference::value is false; - * mozilla::IsLvalueReference::value is false; - * mozilla::IsLvalueReference::value is false; - * mozilla::IsLvalueReference::value is false; - * mozilla::IsLvalueReference::value is false; - * mozilla::IsLvalueReference::value is true; - * mozilla::IsLvalueReference::value is false. - */ -template -struct IsLvalueReference : FalseType {}; - -template -struct IsLvalueReference : TrueType {}; - -/** - * IsRvalueReference determines whether a type is an rvalue reference. - * - * mozilla::IsRvalueReference::value is false; - * mozilla::IsRvalueReference::value is false; - * mozilla::IsRvalueReference::value is false; - * mozilla::IsRvalueReference::value is false; - * mozilla::IsRvalueReference::value is false; - * mozilla::IsRvalueReference::value is false; - * mozilla::IsRvalueReference::value is true. - */ -template -struct IsRvalueReference : FalseType {}; - -template -struct IsRvalueReference : TrueType {}; - -namespace detail { - -// __is_enum is a supported extension across all of our supported compilers. -template -struct IsEnumHelper - : IntegralConstant -{}; - -} // namespace detail - -/** - * IsEnum determines whether a type is an enum type. - * - * mozilla::IsEnum::value is true; - * mozilla::IsEnum::value is false; - * mozilla::IsEnum::value is false; - */ -template -struct IsEnum - : detail::IsEnumHelper::Type> -{}; - -namespace detail { - -// __is_class is a supported extension across all of our supported compilers: -// http://llvm.org/releases/3.0/docs/ClangReleaseNotes.html -// http://gcc.gnu.org/onlinedocs/gcc-4.4.7/gcc/Type-Traits.html#Type-Traits -// http://msdn.microsoft.com/en-us/library/ms177194%28v=vs.100%29.aspx -template -struct IsClassHelper - : IntegralConstant -{}; - -} // namespace detail - -/** - * IsClass determines whether a type is a class type (but not a union). - * - * struct S {}; - * union U {}; - * mozilla::IsClass::value is false; - * mozilla::IsClass::value is true; - * mozilla::IsClass::value is false; - */ -template -struct IsClass - : detail::IsClassHelper::Type> -{}; - -/* 20.9.4.2 Composite type traits [meta.unary.comp] */ - -/** - * IsReference determines whether a type is an lvalue or rvalue reference. - * - * mozilla::IsReference::value is false; - * mozilla::IsReference::value is false; - * mozilla::IsReference::value is true; - * mozilla::IsReference::value is false; - * mozilla::IsReference::value is true; - * mozilla::IsReference::value is false; - * mozilla::IsReference::value is false; - * mozilla::IsReference::value is true; - * mozilla::IsReference::value is true; - * mozilla::IsReference::value is true. - */ -template -struct IsReference - : IntegralConstant::value || IsRvalueReference::value> -{}; - -/** - * IsArithmetic determines whether a type is arithmetic. A type is arithmetic - * iff it is an integral type or a floating point type. - * - * mozilla::IsArithmetic::value is true; - * mozilla::IsArithmetic::value is true; - * mozilla::IsArithmetic::value is false. - */ -template -struct IsArithmetic - : IntegralConstant::value || IsFloatingPoint::value> -{}; - -/* 20.9.4.3 Type properties [meta.unary.prop] */ - -/** - * IsConst determines whether a type is const or not. - * - * mozilla::IsConst::value is false; - * mozilla::IsConst::value is true; - * mozilla::IsConst::value is false. - */ -template -struct IsConst : FalseType {}; - -template -struct IsConst : TrueType {}; - -/** - * IsVolatile determines whether a type is volatile or not. - * - * mozilla::IsVolatile::value is false; - * mozilla::IsVolatile::value is true; - * mozilla::IsVolatile::value is false. - */ -template -struct IsVolatile : FalseType {}; - -template -struct IsVolatile : TrueType {}; - -/** - * Traits class for identifying POD types. Until C++11 there's no automatic - * way to detect PODs, so for the moment this is done manually. Users may - * define specializations of this class that inherit from mozilla::TrueType and - * mozilla::FalseType (or equivalently mozilla::IntegralConstant, or conveniently from mozilla::IsPod for composite types) as needed to - * ensure correct IsPod behavior. - */ -template -struct IsPod : public FalseType {}; - -template<> struct IsPod : TrueType {}; -template<> struct IsPod : TrueType {}; -template<> struct IsPod : TrueType {}; -template<> struct IsPod : TrueType {}; -template<> struct IsPod : TrueType {}; -template<> struct IsPod : TrueType {}; -template<> struct IsPod : TrueType {}; -template<> struct IsPod : TrueType {}; -template<> struct IsPod : TrueType {}; -template<> struct IsPod : TrueType {}; -template<> struct IsPod : TrueType {}; -template<> struct IsPod : TrueType {}; -template<> struct IsPod : TrueType {}; -template<> struct IsPod : TrueType {}; -template<> struct IsPod : TrueType {}; -#ifdef MOZ_CHAR16_IS_NOT_WCHAR -template<> struct IsPod : TrueType {}; -#endif -template struct IsPod : TrueType {}; - -namespace detail { - -// __is_empty is a supported extension across all of our supported compilers: -// http://llvm.org/releases/3.0/docs/ClangReleaseNotes.html -// http://gcc.gnu.org/onlinedocs/gcc-4.4.7/gcc/Type-Traits.html#Type-Traits -// http://msdn.microsoft.com/en-us/library/ms177194%28v=vs.100%29.aspx -template -struct IsEmptyHelper - : IntegralConstant::value && __is_empty(T)> -{}; - -} // namespace detail - -/** - * IsEmpty determines whether a type is a class (but not a union) that is empty. - * - * A class is empty iff it and all its base classes have no non-static data - * members (except bit-fields of length 0) and no virtual member functions, and - * no base class is empty or a virtual base class. - * - * Intuitively, empty classes don't have any data that has to be stored in - * instances of those classes. (The size of the class must still be non-zero, - * because distinct array elements of any type must have different addresses. - * However, if the Empty Base Optimization is implemented by the compiler [most - * compilers implement it, and in certain cases C++11 requires it], the size of - * a class inheriting from an empty |Base| class need not be inflated by - * |sizeof(Base)|.) And intuitively, non-empty classes have data members and/or - * vtable pointers that must be stored in each instance for proper behavior. - * - * static_assert(!mozilla::IsEmpty::value, "not a class => not empty"); - * union U1 { int x; }; - * static_assert(!mozilla::IsEmpty::value, "not a class => not empty"); - * struct E1 {}; - * struct E2 { int : 0 }; - * struct E3 : E1 {}; - * struct E4 : E2 {}; - * static_assert(mozilla::IsEmpty::value && - * mozilla::IsEmpty::value && - * mozilla::IsEmpty::value && - * mozilla::IsEmpty::value, - * "all empty"); - * union U2 { E1 e1; }; - * static_assert(!mozilla::IsEmpty::value, "not a class => not empty"); - * struct NE1 { int x; }; - * struct NE2 : virtual E1 {}; - * struct NE3 : E2 { virtual ~NE3() {} }; - * struct NE4 { virtual void f() {} }; - * static_assert(!mozilla::IsEmpty::value && - * !mozilla::IsEmpty::value && - * !mozilla::IsEmpty::value && - * !mozilla::IsEmpty::value, - * "all empty"); - */ -template -struct IsEmpty : detail::IsEmptyHelper::Type> -{}; - - -namespace detail { - -template::value, - bool = IsIntegral::value, - typename NoCV = typename RemoveCV::Type> -struct IsSignedHelper; - -// Floating point is signed. -template -struct IsSignedHelper : TrueType {}; - -// Integral is conditionally signed. -template -struct IsSignedHelper - : IntegralConstant -{}; - -// Non-floating point, non-integral is not signed. -template -struct IsSignedHelper : FalseType {}; - -} // namespace detail - -/** - * IsSigned determines whether a type is a signed arithmetic type. |char| is - * considered a signed type if it has the same representation as |signed char|. - * - * mozilla::IsSigned::value is true; - * mozilla::IsSigned::value is false; - * mozilla::IsSigned::value is false; - * mozilla::IsSigned::value is true. - */ -template -struct IsSigned : detail::IsSignedHelper {}; - -namespace detail { - -template::value, - bool = IsIntegral::value, - typename NoCV = typename RemoveCV::Type> -struct IsUnsignedHelper; - -// Floating point is not unsigned. -template -struct IsUnsignedHelper : FalseType {}; - -// Integral is conditionally unsigned. -template -struct IsUnsignedHelper - : IntegralConstant::value || bool(NoCV(1) < NoCV(-1)))> -{}; - -// Non-floating point, non-integral is not unsigned. -template -struct IsUnsignedHelper : FalseType {}; - -} // namespace detail - -/** - * IsUnsigned determines whether a type is an unsigned arithmetic type. - * - * mozilla::IsUnsigned::value is false; - * mozilla::IsUnsigned::value is true; - * mozilla::IsUnsigned::value is true; - * mozilla::IsUnsigned::value is false. - */ -template -struct IsUnsigned : detail::IsUnsignedHelper {}; - -/* 20.9.5 Type property queries [meta.unary.prop.query] */ - -/* 20.9.6 Relationships between types [meta.rel] */ - -/** - * IsSame tests whether two types are the same type. - * - * mozilla::IsSame::value is true; - * mozilla::IsSame::value is true; - * mozilla::IsSame::value is false; - * mozilla::IsSame::value is true; - * mozilla::IsSame::value is false; - * mozilla::IsSame::value is true. - */ -template -struct IsSame : FalseType {}; - -template -struct IsSame : TrueType {}; - -namespace detail { - -#if defined(__GNUC__) || defined(__clang__) || defined(_MSC_VER) - -template -struct BaseOfTester : IntegralConstant {}; - -#else - -// The trickery used to implement IsBaseOf here makes it possible to use it for -// the cases of private and multiple inheritance. This code was inspired by the -// sample code here: -// -// http://stackoverflow.com/questions/2910979/how-is-base-of-works -template -struct BaseOfHelper -{ -public: - operator Base*() const; - operator Derived*(); -}; - -template -struct BaseOfTester -{ -private: - template - static char test(Derived*, T); - static int test(Base*, int); - -public: - static const bool value = - sizeof(test(BaseOfHelper(), int())) == sizeof(char); -}; - -template -struct BaseOfTester -{ -private: - template - static char test(Derived*, T); - static int test(Base*, int); - -public: - static const bool value = - sizeof(test(BaseOfHelper(), int())) == sizeof(char); -}; - -template -struct BaseOfTester : FalseType {}; - -template -struct BaseOfTester : TrueType {}; - -template -struct BaseOfTester : TrueType {}; - -#endif - -} /* namespace detail */ - -/* - * IsBaseOf allows to know whether a given class is derived from another. - * - * Consider the following class definitions: - * - * class A {}; - * class B : public A {}; - * class C {}; - * - * mozilla::IsBaseOf::value is true; - * mozilla::IsBaseOf::value is false; - */ -template -struct IsBaseOf - : IntegralConstant::value> -{}; - -namespace detail { - -template -struct ConvertibleTester -{ -private: - static From create(); - - template - static char test(To to); - - template - static int test(...); - -public: - static const bool value = - sizeof(test(create())) == sizeof(char); -}; - -} // namespace detail - -/** - * IsConvertible determines whether a value of type From will implicitly convert - * to a value of type To. For example: - * - * struct A {}; - * struct B : public A {}; - * struct C {}; - * - * mozilla::IsConvertible::value is true; - * mozilla::IsConvertible::value is true; - * mozilla::IsConvertible::value is true; - * mozilla::IsConvertible::value is true; - * mozilla::IsConvertible::value is false; - * mozilla::IsConvertible::value is false; - * mozilla::IsConvertible::value is false; - * mozilla::IsConvertible::value is false. - * - * For obscure reasons, you can't use IsConvertible when the types being tested - * are related through private inheritance, and you'll get a compile error if - * you try. Just don't do it! - * - * Note - we need special handling for void, which ConvertibleTester doesn't - * handle. The void handling here doesn't handle const/volatile void correctly, - * which could be easily fixed if the need arises. - */ -template -struct IsConvertible - : IntegralConstant::value> -{}; - -template -struct IsConvertible - : IntegralConstant::value> -{}; - -template -struct IsConvertible - : IntegralConstant::value> -{}; - -template<> -struct IsConvertible - : TrueType -{}; - -/* 20.9.7 Transformations between types [meta.trans] */ - -/* 20.9.7.1 Const-volatile modifications [meta.trans.cv] */ - -/** - * RemoveConst removes top-level const qualifications on a type. - * - * mozilla::RemoveConst::Type is int; - * mozilla::RemoveConst::Type is int; - * mozilla::RemoveConst::Type is const int*; - * mozilla::RemoveConst::Type is int*. - */ -template -struct RemoveConst -{ - typedef T Type; -}; - -template -struct RemoveConst -{ - typedef T Type; -}; - -/** - * RemoveVolatile removes top-level volatile qualifications on a type. - * - * mozilla::RemoveVolatile::Type is int; - * mozilla::RemoveVolatile::Type is int; - * mozilla::RemoveVolatile::Type is volatile int*; - * mozilla::RemoveVolatile::Type is int*. - */ -template -struct RemoveVolatile -{ - typedef T Type; -}; - -template -struct RemoveVolatile -{ - typedef T Type; -}; - -/** - * RemoveCV removes top-level const and volatile qualifications on a type. - * - * mozilla::RemoveCV::Type is int; - * mozilla::RemoveCV::Type is int; - * mozilla::RemoveCV::Type is int; - * mozilla::RemoveCV::Type is int*. - */ -template -struct RemoveCV -{ - typedef typename RemoveConst::Type>::Type Type; -}; - -/* 20.9.7.2 Reference modifications [meta.trans.ref] */ - -/** - * Converts reference types to the underlying types. - * - * mozilla::RemoveReference::Type is T; - * mozilla::RemoveReference::Type is T; - * mozilla::RemoveReference::Type is T; - */ - -template -struct RemoveReference -{ - typedef T Type; -}; - -template -struct RemoveReference -{ - typedef T Type; -}; - -template -struct RemoveReference -{ - typedef T Type; -}; - -template -struct Conditional; - -namespace detail { - -enum Voidness { TIsVoid, TIsNotVoid }; - -template::value ? TIsVoid : TIsNotVoid> -struct AddLvalueReferenceHelper; - -template -struct AddLvalueReferenceHelper -{ - typedef void Type; -}; - -template -struct AddLvalueReferenceHelper -{ - typedef T& Type; -}; - -} // namespace detail - -/** - * AddLvalueReference adds an lvalue & reference to T if one isn't already - * present. (Note: adding an lvalue reference to an rvalue && reference in - * essence replaces the && with a &&, per C+11 reference collapsing rules. For - * example, int&& would become int&.) - * - * The final computed type will only *not* be an lvalue reference if T is void. - * - * mozilla::AddLvalueReference::Type is int&; - * mozilla::AddLvalueRference::Type is volatile int&; - * mozilla::AddLvalueReference::Type is void*&; - * mozilla::AddLvalueReference::Type is void; - * mozilla::AddLvalueReference::Type is struct S&. - */ -template -struct AddLvalueReference - : detail::AddLvalueReferenceHelper -{}; - -namespace detail { - -template::value ? TIsVoid : TIsNotVoid> -struct AddRvalueReferenceHelper; - -template -struct AddRvalueReferenceHelper -{ - typedef void Type; -}; - -template -struct AddRvalueReferenceHelper -{ - typedef T&& Type; -}; - -} // namespace detail - -/** - * AddRvalueReference adds an rvalue && reference to T if one isn't already - * present. (Note: adding an rvalue reference to an lvalue & reference in - * essence keeps the &, per C+11 reference collapsing rules. For example, - * int& would remain int&.) - * - * The final computed type will only *not* be a reference if T is void. - * - * mozilla::AddRvalueReference::Type is int&&; - * mozilla::AddRvalueRference::Type is volatile int&; - * mozilla::AddRvalueRference::Type is const int&&; - * mozilla::AddRvalueReference::Type is void*&&; - * mozilla::AddRvalueReference::Type is void; - * mozilla::AddRvalueReference::Type is struct S&. - */ -template -struct AddRvalueReference - : detail::AddRvalueReferenceHelper -{}; - -/* 20.2.4 Function template declval [declval] */ - -/** - * DeclVal simplifies the definition of expressions which occur as unevaluated - * operands. It converts T to a reference type, making it possible to use in - * decltype expressions even if T does not have a default constructor, e.g.: - * decltype(DeclVal().foo()) - */ -template -typename AddRvalueReference::Type DeclVal(); - -/* 20.9.7.3 Sign modifications [meta.trans.sign] */ - -template -struct EnableIf; - -namespace detail { - -template -struct WithC : Conditional -{}; - -template -struct WithV : Conditional -{}; - - -template -struct WithCV : WithC::Type> -{}; - -template -struct CorrespondingSigned; - -template<> -struct CorrespondingSigned { typedef signed char Type; }; -template<> -struct CorrespondingSigned { typedef signed char Type; }; -template<> -struct CorrespondingSigned { typedef short Type; }; -template<> -struct CorrespondingSigned { typedef int Type; }; -template<> -struct CorrespondingSigned { typedef long Type; }; -template<> -struct CorrespondingSigned { typedef long long Type; }; - -template::Type, - bool IsSignedIntegerType = IsSigned::value && - !IsSame::value> -struct MakeSigned; - -template -struct MakeSigned -{ - typedef T Type; -}; - -template -struct MakeSigned - : WithCV::value, IsVolatile::value, - typename CorrespondingSigned::Type> -{}; - -} // namespace detail - -/** - * MakeSigned produces the corresponding signed integer type for a given - * integral type T, with the const/volatile qualifiers of T. T must be a - * possibly-const/volatile-qualified integral type that isn't bool. - * - * If T is already a signed integer type (not including char!), then T is - * produced. - * - * Otherwise, if T is an unsigned integer type, the signed variety of T, with - * T's const/volatile qualifiers, is produced. - * - * Otherwise, the integral type of the same size as T, with the lowest rank, - * with T's const/volatile qualifiers, is produced. (This basically only acts - * to produce signed char when T = char.) - * - * mozilla::MakeSigned::Type is signed long; - * mozilla::MakeSigned::Type is volatile int; - * mozilla::MakeSigned::Type is const signed short; - * mozilla::MakeSigned::Type is const signed char; - * mozilla::MakeSigned is an error; - * mozilla::MakeSigned is an error. - */ -template -struct MakeSigned - : EnableIf::value && - !IsSame::Type>::value, - typename detail::MakeSigned - >::Type -{}; - -namespace detail { - -template -struct CorrespondingUnsigned; - -template<> -struct CorrespondingUnsigned { typedef unsigned char Type; }; -template<> -struct CorrespondingUnsigned { typedef unsigned char Type; }; -template<> -struct CorrespondingUnsigned { typedef unsigned short Type; }; -template<> -struct CorrespondingUnsigned { typedef unsigned int Type; }; -template<> -struct CorrespondingUnsigned { typedef unsigned long Type; }; -template<> -struct CorrespondingUnsigned { typedef unsigned long long Type; }; - - -template::Type, - bool IsUnsignedIntegerType = IsUnsigned::value && - !IsSame::value> -struct MakeUnsigned; - -template -struct MakeUnsigned -{ - typedef T Type; -}; - -template -struct MakeUnsigned - : WithCV::value, IsVolatile::value, - typename CorrespondingUnsigned::Type> -{}; - -} // namespace detail - -/** - * MakeUnsigned produces the corresponding unsigned integer type for a given - * integral type T, with the const/volatile qualifiers of T. T must be a - * possibly-const/volatile-qualified integral type that isn't bool. - * - * If T is already an unsigned integer type (not including char!), then T is - * produced. - * - * Otherwise, if T is an signed integer type, the unsigned variety of T, with - * T's const/volatile qualifiers, is produced. - * - * Otherwise, the unsigned integral type of the same size as T, with the lowest - * rank, with T's const/volatile qualifiers, is produced. (This basically only - * acts to produce unsigned char when T = char.) - * - * mozilla::MakeUnsigned::Type is unsigned long; - * mozilla::MakeUnsigned::Type is volatile unsigned int; - * mozilla::MakeUnsigned::Type is const unsigned short; - * mozilla::MakeUnsigned::Type is const unsigned char; - * mozilla::MakeUnsigned is an error; - * mozilla::MakeUnsigned is an error. - */ -template -struct MakeUnsigned - : EnableIf::value && - !IsSame::Type>::value, - typename detail::MakeUnsigned - >::Type -{}; - -/* 20.9.7.4 Array modifications [meta.trans.arr] */ - -/** - * RemoveExtent produces either the type of the elements of the array T, or T - * itself. - * - * mozilla::RemoveExtent::Type is int; - * mozilla::RemoveExtent::Type is const int; - * mozilla::RemoveExtent::Type is volatile int; - * mozilla::RemoveExtent::Type is long[17]. - */ -template -struct RemoveExtent -{ - typedef T Type; -}; - -template -struct RemoveExtent -{ - typedef T Type; -}; - -template -struct RemoveExtent -{ - typedef T Type; -}; - -/* 20.9.7.5 Pointer modifications [meta.trans.ptr] */ - -namespace detail { - -template -struct RemovePointerHelper -{ - typedef T Type; -}; - -template -struct RemovePointerHelper -{ - typedef Pointee Type; -}; - -} // namespac detail - -/** - * Produces the pointed-to type if a pointer is provided, else returns the input - * type. Note that this does not dereference pointer-to-member pointers. - * - * struct S { bool m; void f(); }; - * mozilla::RemovePointer::Type is int; - * mozilla::RemovePointer::Type is int; - * mozilla::RemovePointer::Type is int; - * mozilla::RemovePointer::Type is int; - * mozilla::RemovePointer::Type is const long; - * mozilla::RemovePointer::Type is void; - * mozilla::RemovePointer::Type is void (S::*)(); - * mozilla::RemovePointer::Type is void(); - * mozilla::RemovePointer::Type is bool S::*. - */ -template -struct RemovePointer - : detail::RemovePointerHelper::Type> -{}; - -/* 20.9.7.6 Other transformations [meta.trans.other] */ - -/** - * EnableIf is a struct containing a typedef of T if and only if B is true. - * - * mozilla::EnableIf::Type is int; - * mozilla::EnableIf::Type is a compile-time error. - * - * Use this template to implement SFINAE-style (Substitution Failure Is not An - * Error) requirements. For example, you might use it to impose a restriction - * on a template parameter: - * - * template - * class PodVector // vector optimized to store POD (memcpy-able) types - * { - * EnableIf::value, T>::Type* vector; - * size_t length; - * ... - * }; - */ -template -struct EnableIf -{}; - -template -struct EnableIf -{ - typedef T Type; -}; - -/** - * Conditional selects a class between two, depending on a given boolean value. - * - * mozilla::Conditional::Type is A; - * mozilla::Conditional::Type is B; - */ -template -struct Conditional -{ - typedef A Type; -}; - -template -struct Conditional -{ - typedef B Type; -}; - -} /* namespace mozilla */ - -#endif /* mozilla_TypeTraits_h */ diff --git a/onlineupdate/source/update/inc/mozilla/Types.h b/onlineupdate/source/update/inc/mozilla/Types.h deleted file mode 100644 index 9d1e34b6d1d6..000000000000 --- a/onlineupdate/source/update/inc/mozilla/Types.h +++ /dev/null @@ -1,134 +0,0 @@ -/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* vim: set ts=8 sts=2 et sw=2 tw=80: */ -/* This Source Code Form is subject to the terms of the Mozilla Public - * 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/. */ - -/* mfbt foundational types and macros. */ - -#ifndef mozilla_Types_h -#define mozilla_Types_h - -/* - * This header must be valid C and C++, includable by code embedding either - * SpiderMonkey or Gecko. - */ - -/* Expose all types and size_t. */ -#include -#include - -/* Implement compiler and linker macros needed for APIs. */ - -/* - * MOZ_EXPORT is used to declare and define a symbol or type which is externally - * visible to users of the current library. It encapsulates various decorations - * needed to properly export the method's symbol. - * - * api.h: - * extern MOZ_EXPORT int MeaningOfLife(void); - * extern MOZ_EXPORT int LuggageCombination; - * - * api.c: - * int MeaningOfLife(void) { return 42; } - * int LuggageCombination = 12345; - * - * If you are merely sharing a method across files, just use plain |extern|. - * These macros are designed for use by library interfaces -- not for normal - * methods or data used cross-file. - */ -#if defined(_WIN32) -# define MOZ_EXPORT __declspec(dllexport) -#else /* Unix */ -# ifdef HAVE_VISIBILITY_ATTRIBUTE -# define MOZ_EXPORT __attribute__((visibility("default"))) -# elif defined(__SUNPRO_C) || defined(__SUNPRO_CC) -# define MOZ_EXPORT __global -# else -# define MOZ_EXPORT /* nothing */ -# endif -#endif - - -/* - * Whereas implementers use MOZ_EXPORT to declare and define library symbols, - * users use MOZ_IMPORT_API and MOZ_IMPORT_DATA to access them. Most often the - * implementer of the library will expose an API macro which expands to either - * the export or import version of the macro, depending upon the compilation - * mode. - */ -#ifdef _WIN32 -# if defined(__MWERKS__) -# define MOZ_IMPORT_API /* nothing */ -# else -# define MOZ_IMPORT_API __declspec(dllimport) -# endif -#else -# define MOZ_IMPORT_API MOZ_EXPORT -#endif - -#if defined(_WIN32) && !defined(__MWERKS__) -# define MOZ_IMPORT_DATA __declspec(dllimport) -#else -# define MOZ_IMPORT_DATA MOZ_EXPORT -#endif - -/* - * Consistent with the above comment, the MFBT_API and MFBT_DATA macros expose - * export mfbt declarations when building mfbt, and they expose import mfbt - * declarations when using mfbt. - */ -#if defined(IMPL_MFBT) -# define MFBT_API MOZ_EXPORT -# define MFBT_DATA MOZ_EXPORT -#else - /* - * On linux mozglue is linked in the program and we link libxul.so with - * -z,defs. Normally that causes the linker to reject undefined references in - * libxul.so, but as a loophole it allows undefined references to weak - * symbols. We add the weak attribute to the import version of the MFBT API - * macros to exploit this. - */ -# if defined(MOZ_GLUE_IN_PROGRAM) && !defined(MOZILLA_XPCOMRT_API) -# define MFBT_API __attribute__((weak)) MOZ_IMPORT_API -# define MFBT_DATA __attribute__((weak)) MOZ_IMPORT_DATA -# else -# define MFBT_API MOZ_IMPORT_API -# define MFBT_DATA MOZ_IMPORT_DATA -# endif -#endif - -/* - * C symbols in C++ code must be declared immediately within |extern "C"| - * blocks. However, in C code, they need not be declared specially. This - * difference is abstracted behind the MOZ_BEGIN_EXTERN_C and MOZ_END_EXTERN_C - * macros, so that the user need not know whether he is being used in C or C++ - * code. - * - * MOZ_BEGIN_EXTERN_C - * - * extern MOZ_EXPORT int MostRandomNumber(void); - * ...other declarations... - * - * MOZ_END_EXTERN_C - * - * This said, it is preferable to just use |extern "C"| in C++ header files for - * its greater clarity. - */ -#ifdef __cplusplus -# define MOZ_BEGIN_EXTERN_C extern "C" { -# define MOZ_END_EXTERN_C } -#else -# define MOZ_BEGIN_EXTERN_C -# define MOZ_END_EXTERN_C -#endif - -/* - * GCC's typeof is available when decltype is not. - */ -#if defined(__GNUC__) && defined(__cplusplus) && \ - !defined(__GXX_EXPERIMENTAL_CXX0X__) && __cplusplus < 201103L -# define decltype __typeof__ -#endif - -#endif /* mozilla_Types_h */ diff --git a/onlineupdate/source/update/inc/mozilla/UniquePtr.h b/onlineupdate/source/update/inc/mozilla/UniquePtr.h deleted file mode 100644 index 6fad8d1cfb8a..000000000000 --- a/onlineupdate/source/update/inc/mozilla/UniquePtr.h +++ /dev/null @@ -1,659 +0,0 @@ -/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* vim: set ts=8 sts=2 et sw=2 tw=80: */ -/* This Source Code Form is subject to the terms of the Mozilla Public - * 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/. */ - -/* Smart pointer managing sole ownership of a resource. */ - -#ifndef mozilla_UniquePtr_h -#define mozilla_UniquePtr_h - -#include "mozilla/Assertions.h" -#include "mozilla/Attributes.h" -#include "mozilla/Compiler.h" -#include "mozilla/Move.h" -#include "mozilla/Pair.h" -#include "mozilla/TypeTraits.h" - -namespace mozilla { - -template class DefaultDelete; -template> class UniquePtr; - -} // namespace mozilla - -namespace mozilla { - -/** - * UniquePtr is a smart pointer that wholly owns a resource. Ownership may be - * transferred out of a UniquePtr through explicit action, but otherwise the - * resource is destroyed when the UniquePtr is destroyed. - * - * UniquePtr is similar to C++98's std::auto_ptr, but it improves upon auto_ptr - * in one crucial way: it's impossible to copy a UniquePtr. Copying an auto_ptr - * obviously *can't* copy ownership of its singly-owned resource. So what - * happens if you try to copy one? Bizarrely, ownership is implicitly - * *transferred*, preserving single ownership but breaking code that assumes a - * copy of an object is identical to the original. (This is why auto_ptr is - * prohibited in STL containers.) - * - * UniquePtr solves this problem by being *movable* rather than copyable. - * Instead of passing a |UniquePtr u| directly to the constructor or assignment - * operator, you pass |Move(u)|. In doing so you indicate that you're *moving* - * ownership out of |u|, into the target of the construction/assignment. After - * the transfer completes, |u| contains |nullptr| and may be safely destroyed. - * This preserves single ownership but also allows UniquePtr to be moved by - * algorithms that have been made move-safe. (Note: if |u| is instead a - * temporary expression, don't use |Move()|: just pass the expression, because - * it's already move-ready. For more information see Move.h.) - * - * UniquePtr is also better than std::auto_ptr in that the deletion operation is - * customizable. An optional second template parameter specifies a class that - * (through its operator()(T*)) implements the desired deletion policy. If no - * policy is specified, mozilla::DefaultDelete is used -- which will either - * |delete| or |delete[]| the resource, depending whether the resource is an - * array. Custom deletion policies ideally should be empty classes (no member - * fields, no member fields in base classes, no virtual methods/inheritance), - * because then UniquePtr can be just as efficient as a raw pointer. - * - * Use of UniquePtr proceeds like so: - * - * UniquePtr g1; // initializes to nullptr - * g1.reset(new int); // switch resources using reset() - * g1 = nullptr; // clears g1, deletes the int - * - * UniquePtr g2(new int); // owns that int - * int* p = g2.release(); // g2 leaks its int -- still requires deletion - * delete p; // now freed - * - * struct S { int x; S(int x) : x(x) {} }; - * UniquePtr g3, g4(new S(5)); - * g3 = Move(g4); // g3 owns the S, g4 cleared - * S* p = g3.get(); // g3 still owns |p| - * assert(g3->x == 5); // operator-> works (if .get() != nullptr) - * assert((*g3).x == 5); // also operator* (again, if not cleared) - * Swap(g3, g4); // g4 now owns the S, g3 cleared - * g3.swap(g4); // g3 now owns the S, g4 cleared - * UniquePtr g5(Move(g3)); // g5 owns the S, g3 cleared - * g5.reset(); // deletes the S, g5 cleared - * - * struct FreePolicy { void operator()(void* p) { free(p); } }; - * UniquePtr g6(static_cast(malloc(sizeof(int)))); - * int* ptr = g6.get(); - * g6 = nullptr; // calls free(ptr) - * - * Now, carefully note a few things you *can't* do: - * - * UniquePtr b1; - * b1 = new int; // BAD: can only assign another UniquePtr - * int* ptr = b1; // BAD: no auto-conversion to pointer, use get() - * - * UniquePtr b2(b1); // BAD: can't copy a UniquePtr - * UniquePtr b3 = b1; // BAD: can't copy-assign a UniquePtr - * - * (Note that changing a UniquePtr to store a direct |new| expression is - * permitted, but usually you should use MakeUnique, defined at the end of this - * header.) - * - * A few miscellaneous notes: - * - * UniquePtr, when not instantiated for an array type, can be move-constructed - * and move-assigned, not only from itself but from "derived" UniquePtr - * instantiations where U converts to T and E converts to D. If you want to use - * this, you're going to have to specify a deletion policy for both UniquePtr - * instantiations, and T pretty much has to have a virtual destructor. In other - * words, this doesn't work: - * - * struct Base { virtual ~Base() {} }; - * struct Derived : Base {}; - * - * UniquePtr b1; - * // BAD: DefaultDelete and DefaultDelete don't interconvert - * UniquePtr d1(Move(b)); - * - * UniquePtr b2; - * UniquePtr> d2(Move(b2)); // okay - * - * UniquePtr is specialized for array types. Specializing with an array type - * creates a smart-pointer version of that array -- not a pointer to such an - * array. - * - * UniquePtr arr(new int[5]); - * arr[0] = 4; - * - * What else is different? Deletion of course uses |delete[]|. An operator[] - * is provided. Functionality that doesn't make sense for arrays is removed. - * The constructors and mutating methods only accept array pointers (not T*, U* - * that converts to T*, or UniquePtr or UniquePtr) or |nullptr|. - * - * It's perfectly okay to return a UniquePtr from a method to assure the related - * resource is properly deleted. You'll need to use |Move()| when returning a - * local UniquePtr. Otherwise you can return |nullptr|, or you can return - * |UniquePtr(ptr)|. - * - * UniquePtr will commonly be a member of a class, with lifetime equivalent to - * that of that class. If you want to expose the related resource, you could - * expose a raw pointer via |get()|, but ownership of a raw pointer is - * inherently unclear. So it's better to expose a |const UniquePtr&| instead. - * This prohibits mutation but still allows use of |get()| when needed (but - * operator-> is preferred). Of course, you can only use this smart pointer as - * long as the enclosing class instance remains live -- no different than if you - * exposed the |get()| raw pointer. - * - * To pass a UniquePtr-managed resource as a pointer, use a |const UniquePtr&| - * argument. To specify an inout parameter (where the method may or may not - * take ownership of the resource, or reset it), or to specify an out parameter - * (where simply returning a |UniquePtr| isn't possible), use a |UniquePtr&| - * argument. To unconditionally transfer ownership of a UniquePtr - * into a method, use a |UniquePtr| argument. To conditionally transfer - * ownership of a resource into a method, should the method want it, use a - * |UniquePtr&&| argument. - */ -template -class UniquePtr -{ -public: - typedef T* Pointer; - typedef T ElementType; - typedef D DeleterType; - -private: - Pair mTuple; - - Pointer& ptr() { return mTuple.first(); } - const Pointer& ptr() const { return mTuple.first(); } - - DeleterType& del() { return mTuple.second(); } - const DeleterType& del() const { return mTuple.second(); } - -public: - /** - * Construct a UniquePtr containing |nullptr|. - */ - MOZ_CONSTEXPR UniquePtr() - : mTuple(static_cast(nullptr), DeleterType()) - { - static_assert(!IsPointer::value, "must provide a deleter instance"); - static_assert(!IsReference::value, "must provide a deleter instance"); - } - - /** - * Construct a UniquePtr containing |aPtr|. - */ - explicit UniquePtr(Pointer aPtr) - : mTuple(aPtr, DeleterType()) - { - static_assert(!IsPointer::value, "must provide a deleter instance"); - static_assert(!IsReference::value, "must provide a deleter instance"); - } - - UniquePtr(Pointer aPtr, - typename Conditional::value, - D, - const D&>::Type aD1) - : mTuple(aPtr, aD1) - {} - - // If you encounter an error with MSVC10 about RemoveReference below, along - // the lines that "more than one partial specialization matches the template - // argument list": don't use UniquePtr! Ideally - // you should make deletion use the same function every time, using a - // deleter policy: - // - // // BAD, won't compile with MSVC10, deleter doesn't need to be a - // // variable at all - // typedef void (&FreeSignature)(void*); - // UniquePtr ptr((int*) malloc(sizeof(int)), free); - // - // // GOOD, compiles with MSVC10, deletion behavior statically known and - // // optimizable - // struct DeleteByFreeing - // { - // void operator()(void* aPtr) { free(aPtr); } - // }; - // - // If deletion really, truly, must be a variable: you might be able to work - // around this with a deleter class that contains the function reference. - // But this workaround is untried and untested, because variable deletion - // behavior really isn't something you should use. - UniquePtr(Pointer aPtr, - typename RemoveReference::Type&& aD2) - : mTuple(aPtr, Move(aD2)) - { - static_assert(!IsReference::value, - "rvalue deleter can't be stored by reference"); - } - - UniquePtr(UniquePtr&& aOther) - : mTuple(aOther.release(), Forward(aOther.getDeleter())) - {} - - MOZ_IMPLICIT - UniquePtr(decltype(nullptr)) - : mTuple(nullptr, DeleterType()) - { - static_assert(!IsPointer::value, "must provide a deleter instance"); - static_assert(!IsReference::value, "must provide a deleter instance"); - } - - template - UniquePtr(UniquePtr&& aOther, - typename EnableIf::Pointer, - Pointer>::value && - !IsArray::value && - (IsReference::value - ? IsSame::value - : IsConvertible::value), - int>::Type aDummy = 0) - : mTuple(aOther.release(), Forward(aOther.getDeleter())) - { - } - - ~UniquePtr() { reset(nullptr); } - - UniquePtr& operator=(UniquePtr&& aOther) - { - reset(aOther.release()); - getDeleter() = Forward(aOther.getDeleter()); - return *this; - } - - template - UniquePtr& operator=(UniquePtr&& aOther) - { - static_assert(IsConvertible::Pointer, - Pointer>::value, - "incompatible UniquePtr pointees"); - static_assert(!IsArray::value, - "can't assign from UniquePtr holding an array"); - - reset(aOther.release()); - getDeleter() = Forward(aOther.getDeleter()); - return *this; - } - - UniquePtr& operator=(decltype(nullptr)) - { - reset(nullptr); - return *this; - } - - T& operator*() const { return *get(); } - Pointer operator->() const - { - MOZ_ASSERT(get(), "dereferencing a UniquePtr containing nullptr"); - return get(); - } - - explicit operator bool() const { return get() != nullptr; } - - Pointer get() const { return ptr(); } - - DeleterType& getDeleter() { return del(); } - const DeleterType& getDeleter() const { return del(); } - - Pointer release() - { - Pointer p = ptr(); - ptr() = nullptr; - return p; - } - - void reset(Pointer aPtr = Pointer()) - { - Pointer old = ptr(); - ptr() = aPtr; - if (old != nullptr) { - getDeleter()(old); - } - } - - void swap(UniquePtr& aOther) - { - mTuple.swap(aOther.mTuple); - } - -private: - UniquePtr(const UniquePtr& aOther) = delete; // construct using Move()! - void operator=(const UniquePtr& aOther) = delete; // assign using Move()! -}; - -// In case you didn't read the comment by the main definition (you should!): the -// UniquePtr specialization exists to manage array pointers. It deletes -// such pointers using delete[], it will reject construction and modification -// attempts using U* or U[]. Otherwise it works like the normal UniquePtr. -template -class UniquePtr -{ -public: - typedef T* Pointer; - typedef T ElementType; - typedef D DeleterType; - -private: - Pair mTuple; - -public: - /** - * Construct a UniquePtr containing nullptr. - */ - MOZ_CONSTEXPR UniquePtr() - : mTuple(static_cast(nullptr), DeleterType()) - { - static_assert(!IsPointer::value, "must provide a deleter instance"); - static_assert(!IsReference::value, "must provide a deleter instance"); - } - - /** - * Construct a UniquePtr containing |aPtr|. - */ - explicit UniquePtr(Pointer aPtr) - : mTuple(aPtr, DeleterType()) - { - static_assert(!IsPointer::value, "must provide a deleter instance"); - static_assert(!IsReference::value, "must provide a deleter instance"); - } - -private: - // delete[] knows how to handle *only* an array of a single class type. For - // delete[] to work correctly, it must know the size of each element, the - // fields and base classes of each element requiring destruction, and so on. - // So forbid all overloads which would end up invoking delete[] on a pointer - // of the wrong type. - template - UniquePtr(U&& aU, - typename EnableIf::value && - IsConvertible::value, - int>::Type aDummy = 0) - = delete; - -public: - UniquePtr(Pointer aPtr, - typename Conditional::value, - D, - const D&>::Type aD1) - : mTuple(aPtr, aD1) - {} - - // If you encounter an error with MSVC10 about RemoveReference below, along - // the lines that "more than one partial specialization matches the template - // argument list": don't use UniquePtr! See the - // comment by this constructor in the non-T[] specialization above. - UniquePtr(Pointer aPtr, - typename RemoveReference::Type&& aD2) - : mTuple(aPtr, Move(aD2)) - { - static_assert(!IsReference::value, - "rvalue deleter can't be stored by reference"); - } - -private: - // Forbidden for the same reasons as stated above. - template - UniquePtr(U&& aU, V&& aV, - typename EnableIf::value && - IsConvertible::value, - int>::Type aDummy = 0) - = delete; - -public: - UniquePtr(UniquePtr&& aOther) - : mTuple(aOther.release(), Forward(aOther.getDeleter())) - {} - - MOZ_IMPLICIT - UniquePtr(decltype(nullptr)) - : mTuple(nullptr, DeleterType()) - { - static_assert(!IsPointer::value, "must provide a deleter instance"); - static_assert(!IsReference::value, "must provide a deleter instance"); - } - - ~UniquePtr() { reset(nullptr); } - - UniquePtr& operator=(UniquePtr&& aOther) - { - reset(aOther.release()); - getDeleter() = Forward(aOther.getDeleter()); - return *this; - } - - UniquePtr& operator=(decltype(nullptr)) - { - reset(); - return *this; - } - - explicit operator bool() const { return get() != nullptr; } - - T& operator[](decltype(sizeof(int)) aIndex) const { return get()[aIndex]; } - Pointer get() const { return mTuple.first(); } - - DeleterType& getDeleter() { return mTuple.second(); } - const DeleterType& getDeleter() const { return mTuple.second(); } - - Pointer release() - { - Pointer p = mTuple.first(); - mTuple.first() = nullptr; - return p; - } - - void reset(Pointer aPtr = Pointer()) - { - Pointer old = mTuple.first(); - mTuple.first() = aPtr; - if (old != nullptr) { - mTuple.second()(old); - } - } - - void reset(decltype(nullptr)) - { - Pointer old = mTuple.first(); - mTuple.first() = nullptr; - if (old != nullptr) { - mTuple.second()(old); - } - } - -private: - template - void reset(U) = delete; - -public: - void swap(UniquePtr& aOther) { mTuple.swap(aOther.mTuple); } - -private: - UniquePtr(const UniquePtr& aOther) = delete; // construct using Move()! - void operator=(const UniquePtr& aOther) = delete; // assign using Move()! -}; - -/** A default deletion policy using plain old operator delete. */ -template -class DefaultDelete -{ -public: - MOZ_CONSTEXPR DefaultDelete() {} - - template - DefaultDelete(const DefaultDelete& aOther, - typename EnableIf::value, - int>::Type aDummy = 0) - {} - - void operator()(T* aPtr) const - { - static_assert(sizeof(T) > 0, "T must be complete"); - delete aPtr; - } -}; - -/** A default deletion policy using operator delete[]. */ -template -class DefaultDelete -{ -public: - MOZ_CONSTEXPR DefaultDelete() {} - - void operator()(T* aPtr) const - { - static_assert(sizeof(T) > 0, "T must be complete"); - delete[] aPtr; - } - -private: - template - void operator()(U* aPtr) const = delete; -}; - -template -void -Swap(UniquePtr& aX, UniquePtr& aY) -{ - aX.swap(aY); -} - -template -bool -operator==(const UniquePtr& aX, const UniquePtr& aY) -{ - return aX.get() == aY.get(); -} - -template -bool -operator!=(const UniquePtr& aX, const UniquePtr& aY) -{ - return aX.get() != aY.get(); -} - -template -bool -operator==(const UniquePtr& aX, decltype(nullptr)) -{ - return !aX; -} - -template -bool -operator==(decltype(nullptr), const UniquePtr& aX) -{ - return !aX; -} - -template -bool -operator!=(const UniquePtr& aX, decltype(nullptr)) -{ - return bool(aX); -} - -template -bool -operator!=(decltype(nullptr), const UniquePtr& aX) -{ - return bool(aX); -} - -// No operator<, operator>, operator<=, operator>= for now because simplicity. - -namespace detail { - -template -struct UniqueSelector -{ - typedef UniquePtr SingleObject; -}; - -template -struct UniqueSelector -{ - typedef UniquePtr UnknownBound; -}; - -template -struct UniqueSelector -{ - typedef UniquePtr KnownBound; -}; - -} // namespace detail - -/** - * MakeUnique is a helper function for allocating new'd objects and arrays, - * returning a UniquePtr containing the resulting pointer. The semantics of - * MakeUnique(...) are as follows. - * - * If Type is an array T[n]: - * Disallowed, deleted, no overload for you! - * If Type is an array T[]: - * MakeUnique(size_t) is the only valid overload. The pointer returned - * is as if by |new T[n]()|, which value-initializes each element. (If T - * isn't a class type, this will zero each element. If T is a class type, - * then roughly speaking, each element will be constructed using its default - * constructor. See C++11 [dcl.init]p7 for the full gory details.) - * If Type is non-array T: - * The arguments passed to MakeUnique(...) are forwarded into a - * |new T(...)| call, initializing the T as would happen if executing - * |T(...)|. - * - * There are various benefits to using MakeUnique instead of |new| expressions. - * - * First, MakeUnique eliminates use of |new| from code entirely. If objects are - * only created through UniquePtr, then (assuming all explicit release() calls - * are safe, including transitively, and no type-safety casting funniness) - * correctly maintained ownership of the UniquePtr guarantees no leaks are - * possible. (This pays off best if a class is only ever created through a - * factory method on the class, using a private constructor.) - * - * Second, initializing a UniquePtr using a |new| expression requires repeating - * the name of the new'd type, whereas MakeUnique in concert with the |auto| - * keyword names it only once: - * - * UniquePtr ptr1(new char()); // repetitive - * auto ptr2 = MakeUnique(); // shorter - * - * Of course this assumes the reader understands the operation MakeUnique - * performs. In the long run this is probably a reasonable assumption. In the - * short run you'll have to use your judgment about what readers can be expected - * to know, or to quickly look up. - * - * Third, a call to MakeUnique can be assigned directly to a UniquePtr. In - * contrast you can't assign a pointer into a UniquePtr without using the - * cumbersome reset(). - * - * UniquePtr p; - * p = new char; // ERROR - * p.reset(new char); // works, but ugly - * p = MakeUnique(); // preferred - * - * (And third, although not relevant to Mozilla: MakeUnique is exception-safe. - * An exception thrown after |new T| succeeds will leak that memory, unless the - * pointer is assigned to an object that will manage its ownership. UniquePtr - * ably serves this function.) - */ - -template -typename detail::UniqueSelector::SingleObject -MakeUnique(Args&&... aArgs) -{ - return UniquePtr(new T(Forward(aArgs)...)); -} - -template -typename detail::UniqueSelector::UnknownBound -MakeUnique(decltype(sizeof(int)) aN) -{ - typedef typename RemoveExtent::Type ArrayType; - return UniquePtr(new ArrayType[aN]()); -} - -template -typename detail::UniqueSelector::KnownBound -MakeUnique(Args&&... aArgs) = delete; - -} // namespace mozilla - -#endif /* mozilla_UniquePtr_h */ diff --git a/onlineupdate/source/update/inc/mozilla/nsTraceRefcnt.h b/onlineupdate/source/update/inc/mozilla/nsTraceRefcnt.h deleted file mode 100644 index c5b1de7e806a..000000000000 --- a/onlineupdate/source/update/inc/mozilla/nsTraceRefcnt.h +++ /dev/null @@ -1,67 +0,0 @@ -/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* vim: set ts=8 sts=2 et sw=2 tw=80: */ -/* This Source Code Form is subject to the terms of the Mozilla Public - * 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/. */ -#ifndef nsTraceRefcnt_h___ -#define nsTraceRefcnt_h___ - -#include // for FILE -#include "nscore.h" - -class nsTraceRefcnt -{ -public: - static void Shutdown(); - - enum StatisticsType { - ALL_STATS, - NEW_STATS - }; - - static nsresult DumpStatistics(StatisticsType aType = ALL_STATS, - FILE* aOut = 0); - - static void ResetStatistics(); - - static void DemangleSymbol(const char* aSymbol, char* aBuffer, int aBufLen); - - static void WalkTheStack(FILE* aStream); - - /** - * This is a variant of |WalkTheStack| that uses |CodeAddressService| to cache - * the results of |NS_DescribeCodeAddress|. If |WalkTheStackCached| is being - * called frequently, it will be a few orders of magnitude faster than - * |WalkTheStack|. However, the cache uses a lot of memory, which can cause - * OOM crashes. Therefore, this should only be used for things like refcount - * logging which walk the stack extremely frequently. - */ - static void WalkTheStackCached(FILE* aStream); - - /** - * Tell nsTraceRefcnt whether refcounting, allocation, and destruction - * activity is legal. This is used to trigger assertions for any such - * activity that occurs because of static constructors or destructors. - */ - static void SetActivityIsLegal(bool aLegal); -}; - -#define NS_TRACE_REFCNT_CONTRACTID "@mozilla.org/xpcom/trace-refcnt;1" -#define NS_TRACE_REFCNT_CID \ -{ /* e3e7511e-a395-4924-94b1-d527861cded4 */ \ - 0xe3e7511e, \ - 0xa395, \ - 0x4924, \ - {0x94, 0xb1, 0xd5, 0x27, 0x86, 0x1c, 0xde, 0xd4} \ -} \ - -//////////////////////////////////////////////////////////////////////////////// -// And now for that utility that you've all been asking for... - -extern "C" void -NS_MeanAndStdDev(double aNumberOfValues, - double aSumOfValues, double aSumOfSquaredValues, - double* aMeanResult, double* aStdDevResult); - -//////////////////////////////////////////////////////////////////////////////// -#endif diff --git a/onlineupdate/source/update/inc/nsAutoRef.h b/onlineupdate/source/update/inc/nsAutoRef.h deleted file mode 100644 index a159f5954e96..000000000000 --- a/onlineupdate/source/update/inc/nsAutoRef.h +++ /dev/null @@ -1,670 +0,0 @@ -/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* vim: set ts=8 sts=2 et sw=2 tw=80: */ -/* This Source Code Form is subject to the terms of the Mozilla Public - * 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/. */ - -#ifndef nsAutoRef_h_ -#define nsAutoRef_h_ - -#include "mozilla/Attributes.h" - -template class nsSimpleRef; -template class nsAutoRefBase; -template class nsReturnRef; -template class nsReturningRef; - -/** - * template class nsAutoRef - * - * A class that holds a handle to a resource that must be released. - * No reference is added on construction. - * - * No copy constructor nor copy assignment operators are available, so the - * resource will be held until released on destruction or explicitly - * |reset()| or transferred through provided methods. - * - * The publicly available methods are the public methods on this class and its - * public base classes |nsAutoRefBase| and |nsSimpleRef|. - * - * For ref-counted resources see also |nsCountedRef|. - * For function return values see |nsReturnRef|. - * - * For each class |T|, |nsAutoRefTraits| or |nsSimpleRef| must be - * specialized to use |nsAutoRef| and |nsCountedRef|. - * - * @param T A class identifying the type of reference held by the - * |nsAutoRef| and the unique set methods for managing references - * to the resource (defined by |nsAutoRefTraits| or - * |nsSimpleRef|). - * - * Often this is the class representing the resource. Sometimes a - * new possibly-incomplete class may need to be declared. - * - * - * Example: An Automatically closing file descriptor - * - * // References that are simple integral types (as file-descriptors are) - * // usually need a new class to represent the resource and how to handle its - * // references. - * class nsRawFD; - * - * // Specializing nsAutoRefTraits describes how to manage file - * // descriptors, so that nsAutoRef provides automatic closing of - * // its file descriptor on destruction. - * template <> - * class nsAutoRefTraits { - * public: - * // The file descriptor is held in an int. - * typedef int RawRef; - * // -1 means that there is no file associated with the handle. - * static int Void() { return -1; } - * // The file associated with a file descriptor is released with close(). - * static void Release(RawRef aFD) { close(aFD); } - * }; - * - * // A function returning a file descriptor that must be closed. - * nsReturnRef get_file(const char *filename) { - * // Constructing from a raw file descriptor assumes ownership. - * nsAutoRef fd(open(filename, O_RDONLY)); - * fcntl(fd, F_SETFD, FD_CLOEXEC); - * return fd.out(); - * } - * - * void f() { - * unsigned char buf[1024]; - * - * // Hold a file descriptor for /etc/hosts in fd1. - * nsAutoRef fd1(get_file("/etc/hosts")); - * - * nsAutoRef fd2; - * fd2.steal(fd1); // fd2 takes the file descriptor from fd1 - * ssize_t count = read(fd1, buf, 1024); // error fd1 has no file - * count = read(fd2, buf, 1024); // reads from /etc/hosts - * - * // If the file descriptor is not stored then it is closed. - * get_file("/etc/login.defs"); // login.defs is closed - * - * // Now use fd1 to hold a file descriptor for /etc/passwd. - * fd1 = get_file("/etc/passwd"); - * - * // The nsAutoRef can give up the file descriptor if explicitly - * // instructed, but the caller must then ensure that the file is closed. - * int rawfd = fd1.disown(); - * - * // Assume ownership of another file descriptor. - * fd1.own(open("/proc/1/maps"); - * - * // On destruction, fd1 closes /proc/1/maps and fd2 closes /etc/hosts, - * // but /etc/passwd is not closed. - * } - * - */ - - -template -class nsAutoRef : public nsAutoRefBase -{ -protected: - typedef nsAutoRef ThisClass; - typedef nsAutoRefBase BaseClass; - typedef nsSimpleRef SimpleRef; - typedef typename BaseClass::RawRefOnly RawRefOnly; - typedef typename BaseClass::LocalSimpleRef LocalSimpleRef; - -public: - nsAutoRef() - { - } - - // Explicit construction is required so as not to risk unintentionally - // releasing the resource associated with a raw ref. - explicit nsAutoRef(RawRefOnly aRefToRelease) - : BaseClass(aRefToRelease) - { - } - - // Construction from a nsReturnRef function return value, which expects - // to give up ownership, transfers ownership. - // (nsReturnRef is converted to const nsReturningRef.) - explicit nsAutoRef(const nsReturningRef& aReturning) - : BaseClass(aReturning) - { - } - - // The only assignment operator provided is for transferring from an - // nsReturnRef smart reference, which expects to pass its ownership to - // another object. - // - // With raw references and other smart references, the type of the lhs and - // its taking and releasing nature is often not obvious from an assignment - // statement. Assignment from a raw ptr especially is not normally - // expected to release the reference. - // - // Use |steal| for taking ownership from other smart refs. - // - // For raw references, use |own| to indicate intention to have the - // resource released. - // - // Or, to create another owner of the same reference, use an nsCountedRef. - - ThisClass& operator=(const nsReturningRef& aReturning) - { - BaseClass::steal(aReturning.mReturnRef); - return *this; - } - - // Conversion to a raw reference allow the nsAutoRef to often be used - // like a raw reference. - operator typename SimpleRef::RawRef() const - { - return this->get(); - } - - // Transfer ownership from another smart reference. - void steal(ThisClass& aOtherRef) - { - BaseClass::steal(aOtherRef); - } - - // Assume ownership of a raw ref. - // - // |own| has similar function to |steal|, and is useful for receiving - // ownership from a return value of a function. It is named differently - // because |own| requires more care to ensure that the function intends to - // give away ownership, and so that |steal| can be safely used, knowing - // that it won't steal ownership from any methods returning raw ptrs to - // data owned by a foreign object. - void own(RawRefOnly aRefToRelease) - { - BaseClass::own(aRefToRelease); - } - - // Exchange ownership with |aOther| - void swap(ThisClass& aOther) - { - LocalSimpleRef temp; - temp.SimpleRef::operator=(*this); - SimpleRef::operator=(aOther); - aOther.SimpleRef::operator=(temp); - } - - // Release the reference now. - void reset() - { - this->SafeRelease(); - LocalSimpleRef empty; - SimpleRef::operator=(empty); - } - - // Pass out the reference for a function return values. - nsReturnRef out() - { - return nsReturnRef(this->disown()); - } - - // operator->() and disown() are provided by nsAutoRefBase. - // The default nsSimpleRef provides get(). - -private: - // No copy constructor - explicit nsAutoRef(ThisClass& aRefToSteal); -}; - -/** - * template class nsCountedRef - * - * A class that creates (adds) a new reference to a resource on construction - * or assignment and releases on destruction. - * - * This class is similar to nsAutoRef and inherits its methods, but also - * provides copy construction and assignment operators that enable more than - * one concurrent reference to the same resource. - * - * Specialize |nsAutoRefTraits| or |nsSimpleRef| to use this. This - * class assumes that the resource itself counts references and so can only be - * used when |T| represents a reference-counting resource. - */ - -template -class nsCountedRef : public nsAutoRef -{ -protected: - typedef nsCountedRef ThisClass; - typedef nsAutoRef BaseClass; - typedef nsSimpleRef SimpleRef; - typedef typename BaseClass::RawRef RawRef; - -public: - nsCountedRef() - { - } - - // Construction and assignment from a another nsCountedRef - // or a raw ref copies and increments the ref count. - nsCountedRef(const ThisClass& aRefToCopy) - { - SimpleRef::operator=(aRefToCopy); - SafeAddRef(); - } - ThisClass& operator=(const ThisClass& aRefToCopy) - { - if (this == &aRefToCopy) { - return *this; - } - - this->SafeRelease(); - SimpleRef::operator=(aRefToCopy); - SafeAddRef(); - return *this; - } - - // Implicit conversion from another smart ref argument (to a raw ref) is - // accepted here because construction and assignment safely creates a new - // reference without interfering with the reference to copy. - explicit nsCountedRef(RawRef aRefToCopy) - : BaseClass(aRefToCopy) - { - SafeAddRef(); - } - ThisClass& operator=(RawRef aRefToCopy) - { - this->own(aRefToCopy); - SafeAddRef(); - return *this; - } - - // Construction and assignment from an nsReturnRef function return value, - // which expects to give up ownership, transfers ownership. - explicit nsCountedRef(const nsReturningRef& aReturning) - : BaseClass(aReturning) - { - } - ThisClass& operator=(const nsReturningRef& aReturning) - { - BaseClass::operator=(aReturning); - return *this; - } - -protected: - // Increase the reference count if there is a resource. - void SafeAddRef() - { - if (this->HaveResource()) { - this->AddRef(this->get()); - } - } -}; - -/** - * template class nsReturnRef - * - * A type for function return values that hold a reference to a resource that - * must be released. See also |nsAutoRef::out()|. - */ - -template -class nsReturnRef : public nsAutoRefBase -{ -protected: - typedef nsAutoRefBase BaseClass; - typedef typename BaseClass::RawRefOnly RawRefOnly; - -public: - // For constructing a return value with no resource - nsReturnRef() - { - } - - // For returning a smart reference from a raw reference that must be - // released. Explicit construction is required so as not to risk - // unintentionally releasing the resource associated with a raw ref. - MOZ_IMPLICIT nsReturnRef(RawRefOnly aRefToRelease) - : BaseClass(aRefToRelease) - { - } - - // Copy construction transfers ownership - nsReturnRef(nsReturnRef& aRefToSteal) - : BaseClass(aRefToSteal) - { - } - - MOZ_IMPLICIT nsReturnRef(const nsReturningRef& aReturning) - : BaseClass(aReturning) - { - } - - // Conversion to a temporary (const) object referring to this object so - // that the reference may be passed from a function return value - // (temporary) to another smart reference. There is no need to use this - // explicitly. Simply assign a nsReturnRef function return value to a - // smart reference. - operator nsReturningRef() - { - return nsReturningRef(*this); - } - - // No conversion to RawRef operator is provided on nsReturnRef, to ensure - // that the return value is not carelessly assigned to a raw ptr (and the - // resource then released). If passing to a function that takes a raw - // ptr, use get or disown as appropriate. -}; - -/** - * template class nsReturningRef - * - * A class to allow ownership to be transferred from nsReturnRef function - * return values. - * - * It should not be necessary for clients to reference this - * class directly. Simply pass an nsReturnRef to a parameter taking an - * |nsReturningRef|. - * - * The conversion operator on nsReturnRef constructs a temporary wrapper of - * class nsReturningRef around a non-const reference to the nsReturnRef. - * The wrapper can then be passed as an rvalue parameter. - */ - -template -class nsReturningRef -{ -private: - friend class nsReturnRef; - - explicit nsReturningRef(nsReturnRef& aReturnRef) - : mReturnRef(aReturnRef) - { - } -public: - nsReturnRef& mReturnRef; -}; - -/** - * template class nsAutoRefTraits - * - * A class describing traits of references managed by the default - * |nsSimpleRef| implementation and thus |nsAutoRef| and |nsCountedRef|. - * The default |nsSimpleRef is suitable for resources with handles that - * have a void value. (If there is no such void value for a handle, - * specialize |nsSimpleRef|.) - * - * Specializations must be provided for each class |T| according to the - * following pattern: - * - * // The template parameter |T| should be a class such that the set of fields - * // in class nsAutoRefTraits is unique for class |T|. Usually the - * // resource object class is sufficient. For handles that are simple - * // integral typedefs, a new unique possibly-incomplete class may need to be - * // declared. - * - * template <> - * class nsAutoRefTraits - * { - * // Specializations must provide a typedef for RawRef, describing the - * // type of the handle to the resource. - * typedef RawRef; - * - * // Specializations should define Void(), a function returning a value - * // suitable for a handle that does not have an associated resource. - * // - * // The return type must be a suitable as the parameter to a RawRef - * // constructor and operator==. - * // - * // If this method is not accessible then some limited nsAutoRef - * // functionality will still be available, but the default constructor, - * // |reset|, and most transfer of ownership methods will not be available. - * static Void(); - * - * // Specializations must define Release() to properly finalize the - * // handle to a non-void custom-deleted or reference-counted resource. - * static void Release(RawRef aRawRef); - * - * // For reference-counted resources, if |nsCountedRef| is to be used, - * // specializations must define AddRef to increment the reference count - * // held by a non-void handle. - * // (AddRef() is not necessary for |nsAutoRef|.) - * static void AddRef(RawRef aRawRef); - * }; - * - * See nsPointerRefTraits for example specializations for simple pointer - * references. See nsAutoRef for an example specialization for a non-pointer - * reference. - */ - -template class nsAutoRefTraits; - -/** - * template class nsPointerRefTraits - * - * A convenience class useful as a base class for specializations of - * |nsAutoRefTraits| where the handle to the resource is a pointer to |T|. - * By inheriting from this class, definitions of only Release(RawRef) and - * possibly AddRef(RawRef) need to be added. - * - * Examples of use: - * - * template <> - * class nsAutoRefTraits : public nsPointerRefTraits - * { - * public: - * static void Release(PRFileDesc *ptr) { PR_Close(ptr); } - * }; - * - * template <> - * class nsAutoRefTraits : public nsPointerRefTraits - * { - * public: - * static void Release(FcPattern *ptr) { FcPatternDestroy(ptr); } - * static void AddRef(FcPattern *ptr) { FcPatternReference(ptr); } - * }; - */ - -template -class nsPointerRefTraits -{ -public: - // The handle is a pointer to T. - typedef T* RawRef; - // A nullptr does not have a resource. - static RawRef Void() - { - return nullptr; - } -}; - -/** - * template class nsSimpleRef - * - * Constructs a non-smart reference, and provides methods to test whether - * there is an associated resource and (if so) get its raw handle. - * - * A default implementation is suitable for resources with handles that have a - * void value. This is not intended for direct use but used by |nsAutoRef| - * and thus |nsCountedRef|. - * - * Specialize this class if there is no particular void value for the resource - * handle. A specialized implementation must also provide Release(RawRef), - * and, if |nsCountedRef| is required, AddRef(RawRef), as described in - * nsAutoRefTraits. - */ - -template -class nsSimpleRef : protected nsAutoRefTraits -{ -protected: - // The default implementation uses nsAutoRefTrait. - // Specializations need not define this typedef. - typedef nsAutoRefTraits Traits; - // The type of the handle to the resource. - // A specialization must provide a typedef for RawRef. - typedef typename Traits::RawRef RawRef; - - // Construct with no resource. - // - // If this constructor is not accessible then some limited nsAutoRef - // functionality will still be available, but the default constructor, - // |reset|, and most transfer of ownership methods will not be available. - nsSimpleRef() - : mRawRef(Traits::Void()) - { - } - // Construct with a handle to a resource. - // A specialization must provide this. - explicit nsSimpleRef(RawRef aRawRef) - : mRawRef(aRawRef) - { - } - - // Test whether there is an associated resource. A specialization must - // provide this. The function is permitted to always return true if the - // default constructor is not accessible, or if Release (and AddRef) can - // deal with void handles. - bool HaveResource() const - { - return mRawRef != Traits::Void(); - } - -public: - // A specialization must provide get() or loose some functionality. This - // is inherited by derived classes and the specialization may choose - // whether it is public or protected. - RawRef get() const - { - return mRawRef; - } - -private: - RawRef mRawRef; -}; - - -/** - * template class nsAutoRefBase - * - * Internal base class for |nsAutoRef| and |nsReturnRef|. - * Adds release on destruction to a |nsSimpleRef|. - */ - -template -class nsAutoRefBase : public nsSimpleRef -{ -protected: - typedef nsAutoRefBase ThisClass; - typedef nsSimpleRef SimpleRef; - typedef typename SimpleRef::RawRef RawRef; - - nsAutoRefBase() - { - } - - // A type for parameters that should be passed a raw ref but should not - // accept implicit conversions (from another smart ref). (The only - // conversion to this type is from a raw ref so only raw refs will be - // accepted.) - class RawRefOnly - { - public: - MOZ_IMPLICIT RawRefOnly(RawRef aRawRef) - : mRawRef(aRawRef) - { - } - operator RawRef() const - { - return mRawRef; - } - private: - RawRef mRawRef; - }; - - // Construction from a raw ref assumes ownership - explicit nsAutoRefBase(RawRefOnly aRefToRelease) - : SimpleRef(aRefToRelease) - { - } - - // Constructors that steal ownership - explicit nsAutoRefBase(ThisClass& aRefToSteal) - : SimpleRef(aRefToSteal.disown()) - { - } - explicit nsAutoRefBase(const nsReturningRef& aReturning) - : SimpleRef(aReturning.mReturnRef.disown()) - { - } - - ~nsAutoRefBase() - { - SafeRelease(); - } - - // An internal class providing access to protected nsSimpleRef - // constructors for construction of temporary simple references (that are - // not ThisClass). - class LocalSimpleRef : public SimpleRef - { - public: - LocalSimpleRef() - { - } - explicit LocalSimpleRef(RawRef aRawRef) - : SimpleRef(aRawRef) - { - } - }; - -private: - ThisClass& operator=(const ThisClass& aSmartRef) = delete; - -public: - RawRef operator->() const - { - return this->get(); - } - - // Transfer ownership to a raw reference. - // - // THE CALLER MUST ENSURE THAT THE REFERENCE IS EXPLICITLY RELEASED. - // - // Is this really what you want to use? Using this removes any guarantee - // of release. Use nsAutoRef::out() for return values, or an - // nsAutoRef modifiable lvalue for an out parameter. Use disown() when - // the reference must be stored in a POD type object, such as may be - // preferred for a namespace-scope object with static storage duration, - // for example. - RawRef disown() - { - RawRef temp = this->get(); - LocalSimpleRef empty; - SimpleRef::operator=(empty); - return temp; - } - -protected: - // steal and own are protected because they make no sense on nsReturnRef, - // but steal is implemented on this class for access to aOtherRef.disown() - // when aOtherRef is an nsReturnRef; - - // Transfer ownership from another smart reference. - void steal(ThisClass& aOtherRef) - { - own(aOtherRef.disown()); - } - // Assume ownership of a raw ref. - void own(RawRefOnly aRefToRelease) - { - SafeRelease(); - LocalSimpleRef ref(aRefToRelease); - SimpleRef::operator=(ref); - } - - // Release a resource if there is one. - void SafeRelease() - { - if (this->HaveResource()) { - this->Release(this->get()); - } - } -}; - -#endif // !defined(nsAutoRef_h_) diff --git a/onlineupdate/source/update/inc/nsWindowsHelpers.h b/onlineupdate/source/update/inc/nsWindowsHelpers.h deleted file mode 100644 index 76a3aeb6585c..000000000000 --- a/onlineupdate/source/update/inc/nsWindowsHelpers.h +++ /dev/null @@ -1,153 +0,0 @@ -/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* vim: set ts=8 sts=2 et sw=2 tw=80: */ -/* This Source Code Form is subject to the terms of the Mozilla Public - * 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/. */ - -#ifndef nsWindowsHelpers_h -#define nsWindowsHelpers_h - -#include -#include "nsAutoRef.h" - -// Critical Section helper class - -class AutoCriticalSection -{ -public: - AutoCriticalSection(LPCRITICAL_SECTION aSection) - : mSection(aSection) - { - ::EnterCriticalSection(mSection); - } - ~AutoCriticalSection() - { - ::LeaveCriticalSection(mSection); - } -private: - LPCRITICAL_SECTION mSection; -}; - -template<> -class nsAutoRefTraits -{ -public: - typedef HKEY RawRef; - static HKEY Void() - { - return nullptr; - } - - static void Release(RawRef aFD) - { - if (aFD != Void()) { - RegCloseKey(aFD); - } - } -}; - -template<> -class nsAutoRefTraits -{ -public: - typedef SC_HANDLE RawRef; - static SC_HANDLE Void() - { - return nullptr; - } - - static void Release(RawRef aFD) - { - if (aFD != Void()) { - CloseServiceHandle(aFD); - } - } -}; - -template<> -class nsSimpleRef -{ -protected: - typedef HANDLE RawRef; - - nsSimpleRef() : mRawRef(nullptr) - { - } - - nsSimpleRef(RawRef aRawRef) : mRawRef(aRawRef) - { - } - - bool HaveResource() const - { - return mRawRef && mRawRef != INVALID_HANDLE_VALUE; - } - -public: - RawRef get() const - { - return mRawRef; - } - - static void Release(RawRef aRawRef) - { - if (aRawRef && aRawRef != INVALID_HANDLE_VALUE) { - CloseHandle(aRawRef); - } - } - RawRef mRawRef; -}; - - -template<> -class nsAutoRefTraits -{ -public: - typedef HMODULE RawRef; - static RawRef Void() - { - return nullptr; - } - - static void Release(RawRef aFD) - { - if (aFD != Void()) { - FreeLibrary(aFD); - } - } -}; - - -namespace { - -HMODULE inline -LoadLibrarySystem32(LPCWSTR aModule) -{ - WCHAR systemPath[MAX_PATH + 1] = { L'\0' }; - - // If GetSystemPath fails we accept that we'll load the DLLs from the - // normal search path. - GetSystemDirectoryW(systemPath, MAX_PATH + 1); - size_t systemDirLen = wcslen(systemPath); - - // Make the system directory path terminate with a slash - if (systemDirLen && systemPath[systemDirLen - 1] != L'\\') { - systemPath[systemDirLen] = L'\\'; - ++systemDirLen; - // No need to re-nullptr terminate - } - - size_t fileLen = wcslen(aModule); - wcsncpy(systemPath + systemDirLen, aModule, - MAX_PATH - systemDirLen); - if (systemDirLen + fileLen <= MAX_PATH) { - systemPath[systemDirLen + fileLen] = L'\0'; - } else { - systemPath[MAX_PATH] = L'\0'; - } - return LoadLibraryW(systemPath); -} - -} - -#endif diff --git a/onlineupdate/source/update/src/Makefile.in b/onlineupdate/source/update/src/Makefile.in deleted file mode 100644 index 1da582e5be03..000000000000 --- a/onlineupdate/source/update/src/Makefile.in +++ /dev/null @@ -1,13 +0,0 @@ -# vim:set ts=8 sw=8 sts=8 noet: -# -# This Source Code Form is subject to the terms of the Mozilla Public -# 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/. - -# This makefile just builds support for reading archives. - -include $(topsrcdir)/config/rules.mk - -# The intermediate (.ii/.s) files for host and target can have the same name... -# disable parallel builds -.NOTPARALLEL: diff --git a/onlineupdate/source/update/src/mar.h b/onlineupdate/source/update/src/mar.h deleted file mode 100644 index 0e21efb920a5..000000000000 --- a/onlineupdate/source/update/src/mar.h +++ /dev/null @@ -1,198 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* vim:set ts=2 sw=2 sts=2 et cindent: */ -/* This Source Code Form is subject to the terms of the Mozilla Public - * 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/. */ - -#ifndef MAR_H__ -#define MAR_H__ - -#include "mozilla/Assertions.h" -#include - -#ifdef __cplusplus -extern "C" { -#endif - -/* We have a MAX_SIGNATURES limit so that an invalid MAR will never - * waste too much of either updater's or signmar's time. - * It is also used at various places internally and will affect memory usage. - * If you want to increase this value above 9 then you need to adjust parsing - * code in tool/mar.c. -*/ -#define MAX_SIGNATURES 8 -#ifdef __cplusplus -static_assert(MAX_SIGNATURES <= 9, "too many signatures"); -#else -MOZ_STATIC_ASSERT(MAX_SIGNATURES <= 9, "too many signatures"); -#endif - -struct ProductInformationBlock { - const char *MARChannelID; - const char *productVersion; -}; - -/** - * The MAR item data structure. - */ -typedef struct MarItem_ { - struct MarItem_ *next; /* private field */ - uint32_t offset; /* offset into archive */ - uint32_t length; /* length of data in bytes */ - uint32_t flags; /* contains file mode bits */ - char name[1]; /* file path */ -} MarItem; - -#define TABLESIZE 256 - -struct MarFile_ { - FILE *fp; - MarItem *item_table[TABLESIZE]; -}; - -typedef struct MarFile_ MarFile; - -/** - * Signature of callback function passed to mar_enum_items. - * @param mar The MAR file being visited. - * @param item The MAR item being visited. - * @param data The data parameter passed by the caller of mar_enum_items. - * @return A non-zero value to stop enumerating. - */ -typedef int (* MarItemCallback)(MarFile *mar, const MarItem *item, void *data); - -/** - * Open a MAR file for reading. - * @param path Specifies the path to the MAR file to open. This path must - * be compatible with fopen. - * @return NULL if an error occurs. - */ -MarFile *mar_open(const char *path); - -#ifdef _WIN32 -MarFile *mar_wopen(const wchar_t *path); -#endif - -/** - * Close a MAR file that was opened using mar_open. - * @param mar The MarFile object to close. - */ -void mar_close(MarFile *mar); - -/** - * Find an item in the MAR file by name. - * @param mar The MarFile object to query. - * @param item The name of the item to query. - * @return A const reference to a MAR item or NULL if not found. - */ -const MarItem *mar_find_item(MarFile *mar, const char *item); - -/** - * Enumerate all MAR items via callback function. - * @param mar The MAR file to enumerate. - * @param callback The function to call for each MAR item. - * @param data A caller specified value that is passed along to the - * callback function. - * @return 0 if the enumeration ran to completion. Otherwise, any - * non-zero return value from the callback is returned. - */ -int mar_enum_items(MarFile *mar, MarItemCallback callback, void *data); - -/** - * Read from MAR item at given offset up to bufsize bytes. - * @param mar The MAR file to read. - * @param item The MAR item to read. - * @param offset The byte offset relative to the start of the item. - * @param buf A pointer to a buffer to copy the data into. - * @param bufsize The length of the buffer to copy the data into. - * @return The number of bytes written or a negative value if an - * error occurs. - */ -int mar_read(MarFile *mar, const MarItem *item, int offset, char *buf, - int bufsize); - -/** - * Create a MAR file from a set of files. - * @param dest The path to the file to create. This path must be - * compatible with fopen. - * @param numfiles The number of files to store in the archive. - * @param files The list of null-terminated file paths. Each file - * path must be compatible with fopen. - * @param infoBlock The information to store in the product information block. - * @return A non-zero value if an error occurs. - */ -int mar_create(const char *dest, - int numfiles, - char **files, - struct ProductInformationBlock *infoBlock); - -/** - * Extract a MAR file to the current working directory. - * @param path The path to the MAR file to extract. This path must be - * compatible with fopen. - * @return A non-zero value if an error occurs. - */ -int mar_extract(const char *path); - -#define MAR_MAX_CERT_SIZE (16*1024) // Way larger than necessary - -/* Read the entire file (not a MAR file) into a newly-allocated buffer. - * This function does not write to stderr. Instead, the caller should - * write whatever error messages it sees fit. The caller must free the returned - * buffer using free(). - * - * @param filePath The path to the file that should be read. - * @param maxSize The maximum valid file size. - * @param data On success, *data will point to a newly-allocated buffer - * with the file's contents in it. - * @param size On success, *size will be the size of the created buffer. - * - * @return 0 on success, -1 on error - */ -int mar_read_entire_file(const char * filePath, - uint32_t maxSize, - /*out*/ const uint8_t * *data, - /*out*/ uint32_t *size); - -/** - * Verifies a MAR file by verifying each signature with the corresponding - * certificate. That is, the first signature will be verified using the first - * certificate given, the second signature will be verified using the second - * certificate given, etc. The signature count must exactly match the number of - * certificates given, and all signature verifications must succeed. - * We do not check that the certificate was issued by any trusted authority. - * We assume it to be self-signed. We do not check whether the certificate - * is valid for this usage. - * - * @param mar The already opened MAR file. - * @param certData Pointer to the first element in an array of certificate - * file data. - * @param certDataSizes Pointer to the first element in an array for size of - * the cert data. - * @param certCount The number of elements in certData and certDataSizes - * @return 0 on success - * a negative number if there was an error - * a positive number if the signature does not verify - */ -int mar_verify_signatures(MarFile *mar, - const uint8_t * const *certData, - const uint32_t *certDataSizes, - uint32_t certCount); - -/** - * Reads the product info block from the MAR file's additional block section. - * The caller is responsible for freeing the fields in infoBlock - * if the return is successful. - * - * @param infoBlock Out parameter for where to store the result to - * @return 0 on success, -1 on failure -*/ -int -mar_read_product_info_block(MarFile *mar, - struct ProductInformationBlock *infoBlock); - -#ifdef __cplusplus -} -#endif - -#endif /* MAR_H__ */ diff --git a/onlineupdate/source/update/src/mar_cmdline.h b/onlineupdate/source/update/src/mar_cmdline.h deleted file mode 100644 index ef6867f06fc3..000000000000 --- a/onlineupdate/source/update/src/mar_cmdline.h +++ /dev/null @@ -1,110 +0,0 @@ -/* This Source Code Form is subject to the terms of the Mozilla Public - * 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/. */ - -#ifndef MAR_CMDLINE_H__ -#define MAR_CMDLINE_H__ - -/* We use NSPR here just to import the definition of uint32_t */ - -#ifdef __cplusplus -extern "C" { -#endif - -struct ProductInformationBlock; - -/** - * Determines MAR file information. - * - * @param path The path of the MAR file to check. - * @param hasSignatureBlock Optional out parameter specifying if the MAR - * file has a signature block or not. - * @param numSignatures Optional out parameter for storing the number - * of signatures in the MAR file. - * @param hasAdditionalBlocks Optional out parameter specifying if the MAR - * file has additional blocks or not. - * @param offsetAdditionalBlocks Optional out parameter for the offset to the - * first additional block. Value is only valid if - * hasAdditionalBlocks is not equal to 0. - * @param numAdditionalBlocks Optional out parameter for the number of - * additional blocks. Value is only valid if - * has_additional_blocks is not equal to 0. - * @return 0 on success and non-zero on failure. - */ -int get_mar_file_info(const char *path, - int *hasSignatureBlock, - uint32_t *numSignatures, - int *hasAdditionalBlocks, - uint32_t *offsetAdditionalBlocks, - uint32_t *numAdditionalBlocks); - -/** - * Reads the product info block from the MAR file's additional block section. - * The caller is responsible for freeing the fields in infoBlock - * if the return is successful. - * - * @param infoBlock Out parameter for where to store the result to - * @return 0 on success, -1 on failure -*/ -int -read_product_info_block(char *path, - struct ProductInformationBlock *infoBlock); - -/** - * Refreshes the product information block with the new information. - * The input MAR must not be signed or the function call will fail. - * - * @param path The path to the MAR file whose product info block - * should be refreshed. - * @param infoBlock Out parameter for where to store the result to - * @return 0 on success, -1 on failure -*/ -int -refresh_product_info_block(const char *path, - struct ProductInformationBlock *infoBlock); - -/** - * Writes out a copy of the MAR at src but with the signature block stripped. - * - * @param src The path of the source MAR file - * @param dest The path of the MAR file to write out that - has no signature block - * @return 0 on success - * -1 on error -*/ -int -strip_signature_block(const char *src, const char * dest); - -/** - * Extracts a signature from a MAR file, base64 encodes it, and writes it out - * - * @param src The path of the source MAR file - * @param sigIndex The index of the signature to extract - * @param dest The path of file to write the signature to - * @return 0 on success - * -1 on error -*/ -int -extract_signature(const char *src, uint32_t sigIndex, const char * dest); - -/** - * Imports a base64 encoded signature into a MAR file - * - * @param src The path of the source MAR file - * @param sigIndex The index of the signature to import - * @param base64SigFile A file which contains the signature to import - * @param dest The path of the destination MAR file with replaced signature - * @return 0 on success - * -1 on error -*/ -int -import_signature(const char *src, - uint32_t sigIndex, - const char * base64SigFile, - const char *dest); - -#ifdef __cplusplus -} -#endif - -#endif /* MAR_CMDLINE_H__ */ diff --git a/onlineupdate/source/update/src/mar_create.c b/onlineupdate/source/update/src/mar_create.c deleted file mode 100644 index 4e4e2b4058c2..000000000000 --- a/onlineupdate/source/update/src/mar_create.c +++ /dev/null @@ -1,398 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* vim:set ts=2 sw=2 sts=2 et cindent: */ -/* This Source Code Form is subject to the terms of the Mozilla Public - * 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 -#include -#include -#include -#include -#include "mar_private.h" -#include "mar_cmdline.h" -#include "mar.h" - -#ifdef _WIN32 -#include -#else -#include -#include -#endif - -struct MarItemStack { - void *head; - uint32_t size_used; - uint32_t size_allocated; - uint32_t last_offset; -}; - -/** - * Push a new item onto the stack of items. The stack is a single block - * of memory. - */ -static int mar_push(struct MarItemStack *stack, uint32_t length, uint32_t flags, - const char *name) { - int namelen; - uint32_t n_offset, n_length, n_flags; - uint32_t size; - char *data; - - namelen = strlen(name); - size = MAR_ITEM_SIZE(namelen); - - if (stack->size_allocated - stack->size_used < size) { - /* increase size of stack */ - size_t size_needed = ROUND_UP(stack->size_used + size, BLOCKSIZE); - stack->head = realloc(stack->head, size_needed); - if (!stack->head) - return -1; - stack->size_allocated = size_needed; - } - - data = (((char *) stack->head) + stack->size_used); - - n_offset = htonl(stack->last_offset); - n_length = htonl(length); - n_flags = htonl(flags); - - memcpy(data, &n_offset, sizeof(n_offset)); - data += sizeof(n_offset); - - memcpy(data, &n_length, sizeof(n_length)); - data += sizeof(n_length); - - memcpy(data, &n_flags, sizeof(n_flags)); - data += sizeof(n_flags); - - memcpy(data, name, namelen + 1); - - stack->size_used += size; - stack->last_offset += length; - return 0; -} - -static int mar_concat_file(FILE *fp, const char *path) { - FILE *in; - char buf[BLOCKSIZE]; - size_t len; - int rv = 0; - - in = fopen(path, "rb"); - if (!in) { - fprintf(stderr, "ERROR: could not open file in mar_concat_file()\n"); - perror(path); - return -1; - } - - while ((len = fread(buf, 1, BLOCKSIZE, in)) > 0) { - if (fwrite(buf, len, 1, fp) != 1) { - rv = -1; - break; - } - } - - fclose(in); - return rv; -} - -/** - * Writes out the product information block to the specified file. - * - * @param fp The opened MAR file being created. - * @param stack A pointer to the MAR item stack being used to create - * the MAR - * @param infoBlock The product info block to store in the file. - * @return 0 on success. -*/ -static int -mar_concat_product_info_block(FILE *fp, - struct MarItemStack *stack, - struct ProductInformationBlock *infoBlock) -{ - char buf[PIB_MAX_MAR_CHANNEL_ID_SIZE + PIB_MAX_PRODUCT_VERSION_SIZE]; - uint32_t additionalBlockID = 1, infoBlockSize, unused; - if (!fp || !infoBlock || - !infoBlock->MARChannelID || - !infoBlock->productVersion) { - return -1; - } - - /* The MAR channel name must be < 64 bytes per the spec */ - if (strlen(infoBlock->MARChannelID) > PIB_MAX_MAR_CHANNEL_ID_SIZE) { - return -1; - } - - /* The product version must be < 32 bytes per the spec */ - if (strlen(infoBlock->productVersion) > PIB_MAX_PRODUCT_VERSION_SIZE) { - return -1; - } - - /* Although we don't need the product information block size to include the - maximum MAR channel name and product version, we allocate the maximum - amount to make it easier to modify the MAR file for repurposing MAR files - to different MAR channels. + 2 is for the NULL terminators. */ - infoBlockSize = sizeof(infoBlockSize) + - sizeof(additionalBlockID) + - PIB_MAX_MAR_CHANNEL_ID_SIZE + - PIB_MAX_PRODUCT_VERSION_SIZE + 2; - if (stack) { - stack->last_offset += infoBlockSize; - } - - /* Write out the product info block size */ - infoBlockSize = htonl(infoBlockSize); - if (fwrite(&infoBlockSize, - sizeof(infoBlockSize), 1, fp) != 1) { - return -1; - } - infoBlockSize = ntohl(infoBlockSize); - - /* Write out the product info block ID */ - additionalBlockID = htonl(additionalBlockID); - if (fwrite(&additionalBlockID, - sizeof(additionalBlockID), 1, fp) != 1) { - return -1; - } - additionalBlockID = ntohl(additionalBlockID); - - /* Write out the channel name and NULL terminator */ - if (fwrite(infoBlock->MARChannelID, - strlen(infoBlock->MARChannelID) + 1, 1, fp) != 1) { - return -1; - } - - /* Write out the product version string and NULL terminator */ - if (fwrite(infoBlock->productVersion, - strlen(infoBlock->productVersion) + 1, 1, fp) != 1) { - return -1; - } - - /* Write out the rest of the block that is unused */ - unused = infoBlockSize - (sizeof(infoBlockSize) + - sizeof(additionalBlockID) + - strlen(infoBlock->MARChannelID) + - strlen(infoBlock->productVersion) + 2); - memset(buf, 0, sizeof(buf)); - if (fwrite(buf, unused, 1, fp) != 1) { - return -1; - } - return 0; -} - -/** - * Refreshes the product information block with the new information. - * The input MAR must not be signed or the function call will fail. - * - * @param path The path to the MAR file whose product info block - * should be refreshed. - * @param infoBlock Out parameter for where to store the result to - * @return 0 on success, -1 on failure -*/ -int -refresh_product_info_block(const char *path, - struct ProductInformationBlock *infoBlock) -{ - FILE *fp ; - int rv; - uint32_t numSignatures, additionalBlockSize, additionalBlockID, - offsetAdditionalBlocks, numAdditionalBlocks, i; - int additionalBlocks, hasSignatureBlock; - - rv = get_mar_file_info(path, - &hasSignatureBlock, - &numSignatures, - &additionalBlocks, - &offsetAdditionalBlocks, - &numAdditionalBlocks); - if (rv) { - fprintf(stderr, "ERROR: Could not obtain MAR information.\n"); - return -1; - } - - if (hasSignatureBlock && numSignatures) { - fprintf(stderr, "ERROR: Cannot refresh a signed MAR\n"); - return -1; - } - - fp = fopen(path, "r+b"); - if (!fp) { - fprintf(stderr, "ERROR: could not open target file: %s\n", path); - return -1; - } - - if (fseeko(fp, offsetAdditionalBlocks, SEEK_SET)) { - fprintf(stderr, "ERROR: could not seek to additional blocks\n"); - fclose(fp); - return -1; - } - - for (i = 0; i < numAdditionalBlocks; ++i) { - /* Get the position of the start of this block */ - int64_t oldPos = ftello(fp); - - /* Read the additional block size */ - if (fread(&additionalBlockSize, - sizeof(additionalBlockSize), - 1, fp) != 1) { - fclose(fp); - return -1; - } - additionalBlockSize = ntohl(additionalBlockSize); - - /* Read the additional block ID */ - if (fread(&additionalBlockID, - sizeof(additionalBlockID), - 1, fp) != 1) { - fclose(fp); - return -1; - } - additionalBlockID = ntohl(additionalBlockID); - - if (PRODUCT_INFO_BLOCK_ID == additionalBlockID) { - if (fseeko(fp, oldPos, SEEK_SET)) { - fprintf(stderr, "Could not seek back to Product Information Block\n"); - fclose(fp); - return -1; - } - - if (mar_concat_product_info_block(fp, NULL, infoBlock)) { - fprintf(stderr, "Could not concat Product Information Block\n"); - fclose(fp); - return -1; - } - - fclose(fp); - return 0; - } else { - /* This is not the additional block you're looking for. Move along. */ - if (fseek(fp, additionalBlockSize, SEEK_CUR)) { - fprintf(stderr, "ERROR: Could not seek past current block.\n"); - fclose(fp); - return -1; - } - } - } - - /* If we had a product info block we would have already returned */ - fclose(fp); - fprintf(stderr, "ERROR: Could not refresh because block does not exist\n"); - return -1; -} - -/** - * Create a MAR file from a set of files. - * @param dest The path to the file to create. This path must be - * compatible with fopen. - * @param numfiles The number of files to store in the archive. - * @param files The list of null-terminated file paths. Each file - * path must be compatible with fopen. - * @param infoBlock The information to store in the product information block. - * @return A non-zero value if an error occurs. - */ -int mar_create(const char *dest, int - num_files, char **files, - struct ProductInformationBlock *infoBlock) { - struct MarItemStack stack; - uint32_t offset_to_index = 0, size_of_index, - numSignatures, numAdditionalSections; - uint64_t sizeOfEntireMAR = 0; - struct stat st; - FILE *fp; - int i, rv = -1; - - memset(&stack, 0, sizeof(stack)); - - fp = fopen(dest, "wb"); - if (!fp) { - fprintf(stderr, "ERROR: could not create target file: %s\n", dest); - return -1; - } - - if (fwrite(MAR_ID, MAR_ID_SIZE, 1, fp) != 1) - goto failure; - if (fwrite(&offset_to_index, sizeof(uint32_t), 1, fp) != 1) - goto failure; - - stack.last_offset = MAR_ID_SIZE + - sizeof(offset_to_index) + - sizeof(numSignatures) + - sizeof(numAdditionalSections) + - sizeof(sizeOfEntireMAR); - - /* We will circle back on this at the end of the MAR creation to fill it */ - if (fwrite(&sizeOfEntireMAR, sizeof(sizeOfEntireMAR), 1, fp) != 1) { - goto failure; - } - - /* Write out the number of signatures, for now only at most 1 is supported */ - numSignatures = 0; - if (fwrite(&numSignatures, sizeof(numSignatures), 1, fp) != 1) { - goto failure; - } - - /* Write out the number of additional sections, for now just 1 - for the product info block */ - numAdditionalSections = htonl(1); - if (fwrite(&numAdditionalSections, - sizeof(numAdditionalSections), 1, fp) != 1) { - goto failure; - } - numAdditionalSections = ntohl(numAdditionalSections); - - if (mar_concat_product_info_block(fp, &stack, infoBlock)) { - goto failure; - } - - for (i = 0; i < num_files; ++i) { - if (stat(files[i], &st)) { - fprintf(stderr, "ERROR: file not found: %s\n", files[i]); - goto failure; - } - - if (mar_push(&stack, st.st_size, st.st_mode & 0777, files[i])) - goto failure; - - /* concatenate input file to archive */ - if (mar_concat_file(fp, files[i])) - goto failure; - } - - /* write out the index (prefixed with length of index) */ - size_of_index = htonl(stack.size_used); - if (fwrite(&size_of_index, sizeof(size_of_index), 1, fp) != 1) - goto failure; - if (fwrite(stack.head, stack.size_used, 1, fp) != 1) - goto failure; - - /* To protect against invalid MAR files, we assumes that the MAR file - size is less than or equal to MAX_SIZE_OF_MAR_FILE. */ - if (ftell(fp) > MAX_SIZE_OF_MAR_FILE) { - goto failure; - } - - /* write out offset to index file in network byte order */ - offset_to_index = htonl(stack.last_offset); - if (fseek(fp, MAR_ID_SIZE, SEEK_SET)) - goto failure; - if (fwrite(&offset_to_index, sizeof(offset_to_index), 1, fp) != 1) - goto failure; - offset_to_index = ntohl(stack.last_offset); - - sizeOfEntireMAR = ((uint64_t)stack.last_offset) + - stack.size_used + - sizeof(size_of_index); - sizeOfEntireMAR = HOST_TO_NETWORK64(sizeOfEntireMAR); - if (fwrite(&sizeOfEntireMAR, sizeof(sizeOfEntireMAR), 1, fp) != 1) - goto failure; - sizeOfEntireMAR = NETWORK_TO_HOST64(sizeOfEntireMAR); - - rv = 0; -failure: - if (stack.head) - free(stack.head); - fclose(fp); - if (rv) - remove(dest); - return rv; -} diff --git a/onlineupdate/source/update/src/mar_extract.c b/onlineupdate/source/update/src/mar_extract.c deleted file mode 100644 index 75cbd645f296..000000000000 --- a/onlineupdate/source/update/src/mar_extract.c +++ /dev/null @@ -1,85 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* vim:set ts=2 sw=2 sts=2 et cindent: */ -/* This Source Code Form is subject to the terms of the Mozilla Public - * 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 -#include -#include -#include -#include -#include "mar_private.h" -#include "mar.h" - -#ifdef _WIN32 -#include -#include -#endif - -/* Ensure that the directory containing this file exists */ -static int mar_ensure_parent_dir(const char *path) -{ - char *slash = strrchr(path, '/'); - if (slash) - { - *slash = '\0'; - mar_ensure_parent_dir(path); -#ifdef _WIN32 - _mkdir(path); -#else - mkdir(path, 0755); -#endif - *slash = '/'; - } - return 0; -} - -static int mar_test_callback(MarFile *mar, const MarItem *item, void *unused) { - FILE *fp; - char buf[BLOCKSIZE]; - int fd, len, offset = 0; - - (void) unused; // avoid warnings - - if (mar_ensure_parent_dir(item->name)) - return -1; - -#ifdef _WIN32 - fd = _open(item->name, _O_BINARY|_O_CREAT|_O_TRUNC|_O_WRONLY, item->flags); -#else - fd = creat(item->name, item->flags); -#endif - if (fd == -1) { - fprintf(stderr, "ERROR: could not create file in mar_test_callback()\n"); - perror(item->name); - return -1; - } - - fp = fdopen(fd, "wb"); - if (!fp) - return -1; - - while ((len = mar_read(mar, item, offset, buf, sizeof(buf))) > 0) { - if (fwrite(buf, len, 1, fp) != 1) - break; - offset += len; - } - - fclose(fp); - return len == 0 ? 0 : -1; -} - -int mar_extract(const char *path) { - MarFile *mar; - int rv; - - mar = mar_open(path); - if (!mar) - return -1; - - rv = mar_enum_items(mar, mar_test_callback, NULL); - - mar_close(mar); - return rv; -} diff --git a/onlineupdate/source/update/src/mar_private.h b/onlineupdate/source/update/src/mar_private.h deleted file mode 100644 index a770998da6fe..000000000000 --- a/onlineupdate/source/update/src/mar_private.h +++ /dev/null @@ -1,79 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* vim:set ts=2 sw=2 sts=2 et cindent: */ -/* This Source Code Form is subject to the terms of the Mozilla Public - * 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/. */ - -#ifndef MAR_PRIVATE_H__ -#define MAR_PRIVATE_H__ - -#include "limits.h" -#include "mozilla/Assertions.h" -#include - -#define BLOCKSIZE 4096 -#define ROUND_UP(n, incr) (((n) / (incr) + 1) * (incr)) - -#define MAR_ID "MAR1" -#define MAR_ID_SIZE 4 - -/* The signature block comes directly after the header block - which is 16 bytes */ -#define SIGNATURE_BLOCK_OFFSET 16 - -/* Make sure the file is less than 500MB. We do this to protect against - invalid MAR files. */ -#define MAX_SIZE_OF_MAR_FILE ((int64_t)524288000) - -/* Existing code makes assumptions that the file size is - smaller than LONG_MAX. */ -MOZ_STATIC_ASSERT(MAX_SIZE_OF_MAR_FILE < ((int64_t)LONG_MAX), - "max mar file size is too big"); - -/* We store at most the size up to the signature block + 4 - bytes per BLOCKSIZE bytes */ -MOZ_STATIC_ASSERT(sizeof(BLOCKSIZE) < \ - (SIGNATURE_BLOCK_OFFSET + sizeof(uint32_t)), - "BLOCKSIZE is too big"); - -/* The maximum size of any signature supported by current and future - implementations of the signmar program. */ -#define MAX_SIGNATURE_LENGTH 2048 - -/* Each additional block has a unique ID. - The product information block has an ID of 1. */ -#define PRODUCT_INFO_BLOCK_ID 1 - -#define MAR_ITEM_SIZE(namelen) (3*sizeof(uint32_t) + (namelen) + 1) - -/* Product Information Block (PIB) constants */ -#define PIB_MAX_MAR_CHANNEL_ID_SIZE 63 -#define PIB_MAX_PRODUCT_VERSION_SIZE 31 - -/* The mar program is compiled as a host bin so we don't have access to NSPR at - runtime. For that reason we use ntohl, htonl, and define HOST_TO_NETWORK64 - instead of the NSPR equivalents. */ -#ifdef _WIN32 -#include -#define ftello _ftelli64 -#define fseeko _fseeki64 -#else -#define _FILE_OFFSET_BITS 64 -#include -#include -#endif - -#include - -#define HOST_TO_NETWORK64(x) ( \ - ((((uint64_t) x) & 0xFF) << 56) | \ - ((((uint64_t) x) >> 8) & 0xFF) << 48) | \ - (((((uint64_t) x) >> 16) & 0xFF) << 40) | \ - (((((uint64_t) x) >> 24) & 0xFF) << 32) | \ - (((((uint64_t) x) >> 32) & 0xFF) << 24) | \ - (((((uint64_t) x) >> 40) & 0xFF) << 16) | \ - (((((uint64_t) x) >> 48) & 0xFF) << 8) | \ - (((uint64_t) x) >> 56) -#define NETWORK_TO_HOST64 HOST_TO_NETWORK64 - -#endif /* MAR_PRIVATE_H__ */ diff --git a/onlineupdate/source/update/src/mar_read.c b/onlineupdate/source/update/src/mar_read.c deleted file mode 100644 index 0ed8c6be6ea9..000000000000 --- a/onlineupdate/source/update/src/mar_read.c +++ /dev/null @@ -1,572 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* vim:set ts=2 sw=2 sts=2 et cindent: */ -/* This Source Code Form is subject to the terms of the Mozilla Public - * 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 -#include -#include -#include -#include "mar_private.h" -#include "mar.h" - -#ifdef _WIN32 -#include -#else -#include -#endif - - -/* this is the same hash algorithm used by nsZipArchive.cpp */ -static uint32_t mar_hash_name(const char *name) { - uint32_t val = 0; - unsigned char* c; - - for (c = (unsigned char *) name; *c; ++c) - val = val*37 + *c; - - return val % TABLESIZE; -} - -static int mar_insert_item(MarFile *mar, const char *name, int namelen, - uint32_t offset, uint32_t length, uint32_t flags) { - MarItem *item, *root; - uint32_t hash; - - item = (MarItem *) malloc(sizeof(MarItem) + namelen); - if (!item) - return -1; - item->next = NULL; - item->offset = offset; - item->length = length; - item->flags = flags; - memcpy(item->name, name, namelen + 1); - - hash = mar_hash_name(name); - - root = mar->item_table[hash]; - if (!root) { - mar->item_table[hash] = item; - } else { - /* append item */ - while (root->next) - root = root->next; - root->next = item; - } - return 0; -} - -static int mar_consume_index(MarFile *mar, char **buf, const char *buf_end) { - /* - * Each item has the following structure: - * uint32_t offset (network byte order) - * uint32_t length (network byte order) - * uint32_t flags (network byte order) - * char name[N] (where N >= 1) - * char null_byte; - */ - uint32_t offset; - uint32_t length; - uint32_t flags; - const char *name; - int namelen; - - if ((buf_end - *buf) < (int)(3*sizeof(uint32_t) + 2)) - return -1; - - memcpy(&offset, *buf, sizeof(offset)); - *buf += sizeof(offset); - - memcpy(&length, *buf, sizeof(length)); - *buf += sizeof(length); - - memcpy(&flags, *buf, sizeof(flags)); - *buf += sizeof(flags); - - offset = ntohl(offset); - length = ntohl(length); - flags = ntohl(flags); - - name = *buf; - /* find namelen; must take care not to read beyond buf_end */ - while (**buf) { - if (*buf == buf_end) - return -1; - ++(*buf); - } - namelen = (*buf - name); - /* consume null byte */ - if (*buf == buf_end) - return -1; - ++(*buf); - - return mar_insert_item(mar, name, namelen, offset, length, flags); -} - -static int mar_read_index(MarFile *mar) { - char id[MAR_ID_SIZE], *buf, *bufptr, *bufend; - uint32_t offset_to_index, size_of_index; - - /* verify MAR ID */ - if (fread(id, MAR_ID_SIZE, 1, mar->fp) != 1) - return -1; - if (memcmp(id, MAR_ID, MAR_ID_SIZE) != 0) - return -1; - - if (fread(&offset_to_index, sizeof(uint32_t), 1, mar->fp) != 1) - return -1; - offset_to_index = ntohl(offset_to_index); - - if (fseek(mar->fp, offset_to_index, SEEK_SET)) - return -1; - if (fread(&size_of_index, sizeof(uint32_t), 1, mar->fp) != 1) - return -1; - size_of_index = ntohl(size_of_index); - - buf = (char *) malloc(size_of_index); - if (!buf) - return -1; - if (fread(buf, size_of_index, 1, mar->fp) != 1) { - free(buf); - return -1; - } - - bufptr = buf; - bufend = buf + size_of_index; - while (bufptr < bufend && mar_consume_index(mar, &bufptr, bufend) == 0); - - free(buf); - return (bufptr == bufend) ? 0 : -1; -} - -/** - * Internal shared code for mar_open and mar_wopen. - * On failure, will fclose(fp). - */ -static MarFile *mar_fpopen(FILE *fp) -{ - MarFile *mar; - - mar = (MarFile *) malloc(sizeof(*mar)); - if (!mar) { - fclose(fp); - return NULL; - } - - mar->fp = fp; - memset(mar->item_table, 0, sizeof(mar->item_table)); - if (mar_read_index(mar)) { - mar_close(mar); - return NULL; - } - - return mar; -} - -MarFile *mar_open(const char *path) { - FILE *fp; - - fp = fopen(path, "rb"); - if (!fp) { - fprintf(stderr, "ERROR: could not open file in mar_open()\n"); - perror(path); - return NULL; - } - - return mar_fpopen(fp); -} - -#ifdef _WIN32 -MarFile *mar_wopen(const wchar_t *path) { - FILE *fp; - - _wfopen_s(&fp, path, L"rb"); - if (!fp) { - fprintf(stderr, "ERROR: could not open file in mar_wopen()\n"); - _wperror(path); - return NULL; - } - - return mar_fpopen(fp); -} -#endif - -void mar_close(MarFile *mar) { - MarItem *item; - int i; - - fclose(mar->fp); - - for (i = 0; i < TABLESIZE; ++i) { - item = mar->item_table[i]; - while (item) { - MarItem *temp = item; - item = item->next; - free(temp); - } - } - - free(mar); -} - -/** - * Determines the MAR file information. - * - * @param fp An opened MAR file in read mode. - * @param hasSignatureBlock Optional out parameter specifying if the MAR - * file has a signature block or not. - * @param numSignatures Optional out parameter for storing the number - * of signatures in the MAR file. - * @param hasAdditionalBlocks Optional out parameter specifying if the MAR - * file has additional blocks or not. - * @param offsetAdditionalBlocks Optional out parameter for the offset to the - * first additional block. Value is only valid if - * hasAdditionalBlocks is not equal to 0. - * @param numAdditionalBlocks Optional out parameter for the number of - * additional blocks. Value is only valid if - * hasAdditionalBlocks is not equal to 0. - * @return 0 on success and non-zero on failure. - */ -int get_mar_file_info_fp(FILE *fp, - int *hasSignatureBlock, - uint32_t *numSignatures, - int *hasAdditionalBlocks, - uint32_t *offsetAdditionalBlocks, - uint32_t *numAdditionalBlocks) -{ - uint32_t offsetToIndex, offsetToContent, signatureCount, signatureLen, i; - - /* One of hasSignatureBlock or hasAdditionalBlocks must be non NULL */ - if (!hasSignatureBlock && !hasAdditionalBlocks) { - return -1; - } - - - /* Skip to the start of the offset index */ - if (fseek(fp, MAR_ID_SIZE, SEEK_SET)) { - return -1; - } - - /* Read the offset to the index. */ - if (fread(&offsetToIndex, sizeof(offsetToIndex), 1, fp) != 1) { - return -1; - } - offsetToIndex = ntohl(offsetToIndex); - - if (numSignatures) { - /* Skip past the MAR file size field */ - if (fseek(fp, sizeof(uint64_t), SEEK_CUR)) { - return -1; - } - - /* Read the number of signatures field */ - if (fread(numSignatures, sizeof(*numSignatures), 1, fp) != 1) { - return -1; - } - *numSignatures = ntohl(*numSignatures); - } - - /* Skip to the first index entry past the index size field - We do it in 2 calls because offsetToIndex + sizeof(uint32_t) - could oerflow in theory. */ - if (fseek(fp, offsetToIndex, SEEK_SET)) { - return -1; - } - - if (fseek(fp, sizeof(uint32_t), SEEK_CUR)) { - return -1; - } - - /* Read the first offset to content field. */ - if (fread(&offsetToContent, sizeof(offsetToContent), 1, fp) != 1) { - return -1; - } - offsetToContent = ntohl(offsetToContent); - - /* Check if we have a new or old MAR file */ - if (hasSignatureBlock) { - if (offsetToContent == MAR_ID_SIZE + sizeof(uint32_t)) { - *hasSignatureBlock = 0; - } else { - *hasSignatureBlock = 1; - } - } - - /* If the caller doesn't care about the product info block - value, then just return */ - if (!hasAdditionalBlocks) { - return 0; - } - - /* Skip to the start of the signature block */ - if (fseeko(fp, SIGNATURE_BLOCK_OFFSET, SEEK_SET)) { - return -1; - } - - /* Get the number of signatures */ - if (fread(&signatureCount, sizeof(signatureCount), 1, fp) != 1) { - return -1; - } - signatureCount = ntohl(signatureCount); - - /* Check that we have less than the max amount of signatures so we don't - waste too much of either updater's or signmar's time. */ - if (signatureCount > MAX_SIGNATURES) { - return -1; - } - - /* Skip past the whole signature block */ - for (i = 0; i < signatureCount; i++) { - /* Skip past the signature algorithm ID */ - if (fseek(fp, sizeof(uint32_t), SEEK_CUR)) { - return -1; - } - - /* Read the signature length and skip past the signature */ - if (fread(&signatureLen, sizeof(uint32_t), 1, fp) != 1) { - return -1; - } - signatureLen = ntohl(signatureLen); - if (fseek(fp, signatureLen, SEEK_CUR)) { - return -1; - } - } - - if (ftell(fp) == offsetToContent) { - *hasAdditionalBlocks = 0; - } else { - if (numAdditionalBlocks) { - /* We have an additional block, so read in the number of additional blocks - and set the offset. */ - *hasAdditionalBlocks = 1; - if (fread(numAdditionalBlocks, sizeof(uint32_t), 1, fp) != 1) { - return -1; - } - *numAdditionalBlocks = ntohl(*numAdditionalBlocks); - if (offsetAdditionalBlocks) { - *offsetAdditionalBlocks = ftell(fp); - } - } else if (offsetAdditionalBlocks) { - /* numAdditionalBlocks is not specified but offsetAdditionalBlocks - is, so fill it! */ - *offsetAdditionalBlocks = ftell(fp) + sizeof(uint32_t); - } - } - - return 0; -} - -/** - * Reads the product info block from the MAR file's additional block section. - * The caller is responsible for freeing the fields in infoBlock - * if the return is successful. - * - * @param infoBlock Out parameter for where to store the result to - * @return 0 on success, -1 on failure -*/ -int -read_product_info_block(char *path, - struct ProductInformationBlock *infoBlock) -{ - int rv; - MarFile mar; - mar.fp = fopen(path, "rb"); - if (!mar.fp) { - fprintf(stderr, "ERROR: could not open file in read_product_info_block()\n"); - perror(path); - return -1; - } - rv = mar_read_product_info_block(&mar, infoBlock); - fclose(mar.fp); - return rv; -} - -/** - * Reads the product info block from the MAR file's additional block section. - * The caller is responsible for freeing the fields in infoBlock - * if the return is successful. - * - * @param infoBlock Out parameter for where to store the result to - * @return 0 on success, -1 on failure -*/ -int -mar_read_product_info_block(MarFile *mar, - struct ProductInformationBlock *infoBlock) -{ - uint32_t i, offsetAdditionalBlocks, numAdditionalBlocks, - additionalBlockSize, additionalBlockID; - int hasAdditionalBlocks; - - /* The buffer size is 97 bytes because the MAR channel name < 64 bytes, and - product version < 32 bytes + 3 NULL terminator bytes. */ - char buf[97] = { '\0' }; - int ret = get_mar_file_info_fp(mar->fp, NULL, NULL, - &hasAdditionalBlocks, - &offsetAdditionalBlocks, - &numAdditionalBlocks); - if (ret) - return ret; - for (i = 0; i < numAdditionalBlocks; ++i) { - /* Read the additional block size */ - if (fread(&additionalBlockSize, - sizeof(additionalBlockSize), - 1, mar->fp) != 1) { - return -1; - } - additionalBlockSize = ntohl(additionalBlockSize) - - sizeof(additionalBlockSize) - - sizeof(additionalBlockID); - - /* Read the additional block ID */ - if (fread(&additionalBlockID, - sizeof(additionalBlockID), - 1, mar->fp) != 1) { - return -1; - } - additionalBlockID = ntohl(additionalBlockID); - - if (PRODUCT_INFO_BLOCK_ID == additionalBlockID) { - const char *location; - int len; - - /* This block must be at most 104 bytes. - MAR channel name < 64 bytes, and product version < 32 bytes + 3 NULL - terminator bytes. We only check for 96 though because we remove 8 - bytes above from the additionalBlockSize: We subtract - sizeof(additionalBlockSize) and sizeof(additionalBlockID) */ - if (additionalBlockSize > 96) { - return -1; - } - - if (fread(buf, additionalBlockSize, 1, mar->fp) != 1) { - return -1; - } - - /* Extract the MAR channel name from the buffer. For now we - point to the stack allocated buffer but we strdup this - if we are within bounds of each field's max length. */ - location = buf; - len = strlen(location); - infoBlock->MARChannelID = location; - location += len + 1; - if (len >= 64) { - infoBlock->MARChannelID = NULL; - return -1; - } - - /* Extract the version from the buffer */ - len = strlen(location); - infoBlock->productVersion = location; - location += len + 1; - if (len >= 32) { - infoBlock->MARChannelID = NULL; - infoBlock->productVersion = NULL; - return -1; - } - infoBlock->MARChannelID = - strdup(infoBlock->MARChannelID); - infoBlock->productVersion = - strdup(infoBlock->productVersion); - return 0; - } else { - /* This is not the additional block you're looking for. Move along. */ - if (fseek(mar->fp, additionalBlockSize, SEEK_CUR)) { - return -1; - } - } - } - - /* If we had a product info block we would have already returned */ - return -1; -} - -const MarItem *mar_find_item(MarFile *mar, const char *name) { - uint32_t hash; - const MarItem *item; - - hash = mar_hash_name(name); - - item = mar->item_table[hash]; - while (item && strcmp(item->name, name) != 0) - item = item->next; - - return item; -} - -int mar_enum_items(MarFile *mar, MarItemCallback callback, void *closure) { - MarItem *item; - int i; - - for (i = 0; i < TABLESIZE; ++i) { - item = mar->item_table[i]; - while (item) { - int rv = callback(mar, item, closure); - if (rv) - return rv; - item = item->next; - } - } - - return 0; -} - -int mar_read(MarFile *mar, const MarItem *item, int offset, char *buf, - int bufsize) { - int nr; - - if (offset == (int) item->length) - return 0; - if (offset > (int) item->length) - return -1; - - nr = item->length - offset; - if (nr > bufsize) - nr = bufsize; - - if (fseek(mar->fp, item->offset + offset, SEEK_SET)) - return -1; - - return fread(buf, 1, nr, mar->fp); -} - -/** - * Determines the MAR file information. - * - * @param path The path of the MAR file to check. - * @param hasSignatureBlock Optional out parameter specifying if the MAR - * file has a signature block or not. - * @param numSignatures Optional out parameter for storing the number - * of signatures in the MAR file. - * @param hasAdditionalBlocks Optional out parameter specifying if the MAR - * file has additional blocks or not. - * @param offsetAdditionalBlocks Optional out parameter for the offset to the - * first additional block. Value is only valid if - * hasAdditionalBlocks is not equal to 0. - * @param numAdditionalBlocks Optional out parameter for the number of - * additional blocks. Value is only valid if - * has_additional_blocks is not equal to 0. - * @return 0 on success and non-zero on failure. - */ -int get_mar_file_info(const char *path, - int *hasSignatureBlock, - uint32_t *numSignatures, - int *hasAdditionalBlocks, - uint32_t *offsetAdditionalBlocks, - uint32_t *numAdditionalBlocks) -{ - int rv; - FILE *fp = fopen(path, "rb"); - if (!fp) { - fprintf(stderr, "ERROR: could not open file in get_mar_file_info()\n"); - perror(path); - return -1; - } - - rv = get_mar_file_info_fp(fp, hasSignatureBlock, - numSignatures, hasAdditionalBlocks, - offsetAdditionalBlocks, numAdditionalBlocks); - - fclose(fp); - return rv; -} diff --git a/onlineupdate/source/update/updater/archivereader.h b/onlineupdate/source/update/updater/archivereader.h index 8d0b7c3d74ee..f045566b772b 100644 --- a/onlineupdate/source/update/updater/archivereader.h +++ b/onlineupdate/source/update/updater/archivereader.h @@ -8,7 +8,7 @@ #define ArchiveReader_h__ #include -#include "mar.h" +#include #ifdef _WIN32 typedef WCHAR NS_tchar; diff --git a/onlineupdate/source/update/updater/updater.cxx b/onlineupdate/source/update/updater/updater.cxx index b2b4866c16be..145e080fcbe2 100644 --- a/onlineupdate/source/update/updater/updater.cxx +++ b/onlineupdate/source/update/updater/updater.cxx @@ -54,8 +54,8 @@ #include "updatelogging.h" -#include "mozilla/Compiler.h" -#include "mozilla/Types.h" +#include +#include // Amount of the progress bar to use in each of the 3 update stages, // should total 100.0. -- cgit