Commit 72e2bc05 authored by Jeff Huang's avatar Jeff Huang 🤔

chromium: update to 62.0.3202.62

parent e4e3ea91
From 6cdb5f2ad7684302a8a66217462d2aef4c5f4632 Mon Sep 17 00:00:00 2001
From: Ben Wagner <bungeman@behemoth.cnc.corp.google.com>
Date: Thu, 15 Jun 2017 10:43:17 -0400
Subject: [PATCH] Clip FreeType glyph bitmap to mask.
Skia has for some time assumed that when using FT_Render_Glyph with one
of the LCD render modes that one extra pixel would be applied to each
side of the resulting bitmap. FreieType has changed to make this more
conservative when possible, so the pre-allocated SkMask and the generated
FT_Bitmap may no longer agree on the size and origin.
This change ensures the SkMask and FT_Bitmap are the same size and their
origins align. This is not an ideal long term fix, but is both simple and
localized for easy and quick back-porting, should that become necessary.
BUG=skia:6663
Change-Id: I49ec8f45376be8d867e8aef54eab79537731c310
Reviewed-on: https://skia-review.googlesource.com/20327
Reviewed-by: Herb Derby <herb@google.com>
Commit-Queue: Ben Wagner <bungeman@google.com>
---
src/ports/SkFontHost_FreeType_common.cpp | 100 +++++++++++++++++++++++++------
1 file changed, 83 insertions(+), 17 deletions(-)
diff --git a/src/ports/SkFontHost_FreeType_common.cpp b/src/ports/SkFontHost_FreeType_common.cpp
index 9df7268bb4..a216fdb29c 100644
--- a/src/ports/SkFontHost_FreeType_common.cpp
+++ b/src/ports/SkFontHost_FreeType_common.cpp
@@ -395,8 +395,6 @@ void SkScalerContext_FreeType_Base::generateGlyphImage(
switch ( face->glyph->format ) {
case FT_GLYPH_FORMAT_OUTLINE: {
FT_Outline* outline = &face->glyph->outline;
- FT_BBox bbox;
- FT_Bitmap target;
int dx = 0, dy = 0;
if (fRec.fFlags & SkScalerContext::kSubpixelPositioning_Flag) {
@@ -405,36 +403,97 @@ void SkScalerContext_FreeType_Base::generateGlyphImage(
// negate dy since freetype-y-goes-up and skia-y-goes-down
dy = -dy;
}
- FT_Outline_Get_CBox(outline, &bbox);
- /*
- what we really want to do for subpixel is
- offset(dx, dy)
- compute_bounds
- offset(bbox & !63)
- but that is two calls to offset, so we do the following, which
- achieves the same thing with only one offset call.
- */
- FT_Outline_Translate(outline, dx - ((bbox.xMin + dx) & ~63),
- dy - ((bbox.yMin + dy) & ~63));
+
+ memset(glyph.fImage, 0, glyph.rowBytes() * glyph.fHeight);
if (SkMask::kLCD16_Format == glyph.fMaskFormat) {
+ FT_Outline_Translate(outline, dx, dy);
FT_Error err = FT_Render_Glyph(face->glyph, doVert ? FT_RENDER_MODE_LCD_V :
FT_RENDER_MODE_LCD);
if (err) {
SK_TRACEFTR(err, "Could not render glyph.");
- sk_bzero(glyph.fImage, glyph.computeImageSize());
return;
}
+
SkMask mask;
glyph.toMask(&mask);
+#ifdef SK_SHOW_TEXT_BLIT_COVERAGE
+ memset(mask.fImage, 0x80, mask.fBounds.height() * mask.fRowBytes);
+#endif
+ FT_GlyphSlotRec& ftGlyph = *face->glyph;
+
+ if (!SkIRect::Intersects(mask.fBounds,
+ SkIRect::MakeXYWH( ftGlyph.bitmap_left,
+ -ftGlyph.bitmap_top,
+ ftGlyph.bitmap.width,
+ ftGlyph.bitmap.rows)))
+ {
+ return;
+ }
+
+ // If the FT_Bitmap extent is larger, discard bits of the bitmap outside the mask.
+ // If the SkMask extent is larger, shrink mask to fit bitmap (clearing discarded).
+ unsigned char* origBuffer = ftGlyph.bitmap.buffer;
+ // First align the top left (origin).
+ if (-ftGlyph.bitmap_top < mask.fBounds.fTop) {
+ int32_t topDiff = mask.fBounds.fTop - (-ftGlyph.bitmap_top);
+ ftGlyph.bitmap.buffer += ftGlyph.bitmap.pitch * topDiff;
+ ftGlyph.bitmap.rows -= topDiff;
+ ftGlyph.bitmap_top = -mask.fBounds.fTop;
+ }
+ if (ftGlyph.bitmap_left < mask.fBounds.fLeft) {
+ int32_t leftDiff = mask.fBounds.fLeft - ftGlyph.bitmap_left;
+ ftGlyph.bitmap.buffer += leftDiff;
+ ftGlyph.bitmap.width -= leftDiff;
+ ftGlyph.bitmap_left = mask.fBounds.fLeft;
+ }
+ if (mask.fBounds.fTop < -ftGlyph.bitmap_top) {
+ mask.fImage += mask.fRowBytes * (-ftGlyph.bitmap_top - mask.fBounds.fTop);
+ mask.fBounds.fTop = -ftGlyph.bitmap_top;
+ }
+ if (mask.fBounds.fLeft < ftGlyph.bitmap_left) {
+ mask.fImage += sizeof(uint16_t) * (ftGlyph.bitmap_left - mask.fBounds.fLeft);
+ mask.fBounds.fLeft = ftGlyph.bitmap_left;
+ }
+ // Origins aligned, clean up the width and height.
+ int ftVertScale = (doVert ? 3 : 1);
+ int ftHoriScale = (doVert ? 1 : 3);
+ if (mask.fBounds.height() * ftVertScale < SkToInt(ftGlyph.bitmap.rows)) {
+ ftGlyph.bitmap.rows = mask.fBounds.height() * ftVertScale;
+ }
+ if (mask.fBounds.width() * ftHoriScale < SkToInt(ftGlyph.bitmap.width)) {
+ ftGlyph.bitmap.width = mask.fBounds.width() * ftHoriScale;
+ }
+ if (SkToInt(ftGlyph.bitmap.rows) < mask.fBounds.height() * ftVertScale) {
+ mask.fBounds.fBottom = mask.fBounds.fTop + ftGlyph.bitmap.rows / ftVertScale;
+ }
+ if (SkToInt(ftGlyph.bitmap.width) < mask.fBounds.width() * ftHoriScale) {
+ mask.fBounds.fRight = mask.fBounds.fLeft + ftGlyph.bitmap.width / ftHoriScale;
+ }
if (fPreBlend.isApplicable()) {
- copyFT2LCD16<true>(face->glyph->bitmap, mask, doBGR,
+ copyFT2LCD16<true>(ftGlyph.bitmap, mask, doBGR,
fPreBlend.fR, fPreBlend.fG, fPreBlend.fB);
} else {
- copyFT2LCD16<false>(face->glyph->bitmap, mask, doBGR,
+ copyFT2LCD16<false>(ftGlyph.bitmap, mask, doBGR,
fPreBlend.fR, fPreBlend.fG, fPreBlend.fB);
}
+ // Restore the buffer pointer so FreeType can properly free it.
+ ftGlyph.bitmap.buffer = origBuffer;
} else {
+ FT_BBox bbox;
+ FT_Bitmap target;
+ FT_Outline_Get_CBox(outline, &bbox);
+ /*
+ what we really want to do for subpixel is
+ offset(dx, dy)
+ compute_bounds
+ offset(bbox & !63)
+ but that is two calls to offset, so we do the following, which
+ achieves the same thing with only one offset call.
+ */
+ FT_Outline_Translate(outline, dx - ((bbox.xMin + dx) & ~63),
+ dy - ((bbox.yMin + dy) & ~63));
+
target.width = glyph.fWidth;
target.rows = glyph.fHeight;
target.pitch = glyph.rowBytes();
@@ -442,8 +501,15 @@ void SkScalerContext_FreeType_Base::generateGlyphImage(
target.pixel_mode = compute_pixel_mode( (SkMask::Format)fRec.fMaskFormat);
target.num_grays = 256;
- memset(glyph.fImage, 0, glyph.rowBytes() * glyph.fHeight);
FT_Outline_Get_Bitmap(face->glyph->library, outline, &target);
+#ifdef SK_SHOW_TEXT_BLIT_COVERAGE
+ for (int y = 0; y < glyph.fHeight; ++y) {
+ for (int x = 0; x < glyph.fWidth; ++x) {
+ uint8_t& a = ((uint8_t*)glyph.fImage)[(glyph.rowBytes() * y) + x];
+ a = SkTMax<uint8_t>(a, 0x20);
+ }
+ }
+#endif
}
} break;
--
2.13.2
......@@ -11,7 +11,7 @@ declare -rgA _system_libs=(
[flac]=flac
#[freetype]=freetype2 # https://crbug.com/pdfium/733
[harfbuzz-ng]=harfbuzz-icu
#[icu]=icu # Enable again when upstream supports ICU 59
[icu]=icu
[libdrm]=
[libjpeg]=libjpeg
#[libpng]=libpng # https://crbug.com/752403#c10
......@@ -27,7 +27,7 @@ declare -rgA _system_libs=(
)
pkgname=chromium
pkgver=61.0.3163.100
pkgver=62.0.3202.62
pkgrel=1
_launcher_ver=5
pkgdesc="A web browser built for speed, simplicity, and security"
......@@ -46,19 +46,15 @@ source=(https://commondatastorage.googleapis.com/chromium-browser-official/$pkgn
chromium-launcher-$_launcher_ver.tar.gz::https://github.com/foutrelis/chromium-launcher/archive/v$_launcher_ver.tar.gz
chromium.desktop
breakpad-use-ucontext_t.patch
chromium-gcc-r1.patch
chromium-gn-bootstrap-r14.patch
chromium-atk-r1.patch
chromium-blink-gcc7.patch
crc32c-string-view-check.patch
chromium-gn-bootstrap-r17.patch
chromium-widevine.patch)
sha256sums=('4135968cac6623c1d2b224494600cd274098cce41c298f8c3908b354a34c281b'
sha256sums=('e8df3150386729ddcb4971636627e54815ad447be5f122201e310f5bb0bcc362'
'4dc3428f2c927955d9ae117f2fb24d098cc6dd67adb760ac9c82b522ec8b0587'
'028a748a5c275de9b8f776f97909f999a8583a4b77fd1cd600b4fc5c0c3e91e9'
'6e9a345f810d36068ee74ebba4708c70ab30421dad3571b6be5e9db635078ea8'
'11cffe305dd49027c91638261463871e9ecb0ecc6ecc02bfa37b203c5960ab58'
'98784c4a0a793ecf34987bc8f91ae360d78596a4a59dd47651411381f752a080'
'fc0e9abb77b6f8e21a7601ff53f267a854736d711b530be5bbd80d976678e98d'
'f94310a7ba9b8b777adfb4442bcc0a8f0a3d549b2cf4a156066f8e2e28e2f323'
'35435e8dae76737baafecdc76d74a1c97281c4179e416556e033a06a31468e6d'
'd81319f168dad0e411c8e810f73daa2f56ff579578771bd9c9bb1aa2d7c09a8b'
'd6fdcb922e5a7fbe15759d39ccc8ea4225821c44d98054ce0f23f9d1f00c9808')
# Google API keys (see http://www.chromium.org/developers/how-tos/api-keys)
......@@ -71,22 +67,29 @@ _google_default_client_secret=TPvjII_2SwZn_9Ic0kRKqjtG
prepare() {
cd "$srcdir/$pkgname-$pkgver"
# https://crbug.com/710701
local _chrome_build_hash=$(curl -s https://chromium.googlesource.com/chromium/src.git/+/$pkgver?format=TEXT |
base64 -d | grep -Po '^parent \K[0-9a-f]{40}$')
if [[ -z $_chrome_build_hash ]]; then
error "Unable to fetch Chrome build hash."
return 1
fi
echo "LASTCHANGE=$_chrome_build_hash-" >build/util/LASTCHANGE
# Enable support for the Widevine CDM plugin
# libwidevinecdm.so is not included, but can be copied over from Chrome
# (Version string doesn't seem to matter so let's go with "Pinkie Pie")
sed "s/@WIDEVINE_VERSION@/Pinkie Pie/" ../chromium-widevine.patch |
patch -Np1
# https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=853347
patch -Np1 -i ../chromium-blink-gcc7.patch
# Fix build with glibc 2.26
patch -Np1 -i ../breakpad-use-ucontext_t.patch
# Fix incorrect inclusion of <string_view> in modes other than >= C++17
patch -Np1 -d third_party/crc32c/src <../crc32c-string-view-check.patch
# Fixes from Gentoo
patch -Np1 -i ../chromium-gcc-r1.patch
patch -Np1 -i ../chromium-gn-bootstrap-r14.patch
patch -Np1 -i ../chromium-atk-r1.patch
patch -Np1 -i ../chromium-gn-bootstrap-r17.patch
# Use Python 2
find . -name '*.py' -exec sed -i -r 's|/usr/bin/python$|&2|g' {} +
......
--- a/content/browser/accessibility/browser_accessibility_auralinux.cc.orig 2017-07-27 06:28:01.090257874 +0000
+++ b/content/browser/accessibility/browser_accessibility_auralinux.cc 2017-07-27 06:28:21.174653680 +0000
@@ -571,7 +571,7 @@
// it's best to leave this out rather than break people's builds:
#if defined(ATK_CHECK_VERSION)
#if ATK_CHECK_VERSION(2, 16, 0)
- atk_state_set_add_state(atk_state_set, ATK_STATE_READ_ONLY);
+ atk_state_set_add_state(state_set, ATK_STATE_READ_ONLY);
#endif
#endif
break;
--- chromium-59.0.3071.86/third_party/WebKit/Source/platform/wtf/LinkedHashSet.h.orig 2017-06-06 15:05:38.145247996 +0300
+++ chromium-59.0.3071.86/third_party/WebKit/Source/platform/wtf/LinkedHashSet.h 2017-06-06 15:06:13.866246667 +0300
@@ -685,6 +685,31 @@ inline LinkedHashSet<T, U, V, W>& Linked
return *this;
}
+inline void SwapAnchor(LinkedHashSetNodeBase& a, LinkedHashSetNodeBase& b) {
+ DCHECK(a.prev_);
+ DCHECK(a.next_);
+ DCHECK(b.prev_);
+ DCHECK(b.next_);
+ swap(a.prev_, b.prev_);
+ swap(a.next_, b.next_);
+ if (b.next_ == &a) {
+ DCHECK_EQ(b.prev_, &a);
+ b.next_ = &b;
+ b.prev_ = &b;
+ } else {
+ b.next_->prev_ = &b;
+ b.prev_->next_ = &b;
+ }
+ if (a.next_ == &b) {
+ DCHECK_EQ(a.prev_, &b);
+ a.next_ = &a;
+ a.prev_ = &a;
+ } else {
+ a.next_->prev_ = &a;
+ a.prev_->next_ = &a;
+ }
+}
+
template <typename T, typename U, typename V, typename W>
inline void LinkedHashSet<T, U, V, W>::Swap(LinkedHashSet& other) {
impl_.Swap(other.impl_);
@@ -877,31 +902,6 @@ inline void LinkedHashSet<T, U, V, W>::e
erase(Find(value));
}
-inline void SwapAnchor(LinkedHashSetNodeBase& a, LinkedHashSetNodeBase& b) {
- DCHECK(a.prev_);
- DCHECK(a.next_);
- DCHECK(b.prev_);
- DCHECK(b.next_);
- swap(a.prev_, b.prev_);
- swap(a.next_, b.next_);
- if (b.next_ == &a) {
- DCHECK_EQ(b.prev_, &a);
- b.next_ = &b;
- b.prev_ = &b;
- } else {
- b.next_->prev_ = &b;
- b.prev_->next_ = &b;
- }
- if (a.next_ == &b) {
- DCHECK_EQ(a.prev_, &b);
- a.next_ = &a;
- a.prev_ = &a;
- } else {
- a.next_->prev_ = &a;
- a.prev_->next_ = &a;
- }
-}
-
inline void swap(LinkedHashSetNodeBase& a, LinkedHashSetNodeBase& b) {
DCHECK_NE(a.next_, &a);
DCHECK_NE(b.next_, &b);
--- chromium-59.0.3071.86/third_party/WebKit/Source/platform/graphics/gpu/SharedGpuContext.h.orig 2017-06-06 16:16:43.657661313 +0300
+++ chromium-59.0.3071.86/third_party/WebKit/Source/platform/graphics/gpu/SharedGpuContext.h 2017-06-06 16:16:50.911198032 +0300
@@ -5,6 +5,7 @@
#include "platform/PlatformExport.h"
#include "platform/wtf/ThreadSpecific.h"
+#include <functional>
#include <memory>
namespace gpu {
diff --git a/base/numerics/safe_math_shared_impl.h b/base/numerics/safe_math_shared_impl.h
index 99f230ce7e9a..de2415d402f5 100644
--- a/base/numerics/safe_math_shared_impl.h
+++ b/base/numerics/safe_math_shared_impl.h
@@ -21,8 +21,7 @@
#if !defined(__native_client__) && \
((defined(__clang__) && \
((__clang_major__ > 3) || \
- (__clang_major__ == 3 && __clang_minor__ >= 4))) || \
- (defined(__GNUC__) && __GNUC__ >= 5))
+ (__clang_major__ == 3 && __clang_minor__ >= 4))))
#include "base/numerics/safe_math_clang_gcc_impl.h"
#define BASE_HAS_OPTIMIZED_SAFE_MATH (1)
#else
commit 96c271f8ab2be7ea4199078ea65ac50c6ada4685
Author: Pawel Hajdan, Jr <phajdan.jr@chromium.org>
Date: Wed Jul 26 21:51:54 2017 +0000
wip
diff --git a/tools/gn/bootstrap/bootstrap.py b/tools/gn/bootstrap/bootstrap.py
index 1390560f8e37..ff2ae57c46b0 100755
--- a/tools/gn/bootstrap/bootstrap.py
+++ b/tools/gn/bootstrap/bootstrap.py
@@ -449,6 +449,7 @@ def write_gn_ninja(path, root_gen_dir, options):
'base/metrics/histogram_base.cc',
'base/metrics/histogram_functions.cc',
'base/metrics/histogram_samples.cc',
+ 'base/metrics/histogram_snapshot_manager.cc',
'base/metrics/metrics_hashes.cc',
'base/metrics/persistent_histogram_allocator.cc',
'base/metrics/persistent_memory_allocator.cc',
@@ -534,7 +535,7 @@ def write_gn_ninja(path, root_gen_dir, options):
'base/trace_event/heap_profiler_allocation_context_tracker.cc',
'base/trace_event/heap_profiler_allocation_register.cc',
'base/trace_event/heap_profiler_event_filter.cc',
- 'base/trace_event/heap_profiler_event_writer.cc',
+ 'base/trace_event/heap_profiler_heap_dump_writer.cc',
'base/trace_event/heap_profiler_serialization_state.cc',
'base/trace_event/heap_profiler_stack_frame_deduplicator.cc',
'base/trace_event/heap_profiler_type_name_deduplicator.cc',
--- a/tools/gn/bootstrap/bootstrap.py
+++ b/tools/gn/bootstrap/bootstrap.py
@@ -179,6 +179,7 @@ def build_gn_with_ninja_manually(tempdir, options):
write_buildflag_header_manually(root_gen_dir, 'base/debug/debugging_flags.h',
{
+ 'ENABLE_LOCATION_SOURCE': 'false',
'ENABLE_PROFILING': 'false',
'CAN_UNWIND_WITH_FRAME_POINTERS': 'false'
})
@@ -204,7 +205,7 @@ def build_gn_with_ninja_manually(tempdir, options):
write_gn_ninja(os.path.join(tempdir, 'build.ninja'),
root_gen_dir, options)
- cmd = ['ninja', '-C', tempdir]
+ cmd = ['ninja', '-C', tempdir, '-w', 'dupbuild=err']
if options.verbose:
cmd.append('-v')
@@ -458,6 +459,7 @@ def write_gn_ninja(path, root_gen_dir, options):
'base/metrics/bucket_ranges.cc',
'base/metrics/field_trial.cc',
'base/metrics/field_trial_param_associator.cc',
+ 'base/metrics/field_trial_params.cc',
'base/metrics/histogram.cc',
'base/metrics/histogram_base.cc',
'base/metrics/histogram_functions.cc',
@@ -507,6 +509,7 @@ def write_gn_ninja(path, root_gen_dir, options):
'base/task_scheduler/scheduler_lock_impl.cc',
'base/task_scheduler/scheduler_single_thread_task_runner_manager.cc',
'base/task_scheduler/scheduler_worker.cc',
+ 'base/task_scheduler/scheduler_worker_pool.cc',
'base/task_scheduler/scheduler_worker_pool_impl.cc',
'base/task_scheduler/scheduler_worker_pool_params.cc',
'base/task_scheduler/scheduler_worker_stack.cc',
@@ -523,6 +526,7 @@ def write_gn_ninja(path, root_gen_dir, options):
'base/third_party/icu/icu_utf.cc',
'base/third_party/nspr/prtime.cc',
'base/threading/post_task_and_reply_impl.cc',
+ 'base/threading/scoped_blocking_call.cc',
'base/threading/sequence_local_storage_map.cc',
'base/threading/sequenced_task_runner_handle.cc',
'base/threading/sequenced_worker_pool.cc',
@@ -579,7 +583,6 @@ def write_gn_ninja(path, root_gen_dir, options):
'base/unguessable_token.cc',
'base/value_iterators.cc',
'base/values.cc',
- 'base/value_iterators.cc',
'base/vlog.cc',
])
@@ -652,7 +655,6 @@ def write_gn_ninja(path, root_gen_dir, options):
static_libraries['base']['sources'].extend([
'base/memory/shared_memory_handle_posix.cc',
'base/memory/shared_memory_posix.cc',
- 'base/memory/shared_memory_tracker.cc',
'base/nix/xdg_util.cc',
'base/process/internal_linux.cc',
'base/process/memory_linux.cc',
@@ -827,7 +829,7 @@ def build_gn_with_gn(temp_gn, build_dir, options):
cmd = [temp_gn, 'gen', build_dir, '--args=%s' % gn_gen_args]
check_call(cmd)
- cmd = ['ninja', '-C', build_dir]
+ cmd = ['ninja', '-C', build_dir, '-w', 'dupbuild=err']
if options.verbose:
cmd.append('-v')
cmd.append('gn')
--- a/media/ffmpeg/ffmpeg_common.h.orig 2017-04-07 18:17:22.623538889 +0000
+++ b/media/ffmpeg/ffmpeg_common.h 2017-04-07 18:18:16.780656283 +0000
@@ -23,10 +23,12 @@
// Include FFmpeg header files.
extern "C" {
+#if !defined(USE_SYSTEM_FFMPEG)
// Disable deprecated features which result in spammy compile warnings. This
// list of defines must mirror those in the 'defines' section of FFmpeg's
// BUILD.gn file or the headers below will generate different structures!
#define FF_API_CONVERGENCE_DURATION 0
+#endif // !defined(USE_SYSTEM_FFMPEG)
// Upstream libavcodec/utils.c still uses the deprecated
// av_dup_packet(), causing deprecation warnings.
// The normal fix for such things is to disable the feature as below,
@@ -40,7 +42,9 @@
MSVC_PUSH_DISABLE_WARNING(4244);
#include <libavcodec/avcodec.h>
#include <libavformat/avformat.h>
+#if !defined(USE_SYSTEM_FFMPEG)
#include <libavformat/internal.h>
+#endif // !defined(USE_SYSTEM_FFMPEG)
#include <libavformat/avio.h>
#include <libavutil/avutil.h>
#include <libavutil/imgutils.h>
--- a/media/filters/ffmpeg_demuxer.cc.orig 2017-04-07 18:15:14.776901183 +0000
+++ b/media/filters/ffmpeg_demuxer.cc 2017-04-07 18:15:54.813727201 +0000
@@ -1223,6 +1223,7 @@
// If no estimate is found, the stream entry will be kInfiniteDuration.
std::vector<base::TimeDelta> start_time_estimates(format_context->nb_streams,
kInfiniteDuration);
+#if !defined(USE_SYSTEM_FFMPEG)
const AVFormatInternal* internal = format_context->internal;
if (internal && internal->packet_buffer &&
format_context->start_time != static_cast<int64_t>(AV_NOPTS_VALUE)) {
@@ -1246,6 +1247,7 @@
packet_buffer = packet_buffer->next;
}
}
+#endif // !defined(USE_SYSTEM_FFMPEG)
std::unique_ptr<MediaTracks> media_tracks(new MediaTracks());
From d0f929a5db87cb34d03afb0d8e8bfc95b8f786e3 Mon Sep 17 00:00:00 2001
From: Victor Costan <costan@gmail.com>
Date: Mon, 11 Sep 2017 13:18:27 -0700
Subject: [PATCH] More conservative check for <string_view> availability. (#4)
has_include(<string_view>) does not imply that the header can be
included and will work. The assumption fails on MSVC and libc++ [1, 2].
Conversely, checking that __cplusplus > 201402L is not sufficient on its
own either, as the toolchain on Mac OS 10.12 passes that check but does
not contain a <string_view> header.
[1] https://crbug.com/759349
[2] https://gcc.gnu.org/bugzilla/show_bug.cgi?id=79433
---
include/crc32c/crc32c.h | 10 +++-------
src/crc32c_unittest.cc | 6 ++----
2 files changed, 5 insertions(+), 11 deletions(-)
diff --git a/include/crc32c/crc32c.h b/include/crc32c/crc32c.h
index 9f1973a..8ecab0d 100644
--- a/include/crc32c/crc32c.h
+++ b/include/crc32c/crc32c.h
@@ -33,22 +33,18 @@ inline uint32_t Crc32c(const std::string& string) {
string.size());
}
-#if defined(__has_include)
+#if __cplusplus > 201402L
#if __has_include(<string_view>)
-// Visual Studio provides a <string_view> header even in C++11 mode. When
-// included, the header issues an #error. (C1189)
-#if !defined(_MSC_VER) || __cplusplus >= 201703L
#include <string_view>
-// Comptues the CRC32C of the bytes in the string_view.
+// Computes the CRC32C of the bytes in the string_view.
inline uint32_t Crc32c(const std::string_view& string_view) {
return Crc32c(reinterpret_cast<const uint8_t*>(string_view.data()),
string_view.size());
}
-#endif // !defined(_MSC_VER) || __cplusplus >= 201703L
#endif // __has_include(<string_view>)
-#endif // defined(__has_include)
+#endif // __cplusplus > 201402L
} // namespace crc32c
diff --git a/src/crc32c_unittest.cc b/src/crc32c_unittest.cc
index 7a9c765..69babb3 100644
--- a/src/crc32c_unittest.cc
+++ b/src/crc32c_unittest.cc
@@ -95,9 +95,8 @@ TEST(CRC32CTest, Crc32cStdString) {
EXPECT_EQ(static_cast<uint32_t>(0x113fdb5c), crc32c::Crc32c(buf));
}
-#if defined(__has_include)
+#if __cplusplus > 201402L
#if __has_include(<string_view>)
-#if !defined(_MSC_VER) || __cplusplus >= 201703L
TEST(CRC32CTest, Crc32cStdStringView) {
uint8_t buf[32];
@@ -118,9 +117,8 @@ TEST(CRC32CTest, Crc32cStdStringView) {
EXPECT_EQ(static_cast<uint32_t>(0x113fdb5c), crc32c::Crc32c(view));
}
-#endif // !defined(_MSC_VER) || __cplusplus >= 201703L
#endif // __has_include(<string_view>)
-#endif // defined(__has_include)
+#endif // __cplusplus > 201402L
#define TESTED_EXTEND Extend
#include "./crc32c_extend_unittests.h"
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