Kaydet (Commit) 90371480 authored tarafından Ras-al-Ghul's avatar Ras-al-Ghul Kaydeden (comit) Jan Holesovsky

tdf#98602 Duplicate code in onlineupdate/

Converted libmar into static library and removed duplicate code.

Change-Id: I51c58ae9a6a1f1128422b4a79491d0cd62e6ced6
Reviewed-on: https://gerrit.libreoffice.org/23312Tested-by: 's avatarJenkins <ci@libreoffice.org>
Reviewed-by: 's avatarMarkus Mohrhard <markus.mohrhard@googlemail.com>
Tested-by: 's avatarMarkus Mohrhard <markus.mohrhard@googlemail.com>
Reviewed-by: 's avatarJan Holesovsky <kendy@collabora.com>
üst b3e93997
......@@ -13,10 +13,10 @@
#define MOZ_DUMP_ASSERTION_STACK
#endif
#include "mozilla/Attributes.h"
#include "mozilla/Compiler.h"
#include "mozilla/Likely.h"
#include "mozilla/MacroArgs.h"
#include "Attributes.h"
#include "Compiler.h"
#include "Likely.h"
#include "MacroArgs.h"
#ifdef MOZ_DUMP_ASSERTION_STACK
#include "nsTraceRefcnt.h"
#endif
......@@ -309,7 +309,7 @@ __declspec(noreturn) __inline void MOZ_NoReturn() {}
*/
#ifdef __cplusplus
# include "mozilla/TypeTraits.h"
# include "TypeTraits.h"
namespace mozilla {
namespace detail {
......
......@@ -9,7 +9,7 @@
#ifndef mozilla_Attributes_h
#define mozilla_Attributes_h
#include "mozilla/Compiler.h"
#include "Compiler.h"
/*
* MOZ_ALWAYS_INLINE is a macro which expands to tell the compiler that the
......
......@@ -9,7 +9,7 @@
#ifndef mozilla_TypeTraits_h
#define mozilla_TypeTraits_h
#include "mozilla/Types.h"
#include "Types.h"
/*
* These traits are approximate copies of the traits and semantics from C++11's
......
......@@ -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 \
......
......@@ -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: */
......@@ -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 \
))
......
# -*- 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: */
......@@ -13,9 +13,9 @@
#include <fcntl.h>
#include <stdlib.h>
#include <string.h>
#include "mar_private.h"
#include "mar_cmdline.h"
#include "mar.h"
#include <onlineupdate/mar_private.h>
#include <onlineupdate/mar_cmdline.h>
#include <onlineupdate/mar.h>
#include "cryptox.h"
#ifndef _WIN32
#include <unistd.h>
......
......@@ -9,9 +9,9 @@
#include <fcntl.h>
#include <stdlib.h>
#include <string.h>
#include "mar_private.h"
#include "mar_cmdline.h"
#include "mar.h"
#include <onlineupdate/mar_private.h>
#include <onlineupdate/mar_cmdline.h>
#include <onlineupdate/mar.h>
#ifdef _WIN32
#include <winsock2.h>
......
......@@ -9,8 +9,8 @@
#include <fcntl.h>
#include <string.h>
#include <stdlib.h>
#include "mar_private.h"
#include "mar.h"
#include <onlineupdate/mar_private.h>
#include <onlineupdate/mar.h>
#ifdef _WIN32
#include <io.h>
......
......@@ -8,8 +8,8 @@
#include <fcntl.h>
#include <stdlib.h>
#include <string.h>
#include "mar_private.h"
#include "mar.h"
#include <onlineupdate/mar_private.h>
#include <onlineupdate/mar.h>
#ifdef _WIN32
#include <winsock2.h>
......
......@@ -7,8 +7,8 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "mar.h"
#include "mar_cmdline.h"
#include <onlineupdate/mar.h>
#include <onlineupdate/mar_cmdline.h>
#ifdef _WIN32
#include <windows.h>
......
......@@ -14,8 +14,8 @@
#include <stdlib.h>
#include <string.h>
#include <assert.h>
#include "mar_private.h"
#include "mar.h"
#include <onlineupdate/mar_private.h>
#include <onlineupdate/mar.h>
#include "cryptox.h"
int
......
/* -*- 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 <string>
/**
* 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<const char16_t*>(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<const wchar_t*>(mPtr);
}
operator const void*() const
{
return mPtr;
}
operator bool() const
{
return mPtr != nullptr;
}
operator std::wstring() const
{
return std::wstring(static_cast<const wchar_t*>(*this));
}
/* Explicit cast operators to allow things like (char16_t*)str. */
explicit operator char16_t*() const
{
return const_cast<char16_t*>(mPtr);
}
explicit operator wchar_t*() const
{
return const_cast<wchar_t*>(static_cast<const wchar_t*>(*this));
}
explicit operator int() const
{
return reinterpret_cast<intptr_t>(mPtr);
}
explicit operator unsigned int() const
{
return reinterpret_cast<uintptr_t>(mPtr);
}
explicit operator long() const
{
return reinterpret_cast<intptr_t>(mPtr);
}
explicit operator unsigned long() const
{
return reinterpret_cast<uintptr_t>(mPtr);
}
explicit operator long long() const
{
return reinterpret_cast<intptr_t>(mPtr);
}
explicit operator unsigned long long() const
{
return reinterpret_cast<uintptr_t>(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<const char*>(mPtr);
}
explicit operator const unsigned char*() const
{
return reinterpret_cast<const unsigned char*>(mPtr);
}
explicit operator unsigned char*() const
{
return
const_cast<unsigned char*>(reinterpret_cast<const unsigned char*>(mPtr));
}
explicit operator void*() const
{
return const_cast<char16_t*>(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<const char16_t*>(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 */
/* -*- 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 <cstddef>
# 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 */
/* -*- 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 */
/* -*- 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__, <rest of arguments>) rather than simply calling
* MOZ_MACROARGS_ARG_COUNT_HELPER2(__VA_ARGS__, <rest of arguments>) 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 */
/* -*- 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<T> u;
* Vector<T> 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 <typename XArg, typename YArg>
* C::C(XArg&& x, YArg&& y) : x(Forward<XArg>(x)), y(Forward<YArg>(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<T>' 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 <utility> 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<typename T>
inline typename RemoveReference<T>::Type&&
Move(T&& aX)
{
return static_cast<typename RemoveReference<T>::Type&&>(aX);
}
/**
* These two overloads are identical to std::forward(); they are necessary until
* our stlport supports std::forward().
*/
template<typename T>
inline T&&
Forward(typename RemoveReference<T>::Type& aX)
{
return static_cast<T&&>(aX);
}
template<typename T>
inline T&&
Forward(typename RemoveReference<T>::Type&& aX)
{
static_assert(!IsLvalueReference<T>::value,
"misuse of Forward detected! try the other overload");
return static_cast<T&&>(aX);
}
/** Swap |aX| and |aY| using move-construction if possible. */
template<typename T>
inline void
Swap(T& aX, T& aY)
{
T tmp(Move(aX));
aX = Move(aY);
aY = Move(tmp);
}
} // namespace mozilla
#endif /* mozilla_Move_h */
/* -*- 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<typename A, typename B,
detail::StorageType =
IsEmpty<A>::value ? detail::AsBase : detail::AsMember,
detail::StorageType =
IsEmpty<B>::value && !IsBaseOf<A, B>::value && !IsBaseOf<B, A>::value
? detail::AsBase
: detail::AsMember>
struct PairHelper;
template<typename A, typename B>
struct PairHelper<A, B, AsMember, AsMember>
{
protected:
template<typename AArg, typename BArg>
PairHelper(AArg&& aA, BArg&& aB)
: mFirstA(Forward<AArg>(aA)),
mSecondB(Forward<BArg>(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<typename A, typename B>
struct PairHelper<A, B, AsMember, AsBase> : private B
{
protected:
template<typename AArg, typename BArg>
PairHelper(AArg&& aA, BArg&& aB)
: B(Forward<BArg>(aB)),
mFirstA(Forward<AArg>(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<B&>(*this), static_cast<B&>(aOther));
}
private:
A mFirstA;
};
template<typename A, typename B>
struct PairHelper<A, B, AsBase, AsMember> : private A
{
protected:
template<typename AArg, typename BArg>
PairHelper(AArg&& aA, BArg&& aB)
: A(Forward<AArg>(aA)),
mSecondB(Forward<BArg>(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<A&>(*this), static_cast<A&>(aOther));
Swap(mSecondB, aOther.mSecondB);
}
private:
B mSecondB;
};
template<typename A, typename B>
struct PairHelper<A, B, AsBase, AsBase> : private A, private B
{
protected:
template<typename AArg, typename BArg>
PairHelper(AArg&& aA, BArg&& aB)
: A(Forward<AArg>(aA)),
B(Forward<BArg>(aB))
{}
A& first() { return static_cast<A&>(*this); }
const A& first() const { return static_cast<A&>(*this); }
B& second() { return static_cast<B&>(*this); }
const B& second() const { return static_cast<B&>(*this); }
void swap(PairHelper& aOther)
{
Swap(static_cast<A&>(*this), static_cast<A&>(aOther));
Swap(static_cast<B&>(*this), static_cast<B&>(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<typename A, typename B>
struct Pair
: private detail::PairHelper<A, B>
{
typedef typename detail::PairHelper<A, B> Base;
public:
template<typename AArg, typename BArg>
Pair(AArg&& aA, BArg&& aB)
: Base(Forward<AArg>(aA), Forward<BArg>(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<typename A, class B>
void
Swap(Pair<A, B>& aX, Pair<A, B>& 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<Foo, Bar>.
*/
template<typename A, typename B>
Pair<typename RemoveCV<typename RemoveReference<A>::Type>::Type,
typename RemoveCV<typename RemoveReference<B>::Type>::Type>
MakePair(A&& aA, B&& aB)
{
return
Pair<typename RemoveCV<typename RemoveReference<A>::Type>::Type,
typename RemoveCV<typename RemoveReference<B>::Type>::Type>(
Forward<A>(aA),
Forward<B>(aB));
}
} // namespace mozilla
#endif /* mozilla_Pair_h */
/* -*- 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 <stdint.h> types and size_t. */
#include <stddef.h>
#include <stdint.h>
/* 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 */
/* -*- 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 <stdio.h> // 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
This diff is collapsed.
/* -*- 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 <windows.h>
#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<HKEY>
{
public:
typedef HKEY RawRef;
static HKEY Void()
{
return nullptr;
}
static void Release(RawRef aFD)
{
if (aFD != Void()) {
RegCloseKey(aFD);
}
}
};
template<>
class nsAutoRefTraits<SC_HANDLE>
{
public:
typedef SC_HANDLE RawRef;
static SC_HANDLE Void()
{
return nullptr;
}
static void Release(RawRef aFD)
{
if (aFD != Void()) {
CloseServiceHandle(aFD);
}
}
};
template<>
class nsSimpleRef<HANDLE>
{
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<HMODULE>
{
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
# 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:
This diff is collapsed.
/* -*- 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 <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <string.h>
#include <stdlib.h>
#include "mar_private.h"
#include "mar.h"
#ifdef _WIN32
#include <io.h>
#include <direct.h>
#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;
}
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment