From ade1cca41b0dde94ef04acbecc686415d303f0bc Mon Sep 17 00:00:00 2001 From: Yuhang Zhao <2546789017@qq.com> Date: Tue, 24 May 2022 09:51:55 +0800 Subject: [PATCH] Network: make Public Suffix List constexpr MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Upstream PR: https://github.com/rockdaboot/libpsl/pull/182 The repo owner denied the PR because the library only produces C89-compatible code and constexpr is a C++ feature. Task-number: QTBUG-100485 Change-Id: I9e01705b27022a636a98ac67b19169677d7c7652 Reviewed-by: Marc Mutz Reviewed-by: MÃ¥rten Nordheim (cherry picked from commit 797a493f5093187d2a849d9c483b79229a1316f0) Reviewed-by: Qt Cherry-pick Bot --- src/3rdparty/libpsl/qtpatches.diff | 42 ++++++++++++++++++++++++++ src/3rdparty/libpsl/src/psl-make-dafsa | 10 +++--- src/network/kernel/qurltlds_p.h | 2 +- 3 files changed, 48 insertions(+), 6 deletions(-) create mode 100644 src/3rdparty/libpsl/qtpatches.diff diff --git a/src/3rdparty/libpsl/qtpatches.diff b/src/3rdparty/libpsl/qtpatches.diff new file mode 100644 index 00000000000..1eb89bb862b --- /dev/null +++ b/src/3rdparty/libpsl/qtpatches.diff @@ -0,0 +1,42 @@ +diff --git a/src/3rdparty/libpsl/src/psl-make-dafsa b/src/3rdparty/libpsl/src/psl-make-dafsa +index 2bfd8796fa..8a374053d5 100755 +--- a/src/3rdparty/libpsl/src/psl-make-dafsa ++++ b/src/3rdparty/libpsl/src/psl-make-dafsa +@@ -161,7 +161,7 @@ sink = None + + A C++ representation of the compressed graph is generated: + +-const unsigned char dafsa[7] = { ++constexpr unsigned char dafsa[7] = { + 0x81, 0xE1, 0x02, 0x81, 0x82, 0x61, 0x81, + }; + +@@ -198,7 +198,7 @@ sink = None + + A C++ representation of the compressed graph is generated: + +-const unsigned char dafsa[11] = { ++constexpr unsigned char dafsa[11] = { + 0x02, 0x83, 0xE2, 0x02, 0x83, 0x61, 0x61, 0x81, 0x62, 0x62, 0x82, + }; + +@@ -490,7 +490,7 @@ def to_cxx(data, codecs): + text += b'The byte array encodes effective tld names. See psl-make-dafsa source for' + text += b' documentation.' + text += b'*/\n\n' +- text += b'static const unsigned char kDafsa[' ++ text += b'static constexpr unsigned char kDafsa[' + text += bytes(str(len(data)), **codecs) + text += b'] = {\n' + for i in range(0, len(data), 12): +@@ -517,8 +517,8 @@ def to_cxx_plus(data, codecs): + text += b'static int _psl_nsuffixes = %d;\n' % psl_nsuffixes + text += b'static int _psl_nexceptions = %d;\n' % psl_nexceptions + text += b'static int _psl_nwildcards = %d;\n' % psl_nwildcards +- text += b'static const char _psl_sha1_checksum[] = "%s";\n' % bytes(sha1_file(psl_input_file), **codecs) +- text += b'static const char _psl_filename[] = "%s";\n' % bytes(psl_input_file, **codecs) ++ text += b'static constexpr char _psl_sha1_checksum[] = "%s";\n' % bytes(sha1_file(psl_input_file), **codecs) ++ text += b'static constexpr char _psl_filename[] = "%s";\n' % bytes(psl_input_file, **codecs) + return text + + def words_to_whatever(words, converter, utf_mode, codecs): diff --git a/src/3rdparty/libpsl/src/psl-make-dafsa b/src/3rdparty/libpsl/src/psl-make-dafsa index 2bfd8796fa1..8a374053d58 100755 --- a/src/3rdparty/libpsl/src/psl-make-dafsa +++ b/src/3rdparty/libpsl/src/psl-make-dafsa @@ -161,7 +161,7 @@ sink = None A C++ representation of the compressed graph is generated: -const unsigned char dafsa[7] = { +constexpr unsigned char dafsa[7] = { 0x81, 0xE1, 0x02, 0x81, 0x82, 0x61, 0x81, }; @@ -198,7 +198,7 @@ sink = None A C++ representation of the compressed graph is generated: -const unsigned char dafsa[11] = { +constexpr unsigned char dafsa[11] = { 0x02, 0x83, 0xE2, 0x02, 0x83, 0x61, 0x61, 0x81, 0x62, 0x62, 0x82, }; @@ -490,7 +490,7 @@ def to_cxx(data, codecs): text += b'The byte array encodes effective tld names. See psl-make-dafsa source for' text += b' documentation.' text += b'*/\n\n' - text += b'static const unsigned char kDafsa[' + text += b'static constexpr unsigned char kDafsa[' text += bytes(str(len(data)), **codecs) text += b'] = {\n' for i in range(0, len(data), 12): @@ -517,8 +517,8 @@ def to_cxx_plus(data, codecs): text += b'static int _psl_nsuffixes = %d;\n' % psl_nsuffixes text += b'static int _psl_nexceptions = %d;\n' % psl_nexceptions text += b'static int _psl_nwildcards = %d;\n' % psl_nwildcards - text += b'static const char _psl_sha1_checksum[] = "%s";\n' % bytes(sha1_file(psl_input_file), **codecs) - text += b'static const char _psl_filename[] = "%s";\n' % bytes(psl_input_file, **codecs) + text += b'static constexpr char _psl_sha1_checksum[] = "%s";\n' % bytes(sha1_file(psl_input_file), **codecs) + text += b'static constexpr char _psl_filename[] = "%s";\n' % bytes(psl_input_file, **codecs) return text def words_to_whatever(words, converter, utf_mode, codecs): diff --git a/src/network/kernel/qurltlds_p.h b/src/network/kernel/qurltlds_p.h index d7889788453..0639247e190 100644 --- a/src/network/kernel/qurltlds_p.h +++ b/src/network/kernel/qurltlds_p.h @@ -2,7 +2,7 @@ The byte array encodes effective tld names. See psl-make-dafsa source for documentation.*/ -static const unsigned char kDafsa[53647] = { +static constexpr unsigned char kDafsa[53647] = { 0x40, 0x42, 0x4a, 0xa2, 0x40, 0xc1, 0x42, 0xc1, 0x50, 0xa1, 0x43, 0xaf, 0x43, 0x58, 0x43, 0x5d, 0x49, 0xab, 0x51, 0x6f, 0x44, 0xcb, 0x40, 0x7b, 0x47, 0x14, 0x47, 0x05, 0x49, 0x33, 0x4c, 0x44, 0x45, 0x5b, 0x4a, 0xc3,