From 7ac3af8c89af7d481c027df75026f390258e6e5a Mon Sep 17 00:00:00 2001 From: Michael Stahl Date: Thu, 3 Dec 2020 17:42:18 +0100 Subject: pdfium: MSVC 2015 build --- external/pdfium/UnpackedTarball_pdfium.mk | 3 + external/pdfium/msvc2015.patch.1 | 202 ++ external/pdfium/pdfium4137-numerics.patch.3 | 3364 +++++++++++++++++++++++++++ 3 files changed, 3569 insertions(+) create mode 100644 external/pdfium/msvc2015.patch.1 create mode 100644 external/pdfium/pdfium4137-numerics.patch.3 diff --git a/external/pdfium/UnpackedTarball_pdfium.mk b/external/pdfium/UnpackedTarball_pdfium.mk index f4643376cee0..8b12e494f94b 100644 --- a/external/pdfium/UnpackedTarball_pdfium.mk +++ b/external/pdfium/UnpackedTarball_pdfium.mk @@ -14,6 +14,9 @@ pdfium_patches += build.patch.1 # Avoids Windows 8 build dependency. pdfium_patches += windows7.patch.1 pdfium_patches += c++20-comparison.patch +ifeq (MSC,$(COM)) +pdfium_patches += pdfium4137-numerics.patch.3 msvc2015.patch.1 +endif $(eval $(call gb_UnpackedTarball_UnpackedTarball,pdfium)) diff --git a/external/pdfium/msvc2015.patch.1 b/external/pdfium/msvc2015.patch.1 new file mode 100644 index 000000000000..36cb5332c7b0 --- /dev/null +++ b/external/pdfium/msvc2015.patch.1 @@ -0,0 +1,202 @@ +Fix MSVC 2015 build + +--- pdfium/third_party/base/optional.h.orig 2020-10-26 19:26:04.000000000 +0100 ++++ pdfium/third_party/base/optional.h 2020-12-03 16:00:54.879883100 +0100 +@@ -36,7 +36,7 @@ + struct OptionalStorageBase { + // Provide non-defaulted default ctor to make sure it's not deleted by + // non-trivial T::T() in the union. +- constexpr OptionalStorageBase() : dummy_() {} ++ OptionalStorageBase() : dummy_() {} + + template + constexpr explicit OptionalStorageBase(in_place_t, Args&&... args) +@@ -88,7 +88,7 @@ + struct OptionalStorageBase { + // Provide non-defaulted default ctor to make sure it's not deleted by + // non-trivial T::T() in the union. +- constexpr OptionalStorageBase() : dummy_() {} ++ OptionalStorageBase() : dummy_() {} + + template + constexpr explicit OptionalStorageBase(in_place_t, Args&&... args) +@@ -607,32 +607,32 @@ + return *this; + } + +- constexpr const T* operator->() const { ++ const T* operator->() const { + CHECK(storage_.is_populated_); + return &storage_.value_; + } + +- constexpr T* operator->() { ++ T* operator->() { + CHECK(storage_.is_populated_); + return &storage_.value_; + } + +- constexpr const T& operator*() const & { ++ const T& operator*() const & { + CHECK(storage_.is_populated_); + return storage_.value_; + } + +- constexpr T& operator*() & { ++ T& operator*() & { + CHECK(storage_.is_populated_); + return storage_.value_; + } + +- constexpr const T&& operator*() const && { ++ const T&& operator*() const && { + CHECK(storage_.is_populated_); + return std::move(storage_.value_); + } + +- constexpr T&& operator*() && { ++ T&& operator*() && { + CHECK(storage_.is_populated_); + return std::move(storage_.value_); + } +@@ -641,22 +641,22 @@ + + constexpr bool has_value() const { return storage_.is_populated_; } + +- constexpr T& value() & { ++ T& value() & { + CHECK(storage_.is_populated_); + return storage_.value_; + } + +- constexpr const T& value() const & { ++ const T& value() const & { + CHECK(storage_.is_populated_); + return storage_.value_; + } + +- constexpr T&& value() && { ++ T&& value() && { + CHECK(storage_.is_populated_); + return std::move(storage_.value_); + } + +- constexpr const T&& value() const && { ++ const T&& value() const && { + CHECK(storage_.is_populated_); + return std::move(storage_.value_); + } +--- pdfium/third_party/base/span.h.orig 2020-10-26 19:26:04.000000000 +0100 ++++ pdfium/third_party/base/span.h 2020-12-03 16:28:15.642138100 +0100 +@@ -193,7 +193,7 @@ + + // TODO(dcheng): Implement construction from a |begin| and |end| pointer. + template +- constexpr span(T (&array)[N]) noexcept : span(array, N) {} ++ span(T (&array)[N]) noexcept : span(array, N) {} + // TODO(dcheng): Implement construction from std::array. + // Conversion from a container that provides |T* data()| and |integral_type + // size()|. +--- pdfium/core/fpdfapi/page/cpdf_colorspace.cpp.orig 2020-12-03 16:54:15.514659400 +0100 ++++ pdfium/core/fpdfapi/page/cpdf_colorspace.cpp 2020-12-03 16:38:52.167650200 +0100 +@@ -905,7 +905,7 @@ + float R; + float G; + float B; +- GetRGB(lab, &R, &G, &B); ++ GetRGB(pdfium::span(lab), &R, &G, &B); + pDestBuf[0] = static_cast(B * 255); + pDestBuf[1] = static_cast(G * 255); + pDestBuf[2] = static_cast(R * 255); +--- pdfium/core/fpdfapi/page/cpdf_meshstream.cpp.orig 2020-12-03 16:54:09.233498800 +0100 ++++ pdfium/core/fpdfapi/page/cpdf_meshstream.cpp 2020-12-03 16:41:29.173766500 +0100 +@@ -209,7 +209,7 @@ + func->Call(color_value, 1, result, &nResults); + } + +- m_pCS->GetRGB(result, &r, &g, &b); ++ m_pCS->GetRGB(pdfium::span(result), &r, &g, &b); + return std::tuple(r, g, b); + } + +--- pdfium/core/fpdfapi/parser/cpdf_security_handler.cpp.orig 2020-12-03 16:53:56.077095400 +0100 ++++ pdfium/core/fpdfapi/parser/cpdf_security_handler.cpp 2020-12-03 16:44:23.951334200 +0100 +@@ -481,7 +481,7 @@ + uint8_t passcode[32]; + GetPassCode(owner_password, passcode); + uint8_t digest[16]; +- CRYPT_MD5Generate(passcode, digest); ++ CRYPT_MD5Generate(pdfium::span(passcode), digest); + if (m_Revision >= 3) { + for (uint32_t i = 0; i < 50; i++) + CRYPT_MD5Generate(digest, digest); +@@ -570,10 +570,10 @@ + uint8_t passcode[32]; + GetPassCode(owner_password_copy, passcode); + uint8_t digest[16]; +- CRYPT_MD5Generate(passcode, digest); ++ CRYPT_MD5Generate(pdfium::span(passcode), digest); + if (m_Revision >= 3) { + for (uint32_t i = 0; i < 50; i++) +- CRYPT_MD5Generate(digest, digest); ++ CRYPT_MD5Generate(pdfium::span(digest), digest); + } + uint8_t enckey[32]; + memcpy(enckey, digest, key_len); +--- pdfium/core/fpdfapi/page/cpdf_dib.cpp.orig 2020-12-03 16:53:44.548444600 +0100 ++++ pdfium/core/fpdfapi/page/cpdf_dib.cpp 2020-12-03 16:49:11.937584700 +0100 +@@ -874,7 +874,7 @@ + color_values[0] += m_CompData[0].m_DecodeStep; + color_values[1] += m_CompData[0].m_DecodeStep; + color_values[2] += m_CompData[0].m_DecodeStep; +- m_pColorSpace->GetRGB(color_values, &R, &G, &B); ++ m_pColorSpace->GetRGB(pdfium::span(color_values), &R, &G, &B); + FX_ARGB argb1 = ArgbEncode(255, FXSYS_roundf(R * 255), + FXSYS_roundf(G * 255), FXSYS_roundf(B * 255)); + if (argb0 != 0xFF000000 || argb1 != 0xFFFFFFFF) { +--- pdfium/third_party/base/allocator/partition_allocator/partition_alloc.cc.orig 2020-12-03 17:09:02.887283800 +0100 ++++ pdfium/third_party/base/allocator/partition_allocator/partition_alloc.cc 2020-12-03 17:07:22.198993800 +0100 +@@ -67,12 +67,12 @@ + // Chained hooks are not supported. Registering a non-null hook when a + // non-null hook is already registered indicates somebody is trying to + // overwrite a hook. +- CHECK((!allocation_observer_hook_ && !free_observer_hook_) || ++ CHECK((!allocation_observer_hook_.load() && !free_observer_hook_.load()) || + (!alloc_hook && !free_hook)); + allocation_observer_hook_ = alloc_hook; + free_observer_hook_ = free_hook; + +- hooks_enabled_ = allocation_observer_hook_ || allocation_override_hook_; ++ hooks_enabled_ = allocation_observer_hook_.load() || allocation_override_hook_.load(); + } + + void PartitionAllocHooks::SetOverrideHooks(AllocationOverrideHook* alloc_hook, +@@ -80,14 +80,14 @@ + ReallocOverrideHook realloc_hook) { + subtle::SpinLock::Guard guard(set_hooks_lock_); + +- CHECK((!allocation_override_hook_ && !free_override_hook_ && +- !realloc_override_hook_) || ++ CHECK((!allocation_override_hook_.load() && !free_override_hook_.load() && ++ !realloc_override_hook_.load()) || + (!alloc_hook && !free_hook && !realloc_hook)); + allocation_override_hook_ = alloc_hook; + free_override_hook_ = free_hook; + realloc_override_hook_ = realloc_hook; + +- hooks_enabled_ = allocation_observer_hook_ || allocation_override_hook_; ++ hooks_enabled_ = allocation_observer_hook_.load() || allocation_override_hook_.load(); + } + + void PartitionAllocHooks::AllocationObserverHookIfEnabled( +--- pdfium/third_party/base/allocator/partition_allocator/partition_page.h.orig 2020-12-03 17:13:56.944624000 +0100 ++++ pdfium/third_party/base/allocator/partition_allocator/partition_page.h 2020-12-03 17:13:34.385932300 +0100 +@@ -25,6 +25,8 @@ + struct DeferredUnmap { + void* ptr = nullptr; + size_t size = 0; ++ DeferredUnmap(void* const p, size_t const s) : ptr(p), size(s) {} ++ DeferredUnmap() = default; + // In most cases there is no page to unmap and ptr == nullptr. This function + // is inlined to avoid the overhead of a function call in the common case. + ALWAYS_INLINE void Run(); diff --git a/external/pdfium/pdfium4137-numerics.patch.3 b/external/pdfium/pdfium4137-numerics.patch.3 new file mode 100644 index 000000000000..7d27ccd7f3cb --- /dev/null +++ b/external/pdfium/pdfium4137-numerics.patch.3 @@ -0,0 +1,3364 @@ +Restore numerics headers from release 4137 + +diff -Naur workdir/UnpackedTarball/pdfium/third_party/base/numerics/checked_math.h workdir/UnpackedTarball/pdfium.4137/third_party/base/numerics/checked_math.h +--- workdir/UnpackedTarball/pdfium/third_party/base/numerics/checked_math.h 2020-10-26 19:26:04.000000000 +0100 ++++ workdir/UnpackedTarball/pdfium.4137/third_party/base/numerics/checked_math.h 1970-01-01 01:00:00.000000000 +0100 +@@ -1,395 +0,0 @@ +-// Copyright 2017 The Chromium Authors. All rights reserved. +-// Use of this source code is governed by a BSD-style license that can be +-// found in the LICENSE file. +- +-#ifndef THIRD_PARTY_BASE_NUMERICS_CHECKED_MATH_H_ +-#define THIRD_PARTY_BASE_NUMERICS_CHECKED_MATH_H_ +- +-#include +- +-#include +-#include +- +-#include "third_party/base/numerics/checked_math_impl.h" +- +-namespace pdfium { +-namespace base { +-namespace internal { +- +-template +-class CheckedNumeric { +- static_assert(std::is_arithmetic::value, +- "CheckedNumeric: T must be a numeric type."); +- +- public: +- using type = T; +- +- constexpr CheckedNumeric() = default; +- +- // Copy constructor. +- template +- constexpr CheckedNumeric(const CheckedNumeric& rhs) +- : state_(rhs.state_.value(), rhs.IsValid()) {} +- +- template +- friend class CheckedNumeric; +- +- // This is not an explicit constructor because we implicitly upgrade regular +- // numerics to CheckedNumerics to make them easier to use. +- template +- constexpr CheckedNumeric(Src value) // NOLINT(runtime/explicit) +- : state_(value) { +- static_assert(std::is_arithmetic::value, "Argument must be numeric."); +- } +- +- // This is not an explicit constructor because we want a seamless conversion +- // from StrictNumeric types. +- template +- constexpr CheckedNumeric( +- StrictNumeric value) // NOLINT(runtime/explicit) +- : state_(static_cast(value)) {} +- +- // IsValid() - The public API to test if a CheckedNumeric is currently valid. +- // A range checked destination type can be supplied using the Dst template +- // parameter. +- template +- constexpr bool IsValid() const { +- return state_.is_valid() && +- IsValueInRangeForNumericType(state_.value()); +- } +- +- // AssignIfValid(Dst) - Assigns the underlying value if it is currently valid +- // and is within the range supported by the destination type. Returns true if +- // successful and false otherwise. +- template +-#if defined(__clang__) || defined(__GNUC__) +- __attribute__((warn_unused_result)) +-#elif defined(_MSC_VER) +- _Check_return_ +-#endif +- constexpr bool +- AssignIfValid(Dst* result) const { +- return BASE_NUMERICS_LIKELY(IsValid()) +- ? ((*result = static_cast(state_.value())), true) +- : false; +- } +- +- // ValueOrDie() - The primary accessor for the underlying value. If the +- // current state is not valid it will CHECK and crash. +- // A range checked destination type can be supplied using the Dst template +- // parameter, which will trigger a CHECK if the value is not in bounds for +- // the destination. +- // The CHECK behavior can be overridden by supplying a handler as a +- // template parameter, for test code, etc. However, the handler cannot access +- // the underlying value, and it is not available through other means. +- template +- constexpr StrictNumeric ValueOrDie() const { +- return BASE_NUMERICS_LIKELY(IsValid()) +- ? static_cast(state_.value()) +- : CheckHandler::template HandleFailure(); +- } +- +- // ValueOrDefault(T default_value) - A convenience method that returns the +- // current value if the state is valid, and the supplied default_value for +- // any other state. +- // A range checked destination type can be supplied using the Dst template +- // parameter. WARNING: This function may fail to compile or CHECK at runtime +- // if the supplied default_value is not within range of the destination type. +- template +- constexpr StrictNumeric ValueOrDefault(const Src default_value) const { +- return BASE_NUMERICS_LIKELY(IsValid()) +- ? static_cast(state_.value()) +- : checked_cast(default_value); +- } +- +- // Returns a checked numeric of the specified type, cast from the current +- // CheckedNumeric. If the current state is invalid or the destination cannot +- // represent the result then the returned CheckedNumeric will be invalid. +- template +- constexpr CheckedNumeric::type> Cast() const { +- return *this; +- } +- +- // This friend method is available solely for providing more detailed logging +- // in the the tests. Do not implement it in production code, because the +- // underlying values may change at any time. +- template +- friend U GetNumericValueForTest(const CheckedNumeric& src); +- +- // Prototypes for the supported arithmetic operator overloads. +- template +- constexpr CheckedNumeric& operator+=(const Src rhs); +- template +- constexpr CheckedNumeric& operator-=(const Src rhs); +- template +- constexpr CheckedNumeric& operator*=(const Src rhs); +- template +- constexpr CheckedNumeric& operator/=(const Src rhs); +- template +- constexpr CheckedNumeric& operator%=(const Src rhs); +- template +- constexpr CheckedNumeric& operator<<=(const Src rhs); +- template +- constexpr CheckedNumeric& operator>>=(const Src rhs); +- template +- constexpr CheckedNumeric& operator&=(const Src rhs); +- template +- constexpr CheckedNumeric& operator|=(const Src rhs); +- template +- constexpr CheckedNumeric& operator^=(const Src rhs); +- +- constexpr CheckedNumeric operator-() const { +- // The negation of two's complement int min is int min, so we simply +- // check for that in the constexpr case. +- // We use an optimized code path for a known run-time variable. +- return MustTreatAsConstexpr(state_.value()) || !std::is_signed::value || +- std::is_floating_point::value +- ? CheckedNumeric( +- NegateWrapper(state_.value()), +- IsValid() && (!std::is_signed::value || +- std::is_floating_point::value || +- NegateWrapper(state_.value()) != +- std::numeric_limits::lowest())) +- : FastRuntimeNegate(); +- } +- +- constexpr CheckedNumeric operator~() const { +- return CheckedNumeric( +- InvertWrapper(state_.value()), IsValid()); +- } +- +- constexpr CheckedNumeric Abs() const { +- return !IsValueNegative(state_.value()) ? *this : -*this; +- } +- +- template +- constexpr CheckedNumeric::type> Max( +- const U rhs) const { +- using R = typename UnderlyingType::type; +- using result_type = typename MathWrapper::type; +- // TODO(jschuh): This can be converted to the MathOp version and remain +- // constexpr once we have C++14 support. +- return CheckedNumeric( +- static_cast( +- IsGreater::Test(state_.value(), Wrapper::value(rhs)) +- ? state_.value() +- : Wrapper::value(rhs)), +- state_.is_valid() && Wrapper::is_valid(rhs)); +- } +- +- template +- constexpr CheckedNumeric::type> Min( +- const U rhs) const { +- using R = typename UnderlyingType::type; +- using result_type = typename MathWrapper::type; +- // TODO(jschuh): This can be converted to the MathOp version and remain +- // constexpr once we have C++14 support. +- return CheckedNumeric( +- static_cast( +- IsLess::Test(state_.value(), Wrapper::value(rhs)) +- ? state_.value() +- : Wrapper::value(rhs)), +- state_.is_valid() && Wrapper::is_valid(rhs)); +- } +- +- // This function is available only for integral types. It returns an unsigned +- // integer of the same width as the source type, containing the absolute value +- // of the source, and properly handling signed min. +- constexpr CheckedNumeric::type> +- UnsignedAbs() const { +- return CheckedNumeric::type>( +- SafeUnsignedAbs(state_.value()), state_.is_valid()); +- } +- +- constexpr CheckedNumeric& operator++() { +- *this += 1; +- return *this; +- } +- +- constexpr CheckedNumeric operator++(int) { +- CheckedNumeric value = *this; +- *this += 1; +- return value; +- } +- +- constexpr CheckedNumeric& operator--() { +- *this -= 1; +- return *this; +- } +- +- constexpr CheckedNumeric operator--(int) { +- CheckedNumeric value = *this; +- *this -= 1; +- return value; +- } +- +- // These perform the actual math operations on the CheckedNumerics. +- // Binary arithmetic operations. +- template