From aa0c5df4199ef4e96df2b856c8f629e49fdd5120 Mon Sep 17 00:00:00 2001 From: Ebrahim Byagowi Date: Sun, 17 Jun 2018 16:49:34 +0430 Subject: [PATCH 001/106] Fix reading fonts from stdin (#1060) We were passing the font path directly to freetype so rendering was broken when we are getting the font from stdin. This fixes it by using FT_New_Memory_Face instead. This fixes: * build/util/hb-view /dev/stdin text < font.ttf * build/util/hb-view - text < font.ttf * cat font.ttf | build/util/hb-view - text but doesn't work on * cat font.ttf | build/util/hb-view /dev/stdin text which I will try to fix separately. --- util/helper-cairo.cc | 14 ++++++++++---- util/options.cc | 5 ++--- util/options.hh | 4 +++- 3 files changed, 15 insertions(+), 8 deletions(-) diff --git a/util/helper-cairo.cc b/util/helper-cairo.cc index b9f498516..3eaf90a74 100644 --- a/util/helper-cairo.cc +++ b/util/helper-cairo.cc @@ -89,10 +89,16 @@ helper_cairo_create_scaled_font (const font_options_t *font_opts) atexit (free_ft_library); #endif } - FT_New_Face (ft_library, - font_opts->font_file, - font_opts->face_index, - &ft_face); + + unsigned int blob_length; + const char *blob_data = hb_blob_get_data (font_opts->blob, &blob_length); + + if (FT_New_Memory_Face (ft_library, + (const FT_Byte *) blob_data, + blob_length, + font_opts->face_index, + &ft_face)) + fail (false, "FT_New_Memory_Face fail"); } if (!ft_face) { diff --git a/util/options.cc b/util/options.cc index 24dc41f26..4c65735f8 100644 --- a/util/options.cc +++ b/util/options.cc @@ -643,8 +643,6 @@ font_options_t::get_font (void) const if (font) return font; - hb_blob_t *blob = nullptr; - /* Create the blob */ if (!font_file) fail (true, "No font file set"); @@ -663,8 +661,9 @@ font_options_t::get_font (void) const strerror (errno)); g_string_append_len (gs, buf, ret); } + unsigned int len = gs->len; char *font_data = g_string_free (gs, false); - blob = hb_blob_create (font_data, gs->len, + blob = hb_blob_create (font_data, len, HB_MEMORY_MODE_WRITABLE, font_data, (hb_destroy_func_t) g_free); } else { diff --git a/util/options.hh b/util/options.hh index 8dfc84200..5287395af 100644 --- a/util/options.hh +++ b/util/options.hh @@ -455,6 +455,7 @@ struct font_options_t : option_group_t font_size_x = font_size_y = default_font_size; font_funcs = nullptr; + blob = nullptr; font = nullptr; add_options (parser); @@ -471,6 +472,7 @@ struct font_options_t : option_group_t hb_font_t *get_font (void) const; char *font_file; + mutable hb_blob_t *blob; int face_index; hb_variation_t *variations; unsigned int num_variations; @@ -483,7 +485,7 @@ struct font_options_t : option_group_t mutable double font_size_y; char *font_funcs; - private: +private: mutable hb_font_t *font; }; From c53697d3f2a3fae8b68ec4c5146c7000a07e0963 Mon Sep 17 00:00:00 2001 From: Ebrahim Byagowi Date: Sun, 17 Jun 2018 17:04:55 +0430 Subject: [PATCH 002/106] Verbose fail when something is wrong with hb-shape/hb-view input font file (#1059) This checks if the blob isn't empty and uses `hb_face_count` to see if the font file passes the simple font file sanitization so can detect if the input is actually a font and checks also whether input font-index is out of range. --- util/options.cc | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/util/options.cc b/util/options.cc index 4c65735f8..299466fe6 100644 --- a/util/options.cc +++ b/util/options.cc @@ -670,6 +670,17 @@ font_options_t::get_font (void) const blob = hb_blob_create_from_file (font_file); } + if (hb_blob_get_length (blob) == 0) + fail (false, "No such file or directory, or is empty"); + + unsigned int face_count = hb_face_count (blob); + + if (face_count == 0) + fail (false, "Not a font file"); // most likely + + if (face_index > face_count) + fail (false, "The requested font index wasn't available in the file"); + /* Create the face */ hb_face_t *face = hb_face_create (blob, face_index); hb_blob_destroy (blob); From d0c2889dfc43da92c76d6eab5482b1298744dc9c Mon Sep 17 00:00:00 2001 From: Ebrahim Byagowi Date: Mon, 18 Jun 2018 19:59:33 +0430 Subject: [PATCH 003/106] Revert file blob sanitization and index checking (#1062) As https://github.com/harfbuzz/harfbuzz/pull/1059#issuecomment-397912812 we like to still work with blobs that harfbuzz itself can't handle directly that are failing sanitization currently apparently. --- util/options.cc | 12 ++---------- util/options.hh | 2 +- 2 files changed, 3 insertions(+), 11 deletions(-) diff --git a/util/options.cc b/util/options.cc index 299466fe6..682e40c4d 100644 --- a/util/options.cc +++ b/util/options.cc @@ -670,16 +670,8 @@ font_options_t::get_font (void) const blob = hb_blob_create_from_file (font_file); } - if (hb_blob_get_length (blob) == 0) - fail (false, "No such file or directory, or is empty"); - - unsigned int face_count = hb_face_count (blob); - - if (face_count == 0) - fail (false, "Not a font file"); // most likely - - if (face_index > face_count) - fail (false, "The requested font index wasn't available in the file"); + if (blob == hb_blob_get_empty ()) + fail (false, "No such file or directory"); /* Create the face */ hb_face_t *face = hb_face_create (blob, face_index); diff --git a/util/options.hh b/util/options.hh index 5287395af..2160d5ec3 100644 --- a/util/options.hh +++ b/util/options.hh @@ -485,7 +485,7 @@ struct font_options_t : option_group_t mutable double font_size_y; char *font_funcs; -private: + private: mutable hb_font_t *font; }; From 941f2b85489b344698bf036922c589483034a7f2 Mon Sep 17 00:00:00 2001 From: Ebrahim Byagowi Date: Mon, 18 Jun 2018 20:35:40 +0430 Subject: [PATCH 004/106] Support pipe and friends on hb_blob_create_from_file (#1061) With this hb-view/hb-shape support pipes and possibly socket and named pipe also, anything fails just on mmap. We can later do the same for Windows also. This however reveals two issues, the fact most of our bots don't have HAVE_MMAP and using this instead the other fread/fopen reader can make failure on CI. I should look at them separately this change however is very low risk I believe. --- src/hb-blob.cc | 44 +++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 43 insertions(+), 1 deletion(-) diff --git a/src/hb-blob.cc b/src/hb-blob.cc index c138648ca..77dbc7150 100644 --- a/src/hb-blob.cc +++ b/src/hb-blob.cc @@ -499,6 +499,36 @@ hb_blob_t::try_make_writable (void) # define MAP_NORESERVE 0 #endif +static hb_blob_t * +_fread_to_end (FILE *file) +{ + int allocated = BUFSIZ * 16; + char *blob = (char *) malloc (allocated); + if (blob == nullptr) return hb_blob_get_empty (); + + int len = 0; + while (!feof (file)) + { + if (allocated - len < BUFSIZ) + { + allocated *= 2; + char *new_blob = (char *) realloc (blob, allocated); + if (unlikely (!new_blob)) goto fail; + blob = new_blob; + } + + len += fread (blob + len, 1, allocated - len, file); + if (ferror (file)) goto fail; + } + + return hb_blob_create (blob, len, HB_MEMORY_MODE_WRITABLE, blob, + (hb_destroy_func_t) free); + +fail: + free (blob); + return hb_blob_get_empty (); +} + struct hb_mapped_file_t { char *contents; @@ -557,7 +587,19 @@ hb_blob_create_from_file (const char *file_name) writable ? PROT_READ|PROT_WRITE : PROT_READ, MAP_PRIVATE | MAP_NORESERVE, fd, 0); - if (unlikely (file->contents == MAP_FAILED)) goto fail; + if (unlikely (file->contents == MAP_FAILED)) + { + free (file); + FILE *f = fdopen (fd, "rb"); + if (unlikely (f == nullptr)) + { + CLOSE (fd); + return hb_blob_get_empty (); + } + hb_blob_t *blob = _fread_to_end (f); + fclose (f); + return blob; + } #elif defined(_WIN32) || defined(__CYGWIN__) HANDLE fd = CreateFile (file_name, From b2a187918757a0faaf0f564ec2b0766c09fa364c Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Sat, 23 Jun 2018 10:32:28 -0400 Subject: [PATCH 005/106] In Coverage iterator, bail out if table smells In particular, if CoverageFormat2 has unsorted ranges, bail out. Otherwise, 64k ranges of each 64k glyphs can DoS closure() method. We can do the same for CoverageFormat1, but that one does not expose the quadratic behavior, so, fine. --- src/hb-ot-layout-common-private.hh | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/src/hb-ot-layout-common-private.hh b/src/hb-ot-layout-common-private.hh index 763ea92f9..ff9c5650f 100644 --- a/src/hb-ot-layout-common-private.hh +++ b/src/hb-ot-layout-common-private.hh @@ -832,7 +832,12 @@ struct CoverageFormat2 c = &c_; coverage = 0; i = 0; - j = c->rangeRecord.len ? c_.rangeRecord[0].start : 0; + j = c->rangeRecord.len ? c->rangeRecord[0].start : 0; + if (unlikely (c->rangeRecord[0].start > c->rangeRecord[0].end)) + { + /* Broken table. Skip. */ + i = c->rangeRecord.len; + } } inline bool more (void) { return i < c->rangeRecord.len; } inline void next (void) @@ -842,7 +847,14 @@ struct CoverageFormat2 i++; if (more ()) { + hb_codepoint_t old = j; j = c->rangeRecord[i].start; + if (unlikely (j <= old)) + { + /* Broken table. Skip. Important to avoid DoS. */ + i = c->rangeRecord.len; + return; + } coverage = c->rangeRecord[i].value; } return; @@ -855,7 +867,8 @@ struct CoverageFormat2 private: const struct CoverageFormat2 *c; - unsigned int i, j, coverage; + unsigned int i, coverage; + hb_codepoint_t j; }; private: From 159ddb872986f121818e816d2ea75d271075ba1f Mon Sep 17 00:00:00 2001 From: Ebrahim Byagowi Date: Sun, 24 Jun 2018 23:09:16 +0430 Subject: [PATCH 006/106] Treat - just as /dev/stdin and remove one extra file reader (#1065) --- util/options.cc | 27 +++++++++------------------ 1 file changed, 9 insertions(+), 18 deletions(-) diff --git a/util/options.cc b/util/options.cc index 682e40c4d..57cc4aa8d 100644 --- a/util/options.cc +++ b/util/options.cc @@ -647,29 +647,20 @@ font_options_t::get_font (void) const if (!font_file) fail (true, "No font file set"); - if (0 == strcmp (font_file, "-")) { - /* read it */ - GString *gs = g_string_new (nullptr); - char buf[BUFSIZ]; + const char *font_path = font_file; + + if (0 == strcmp (font_path, "-")) + { #if defined(_WIN32) || defined(__CYGWIN__) setmode (fileno (stdin), O_BINARY); + font_path = "STDIN"; +#else + font_path = "/dev/stdin"; #endif - while (!feof (stdin)) { - size_t ret = fread (buf, 1, sizeof (buf), stdin); - if (ferror (stdin)) - fail (false, "Failed reading font from standard input: %s", - strerror (errno)); - g_string_append_len (gs, buf, ret); - } - unsigned int len = gs->len; - char *font_data = g_string_free (gs, false); - blob = hb_blob_create (font_data, len, - HB_MEMORY_MODE_WRITABLE, font_data, - (hb_destroy_func_t) g_free); - } else { - blob = hb_blob_create_from_file (font_file); } + blob = hb_blob_create_from_file (font_path); + if (blob == hb_blob_get_empty ()) fail (false, "No such file or directory"); From f57804a8a596e88843ddc8b88afac7526349b89b Mon Sep 17 00:00:00 2001 From: Ebrahim Byagowi Date: Mon, 25 Jun 2018 18:45:49 +0430 Subject: [PATCH 007/106] Resolve ttx absolute path before use (#1075) --- test/subset/run-tests.py | 101 ++++++++++++++++++++++----------------- 1 file changed, 57 insertions(+), 44 deletions(-) diff --git a/test/subset/run-tests.py b/test/subset/run-tests.py index 1cd1a19f6..bc0d082e2 100755 --- a/test/subset/run-tests.py +++ b/test/subset/run-tests.py @@ -15,75 +15,94 @@ import tempfile from subset_test_suite import SubsetTestSuite +# https://stackoverflow.com/a/377028 +def which(program): + def is_exe(fpath): + return os.path.isfile(fpath) and os.access(fpath, os.X_OK) + + fpath, _ = os.path.split(program) + if fpath: + if is_exe(program): + return program + else: + for path in os.environ["PATH"].split(os.pathsep): + exe_file = os.path.join(path, program) + if is_exe(exe_file): + return exe_file + + return None + +ttx = which ("ttx") +ots_sanitize = which ("ots-sanitize") + +if not ttx: + print("TTX is not present, skipping test.") + sys.exit (77) def cmd(command): p = subprocess.Popen ( command, stdout=subprocess.PIPE, stderr=subprocess.PIPE) - (stdoutdata, stderrdata) = p.communicate() + (stdoutdata, stderrdata) = p.communicate () print (stderrdata, end="") # file=sys.stderr return stdoutdata, p.returncode -def read_binary(file_path): - with open(file_path, 'rb') as f: - return f.read() +def read_binary (file_path): + with open (file_path, 'rb') as f: + return f.read () def fail_test(test, cli_args, message): print ('ERROR: %s' % message) print ('Test State:') - print (' test.font_path %s' % os.path.abspath(test.font_path)) - print (' test.profile_path %s' % os.path.abspath(test.profile_path)) - print (' test.unicodes %s' % test.unicodes()) - expected_file = os.path.join(test_suite.get_output_directory(), - test.get_font_name()) - print (' expected_file %s' % os.path.abspath(expected_file)) + print (' test.font_path %s' % os.path.abspath (test.font_path)) + print (' test.profile_path %s' % os.path.abspath (test.profile_path)) + print (' test.unicodes %s' % test.unicodes ()) + expected_file = os.path.join(test_suite.get_output_directory (), + test.get_font_name ()) + print (' expected_file %s' % os.path.abspath (expected_file)) return 1 def run_test(test, should_check_ots): - out_file = os.path.join(tempfile.mkdtemp(), test.get_font_name() + '-subset.ttf') + out_file = os.path.join(tempfile.mkdtemp (), test.get_font_name () + '-subset.ttf') cli_args = [hb_subset, "--font-file=" + test.font_path, "--output-file=" + out_file, - "--unicodes=%s" % test.unicodes()] - cli_args.extend (test.get_profile_flags()) - print (' '.join(cli_args)) - _, return_code = cmd(cli_args) + "--unicodes=%s" % test.unicodes ()] + cli_args.extend (test.get_profile_flags ()) + print (' '.join (cli_args)) + _, return_code = cmd (cli_args) if return_code: - return fail_test(test, cli_args, "%s returned %d" % (' '.join(cli_args), return_code)) + return fail_test (test, cli_args, "%s returned %d" % (' '.join (cli_args), return_code)) - expected_ttx, return_code = run_ttx(os.path.join(test_suite.get_output_directory(), - test.get_font_name())) + expected_ttx, return_code = run_ttx (os.path.join (test_suite.get_output_directory (), + test.get_font_name ())) if return_code: - return fail_test(test, cli_args, "ttx (expected) returned %d" % (return_code)) + return fail_test (test, cli_args, "ttx (expected) returned %d" % (return_code)) actual_ttx, return_code = run_ttx(out_file) if return_code: - return fail_test(test, cli_args, "ttx (actual) returned %d" % (return_code)) + return fail_test (test, cli_args, "ttx (actual) returned %d" % (return_code)) print ("stripping checksums.") expected_ttx = strip_check_sum (expected_ttx) actual_ttx = strip_check_sum (actual_ttx) if not actual_ttx == expected_ttx: - for line in unified_diff(expected_ttx.splitlines(1), actual_ttx.splitlines(1)): - sys.stdout.write(line) - sys.stdout.flush() + for line in unified_diff (expected_ttx.splitlines (1), actual_ttx.splitlines (1)): + sys.stdout.write (line) + sys.stdout.flush () return fail_test(test, cli_args, 'ttx for expected and actual does not match.') if should_check_ots: print ("Checking output with ots-sanitize.") - if not check_ots(out_file): - return fail_test(test, cli_args, 'ots for subsetted file fails.') + if not check_ots (out_file): + return fail_test (test, cli_args, 'ots for subsetted file fails.') return 0 -def run_ttx(file): +def run_ttx (file): print ("ttx %s" % file) - cli_args = ["ttx", - "-q", - "-o-", - file] - return cmd(cli_args) + return cmd([ttx, "-q", "-o-", file]) def strip_check_sum (ttx_string): return re.sub ('checkSumAdjustment value=["]0x([0-9a-fA-F])+["]', @@ -91,14 +110,13 @@ def strip_check_sum (ttx_string): ttx_string.decode (), count=1) def has_ots (): - _, returncode = cmd(["which", "ots-sanitize"]) - if returncode: + if not ots_sanitize: print("OTS is not present, skipping all ots checks.") return False return True def check_ots (path): - ots_report, returncode = cmd(["ots-sanitize", path]) + ots_report, returncode = cmd ([ots_sanitize, path]) if returncode: print("OTS Failure: %s" % ots_report); return False @@ -110,24 +128,19 @@ if not args or sys.argv[1].find('hb-subset') == -1 or not os.path.exists (sys.ar sys.exit (1) hb_subset, args = args[0], args[1:] -if not len(args): +if not len (args): print ("No tests supplied.") sys.exit (1) -_, returncode = cmd(["which", "ttx"]) -if returncode: - print("TTX is not present, skipping test.") - sys.exit (77) - has_ots = has_ots() fails = 0 for path in args: - with io.open(path, mode="r", encoding="utf-8") as f: + with io.open (path, mode="r", encoding="utf-8") as f: print ("Running tests in " + path) - test_suite = SubsetTestSuite(path, f.read()) - for test in test_suite.tests(): - fails += run_test(test, has_ots) + test_suite = SubsetTestSuite (path, f.read()) + for test in test_suite.tests (): + fails += run_test (test, has_ots) if fails != 0: print (str (fails) + " test(s) failed.") From 35ce8f31d37cf7c2a1f8265d36ba4c2c9a3efb2c Mon Sep 17 00:00:00 2001 From: Ebrahim Byagowi Date: Mon, 25 Jun 2018 22:23:43 +0430 Subject: [PATCH 008/106] Unify our pipe reader with the fallback reader (#1068) And assign one bot to use the path always using NOMMAPFILEREADER token. It's limited to 200mb so no more fun with using /dev/zero on hb-view! --- .circleci/config.yml | 6 +- src/hb-blob.cc | 154 +++++++++++++++++++------------------------ 2 files changed, 69 insertions(+), 91 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 558200057..de130b506 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -40,14 +40,14 @@ jobs: - run: rm -rf harfbuzz-* - run: make distdir && cd harfbuzz-* && cmake -DHB_CHECK=ON -Bbuild -H. -GNinja && ninja -Cbuild && CTEST_OUTPUT_ON_FAILURE=1 ninja -Cbuild test && ninja -Cbuild install - alpine-O3: + alpine-O3-NOMMAP: docker: - image: alpine steps: - checkout - run: apk update && apk add ragel make pkgconfig libtool autoconf automake gettext gcc g++ glib-dev freetype-dev cairo-dev # C??FLAGS are not needed for a regular build - - run: CFLAGS="-O3" CXXFLAGS="-O3" ./autogen.sh + - run: CFLAGS="-O3" CXXFLAGS="-O3 -DNOMMAPFILEREADER" ./autogen.sh - run: make - run: make check || .ci/fail.sh @@ -196,7 +196,7 @@ workflows: - distcheck # autotools based builds - - alpine-O3 + - alpine-O3-NOMMAP - archlinux-debug-O0-py3 - clang-O3-O0 - fedora-outoftreebuild diff --git a/src/hb-blob.cc b/src/hb-blob.cc index 77dbc7150..37a6d8cbc 100644 --- a/src/hb-blob.cc +++ b/src/hb-blob.cc @@ -499,36 +499,6 @@ hb_blob_t::try_make_writable (void) # define MAP_NORESERVE 0 #endif -static hb_blob_t * -_fread_to_end (FILE *file) -{ - int allocated = BUFSIZ * 16; - char *blob = (char *) malloc (allocated); - if (blob == nullptr) return hb_blob_get_empty (); - - int len = 0; - while (!feof (file)) - { - if (allocated - len < BUFSIZ) - { - allocated *= 2; - char *new_blob = (char *) realloc (blob, allocated); - if (unlikely (!new_blob)) goto fail; - blob = new_blob; - } - - len += fread (blob + len, 1, allocated - len, file); - if (ferror (file)) goto fail; - } - - return hb_blob_create (blob, len, HB_MEMORY_MODE_WRITABLE, blob, - (hb_destroy_func_t) free); - -fail: - free (blob); - return hb_blob_get_empty (); -} - struct hb_mapped_file_t { char *contents; @@ -547,7 +517,7 @@ _hb_mapped_file_destroy (hb_mapped_file_t *file) UnmapViewOfFile (file->contents); CloseHandle (file->mapping); #else - free (file->contents); + assert (0); // If we don't have mmap we shouldn't reach here #endif free (file); @@ -566,87 +536,95 @@ hb_blob_create_from_file (const char *file_name) { // Adopted from glib's gmappedfile.c with Matthias Clasen and // Allison Lortie permission but changed a lot to suit our need. - bool writable = false; - hb_memory_mode_t mm = HB_MEMORY_MODE_READONLY_MAY_MAKE_WRITABLE; +#if defined(HAVE_MMAP) && !defined(NOMMAPFILEREADER) hb_mapped_file_t *file = (hb_mapped_file_t *) calloc (1, sizeof (hb_mapped_file_t)); if (unlikely (!file)) return hb_blob_get_empty (); -#ifdef HAVE_MMAP - int fd = open (file_name, (writable ? O_RDWR : O_RDONLY) | _O_BINARY, 0); -# define CLOSE close + int fd = open (file_name, O_RDONLY | _O_BINARY, 0); if (unlikely (fd == -1)) goto fail_without_close; struct stat st; if (unlikely (fstat (fd, &st) == -1)) goto fail; - // See https://github.com/GNOME/glib/blob/f9faac7/glib/gmappedfile.c#L139-L142 - if (unlikely (st.st_size == 0 && S_ISREG (st.st_mode))) goto fail; - file->length = (unsigned long) st.st_size; - file->contents = (char *) mmap (nullptr, file->length, - writable ? PROT_READ|PROT_WRITE : PROT_READ, + file->contents = (char *) mmap (nullptr, file->length, PROT_READ, MAP_PRIVATE | MAP_NORESERVE, fd, 0); - if (unlikely (file->contents == MAP_FAILED)) - { - free (file); - FILE *f = fdopen (fd, "rb"); - if (unlikely (f == nullptr)) - { - CLOSE (fd); - return hb_blob_get_empty (); - } - hb_blob_t *blob = _fread_to_end (f); - fclose (f); - return blob; - } + if (unlikely (file->contents == MAP_FAILED)) goto fail; -#elif defined(_WIN32) || defined(__CYGWIN__) - HANDLE fd = CreateFile (file_name, - writable ? GENERIC_READ|GENERIC_WRITE : GENERIC_READ, - FILE_SHARE_READ, nullptr, OPEN_EXISTING, - FILE_ATTRIBUTE_NORMAL | FILE_FLAG_OVERLAPPED, nullptr); -# define CLOSE CloseHandle + close (fd); + + return hb_blob_create (file->contents, file->length, + HB_MEMORY_MODE_READONLY_MAY_MAKE_WRITABLE, (void *) file, + (hb_destroy_func_t) _hb_mapped_file_destroy); + +fail: + close (fd); +fail_without_close: + free (file); + +#elif (defined(_WIN32) || defined(__CYGWIN__)) && !defined(NOMMAPFILEREADER) + hb_mapped_file_t *file = (hb_mapped_file_t *) calloc (1, sizeof (hb_mapped_file_t)); + if (unlikely (!file)) return hb_blob_get_empty (); + + HANDLE fd = CreateFile (file_name, GENERIC_READ, FILE_SHARE_READ, nullptr, + OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL|FILE_FLAG_OVERLAPPED, + nullptr); if (unlikely (fd == INVALID_HANDLE_VALUE)) goto fail_without_close; file->length = (unsigned long) GetFileSize (fd, nullptr); - file->mapping = CreateFileMapping (fd, nullptr, - writable ? PAGE_WRITECOPY : PAGE_READONLY, - 0, 0, nullptr); + file->mapping = CreateFileMapping (fd, nullptr, PAGE_READONLY, 0, 0, nullptr); if (unlikely (file->mapping == nullptr)) goto fail; - file->contents = (char *) MapViewOfFile (file->mapping, - writable ? FILE_MAP_COPY : FILE_MAP_READ, - 0, 0, 0); + file->contents = (char *) MapViewOfFile (file->mapping, FILE_MAP_READ, 0, 0, 0); if (unlikely (file->contents == nullptr)) goto fail; -#else - mm = HB_MEMORY_MODE_WRITABLE; - - FILE *fd = fopen (file_name, "rb"); -# define CLOSE fclose - if (unlikely (!fd)) goto fail_without_close; - - fseek (fd, 0, SEEK_END); - file->length = ftell (fd); - rewind (fd); - file->contents = (char *) malloc (file->length); - if (unlikely (!file->contents)) goto fail; - - if (unlikely (fread (file->contents, 1, file->length, fd) != file->length)) - goto fail; - -#endif - - CLOSE (fd); - return hb_blob_create (file->contents, file->length, mm, (void *) file, + CloseHandle (fd); + return hb_blob_create (file->contents, file->length, + HB_MEMORY_MODE_READONLY_MAY_MAKE_WRITABLE, (void *) file, (hb_destroy_func_t) _hb_mapped_file_destroy); fail: - CLOSE (fd); -#undef CLOSE + CloseHandle (fd); fail_without_close: free (file); + +#endif + + // The following tries to read a file without knowing its size beforehand + // It's used for systems without mmap concept or to read from pipes + int len = 0; + int allocated = BUFSIZ * 16; + char *blob = (char *) malloc (allocated); + if (blob == nullptr) return hb_blob_get_empty (); + + FILE *fp = fopen (file_name, "rb"); + if (unlikely (fp == nullptr)) goto fread_fail_without_close; + + while (!feof (fp)) + { + if (allocated - len < BUFSIZ) + { + allocated *= 2; + // Don't allocate more than 200MB, our mmap reader still + // can cover files like that but lets limit our fallback reader + if (unlikely (allocated > 200000000)) goto fread_fail; + char *new_blob = (char *) realloc (blob, allocated); + if (unlikely (!new_blob)) goto fread_fail; + blob = new_blob; + } + + len += fread (blob + len, 1, allocated - len, fp); + if (unlikely (ferror (fp))) goto fread_fail; + } + + return hb_blob_create (blob, len, HB_MEMORY_MODE_WRITABLE, blob, + (hb_destroy_func_t) free); + +fread_fail: + fclose (fp); +fread_fail_without_close: + free (blob); return hb_blob_get_empty (); } From 4f8753464ae44dfb60bee81ede10448175db7b90 Mon Sep 17 00:00:00 2001 From: Garret Rieger Date: Fri, 22 Jun 2018 15:29:34 -0700 Subject: [PATCH 009/106] [subset] Add fuzzer test case that caused a timeout to the corpus. --- ...-minimized-hb-subset-fuzzer-5750092395970560 | Bin 0 -> 72435 bytes 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 test/api/fonts/clusterfuzz-testcase-minimized-hb-subset-fuzzer-5750092395970560 diff --git a/test/api/fonts/clusterfuzz-testcase-minimized-hb-subset-fuzzer-5750092395970560 b/test/api/fonts/clusterfuzz-testcase-minimized-hb-subset-fuzzer-5750092395970560 new file mode 100644 index 0000000000000000000000000000000000000000..d622c25639f5be075900ab05a159f933eeb4a72d GIT binary patch literal 72435 zcmeFa4SW>Geg8i@dkE=tdf@JKItfY0JjgNzEMqLo7-Nj_B4Z4?1!EzDES`jTl4T)? zjDZpigkXX(!GuyuD0Kdzh>OD zF%6rG=S)L-FN&)kH?yfQbxFb3lvPrQ<+Zg96Q}(s{G+Q#FIFn`D-*{|Z$N&gviivK z1iY&FbB~ zkv^(auzu=`{e~&zYTw3{g`PJYL744hxBo!e1jTZ zoZj^9*VkvNHeV=I>XF|xG)`!km)CegwfQHc)td-XTL}iBj;d8!r6`}(R#{fEm7=ue z*F%)0huRM)ZTGS#Da-yxUy8DP>Av>L_I33&fuHluPF5<4b(7_2l@Dt_Vz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>OV@U$Km@HREe(R>s%L_*xN{E8}Z<4DX@Yb}Zv- zKjy8^xA7dy_}Y(Qm$Zzp&B*{(Q2f4w0$4$v$_sJePY@ryLa#vmNzj&xK-~A&$Qb=P zy-JSIZ_o{Llzx*w4e{UKrq7bQ>38XKM5W&YH6opUAM}HC`U6n>(dkQ|yfX~ZMR{5@q<2rRsTmT$B@{Oo{RyQJxj$IZ-|+%AzP`$f*oD-RU&k zt8RvY%3x6LrnMY=7PlRE+coLRJE*Qax!wH#db_y{o!ps+Pv+f&M0_&u-r>o+_b>gE BZhZg% literal 0 HcmV?d00001 From 7db2e9ea38329b9393c9e8cc905b180735c9b0f4 Mon Sep 17 00:00:00 2001 From: Ebrahim Byagowi Date: Tue, 26 Jun 2018 10:46:10 +0430 Subject: [PATCH 010/106] Minor on hb_blob_create_from_file Add one more "unlikely" annotation and use explicit nullptr check for more consistency. --- src/hb-blob.cc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/hb-blob.cc b/src/hb-blob.cc index 37a6d8cbc..155c2e6b1 100644 --- a/src/hb-blob.cc +++ b/src/hb-blob.cc @@ -597,7 +597,7 @@ fail_without_close: int len = 0; int allocated = BUFSIZ * 16; char *blob = (char *) malloc (allocated); - if (blob == nullptr) return hb_blob_get_empty (); + if (unlikely (blob == nullptr)) return hb_blob_get_empty (); FILE *fp = fopen (file_name, "rb"); if (unlikely (fp == nullptr)) goto fread_fail_without_close; @@ -611,7 +611,7 @@ fail_without_close: // can cover files like that but lets limit our fallback reader if (unlikely (allocated > 200000000)) goto fread_fail; char *new_blob = (char *) realloc (blob, allocated); - if (unlikely (!new_blob)) goto fread_fail; + if (unlikely (new_blob == nullptr)) goto fread_fail; blob = new_blob; } From 01dff1ea1aa871fa19a92c2afd63c8cb5dd6e455 Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Tue, 26 Jun 2018 18:00:58 -0400 Subject: [PATCH 011/106] Make round() fallback portable to systems that do have round() Makes compiling without HAVE_ROUND on systems that do have it work. --- src/hb-private.hh | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/hb-private.hh b/src/hb-private.hh index 32e335495..91162f93a 100644 --- a/src/hb-private.hh +++ b/src/hb-private.hh @@ -1228,13 +1228,14 @@ struct hb_bytes_t /* fallback for round() */ #if !defined (HAVE_ROUND) && !defined (HAVE_DECL_ROUND) static inline double -round (double x) +_hb_round (double x) { if (x >= 0) return floor (x + 0.5); else return ceil (x - 0.5); } +#define round(x) _hb_round(x) #endif From fa090ed4d47df12b2e611c9a667c398742f7e4ba Mon Sep 17 00:00:00 2001 From: Ebrahim Byagowi Date: Wed, 27 Jun 2018 14:13:26 +0430 Subject: [PATCH 012/106] Minor touches on hb_blob_create_from_file (#1079) * Handle EINTR on fallback reader * Increase fallback reader limitation size limitation to 2 << 28 * Ensure _O_BINARY does exist if MMAP is used on Windows (maybe superfluous but makes me more confident) --- src/hb-blob.cc | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/src/hb-blob.cc b/src/hb-blob.cc index 155c2e6b1..918a479cd 100644 --- a/src/hb-blob.cc +++ b/src/hb-blob.cc @@ -489,10 +489,10 @@ hb_blob_t::try_make_writable (void) #if defined(_WIN32) || defined(__CYGWIN__) # include -#endif - -#ifndef _O_BINARY -# define _O_BINARY 0 +#else +# ifndef _O_BINARY +# define _O_BINARY 0 +# endif #endif #ifndef MAP_NORESERVE @@ -594,8 +594,7 @@ fail_without_close: // The following tries to read a file without knowing its size beforehand // It's used for systems without mmap concept or to read from pipes - int len = 0; - int allocated = BUFSIZ * 16; + unsigned long len = 0, allocated = BUFSIZ * 16; char *blob = (char *) malloc (allocated); if (unlikely (blob == nullptr)) return hb_blob_get_empty (); @@ -607,16 +606,21 @@ fail_without_close: if (allocated - len < BUFSIZ) { allocated *= 2; - // Don't allocate more than 200MB, our mmap reader still + // Don't allocate and go more than ~536MB, our mmap reader still // can cover files like that but lets limit our fallback reader - if (unlikely (allocated > 200000000)) goto fread_fail; + if (unlikely (allocated > (2 << 28))) goto fread_fail; char *new_blob = (char *) realloc (blob, allocated); if (unlikely (new_blob == nullptr)) goto fread_fail; blob = new_blob; } - len += fread (blob + len, 1, allocated - len, fp); + unsigned long addition = fread (blob + len, 1, allocated - len, fp); + + int err = ferror (fp); + if (unlikely (err == EINTR)) continue; if (unlikely (ferror (fp))) goto fread_fail; + + len += addition; } return hb_blob_create (blob, len, HB_MEMORY_MODE_WRITABLE, blob, From 7b4099f35f766d33d483a4b9d0805ef16020ea23 Mon Sep 17 00:00:00 2001 From: Ebrahim Byagowi Date: Wed, 27 Jun 2018 16:54:44 +0430 Subject: [PATCH 013/106] Minor, rename blob to data on blob_from_file --- src/hb-blob.cc | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/src/hb-blob.cc b/src/hb-blob.cc index 918a479cd..d17627ff1 100644 --- a/src/hb-blob.cc +++ b/src/hb-blob.cc @@ -593,10 +593,10 @@ fail_without_close: #endif // The following tries to read a file without knowing its size beforehand - // It's used for systems without mmap concept or to read from pipes + // It's used as a fallback for systems without mmap or to read from pipes unsigned long len = 0, allocated = BUFSIZ * 16; - char *blob = (char *) malloc (allocated); - if (unlikely (blob == nullptr)) return hb_blob_get_empty (); + char *data = (char *) malloc (allocated); + if (unlikely (data == nullptr)) return hb_blob_get_empty (); FILE *fp = fopen (file_name, "rb"); if (unlikely (fp == nullptr)) goto fread_fail_without_close; @@ -609,12 +609,12 @@ fail_without_close: // Don't allocate and go more than ~536MB, our mmap reader still // can cover files like that but lets limit our fallback reader if (unlikely (allocated > (2 << 28))) goto fread_fail; - char *new_blob = (char *) realloc (blob, allocated); - if (unlikely (new_blob == nullptr)) goto fread_fail; - blob = new_blob; + char *new_data = (char *) realloc (data, allocated); + if (unlikely (new_data == nullptr)) goto fread_fail; + data = new_data; } - unsigned long addition = fread (blob + len, 1, allocated - len, fp); + unsigned long addition = fread (data + len, 1, allocated - len, fp); int err = ferror (fp); if (unlikely (err == EINTR)) continue; @@ -623,12 +623,12 @@ fail_without_close: len += addition; } - return hb_blob_create (blob, len, HB_MEMORY_MODE_WRITABLE, blob, + return hb_blob_create (data, len, HB_MEMORY_MODE_WRITABLE, data, (hb_destroy_func_t) free); fread_fail: fclose (fp); fread_fail_without_close: - free (blob); + free (data); return hb_blob_get_empty (); } From 71971800ed1c0501a58e6ff7730e3cebec2ef2f8 Mon Sep 17 00:00:00 2001 From: Ebrahim Byagowi Date: Wed, 27 Jun 2018 18:14:52 +0430 Subject: [PATCH 014/106] [ci] Don't fail on apt update and revive clang-O3-O0 --- .circleci/config.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index de130b506..012873e21 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -68,7 +68,8 @@ jobs: - image: multiarch/crossbuild steps: - checkout - - run: apt update && apt install -y ragel libfreetype6-dev libglib2.0-dev libcairo2-dev libicu-dev libgraphite2-dev python python-pip + - run: apt update || true + - run: apt install -y ragel libfreetype6-dev libglib2.0-dev libcairo2-dev libicu-dev libgraphite2-dev python python-pip - run: pip install fonttools - run: wget http://download.savannah.gnu.org/releases/freetype/freetype-2.9.tar.bz2 && tar xf freetype-2.9.tar.bz2 && cd freetype-2.9 && ./autogen.sh && ./configure && make -j4 && cd .. - run: CFLAGS="-O3" CXXFLAGS="-O3" CC=clang CXX=clang++ ./autogen.sh --with-freetype --with-glib --with-cairo --with-icu --with-graphite2 From 8a51f91b7035bbfaf39af1b962faf1613d2ea3b7 Mon Sep 17 00:00:00 2001 From: Ebrahim Byagowi Date: Thu, 28 Jun 2018 13:22:21 +0430 Subject: [PATCH 015/106] Minor on hb_blob_create_from_file, reuse ferror result Oops --- src/hb-blob.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/hb-blob.cc b/src/hb-blob.cc index d17627ff1..d29c6b2c7 100644 --- a/src/hb-blob.cc +++ b/src/hb-blob.cc @@ -618,7 +618,7 @@ fail_without_close: int err = ferror (fp); if (unlikely (err == EINTR)) continue; - if (unlikely (ferror (fp))) goto fread_fail; + if (unlikely (err)) goto fread_fail; len += addition; } From 25970a93aa6596d50ae538c6274625f95153572c Mon Sep 17 00:00:00 2001 From: Ebrahim Byagowi Date: Thu, 28 Jun 2018 14:32:36 +0430 Subject: [PATCH 016/106] armcc compatibility, don't use EINTR if doesn't exist Fixes #1081 --- src/hb-blob.cc | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/hb-blob.cc b/src/hb-blob.cc index d29c6b2c7..10db09785 100644 --- a/src/hb-blob.cc +++ b/src/hb-blob.cc @@ -617,7 +617,9 @@ fail_without_close: unsigned long addition = fread (data + len, 1, allocated - len, fp); int err = ferror (fp); +#ifdef EINTR // armcc doesn't have it if (unlikely (err == EINTR)) continue; +#endif if (unlikely (err)) goto fread_fail; len += addition; From 7b8dfac560abe89d48cfc2f6efb4a61820bd28bf Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Sat, 30 Jun 2018 09:16:54 +0430 Subject: [PATCH 017/106] [khmer] Fix infinite-loop in cluster merging Indic shaper already had this check. We removed it when forking Khmer shaper by mistake. Fixes https://bugzilla.mozilla.org/show_bug.cgi?id=1464623 --- src/hb-ot-shape-complex-khmer.cc | 31 +++++++++++++++++-------------- 1 file changed, 17 insertions(+), 14 deletions(-) diff --git a/src/hb-ot-shape-complex-khmer.cc b/src/hb-ot-shape-complex-khmer.cc index 18e3c941e..7876d3666 100644 --- a/src/hb-ot-shape-complex-khmer.cc +++ b/src/hb-ot-shape-complex-khmer.cc @@ -372,22 +372,25 @@ initial_reordering_consonant_syllable (const hb_ot_shape_plan_t *plan, break; } - /* Note! syllable() is a one-byte field. */ - for (unsigned int i = base; i < end; i++) - if (info[i].syllable() != 255) - { - unsigned int max = i; - unsigned int j = start + info[i].syllable(); - while (j != i) + if (unlikely (end - start >= 127)) + buffer->merge_clusters (start, end); + else + /* Note! syllable() is a one-byte field. */ + for (unsigned int i = base; i < end; i++) + if (info[i].syllable() != 255) { - max = MAX (max, j); - unsigned int next = start + info[j].syllable(); - info[j].syllable() = 255; /* So we don't process j later again. */ - j = next; + unsigned int max = i; + unsigned int j = start + info[i].syllable(); + while (j != i) + { + max = MAX (max, j); + unsigned int next = start + info[j].syllable(); + info[j].syllable() = 255; /* So we don't process j later again. */ + j = next; + } + if (i != max) + buffer->merge_clusters (i, max + 1); } - if (i != max) - buffer->merge_clusters (i, max + 1); - } /* Put syllable back in. */ for (unsigned int i = start; i < end; i++) From 9541c9dae10156fb61e4786545d1976cdcfb6bda Mon Sep 17 00:00:00 2001 From: punchcutter Date: Sun, 24 Jun 2018 22:54:57 -0700 Subject: [PATCH 018/106] Rebase and update USE overrides for Bhaiksuki Gap Fillers and Grantha Anusvara --- src/gen-use-table.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/gen-use-table.py b/src/gen-use-table.py index 6aa5f881c..e7c621cac 100755 --- a/src/gen-use-table.py +++ b/src/gen-use-table.py @@ -47,6 +47,9 @@ defaults = ('Other', 'Not_Applicable', 'Cn', 'No_Block') data[0][0x034F] = defaults[0] data[0][0x2060] = defaults[0] data[0][0x20F0] = defaults[0] +# TODO https://github.com/roozbehp/unicode-data/issues/9 +data[0][0x11C44] = 'Consonant_Placeholder' +data[0][0x11C45] = 'Consonant_Placeholder' for u in range (0xFE00, 0xFE0F + 1): data[0][u] = defaults[0] @@ -165,7 +168,7 @@ def is_BASE(U, UISC, UGC): def is_BASE_IND(U, UISC, UGC): #SPEC-DRAFT return (UISC in [Consonant_Dead, Modifying_Letter] or UGC == Po) return (UISC in [Consonant_Dead, Modifying_Letter] or - (UGC == Po and not U in [0x104B, 0x104E, 0x2022, 0x11A3F, 0x11A45]) or + (UGC == Po and not U in [0x104B, 0x104E, 0x2022, 0x11A3F, 0x11A45, 0x11C44, 0x11C45]) or False # SPEC-DRAFT-OUTDATED! U == 0x002D ) def is_BASE_NUM(U, UISC, UGC): @@ -344,6 +347,9 @@ def map_to_use(data): if 0xA926 <= U <= 0xA92A: UIPC = Top if U == 0x111CA: UIPC = Bottom if U == 0x11300: UIPC = Top + # TODO: https://github.com/harfbuzz/harfbuzz/pull/1037 + if U == 0x11302: UIPC = Top + if U == 0x1133C: UIPC = Bottom if U == 0x1171E: UIPC = Left # Correct?! if 0x1CF2 <= U <= 0x1CF3: UIPC = Right if 0x1CF8 <= U <= 0x1CF9: UIPC = Top From 8b9cbe3b24be2ae0166e682103e22ec916316ecf Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Sat, 30 Jun 2018 12:28:03 +0430 Subject: [PATCH 019/106] [indic] Tweak for old-spec Bengali and halant-ya-halant Fixes https://github.com/harfbuzz/harfbuzz/issues/1073 --- src/hb-ot-shape-complex-indic.cc | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/src/hb-ot-shape-complex-indic.cc b/src/hb-ot-shape-complex-indic.cc index 447e36cc4..8377dae97 100644 --- a/src/hb-ot-shape-complex-indic.cc +++ b/src/hb-ot-shape-complex-indic.cc @@ -668,8 +668,9 @@ initial_reordering_consonant_syllable (const hb_ot_shape_plan_t *plan, * * Reports suggest that in some scripts Uniscribe does this only if there * is *not* a Halant after last consonant already (eg. Kannada), while it - * does it unconditionally in other scripts (eg. Malayalam). We don't - * currently know about other scripts, so we single out Malayalam for now. + * does it unconditionally in other scripts (eg. Malayalam, Bengali). We + * don't currently know about other scripts, so we whitelist Malayalam and + * Bengali for now. * * Kannada test case: * U+0C9A,U+0CCD,U+0C9A,U+0CCD @@ -679,10 +680,16 @@ initial_reordering_consonant_syllable (const hb_ot_shape_plan_t *plan, * Malayalam test case: * U+0D38,U+0D4D,U+0D31,U+0D4D,U+0D31,U+0D4D * With lohit-ttf-20121122/Lohit-Malayalam.ttf + * + * Bengali test case + * U+0998,U+09CD,U+09AF,U+09CD + * With Windows XP vrinda.ttf + * https://github.com/harfbuzz/harfbuzz/issues/1073 */ if (indic_plan->is_old_spec) { - bool disallow_double_halants = buffer->props.script != HB_SCRIPT_MALAYALAM; + bool disallow_double_halants = buffer->props.script != HB_SCRIPT_MALAYALAM && + buffer->props.script != HB_SCRIPT_BENGALI; for (unsigned int i = base + 1; i < end; i++) if (info[i].indic_category() == OT_H) { From d3c0980ac234698627cb281e5526cc99139eed30 Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Sat, 30 Jun 2018 15:59:25 +0430 Subject: [PATCH 020/106] Adjust MarkBasePos heuristic in presence of MultipleSubst From the issue: "In this font, the virama,ya first forms a ligature, then decomposes back to virama,ya. This causes those two to be marked parts of a MultipleSubst sequence. When attaching the matra, we look for the first of the MultipleSubst sequence because that's where we attach to (because of eg #740). In this case, the first glyph in the MultipleSubst sequence is a mark, so we skip it and attach to the base char before it." Font in question is Nirmala UI from Windows 10. Test sequence: U+0926,U+094D,U+092F,U+0941 Fixes https://github.com/harfbuzz/harfbuzz/issues/1020 --- src/hb-ot-layout-gpos-table.hh | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/hb-ot-layout-gpos-table.hh b/src/hb-ot-layout-gpos-table.hh index bc8a5fd6b..182c8d909 100644 --- a/src/hb-ot-layout-gpos-table.hh +++ b/src/hb-ot-layout-gpos-table.hh @@ -1074,10 +1074,13 @@ struct MarkBasePosFormat1 if (!skippy_iter.prev ()) return_trace (false); /* We only want to attach to the first of a MultipleSubst sequence. * https://github.com/harfbuzz/harfbuzz/issues/740 - * Reject others. */ + * Reject others... + * ...but stop if we find a mark in the MultipleSubst sequence: + * https://github.com/harfbuzz/harfbuzz/issues/1020 */ if (!_hb_glyph_info_multiplied (&buffer->info[skippy_iter.idx]) || 0 == _hb_glyph_info_get_lig_comp (&buffer->info[skippy_iter.idx]) || (skippy_iter.idx == 0 || + _hb_glyph_info_is_mark (&buffer->info[skippy_iter.idx - 1]) || _hb_glyph_info_get_lig_id (&buffer->info[skippy_iter.idx]) != _hb_glyph_info_get_lig_id (&buffer->info[skippy_iter.idx - 1]) || _hb_glyph_info_get_lig_comp (&buffer->info[skippy_iter.idx]) != From 5d8cafcf6a47ce73afff06499f6be23c72ab6797 Mon Sep 17 00:00:00 2001 From: Ebrahim Byagowi Date: Sun, 1 Jul 2018 01:54:14 +0430 Subject: [PATCH 021/106] Improve nommap naming and use C style comments on create_from_file (#1084) --- .circleci/config.yml | 2 +- src/hb-blob.cc | 16 ++++++++-------- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 012873e21..5ad1ae135 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -47,7 +47,7 @@ jobs: - checkout - run: apk update && apk add ragel make pkgconfig libtool autoconf automake gettext gcc g++ glib-dev freetype-dev cairo-dev # C??FLAGS are not needed for a regular build - - run: CFLAGS="-O3" CXXFLAGS="-O3 -DNOMMAPFILEREADER" ./autogen.sh + - run: CFLAGS="-O3" CXXFLAGS="-O3 -DHB_NO_MMAP" ./autogen.sh - run: make - run: make check || .ci/fail.sh diff --git a/src/hb-blob.cc b/src/hb-blob.cc index 10db09785..98e9c65c2 100644 --- a/src/hb-blob.cc +++ b/src/hb-blob.cc @@ -534,9 +534,9 @@ _hb_mapped_file_destroy (hb_mapped_file_t *file) hb_blob_t * hb_blob_create_from_file (const char *file_name) { - // Adopted from glib's gmappedfile.c with Matthias Clasen and - // Allison Lortie permission but changed a lot to suit our need. -#if defined(HAVE_MMAP) && !defined(NOMMAPFILEREADER) + /* Adopted from glib's gmappedfile.c with Matthias Clasen and + Allison Lortie permission but changed a lot to suit our need. */ +#if defined(HAVE_MMAP) && !defined(HB_NO_MMAP) hb_mapped_file_t *file = (hb_mapped_file_t *) calloc (1, sizeof (hb_mapped_file_t)); if (unlikely (!file)) return hb_blob_get_empty (); @@ -563,7 +563,7 @@ fail: fail_without_close: free (file); -#elif (defined(_WIN32) || defined(__CYGWIN__)) && !defined(NOMMAPFILEREADER) +#elif (defined(_WIN32) || defined(__CYGWIN__)) && !defined(HB_NO_MMAP) hb_mapped_file_t *file = (hb_mapped_file_t *) calloc (1, sizeof (hb_mapped_file_t)); if (unlikely (!file)) return hb_blob_get_empty (); @@ -592,8 +592,8 @@ fail_without_close: #endif - // The following tries to read a file without knowing its size beforehand - // It's used as a fallback for systems without mmap or to read from pipes + /* The following tries to read a file without knowing its size beforehand + It's used as a fallback for systems without mmap or to read from pipes */ unsigned long len = 0, allocated = BUFSIZ * 16; char *data = (char *) malloc (allocated); if (unlikely (data == nullptr)) return hb_blob_get_empty (); @@ -606,8 +606,8 @@ fail_without_close: if (allocated - len < BUFSIZ) { allocated *= 2; - // Don't allocate and go more than ~536MB, our mmap reader still - // can cover files like that but lets limit our fallback reader + /* Don't allocate and go more than ~536MB, our mmap reader still + can cover files like that but lets limit our fallback reader */ if (unlikely (allocated > (2 << 28))) goto fread_fail; char *new_data = (char *) realloc (data, allocated); if (unlikely (new_data == nullptr)) goto fread_fail; From 225b92b7d4437360f8779850ee0aae85966679b5 Mon Sep 17 00:00:00 2001 From: Ebrahim Byagowi Date: Sun, 1 Jul 2018 14:32:00 +0430 Subject: [PATCH 022/106] Support dfont font files (#949) --- src/hb-open-file-private.hh | 196 ++++++++++++++++++++++++++++++++++++ src/hb-open-type-private.hh | 1 + src/main.cc | 3 + 3 files changed, 200 insertions(+) diff --git a/src/hb-open-file-private.hh b/src/hb-open-file-private.hh index 2965b4626..f69d5f46d 100644 --- a/src/hb-open-file-private.hh +++ b/src/hb-open-file-private.hh @@ -286,6 +286,197 @@ struct TTCHeader } u; }; +/* + * Mac Resource Fork + */ + +struct ResourceRefItem +{ + inline bool sanitize (hb_sanitize_context_t *c) const + { + TRACE_SANITIZE (this); + // actual data sanitization is done on ResourceForkHeader sanitizer + return_trace (likely (c->check_struct (this))); + } + + HBINT16 id; /* Resource ID, is really should be signed? */ + HBINT16 nameOffset; /* Offset from beginning of resource name list + * to resource name, minus means there is no */ + HBUINT8 attr; /* Resource attributes */ + HBUINT24 dataOffset; /* Offset from beginning of resource data to + * data for this resource */ + HBUINT32 reserved; /* Reserved for handle to resource */ + public: + DEFINE_SIZE_STATIC (12); +}; + +struct ResourceTypeItem +{ + inline bool sanitize (hb_sanitize_context_t *c) const + { + TRACE_SANITIZE (this); + // RefList sanitization is done on ResourceMap sanitizer + return_trace (likely (c->check_struct (this))); + } + + inline unsigned int get_resource_count () const + { + return numRes + 1; + } + + inline bool is_sfnt () const + { + return type == HB_TAG ('s','f','n','t'); + } + + inline const ResourceRefItem& get_ref_item (const void *base, + unsigned int i) const + { + return (base+refList)[i]; + } + + protected: + Tag type; /* Resource type */ + HBUINT16 numRes; /* Number of resource this type in map minus 1 */ + OffsetTo > + refList; /* Offset from beginning of resource type list + * to reference list for this type */ + public: + DEFINE_SIZE_STATIC (8); +}; + +struct ResourceMap +{ + inline bool sanitize (hb_sanitize_context_t *c) const + { + TRACE_SANITIZE (this); + if (unlikely (!c->check_struct (this))) + return_trace (false); + for (unsigned int i = 0; i < get_types_count (); ++i) + { + const ResourceTypeItem& type = get_type (i); + if (unlikely (!type.sanitize (c))) + return_trace (false); + for (unsigned int j = 0; j < type.get_resource_count (); ++j) + if (unlikely (!get_ref_item (type, j).sanitize (c))) + return_trace (false); + } + return_trace (true); + } + + inline const ResourceTypeItem& get_type (unsigned int i) const + { + // Why offset from the second byte of the object? I'm not sure + return ((&reserved[2])+typeList)[i]; + } + + inline unsigned int get_types_count () const + { + return nTypes + 1; + } + + inline const ResourceRefItem &get_ref_item (const ResourceTypeItem &type, + unsigned int i) const + { + return type.get_ref_item (&(this+typeList), i); + } + + inline const PString& get_name (const ResourceRefItem &item, + unsigned int i) const + { + if (item.nameOffset == -1) + return Null (PString); + + return StructAtOffset (this, nameList + item.nameOffset); + } + + protected: + HBUINT8 reserved[16]; /* Reserved for copy of resource header */ + LOffsetTo + reserved1; /* Reserved for handle to next resource map */ + HBUINT16 reserved2; /* Reserved for file reference number */ + HBUINT16 attr; /* Resource fork attribute */ + OffsetTo > + typeList; /* Offset from beginning of map to + * resource type list */ + HBUINT16 nameList; /* Offset from beginning of map to + * resource name list */ + HBUINT16 nTypes; /* Number of types in the map minus 1 */ + public: + DEFINE_SIZE_STATIC (30); +}; + +struct ResourceForkHeader +{ + inline unsigned int get_face_count () const + { + const ResourceMap &resource_map = this+map; + for (unsigned int i = 0; i < resource_map.get_types_count (); ++i) + { + const ResourceTypeItem& type = resource_map.get_type (i); + if (type.is_sfnt ()) + return type.get_resource_count (); + } + return 0; + } + + inline const LArrayOf& get_data (const ResourceTypeItem& type, + unsigned int idx) const + { + const ResourceMap &resource_map = this+map; + unsigned int offset = dataOffset; + offset += resource_map.get_ref_item (type, idx).dataOffset; + return StructAtOffset > (this, offset); + } + + inline const OpenTypeFontFace& get_face (unsigned int idx) const + { + const ResourceMap &resource_map = this+map; + for (unsigned int i = 0; i < resource_map.get_types_count (); ++i) + { + const ResourceTypeItem& type = resource_map.get_type (i); + if (type.is_sfnt () && idx < type.get_resource_count ()) + return (OpenTypeFontFace&) get_data (type, idx).arrayZ; + } + return Null (OpenTypeFontFace); + } + + inline bool sanitize (hb_sanitize_context_t *c) const + { + TRACE_SANITIZE (this); + if (unlikely (!c->check_struct (this))) + return_trace (false); + + const ResourceMap &resource_map = this+map; + if (unlikely (!resource_map.sanitize (c))) + return_trace (false); + + for (unsigned int i = 0; i < resource_map.get_types_count (); ++i) + { + const ResourceTypeItem& type = resource_map.get_type (i); + for (unsigned int j = 0; j < type.get_resource_count (); ++j) + { + const LArrayOf& data = get_data (type, j); + if (unlikely (!(data.sanitize (c) && + ((OpenTypeFontFace&) data.arrayZ).sanitize (c)))) + return_trace (false); + } + } + + return_trace (true); + } + + protected: + HBUINT32 dataOffset; /* Offset from beginning of resource fork + * to resource data */ + LOffsetTo + map; /* Offset from beginning of resource fork + * to resource map */ + HBUINT32 dataLen; /* Length of resource data */ + HBUINT32 mapLen; /* Length of resource map */ + public: + DEFINE_SIZE_STATIC (16); +}; /* * OpenType Font File @@ -299,6 +490,7 @@ struct OpenTypeFontFile CFFTag = HB_TAG ('O','T','T','O'), /* OpenType with Postscript outlines */ TrueTypeTag = HB_TAG ( 0 , 1 , 0 , 0 ), /* OpenType with TrueType outlines */ TTCTag = HB_TAG ('t','t','c','f'), /* TrueType Collection */ + DFontTag = HB_TAG ( 0 , 0 , 1 , 0 ), /* DFont Mac Resource Fork */ TrueTag = HB_TAG ('t','r','u','e'), /* Obsolete Apple TrueType */ Typ1Tag = HB_TAG ('t','y','p','1') /* Obsolete Apple Type1 font in SFNT container */ }; @@ -313,6 +505,7 @@ struct OpenTypeFontFile case Typ1Tag: case TrueTypeTag: return 1; case TTCTag: return u.ttcHeader.get_face_count (); + case DFontTag: return u.rfHeader.get_face_count (); default: return 0; } } @@ -327,6 +520,7 @@ struct OpenTypeFontFile case Typ1Tag: case TrueTypeTag: return u.fontFace; case TTCTag: return u.ttcHeader.get_face (i); + case DFontTag: return u.rfHeader.get_face (i); default: return Null(OpenTypeFontFace); } } @@ -353,6 +547,7 @@ struct OpenTypeFontFile case Typ1Tag: case TrueTypeTag: return_trace (u.fontFace.sanitize (c)); case TTCTag: return_trace (u.ttcHeader.sanitize (c)); + case DFontTag: return_trace (u.rfHeader.sanitize (c)); default: return_trace (true); } } @@ -362,6 +557,7 @@ struct OpenTypeFontFile Tag tag; /* 4-byte identifier. */ OpenTypeFontFace fontFace; TTCHeader ttcHeader; + ResourceForkHeader rfHeader; } u; public: DEFINE_SIZE_UNION (4, tag); diff --git a/src/hb-open-type-private.hh b/src/hb-open-type-private.hh index 8180287d4..9a4835b89 100644 --- a/src/hb-open-type-private.hh +++ b/src/hb-open-type-private.hh @@ -1033,6 +1033,7 @@ struct ArrayOf DEFINE_SIZE_ARRAY (sizeof (LenType), arrayZ); }; template struct LArrayOf : ArrayOf {}; +typedef ArrayOf PString; /* Array of Offset's */ template diff --git a/src/main.cc b/src/main.cc index ca0fcc5b6..873d240a3 100644 --- a/src/main.cc +++ b/src/main.cc @@ -78,6 +78,9 @@ main (int argc, char **argv) case OpenTypeFontFile::Typ1Tag: printf ("Obsolete Apple Type1 font in SFNT container\n"); break; + case OpenTypeFontFile::DFontTag: + printf ("DFont Mac Resource Fork\n"); + break; default: printf ("Unknown font format\n"); break; From 32348a43c154eac6bfb21b9e8044b38ed763601e Mon Sep 17 00:00:00 2001 From: Ebrahim Byagowi Date: Sun, 1 Jul 2018 15:32:43 +0430 Subject: [PATCH 023/106] Fix trak table apply logic In collaboration with Behdad --- src/hb-aat-layout-trak-table.hh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/hb-aat-layout-trak-table.hh b/src/hb-aat-layout-trak-table.hh index 0617e23d5..f5dc558c3 100644 --- a/src/hb-aat-layout-trak-table.hh +++ b/src/hb-aat-layout-trak-table.hh @@ -172,7 +172,7 @@ struct trak hb_position_t advance_to_add = c->font->em_scalef_x (tracking / 2); foreach_grapheme (buffer, start, end) { - /* TODO This is wrong. */ + buffer->pos[start].x_offset += advance_to_add; buffer->pos[start].x_advance += advance_to_add; buffer->pos[end].x_advance += advance_to_add; } @@ -184,7 +184,7 @@ struct trak hb_position_t advance_to_add = c->font->em_scalef_y (tracking / 2); foreach_grapheme (buffer, start, end) { - /* TODO This is wrong. */ + buffer->pos[start].y_offset += advance_to_add; buffer->pos[start].y_advance += advance_to_add; buffer->pos[end].y_advance += advance_to_add; } From 29e7879bcf3fe955a0be3bb41e929e68f39ad01e Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Tue, 3 Jul 2018 12:38:21 +0430 Subject: [PATCH 024/106] Disable .dfont code for now The get_table imple was wrong, as table offsets in a dfont are relative to the resource. We were treating them as relative to the big blob itself. To be fixed. Part of https://github.com/harfbuzz/harfbuzz/pull/1085 --- src/hb-open-file-private.hh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/hb-open-file-private.hh b/src/hb-open-file-private.hh index f69d5f46d..226c48f6a 100644 --- a/src/hb-open-file-private.hh +++ b/src/hb-open-file-private.hh @@ -505,7 +505,7 @@ struct OpenTypeFontFile case Typ1Tag: case TrueTypeTag: return 1; case TTCTag: return u.ttcHeader.get_face_count (); - case DFontTag: return u.rfHeader.get_face_count (); +// case DFontTag: return u.rfHeader.get_face_count (); default: return 0; } } @@ -520,7 +520,7 @@ struct OpenTypeFontFile case Typ1Tag: case TrueTypeTag: return u.fontFace; case TTCTag: return u.ttcHeader.get_face (i); - case DFontTag: return u.rfHeader.get_face (i); +// case DFontTag: return u.rfHeader.get_face (i); default: return Null(OpenTypeFontFace); } } @@ -547,7 +547,7 @@ struct OpenTypeFontFile case Typ1Tag: case TrueTypeTag: return_trace (u.fontFace.sanitize (c)); case TTCTag: return_trace (u.ttcHeader.sanitize (c)); - case DFontTag: return_trace (u.rfHeader.sanitize (c)); +// case DFontTag: return_trace (u.rfHeader.sanitize (c)); default: return_trace (true); } } From 343e8c694b03eea625523229a9468fbb456e3aea Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Tue, 3 Jul 2018 12:43:59 +0430 Subject: [PATCH 025/106] 1.8.2 --- NEWS | 8 ++++++++ configure.ac | 2 +- src/hb-version.h | 4 ++-- 3 files changed, 11 insertions(+), 3 deletions(-) diff --git a/NEWS b/NEWS index 12010bdd9..c4fad25a9 100644 --- a/NEWS +++ b/NEWS @@ -1,3 +1,10 @@ +Overview of changes leading to 1.8.2 +Tuesday, July 3, 2018 +==================================== +- Fix infinite loop in Khmer shaper. +- Improve hb_blob_create_from_file() for streams. + + Overview of changes leading to 1.8.1 Tuesday, June 12, 2018 ==================================== @@ -5,6 +12,7 @@ Tuesday, June 12, 2018 - Add correctness bug in hb_set_t operations, introduced in 1.7.7. - Remove HB_SUBSET_BUILTIN build option. Not necessary. + Overview of changes leading to 1.8.0 Tuesday, June 5, 2018 ==================================== diff --git a/configure.ac b/configure.ac index 13cd1ce0d..d6c23e53c 100644 --- a/configure.ac +++ b/configure.ac @@ -1,6 +1,6 @@ AC_PREREQ([2.64]) AC_INIT([HarfBuzz], - [1.8.1], + [1.8.2], [https://github.com/harfbuzz/harfbuzz/issues/new], [harfbuzz], [http://harfbuzz.org/]) diff --git a/src/hb-version.h b/src/hb-version.h index 2180d8490..7f2e9dd72 100644 --- a/src/hb-version.h +++ b/src/hb-version.h @@ -38,9 +38,9 @@ HB_BEGIN_DECLS #define HB_VERSION_MAJOR 1 #define HB_VERSION_MINOR 8 -#define HB_VERSION_MICRO 1 +#define HB_VERSION_MICRO 2 -#define HB_VERSION_STRING "1.8.1" +#define HB_VERSION_STRING "1.8.2" #define HB_VERSION_ATLEAST(major,minor,micro) \ ((major)*10000+(minor)*100+(micro) <= \ From 2cb075fe26201f3e370fccfff6c1bc242b5acc79 Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Tue, 3 Jul 2018 13:04:05 +0430 Subject: [PATCH 026/106] Fix unused function '_hb_mapped_file_destroy' if no mmap --- src/hb-blob.cc | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/hb-blob.cc b/src/hb-blob.cc index 98e9c65c2..61ed79a76 100644 --- a/src/hb-blob.cc +++ b/src/hb-blob.cc @@ -508,6 +508,7 @@ struct hb_mapped_file_t #endif }; +#if (defined(HAVE_MMAP) || defined(_WIN32) || defined(__CYGWIN__)) && !defined(HB_NO_MMAP) static void _hb_mapped_file_destroy (hb_mapped_file_t *file) { @@ -522,6 +523,7 @@ _hb_mapped_file_destroy (hb_mapped_file_t *file) free (file); } +#endif /** * hb_blob_create_from_file: From 9940504e933d6766f87dca7fccc3c2f889976a22 Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Tue, 3 Jul 2018 14:29:25 +0430 Subject: [PATCH 027/106] [indic] Adjust left-matra repositioning and Halant,ZWJ sequence MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit From the new code (first paragraph is from the OT Devanagari spec.): /* o Reorder matras: * * If a pre-base matra character had been reordered before applying basic * features, the glyph can be moved closer to the main consonant based on * whether half-forms had been formed. Actual position for the matra is * defined as “after last standalone halant glyph, after initial matra * position and before the main consonant”. If ZWJ or ZWNJ follow this * halant, position is moved after it. * * IMPLEMENTATION NOTES: * * It looks like the last sentence is wrong. Testing, with Windows 7 Uniscribe * and Devanagari shows that the behavior is best described as: * * "If ZWJ follows this halant, matra is NOT repositioned after this halant. * If ZWNJ follows this halant, position is moved after it." * * Test case, with Adobe Devanagari or Nirmala UI: * * U+091F,U+094D,U+200C,U+092F,U+093F * (Matra moves to the middle, after ZWNJ.) * * U+091F,U+094D,U+200D,U+092F,U+093F * (Matra does NOT move, stays to the left.) Fixes https://github.com/harfbuzz/harfbuzz/issues/1070 Test case added with Adobe Devanagari. --- src/hb-ot-shape-complex-indic.cc | 37 ++++++++++++++++++ ...16e5d8fedfbec74e45dc350d2416d810bed8c4.ttf | Bin 0 -> 4364 bytes .../data/in-house/tests/indic-joiners.tests | 4 ++ 3 files changed, 41 insertions(+) create mode 100644 test/shaping/data/in-house/fonts/8116e5d8fedfbec74e45dc350d2416d810bed8c4.ttf diff --git a/src/hb-ot-shape-complex-indic.cc b/src/hb-ot-shape-complex-indic.cc index 8377dae97..b8d9a3acf 100644 --- a/src/hb-ot-shape-complex-indic.cc +++ b/src/hb-ot-shape-complex-indic.cc @@ -1127,6 +1127,24 @@ final_reordering_syllable (const hb_ot_shape_plan_t *plan, * defined as “after last standalone halant glyph, after initial matra * position and before the main consonant”. If ZWJ or ZWNJ follow this * halant, position is moved after it. + * + * IMPLEMENTATION NOTES: + * + * It looks like the last sentence is wrong. Testing, with Windows 7 Uniscribe + * and Devanagari shows that the behavior is best described as: + * + * "If ZWJ follows this halant, matra is NOT repositioned after this halant. + * If ZWNJ follows this halant, position is moved after it." + * + * Test case, with Adobe Devanagari or Nirmala UI: + * + * U+091F,U+094D,U+200C,U+092F,U+093F + * (Matra moves to the middle, after ZWNJ.) + * + * U+091F,U+094D,U+200D,U+092F,U+093F + * (Matra does NOT move, stays to the left.) + * + * https://github.com/harfbuzz/harfbuzz/issues/1070 */ if (start + 1 < end && start < base) /* Otherwise there can't be any pre-base matra characters. */ @@ -1140,6 +1158,7 @@ final_reordering_syllable (const hb_ot_shape_plan_t *plan, */ if (buffer->props.script != HB_SCRIPT_MALAYALAM && buffer->props.script != HB_SCRIPT_TAMIL) { + search: while (new_pos > start && !(is_one_of (info[new_pos], (FLAG (OT_M) | FLAG (OT_H))))) new_pos--; @@ -1150,9 +1169,27 @@ final_reordering_syllable (const hb_ot_shape_plan_t *plan, if (is_halant (info[new_pos]) && info[new_pos].indic_position() != POS_PRE_M) { +#if 0 // See comment above /* -> If ZWJ or ZWNJ follow this halant, position is moved after it. */ if (new_pos + 1 < end && is_joiner (info[new_pos + 1])) new_pos++; +#endif + if (new_pos + 1 < end) + { + /* -> If ZWJ follows this halant, matra is NOT repositioned after this halant. */ + if (info[new_pos + 1].indic_category() == OT_ZWJ) + { + /* Keep searching. */ + if (new_pos > start) + { + new_pos--; + goto search; + } + } + /* -> If ZWNJ follows this halant, position is moved after it. */ + if (info[new_pos + 1].indic_category() == OT_ZWNJ) + new_pos++; + } } else new_pos = start; /* No move. */ diff --git a/test/shaping/data/in-house/fonts/8116e5d8fedfbec74e45dc350d2416d810bed8c4.ttf b/test/shaping/data/in-house/fonts/8116e5d8fedfbec74e45dc350d2416d810bed8c4.ttf new file mode 100644 index 0000000000000000000000000000000000000000..e8512bb29e14215e702082959b9a81179fe08d47 GIT binary patch literal 4364 zcmaJE3sh8P`nz}L-hq2zP?s@f_-8Hyf)7AuK*YD`IHF(>n39qJYX2n4;TMUjj1V~EzA{`3;z3>>T@PJJvwlOL2eXe z=jZ0=f?QAb#0fW0rz>v&&npPydG3g%oJo0ZZZQlaCZlA;QIw2GT{mwIlY`75>dMKP z9R_Y^wlimfUQBJEnp%B}=G9sQ-dbOyH*l}!U!jG!RJ6CW`Wjobc}+F`K(jyKZS~b= z&-ORB2kKYWwQ6WLCzG!(ea+{q)A|2&wZeu5t(+^jXyv{ZU!V;Q{wkcv;oi!J9DX=) za2q6Jhm=7TtbkS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00001 diff --git a/test/shaping/data/in-house/tests/indic-joiners.tests b/test/shaping/data/in-house/tests/indic-joiners.tests index 57107d587..dca83f87d 100644 --- a/test/shaping/data/in-house/tests/indic-joiners.tests +++ b/test/shaping/data/in-house/tests/indic-joiners.tests @@ -1,2 +1,6 @@ ../fonts/f443753e8ffe8e8aae606cfba158e00334b6efb1.ttf::U+179A,U+1784,U+17D2,U+179F,U+200C,U+17CA,U+17B8,U+0020:[uni179a=0+775|uni1784=1+1550|uni179f.sub=1+775|space=1+0|uni17ca=1+0|uni17b8=1@0,300+0|space=7+600] ../fonts/f443753e8ffe8e8aae606cfba158e00334b6efb1.ttf::U+179A,U+1784,U+17D2,U+179F,U+17CA,U+17B8:[uni179a=0+775|uni1784=1+1550|uni179f.sub=1+775|uni17bb=1@-75,-700+0|uni17b8=1+0] +../fonts/8116e5d8fedfbec74e45dc350d2416d810bed8c4.ttf:--font-funcs=ft:U+091F,U+094D,U+200C,U+092F,U+093F:[uni091F=0+876|uni094D=0@4,0+0|space=0+0|uni093F.750=3+397|uni092F=3+924] +../fonts/8116e5d8fedfbec74e45dc350d2416d810bed8c4.ttf:--font-funcs=ft:U+091F,U+094D,U+200D,U+092F,U+093F:[uni093F=0+398|uni091F=0+876|uni094D=0@4,0+0|space=0+0|uni092F=0+924] +../fonts/8116e5d8fedfbec74e45dc350d2416d810bed8c4.ttf:--font-funcs=ft:U+091F,U+094D,U+200D,U+091F,U+094D,U+200C,U+091F,U+094D,U+200D,U+092F,U+093F:[uni091F=0+876|uni094D=0@4,0+0|space=0+0|uni091F=3+876|uni094D=3@4,0+0|space=3+0|uni093F=6+398|uni091F=6+876|uni094D=6@4,0+0|space=6+0|uni092F=6+924] +../fonts/8116e5d8fedfbec74e45dc350d2416d810bed8c4.ttf:--font-funcs=ft:U+091F,U+094D,U+200D,U+091F,U+094D,U+200D,U+091F,U+094D,U+200D,U+092F,U+093F:[uni093F=0+398|uni091F=0+876|uni094D=0@4,0+0|space=0+0|uni091F=0+876|uni094D=0@4,0+0|space=0+0|uni091F=0+876|uni094D=0@4,0+0|space=0+0|uni092F=0+924] From d8a7dedc83042c5a643195172830acf78f2e59ff Mon Sep 17 00:00:00 2001 From: Ebrahim Byagowi Date: Wed, 4 Jul 2018 15:33:39 +0430 Subject: [PATCH 028/106] Use CreateFileW explicitly and pass wchar_t to it (#1087) --- src/hb-blob.cc | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/hb-blob.cc b/src/hb-blob.cc index 61ed79a76..b509093e0 100644 --- a/src/hb-blob.cc +++ b/src/hb-blob.cc @@ -569,9 +569,15 @@ fail_without_close: hb_mapped_file_t *file = (hb_mapped_file_t *) calloc (1, sizeof (hb_mapped_file_t)); if (unlikely (!file)) return hb_blob_get_empty (); - HANDLE fd = CreateFile (file_name, GENERIC_READ, FILE_SHARE_READ, nullptr, - OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL|FILE_FLAG_OVERLAPPED, - nullptr); + HANDLE fd; + unsigned int size = strlen (file_name) + 1; + wchar_t * wchar_file_name = (wchar_t *) malloc (sizeof (wchar_t) * size); + if (unlikely (wchar_file_name == nullptr)) goto fail_without_close; + mbstowcs (wchar_file_name, file_name, size); + fd = CreateFileW (wchar_file_name, GENERIC_READ, FILE_SHARE_READ, nullptr, + OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL|FILE_FLAG_OVERLAPPED, + nullptr); + free (wchar_file_name); if (unlikely (fd == INVALID_HANDLE_VALUE)) goto fail_without_close; From 058708a665cdd9e796581dbcf60a5778d3f5e240 Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Thu, 5 Jul 2018 13:16:00 +0430 Subject: [PATCH 029/106] Allow disabling vector_size use --- src/hb-private.hh | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/hb-private.hh b/src/hb-private.hh index 91162f93a..41e6c200c 100644 --- a/src/hb-private.hh +++ b/src/hb-private.hh @@ -1108,10 +1108,12 @@ struct HbOpXor /* Compiler-assisted vectorization. */ /* The `vector_size' attribute was introduced in gcc 3.1. */ -#if defined( __GNUC__ ) && ( __GNUC__ >= 4 ) -#define HB_VECTOR_SIZE 128 -#elif !defined(HB_VECTOR_SIZE) -#define HB_VECTOR_SIZE 0 +#if !defined(HB_VECTOR_SIZE) +# if defined( __GNUC__ ) && ( __GNUC__ >= 4 ) +# define HB_VECTOR_SIZE 128 +# else +# define HB_VECTOR_SIZE 0 +# endif #endif /* Type behaving similar to vectorized vars defined using __attribute__((vector_size(...))). */ From 18a06f8a662ca7a9e63f74c6443e24a035c40655 Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Thu, 5 Jul 2018 14:03:48 +0430 Subject: [PATCH 030/106] Fix warning ../../src/hb-ot-layout-gsubgpos-private.hh:391:18: warning: missed loop optimization, the loop counter may overflow [-Wunsafe-loop-optimizations] --- src/hb-ot-layout-gsubgpos-private.hh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/hb-ot-layout-gsubgpos-private.hh b/src/hb-ot-layout-gsubgpos-private.hh index 661085d51..cbaa64880 100644 --- a/src/hb-ot-layout-gsubgpos-private.hh +++ b/src/hb-ot-layout-gsubgpos-private.hh @@ -388,7 +388,7 @@ struct hb_ot_apply_context_t : inline bool prev (void) { assert (num_items > 0); - while (idx >= num_items) + while (idx > num_items - 1) { idx--; const hb_glyph_info_t &info = c->buffer->out_info[idx]; From 1ebaa090d80bf0b59308d2c70f5e58dd8da47450 Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Thu, 5 Jul 2018 14:04:13 +0430 Subject: [PATCH 031/106] Disable vectorization Disable vectorization for now. To correctly use them, we should use posix_memalign() to allocate them. Otherwise, can cause misaligned access. https://bugs.chromium.org/p/chromium/issues/detail?id=860184 --- src/hb-private.hh | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/hb-private.hh b/src/hb-private.hh index 41e6c200c..5cec8e0b4 100644 --- a/src/hb-private.hh +++ b/src/hb-private.hh @@ -1107,6 +1107,18 @@ struct HbOpXor /* Compiler-assisted vectorization. */ +/* + * Disable vectorization for now. To correctly use them, we should + * use posix_memalign() to allocate them. Otherwise, can cause + * misaligned access. + * + * https://bugs.chromium.org/p/chromium/issues/detail?id=860184 + */ +#if !defined(HB_VECTOR_SIZE) +# define HB_VECTOR_SIZE 0 +#endif + + /* The `vector_size' attribute was introduced in gcc 3.1. */ #if !defined(HB_VECTOR_SIZE) # if defined( __GNUC__ ) && ( __GNUC__ >= 4 ) From 936dadc6610666aa5781e8662b859f18f9baa636 Mon Sep 17 00:00:00 2001 From: David Corbett Date: Sat, 7 Jul 2018 11:08:17 -0400 Subject: [PATCH 032/106] Regenerate the USE table for Grantha and Bhaiksuki (#1090) Completes #1037 and fixes #1035. --- src/hb-ot-shape-complex-use-table.cc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/hb-ot-shape-complex-use-table.cc b/src/hb-ot-shape-complex-use-table.cc index 14315338c..25f7bf427 100644 --- a/src/hb-ot-shape-complex-use-table.cc +++ b/src/hb-ot-shape-complex-use-table.cc @@ -560,7 +560,7 @@ static const USE_TABLE_ELEMENT_TYPE use_table[] = { /* Grantha */ - /* 11300 */ VMAbv, VMAbv, VMPst, VMPst, O, B, B, B, B, B, B, B, B, O, O, B, + /* 11300 */ VMAbv, VMAbv, VMAbv, VMPst, O, B, B, B, B, B, B, B, B, O, O, B, /* 11310 */ B, O, O, B, B, B, B, B, B, B, B, B, B, B, B, B, /* 11320 */ B, B, B, B, B, B, B, B, B, O, B, B, B, B, B, B, /* 11330 */ B, O, B, B, O, B, B, B, B, B, O, CMBlw, CMBlw, B, VPst, VPst, @@ -673,7 +673,7 @@ static const USE_TABLE_ELEMENT_TYPE use_table[] = { /* 11C10 */ B, B, B, B, B, B, B, B, B, B, B, B, B, B, B, B, /* 11C20 */ B, B, B, B, B, B, B, B, B, B, B, B, B, B, B, VPst, /* 11C30 */ VAbv, VAbv, VBlw, VBlw, VBlw, VBlw, VBlw, O, VAbv, VAbv, VAbv, VAbv, VMAbv, VMAbv, VMPst, H, - /* 11C40 */ B, O, O, O, O, O, O, O, O, O, O, O, O, O, O, O, + /* 11C40 */ B, O, O, O, GB, GB, O, O, O, O, O, O, O, O, O, O, /* 11C50 */ B, B, B, B, B, B, B, B, B, B, B, B, B, B, B, B, /* 11C60 */ B, B, B, B, B, B, B, B, B, B, B, B, B, O, O, O, From 46d8f0d5521c3dd0b10c78e66153faefdb9046db Mon Sep 17 00:00:00 2001 From: David Corbett Date: Fri, 6 Jul 2018 15:47:03 -0400 Subject: [PATCH 033/106] Do not enforce a native direction of LTR for Runic Fixes #481 --- src/hb-common.cc | 1 + 1 file changed, 1 insertion(+) diff --git a/src/hb-common.cc b/src/hb-common.cc index a67fcf85e..ca2b32784 100644 --- a/src/hb-common.cc +++ b/src/hb-common.cc @@ -545,6 +545,7 @@ hb_script_get_horizontal_direction (hb_script_t script) /* https://github.com/harfbuzz/harfbuzz/issues/1000 */ case HB_SCRIPT_OLD_ITALIC: + case HB_SCRIPT_RUNIC: return HB_DIRECTION_INVALID; } From e3a931ef0b86419b5e4ba17de51535393471ed9d Mon Sep 17 00:00:00 2001 From: Cosimo Lupo Date: Mon, 9 Jul 2018 18:11:29 +0100 Subject: [PATCH 034/106] gen-def.py: pass headers as arguments so that msys2 can convert posix paths When one is not using the msys2 python, the header files that are passed in as environment variable cannot be found. https://ci.appveyor.com/project/fonttools/ttfautohint-py/build/1.0.65/job/rkremny4jjid9nl2#L803 This is because msys2 shell and make use POSIX paths (e.g. /c/Users/clupo/...) whereas non-msys2 python.exe uses native Windows paths (e.g. C:\Users\clupo\...). Msys2 will automatically convert command line arguments (but not environment variables) from POSIX to Windows paths when calling a native win32 executable, so we pass the header paths as arguments instead of environment variables. This way the gen-def.py script can support both mingw python running in an MSYS2 shell, and native win32 python. --- src/gen-def.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/gen-def.py b/src/gen-def.py index 9a997d65a..ba39eaae5 100755 --- a/src/gen-def.py +++ b/src/gen-def.py @@ -4,8 +4,14 @@ from __future__ import print_function, division, absolute_import import io, os, re, sys +if len (sys.argv) < 3: + sys.exit("usage: gen-def.py harfbuzz.def hb.h [hb-blob.h hb-buffer.h ...]") + +output_file = sys.argv[1] +header_paths = sys.argv[2:] + headers_content = [] -for h in os.environ["headers"].split (' '): +for h in header_paths: if h.endswith (".h"): with io.open (h, encoding='utf-8') as f: headers_content.append (f.read ()) @@ -13,7 +19,7 @@ result = """EXPORTS %s LIBRARY lib%s-0.dll""" % ( "\n".join (sorted (re.findall (r"^hb_\w+(?= \()", "\n".join (headers_content), re.M))), - sys.argv[1].replace ('.def', '') + output_file.replace ('.def', '') ) -with open (sys.argv[1], "w") as f: f.write (result) +with open (output_file, "w") as f: f.write (result) From ccdd15655480fe35226c0b757e28d3527fe2e6af Mon Sep 17 00:00:00 2001 From: Cosimo Lupo Date: Mon, 9 Jul 2018 18:26:44 +0100 Subject: [PATCH 035/106] src/Makefile.am: pass headers to gen-def.py as arguments, not env vars --- src/Makefile.am | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Makefile.am b/src/Makefile.am index 9d5662e4a..6dfec3bfa 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -277,13 +277,13 @@ endif check: $(DEF_FILES) # For check-symbols.sh CLEANFILES += $(DEF_FILES) harfbuzz.def: $(HBHEADERS) $(HBNODISTHEADERS) - $(AM_V_GEN) headers="$^" $(srcdir)/gen-def.py "$@" + $(AM_V_GEN) $(srcdir)/gen-def.py "$@" $^ harfbuzz-subset.def: $(HB_SUBSET_headers) - $(AM_V_GEN) headers="$^" $(srcdir)/gen-def.py "$@" + $(AM_V_GEN) $(srcdir)/gen-def.py "$@" $^ harfbuzz-icu.def: $(HB_ICU_headers) - $(AM_V_GEN) headers="$^" $(srcdir)/gen-def.py "$@" + $(AM_V_GEN) $(srcdir)/gen-def.py "$@" $^ harfbuzz-gobject.def: $(HB_GOBJECT_headers) - $(AM_V_GEN) headers="$^" $(srcdir)/gen-def.py "$@" + $(AM_V_GEN) $(srcdir)/gen-def.py "$@" $^ GENERATORS = \ From 83d2233a5c47cf1feadcdece5bd4a6b498c6ee7a Mon Sep 17 00:00:00 2001 From: Cosimo Lupo Date: Mon, 9 Jul 2018 18:48:20 +0100 Subject: [PATCH 036/106] CMakeLists.txt: pass headers as arguments to gen-def.py; call using PYTHON_EXECUTABLE --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 9ed7e56e8..e0a4b8812 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -836,7 +836,7 @@ if (UNIX OR MINGW) # generate harfbuzz.def after build completion string(REPLACE ";" " " space_separated_headers "${project_headers}") add_custom_command(TARGET harfbuzz POST_BUILD - COMMAND ${CMAKE_COMMAND} -E env "headers=${space_separated_headers}" python ${PROJECT_SOURCE_DIR}/src/gen-def.py ${PROJECT_BINARY_DIR}/harfbuzz.def + COMMAND "${PYTHON_EXECUTABLE}" ${PROJECT_SOURCE_DIR}/src/gen-def.py ${PROJECT_BINARY_DIR}/harfbuzz.def ${space_separated_headers} WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}/src) add_test(NAME check-static-inits.sh From 53f73409a91241765ae6a0cadf7600676988b6af Mon Sep 17 00:00:00 2001 From: Cosimo Lupo Date: Mon, 9 Jul 2018 18:54:23 +0100 Subject: [PATCH 037/106] CMakeLists.txt: don't pass header args as single space-separated string let python's parse command-line args as usual --- CMakeLists.txt | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index e0a4b8812..e881dbd1a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -834,9 +834,8 @@ set_target_properties(hb-ot-tag PROPERTIES COMPILE_FLAGS "-DMAIN") if (UNIX OR MINGW) if (BUILD_SHARED_LIBS) # generate harfbuzz.def after build completion - string(REPLACE ";" " " space_separated_headers "${project_headers}") add_custom_command(TARGET harfbuzz POST_BUILD - COMMAND "${PYTHON_EXECUTABLE}" ${PROJECT_SOURCE_DIR}/src/gen-def.py ${PROJECT_BINARY_DIR}/harfbuzz.def ${space_separated_headers} + COMMAND "${PYTHON_EXECUTABLE}" ${PROJECT_SOURCE_DIR}/src/gen-def.py ${PROJECT_BINARY_DIR}/harfbuzz.def ${project_headers} WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}/src) add_test(NAME check-static-inits.sh From 7cb47d0f3f202843ebc7fb8801bf388bb90ba3aa Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Tue, 10 Jul 2018 12:51:29 +0200 Subject: [PATCH 038/106] Minor --- src/hb-set-private.hh | 1 + 1 file changed, 1 insertion(+) diff --git a/src/hb-set-private.hh b/src/hb-set-private.hh index ccd4d8df5..6841189ec 100644 --- a/src/hb-set-private.hh +++ b/src/hb-set-private.hh @@ -405,6 +405,7 @@ struct hb_set_t if (get_population () > larger_set->get_population ()) return false; + /* TODO Optimize to use pages. */ hb_codepoint_t c = INVALID; while (next (&c)) if (!larger_set->has (c)) From bca83618cda7ee4f683b4685d10db9e1bef4983c Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Tue, 10 Jul 2018 12:58:13 +0200 Subject: [PATCH 039/106] Add fallback implementation for constexpr and alignof --- src/hb-private.hh | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/hb-private.hh b/src/hb-private.hh index 5cec8e0b4..6893bfd35 100644 --- a/src/hb-private.hh +++ b/src/hb-private.hh @@ -84,6 +84,10 @@ extern "C" void hb_free_impl(void *ptr); #define nullptr NULL #endif +#ifndef constexpr +#define constexpr const +#endif + // Static assertions #ifndef static_assert #define static_assert(e, msg) \ @@ -98,6 +102,20 @@ extern "C" void hb_free_impl(void *ptr); #define thread_local #endif +#ifndef alignof +#define alignof(x) _hb_alignof::value; +template +struct _hb_alignof +{ + struct s + { + char c; + T t; + }; + static constexpr unsigned int value = offsetof (s, t); +}; +#endif // alignof + #endif // __cplusplus < 201103L #if (defined(__GNUC__) || defined(__clang__)) && defined(__OPTIMIZE__) From 27c5317d918971c2fb67c213621a19ac790440e4 Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Tue, 10 Jul 2018 13:03:42 +0200 Subject: [PATCH 040/106] Fix alignof impl --- src/hb-private.hh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/hb-private.hh b/src/hb-private.hh index 6893bfd35..8609e04a8 100644 --- a/src/hb-private.hh +++ b/src/hb-private.hh @@ -103,7 +103,7 @@ extern "C" void hb_free_impl(void *ptr); #endif #ifndef alignof -#define alignof(x) _hb_alignof::value; +#define alignof(x) (_hb_alignof::value) template struct _hb_alignof { From 292c100d6141eb2e981fa632602d73768f748727 Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Tue, 10 Jul 2018 13:16:52 +0200 Subject: [PATCH 041/106] Always compile (but not use) alignof() and round() fallback codes Catches compile-errors in them better. --- src/hb-private.hh | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/src/hb-private.hh b/src/hb-private.hh index 8609e04a8..48a7db10e 100644 --- a/src/hb-private.hh +++ b/src/hb-private.hh @@ -78,6 +78,17 @@ extern "C" void hb_free_impl(void *ptr); /* Compiler attributes */ +template +struct _hb_alignof +{ + struct s + { + char c; + T t; + }; + static constexpr unsigned int value = offsetof (s, t); +}; + #if __cplusplus < 201103L #ifndef nullptr @@ -104,16 +115,6 @@ extern "C" void hb_free_impl(void *ptr); #ifndef alignof #define alignof(x) (_hb_alignof::value) -template -struct _hb_alignof -{ - struct s - { - char c; - T t; - }; - static constexpr unsigned int value = offsetof (s, t); -}; #endif // alignof #endif // __cplusplus < 201103L @@ -1258,7 +1259,6 @@ struct hb_bytes_t /* fallback for round() */ -#if !defined (HAVE_ROUND) && !defined (HAVE_DECL_ROUND) static inline double _hb_round (double x) { @@ -1267,6 +1267,7 @@ _hb_round (double x) else return ceil (x - 0.5); } +#if !defined (HAVE_ROUND) && !defined (HAVE_DECL_ROUND) #define round(x) _hb_round(x) #endif From 83ea277178544cd7e417bdfb7b600ede94910e13 Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Tue, 10 Jul 2018 13:17:27 +0200 Subject: [PATCH 042/106] Add posix_memalign() fallback --- configure.ac | 2 +- src/hb-private.hh | 40 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 41 insertions(+), 1 deletion(-) diff --git a/configure.ac b/configure.ac index d6c23e53c..35de036b1 100644 --- a/configure.ac +++ b/configure.ac @@ -78,7 +78,7 @@ GTK_DOC_CHECK([1.15],[--flavour no-tmpl]) ]) # Functions and headers -AC_CHECK_FUNCS(atexit mprotect sysconf getpagesize mmap isatty newlocale strtod_l) +AC_CHECK_FUNCS(atexit mprotect sysconf getpagesize mmap isatty newlocale strtod_l posix_memalign) save_libs="$LIBS" LIBS="$LIBS -lm" diff --git a/src/hb-private.hh b/src/hb-private.hh index 48a7db10e..566065315 100644 --- a/src/hb-private.hh +++ b/src/hb-private.hh @@ -58,6 +58,7 @@ #define HB_PASTE1(a,b) a##b #define HB_PASTE(a,b) HB_PASTE1(a,b) + /* Compile-time custom allocator support. */ #if defined(hb_malloc_impl) \ @@ -72,6 +73,14 @@ extern "C" void hb_free_impl(void *ptr); #define calloc hb_calloc_impl #define realloc hb_realloc_impl #define free hb_free_impl + +#if defined(hb_memalign_impl +extern "C" int hb_memalign_impl(void **memptr, size_t alignment, size_t size); +#define posix_memalign hb_memalign_impl +#else +#undef HAVE_POSIX_MEMALIGN +#endif + #endif @@ -550,6 +559,10 @@ _hb_ceil_to_4 (unsigned int v) return ((v - 1) | 3) + 1; } +static inline bool _hb_ispow2 (unsigned int v) +{ + return 0 == (v & (v - 1)); +} /* @@ -1272,4 +1285,31 @@ _hb_round (double x) #endif +/* fallback for posix_memalign() */ +static inline int +_hb_memalign(void **memptr, size_t alignment, size_t size) +{ + if (unlikely (!_hb_ispow2 (alignment) || + !alignment || + 0 != (alignment & (sizeof (void *) - 1)))) + return EINVAL; + + char *p = (char *) malloc (size + alignment - 1); + if (unlikely (!p)) + return ENOMEM; + + size_t off = (size_t) p & (alignment - 1); + if (off) + p += alignment - off; + + *memptr = (void *) p; + + return 0; +} +#if !defined(posix_memalign) && !defined(HAVE_POSIX_MEMALIGN) +#define posix_memalign _hb_memalign +#endif + + + #endif /* HB_PRIVATE_HH */ From 763f878cc0595162255c58ffe7a82ac1ca51cb0b Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Tue, 10 Jul 2018 13:47:41 +0200 Subject: [PATCH 043/106] Fix syntax Oops. --- src/hb-private.hh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/hb-private.hh b/src/hb-private.hh index 566065315..5131ddeda 100644 --- a/src/hb-private.hh +++ b/src/hb-private.hh @@ -74,7 +74,7 @@ extern "C" void hb_free_impl(void *ptr); #define realloc hb_realloc_impl #define free hb_free_impl -#if defined(hb_memalign_impl +#if defined(hb_memalign_impl) extern "C" int hb_memalign_impl(void **memptr, size_t alignment, size_t size); #define posix_memalign hb_memalign_impl #else From 39f11d8e72c6b2568f3b70847c6c9d1f374cd49c Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Tue, 10 Jul 2018 14:01:39 +0200 Subject: [PATCH 044/106] Minor --- src/hb-private.hh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/hb-private.hh b/src/hb-private.hh index 5131ddeda..c4fae17b6 100644 --- a/src/hb-private.hh +++ b/src/hb-private.hh @@ -656,7 +656,7 @@ struct CrapOrNull { /* arrays and maps */ -#define HB_PREALLOCED_ARRAY_INIT {0, 0, nullptr} +#define HB_VECTOR_INIT {0, 0, false, nullptr} template struct hb_vector_t { @@ -875,7 +875,7 @@ template struct hb_auto_array_t : hb_auto_t > {}; -#define HB_LOCKABLE_SET_INIT {HB_PREALLOCED_ARRAY_INIT} +#define HB_LOCKABLE_SET_INIT {HB_VECTOR_INIT} template struct hb_lockable_set_t { From 9e53b083295ad910a87e778ebd16cbe69ebe2130 Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Tue, 10 Jul 2018 14:03:58 +0200 Subject: [PATCH 045/106] Move hb_stable_sort to hb-dsalgs.hh Also, include hb-dsalgs.hh from end of hb-pricate.hh --- src/hb-dsalgs.hh | 51 +++++++++++++++++++++++++++++++++ src/hb-ot-os2-unicode-ranges.hh | 1 - src/hb-ot-post-table.hh | 1 - src/hb-private.hh | 51 ++------------------------------- 4 files changed, 53 insertions(+), 51 deletions(-) diff --git a/src/hb-dsalgs.hh b/src/hb-dsalgs.hh index 958687194..68b1fd111 100644 --- a/src/hb-dsalgs.hh +++ b/src/hb-dsalgs.hh @@ -158,4 +158,55 @@ static inline void hb_sort_r(void *base, size_t nel, size_t width, sort_r_simple(base, nel, width, compar, arg); } + +template static inline void +hb_stable_sort (T *array, unsigned int len, int(*compar)(const T *, const T *), T2 *array2) +{ + for (unsigned int i = 1; i < len; i++) + { + unsigned int j = i; + while (j && compar (&array[j - 1], &array[i]) > 0) + j--; + if (i == j) + continue; + /* Move item i to occupy place for item j, shift what's in between. */ + { + T t = array[i]; + memmove (&array[j + 1], &array[j], (i - j) * sizeof (T)); + array[j] = t; + } + if (array2) + { + T2 t = array2[i]; + memmove (&array2[j + 1], &array2[j], (i - j) * sizeof (T2)); + array2[j] = t; + } + } +} + +template static inline void +hb_stable_sort (T *array, unsigned int len, int(*compar)(const T *, const T *)) +{ + hb_stable_sort (array, len, compar, (int *) nullptr); +} + +static inline hb_bool_t +hb_codepoint_parse (const char *s, unsigned int len, int base, hb_codepoint_t *out) +{ + /* Pain because we don't know whether s is nul-terminated. */ + char buf[64]; + len = MIN (ARRAY_LENGTH (buf) - 1, len); + strncpy (buf, s, len); + buf[len] = '\0'; + + char *end; + errno = 0; + unsigned long v = strtoul (buf, &end, base); + if (errno) return false; + if (*end) return false; + *out = v; + return true; +} + + #endif /* HB_DSALGS_HH */ diff --git a/src/hb-ot-os2-unicode-ranges.hh b/src/hb-ot-os2-unicode-ranges.hh index 9b32cfabb..cb1260784 100644 --- a/src/hb-ot-os2-unicode-ranges.hh +++ b/src/hb-ot-os2-unicode-ranges.hh @@ -28,7 +28,6 @@ #define HB_OT_OS2_UNICODE_RANGES_HH #include "hb-private.hh" -#include "hb-dsalgs.hh" namespace OT { diff --git a/src/hb-ot-post-table.hh b/src/hb-ot-post-table.hh index 5f42751d8..d05fc091c 100644 --- a/src/hb-ot-post-table.hh +++ b/src/hb-ot-post-table.hh @@ -28,7 +28,6 @@ #define HB_OT_POST_TABLE_HH #include "hb-open-type-private.hh" -#include "hb-dsalgs.hh" #include "hb-subset-plan.hh" #define HB_STRING_ARRAY_NAME format1_names diff --git a/src/hb-private.hh b/src/hb-private.hh index c4fae17b6..49ce6fef6 100644 --- a/src/hb-private.hh +++ b/src/hb-private.hh @@ -1059,55 +1059,6 @@ hb_in_ranges (T u, T lo1, T hi1, T lo2, T hi2, T lo3, T hi3) #define FLAG_RANGE(x,y) (ASSERT_STATIC_EXPR_ZERO ((x) < (y)) + FLAG(y+1) - FLAG(x)) -template static inline void -hb_stable_sort (T *array, unsigned int len, int(*compar)(const T *, const T *), T2 *array2) -{ - for (unsigned int i = 1; i < len; i++) - { - unsigned int j = i; - while (j && compar (&array[j - 1], &array[i]) > 0) - j--; - if (i == j) - continue; - /* Move item i to occupy place for item j, shift what's in between. */ - { - T t = array[i]; - memmove (&array[j + 1], &array[j], (i - j) * sizeof (T)); - array[j] = t; - } - if (array2) - { - T2 t = array2[i]; - memmove (&array2[j + 1], &array2[j], (i - j) * sizeof (T2)); - array2[j] = t; - } - } -} - -template static inline void -hb_stable_sort (T *array, unsigned int len, int(*compar)(const T *, const T *)) -{ - hb_stable_sort (array, len, compar, (int *) nullptr); -} - -static inline hb_bool_t -hb_codepoint_parse (const char *s, unsigned int len, int base, hb_codepoint_t *out) -{ - /* Pain because we don't know whether s is nul-terminated. */ - char buf[64]; - len = MIN (ARRAY_LENGTH (buf) - 1, len); - strncpy (buf, s, len); - buf[len] = '\0'; - - char *end; - errno = 0; - unsigned long v = strtoul (buf, &end, base); - if (errno) return false; - if (*end) return false; - *out = v; - return true; -} - /* Vectorization */ @@ -1311,5 +1262,7 @@ _hb_memalign(void **memptr, size_t alignment, size_t size) #endif +#include "hb-dsalgs.hh" + #endif /* HB_PRIVATE_HH */ From d652ef299d123f28409e755ed2d2411295293f19 Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Tue, 10 Jul 2018 14:05:00 +0200 Subject: [PATCH 046/106] Move hb_vector_t and hb_lockable_set_t to hb-dsalgs.hh --- src/hb-dsalgs.hh | 311 +++++++++++++++++++++++++++++++++++++++++++++ src/hb-private.hh | 315 ---------------------------------------------- 2 files changed, 311 insertions(+), 315 deletions(-) diff --git a/src/hb-dsalgs.hh b/src/hb-dsalgs.hh index 68b1fd111..0e44d7cca 100644 --- a/src/hb-dsalgs.hh +++ b/src/hb-dsalgs.hh @@ -209,4 +209,315 @@ hb_codepoint_parse (const char *s, unsigned int len, int base, hb_codepoint_t *o } +#define HB_VECTOR_INIT {0, 0, false, nullptr} +template +struct hb_vector_t +{ + unsigned int len; + unsigned int allocated; + bool successful; + Type *arrayZ; + Type static_array[StaticSize]; + + void init (void) + { + len = 0; + allocated = ARRAY_LENGTH (static_array); + successful = true; + arrayZ = static_array; + } + + inline Type& operator [] (unsigned int i) + { + if (unlikely (i >= len)) + return Crap (Type); + return arrayZ[i]; + } + inline const Type& operator [] (unsigned int i) const + { + if (unlikely (i >= len)) + return Null(Type); + return arrayZ[i]; + } + + inline Type *push (void) + { + if (unlikely (!resize (len + 1))) + return &Crap(Type); + return &arrayZ[len - 1]; + } + inline Type *push (const Type& v) + { + Type *p = push (); + *p = v; + return p; + } + + /* Allocate for size but don't adjust len. */ + inline bool alloc (unsigned int size) + { + if (unlikely (!successful)) + return false; + + if (likely (size <= allocated)) + return true; + + /* Reallocate */ + + unsigned int new_allocated = allocated; + while (size >= new_allocated) + new_allocated += (new_allocated >> 1) + 8; + + Type *new_array = nullptr; + + if (arrayZ == static_array) + { + new_array = (Type *) calloc (new_allocated, sizeof (Type)); + if (new_array) + memcpy (new_array, arrayZ, len * sizeof (Type)); + } + else + { + bool overflows = (new_allocated < allocated) || _hb_unsigned_int_mul_overflows (new_allocated, sizeof (Type)); + if (likely (!overflows)) + new_array = (Type *) realloc (arrayZ, new_allocated * sizeof (Type)); + } + + if (unlikely (!new_array)) + { + successful = false; + return false; + } + + arrayZ = new_array; + allocated = new_allocated; + + return true; + } + + inline bool resize (int size_) + { + unsigned int size = size_ < 0 ? 0u : (unsigned int) size_; + if (!alloc (size)) + return false; + + if (size > len) + memset (arrayZ + len, 0, (size - len) * sizeof (*arrayZ)); + + len = size; + return true; + } + + inline void pop (void) + { + if (!len) return; + len--; + } + + inline void remove (unsigned int i) + { + if (unlikely (i >= len)) + return; + memmove (static_cast (&arrayZ[i]), + static_cast (&arrayZ[i + 1]), + (len - i - 1) * sizeof (Type)); + len--; + } + + inline void shrink (int size_) + { + unsigned int size = size_ < 0 ? 0u : (unsigned int) size_; + if (size < len) + len = size; + } + + template + inline Type *find (T v) { + for (unsigned int i = 0; i < len; i++) + if (arrayZ[i] == v) + return &arrayZ[i]; + return nullptr; + } + template + inline const Type *find (T v) const { + for (unsigned int i = 0; i < len; i++) + if (arrayZ[i] == v) + return &arrayZ[i]; + return nullptr; + } + + inline void qsort (int (*cmp)(const void*, const void*)) + { + ::qsort (arrayZ, len, sizeof (Type), cmp); + } + + inline void qsort (void) + { + ::qsort (arrayZ, len, sizeof (Type), Type::cmp); + } + + inline void qsort (unsigned int start, unsigned int end) + { + ::qsort (arrayZ + start, end - start, sizeof (Type), Type::cmp); + } + + template + inline Type *lsearch (const T &x) + { + for (unsigned int i = 0; i < len; i++) + if (0 == this->arrayZ[i].cmp (&x)) + return &arrayZ[i]; + return nullptr; + } + + template + inline Type *bsearch (const T &x) + { + unsigned int i; + return bfind (x, &i) ? &arrayZ[i] : nullptr; + } + template + inline const Type *bsearch (const T &x) const + { + unsigned int i; + return bfind (x, &i) ? &arrayZ[i] : nullptr; + } + template + inline bool bfind (const T &x, unsigned int *i) const + { + int min = 0, max = (int) this->len - 1; + while (min <= max) + { + int mid = (min + max) / 2; + int c = this->arrayZ[mid].cmp (&x); + if (c < 0) + max = mid - 1; + else if (c > 0) + min = mid + 1; + else + { + *i = mid; + return true; + } + } + if (max < 0 || (max < (int) this->len && this->arrayZ[max].cmp (&x) > 0)) + max++; + *i = max; + return false; + } + + inline void fini (void) + { + if (arrayZ != static_array) + free (arrayZ); + arrayZ = nullptr; + allocated = len = 0; + } +}; + +template +struct hb_auto_t : Type +{ + hb_auto_t (void) { Type::init (); } + ~hb_auto_t (void) { Type::fini (); } + private: /* Hide */ + void init (void) {} + void fini (void) {} +}; +template +struct hb_auto_array_t : hb_auto_t > {}; + + +#define HB_LOCKABLE_SET_INIT {HB_VECTOR_INIT} +template +struct hb_lockable_set_t +{ + hb_vector_t items; + + inline void init (void) { items.init (); } + + template + inline item_t *replace_or_insert (T v, lock_t &l, bool replace) + { + l.lock (); + item_t *item = items.find (v); + if (item) { + if (replace) { + item_t old = *item; + *item = v; + l.unlock (); + old.fini (); + } + else { + item = nullptr; + l.unlock (); + } + } else { + item = items.push (v); + l.unlock (); + } + return item; + } + + template + inline void remove (T v, lock_t &l) + { + l.lock (); + item_t *item = items.find (v); + if (item) { + item_t old = *item; + *item = items[items.len - 1]; + items.pop (); + l.unlock (); + old.fini (); + } else { + l.unlock (); + } + } + + template + inline bool find (T v, item_t *i, lock_t &l) + { + l.lock (); + item_t *item = items.find (v); + if (item) + *i = *item; + l.unlock (); + return !!item; + } + + template + inline item_t *find_or_insert (T v, lock_t &l) + { + l.lock (); + item_t *item = items.find (v); + if (!item) { + item = items.push (v); + } + l.unlock (); + return item; + } + + inline void fini (lock_t &l) + { + if (!items.len) { + /* No need for locking. */ + items.fini (); + return; + } + l.lock (); + while (items.len) { + item_t old = items[items.len - 1]; + items.pop (); + l.unlock (); + old.fini (); + l.lock (); + } + items.fini (); + l.unlock (); + } + +}; + + #endif /* HB_DSALGS_HH */ diff --git a/src/hb-private.hh b/src/hb-private.hh index 49ce6fef6..65d4bae2f 100644 --- a/src/hb-private.hh +++ b/src/hb-private.hh @@ -652,321 +652,6 @@ struct CrapOrNull { #define CrapOrNull(Type) CrapOrNull::get () - -/* arrays and maps */ - - -#define HB_VECTOR_INIT {0, 0, false, nullptr} -template -struct hb_vector_t -{ - unsigned int len; - unsigned int allocated; - bool successful; - Type *arrayZ; - Type static_array[StaticSize]; - - void init (void) - { - len = 0; - allocated = ARRAY_LENGTH (static_array); - successful = true; - arrayZ = static_array; - } - - inline Type& operator [] (unsigned int i) - { - if (unlikely (i >= len)) - return Crap (Type); - return arrayZ[i]; - } - inline const Type& operator [] (unsigned int i) const - { - if (unlikely (i >= len)) - return Null(Type); - return arrayZ[i]; - } - - inline Type *push (void) - { - if (unlikely (!resize (len + 1))) - return &Crap(Type); - return &arrayZ[len - 1]; - } - inline Type *push (const Type& v) - { - Type *p = push (); - *p = v; - return p; - } - - /* Allocate for size but don't adjust len. */ - inline bool alloc (unsigned int size) - { - if (unlikely (!successful)) - return false; - - if (likely (size <= allocated)) - return true; - - /* Reallocate */ - - unsigned int new_allocated = allocated; - while (size >= new_allocated) - new_allocated += (new_allocated >> 1) + 8; - - Type *new_array = nullptr; - - if (arrayZ == static_array) - { - new_array = (Type *) calloc (new_allocated, sizeof (Type)); - if (new_array) - memcpy (new_array, arrayZ, len * sizeof (Type)); - } - else - { - bool overflows = (new_allocated < allocated) || _hb_unsigned_int_mul_overflows (new_allocated, sizeof (Type)); - if (likely (!overflows)) - new_array = (Type *) realloc (arrayZ, new_allocated * sizeof (Type)); - } - - if (unlikely (!new_array)) - { - successful = false; - return false; - } - - arrayZ = new_array; - allocated = new_allocated; - - return true; - } - - inline bool resize (int size_) - { - unsigned int size = size_ < 0 ? 0u : (unsigned int) size_; - if (!alloc (size)) - return false; - - if (size > len) - memset (arrayZ + len, 0, (size - len) * sizeof (*arrayZ)); - - len = size; - return true; - } - - inline void pop (void) - { - if (!len) return; - len--; - } - - inline void remove (unsigned int i) - { - if (unlikely (i >= len)) - return; - memmove (static_cast (&arrayZ[i]), - static_cast (&arrayZ[i + 1]), - (len - i - 1) * sizeof (Type)); - len--; - } - - inline void shrink (int size_) - { - unsigned int size = size_ < 0 ? 0u : (unsigned int) size_; - if (size < len) - len = size; - } - - template - inline Type *find (T v) { - for (unsigned int i = 0; i < len; i++) - if (arrayZ[i] == v) - return &arrayZ[i]; - return nullptr; - } - template - inline const Type *find (T v) const { - for (unsigned int i = 0; i < len; i++) - if (arrayZ[i] == v) - return &arrayZ[i]; - return nullptr; - } - - inline void qsort (int (*cmp)(const void*, const void*)) - { - ::qsort (arrayZ, len, sizeof (Type), cmp); - } - - inline void qsort (void) - { - ::qsort (arrayZ, len, sizeof (Type), Type::cmp); - } - - inline void qsort (unsigned int start, unsigned int end) - { - ::qsort (arrayZ + start, end - start, sizeof (Type), Type::cmp); - } - - template - inline Type *lsearch (const T &x) - { - for (unsigned int i = 0; i < len; i++) - if (0 == this->arrayZ[i].cmp (&x)) - return &arrayZ[i]; - return nullptr; - } - - template - inline Type *bsearch (const T &x) - { - unsigned int i; - return bfind (x, &i) ? &arrayZ[i] : nullptr; - } - template - inline const Type *bsearch (const T &x) const - { - unsigned int i; - return bfind (x, &i) ? &arrayZ[i] : nullptr; - } - template - inline bool bfind (const T &x, unsigned int *i) const - { - int min = 0, max = (int) this->len - 1; - while (min <= max) - { - int mid = (min + max) / 2; - int c = this->arrayZ[mid].cmp (&x); - if (c < 0) - max = mid - 1; - else if (c > 0) - min = mid + 1; - else - { - *i = mid; - return true; - } - } - if (max < 0 || (max < (int) this->len && this->arrayZ[max].cmp (&x) > 0)) - max++; - *i = max; - return false; - } - - inline void fini (void) - { - if (arrayZ != static_array) - free (arrayZ); - arrayZ = nullptr; - allocated = len = 0; - } -}; - -template -struct hb_auto_t : Type -{ - hb_auto_t (void) { Type::init (); } - ~hb_auto_t (void) { Type::fini (); } - private: /* Hide */ - void init (void) {} - void fini (void) {} -}; -template -struct hb_auto_array_t : hb_auto_t > {}; - - -#define HB_LOCKABLE_SET_INIT {HB_VECTOR_INIT} -template -struct hb_lockable_set_t -{ - hb_vector_t items; - - inline void init (void) { items.init (); } - - template - inline item_t *replace_or_insert (T v, lock_t &l, bool replace) - { - l.lock (); - item_t *item = items.find (v); - if (item) { - if (replace) { - item_t old = *item; - *item = v; - l.unlock (); - old.fini (); - } - else { - item = nullptr; - l.unlock (); - } - } else { - item = items.push (v); - l.unlock (); - } - return item; - } - - template - inline void remove (T v, lock_t &l) - { - l.lock (); - item_t *item = items.find (v); - if (item) { - item_t old = *item; - *item = items[items.len - 1]; - items.pop (); - l.unlock (); - old.fini (); - } else { - l.unlock (); - } - } - - template - inline bool find (T v, item_t *i, lock_t &l) - { - l.lock (); - item_t *item = items.find (v); - if (item) - *i = *item; - l.unlock (); - return !!item; - } - - template - inline item_t *find_or_insert (T v, lock_t &l) - { - l.lock (); - item_t *item = items.find (v); - if (!item) { - item = items.push (v); - } - l.unlock (); - return item; - } - - inline void fini (lock_t &l) - { - if (!items.len) { - /* No need for locking. */ - items.fini (); - return; - } - l.lock (); - while (items.len) { - item_t old = items[items.len - 1]; - items.pop (); - l.unlock (); - old.fini (); - l.lock (); - } - items.fini (); - l.unlock (); - } - -}; - - /* ASCII tag/character handling */ static inline bool ISALPHA (unsigned char c) From bddeb2b10ca2f4b4bee6f7eaaf5615875a67111d Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Tue, 10 Jul 2018 14:12:37 +0200 Subject: [PATCH 047/106] Minor renamings of internal inline functions --- src/hb-buffer.cc | 4 ++-- src/hb-dsalgs.hh | 2 +- src/hb-map-private.hh | 2 +- src/hb-open-type-private.hh | 4 ++-- src/hb-ot-cmap-table.hh | 2 +- src/hb-ot-hdmx-table.hh | 2 +- src/hb-ot-layout-gpos-table.hh | 4 ++-- src/hb-ot-layout-gsub-table.hh | 2 +- src/hb-ot-map.cc | 4 ++-- src/hb-ot-shape.cc | 4 ++-- src/hb-private.hh | 27 ++++++++++++++------------- src/hb-set-private.hh | 6 +++--- src/hb-subset.cc | 2 +- 13 files changed, 33 insertions(+), 32 deletions(-) diff --git a/src/hb-buffer.cc b/src/hb-buffer.cc index 7b95aea43..d04e1e80f 100644 --- a/src/hb-buffer.cc +++ b/src/hb-buffer.cc @@ -124,14 +124,14 @@ hb_buffer_t::enlarge (unsigned int size) hb_glyph_info_t *new_info = nullptr; bool separate_out = out_info != info; - if (unlikely (_hb_unsigned_int_mul_overflows (size, sizeof (info[0])))) + if (unlikely (hb_unsigned_mul_overflows (size, sizeof (info[0])))) goto done; while (size >= new_allocated) new_allocated += (new_allocated >> 1) + 32; static_assert ((sizeof (info[0]) == sizeof (pos[0])), ""); - if (unlikely (_hb_unsigned_int_mul_overflows (new_allocated, sizeof (info[0])))) + if (unlikely (hb_unsigned_mul_overflows (new_allocated, sizeof (info[0])))) goto done; new_pos = (hb_glyph_position_t *) realloc (pos, new_allocated * sizeof (pos[0])); diff --git a/src/hb-dsalgs.hh b/src/hb-dsalgs.hh index 0e44d7cca..ef48fb081 100644 --- a/src/hb-dsalgs.hh +++ b/src/hb-dsalgs.hh @@ -278,7 +278,7 @@ struct hb_vector_t } else { - bool overflows = (new_allocated < allocated) || _hb_unsigned_int_mul_overflows (new_allocated, sizeof (Type)); + bool overflows = (new_allocated < allocated) || hb_unsigned_mul_overflows (new_allocated, sizeof (Type)); if (likely (!overflows)) new_array = (Type *) realloc (arrayZ, new_allocated * sizeof (Type)); } diff --git a/src/hb-map-private.hh b/src/hb-map-private.hh index d3d4ddeda..c4f2fc7da 100644 --- a/src/hb-map-private.hh +++ b/src/hb-map-private.hh @@ -89,7 +89,7 @@ struct hb_map_t { if (unlikely (!successful)) return false; - unsigned int power = _hb_bit_storage (population * 2 + 8); + unsigned int power = hb_bit_storage (population * 2 + 8); unsigned int new_size = 1u << power; item_t *new_items = (item_t *) malloc ((size_t) new_size * sizeof (item_t)); if (unlikely (!new_items)) diff --git a/src/hb-open-type-private.hh b/src/hb-open-type-private.hh index 9a4835b89..59b8cc02b 100644 --- a/src/hb-open-type-private.hh +++ b/src/hb-open-type-private.hh @@ -230,7 +230,7 @@ struct hb_sanitize_context_t : inline bool check_array (const void *base, unsigned int record_size, unsigned int len) const { const char *p = (const char *) base; - bool overflows = _hb_unsigned_int_mul_overflows (len, record_size); + bool overflows = hb_unsigned_mul_overflows (len, record_size); unsigned int array_size = record_size * len; bool ok = !overflows && this->check_range (base, array_size); @@ -1178,7 +1178,7 @@ struct BinSearchHeader { len.set (v); assert (len == v); - entrySelector.set (MAX (1u, _hb_bit_storage (v)) - 1); + entrySelector.set (MAX (1u, hb_bit_storage (v)) - 1); searchRange.set (16 * (1u << entrySelector)); rangeShift.set (v * 16 > searchRange ? 16 * v - searchRange diff --git a/src/hb-ot-cmap-table.hh b/src/hb-ot-cmap-table.hh index c1903f6e3..0ea37209a 100644 --- a/src/hb-ot-cmap-table.hh +++ b/src/hb-ot-cmap-table.hh @@ -89,7 +89,7 @@ struct CmapSubtableFormat4 this->length.set (get_sub_table_size (segments)); this->segCountX2.set (segments.len * 2); - this->entrySelector.set (MAX (1u, _hb_bit_storage (segments.len)) - 1); + this->entrySelector.set (MAX (1u, hb_bit_storage (segments.len)) - 1); this->searchRange.set (2 * (1u << this->entrySelector)); this->rangeShift.set (segments.len * 2 > this->searchRange ? 2 * segments.len - this->searchRange diff --git a/src/hb-ot-hdmx-table.hh b/src/hb-ot-hdmx-table.hh index d406e3e21..0951871ce 100644 --- a/src/hb-ot-hdmx-table.hh +++ b/src/hb-ot-hdmx-table.hh @@ -199,7 +199,7 @@ struct hdmx { TRACE_SANITIZE (this); return_trace (c->check_struct (this) && version == 0 && - !_hb_unsigned_int_mul_overflows (num_records, size_device_record) && + !hb_unsigned_mul_overflows (num_records, size_device_record) && size_device_record >= DeviceRecord::min_size && c->check_range (this, get_size())); } diff --git a/src/hb-ot-layout-gpos-table.hh b/src/hb-ot-layout-gpos-table.hh index 182c8d909..b52c0144f 100644 --- a/src/hb-ot-layout-gpos-table.hh +++ b/src/hb-ot-layout-gpos-table.hh @@ -99,7 +99,7 @@ struct ValueFormat : HBUINT16 #endif inline unsigned int get_len (void) const - { return _hb_popcount ((unsigned int) *this); } + { return hb_popcount ((unsigned int) *this); } inline unsigned int get_size (void) const { return get_len () * Value::static_size; } @@ -374,7 +374,7 @@ struct AnchorMatrix { TRACE_SANITIZE (this); if (!c->check_struct (this)) return_trace (false); - if (unlikely (_hb_unsigned_int_mul_overflows (rows, cols))) return_trace (false); + if (unlikely (hb_unsigned_mul_overflows (rows, cols))) return_trace (false); unsigned int count = rows * cols; if (!c->check_array (matrixZ, matrixZ[0].static_size, count)) return_trace (false); for (unsigned int i = 0; i < count; i++) diff --git a/src/hb-ot-layout-gsub-table.hh b/src/hb-ot-layout-gsub-table.hh index bd72fe6bf..91b898b63 100644 --- a/src/hb-ot-layout-gsub-table.hh +++ b/src/hb-ot-layout-gsub-table.hh @@ -511,7 +511,7 @@ struct AlternateSubstFormat1 hb_mask_t lookup_mask = c->lookup_mask; /* Note: This breaks badly if two features enabled this lookup together. */ - unsigned int shift = _hb_ctz (lookup_mask); + unsigned int shift = hb_ctz (lookup_mask); unsigned int alt_index = ((lookup_mask & glyph_mask) >> shift); if (unlikely (alt_index > alt_set.len || alt_index == 0)) return_trace (false); diff --git a/src/hb-ot-map.cc b/src/hb-ot-map.cc index 46bf2db0c..f26cac9b1 100644 --- a/src/hb-ot-map.cc +++ b/src/hb-ot-map.cc @@ -145,7 +145,7 @@ hb_ot_map_builder_t::compile (hb_ot_map_t &m, { static_assert ((!(HB_GLYPH_FLAG_DEFINED & (HB_GLYPH_FLAG_DEFINED + 1))), ""); unsigned int global_bit_mask = HB_GLYPH_FLAG_DEFINED + 1; - unsigned int global_bit_shift = _hb_popcount (HB_GLYPH_FLAG_DEFINED); + unsigned int global_bit_shift = hb_popcount (HB_GLYPH_FLAG_DEFINED); m.global_mask = global_bit_mask; @@ -209,7 +209,7 @@ hb_ot_map_builder_t::compile (hb_ot_map_t &m, bits_needed = 0; else /* Limit to 8 bits per feature. */ - bits_needed = MIN(8u, _hb_bit_storage (info->max_value)); + bits_needed = MIN(8u, hb_bit_storage (info->max_value)); if (!info->max_value || next_bit + bits_needed > 8 * sizeof (hb_mask_t)) continue; /* Feature disabled, or not enough bits. */ diff --git a/src/hb-ot-shape.cc b/src/hb-ot-shape.cc index 36e0bf9c3..1189b2075 100644 --- a/src/hb-ot-shape.cc +++ b/src/hb-ot-shape.cc @@ -829,12 +829,12 @@ hb_ot_shape_internal (hb_ot_shape_context_t *c) { c->buffer->deallocate_var_all (); c->buffer->scratch_flags = HB_BUFFER_SCRATCH_FLAG_DEFAULT; - if (likely (!_hb_unsigned_int_mul_overflows (c->buffer->len, HB_BUFFER_MAX_LEN_FACTOR))) + if (likely (!hb_unsigned_mul_overflows (c->buffer->len, HB_BUFFER_MAX_LEN_FACTOR))) { c->buffer->max_len = MAX (c->buffer->len * HB_BUFFER_MAX_LEN_FACTOR, (unsigned) HB_BUFFER_MAX_LEN_MIN); } - if (likely (!_hb_unsigned_int_mul_overflows (c->buffer->len, HB_BUFFER_MAX_OPS_FACTOR))) + if (likely (!hb_unsigned_mul_overflows (c->buffer->len, HB_BUFFER_MAX_OPS_FACTOR))) { c->buffer->max_ops = MAX (c->buffer->len * HB_BUFFER_MAX_OPS_FACTOR, (unsigned) HB_BUFFER_MAX_OPS_MIN); diff --git a/src/hb-private.hh b/src/hb-private.hh index 65d4bae2f..fa9a1aee2 100644 --- a/src/hb-private.hh +++ b/src/hb-private.hh @@ -362,7 +362,7 @@ typedef const struct _hb_void_t *hb_void_t; /* Return the number of 1 bits in v. */ template static inline HB_CONST_FUNC unsigned int -_hb_popcount (T v) +hb_popcount (T v) { #if (__GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4)) && defined(__OPTIMIZE__) if (sizeof (T) <= sizeof (unsigned int)) @@ -387,13 +387,13 @@ _hb_popcount (T v) if (sizeof (T) == 8) { unsigned int shift = 32; - return _hb_popcount ((uint32_t) v) + _hb_popcount ((uint32_t) (v >> shift)); + return hb_popcount ((uint32_t) v) + hb_popcount ((uint32_t) (v >> shift)); } if (sizeof (T) == 16) { unsigned int shift = 64; - return _hb_popcount ((uint64_t) v) + _hb_popcount ((uint64_t) (v >> shift)); + return hb_popcount ((uint64_t) v) + hb_popcount ((uint64_t) (v >> shift)); } assert (0); @@ -403,7 +403,7 @@ _hb_popcount (T v) /* Returns the number of bits needed to store number */ template static inline HB_CONST_FUNC unsigned int -_hb_bit_storage (T v) +hb_bit_storage (T v) { if (unlikely (!v)) return 0; @@ -466,8 +466,8 @@ _hb_bit_storage (T v) if (sizeof (T) == 16) { unsigned int shift = 64; - return (v >> shift) ? _hb_bit_storage ((uint64_t) (v >> shift)) + shift : - _hb_bit_storage ((uint64_t) v); + return (v >> shift) ? hb_bit_storage ((uint64_t) (v >> shift)) + shift : + hb_bit_storage ((uint64_t) v); } assert (0); @@ -477,7 +477,7 @@ _hb_bit_storage (T v) /* Returns the number of zero bits in the least significant side of v */ template static inline HB_CONST_FUNC unsigned int -_hb_ctz (T v) +hb_ctz (T v) { if (unlikely (!v)) return 0; @@ -539,8 +539,8 @@ _hb_ctz (T v) if (sizeof (T) == 16) { unsigned int shift = 64; - return (uint64_t) v ? _hb_bit_storage ((uint64_t) v) : - _hb_bit_storage ((uint64_t) v >> shift) + shift; + return (uint64_t) v ? hb_bit_storage ((uint64_t) v) : + hb_bit_storage ((uint64_t) v >> shift) + shift; } assert (0); @@ -548,18 +548,19 @@ _hb_ctz (T v) } static inline bool -_hb_unsigned_int_mul_overflows (unsigned int count, unsigned int size) +hb_unsigned_mul_overflows (unsigned int count, unsigned int size) { return (size > 0) && (count >= ((unsigned int) -1) / size); } static inline unsigned int -_hb_ceil_to_4 (unsigned int v) +hb_ceil_to_4 (unsigned int v) { return ((v - 1) | 3) + 1; } -static inline bool _hb_ispow2 (unsigned int v) +static inline bool +hb_ispow2 (unsigned int v) { return 0 == (v & (v - 1)); } @@ -925,7 +926,7 @@ _hb_round (double x) static inline int _hb_memalign(void **memptr, size_t alignment, size_t size) { - if (unlikely (!_hb_ispow2 (alignment) || + if (unlikely (!hb_ispow2 (alignment) || !alignment || 0 != (alignment & (sizeof (void *) - 1)))) return EINVAL; diff --git a/src/hb-set-private.hh b/src/hb-set-private.hh index 6841189ec..bdaf3f1a2 100644 --- a/src/hb-set-private.hh +++ b/src/hb-set-private.hh @@ -94,7 +94,7 @@ struct hb_set_t { unsigned int pop = 0; for (unsigned int i = 0; i < len (); i++) - pop += _hb_popcount (v[i]); + pop += hb_popcount (v[i]); return pop; } @@ -161,8 +161,8 @@ struct hb_set_t static const unsigned int PAGE_BITS = 512; static_assert ((PAGE_BITS & ((PAGE_BITS) - 1)) == 0, ""); - static inline unsigned int elt_get_min (const elt_t &elt) { return _hb_ctz (elt); } - static inline unsigned int elt_get_max (const elt_t &elt) { return _hb_bit_storage (elt) - 1; } + static inline unsigned int elt_get_min (const elt_t &elt) { return hb_ctz (elt); } + static inline unsigned int elt_get_max (const elt_t &elt) { return hb_bit_storage (elt) - 1; } typedef hb_vector_size_t vector_t; diff --git a/src/hb-subset.cc b/src/hb-subset.cc index b97c7633e..e86063418 100644 --- a/src/hb-subset.cc +++ b/src/hb-subset.cc @@ -154,7 +154,7 @@ _hb_subset_face_data_reference_blob (hb_subset_face_data_t *data) unsigned int face_length = table_count * 16 + 12; for (unsigned int i = 0; i < table_count; i++) - face_length += _hb_ceil_to_4 (hb_blob_get_length (data->tables.arrayZ[i].blob)); + face_length += hb_ceil_to_4 (hb_blob_get_length (data->tables.arrayZ[i].blob)); char *buf = (char *) malloc (face_length); if (unlikely (!buf)) From be458eb05962dd5f5c60a25f54cf0b20e7d8b055 Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Tue, 10 Jul 2018 14:41:04 +0200 Subject: [PATCH 048/106] Include more basic internal headers from hb-private.hh --- src/hb-blob-private.hh | 2 -- src/hb-blob.cc | 1 - src/hb-buffer-private.hh | 1 - src/hb-common.cc | 2 -- src/hb-coretext.cc | 1 - src/hb-directwrite.cc | 1 - src/hb-face-private.hh | 1 - src/hb-font-private.hh | 1 - src/hb-ft.cc | 1 - src/hb-map-private.hh | 1 - src/hb-object-private.hh | 4 ---- src/hb-open-type-private.hh | 1 - src/hb-ot-layout-common-private.hh | 1 - src/hb-ot-layout-gsubgpos-private.hh | 1 - src/hb-ot-shape-complex-arabic.cc | 1 - src/hb-private.hh | 6 +++++- src/hb-set-private.hh | 1 - src/hb-shape-plan-private.hh | 1 - src/hb-shape-plan.cc | 1 - src/hb-subset-input.cc | 1 - src/hb-subset-plan.hh | 1 - src/hb-subset.cc | 1 - src/hb-unicode-private.hh | 1 - src/hb-uniscribe.cc | 1 - src/hb-warning.cc | 4 +--- 25 files changed, 6 insertions(+), 32 deletions(-) diff --git a/src/hb-blob-private.hh b/src/hb-blob-private.hh index b72fa721b..56a7b668b 100644 --- a/src/hb-blob-private.hh +++ b/src/hb-blob-private.hh @@ -31,8 +31,6 @@ #include "hb-private.hh" -#include "hb-object-private.hh" - /* * hb_blob_t diff --git a/src/hb-blob.cc b/src/hb-blob.cc index b509093e0..5bab1abbe 100644 --- a/src/hb-blob.cc +++ b/src/hb-blob.cc @@ -31,7 +31,6 @@ #endif #include "hb-private.hh" -#include "hb-debug.hh" #include "hb-blob-private.hh" #ifdef HAVE_SYS_MMAN_H diff --git a/src/hb-buffer-private.hh b/src/hb-buffer-private.hh index dd6f1dcd3..f45814070 100644 --- a/src/hb-buffer-private.hh +++ b/src/hb-buffer-private.hh @@ -31,7 +31,6 @@ #define HB_BUFFER_PRIVATE_HH #include "hb-private.hh" -#include "hb-object-private.hh" #include "hb-unicode-private.hh" diff --git a/src/hb-common.cc b/src/hb-common.cc index ca2b32784..243c2163e 100644 --- a/src/hb-common.cc +++ b/src/hb-common.cc @@ -28,8 +28,6 @@ #include "hb-private.hh" -#include "hb-mutex-private.hh" -#include "hb-object-private.hh" #include #ifdef HAVE_XLOCALE_H diff --git a/src/hb-coretext.cc b/src/hb-coretext.cc index 61f9c35a1..3bdc3f784 100644 --- a/src/hb-coretext.cc +++ b/src/hb-coretext.cc @@ -29,7 +29,6 @@ #define HB_SHAPER coretext #include "hb-private.hh" -#include "hb-debug.hh" #include "hb-shaper-impl-private.hh" #include "hb-coretext.h" diff --git a/src/hb-directwrite.cc b/src/hb-directwrite.cc index 187ab3f9d..7c688494f 100644 --- a/src/hb-directwrite.cc +++ b/src/hb-directwrite.cc @@ -23,7 +23,6 @@ */ #include "hb-private.hh" -#include "hb-debug.hh" #define HB_SHAPER directwrite #include "hb-shaper-impl-private.hh" diff --git a/src/hb-face-private.hh b/src/hb-face-private.hh index 43e7b1cb3..fe3b8b240 100644 --- a/src/hb-face-private.hh +++ b/src/hb-face-private.hh @@ -31,7 +31,6 @@ #include "hb-private.hh" -#include "hb-object-private.hh" #include "hb-shaper-private.hh" #include "hb-shape-plan-private.hh" diff --git a/src/hb-font-private.hh b/src/hb-font-private.hh index 7ba16cdef..9f657db60 100644 --- a/src/hb-font-private.hh +++ b/src/hb-font-private.hh @@ -31,7 +31,6 @@ #include "hb-private.hh" -#include "hb-object-private.hh" #include "hb-face-private.hh" #include "hb-shaper-private.hh" diff --git a/src/hb-ft.cc b/src/hb-ft.cc index 7caafba83..6670d9a60 100644 --- a/src/hb-ft.cc +++ b/src/hb-ft.cc @@ -28,7 +28,6 @@ */ #include "hb-private.hh" -#include "hb-debug.hh" #include "hb-ft.h" diff --git a/src/hb-map-private.hh b/src/hb-map-private.hh index c4f2fc7da..00f089e81 100644 --- a/src/hb-map-private.hh +++ b/src/hb-map-private.hh @@ -28,7 +28,6 @@ #define HB_MAP_PRIVATE_HH #include "hb-private.hh" -#include "hb-object-private.hh" template diff --git a/src/hb-object-private.hh b/src/hb-object-private.hh index fc48a91b7..95847b9cc 100644 --- a/src/hb-object-private.hh +++ b/src/hb-object-private.hh @@ -33,10 +33,6 @@ #define HB_OBJECT_PRIVATE_HH #include "hb-private.hh" -#include "hb-debug.hh" - -#include "hb-atomic-private.hh" -#include "hb-mutex-private.hh" /* reference_count */ diff --git a/src/hb-open-type-private.hh b/src/hb-open-type-private.hh index 59b8cc02b..207f6e0e2 100644 --- a/src/hb-open-type-private.hh +++ b/src/hb-open-type-private.hh @@ -30,7 +30,6 @@ #define HB_OPEN_TYPE_PRIVATE_HH #include "hb-private.hh" -#include "hb-debug.hh" #include "hb-blob-private.hh" #include "hb-face-private.hh" diff --git a/src/hb-ot-layout-common-private.hh b/src/hb-ot-layout-common-private.hh index ff9c5650f..21a8382c3 100644 --- a/src/hb-ot-layout-common-private.hh +++ b/src/hb-ot-layout-common-private.hh @@ -30,7 +30,6 @@ #define HB_OT_LAYOUT_COMMON_PRIVATE_HH #include "hb-private.hh" -#include "hb-debug.hh" #include "hb-ot-layout-private.hh" #include "hb-open-type-private.hh" #include "hb-set-private.hh" diff --git a/src/hb-ot-layout-gsubgpos-private.hh b/src/hb-ot-layout-gsubgpos-private.hh index cbaa64880..aed00f151 100644 --- a/src/hb-ot-layout-gsubgpos-private.hh +++ b/src/hb-ot-layout-gsubgpos-private.hh @@ -30,7 +30,6 @@ #define HB_OT_LAYOUT_GSUBGPOS_PRIVATE_HH #include "hb-private.hh" -#include "hb-debug.hh" #include "hb-buffer-private.hh" #include "hb-map-private.hh" #include "hb-ot-layout-gdef-table.hh" diff --git a/src/hb-ot-shape-complex-arabic.cc b/src/hb-ot-shape-complex-arabic.cc index 124a67f32..b1cba1c71 100644 --- a/src/hb-ot-shape-complex-arabic.cc +++ b/src/hb-ot-shape-complex-arabic.cc @@ -25,7 +25,6 @@ */ #include "hb-private.hh" -#include "hb-debug.hh" #include "hb-ot-shape-complex-arabic-private.hh" #include "hb-ot-shape-private.hh" diff --git a/src/hb-private.hh b/src/hb-private.hh index fa9a1aee2..4201fe6ef 100644 --- a/src/hb-private.hh +++ b/src/hb-private.hh @@ -948,7 +948,11 @@ _hb_memalign(void **memptr, size_t alignment, size_t size) #endif +/* Headers we include for everyone. Specifically ordered to resolve dependencies. */ +#include "hb-debug.hh" +#include "hb-atomic-private.hh" +#include "hb-mutex-private.hh" #include "hb-dsalgs.hh" - +#include "hb-object-private.hh" #endif /* HB_PRIVATE_HH */ diff --git a/src/hb-set-private.hh b/src/hb-set-private.hh index bdaf3f1a2..032ddb1ee 100644 --- a/src/hb-set-private.hh +++ b/src/hb-set-private.hh @@ -28,7 +28,6 @@ #define HB_SET_PRIVATE_HH #include "hb-private.hh" -#include "hb-object-private.hh" /* diff --git a/src/hb-shape-plan-private.hh b/src/hb-shape-plan-private.hh index aa0413a27..c2c4987e5 100644 --- a/src/hb-shape-plan-private.hh +++ b/src/hb-shape-plan-private.hh @@ -28,7 +28,6 @@ #define HB_SHAPE_PLAN_PRIVATE_HH #include "hb-private.hh" -#include "hb-object-private.hh" #include "hb-shaper-private.hh" diff --git a/src/hb-shape-plan.cc b/src/hb-shape-plan.cc index 6eeba2b3d..37ff1a6e6 100644 --- a/src/hb-shape-plan.cc +++ b/src/hb-shape-plan.cc @@ -25,7 +25,6 @@ */ #include "hb-private.hh" -#include "hb-debug.hh" #include "hb-shape-plan-private.hh" #include "hb-shaper-private.hh" #include "hb-font-private.hh" diff --git a/src/hb-subset-input.cc b/src/hb-subset-input.cc index 39c5ac4f2..74470fd1f 100644 --- a/src/hb-subset-input.cc +++ b/src/hb-subset-input.cc @@ -24,7 +24,6 @@ * Google Author(s): Garret Rieger, Rod Sheeter, Behdad Esfahbod */ -#include "hb-object-private.hh" #include "hb-subset-private.hh" #include "hb-set-private.hh" diff --git a/src/hb-subset-plan.hh b/src/hb-subset-plan.hh index f4b261df0..7501294d7 100644 --- a/src/hb-subset-plan.hh +++ b/src/hb-subset-plan.hh @@ -32,7 +32,6 @@ #include "hb-subset.h" #include "hb-subset-private.hh" -#include "hb-object-private.hh" #include "hb-map-private.hh" struct hb_subset_plan_t diff --git a/src/hb-subset.cc b/src/hb-subset.cc index e86063418..a65b58d26 100644 --- a/src/hb-subset.cc +++ b/src/hb-subset.cc @@ -25,7 +25,6 @@ */ #include "hb-private.hh" -#include "hb-object-private.hh" #include "hb-open-type-private.hh" #include "hb-subset-glyf.hh" diff --git a/src/hb-unicode-private.hh b/src/hb-unicode-private.hh index 5472ece2f..b2c203d26 100644 --- a/src/hb-unicode-private.hh +++ b/src/hb-unicode-private.hh @@ -32,7 +32,6 @@ #define HB_UNICODE_PRIVATE_HH #include "hb-private.hh" -#include "hb-object-private.hh" extern HB_INTERNAL const uint8_t _hb_modified_combining_class[256]; diff --git a/src/hb-uniscribe.cc b/src/hb-uniscribe.cc index 6d6afe80a..b17fa31ca 100644 --- a/src/hb-uniscribe.cc +++ b/src/hb-uniscribe.cc @@ -25,7 +25,6 @@ */ #include "hb-private.hh" -#include "hb-debug.hh" #define HB_SHAPER uniscribe #include "hb-shaper-impl-private.hh" diff --git a/src/hb-warning.cc b/src/hb-warning.cc index 8f322bcb1..f7a87b5ab 100644 --- a/src/hb-warning.cc +++ b/src/hb-warning.cc @@ -24,9 +24,7 @@ * Google Author(s): Behdad Esfahbod */ -#include "hb-atomic-private.hh" -#include "hb-mutex-private.hh" - +#include "hb-private.hh" #if defined(HB_ATOMIC_INT_NIL) #error "Could not find any system to define atomic_int macros, library WILL NOT be thread-safe" From 7a00f7eb2e3859db4563071934e76142bfd13916 Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Tue, 10 Jul 2018 14:42:10 +0200 Subject: [PATCH 049/106] Remove hb_auto_array_t --- src/hb-dsalgs.hh | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/hb-dsalgs.hh b/src/hb-dsalgs.hh index ef48fb081..e8fa9b3c7 100644 --- a/src/hb-dsalgs.hh +++ b/src/hb-dsalgs.hh @@ -424,8 +424,6 @@ struct hb_auto_t : Type void init (void) {} void fini (void) {} }; -template -struct hb_auto_array_t : hb_auto_t > {}; #define HB_LOCKABLE_SET_INIT {HB_VECTOR_INIT} From be7f664f723fb4e7bcf15c1c2b7c6bec46f90393 Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Tue, 10 Jul 2018 15:23:08 +0200 Subject: [PATCH 050/106] Move hb_bytes_t to hb-dsalgs.hh --- src/hb-dsalgs.hh | 45 ++++++++++++++++++++++++++++++++++----------- src/hb-private.hh | 26 -------------------------- 2 files changed, 34 insertions(+), 37 deletions(-) diff --git a/src/hb-dsalgs.hh b/src/hb-dsalgs.hh index e8fa9b3c7..4eceeb2fb 100644 --- a/src/hb-dsalgs.hh +++ b/src/hb-dsalgs.hh @@ -53,7 +53,6 @@ hb_bsearch_r (const void *key, const void *base, } - /* From https://github.com/noporpoise/sort_r */ /* Isaac Turner 29 April 2014 Public Domain */ @@ -415,16 +414,6 @@ struct hb_vector_t } }; -template -struct hb_auto_t : Type -{ - hb_auto_t (void) { Type::init (); } - ~hb_auto_t (void) { Type::fini (); } - private: /* Hide */ - void init (void) {} - void fini (void) {} -}; - #define HB_LOCKABLE_SET_INIT {HB_VECTOR_INIT} template @@ -518,4 +507,38 @@ struct hb_lockable_set_t }; +template +struct hb_auto_t : Type +{ + hb_auto_t (void) { Type::init (); } + ~hb_auto_t (void) { Type::fini (); } + private: /* Hide */ + void init (void) {} + void fini (void) {} +}; + +struct hb_bytes_t +{ + inline hb_bytes_t (void) : bytes (nullptr), len (0) {} + inline hb_bytes_t (const char *bytes_, unsigned int len_) : bytes (bytes_), len (len_) {} + + inline int cmp (const hb_bytes_t &a) const + { + if (len != a.len) + return (int) a.len - (int) len; + + return memcmp (a.bytes, bytes, len); + } + static inline int cmp (const void *pa, const void *pb) + { + hb_bytes_t *a = (hb_bytes_t *) pa; + hb_bytes_t *b = (hb_bytes_t *) pb; + return b->cmp (*a); + } + + const char *bytes; + unsigned int len; +}; + + #endif /* HB_DSALGS_HH */ diff --git a/src/hb-private.hh b/src/hb-private.hh index 4201fe6ef..aa4d017c9 100644 --- a/src/hb-private.hh +++ b/src/hb-private.hh @@ -882,32 +882,6 @@ hb_options (void) #define VAR 1 -/* String type. */ - -struct hb_bytes_t -{ - inline hb_bytes_t (void) : bytes (nullptr), len (0) {} - inline hb_bytes_t (const char *bytes_, unsigned int len_) : bytes (bytes_), len (len_) {} - - inline int cmp (const hb_bytes_t &a) const - { - if (len != a.len) - return (int) a.len - (int) len; - - return memcmp (a.bytes, bytes, len); - } - static inline int cmp (const void *pa, const void *pb) - { - hb_bytes_t *a = (hb_bytes_t *) pa; - hb_bytes_t *b = (hb_bytes_t *) pb; - return b->cmp (*a); - } - - const char *bytes; - unsigned int len; -}; - - /* fallback for round() */ static inline double _hb_round (double x) From f477765661c196ac17b2c86731881a3da36a5ae6 Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Tue, 10 Jul 2018 15:49:05 +0200 Subject: [PATCH 051/106] Move more stuff to hb-dsalgs.hh --- src/hb-dsalgs.hh | 83 +++++++++++++++++++++++++++++++++++++++++++++++ src/hb-private.hh | 81 --------------------------------------------- 2 files changed, 83 insertions(+), 81 deletions(-) diff --git a/src/hb-dsalgs.hh b/src/hb-dsalgs.hh index 4eceeb2fb..60cb0023d 100644 --- a/src/hb-dsalgs.hh +++ b/src/hb-dsalgs.hh @@ -541,4 +541,87 @@ struct hb_bytes_t }; +struct HbOpOr +{ + static const bool passthru_left = true; + static const bool passthru_right = true; + template static void process (T &o, const T &a, const T &b) { o = a | b; } +}; +struct HbOpAnd +{ + static const bool passthru_left = false; + static const bool passthru_right = false; + template static void process (T &o, const T &a, const T &b) { o = a & b; } +}; +struct HbOpMinus +{ + static const bool passthru_left = true; + static const bool passthru_right = false; + template static void process (T &o, const T &a, const T &b) { o = a & ~b; } +}; +struct HbOpXor +{ + static const bool passthru_left = true; + static const bool passthru_right = true; + template static void process (T &o, const T &a, const T &b) { o = a ^ b; } +}; + + +/* Compiler-assisted vectorization. */ + +/* Type behaving similar to vectorized vars defined using __attribute__((vector_size(...))), + * using vectorized operations if HB_VECTOR_SIZE is set to **bit** numbers (eg 128). + * Define that to 0 to disable. */ +template +struct hb_vector_size_t +{ + elt_t& operator [] (unsigned int i) { return u.v[i]; } + const elt_t& operator [] (unsigned int i) const { return u.v[i]; } + + template + inline hb_vector_size_t process (const hb_vector_size_t &o) const + { + hb_vector_size_t r; +#if HB_VECTOR_SIZE + if (HB_VECTOR_SIZE && 0 == (byte_size * 8) % HB_VECTOR_SIZE) + for (unsigned int i = 0; i < ARRAY_LENGTH (u.vec); i++) + Op::process (r.u.vec[i], u.vec[i], o.u.vec[i]); + else +#endif + for (unsigned int i = 0; i < ARRAY_LENGTH (u.v); i++) + Op::process (r.u.v[i], u.v[i], o.u.v[i]); + return r; + } + inline hb_vector_size_t operator | (const hb_vector_size_t &o) const + { return process (o); } + inline hb_vector_size_t operator & (const hb_vector_size_t &o) const + { return process (o); } + inline hb_vector_size_t operator ^ (const hb_vector_size_t &o) const + { return process (o); } + inline hb_vector_size_t operator ~ () const + { + hb_vector_size_t r; +#if HB_VECTOR_SIZE && 0 + if (HB_VECTOR_SIZE && 0 == (byte_size * 8) % HB_VECTOR_SIZE) + for (unsigned int i = 0; i < ARRAY_LENGTH (u.vec); i++) + r.u.vec[i] = ~u.vec[i]; + else +#endif + for (unsigned int i = 0; i < ARRAY_LENGTH (u.v); i++) + r.u.v[i] = ~u.v[i]; + return r; + } + + private: + static_assert (byte_size / sizeof (elt_t) * sizeof (elt_t) == byte_size, ""); + union { + elt_t v[byte_size / sizeof (elt_t)]; +#if HB_VECTOR_SIZE + typedef unsigned long vec_t __attribute__((vector_size (HB_VECTOR_SIZE / 8))); + vec_t vec[byte_size / sizeof (vec_t)]; +#endif + } u; +}; + + #endif /* HB_DSALGS_HH */ diff --git a/src/hb-private.hh b/src/hb-private.hh index aa4d017c9..61a13215f 100644 --- a/src/hb-private.hh +++ b/src/hb-private.hh @@ -746,34 +746,6 @@ hb_in_ranges (T u, T lo1, T hi1, T lo2, T hi2, T lo3, T hi3) -/* Vectorization */ - -struct HbOpOr -{ - static const bool passthru_left = true; - static const bool passthru_right = true; - template static void process (T &o, const T &a, const T &b) { o = a | b; } -}; -struct HbOpAnd -{ - static const bool passthru_left = false; - static const bool passthru_right = false; - template static void process (T &o, const T &a, const T &b) { o = a & b; } -}; -struct HbOpMinus -{ - static const bool passthru_left = true; - static const bool passthru_right = false; - template static void process (T &o, const T &a, const T &b) { o = a & ~b; } -}; -struct HbOpXor -{ - static const bool passthru_left = true; - static const bool passthru_right = true; - template static void process (T &o, const T &a, const T &b) { o = a ^ b; } -}; - - /* Compiler-assisted vectorization. */ /* @@ -787,7 +759,6 @@ struct HbOpXor # define HB_VECTOR_SIZE 0 #endif - /* The `vector_size' attribute was introduced in gcc 3.1. */ #if !defined(HB_VECTOR_SIZE) # if defined( __GNUC__ ) && ( __GNUC__ >= 4 ) @@ -797,58 +768,6 @@ struct HbOpXor # endif #endif -/* Type behaving similar to vectorized vars defined using __attribute__((vector_size(...))). */ -template -struct hb_vector_size_t -{ - elt_t& operator [] (unsigned int i) { return u.v[i]; } - const elt_t& operator [] (unsigned int i) const { return u.v[i]; } - - template - inline hb_vector_size_t process (const hb_vector_size_t &o) const - { - hb_vector_size_t r; -#if HB_VECTOR_SIZE - if (HB_VECTOR_SIZE && 0 == (byte_size * 8) % HB_VECTOR_SIZE) - for (unsigned int i = 0; i < ARRAY_LENGTH (u.vec); i++) - Op::process (r.u.vec[i], u.vec[i], o.u.vec[i]); - else -#endif - for (unsigned int i = 0; i < ARRAY_LENGTH (u.v); i++) - Op::process (r.u.v[i], u.v[i], o.u.v[i]); - return r; - } - inline hb_vector_size_t operator | (const hb_vector_size_t &o) const - { return process (o); } - inline hb_vector_size_t operator & (const hb_vector_size_t &o) const - { return process (o); } - inline hb_vector_size_t operator ^ (const hb_vector_size_t &o) const - { return process (o); } - inline hb_vector_size_t operator ~ () const - { - hb_vector_size_t r; -#if HB_VECTOR_SIZE && 0 - if (HB_VECTOR_SIZE && 0 == (byte_size * 8) % HB_VECTOR_SIZE) - for (unsigned int i = 0; i < ARRAY_LENGTH (u.vec); i++) - r.u.vec[i] = ~u.vec[i]; - else -#endif - for (unsigned int i = 0; i < ARRAY_LENGTH (u.v); i++) - r.u.v[i] = ~u.v[i]; - return r; - } - - private: - static_assert (byte_size / sizeof (elt_t) * sizeof (elt_t) == byte_size, ""); - union { - elt_t v[byte_size / sizeof (elt_t)]; -#if HB_VECTOR_SIZE - typedef unsigned long vec_t __attribute__((vector_size (HB_VECTOR_SIZE / 8))); - vec_t vec[byte_size / sizeof (vec_t)]; -#endif - } u; -}; - /* Global runtime options. */ From 491d93bf74dd0483715ecca430715b69664e1211 Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Tue, 10 Jul 2018 16:03:31 +0200 Subject: [PATCH 052/106] Move more stuff from hb-private.hh to hb-dsalgs.hh --- src/hb-debug.hh | 1 + src/hb-dsalgs.hh | 237 ++++++++++++++++++++++++++++++++++++++++++++ src/hb-private.hh | 246 +--------------------------------------------- 3 files changed, 240 insertions(+), 244 deletions(-) diff --git a/src/hb-debug.hh b/src/hb-debug.hh index c244347b3..ae0b6774d 100644 --- a/src/hb-debug.hh +++ b/src/hb-debug.hh @@ -28,6 +28,7 @@ #define HB_DEBUG_HH #include "hb-private.hh" +#include "hb-dsalgs.hh" #ifndef HB_DEBUG diff --git a/src/hb-dsalgs.hh b/src/hb-dsalgs.hh index 60cb0023d..4d3db9663 100644 --- a/src/hb-dsalgs.hh +++ b/src/hb-dsalgs.hh @@ -30,6 +30,243 @@ #include "hb-private.hh" +/* Void! For when we need a expression-type of void. */ +typedef const struct _hb_void_t *hb_void_t; +#define HB_VOID ((const _hb_void_t *) nullptr) + + +/* + * Bithacks. + */ + +/* Return the number of 1 bits in v. */ +template +static inline HB_CONST_FUNC unsigned int +hb_popcount (T v) +{ +#if (__GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4)) && defined(__OPTIMIZE__) + if (sizeof (T) <= sizeof (unsigned int)) + return __builtin_popcount (v); + + if (sizeof (T) <= sizeof (unsigned long)) + return __builtin_popcountl (v); + + if (sizeof (T) <= sizeof (unsigned long long)) + return __builtin_popcountll (v); +#endif + + if (sizeof (T) <= 4) + { + /* "HACKMEM 169" */ + uint32_t y; + y = (v >> 1) &033333333333; + y = v - y - ((y >>1) & 033333333333); + return (((y + (y >> 3)) & 030707070707) % 077); + } + + if (sizeof (T) == 8) + { + unsigned int shift = 32; + return hb_popcount ((uint32_t) v) + hb_popcount ((uint32_t) (v >> shift)); + } + + if (sizeof (T) == 16) + { + unsigned int shift = 64; + return hb_popcount ((uint64_t) v) + hb_popcount ((uint64_t) (v >> shift)); + } + + assert (0); + return 0; /* Shut up stupid compiler. */ +} + +/* Returns the number of bits needed to store number */ +template +static inline HB_CONST_FUNC unsigned int +hb_bit_storage (T v) +{ + if (unlikely (!v)) return 0; + +#if defined(__GNUC__) && (__GNUC__ >= 4) && defined(__OPTIMIZE__) + if (sizeof (T) <= sizeof (unsigned int)) + return sizeof (unsigned int) * 8 - __builtin_clz (v); + + if (sizeof (T) <= sizeof (unsigned long)) + return sizeof (unsigned long) * 8 - __builtin_clzl (v); + + if (sizeof (T) <= sizeof (unsigned long long)) + return sizeof (unsigned long long) * 8 - __builtin_clzll (v); +#endif + +#if (defined(_MSC_VER) && _MSC_VER >= 1500) || defined(__MINGW32__) + if (sizeof (T) <= sizeof (unsigned int)) + { + unsigned long where; + _BitScanReverse (&where, v); + return 1 + where; + } +# if _WIN64 + if (sizeof (T) <= 8) + { + unsigned long where; + _BitScanReverse64 (&where, v); + return 1 + where; + } +# endif +#endif + + if (sizeof (T) <= 4) + { + /* "bithacks" */ + const unsigned int b[] = {0x2, 0xC, 0xF0, 0xFF00, 0xFFFF0000}; + const unsigned int S[] = {1, 2, 4, 8, 16}; + unsigned int r = 0; + for (int i = 4; i >= 0; i--) + if (v & b[i]) + { + v >>= S[i]; + r |= S[i]; + } + return r + 1; + } + if (sizeof (T) <= 8) + { + /* "bithacks" */ + const uint64_t b[] = {0x2ULL, 0xCULL, 0xF0ULL, 0xFF00ULL, 0xFFFF0000ULL, 0xFFFFFFFF00000000ULL}; + const unsigned int S[] = {1, 2, 4, 8, 16, 32}; + unsigned int r = 0; + for (int i = 5; i >= 0; i--) + if (v & b[i]) + { + v >>= S[i]; + r |= S[i]; + } + return r + 1; + } + if (sizeof (T) == 16) + { + unsigned int shift = 64; + return (v >> shift) ? hb_bit_storage ((uint64_t) (v >> shift)) + shift : + hb_bit_storage ((uint64_t) v); + } + + assert (0); + return 0; /* Shut up stupid compiler. */ +} + +/* Returns the number of zero bits in the least significant side of v */ +template +static inline HB_CONST_FUNC unsigned int +hb_ctz (T v) +{ + if (unlikely (!v)) return 0; + +#if defined(__GNUC__) && (__GNUC__ >= 4) && defined(__OPTIMIZE__) + if (sizeof (T) <= sizeof (unsigned int)) + return __builtin_ctz (v); + + if (sizeof (T) <= sizeof (unsigned long)) + return __builtin_ctzl (v); + + if (sizeof (T) <= sizeof (unsigned long long)) + return __builtin_ctzll (v); +#endif + +#if (defined(_MSC_VER) && _MSC_VER >= 1500) || defined(__MINGW32__) + if (sizeof (T) <= sizeof (unsigned int)) + { + unsigned long where; + _BitScanForward (&where, v); + return where; + } +# if _WIN64 + if (sizeof (T) <= 8) + { + unsigned long where; + _BitScanForward64 (&where, v); + return where; + } +# endif +#endif + + if (sizeof (T) <= 4) + { + /* "bithacks" */ + unsigned int c = 32; + v &= - (int32_t) v; + if (v) c--; + if (v & 0x0000FFFF) c -= 16; + if (v & 0x00FF00FF) c -= 8; + if (v & 0x0F0F0F0F) c -= 4; + if (v & 0x33333333) c -= 2; + if (v & 0x55555555) c -= 1; + return c; + } + if (sizeof (T) <= 8) + { + /* "bithacks" */ + unsigned int c = 64; + v &= - (int64_t) (v); + if (v) c--; + if (v & 0x00000000FFFFFFFFULL) c -= 32; + if (v & 0x0000FFFF0000FFFFULL) c -= 16; + if (v & 0x00FF00FF00FF00FFULL) c -= 8; + if (v & 0x0F0F0F0F0F0F0F0FULL) c -= 4; + if (v & 0x3333333333333333ULL) c -= 2; + if (v & 0x5555555555555555ULL) c -= 1; + return c; + } + if (sizeof (T) == 16) + { + unsigned int shift = 64; + return (uint64_t) v ? hb_bit_storage ((uint64_t) v) : + hb_bit_storage ((uint64_t) v >> shift) + shift; + } + + assert (0); + return 0; /* Shut up stupid compiler. */ +} + + +/* + * Tiny stuff. + */ + +#undef MIN +template +static inline Type MIN (const Type &a, const Type &b) { return a < b ? a : b; } + +#undef MAX +template +static inline Type MAX (const Type &a, const Type &b) { return a > b ? a : b; } + +static inline unsigned int DIV_CEIL (const unsigned int a, unsigned int b) +{ return (a + (b - 1)) / b; } + + +#undef ARRAY_LENGTH +template +static inline unsigned int ARRAY_LENGTH (const Type (&)[n]) { return n; } +/* A const version, but does not detect erratically being called on pointers. */ +#define ARRAY_LENGTH_CONST(__array) ((signed int) (sizeof (__array) / sizeof (__array[0]))) + +static inline bool +hb_unsigned_mul_overflows (unsigned int count, unsigned int size) +{ + return (size > 0) && (count >= ((unsigned int) -1) / size); +} + +static inline unsigned int +hb_ceil_to_4 (unsigned int v) +{ + return ((v - 1) | 3) + 1; +} + + +/* + * Sort and search. + */ + static inline void * hb_bsearch_r (const void *key, const void *base, size_t nmemb, size_t size, diff --git a/src/hb-private.hh b/src/hb-private.hh index 61a13215f..3520919fe 100644 --- a/src/hb-private.hh +++ b/src/hb-private.hh @@ -279,26 +279,6 @@ static int errno = 0; /* Use something better? */ # undef HB_USE_ATEXIT #endif -/* Basics */ - -#undef MIN -template -static inline Type MIN (const Type &a, const Type &b) { return a < b ? a : b; } - -#undef MAX -template -static inline Type MAX (const Type &a, const Type &b) { return a > b ? a : b; } - -static inline unsigned int DIV_CEIL (const unsigned int a, unsigned int b) -{ return (a + (b - 1)) / b; } - - -#undef ARRAY_LENGTH -template -static inline unsigned int ARRAY_LENGTH (const Type (&)[n]) { return n; } -/* A const version, but does not detect erratically being called on pointers. */ -#define ARRAY_LENGTH_CONST(__array) ((signed int) (sizeof (__array) / sizeof (__array[0]))) - #define HB_STMT_START do #define HB_STMT_END while (0) @@ -350,228 +330,6 @@ static_assert ((sizeof (hb_var_int_t) == 4), ""); # define ASSERT_POD() _ASSERT_POD0 (__LINE__) - -/* Tiny functions */ - -/* - * Void! - */ -typedef const struct _hb_void_t *hb_void_t; -#define HB_VOID ((const _hb_void_t *) nullptr) - -/* Return the number of 1 bits in v. */ -template -static inline HB_CONST_FUNC unsigned int -hb_popcount (T v) -{ -#if (__GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4)) && defined(__OPTIMIZE__) - if (sizeof (T) <= sizeof (unsigned int)) - return __builtin_popcount (v); - - if (sizeof (T) <= sizeof (unsigned long)) - return __builtin_popcountl (v); - - if (sizeof (T) <= sizeof (unsigned long long)) - return __builtin_popcountll (v); -#endif - - if (sizeof (T) <= 4) - { - /* "HACKMEM 169" */ - uint32_t y; - y = (v >> 1) &033333333333; - y = v - y - ((y >>1) & 033333333333); - return (((y + (y >> 3)) & 030707070707) % 077); - } - - if (sizeof (T) == 8) - { - unsigned int shift = 32; - return hb_popcount ((uint32_t) v) + hb_popcount ((uint32_t) (v >> shift)); - } - - if (sizeof (T) == 16) - { - unsigned int shift = 64; - return hb_popcount ((uint64_t) v) + hb_popcount ((uint64_t) (v >> shift)); - } - - assert (0); - return 0; /* Shut up stupid compiler. */ -} - -/* Returns the number of bits needed to store number */ -template -static inline HB_CONST_FUNC unsigned int -hb_bit_storage (T v) -{ - if (unlikely (!v)) return 0; - -#if defined(__GNUC__) && (__GNUC__ >= 4) && defined(__OPTIMIZE__) - if (sizeof (T) <= sizeof (unsigned int)) - return sizeof (unsigned int) * 8 - __builtin_clz (v); - - if (sizeof (T) <= sizeof (unsigned long)) - return sizeof (unsigned long) * 8 - __builtin_clzl (v); - - if (sizeof (T) <= sizeof (unsigned long long)) - return sizeof (unsigned long long) * 8 - __builtin_clzll (v); -#endif - -#if (defined(_MSC_VER) && _MSC_VER >= 1500) || defined(__MINGW32__) - if (sizeof (T) <= sizeof (unsigned int)) - { - unsigned long where; - _BitScanReverse (&where, v); - return 1 + where; - } -# if _WIN64 - if (sizeof (T) <= 8) - { - unsigned long where; - _BitScanReverse64 (&where, v); - return 1 + where; - } -# endif -#endif - - if (sizeof (T) <= 4) - { - /* "bithacks" */ - const unsigned int b[] = {0x2, 0xC, 0xF0, 0xFF00, 0xFFFF0000}; - const unsigned int S[] = {1, 2, 4, 8, 16}; - unsigned int r = 0; - for (int i = 4; i >= 0; i--) - if (v & b[i]) - { - v >>= S[i]; - r |= S[i]; - } - return r + 1; - } - if (sizeof (T) <= 8) - { - /* "bithacks" */ - const uint64_t b[] = {0x2ULL, 0xCULL, 0xF0ULL, 0xFF00ULL, 0xFFFF0000ULL, 0xFFFFFFFF00000000ULL}; - const unsigned int S[] = {1, 2, 4, 8, 16, 32}; - unsigned int r = 0; - for (int i = 5; i >= 0; i--) - if (v & b[i]) - { - v >>= S[i]; - r |= S[i]; - } - return r + 1; - } - if (sizeof (T) == 16) - { - unsigned int shift = 64; - return (v >> shift) ? hb_bit_storage ((uint64_t) (v >> shift)) + shift : - hb_bit_storage ((uint64_t) v); - } - - assert (0); - return 0; /* Shut up stupid compiler. */ -} - -/* Returns the number of zero bits in the least significant side of v */ -template -static inline HB_CONST_FUNC unsigned int -hb_ctz (T v) -{ - if (unlikely (!v)) return 0; - -#if defined(__GNUC__) && (__GNUC__ >= 4) && defined(__OPTIMIZE__) - if (sizeof (T) <= sizeof (unsigned int)) - return __builtin_ctz (v); - - if (sizeof (T) <= sizeof (unsigned long)) - return __builtin_ctzl (v); - - if (sizeof (T) <= sizeof (unsigned long long)) - return __builtin_ctzll (v); -#endif - -#if (defined(_MSC_VER) && _MSC_VER >= 1500) || defined(__MINGW32__) - if (sizeof (T) <= sizeof (unsigned int)) - { - unsigned long where; - _BitScanForward (&where, v); - return where; - } -# if _WIN64 - if (sizeof (T) <= 8) - { - unsigned long where; - _BitScanForward64 (&where, v); - return where; - } -# endif -#endif - - if (sizeof (T) <= 4) - { - /* "bithacks" */ - unsigned int c = 32; - v &= - (int32_t) v; - if (v) c--; - if (v & 0x0000FFFF) c -= 16; - if (v & 0x00FF00FF) c -= 8; - if (v & 0x0F0F0F0F) c -= 4; - if (v & 0x33333333) c -= 2; - if (v & 0x55555555) c -= 1; - return c; - } - if (sizeof (T) <= 8) - { - /* "bithacks" */ - unsigned int c = 64; - v &= - (int64_t) (v); - if (v) c--; - if (v & 0x00000000FFFFFFFFULL) c -= 32; - if (v & 0x0000FFFF0000FFFFULL) c -= 16; - if (v & 0x00FF00FF00FF00FFULL) c -= 8; - if (v & 0x0F0F0F0F0F0F0F0FULL) c -= 4; - if (v & 0x3333333333333333ULL) c -= 2; - if (v & 0x5555555555555555ULL) c -= 1; - return c; - } - if (sizeof (T) == 16) - { - unsigned int shift = 64; - return (uint64_t) v ? hb_bit_storage ((uint64_t) v) : - hb_bit_storage ((uint64_t) v >> shift) + shift; - } - - assert (0); - return 0; /* Shut up stupid compiler. */ -} - -static inline bool -hb_unsigned_mul_overflows (unsigned int count, unsigned int size) -{ - return (size > 0) && (count >= ((unsigned int) -1) / size); -} - -static inline unsigned int -hb_ceil_to_4 (unsigned int v) -{ - return ((v - 1) | 3) + 1; -} - -static inline bool -hb_ispow2 (unsigned int v) -{ - return 0 == (v & (v - 1)); -} - - -/* - * - * Utility types - * - */ - #define HB_DISALLOW_COPY_AND_ASSIGN(TypeName) \ TypeName(const TypeName&); \ void operator=(const TypeName&) @@ -819,7 +577,7 @@ _hb_round (double x) static inline int _hb_memalign(void **memptr, size_t alignment, size_t size) { - if (unlikely (!hb_ispow2 (alignment) || + if (unlikely (0 != (alignment & (alignment - 1)) || !alignment || 0 != (alignment & (sizeof (void *) - 1)))) return EINVAL; @@ -842,10 +600,10 @@ _hb_memalign(void **memptr, size_t alignment, size_t size) /* Headers we include for everyone. Specifically ordered to resolve dependencies. */ -#include "hb-debug.hh" #include "hb-atomic-private.hh" #include "hb-mutex-private.hh" #include "hb-dsalgs.hh" +#include "hb-debug.hh" #include "hb-object-private.hh" #endif /* HB_PRIVATE_HH */ From 25aa411ac524ed08624033da473a5e050ff41633 Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Tue, 10 Jul 2018 16:05:03 +0200 Subject: [PATCH 053/106] Put back include dependencies --- src/hb-object-private.hh | 2 ++ src/hb-private.hh | 7 ++++--- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/src/hb-object-private.hh b/src/hb-object-private.hh index 95847b9cc..fcdc9256d 100644 --- a/src/hb-object-private.hh +++ b/src/hb-object-private.hh @@ -33,6 +33,8 @@ #define HB_OBJECT_PRIVATE_HH #include "hb-private.hh" +#include "hb-atomic-private.hh" +#include "hb-mutex-private.hh" /* reference_count */ diff --git a/src/hb-private.hh b/src/hb-private.hh index 3520919fe..ff339df4d 100644 --- a/src/hb-private.hh +++ b/src/hb-private.hh @@ -599,11 +599,12 @@ _hb_memalign(void **memptr, size_t alignment, size_t size) #endif -/* Headers we include for everyone. Specifically ordered to resolve dependencies. */ +/* Headers we include for everyone. Keep sorted. They express dependency amongst + * themselves, but no other file should include them.*/ #include "hb-atomic-private.hh" -#include "hb-mutex-private.hh" -#include "hb-dsalgs.hh" #include "hb-debug.hh" +#include "hb-dsalgs.hh" +#include "hb-mutex-private.hh" #include "hb-object-private.hh" #endif /* HB_PRIVATE_HH */ From 718dfd4189275b1e4233dc7c12ab457352fccfcb Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Tue, 10 Jul 2018 16:34:31 +0200 Subject: [PATCH 054/106] Fix shift --- src/hb-dsalgs.hh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/hb-dsalgs.hh b/src/hb-dsalgs.hh index 4d3db9663..6a8ddaa99 100644 --- a/src/hb-dsalgs.hh +++ b/src/hb-dsalgs.hh @@ -220,7 +220,7 @@ hb_ctz (T v) { unsigned int shift = 64; return (uint64_t) v ? hb_bit_storage ((uint64_t) v) : - hb_bit_storage ((uint64_t) v >> shift) + shift; + hb_bit_storage ((uint64_t) (v >> shift)) + shift; } assert (0); From 2b76767bf572364d3d647cdd139f2044a7ad06b2 Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Wed, 11 Jul 2018 15:27:13 +0200 Subject: [PATCH 055/106] 1.8.3 --- NEWS | 8 ++++++++ configure.ac | 2 +- src/hb-version.h | 4 ++-- 3 files changed, 11 insertions(+), 3 deletions(-) diff --git a/NEWS b/NEWS index c4fad25a9..9031766db 100644 --- a/NEWS +++ b/NEWS @@ -1,3 +1,11 @@ +Overview of changes leading to 1.8.3 +Wednesday, July 11, 2018 +==================================== +- A couple of Indic / USE bug fixes. +- Disable vectorization, as it was causing unaligned access bus error on + certain 32bit architectures. + + Overview of changes leading to 1.8.2 Tuesday, July 3, 2018 ==================================== diff --git a/configure.ac b/configure.ac index 35de036b1..b6fcfc02a 100644 --- a/configure.ac +++ b/configure.ac @@ -1,6 +1,6 @@ AC_PREREQ([2.64]) AC_INIT([HarfBuzz], - [1.8.2], + [1.8.3], [https://github.com/harfbuzz/harfbuzz/issues/new], [harfbuzz], [http://harfbuzz.org/]) diff --git a/src/hb-version.h b/src/hb-version.h index 7f2e9dd72..c3c38de7b 100644 --- a/src/hb-version.h +++ b/src/hb-version.h @@ -38,9 +38,9 @@ HB_BEGIN_DECLS #define HB_VERSION_MAJOR 1 #define HB_VERSION_MINOR 8 -#define HB_VERSION_MICRO 2 +#define HB_VERSION_MICRO 3 -#define HB_VERSION_STRING "1.8.2" +#define HB_VERSION_STRING "1.8.3" #define HB_VERSION_ATLEAST(major,minor,micro) \ ((major)*10000+(minor)*100+(micro) <= \ From 7796857c93b779e3c93eedd1cceb217d691dfd81 Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Wed, 11 Jul 2018 15:27:37 +0200 Subject: [PATCH 056/106] Minor --- RELEASING.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/RELEASING.md b/RELEASING.md index 0aef610b6..c57f8466a 100644 --- a/RELEASING.md +++ b/RELEASING.md @@ -29,7 +29,7 @@ HarfBuzz release walk-through checklist: 7. "make release-files". Enter your GPG password. This creates a sha256 hash and signs it. -8. Now that you have release files built, commit NEWS and configure.ac changes, +8. Now that you have release files, commit NEWS, configure.ac, and src/hb-version.h, as well as any REPLACEME changes you made. The commit message is simply the release number. Eg. "1.4.7" From 58cb4d9f73f1292454e3673d5e7ae5a58a566522 Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Wed, 11 Jul 2018 16:44:21 +0200 Subject: [PATCH 057/106] Minor --- test/api/test-ot-math.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/api/test-ot-math.c b/test/api/test-ot-math.c index 0ca5566df..d071c8895 100644 --- a/test/api/test-ot-math.c +++ b/test/api/test-ot-math.c @@ -396,8 +396,8 @@ test_get_min_connector_overlap (void) initFreeType(); openFont("fonts/MathTestFontEmpty.otf"); - g_assert_cmpint(hb_ot_math_get_min_connector_overlap(hb_font, FALSE), ==, 0); // MathVariants not available - g_assert_cmpint(hb_ot_math_get_min_connector_overlap(hb_font, TRUE), ==, 0); // MathVariants not available + g_assert_cmpint(hb_ot_math_get_min_connector_overlap(hb_font, HB_DIRECTION_LTR), ==, 0); // MathVariants not available + g_assert_cmpint(hb_ot_math_get_min_connector_overlap(hb_font, HB_DIRECTION_TTB), ==, 0); // MathVariants not available closeFont(); openFont("fonts/MathTestFontPartial1.otf"); From 20a318d06acaabdee0090339dfa621aab46f1441 Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Wed, 11 Jul 2018 17:00:13 +0200 Subject: [PATCH 058/106] Fix return type of alignof() fallback --- src/hb-private.hh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/hb-private.hh b/src/hb-private.hh index ff339df4d..ae7338724 100644 --- a/src/hb-private.hh +++ b/src/hb-private.hh @@ -95,7 +95,7 @@ struct _hb_alignof char c; T t; }; - static constexpr unsigned int value = offsetof (s, t); + static constexpr size_t value = offsetof (s, t); }; #if __cplusplus < 201103L From 44999f8b758374015f5d48c83f9adcb464607c2f Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Wed, 11 Jul 2018 17:00:59 +0200 Subject: [PATCH 059/106] Align NullPool and CrapPool to HB_VECTOR_SIZE --- src/hb-dsalgs.hh | 3 +-- src/hb-private.hh | 64 +++++++++++++++++++++++++++-------------------- src/hb-static.cc | 4 +-- 3 files changed, 40 insertions(+), 31 deletions(-) diff --git a/src/hb-dsalgs.hh b/src/hb-dsalgs.hh index 6a8ddaa99..953310bcd 100644 --- a/src/hb-dsalgs.hh +++ b/src/hb-dsalgs.hh @@ -854,8 +854,7 @@ struct hb_vector_size_t union { elt_t v[byte_size / sizeof (elt_t)]; #if HB_VECTOR_SIZE - typedef unsigned long vec_t __attribute__((vector_size (HB_VECTOR_SIZE / 8))); - vec_t vec[byte_size / sizeof (vec_t)]; + hb_vector_size_impl_t vec[byte_size / sizeof (hb_vector_size_impl_t)]; #endif } u; }; diff --git a/src/hb-private.hh b/src/hb-private.hh index ae7338724..74b9e274b 100644 --- a/src/hb-private.hh +++ b/src/hb-private.hh @@ -334,6 +334,39 @@ static_assert ((sizeof (hb_var_int_t) == 4), ""); TypeName(const TypeName&); \ void operator=(const TypeName&) + +/* + * Compiler-assisted vectorization parameters. + */ + +/* + * Disable vectorization for now. To correctly use them, we should + * use posix_memalign() to allocate in hb_vector_t. Otherwise, can + * cause misaligned access. + * + * https://bugs.chromium.org/p/chromium/issues/detail?id=860184 + */ +#if !defined(HB_VECTOR_SIZE) +# define HB_VECTOR_SIZE 0 +#endif + +/* The `vector_size' attribute was introduced in gcc 3.1. */ +#if !defined(HB_VECTOR_SIZE) +# if defined( __GNUC__ ) && ( __GNUC__ >= 4 ) +# define HB_VECTOR_SIZE 128 +# else +# define HB_VECTOR_SIZE 0 +# endif +#endif +static_assert (0 == (HB_VECTOR_SIZE & (HB_VECTOR_SIZE - 1)), "HB_VECTOR_SIZE is not power of 2."); +static_assert (0 == (HB_VECTOR_SIZE % 64), "HB_VECTOR_SIZE is not multiple of 64."); +#if HB_VECTOR_SIZE +typedef uint64_t hb_vector_size_impl_t __attribute__((vector_size (HB_VECTOR_SIZE / 8))); +#else +typedef uint64_t hb_vector_size_impl_t; +#endif + + /* * Static pools */ @@ -341,18 +374,18 @@ static_assert ((sizeof (hb_var_int_t) == 4), ""); /* Global nul-content Null pool. Enlarge as necessary. */ #define HB_NULL_POOL_SIZE 264 -static_assert (HB_NULL_POOL_SIZE % sizeof (void *) == 0, "Align HB_NULL_POOL_SIZE."); #ifdef HB_NO_VISIBILITY static #else extern HB_INTERNAL #endif -void * const _hb_NullPool[HB_NULL_POOL_SIZE / sizeof (void *)] +hb_vector_size_impl_t const _hb_NullPool[(HB_NULL_POOL_SIZE + sizeof (hb_vector_size_impl_t) - 1) / sizeof (hb_vector_size_impl_t)] #ifdef HB_NO_VISIBILITY = {} #endif ; + /* Generic nul-content Null objects. */ template static inline Type const & Null (void) { @@ -385,11 +418,12 @@ static #else extern HB_INTERNAL #endif -/*thread_local*/ void * _hb_CrapPool[HB_NULL_POOL_SIZE / sizeof (void *)] +/*thread_local*/ hb_vector_size_impl_t _hb_CrapPool[(HB_NULL_POOL_SIZE + sizeof (hb_vector_size_impl_t) - 1) / sizeof (hb_vector_size_impl_t)] #ifdef HB_NO_VISIBILITY = {} #endif ; + /* CRAP pool: Common Region for Access Protection. */ template static inline Type& Crap (void) { @@ -503,30 +537,6 @@ hb_in_ranges (T u, T lo1, T hi1, T lo2, T hi2, T lo3, T hi3) #define FLAG_RANGE(x,y) (ASSERT_STATIC_EXPR_ZERO ((x) < (y)) + FLAG(y+1) - FLAG(x)) - -/* Compiler-assisted vectorization. */ - -/* - * Disable vectorization for now. To correctly use them, we should - * use posix_memalign() to allocate them. Otherwise, can cause - * misaligned access. - * - * https://bugs.chromium.org/p/chromium/issues/detail?id=860184 - */ -#if !defined(HB_VECTOR_SIZE) -# define HB_VECTOR_SIZE 0 -#endif - -/* The `vector_size' attribute was introduced in gcc 3.1. */ -#if !defined(HB_VECTOR_SIZE) -# if defined( __GNUC__ ) && ( __GNUC__ >= 4 ) -# define HB_VECTOR_SIZE 128 -# else -# define HB_VECTOR_SIZE 0 -# endif -#endif - - /* Global runtime options. */ struct hb_options_t diff --git a/src/hb-static.cc b/src/hb-static.cc index e26e5c801..ee17cd348 100644 --- a/src/hb-static.cc +++ b/src/hb-static.cc @@ -27,6 +27,6 @@ #include "hb-private.hh" #ifndef HB_NO_VISIBILITY -void * const _hb_NullPool[HB_NULL_POOL_SIZE / sizeof (void *)] = {}; -/*thread_local*/ void * _hb_CrapPool[HB_NULL_POOL_SIZE / sizeof (void *)] = {}; +hb_vector_size_impl_t const _hb_NullPool[(HB_NULL_POOL_SIZE + sizeof (hb_vector_size_impl_t) - 1) / sizeof (hb_vector_size_impl_t)] = {}; +/*thread_local*/ hb_vector_size_impl_t _hb_CrapPool[(HB_NULL_POOL_SIZE + sizeof (hb_vector_size_impl_t) - 1) / sizeof (hb_vector_size_impl_t)] = {}; #endif From f3a74c16ecafdca135a647ebe85117c35c1ef585 Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Wed, 11 Jul 2018 17:23:53 +0200 Subject: [PATCH 060/106] Make hb_vector_t 8 bytes smaller --- src/hb-dsalgs.hh | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/src/hb-dsalgs.hh b/src/hb-dsalgs.hh index 953310bcd..fc7d1f0a9 100644 --- a/src/hb-dsalgs.hh +++ b/src/hb-dsalgs.hh @@ -450,8 +450,7 @@ template struct hb_vector_t { unsigned int len; - unsigned int allocated; - bool successful; + unsigned int allocated; /* == 0 means allocation failed. */ Type *arrayZ; Type static_array[StaticSize]; @@ -459,7 +458,6 @@ struct hb_vector_t { len = 0; allocated = ARRAY_LENGTH (static_array); - successful = true; arrayZ = static_array; } @@ -492,7 +490,7 @@ struct hb_vector_t /* Allocate for size but don't adjust len. */ inline bool alloc (unsigned int size) { - if (unlikely (!successful)) + if (unlikely (!allocated)) return false; if (likely (size <= allocated)) @@ -521,7 +519,7 @@ struct hb_vector_t if (unlikely (!new_array)) { - successful = false; + allocated = 0; return false; } From 2aae617a84f47836f10efd30df43e13e3a9447e1 Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Wed, 11 Jul 2018 17:27:23 +0200 Subject: [PATCH 061/106] Move _hb_alignof later again It uses constexpr... --- src/hb-private.hh | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/src/hb-private.hh b/src/hb-private.hh index 74b9e274b..ddb256f80 100644 --- a/src/hb-private.hh +++ b/src/hb-private.hh @@ -84,19 +84,9 @@ extern "C" int hb_memalign_impl(void **memptr, size_t alignment, size_t size); #endif -/* Compiler attributes */ - - -template -struct _hb_alignof -{ - struct s - { - char c; - T t; - }; - static constexpr size_t value = offsetof (s, t); -}; +/* + * Compiler attributes + * */ #if __cplusplus < 201103L @@ -122,6 +112,16 @@ struct _hb_alignof #define thread_local #endif +template +struct _hb_alignof +{ + struct s + { + char c; + T t; + }; + static constexpr size_t value = offsetof (s, t); +}; #ifndef alignof #define alignof(x) (_hb_alignof::value) #endif // alignof From 5631d70d36aa7952d343ea794bd5169a730706ae Mon Sep 17 00:00:00 2001 From: Cosimo Lupo Date: Mon, 16 Jul 2018 12:41:59 +0200 Subject: [PATCH 062/106] appveyor.yml: try updating msys2 to fix failing mingw-w64-x86_64 build https://github.com/harfbuzz/harfbuzz/pull/1093#issuecomment-405201903 https://ci.appveyor.com/project/harfbuzz/harfbuzz/build/job/ky7lao1ii1bi7ew4#L71 --- appveyor.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/appveyor.yml b/appveyor.yml index 05a72d96d..91316e665 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -29,6 +29,8 @@ environment: MSYS2_ARCH: i686 install: + - 'if "%compiler%"=="msys2" C:\msys64\usr\bin\bash -lc "pacman -Syu --noconfirm"' + - 'if "%compiler%"=="msys2" C:\msys64\usr\bin\bash -lc "pacman -Su --noconfirm"' - C:\msys64\usr\bin\bash -lc "pacman --noconfirm -S mingw-w64-x86_64-ragel" build_script: From 3ab52c6cb5c405366af804d278216e2d02a39ecb Mon Sep 17 00:00:00 2001 From: Cosimo Lupo Date: Mon, 16 Jul 2018 12:57:27 +0200 Subject: [PATCH 063/106] appveyor.yml: pass --needed option to pacman so it won't attempt reinstalling packages which are already installed --- appveyor.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/appveyor.yml b/appveyor.yml index 91316e665..9b00d84dc 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -45,7 +45,7 @@ build_script: - 'if "%compiler%"=="msvc" msbuild harfbuzz.sln /p:Configuration=%configuration% /p:Platform=%platform%' - 'if "%compiler%"=="msvc" if not "%platform%"=="ARM" ctest --output-on-failure -C %configuration%' - - 'if "%compiler%"=="msys2" C:\msys64\usr\bin\bash -lc "pacman --noconfirm -S mingw-w64-$MSYS2_ARCH-{freetype,cairo,icu,gettext,gobject-introspection,gcc,gcc-libs,glib2,graphite2,pkg-config,python2}"' + - 'if "%compiler%"=="msys2" C:\msys64\usr\bin\bash -lc "pacman --noconfirm -S --needed mingw-w64-$MSYS2_ARCH-{freetype,cairo,icu,gettext,gobject-introspection,gcc,gcc-libs,glib2,graphite2,pkg-config,python2}"' - 'if "%compiler%"=="msys2" C:\msys64\usr\bin\bash -lc "curl https://raw.githubusercontent.com/mirror/mingw-w64/023eb04c396d4e8d8fcf604cfababc53dae13398/mingw-w64-headers/include/dwrite_1.h > %MINGW_PREFIX%/%MINGW_CHOST%/include/dwrite_1.h"' - 'if "%compiler%"=="msys2" C:\msys64\usr\bin\bash -lc "cd $APPVEYOR_BUILD_FOLDER; PATH=$PATH:/mingw64/bin:/mingw32/bin; ./autogen.sh --with-uniscribe --with-freetype --with-glib --with-gobject --with-cairo --with-icu --with-graphite2 --with-directwrite --build=%MINGW_CHOST% --host=%MINGW_CHOST% --prefix=%MINGW_PREFIX%; make; make check || .ci/fail.sh"' From 269eb45650be66901627da7f1014339065a948a5 Mon Sep 17 00:00:00 2001 From: Cosimo Lupo Date: Mon, 16 Jul 2018 14:14:42 +0200 Subject: [PATCH 064/106] appveyor.yml: try only updating msys2 core, not the rest of the packages maybe it'll get a bit faster --- appveyor.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/appveyor.yml b/appveyor.yml index 9b00d84dc..6250a91ed 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -30,7 +30,6 @@ environment: install: - 'if "%compiler%"=="msys2" C:\msys64\usr\bin\bash -lc "pacman -Syu --noconfirm"' - - 'if "%compiler%"=="msys2" C:\msys64\usr\bin\bash -lc "pacman -Su --noconfirm"' - C:\msys64\usr\bin\bash -lc "pacman --noconfirm -S mingw-w64-x86_64-ragel" build_script: From bda242409fc0cbb79a0ff00eba9856c4b0a9c7a1 Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Mon, 16 Jul 2018 15:41:09 +0200 Subject: [PATCH 065/106] Implement C++11 operations Fixes https://github.com/harfbuzz/harfbuzz/issues/345 --- src/hb-atomic-private.hh | 27 ++++++++++++++++++++++++--- src/hb-open-type-private.hh | 2 +- src/hb-ot-shape-complex-arabic.cc | 2 +- 3 files changed, 26 insertions(+), 5 deletions(-) diff --git a/src/hb-atomic-private.hh b/src/hb-atomic-private.hh index 12caacaab..f234fe041 100644 --- a/src/hb-atomic-private.hh +++ b/src/hb-atomic-private.hh @@ -46,6 +46,25 @@ /* Defined externally, i.e. in config.h; must have typedef'ed hb_atomic_int_impl_t as well. */ +#elif !defined(HB_NO_MT) && __cplusplus >= 201103L + +/* Prefer C++11 atomics. */ + +#include + +typedef int hb_atomic_int_impl_t; +#define hb_atomic_int_impl_add(AI, V) (reinterpret_cast *> (&AI)->fetch_add (V)) + +#define hb_atomic_ptr_impl_get(P) (reinterpret_cast *> (P)->load ()) +static inline bool +_hb_atomic_ptr_impl_cmplexch (const void **P, const void *O_, const void *N) +{ + const void *O = O_; // Need lvalue + return reinterpret_cast *> (P)->compare_exchange_weak ((O), (N)); +} +#define hb_atomic_ptr_impl_cmpexch(P,O,N) (_hb_atomic_ptr_impl_cmplexch ((const void **) (P), (O), (N))) + + #elif !defined(HB_NO_MT) && (defined(_WIN32) || defined(__CYGWIN__)) #include @@ -162,16 +181,18 @@ typedef int hb_atomic_int_impl_t; #endif +#ifndef HB_ATOMIC_INT_INIT #define HB_ATOMIC_INT_INIT(V) {V} +#endif struct hb_atomic_int_t { - hb_atomic_int_impl_t v; + mutable hb_atomic_int_impl_t v; inline void set_unsafe (int v_) { v = v_; } inline int get_unsafe (void) const { return v; } - inline int inc (void) { return hb_atomic_int_impl_add (const_cast (v), 1); } - inline int dec (void) { return hb_atomic_int_impl_add (const_cast (v), -1); } + inline int inc (void) { return hb_atomic_int_impl_add (v, 1); } + inline int dec (void) { return hb_atomic_int_impl_add (v, -1); } }; diff --git a/src/hb-open-type-private.hh b/src/hb-open-type-private.hh index 207f6e0e2..f6113c33a 100644 --- a/src/hb-open-type-private.hh +++ b/src/hb-open-type-private.hh @@ -1247,7 +1247,7 @@ struct hb_lazy_loader_t private: hb_face_t *face; - T *instance; + mutable T *instance; }; /* Logic is shared between hb_lazy_loader_t and hb_table_lazy_loader_t */ diff --git a/src/hb-ot-shape-complex-arabic.cc b/src/hb-ot-shape-complex-arabic.cc index b1cba1c71..0c4948dfd 100644 --- a/src/hb-ot-shape-complex-arabic.cc +++ b/src/hb-ot-shape-complex-arabic.cc @@ -250,7 +250,7 @@ struct arabic_shape_plan_t * mask_array[NONE] == 0. */ hb_mask_t mask_array[ARABIC_NUM_FEATURES + 1]; - arabic_fallback_plan_t *fallback_plan; + mutable arabic_fallback_plan_t *fallback_plan; unsigned int do_fallback : 1; unsigned int has_stch : 1; From 804b59cf4901d471253016e0cbf82cc1bbbc1d15 Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Mon, 16 Jul 2018 15:44:58 +0200 Subject: [PATCH 066/106] Relax C++11 atomic ops memory order to acquire-release --- src/hb-atomic-private.hh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/hb-atomic-private.hh b/src/hb-atomic-private.hh index f234fe041..149600268 100644 --- a/src/hb-atomic-private.hh +++ b/src/hb-atomic-private.hh @@ -53,14 +53,14 @@ #include typedef int hb_atomic_int_impl_t; -#define hb_atomic_int_impl_add(AI, V) (reinterpret_cast *> (&AI)->fetch_add (V)) +#define hb_atomic_int_impl_add(AI, V) (reinterpret_cast *> (&AI)->fetch_add (V, std::memory_order_acq_rel)) -#define hb_atomic_ptr_impl_get(P) (reinterpret_cast *> (P)->load ()) +#define hb_atomic_ptr_impl_get(P) (reinterpret_cast *> (P)->load (std::memory_order_acquire)) static inline bool _hb_atomic_ptr_impl_cmplexch (const void **P, const void *O_, const void *N) { const void *O = O_; // Need lvalue - return reinterpret_cast *> (P)->compare_exchange_weak ((O), (N)); + return reinterpret_cast *> (P)->compare_exchange_weak ((O), (N), std::memory_order_acq_rel); } #define hb_atomic_ptr_impl_cmpexch(P,O,N) (_hb_atomic_ptr_impl_cmplexch ((const void **) (P), (O), (N))) From 21fa170f0bfb0109c506ed17f5aff8b062564ffa Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Mon, 16 Jul 2018 17:58:02 +0200 Subject: [PATCH 067/106] Implement C++11-style GCC builtin atomic ops Hopefully fixes bots. --- src/hb-atomic-private.hh | 22 +++++++++++++++++++--- src/hb-object-private.hh | 2 +- 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/src/hb-atomic-private.hh b/src/hb-atomic-private.hh index 149600268..61d333654 100644 --- a/src/hb-atomic-private.hh +++ b/src/hb-atomic-private.hh @@ -46,21 +46,37 @@ /* Defined externally, i.e. in config.h; must have typedef'ed hb_atomic_int_impl_t as well. */ +#elif !defined(HB_NO_MT) && defined(__ATOMIC_ACQUIRE) + +/* C++11-style GCC primitives. */ + +typedef int hb_atomic_int_impl_t; +#define hb_atomic_int_impl_add(AI, V) __atomic_fetch_add (&(AI), (V), __ATOMIC_ACQ_REL) + +#define hb_atomic_ptr_impl_get(P) __atomic_load_n ((P), __ATOMIC_ACQUIRE) +static inline bool +_hb_atomic_ptr_impl_cmplexch (const void **P, const void *O_, const void *N) +{ + const void *O = O_; // Need lvalue + return __atomic_compare_exchange_n ((void **) P, (void **) O, (void *) N, true, __ATOMIC_ACQ_REL, __ATOMIC_RELAXED); +} +#define hb_atomic_ptr_impl_cmpexch(P,O,N) (_hb_atomic_ptr_impl_cmplexch ((const void **) (P), (O), (N))) + #elif !defined(HB_NO_MT) && __cplusplus >= 201103L -/* Prefer C++11 atomics. */ +/* C++11 atomics. */ #include typedef int hb_atomic_int_impl_t; -#define hb_atomic_int_impl_add(AI, V) (reinterpret_cast *> (&AI)->fetch_add (V, std::memory_order_acq_rel)) +#define hb_atomic_int_impl_add(AI, V) (reinterpret_cast *> (&AI)->fetch_add ((V), std::memory_order_acq_rel)) #define hb_atomic_ptr_impl_get(P) (reinterpret_cast *> (P)->load (std::memory_order_acquire)) static inline bool _hb_atomic_ptr_impl_cmplexch (const void **P, const void *O_, const void *N) { const void *O = O_; // Need lvalue - return reinterpret_cast *> (P)->compare_exchange_weak ((O), (N), std::memory_order_acq_rel); + return reinterpret_cast *> (P)->compare_exchange_weak (O, N, std::memory_order_acq_rel, std::memory_order_relaxed); } #define hb_atomic_ptr_impl_cmpexch(P,O,N) (_hb_atomic_ptr_impl_cmplexch ((const void **) (P), (O), (N))) diff --git a/src/hb-object-private.hh b/src/hb-object-private.hh index fcdc9256d..8199c4b84 100644 --- a/src/hb-object-private.hh +++ b/src/hb-object-private.hh @@ -94,7 +94,7 @@ struct hb_user_data_array_t struct hb_object_header_t { hb_reference_count_t ref_count; - hb_user_data_array_t *user_data; + mutable hb_user_data_array_t *user_data; #define HB_OBJECT_HEADER_STATIC {HB_REFERENCE_COUNT_INIT, nullptr} From 3edef5a19b5c0f30381ae6fe01c3370ded37f6ca Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Tue, 17 Jul 2018 10:50:01 +0200 Subject: [PATCH 068/106] Revert "Implement C++11-style GCC builtin atomic ops" This reverts commit 21fa170f0bfb0109c506ed17f5aff8b062564ffa. Is crashing. Oops. --- src/hb-atomic-private.hh | 22 +++------------------- src/hb-object-private.hh | 2 +- 2 files changed, 4 insertions(+), 20 deletions(-) diff --git a/src/hb-atomic-private.hh b/src/hb-atomic-private.hh index 61d333654..149600268 100644 --- a/src/hb-atomic-private.hh +++ b/src/hb-atomic-private.hh @@ -46,37 +46,21 @@ /* Defined externally, i.e. in config.h; must have typedef'ed hb_atomic_int_impl_t as well. */ -#elif !defined(HB_NO_MT) && defined(__ATOMIC_ACQUIRE) - -/* C++11-style GCC primitives. */ - -typedef int hb_atomic_int_impl_t; -#define hb_atomic_int_impl_add(AI, V) __atomic_fetch_add (&(AI), (V), __ATOMIC_ACQ_REL) - -#define hb_atomic_ptr_impl_get(P) __atomic_load_n ((P), __ATOMIC_ACQUIRE) -static inline bool -_hb_atomic_ptr_impl_cmplexch (const void **P, const void *O_, const void *N) -{ - const void *O = O_; // Need lvalue - return __atomic_compare_exchange_n ((void **) P, (void **) O, (void *) N, true, __ATOMIC_ACQ_REL, __ATOMIC_RELAXED); -} -#define hb_atomic_ptr_impl_cmpexch(P,O,N) (_hb_atomic_ptr_impl_cmplexch ((const void **) (P), (O), (N))) - #elif !defined(HB_NO_MT) && __cplusplus >= 201103L -/* C++11 atomics. */ +/* Prefer C++11 atomics. */ #include typedef int hb_atomic_int_impl_t; -#define hb_atomic_int_impl_add(AI, V) (reinterpret_cast *> (&AI)->fetch_add ((V), std::memory_order_acq_rel)) +#define hb_atomic_int_impl_add(AI, V) (reinterpret_cast *> (&AI)->fetch_add (V, std::memory_order_acq_rel)) #define hb_atomic_ptr_impl_get(P) (reinterpret_cast *> (P)->load (std::memory_order_acquire)) static inline bool _hb_atomic_ptr_impl_cmplexch (const void **P, const void *O_, const void *N) { const void *O = O_; // Need lvalue - return reinterpret_cast *> (P)->compare_exchange_weak (O, N, std::memory_order_acq_rel, std::memory_order_relaxed); + return reinterpret_cast *> (P)->compare_exchange_weak ((O), (N), std::memory_order_acq_rel); } #define hb_atomic_ptr_impl_cmpexch(P,O,N) (_hb_atomic_ptr_impl_cmplexch ((const void **) (P), (O), (N))) diff --git a/src/hb-object-private.hh b/src/hb-object-private.hh index 8199c4b84..fcdc9256d 100644 --- a/src/hb-object-private.hh +++ b/src/hb-object-private.hh @@ -94,7 +94,7 @@ struct hb_user_data_array_t struct hb_object_header_t { hb_reference_count_t ref_count; - mutable hb_user_data_array_t *user_data; + hb_user_data_array_t *user_data; #define HB_OBJECT_HEADER_STATIC {HB_REFERENCE_COUNT_INIT, nullptr} From 019d18e9ae643134bfc3861be65ac618a5892c92 Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Tue, 17 Jul 2018 10:59:19 +0200 Subject: [PATCH 069/106] Minor --- src/Makefile.am | 1 + test/api/Makefile.am | 2 ++ 2 files changed, 3 insertions(+) diff --git a/src/Makefile.am b/src/Makefile.am index 6dfec3bfa..66594bbcd 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -14,6 +14,7 @@ check_PROGRAMS = # Convenience targets: lib: $(BUILT_SOURCES) libharfbuzz.la libharfbuzz-subset.la +libs: $(BUILT_SOURCES) $(lib_LTLIBRARIES) fuzzing: $(BUILT_SOURCES) libharfbuzz-fuzzing.la libharfbuzz-subset-fuzzing.la lib_LTLIBRARIES = libharfbuzz.la diff --git a/test/api/Makefile.am b/test/api/Makefile.am index 65ceeda3c..a20334498 100644 --- a/test/api/Makefile.am +++ b/test/api/Makefile.am @@ -9,6 +9,8 @@ MAINTAINERCLEANFILES = # Convenience targets: lib: @$(MAKE) $(AM_MAKEFLAGS) -C $(top_builddir)/src lib +libs: + @$(MAKE) $(AM_MAKEFLAGS) -C $(top_builddir)/src libs EXTRA_DIST += CMakeLists.txt From 04b7b81bcbf19cb85d06d930192d6591ba45ef72 Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Tue, 17 Jul 2018 10:57:01 +0200 Subject: [PATCH 070/106] Reland "Implement C++11-style GCC builtin atomic ops" Fixed the crasher in it. --- src/hb-atomic-private.hh | 22 +++++++++++++++++++--- src/hb-object-private.hh | 2 +- 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/src/hb-atomic-private.hh b/src/hb-atomic-private.hh index 149600268..02cf6f388 100644 --- a/src/hb-atomic-private.hh +++ b/src/hb-atomic-private.hh @@ -46,21 +46,37 @@ /* Defined externally, i.e. in config.h; must have typedef'ed hb_atomic_int_impl_t as well. */ +#elif !defined(HB_NO_MT) && defined(__ATOMIC_ACQUIRE) + +/* C++11-style GCC primitives. */ + +typedef int hb_atomic_int_impl_t; +#define hb_atomic_int_impl_add(AI, V) __atomic_fetch_add (&(AI), (V), __ATOMIC_ACQ_REL) + +#define hb_atomic_ptr_impl_get(P) __atomic_load_n ((P), __ATOMIC_ACQUIRE) +static inline bool +_hb_atomic_ptr_impl_cmplexch (const void **P, const void *O_, const void *N) +{ + const void *O = O_; // Need lvalue + return __atomic_compare_exchange_n ((void **) P, (void **) &O, (void *) N, true, __ATOMIC_ACQ_REL, __ATOMIC_RELAXED); +} +#define hb_atomic_ptr_impl_cmpexch(P,O,N) (_hb_atomic_ptr_impl_cmplexch ((const void **) (P), (O), (N))) + #elif !defined(HB_NO_MT) && __cplusplus >= 201103L -/* Prefer C++11 atomics. */ +/* C++11 atomics. */ #include typedef int hb_atomic_int_impl_t; -#define hb_atomic_int_impl_add(AI, V) (reinterpret_cast *> (&AI)->fetch_add (V, std::memory_order_acq_rel)) +#define hb_atomic_int_impl_add(AI, V) (reinterpret_cast *> (&AI)->fetch_add ((V), std::memory_order_acq_rel)) #define hb_atomic_ptr_impl_get(P) (reinterpret_cast *> (P)->load (std::memory_order_acquire)) static inline bool _hb_atomic_ptr_impl_cmplexch (const void **P, const void *O_, const void *N) { const void *O = O_; // Need lvalue - return reinterpret_cast *> (P)->compare_exchange_weak ((O), (N), std::memory_order_acq_rel); + return reinterpret_cast *> (P)->compare_exchange_weak (O, N, std::memory_order_acq_rel, std::memory_order_relaxed); } #define hb_atomic_ptr_impl_cmpexch(P,O,N) (_hb_atomic_ptr_impl_cmplexch ((const void **) (P), (O), (N))) diff --git a/src/hb-object-private.hh b/src/hb-object-private.hh index fcdc9256d..8199c4b84 100644 --- a/src/hb-object-private.hh +++ b/src/hb-object-private.hh @@ -94,7 +94,7 @@ struct hb_user_data_array_t struct hb_object_header_t { hb_reference_count_t ref_count; - hb_user_data_array_t *user_data; + mutable hb_user_data_array_t *user_data; #define HB_OBJECT_HEADER_STATIC {HB_REFERENCE_COUNT_INIT, nullptr} From 68310a65cba7eed20f8696f4c670bb195677f467 Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Tue, 17 Jul 2018 13:20:40 +0200 Subject: [PATCH 071/106] 1.8.4 --- NEWS | 7 +++++++ configure.ac | 2 +- src/hb-version.h | 4 ++-- 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/NEWS b/NEWS index 9031766db..fce43a364 100644 --- a/NEWS +++ b/NEWS @@ -1,3 +1,10 @@ +Overview of changes leading to 1.8.4 +Tuesday, July 17, 2018 +==================================== +- Fix build on non-C++11. +- Use C++-style GCC atomics and C++11 atomics. + + Overview of changes leading to 1.8.3 Wednesday, July 11, 2018 ==================================== diff --git a/configure.ac b/configure.ac index b6fcfc02a..0dd70e68f 100644 --- a/configure.ac +++ b/configure.ac @@ -1,6 +1,6 @@ AC_PREREQ([2.64]) AC_INIT([HarfBuzz], - [1.8.3], + [1.8.4], [https://github.com/harfbuzz/harfbuzz/issues/new], [harfbuzz], [http://harfbuzz.org/]) diff --git a/src/hb-version.h b/src/hb-version.h index c3c38de7b..09e3c2c0b 100644 --- a/src/hb-version.h +++ b/src/hb-version.h @@ -38,9 +38,9 @@ HB_BEGIN_DECLS #define HB_VERSION_MAJOR 1 #define HB_VERSION_MINOR 8 -#define HB_VERSION_MICRO 3 +#define HB_VERSION_MICRO 4 -#define HB_VERSION_STRING "1.8.3" +#define HB_VERSION_STRING "1.8.4" #define HB_VERSION_ATLEAST(major,minor,micro) \ ((major)*10000+(minor)*100+(micro) <= \ From db5d430effce67db57ddea2545694b7275ee8b35 Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Tue, 17 Jul 2018 18:14:45 +0200 Subject: [PATCH 072/106] [aat] Update for blob changes Also, uncomment code again, just "if (0)" it out, so it doesn't get stale again. --- src/hb-aat-layout.cc | 58 ++----------------------------------- src/hb-open-type-private.hh | 27 ++++++++++------- src/hb-ot-layout-private.hh | 1 + src/hb-ot-layout.cc | 2 ++ src/hb-ot-shape.cc | 6 ++-- 5 files changed, 25 insertions(+), 69 deletions(-) diff --git a/src/hb-aat-layout.cc b/src/hb-aat-layout.cc index 7784fae33..df6c38c4d 100644 --- a/src/hb-aat-layout.cc +++ b/src/hb-aat-layout.cc @@ -41,43 +41,9 @@ #include "hb-aat-ltag-table.hh" // Just so we compile it; unused otherwise. /* - * morx/kerx/trak + * morx/kerx/trak/ankr */ -#if 0 -static inline const AAT::ankr& -_get_ankr (hb_face_t *face, hb_blob_t **blob = nullptr) -{ - if (unlikely (!hb_ot_shaper_face_data_ensure (face))) - { - if (blob) - *blob = hb_blob_get_empty (); - return Null(AAT::ankr); - } - hb_ot_layout_t * layout = hb_ot_layout_from_face (face); - const AAT::ankr& ankr = *(layout->ankr.get ()); - if (blob) - *blob = layout->ankr.blob; - return ankr; -} - -static inline const AAT::kerx& -_get_kerx (hb_face_t *face, hb_blob_t **blob = nullptr) -{ - if (unlikely (!hb_ot_shaper_face_data_ensure (face))) - { - if (blob) - *blob = hb_blob_get_empty (); - return Null(AAT::kerx); - } - hb_ot_layout_t * layout = hb_ot_layout_from_face (face); - /* XXX this doesn't call set_num_glyphs on sanitizer. */ - const AAT::kerx& kerx = *(layout->kerx.get ()); - if (blob) - *blob = layout->kerx.blob; - return kerx; -} - static inline const AAT::morx& _get_morx (hb_face_t *face, hb_blob_t **blob = nullptr) { @@ -88,30 +54,12 @@ _get_morx (hb_face_t *face, hb_blob_t **blob = nullptr) return Null(AAT::morx); } hb_ot_layout_t * layout = hb_ot_layout_from_face (face); - /* XXX this doesn't call set_num_glyphs on sanitizer. */ const AAT::morx& morx = *(layout->morx.get ()); if (blob) - *blob = layout->morx.blob; + *blob = layout->morx.get_blob (); return morx; } -static inline const AAT::trak& -_get_trak (hb_face_t *face, hb_blob_t **blob = nullptr) -{ - if (unlikely (!hb_ot_shaper_face_data_ensure (face))) - { - if (blob) - *blob = hb_blob_get_empty (); - return Null(AAT::trak); - } - hb_ot_layout_t * layout = hb_ot_layout_from_face (face); - const AAT::trak& trak = *(layout->trak.get ()); - if (blob) - *blob = layout->trak.blob; - return trak; -} -#endif - // static inline void // _hb_aat_layout_create (hb_face_t *face) // { @@ -129,13 +77,11 @@ _get_trak (hb_face_t *face, hb_blob_t **blob = nullptr) void hb_aat_layout_substitute (hb_font_t *font, hb_buffer_t *buffer) { -#if 0 hb_blob_t *blob; const AAT::morx& morx = _get_morx (font->face, &blob); AAT::hb_aat_apply_context_t c (font, buffer, blob); morx.apply (&c); -#endif } void diff --git a/src/hb-open-type-private.hh b/src/hb-open-type-private.hh index f6113c33a..f681c573f 100644 --- a/src/hb-open-type-private.hh +++ b/src/hb-open-type-private.hh @@ -290,9 +290,10 @@ struct hb_sanitize_context_t : template struct Sanitizer { - inline Sanitizer (void) {} + inline Sanitizer (unsigned int num_glyphs = 0) { c->num_glyphs = num_glyphs; } - inline hb_blob_t *sanitize (hb_blob_t *blob) { + inline hb_blob_t *sanitize (hb_blob_t *blob) + { bool sane; /* TODO is_sane() stuff */ @@ -1265,21 +1266,27 @@ struct hb_table_lazy_loader_t hb_blob_destroy (blob); } - inline const T* get (void) const + inline hb_blob_t* get_blob (void) const { retry: - hb_blob_t *blob_ = (hb_blob_t *) hb_atomic_ptr_get (&blob); - if (unlikely (!blob_)) + hb_blob_t *b = (hb_blob_t *) hb_atomic_ptr_get (&blob); + if (unlikely (!b)) { - blob_ = OT::Sanitizer().sanitize (face->reference_table (T::tableTag)); - if (!hb_atomic_ptr_cmpexch (&blob, nullptr, blob_)) + b = OT::Sanitizer(face->get_num_glyphs ()).sanitize (face->reference_table (T::tableTag)); + if (!hb_atomic_ptr_cmpexch (&blob, nullptr, b)) { - hb_blob_destroy (blob_); + hb_blob_destroy (b); goto retry; } - blob = blob_; + blob = b; } - return blob_->as (); + return b; + } + + inline const T* get (void) const + { + hb_blob_t *b = get_blob (); + return b->as (); } inline const T* operator-> (void) const diff --git a/src/hb-ot-layout-private.hh b/src/hb-ot-layout-private.hh index b2f974b82..6fe673e91 100644 --- a/src/hb-ot-layout-private.hh +++ b/src/hb-ot-layout-private.hh @@ -176,6 +176,7 @@ struct hb_ot_layout_t OT::hb_table_lazy_loader_t math; OT::hb_table_lazy_loader_t fvar; OT::hb_table_lazy_loader_t avar; + OT::hb_table_lazy_loader_t morx; unsigned int gsub_lookup_count; unsigned int gpos_lookup_count; diff --git a/src/hb-ot-layout.cc b/src/hb-ot-layout.cc index 655c36c1c..3a0823073 100644 --- a/src/hb-ot-layout.cc +++ b/src/hb-ot-layout.cc @@ -66,6 +66,7 @@ _hb_ot_layout_create (hb_face_t *face) layout->math.init (face); layout->fvar.init (face); layout->avar.init (face); + layout->morx.init (face); { /* @@ -215,6 +216,7 @@ _hb_ot_layout_destroy (hb_ot_layout_t *layout) layout->math.fini (); layout->fvar.fini (); layout->avar.fini (); + layout->morx.fini (); free (layout); } diff --git a/src/hb-ot-shape.cc b/src/hb-ot-shape.cc index 1189b2075..6696ad885 100644 --- a/src/hb-ot-shape.cc +++ b/src/hb-ot-shape.cc @@ -41,7 +41,7 @@ #include "hb-set-private.hh" #include "hb-ot-layout-gsubgpos-private.hh" -//#include "hb-aat-layout-private.hh" +#include "hb-aat-layout-private.hh" static hb_tag_t common_features[] = { HB_TAG('c','c','m','p'), @@ -623,8 +623,8 @@ hb_ot_substitute_complex (hb_ot_shape_context_t *c) c->plan->substitute (c->font, buffer); - /* XXX Call morx instead. */ - //hb_aat_layout_substitute (c->font, c->buffer); + if (0) /* XXX Call morx instead. */ + hb_aat_layout_substitute (c->font, c->buffer); } static inline void From be7073840097c873ce4954c6cffadab175a007d3 Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Tue, 17 Jul 2018 18:45:25 +0200 Subject: [PATCH 073/106] Move sanitizer code around a bit --- src/hb-aat-layout-common-private.hh | 4 +- src/hb-open-type-private.hh | 141 +++++++++++++++------------- src/hb-ot-color-sbix-table.hh | 12 +-- src/hb-ot-layout-common-private.hh | 3 - 4 files changed, 81 insertions(+), 79 deletions(-) diff --git a/src/hb-aat-layout-common-private.hh b/src/hb-aat-layout-common-private.hh index 2825b1813..d7f35052d 100644 --- a/src/hb-aat-layout-common-private.hh +++ b/src/hb-aat-layout-common-private.hh @@ -161,7 +161,7 @@ struct LookupFormat0 inline bool sanitize (hb_sanitize_context_t *c) const { TRACE_SANITIZE (this); - return_trace (arrayZ.sanitize (c, c->num_glyphs)); + return_trace (arrayZ.sanitize (c, c->get_num_glyphs ())); } protected: @@ -625,7 +625,7 @@ struct hb_aat_apply_context_t : sanitizer (), lookup_index (0), debug_depth (0) { sanitizer.init (table); - sanitizer.num_glyphs = face->get_num_glyphs (); + sanitizer.set_num_glyphs (face->get_num_glyphs ()); sanitizer.start_processing (); } diff --git a/src/hb-open-type-private.hh b/src/hb-open-type-private.hh index f681c573f..26afb909b 100644 --- a/src/hb-open-type-private.hh +++ b/src/hb-open-type-private.hh @@ -182,6 +182,9 @@ struct hb_sanitize_context_t : this->writable = false; } + inline void set_num_glyphs (unsigned int num_glyphs_) { num_glyphs = num_glyphs_; } + inline unsigned int get_num_glyphs (void) { return num_glyphs; } + inline void start_processing (void) { this->start = hb_blob_get_data (this->blob, nullptr); @@ -275,8 +278,78 @@ struct hb_sanitize_context_t : return false; } + template + inline hb_blob_t *sanitize (hb_blob_t *blob) + { + bool sane; + + /* TODO is_sane() stuff */ + + init (blob); + + retry: + DEBUG_MSG_FUNC (SANITIZE, start, "start"); + + start_processing (); + + if (unlikely (!start)) + { + end_processing (); + return blob; + } + + Type *t = CastP (const_cast (start)); + + sane = t->sanitize (this); + if (sane) + { + if (edit_count) + { + DEBUG_MSG_FUNC (SANITIZE, start, "passed first round with %d edits; going for second round", edit_count); + + /* sanitize again to ensure no toe-stepping */ + edit_count = 0; + sane = t->sanitize (this); + if (edit_count) { + DEBUG_MSG_FUNC (SANITIZE, start, "requested %d edits in second round; FAILLING", edit_count); + sane = false; + } + } + } + else + { + if (edit_count && !writable) { + start = hb_blob_get_data_writable (blob, nullptr); + end = start + blob->length; + + if (start) + { + writable = true; + /* ok, we made it writable by relocating. try again */ + DEBUG_MSG_FUNC (SANITIZE, start, "retry"); + goto retry; + } + } + } + + end_processing (); + + DEBUG_MSG_FUNC (SANITIZE, start, sane ? "PASSED" : "FAILED"); + if (sane) + { + blob->lock (); + return blob; + } + else + { + hb_blob_destroy (blob); + return hb_blob_get_empty (); + } + } + mutable unsigned int debug_depth; const char *start, *end; + private: bool writable; unsigned int edit_count; mutable int max_ops; @@ -290,72 +363,8 @@ struct hb_sanitize_context_t : template struct Sanitizer { - inline Sanitizer (unsigned int num_glyphs = 0) { c->num_glyphs = num_glyphs; } - - inline hb_blob_t *sanitize (hb_blob_t *blob) - { - bool sane; - - /* TODO is_sane() stuff */ - - c->init (blob); - - retry: - DEBUG_MSG_FUNC (SANITIZE, c->start, "start"); - - c->start_processing (); - - if (unlikely (!c->start)) { - c->end_processing (); - return blob; - } - - Type *t = CastP (const_cast (c->start)); - - sane = t->sanitize (c); - if (sane) { - if (c->edit_count) { - DEBUG_MSG_FUNC (SANITIZE, c->start, "passed first round with %d edits; going for second round", c->edit_count); - - /* sanitize again to ensure no toe-stepping */ - c->edit_count = 0; - sane = t->sanitize (c); - if (c->edit_count) { - DEBUG_MSG_FUNC (SANITIZE, c->start, "requested %d edits in second round; FAILLING", c->edit_count); - sane = false; - } - } - } else { - unsigned int edit_count = c->edit_count; - if (edit_count && !c->writable) { - c->start = hb_blob_get_data_writable (blob, nullptr); - c->end = c->start + blob->length; - - if (c->start) { - c->writable = true; - /* ok, we made it writable by relocating. try again */ - DEBUG_MSG_FUNC (SANITIZE, c->start, "retry"); - goto retry; - } - } - } - - c->end_processing (); - - DEBUG_MSG_FUNC (SANITIZE, c->start, sane ? "PASSED" : "FAILED"); - if (sane) - { - blob->lock (); - return blob; - } - else - { - hb_blob_destroy (blob); - return hb_blob_get_empty (); - } - } - - inline void set_num_glyphs (unsigned int num_glyphs) { c->num_glyphs = num_glyphs; } + inline Sanitizer (unsigned int num_glyphs = 0) { c->set_num_glyphs (num_glyphs); } + inline hb_blob_t *sanitize (hb_blob_t *blob) { return c->sanitize (blob); } private: hb_sanitize_context_t c[1]; diff --git a/src/hb-ot-color-sbix-table.hh b/src/hb-ot-color-sbix-table.hh index 09a9517c4..bf644a67f 100644 --- a/src/hb-ot-color-sbix-table.hh +++ b/src/hb-ot-color-sbix-table.hh @@ -68,7 +68,7 @@ struct SBIXStrike { TRACE_SANITIZE (this); return_trace (c->check_struct (this) && - imageOffsetsZ.sanitize_shallow (c, c->num_glyphs + 1)); + imageOffsetsZ.sanitize_shallow (c, c->get_num_glyphs () + 1)); } protected: @@ -96,14 +96,11 @@ struct sbix { inline void init (hb_face_t *face) { - num_glyphs = hb_face_get_glyph_count (face); - - OT::Sanitizer sanitizer; - sanitizer.set_num_glyphs (num_glyphs); - sbix_blob = sanitizer.sanitize (face->reference_table (HB_OT_TAG_sbix)); + /* XXX Using public API instead of private method to avoid link problem in dump_emoji. + * Kill that! */ + sbix_blob = OT::Sanitizer(hb_face_get_glyph_count (face)/*face->get_num_glyphs ()*/).sanitize (face->reference_table (HB_OT_TAG_sbix)); sbix_len = hb_blob_get_length (sbix_blob); sbix_table = sbix_blob->as (); - } inline void fini (void) @@ -134,7 +131,6 @@ struct sbix unsigned int sbix_len; unsigned int num_glyphs; - }; protected: diff --git a/src/hb-ot-layout-common-private.hh b/src/hb-ot-layout-common-private.hh index 21a8382c3..2ae1157dc 100644 --- a/src/hb-ot-layout-common-private.hh +++ b/src/hb-ot-layout-common-private.hh @@ -540,9 +540,6 @@ struct Feature c->try_set (&featureParams, new_offset) && !featureParams.sanitize (c, this, closure ? closure->tag : HB_TAG_NONE)) return_trace (false); - - if (c->edit_count > 1) - c->edit_count--; /* This was a "legitimate" edit; don't contribute to error count. */ } return_trace (true); From a8cc0b5907e61199334a3a886fe22efe9cc17149 Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Tue, 17 Jul 2018 19:09:03 +0200 Subject: [PATCH 074/106] Remove TODO that is not gonna be done Previously the idea was to cache sanitize results externally (think, in Fontconfig) and avoid resanitizing every time. That's, not a good idea. --- src/hb-open-type-private.hh | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/hb-open-type-private.hh b/src/hb-open-type-private.hh index 26afb909b..457e58c4a 100644 --- a/src/hb-open-type-private.hh +++ b/src/hb-open-type-private.hh @@ -283,8 +283,6 @@ struct hb_sanitize_context_t : { bool sane; - /* TODO is_sane() stuff */ - init (blob); retry: From 1e9e344b2ba076a5fd6d57d1705e17a59c3875ce Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Tue, 17 Jul 2018 19:17:59 +0200 Subject: [PATCH 075/106] Fix hb_face_count() sanitize referencing --- src/hb-face.cc | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/hb-face.cc b/src/hb-face.cc index 2fef09d03..3c22f654f 100644 --- a/src/hb-face.cc +++ b/src/hb-face.cc @@ -52,10 +52,13 @@ hb_face_count (hb_blob_t *blob) if (unlikely (!blob)) return 0; - hb_blob_t *sanitized = OT::Sanitizer ().sanitize (blob); + /* TODO We shouldn't be sanitizing blob. Port to run sanitizer and return if not sane. */ + hb_blob_t *sanitized = OT::Sanitizer ().sanitize (hb_blob_reference (blob)); const OT::OpenTypeFontFile& ot = *sanitized->as (); + unsigned int ret = ot.get_face_count (); + hb_blob_destroy (sanitized); - return ot.get_face_count (); + return ret; } /* From d5cd47a69c40966b4d5b5aed87dd7ac6f070c37a Mon Sep 17 00:00:00 2001 From: Ebrahim Byagowi Date: Tue, 17 Jul 2018 22:32:37 +0430 Subject: [PATCH 076/106] Remove AAT's gcid/fmtx (#1099) We are not going to use them, at least in the foreseeable future --- src/Makefile.sources | 2 -- src/hb-aat-fmtx-table.hh | 67 ------------------------------------ src/hb-aat-gcid-table.hh | 73 ---------------------------------------- src/hb-aat-layout.cc | 2 -- 4 files changed, 144 deletions(-) delete mode 100644 src/hb-aat-fmtx-table.hh delete mode 100644 src/hb-aat-gcid-table.hh diff --git a/src/Makefile.sources b/src/Makefile.sources index 0bc9e589e..9fa926d40 100644 --- a/src/Makefile.sources +++ b/src/Makefile.sources @@ -93,8 +93,6 @@ HB_OT_sources = \ hb-aat-layout-morx-table.hh \ hb-aat-layout-trak-table.hh \ hb-aat-layout-private.hh \ - hb-aat-fmtx-table.hh \ - hb-aat-gcid-table.hh \ hb-aat-ltag-table.hh \ hb-ot-font.cc \ hb-ot-layout.cc \ diff --git a/src/hb-aat-fmtx-table.hh b/src/hb-aat-fmtx-table.hh deleted file mode 100644 index aa82c88cf..000000000 --- a/src/hb-aat-fmtx-table.hh +++ /dev/null @@ -1,67 +0,0 @@ -/* - * Copyright © 2018 Ebrahim Byagowi - * - * This is part of HarfBuzz, a text shaping library. - * - * Permission is hereby granted, without written agreement and without - * license or royalty fees, to use, copy, modify, and distribute this - * software and its documentation for any purpose, provided that the - * above copyright notice and the following two paragraphs appear in - * all copies of this software. - * - * IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE TO ANY PARTY FOR - * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES - * ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN - * IF THE COPYRIGHT HOLDER HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH - * DAMAGE. - * - * THE COPYRIGHT HOLDER SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, - * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND - * FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS - * ON AN "AS IS" BASIS, AND THE COPYRIGHT HOLDER HAS NO OBLIGATION TO - * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. - */ - -#ifndef HB_AAT_FMTX_TABLE_HH -#define HB_AAT_FMTX_TABLE_HH - -#include "hb-aat-layout-common-private.hh" - -/* - * fmtx -- Font Metrics - * https://developer.apple.com/fonts/TrueType-Reference-Manual/RM06/Chap6fmtx.html - */ -#define HB_AAT_TAG_fmtx HB_TAG('f','m','t','x') - - -namespace AAT { - - -struct fmtx -{ - static const hb_tag_t tableTag = HB_AAT_TAG_fmtx; - - inline bool sanitize (hb_sanitize_context_t *c) const - { - TRACE_SANITIZE (this); - return_trace (likely (c->check_struct (this))); - } - - FixedVersion<>version; /* Version (set to 0x00020000). */ - HBUINT32 glyphIndex; /* The glyph whose points represent the metrics. */ - HBUINT8 horizontalBefore; /* Point number for the horizontal ascent. */ - HBUINT8 horizontalAfter; /* Point number for the horizontal descent. */ - HBUINT8 horizontalCaretHead; /* Point number for the horizontal caret head. */ - HBUINT8 horizontalCaretBase; /* Point number for the horizontal caret base. */ - HBUINT8 verticalBefore; /* Point number for the vertical ascent. */ - HBUINT8 verticalAfter; /* Point number for the vertical descent. */ - HBUINT8 verticalCaretHead; /* Point number for the vertical caret head. */ - HBUINT8 verticalCaretBase; /* Point number for the vertical caret base. */ - public: - DEFINE_SIZE_STATIC (16); -}; - -} /* namespace AAT */ - - -#endif /* HB_AAT_FMTX_TABLE_HH */ diff --git a/src/hb-aat-gcid-table.hh b/src/hb-aat-gcid-table.hh deleted file mode 100644 index b48a27984..000000000 --- a/src/hb-aat-gcid-table.hh +++ /dev/null @@ -1,73 +0,0 @@ -/* - * Copyright © 2018 Ebrahim Byagowi - * - * This is part of HarfBuzz, a text shaping library. - * - * Permission is hereby granted, without written agreement and without - * license or royalty fees, to use, copy, modify, and distribute this - * software and its documentation for any purpose, provided that the - * above copyright notice and the following two paragraphs appear in - * all copies of this software. - * - * IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE TO ANY PARTY FOR - * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES - * ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN - * IF THE COPYRIGHT HOLDER HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH - * DAMAGE. - * - * THE COPYRIGHT HOLDER SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, - * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND - * FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS - * ON AN "AS IS" BASIS, AND THE COPYRIGHT HOLDER HAS NO OBLIGATION TO - * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. - */ - -#ifndef HB_AAT_GCID_TABLE_HH -#define HB_AAT_GCID_TABLE_HH - -#include "hb-aat-layout-common-private.hh" - -/* - * gcid -- Glyphs CIDs - * https://developer.apple.com/fonts/TrueType-Reference-Manual/RM06/Chap6gcid.html - */ -#define HB_AAT_TAG_gcid HB_TAG('g','c','i','d') - - -namespace AAT { - - -struct gcid -{ - static const hb_tag_t tableTag = HB_AAT_TAG_gcid; - - inline bool sanitize (hb_sanitize_context_t *c) const - { - TRACE_SANITIZE (this); - return_trace (likely (c->check_struct (this) && CIDs.sanitize (c))); - } - - protected: - HBUINT16 version; /* Version number (set to 0) */ - HBUINT16 format; /* Data format (set to 0) */ - HBUINT32 size; /* Size of the table, including header */ - HBUINT16 registry; /* The registry ID */ - HBUINT8 registryName[64]; - /* The registry name in ASCII */ - HBUINT16 order; /* The order ID */ - HBUINT8 orderName[64]; /* The order name in ASCII */ - HBUINT16 supplementVersion; - /* The supplement version */ - ArrayOf - CIDs; /* The CIDs for the glyphs in the font, - * starting with glyph 0. If a glyph does not correspond - * to a CID in the identified collection, 0xFFFF is used. - * This should not exceed the number of glyphs in the font. */ - public: - DEFINE_SIZE_ARRAY (144, CIDs); -}; - -} /* namespace AAT */ - - -#endif /* HB_AAT_GCID_TABLE_HH */ diff --git a/src/hb-aat-layout.cc b/src/hb-aat-layout.cc index df6c38c4d..696dd3558 100644 --- a/src/hb-aat-layout.cc +++ b/src/hb-aat-layout.cc @@ -36,8 +36,6 @@ #include "hb-aat-layout-kerx-table.hh" #include "hb-aat-layout-morx-table.hh" #include "hb-aat-layout-trak-table.hh" -#include "hb-aat-fmtx-table.hh" // Just so we compile it; unused otherwise. -#include "hb-aat-gcid-table.hh" // Just so we compile it; unused otherwise. #include "hb-aat-ltag-table.hh" // Just so we compile it; unused otherwise. /* From 93b65d9fe331a217640069fad4159cb7c3ec35e6 Mon Sep 17 00:00:00 2001 From: Ebrahim Byagowi Date: Tue, 17 Jul 2018 23:29:16 +0430 Subject: [PATCH 077/106] Remove dump-fon (#1100) It had interesting stuffs like EXE parsing and big-endian parsers but added in an attempt to find a solution for #681 which later found not related. --- src/Makefile.am | 4 - src/dump-fon.cc | 555 ------------------------------------------------ 2 files changed, 559 deletions(-) delete mode 100644 src/dump-fon.cc diff --git a/src/Makefile.am b/src/Makefile.am index 66594bbcd..9e7fd2995 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -374,15 +374,11 @@ dist_check_SCRIPTS += \ endif check_PROGRAMS += \ - dump-fon \ dump-indic-data \ dump-khmer-data \ dump-myanmar-data \ dump-use-data \ $(NULL) -dump_fon_SOURCES = dump-fon.cc -dump_fon_CPPFLAGS = $(HBCFLAGS) -dump_fon_LDADD = libharfbuzz.la $(HBLIBS) dump_indic_data_SOURCES = dump-indic-data.cc hb-ot-shape-complex-indic-table.cc dump_indic_data_CPPFLAGS = $(HBCFLAGS) dump_indic_data_LDADD = libharfbuzz.la $(HBLIBS) diff --git a/src/dump-fon.cc b/src/dump-fon.cc deleted file mode 100644 index 401540940..000000000 --- a/src/dump-fon.cc +++ /dev/null @@ -1,555 +0,0 @@ -/* - * Copyright © 2018 Ebrahim Byagowi - * - * This is part of HarfBuzz, a text shaping library. - * - * Permission is hereby granted, without written agreement and without - * license or royalty fees, to use, copy, modify, and distribute this - * software and its documentation for any purpose, provided that the - * above copyright notice and the following two paragraphs appear in - * all copies of this software. - * - * IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE TO ANY PARTY FOR - * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES - * ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN - * IF THE COPYRIGHT HOLDER HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH - * DAMAGE. - * - * THE COPYRIGHT HOLDER SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, - * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND - * FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS - * ON AN "AS IS" BASIS, AND THE COPYRIGHT HOLDER HAS NO OBLIGATION TO - * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. - */ - -#include "hb-static.cc" -#include -#include -#include "hb-open-type-private.hh" - -template struct LEInt; - -template -struct LEInt -{ - public: - inline void set (Type V) - { - v = V; - } - inline operator Type (void) const - { - return v; - } - private: uint8_t v; -}; -template -struct LEInt -{ - public: - inline void set (Type V) - { - v[1] = (V >> 8) & 0xFF; - v[0] = (V ) & 0xFF; - } - inline operator Type (void) const - { - return (v[1] << 8) - + (v[0] ); - } - private: uint8_t v[2]; -}; -template -struct LEInt -{ - public: - inline void set (Type V) - { - v[2] = (V >> 16) & 0xFF; - v[1] = (V >> 8) & 0xFF; - v[0] = (V ) & 0xFF; - } - inline operator Type (void) const - { - return (v[2] << 16) - + (v[1] << 8) - + (v[0] ); - } - private: uint8_t v[3]; -}; -template -struct LEInt -{ - public: - inline void set (Type V) - { - v[3] = (V >> 24) & 0xFF; - v[2] = (V >> 16) & 0xFF; - v[1] = (V >> 8) & 0xFF; - v[0] = (V ) & 0xFF; - } - inline operator Type (void) const - { - return (v[3] << 24) - + (v[2] << 16) - + (v[1] << 8) - + (v[0] ); - } - private: uint8_t v[4]; -}; - -template -struct LEIntType -{ - inline void set (Type i) { v.set (i); } - inline operator Type(void) const { return v; } - inline bool sanitize (OT::hb_sanitize_context_t *c) const - { - TRACE_SANITIZE (this); - return_trace (likely (c->check_struct (this))); - } - protected: - LEInt v; - public: - DEFINE_SIZE_STATIC (Size); -}; - -typedef LEIntType LEUINT8; /* 8-bit unsigned integer. */ -typedef LEIntType LEINT8; /* 8-bit signed integer. */ -typedef LEIntType LEUINT16; /* 16-bit unsigned integer. */ -typedef LEIntType LEINT16; /* 16-bit signed integer. */ -typedef LEIntType LEUINT32; /* 32-bit unsigned integer. */ -typedef LEIntType LEINT32; /* 32-bit signed integer. */ -typedef LEIntType LEUINT24; /* 24-bit unsigned integer. */ - - -struct LE_FONTINFO16 -{ - inline bool sanitize (OT::hb_sanitize_context_t *c, unsigned int length) const - { - TRACE_SANITIZE (this); - return_trace (likely (c->check_struct (this) && c->check_range (this, length))); - } - - // https://msdn.microsoft.com/en-us/library/cc194829.aspx - enum charset_t - { - // dfCharSet possible values and the codepage they are indicating to - ANSI = 0x00, // 1252 - DEFAULT = 0x01, // - SYMBOL = 0x02, // - SHIFTJIS = 0x80, // 932 - HANGUL = 0x81, // 949 - GB2312 = 0x86, // 936 - CHINESEBIG5 = 0x88, // 950 - GREEK = 0xA1, // 1253 - TURKISH = 0xA2, // 1254 - HEBREW = 0xB1, // 1255 - ARABIC = 0xB2, // 1256 - BALTIC = 0xBA, // 1257 - RUSSIAN = 0xCC, // 1251 - THAI = 0xDE, // 874 - EE = 0xEE, // 1250 - OEM = 0xFF // - }; - - inline const char* get_charset() const - { - switch (dfCharSet) { - case ANSI: return "ISO8859"; - case DEFAULT: return "WinDefault"; - case SYMBOL: return "Symbol"; - case SHIFTJIS: return "JISX0208.1983"; - case HANGUL: return "MSHangul"; - case GB2312: return "GB2312.1980"; - case CHINESEBIG5: return "Big5"; - case GREEK: return "CP1253"; - case TURKISH: return "CP1254"; - case HEBREW: return "CP1255"; - case ARABIC: return "CP1256"; - case BALTIC: return "CP1257"; - case RUSSIAN: return "CP1251"; - case THAI: return "CP874"; - case EE: return "CP1250"; - case OEM: return "OEM"; - default: return "Unknown"; - } - } - - inline unsigned int get_version () const - { - return dfVersion; - } - - inline unsigned int get_weight () const - { - return dfWeight; - } - - enum weight_t { - DONTCARE = 0, - THIN = 100, - EXTRALIGHT = 200, - ULTRALIGHT = 200, - LIGHT = 300, - NORMAL = 400, - REGULAR = 400, - MEDIUM = 500, - SEMIBOLD = 600, - DEMIBOLD = 600, - BOLD = 700, - EXTRABOLD = 800, - ULTRABOLD = 800, - HEAVY = 900, - BLACK = 900 - }; - - inline void dump () const - { - // With https://github.com/juanitogan/mkwinfont/blob/master/python/dewinfont.py help - // Should be implemented differently eventually, but for now - unsigned int ctstart; - unsigned int ctsize; - if (dfVersion == 0x200) - { - ctstart = 0x76; - ctsize = 4; - } - else - { - return; // must of ".fon"s are version 2 and even dewinfont V1 implmentation doesn't seem correct - ctstart = 0x94; - ctsize = 6; - } - // unsigned int maxwidth = 0; - for (unsigned int i = dfFirstChar; i < dfLastChar; ++i) - { - unsigned int entry = ctstart + ctsize * (i-dfFirstChar); - unsigned int w = (uint16_t) OT::StructAtOffset (this, entry); - - unsigned int off; - if (ctsize == 4) - off = (uint16_t) OT::StructAtOffset (this, entry+2); - else - off = (uint32_t) OT::StructAtOffset (this, entry+2); - - unsigned int widthbytes = (w + 7) / 8; - for (unsigned int j = 0; j < dfPixHeight; ++j) - { - for (unsigned int k = 0; k < widthbytes; ++k) - { - unsigned int bytepos = off + k * dfPixHeight + j; - const uint8_t b = (uint8_t) OT::StructAtOffset (this, bytepos); - for (unsigned int a = 128; a > 0; a >>= 1) - printf (b & a ? "x" : "."); - } - printf ("\n"); - } - printf ("\n\n"); - } - } - - protected: - LEUINT16 dfVersion; - LEUINT32 dfSize; - LEUINT8 dfCopyright[60]; - LEUINT16 dfType; - LEUINT16 dfPoints; - LEUINT16 dfVertRes; - LEUINT16 dfHorizRes; - LEUINT16 dfAscent; - LEUINT16 dfInternalLeading; - LEUINT16 dfExternalLeading; - LEUINT8 dfItalic; - LEUINT8 dfUnderline; - LEUINT8 dfStrikeOut; - LEUINT16 dfWeight; // see weight_t - LEUINT8 dfCharSet; // see charset_t - LEUINT16 dfPixWidth; - LEUINT16 dfPixHeight; - LEUINT8 dfPitchAndFamily; - LEUINT16 dfAvgWidth; - LEUINT16 dfMaxWidth; - LEUINT8 dfFirstChar; - LEUINT8 dfLastChar; - LEUINT8 dfDefaultChar; - LEUINT8 dfBreakChar; - LEUINT16 dfWidthBytes; - LEUINT32 dfDevice; - LEUINT32 dfFace; - LEUINT32 dfBitsPointer; - LEUINT32 dfBitsOffset; - LEUINT8 dfReserved; -// LEUINT32 dfFlags; -// LEUINT16 dfAspace; -// LEUINT16 dfBspace; -// LEUINT16 dfCspace; -// LEUINT32 dfColorPointer; -// LEUINT32 dfReserved1[4]; - OT::UnsizedArrayOf - dataZ; - public: - DEFINE_SIZE_ARRAY (118, dataZ); -}; - -struct NE_NAMEINFO -{ - friend struct NE_TYPEINFO; - - inline bool sanitize (OT::hb_sanitize_context_t *c, const void *base, unsigned int shift) const - { - TRACE_SANITIZE (this); - return_trace (likely (c->check_struct (this) && - get_font (base, shift).sanitize (c, length << shift))); - } - - inline const LE_FONTINFO16& get_font (const void *base, int shift) const - { - return OT::StructAtOffset (base, offset << shift); - } - - enum resource_type_flag_t { - NONE = 0x0000, - MOVEABLE = 0x0010, - PURE = 0x0020, - PRELOAD = 0x0040 - }; - - protected: - LEUINT16 offset; // Should be shifted with alignmentShiftCount before use - LEUINT16 length; // Should be shifted with alignmentShiftCount before use - LEUINT16 flags; // resource_type_flag_t - LEUINT16 id; - LEUINT16 handle; - LEUINT16 usage; - public: - DEFINE_SIZE_STATIC (12); -}; - -struct NE_TYPEINFO -{ - inline bool sanitize (OT::hb_sanitize_context_t *c, const void *base, unsigned int shift) const - { - TRACE_SANITIZE (this); - return_trace (c->check_struct (this) && resources.sanitize (c, count, base, shift)); - } - - inline unsigned int get_size (void) const - { return 8 + count * NE_NAMEINFO::static_size; } - - inline const NE_TYPEINFO& next () const - { - const NE_TYPEINFO& next = OT::StructAfter (*this); - if (type_id == 0) - return Null(NE_TYPEINFO); - return next; - } - - inline const LE_FONTINFO16& get_font (unsigned int idx, const void *base, int shift) const - { - if (idx < count) - return resources[idx].get_font (base, shift); - return Null(LE_FONTINFO16); - } - - inline unsigned int get_count () const - { - return count; - } - - inline unsigned int get_type_id () const - { - return type_id; - } - - enum type_id_t { - CURSOR = 0x8001, - BITMAP = 0x8002, - ICON = 0x8003, - MENU = 0x8004, - DIALOG = 0x8005, - STRING = 0x8006, - FONT_DIRECTORY = 0x8007, - FONT = 0x8008, - ACCELERATOR_TABLE = 0x8009, - RESOURCE_DATA = 0x800a, - GROUP_CURSOR = 0x800c, - GROUP_ICON = 0x800e, - VERSION = 0x8010 - }; - - protected: - LEUINT16 type_id; // see type_id_t - LEUINT16 count; - LEUINT32 resloader; - OT::UnsizedArrayOf - resources; - public: - DEFINE_SIZE_ARRAY (8, resources); -}; - -struct NE_RESOURCE_TABLE -{ - inline bool sanitize (OT::hb_sanitize_context_t *c, const void *base) const - { - TRACE_SANITIZE (this); - - if (!c->check_struct (this)) - return_trace (false); - - const NE_TYPEINFO* n = &chain; - while (n != &Null(NE_TYPEINFO) && c->check_struct (n) && n->get_type_id () != 0) - { - if (n->get_type_id () == NE_TYPEINFO::FONT) - return_trace (n->sanitize (c, base, alignmentShiftCount)); - n = &n->next(); - } - return_trace (false); - } - - inline unsigned int get_shift_value () const - { - return alignmentShiftCount; - } - - inline const NE_TYPEINFO& get_fonts_entry () const - { - const NE_TYPEINFO* n = &chain; - while (n != &Null(NE_TYPEINFO) && n->get_type_id () != 0) - { - if (n->get_type_id () == NE_TYPEINFO::FONT) - return *n; - n = &n->next(); - } - return Null(NE_TYPEINFO); - } - - protected: - LEUINT16 alignmentShiftCount; - NE_TYPEINFO chain; - // It is followed by an array of OT::ArrayOf chars; - public: - DEFINE_SIZE_MIN (2); -}; - -// https://github.com/wine-mirror/wine/blob/master/include/winnt.h#L2467 -struct LE_IMAGE_OS2_HEADER -{ - inline bool sanitize (OT::hb_sanitize_context_t *c, const void *base) const - { - TRACE_SANITIZE (this); - return_trace (likely (c->check_struct (this) && (this+rsrctab).sanitize (c, base))); - } - - inline const NE_RESOURCE_TABLE& get_resource_table () const - { - if (magic != 0x454E) // Only NE containers are support for now, NE == 0x454E - return Null(NE_RESOURCE_TABLE); - return this+rsrctab; - } - - protected: - LEUINT16 magic; /* 00 NE signature 'NE' */ - LEUINT8 ver; /* 02 Linker version number */ - LEUINT8 rev; /* 03 Linker revision number */ - LEUINT16 enttab; /* 04 Offset to entry table relative to NE */ - LEUINT16 cbenttab; /* 06 Length of entry table in bytes */ - LEUINT32 crc; /* 08 Checksum */ - LEUINT16 flags; /* 0c Flags about segments in this file */ - LEUINT16 autodata; /* 0e Automatic data segment number */ - LEUINT16 heap; /* 10 Initial size of local heap */ - LEUINT16 stack; /* 12 Initial size of stack */ - LEUINT32 csip; /* 14 Initial CS:IP */ - LEUINT32 sssp; /* 18 Initial SS:SP */ - LEUINT16 cseg; /* 1c # of entries in segment table */ - LEUINT16 cmod; /* 1e # of entries in module reference tab. */ - LEUINT16 cbnrestab; /* 20 Length of nonresident-name table */ - LEUINT16 segtab; /* 22 Offset to segment table */ - OT::OffsetTo - rsrctab; /* 24 Offset to resource table */ - LEUINT16 restab; /* 26 Offset to resident-name table */ - LEUINT16 modtab; /* 28 Offset to module reference table */ - LEUINT16 imptab; /* 2a Offset to imported name table */ - LEUINT32 nrestab; /* 2c Offset to nonresident-name table */ - LEUINT16 cmovent; /* 30 # of movable entry points */ - LEUINT16 align; /* 32 Logical sector alignment shift count */ - LEUINT16 cres; /* 34 # of resource segments */ - LEUINT8 exetyp; /* 36 Flags indicating target OS */ - LEUINT8 flagsothers; /* 37 Additional information flags */ - LEUINT16 pretthunks; /* 38 Offset to return thunks */ - LEUINT16 psegrefbytes; /* 3a Offset to segment ref. bytes */ - LEUINT16 swaparea; /* 3c Reserved by Microsoft */ - LEUINT16 expver; /* 3e Expected Windows version number */ - public: - DEFINE_SIZE_STATIC (64); -}; - -struct LE_IMAGE_DOS_HEADER { - inline bool sanitize (OT::hb_sanitize_context_t *c) const - { - TRACE_SANITIZE (this); - return_trace (likely (c->check_struct (this) && - get_os2_header ().sanitize (c, this))); - } - - inline const LE_IMAGE_OS2_HEADER& get_os2_header () const - { - return this+e_lfanew; - } - - protected: - LEUINT16 e_magic; // Magic number - LEUINT16 e_cblp; // Bytes on last page of file - LEUINT16 e_cp; // Pages in file - LEUINT16 e_crlc; // Relocations - LEUINT16 e_cparhdr; // Size of header in paragraphs - LEUINT16 e_minalloc; // Minimum extra paragraphs needed - LEUINT16 e_maxalloc; // Maximum extra paragraphs needed - LEUINT16 e_ss; // Initial (relative) SS value - LEUINT16 e_sp; // Initial SP value - LEUINT16 e_csum; // Checksum - LEUINT16 e_ip; // Initial IP value - LEUINT16 e_cs; // Initial (relative) CS value - LEUINT16 e_lfarlc; // File address of relocation table - LEUINT16 e_ovno; // Overlay number - LEUINT16 e_res_0; // Reserved words - LEUINT16 e_res_1; // Reserved words - LEUINT16 e_res_2; // Reserved words - LEUINT16 e_res_3; // Reserved words - LEUINT16 e_oemid; // OEM identifier (for e_oeminfo) - LEUINT16 e_oeminfo; // OEM information; e_oemid specific - LEUINT16 e_res2_0; // Reserved words - LEUINT16 e_res2_1; // Reserved words - LEUINT16 e_res2_2; // Reserved words - LEUINT16 e_res2_3; // Reserved words - LEUINT16 e_res2_4; // Reserved words - LEUINT16 e_res2_5; // Reserved words - LEUINT16 e_res2_6; // Reserved words - LEUINT16 e_res2_7; // Reserved words - LEUINT16 e_res2_8; // Reserved words - LEUINT16 e_res2_9; // Reserved words - OT::OffsetTo - e_lfanew; // File address of new exe header - public: - DEFINE_SIZE_STATIC (64); -}; - -int main (int argc, char** argv) { - hb_blob_t *blob = hb_blob_create_from_file (argv[1]); - - OT::Sanitizer sanitizer; - hb_blob_t *font_blob = sanitizer.sanitize (blob); - const LE_IMAGE_DOS_HEADER* dos_header = font_blob->as (); - - const NE_RESOURCE_TABLE &rtable = dos_header->get_os2_header ().get_resource_table (); - int shift = rtable.get_shift_value (); - const NE_TYPEINFO& entry = rtable.get_fonts_entry (); - for (unsigned int i = 0; i < entry.get_count (); ++i) - { - const LE_FONTINFO16& font = entry.get_font (i, dos_header, shift); - printf ("version: %x, weight: %d, charset: %s\n", font.get_version (), - font.get_weight (), font.get_charset ()); - // font.dump (); - } - return 0; -} From 0c1b287b72e91e0898d75acb5d5acf1c6b9a7498 Mon Sep 17 00:00:00 2001 From: Ebrahim Byagowi Date: Sat, 21 Jul 2018 21:14:48 +0430 Subject: [PATCH 078/106] Add a new API, hb_ot_layout_get_feature_name_ids (#976) This new API returns cvXX and ssXX related NameId, things like featUiLabelNameId, featUiTooltipTextNameId, sampleTextNameId, ... of cvXX and UINameId of ssXX, in a unified way. However HarfBuzz currently doesn't expose an API for retrieving the actual information associated with NameId from the `name` table and that should be done separately. --- docs/harfbuzz-sections.txt | 1 + src/hb-ot-layout-common-private.hh | 14 +++++ src/hb-ot-layout.cc | 86 ++++++++++++++++++++++++++++++ src/hb-ot-layout.h | 8 +++ 4 files changed, 109 insertions(+) diff --git a/docs/harfbuzz-sections.txt b/docs/harfbuzz-sections.txt index 5715d7716..b93cd1d60 100644 --- a/docs/harfbuzz-sections.txt +++ b/docs/harfbuzz-sections.txt @@ -450,6 +450,7 @@ hb_ot_layout_collect_lookups hb_ot_layout_feature_get_lookups hb_ot_layout_feature_with_variations_get_lookups hb_ot_layout_get_attach_points +hb_ot_layout_get_feature_name_ids hb_ot_layout_get_glyph_class hb_ot_layout_get_glyphs_in_class hb_ot_layout_get_ligature_carets diff --git a/src/hb-ot-layout-common-private.hh b/src/hb-ot-layout-common-private.hh index 2ae1157dc..21caf9e95 100644 --- a/src/hb-ot-layout-common-private.hh +++ b/src/hb-ot-layout-common-private.hh @@ -478,6 +478,20 @@ struct FeatureParams return Null(FeatureParamsSize); } + inline const FeatureParamsStylisticSet& get_stylistic_set_params (hb_tag_t tag) const + { + if ((tag & 0xFFFF0000u) == HB_TAG ('s','s','\0','\0')) /* ssXX */ + return u.stylisticSet; + return Null(FeatureParamsStylisticSet); + } + + inline const FeatureParamsCharacterVariants& get_character_variants_params (hb_tag_t tag) const + { + if ((tag & 0xFFFF0000u) == HB_TAG ('c','v','\0','\0')) /* cvXX */ + return u.characterVariants; + return Null(FeatureParamsCharacterVariants); + } + private: union { FeatureParamsSize size; diff --git a/src/hb-ot-layout.cc b/src/hb-ot-layout.cc index 3a0823073..3bfa19127 100644 --- a/src/hb-ot-layout.cc +++ b/src/hb-ot-layout.cc @@ -1016,6 +1016,24 @@ hb_ot_layout_position_finish_offsets (hb_font_t *font, hb_buffer_t *buffer) OT::GPOS::position_finish_offsets (font, buffer); } +static const OT::FeatureParams& +_get_gsubgpos_matched_feature_params (hb_face_t *face, hb_tag_t feature) +{ + const OT::GSUB &gsub = _get_gsub (face); + unsigned int gsub_num_features = gsub.get_feature_count (); + for (unsigned int i = 0; i < gsub_num_features; i++) + if (feature == gsub.get_feature_tag (i)) + return gsub.get_feature (i).get_feature_params (); + + const OT::GPOS &gpos = _get_gpos (face); + unsigned int gpos_num_features = gpos.get_feature_count (); + for (unsigned int i = 0; i < gpos_num_features; i++) + if (feature == gpos.get_feature_tag (i)) + return gpos.get_feature (i).get_feature_params (); + + return Null (OT::FeatureParams); +} + /** * hb_ot_layout_get_size_params: * @@ -1066,6 +1084,74 @@ hb_ot_layout_get_size_params (hb_face_t *face, return false; } +/** + * hb_ot_layout_get_feature_name_ids: + * @face: #hb_face_t to work upon + * @feature: ssXX and cvXX tag + * @label_id: (out) (allow-none): The ‘name’ table name ID that specifies a string + * for a user-interface label for this feature. (May be NULL.) + * @tooltip_id: (out) (allow-none): The ‘name’ table name ID that specifies a string + * that an application can use for tooltip text for this + * feature. (May be NULL.) + * @sample_id: (out) (allow-none): The ‘name’ table name ID that specifies sample text + * that illustrates the effect of this feature. (May be NULL.) + * @num_named_parameters: (out) (allow-none): Number of named parameters. (May be zero.) + * @first_param_id: (out) (allow-none): The first ‘name’ table name ID used to specify + * strings for user-interface labels for the feature + * parameters. (Must be zero if numParameters is zero.) + * + * Return value: true if could find any feature with the tag, false otherwise + * + * Since: REPLACEME + **/ +hb_bool_t +hb_ot_layout_get_feature_name_ids (hb_face_t *face, + hb_tag_t feature, + unsigned int *label_id, /* OUT. May be nullptr */ + unsigned int *tooltip_id, /* OUT. May be nullptr */ + unsigned int *sample_id, /* OUT. May be nullptr */ + unsigned int *num_named_parameters, /* OUT. May be nullptr */ + unsigned int *first_param_id /* OUT. May be nullptr */) +{ + const OT::FeatureParams &feature_params = + _get_gsubgpos_matched_feature_params (face, feature); + if (&feature_params != &Null (OT::FeatureParams)) + { + const OT::FeatureParamsStylisticSet& ss_params = + feature_params.get_stylistic_set_params (feature); + if (&ss_params != &Null (OT::FeatureParamsStylisticSet)) /* ssXX */ + { +#define PARAM(a, A) if (a) *a = A + PARAM(label_id, ss_params.uiNameID); + // ssXX features don't have the rest + PARAM(tooltip_id, 0); + PARAM(sample_id, 0); + PARAM(num_named_parameters, 0); + PARAM(first_param_id, 0); + return true; + } + const OT::FeatureParamsCharacterVariants& cv_params = + feature_params.get_character_variants_params (feature); + if (&cv_params != &Null (OT::FeatureParamsCharacterVariants)) /* cvXX */ + { + PARAM(label_id, cv_params.featUILableNameID); + PARAM(tooltip_id, cv_params.featUITooltipTextNameID); + PARAM(sample_id, cv_params.sampleTextNameID); + PARAM(num_named_parameters, cv_params.numNamedParameters); + PARAM(first_param_id, cv_params.firstParamUILabelNameID); + return true; + } + } + + PARAM(label_id, 0); + PARAM(tooltip_id, 0); + PARAM(sample_id, 0); + PARAM(num_named_parameters, 0); + PARAM(first_param_id, 0); +#undef PARAM + return false; +} + /* * Parts of different types are implemented here such that they have direct diff --git a/src/hb-ot-layout.h b/src/hb-ot-layout.h index 027879622..f8597673f 100644 --- a/src/hb-ot-layout.h +++ b/src/hb-ot-layout.h @@ -322,6 +322,14 @@ hb_ot_layout_get_size_params (hb_face_t *face, unsigned int *range_start, /* OUT. May be NULL */ unsigned int *range_end /* OUT. May be NULL */); +HB_EXTERN hb_bool_t +hb_ot_layout_get_feature_name_ids (hb_face_t *face, + hb_tag_t feature, + unsigned int *label_id /* OUT. May be NULL */, + unsigned int *tooltip_id /* OUT. May be NULL */, + unsigned int *sample_id /* OUT. May be NULL */, + unsigned int *num_named_parameters /* OUT. May be NULL */, + unsigned int *first_param_id /* OUT. May be NULL */); /* * BASE From 62fa7cd1ccff4d4448ef84f9cc146464672636aa Mon Sep 17 00:00:00 2001 From: David Corbett Date: Fri, 13 Apr 2018 18:45:37 -0400 Subject: [PATCH 079/106] Order Chakma split vowels in accordance with NFC Fixes #1105. --- src/gen-use-table.py | 10 +++++++++ src/hb-ot-shape-complex-use-table.cc | 4 ++-- src/hb-ot-shape-complex-use.cc | 21 +----------------- ...670df15b73a5dc75a5cc491bde5ac93c5077dc.ttf | Bin 0 -> 1344 bytes test/shaping/data/in-house/tests/use.tests | 5 +++++ 5 files changed, 18 insertions(+), 22 deletions(-) create mode 100644 test/shaping/data/in-house/fonts/2a670df15b73a5dc75a5cc491bde5ac93c5077dc.ttf diff --git a/src/gen-use-table.py b/src/gen-use-table.py index e7c621cac..c742ebaca 100755 --- a/src/gen-use-table.py +++ b/src/gen-use-table.py @@ -328,6 +328,9 @@ def map_to_use(data): # TODO: https://github.com/harfbuzz/harfbuzz/pull/626 if U == 0xA8B4: UISC = Consonant_Medial + # TODO: https://github.com/harfbuzz/harfbuzz/issues/1105 + if U == 0x11134: UISC = Gemination_Mark + values = [k for k,v in items if v(U,UISC,UGC)] assert len(values) == 1, "%s %s %s %s" % (hex(U), UISC, UGC, values) USE = values[0] @@ -356,6 +359,13 @@ def map_to_use(data): # https://github.com/roozbehp/unicode-data/issues/8 if U == 0x0A51: UIPC = Bottom + # TODO: https://github.com/harfbuzz/harfbuzz/pull/982 + if UBlock == 'Chakma' and is_VOWEL (U, UISC, UGC): + if UIPC == Top: + UIPC = Bottom + elif UIPC == Bottom: + UIPC = Top + assert (UIPC in [Not_Applicable, Visual_Order_Left] or USE in use_positions), "%s %s %s %s %s" % (hex(U), UIPC, USE, UISC, UGC) diff --git a/src/hb-ot-shape-complex-use-table.cc b/src/hb-ot-shape-complex-use-table.cc index 25f7bf427..9c796f051 100644 --- a/src/hb-ot-shape-complex-use-table.cc +++ b/src/hb-ot-shape-complex-use-table.cc @@ -510,8 +510,8 @@ static const USE_TABLE_ELEMENT_TYPE use_table[] = { /* 11100 */ VMAbv, VMAbv, VMAbv, B, B, B, B, B, B, B, B, B, B, B, B, B, /* 11110 */ B, B, B, B, B, B, B, B, B, B, B, B, B, B, B, B, - /* 11120 */ B, B, B, B, B, B, B, VAbv, VAbv, VAbv, VBlw, VBlw, VPre, VAbv, VAbv, VAbv, - /* 11130 */ VAbv, VBlw, VBlw, H, VAbv, O, B, B, B, B, B, B, B, B, B, B, + /* 11120 */ B, B, B, B, B, B, B, VBlw, VBlw, VBlw, VAbv, VAbv, VPre, VBlw, VAbv, VAbv, + /* 11130 */ VBlw, VAbv, VAbv, H, CMAbv, O, B, B, B, B, B, B, B, B, B, B, /* 11140 */ O, O, O, O, B, VPst, VPst, O, O, O, O, O, O, O, O, O, /* Mahajani */ diff --git a/src/hb-ot-shape-complex-use.cc b/src/hb-ot-shape-complex-use.cc index 66b95711c..f8e86c9d6 100644 --- a/src/hb-ot-shape-complex-use.cc +++ b/src/hb-ot-shape-complex-use.cc @@ -560,25 +560,6 @@ reorder (const hb_ot_shape_plan_t *plan, HB_BUFFER_DEALLOCATE_VAR (buffer, use_category); } -static bool -decompose_use (const hb_ot_shape_normalize_context_t *c, - hb_codepoint_t ab, - hb_codepoint_t *a, - hb_codepoint_t *b) -{ - switch (ab) - { - /* Chakma: - * Special case where the Unicode decomp gives matras in the wrong order - * for cluster validation. - */ - case 0x1112Eu : *a = 0x11127u; *b= 0x11131u; return true; - case 0x1112Fu : *a = 0x11127u; *b= 0x11132u; return true; - } - - return (bool) c->unicode->decompose (ab, a, b); -} - static bool compose_use (const hb_ot_shape_normalize_context_t *c, hb_codepoint_t a, @@ -602,7 +583,7 @@ const hb_ot_complex_shaper_t _hb_ot_complex_shaper_use = nullptr, /* preprocess_text */ nullptr, /* postprocess_glyphs */ HB_OT_SHAPE_NORMALIZATION_MODE_COMPOSED_DIACRITICS_NO_SHORT_CIRCUIT, - decompose_use, + nullptr, /* decompose */ compose_use, setup_masks_use, nullptr, /* disable_otl */ diff --git a/test/shaping/data/in-house/fonts/2a670df15b73a5dc75a5cc491bde5ac93c5077dc.ttf b/test/shaping/data/in-house/fonts/2a670df15b73a5dc75a5cc491bde5ac93c5077dc.ttf new file mode 100644 index 0000000000000000000000000000000000000000..a1fef49039ec313fddd166cb2295ca65b80fdc58 GIT binary patch literal 1344 zcmZ`(O=whC6#nj=zeH1$H+@Wgka0-HWYJccd6OA2g3_5JqJmNb6%tIwB$KEa9n^>h z30b%hLCiu5V#q>fl|`UZD1zW#vk}uSN(&YWEp#J-BBJm0yXVbFH1s~s`ObIGJ?EZ# z?wx@G(1Zm9aA2^|KY(^L0HFkD<42G0PA?6Q{S5?ekdKX*ixqUotK|QXFHIFMRy>c9 z2(^(nOwC*^ecSVL7wt7bw@ptLC%%|_Kg#ts=d#nB2vpQb@(J?fbotU1edoh-@+0K2 zne*dCeMsLU50bZ(i&rYJQDm;a$P?#^oqSK_{KZS}#ugXJACV9995$M@ ztrLi#8LilX9_&UA`!R^4_#UhTnQS^{hdaA#7_MRTGfdWau!jG~V>N$0pPGnvM57%G zmeDt(9hTMcLhOvpyJrQ|9r3tdePmo+^F0*TE#LFhq>1*4ZWZm`5>ST?SX+gRm~EnB zTcct(i5?bjPBfc{oq&3-?xPVF5Vd1YI-BY4>a6$R)ac&6(wTjIKg>UvpMRk2Yo+nI zQ*TzU&aKWd&|Oz=y@Fmc_pNeH#9hySlUHx6RbH1{^|IbE@tHdizqVtark8-PTer8j zH*Xts1{`O=M1Qy+Z*PmY9xSBNg%q@($@_z^u!Z-!DaS7x<4YSuS>cd+=DyMmQejuG z!rbzrJ}qBKZDY zw>#uz`O;R%8`xPH>M}ZY7i=w^cGul1zahGqORsoYjOZ@IwY{l^AcE>=wTKYCcQt=K zxb36*7mjK)mltB+>q8?^H*u`gKY@jvYn~TyJcoO%;0c`@Pni&A4q*f5^>>)W6lO6)`$E0%-U1w{=yMfe8?*|jpbDw5ibQ75 rolf`W^WoW4DwWRokn^Emz)AU#F_{$4&$H0-&ux0Dcxs~q^3nGn$ll-> literal 0 HcmV?d00001 diff --git a/test/shaping/data/in-house/tests/use.tests b/test/shaping/data/in-house/tests/use.tests index 172946c49..4b46620bb 100644 --- a/test/shaping/data/in-house/tests/use.tests +++ b/test/shaping/data/in-house/tests/use.tests @@ -2,4 +2,9 @@ ../fonts/4cce528e99f600ed9c25a2b69e32eb94a03b4ae8.ttf::U+1A48,U+1A58,U+1A25,U+1A48,U+1A58,U+1A25,U+1A6E,U+1A63:[uni1A48=0+1212|uni1A25=0+1912|uni1A58=0+0|uni1A48=3+1212|uni1A6E=3+0|uni1A25=3+1912|uni1A58=3+0|uni1A63=3+1212] ../fonts/f518eb6f6b5eec2946c9fbbbde44e45d46f5e2ac.ttf::U+1A48,U+1A58,U+1A25,U+1A48,U+1A58,U+1A25,U+1A6E,U+1A63:[uni1A48=0+1212|uni1A25=0+1912|uni1A58=0+0|uni1A48=3+1212|uni1A6E=3+1211|uni1A25=3+1912|uni1A58=3+0|uni1A63=3+1212] ../fonts/6ff0fbead4462d9f229167b4e6839eceb8465058.ttf:--font-funcs=ot:U+11103,U+11128:[u11103=0+837|u11128=0+0] +../fonts/2a670df15b73a5dc75a5cc491bde5ac93c5077dc.ttf::U+11124,U+1112E:[u11124=0+514|u11131=0+0|u11127=0+0] +../fonts/2a670df15b73a5dc75a5cc491bde5ac93c5077dc.ttf::U+11124,U+11131,U+11127:[u11124=0+514|u11131=0+0|u11127=0+0] +../fonts/2a670df15b73a5dc75a5cc491bde5ac93c5077dc.ttf::U+11124,U+11127,U+11131:[u11124=0+514|u11127=0+0|uni25CC=0+547|u11131=0+0] +../fonts/2a670df15b73a5dc75a5cc491bde5ac93c5077dc.ttf::U+11124,U+11134,U+11131:[u11124=0+514|u11134=0+0|u11131=0+0] +../fonts/2a670df15b73a5dc75a5cc491bde5ac93c5077dc.ttf::U+11124,U+11131,U+11134:[u11124=0+514|u11131=0+0|uni25CC=0+547|u11134=0+0] ../fonts/573d3a3177c9a8646e94c8a0d7b224334340946a.ttf:--font-funcs=ft:U+11410,U+11442,U+11411,U+11440,U+11443,U+11410,U+11442,U+11411,U+11441,U+11443:[E_dv.alt=0+275|Ga.icd=0+367|Gha.diag=0@100,0+386|AA_dv.alt=0+208|Candrabindu=0@17,-8+0|E_dv.alt=5+275|Ga.icd=5+367|Gha.diag=5@100,0+386|AU_dv_part.alt=5+213|Candrabindu.sm=5@-52,179+0] From e7737b41d793bfce9455d1797eb5e0af60794f23 Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Sun, 22 Jul 2018 22:24:31 -0700 Subject: [PATCH 080/106] Add sanitizer reference_table, also fix clang build Clang is being really peculiar. Fix with: - inline hb_blob_t *sanitize (hb_blob_t *blob) { return c->sanitize (blob); } + inline hb_blob_t *sanitize (hb_blob_t *blob) { return c[0].template/*clang idiosyncrasy*/sanitize_blob (blob); } --- src/hb-open-type-private.hh | 10 ++++++++-- src/hb-ot-post-table.hh | 2 +- src/hb-subset-glyf.cc | 2 +- src/hb-uniscribe.cc | 2 +- 4 files changed, 11 insertions(+), 5 deletions(-) diff --git a/src/hb-open-type-private.hh b/src/hb-open-type-private.hh index 457e58c4a..92a5142ee 100644 --- a/src/hb-open-type-private.hh +++ b/src/hb-open-type-private.hh @@ -279,7 +279,7 @@ struct hb_sanitize_context_t : } template - inline hb_blob_t *sanitize (hb_blob_t *blob) + inline hb_blob_t *sanitize_blob (hb_blob_t *blob) { bool sane; @@ -345,6 +345,12 @@ struct hb_sanitize_context_t : } } + template + inline hb_blob_t *reference_table (hb_face_t *face, hb_tag_t tableTag = Type::tableTag) + { + return sanitize_blob (face->reference_table (tableTag)); + } + mutable unsigned int debug_depth; const char *start, *end; private: @@ -362,7 +368,7 @@ template struct Sanitizer { inline Sanitizer (unsigned int num_glyphs = 0) { c->set_num_glyphs (num_glyphs); } - inline hb_blob_t *sanitize (hb_blob_t *blob) { return c->sanitize (blob); } + inline hb_blob_t *sanitize (hb_blob_t *blob) { return c[0].template/*clang idiosyncrasy*/sanitize_blob (blob); } private: hb_sanitize_context_t c[1]; diff --git a/src/hb-ot-post-table.hh b/src/hb-ot-post-table.hh index d05fc091c..fed43d470 100644 --- a/src/hb-ot-post-table.hh +++ b/src/hb-ot-post-table.hh @@ -85,7 +85,7 @@ struct post inline bool subset (hb_subset_plan_t *plan) const { unsigned int post_prime_length; - hb_blob_t *post_blob = OT::Sanitizer().sanitize (hb_face_reference_table (plan->source, HB_OT_TAG_post)); + hb_blob_t *post_blob = OT::hb_sanitize_context_t().reference_table(plan->source); hb_blob_t *post_prime_blob = hb_blob_create_sub_blob (post_blob, 0, post::static_size); post *post_prime = (post *) hb_blob_get_data_writable (post_prime_blob, &post_prime_length); hb_blob_destroy (post_blob); diff --git a/src/hb-subset-glyf.cc b/src/hb-subset-glyf.cc index c8fa39be8..2b97a010a 100644 --- a/src/hb-subset-glyf.cc +++ b/src/hb-subset-glyf.cc @@ -292,7 +292,7 @@ hb_subset_glyf_and_loca (hb_subset_plan_t *plan, hb_blob_t **glyf_prime, /* OUT */ hb_blob_t **loca_prime /* OUT */) { - hb_blob_t *glyf_blob = OT::Sanitizer().sanitize (plan->source->reference_table (HB_OT_TAG_glyf)); + hb_blob_t *glyf_blob = OT::hb_sanitize_context_t().reference_table (plan->source); const char *glyf_data = hb_blob_get_data(glyf_blob, nullptr); OT::glyf::accelerator_t glyf; diff --git a/src/hb-uniscribe.cc b/src/hb-uniscribe.cc index b17fa31ca..0199e65f8 100644 --- a/src/hb-uniscribe.cc +++ b/src/hb-uniscribe.cc @@ -358,7 +358,7 @@ _hb_rename_font (hb_blob_t *blob, wchar_t *new_name) * full, PS. All of them point to the same name data with our unique name. */ - blob = OT::Sanitizer().sanitize (blob); + blob = OT::hb_sanitize_context_t().sanitize_blob (blob); unsigned int length, new_length, name_str_len; const char *orig_sfnt_data = hb_blob_get_data (blob, &length); From 9583e0077d0a3a043f8b5bd23925014e04da8d32 Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Sun, 22 Jul 2018 22:40:32 -0700 Subject: [PATCH 081/106] Port more off of Sanitizer<> --- src/hb-face.cc | 4 ++-- src/hb-open-type-private.hh | 2 +- src/hb-ot-cmap-table.hh | 2 +- src/hb-ot-color-cbdt-table.hh | 4 ++-- src/hb-ot-color-svg-table.hh | 4 +--- src/hb-ot-glyf-table.hh | 8 ++++---- src/hb-ot-hmtx-table.hh | 10 +++++----- src/hb-ot-kern-table.hh | 2 +- src/hb-ot-layout.cc | 6 +++--- src/hb-ot-maxp-table.hh | 2 +- src/hb-ot-os2-table.hh | 2 +- src/hb-ot-post-table.hh | 2 +- src/hb-subset.cc | 4 +--- 13 files changed, 24 insertions(+), 28 deletions(-) diff --git a/src/hb-face.cc b/src/hb-face.cc index 3c22f654f..c492adc24 100644 --- a/src/hb-face.cc +++ b/src/hb-face.cc @@ -451,7 +451,7 @@ hb_face_get_upem (hb_face_t *face) void hb_face_t::load_upem (void) const { - hb_blob_t *head_blob = OT::Sanitizer().sanitize (reference_table (HB_OT_TAG_head)); + hb_blob_t *head_blob = OT::hb_sanitize_context_t().reference_table (this); const OT::head *head_table = head_blob->as (); upem = head_table->get_upem (); hb_blob_destroy (head_blob); @@ -495,7 +495,7 @@ hb_face_get_glyph_count (hb_face_t *face) void hb_face_t::load_num_glyphs (void) const { - hb_blob_t *maxp_blob = OT::Sanitizer().sanitize (reference_table (HB_OT_TAG_maxp)); + hb_blob_t *maxp_blob = OT::hb_sanitize_context_t().reference_table (this); const OT::maxp *maxp_table = maxp_blob->as (); num_glyphs = maxp_table->get_num_glyphs (); hb_blob_destroy (maxp_blob); diff --git a/src/hb-open-type-private.hh b/src/hb-open-type-private.hh index 92a5142ee..9a059a4e7 100644 --- a/src/hb-open-type-private.hh +++ b/src/hb-open-type-private.hh @@ -346,7 +346,7 @@ struct hb_sanitize_context_t : } template - inline hb_blob_t *reference_table (hb_face_t *face, hb_tag_t tableTag = Type::tableTag) + inline hb_blob_t *reference_table (const hb_face_t *face, hb_tag_t tableTag = Type::tableTag) { return sanitize_blob (face->reference_table (tableTag)); } diff --git a/src/hb-ot-cmap-table.hh b/src/hb-ot-cmap-table.hh index 0ea37209a..22cdbaf33 100644 --- a/src/hb-ot-cmap-table.hh +++ b/src/hb-ot-cmap-table.hh @@ -894,7 +894,7 @@ struct cmap { inline void init (hb_face_t *face) { - this->blob = OT::Sanitizer().sanitize (face->reference_table (HB_OT_TAG_cmap)); + this->blob = OT::hb_sanitize_context_t().reference_table (face); const OT::cmap *cmap = this->blob->as (); const OT::CmapSubtable *subtable = nullptr; const OT::CmapSubtableFormat14 *subtable_uvs = nullptr; diff --git a/src/hb-ot-color-cbdt-table.hh b/src/hb-ot-color-cbdt-table.hh index d1dd9de47..21c2f4773 100644 --- a/src/hb-ot-color-cbdt-table.hh +++ b/src/hb-ot-color-cbdt-table.hh @@ -394,8 +394,8 @@ struct CBDT { upem = hb_face_get_upem (face); - cblc_blob = Sanitizer().sanitize (face->reference_table (HB_OT_TAG_CBLC)); - cbdt_blob = Sanitizer().sanitize (face->reference_table (HB_OT_TAG_CBDT)); + cblc_blob = hb_sanitize_context_t().reference_table (face); + cbdt_blob = hb_sanitize_context_t().reference_table (face); cbdt_len = hb_blob_get_length (cbdt_blob); if (hb_blob_get_length (cblc_blob) == 0) { diff --git a/src/hb-ot-color-svg-table.hh b/src/hb-ot-color-svg-table.hh index ed6cf9708..9bfd266c7 100644 --- a/src/hb-ot-color-svg-table.hh +++ b/src/hb-ot-color-svg-table.hh @@ -96,11 +96,9 @@ struct SVG { inline void init (hb_face_t *face) { - OT::Sanitizer sanitizer; - svg_blob = sanitizer.sanitize (face->reference_table (HB_OT_TAG_SVG)); + svg_blob = OT::hb_sanitize_context_t().reference_table (face); svg_len = hb_blob_get_length (svg_blob); svg = svg_blob->as (); - } inline void fini (void) diff --git a/src/hb-ot-glyf-table.hh b/src/hb-ot-glyf-table.hh index 89c867dfa..b670d792f 100644 --- a/src/hb-ot-glyf-table.hh +++ b/src/hb-ot-glyf-table.hh @@ -103,7 +103,7 @@ struct glyf static bool _add_head_and_set_loca_version (hb_subset_plan_t *plan, bool use_short_loca) { - hb_blob_t *head_blob = OT::Sanitizer().sanitize (hb_face_reference_table (plan->source, HB_OT_TAG_head)); + hb_blob_t *head_blob = OT::hb_sanitize_context_t().reference_table (plan->source); hb_blob_t *head_prime_blob = hb_blob_copy_writable_or_fail (head_blob); hb_blob_destroy (head_blob); @@ -236,7 +236,7 @@ struct glyf { memset (this, 0, sizeof (accelerator_t)); - hb_blob_t *head_blob = Sanitizer().sanitize (face->reference_table (HB_OT_TAG_head)); + hb_blob_t *head_blob = hb_sanitize_context_t().reference_table (face); const head *head_table = head_blob->as (); if (head_table == &Null(head) || (unsigned int) head_table->indexToLocFormat > 1 || head_table->glyphDataFormat != 0) { @@ -247,9 +247,9 @@ struct glyf short_offset = 0 == head_table->indexToLocFormat; hb_blob_destroy (head_blob); - loca_blob = Sanitizer().sanitize (face->reference_table (HB_OT_TAG_loca)); + loca_blob = hb_sanitize_context_t().reference_table (face); loca_table = loca_blob->as (); - glyf_blob = Sanitizer().sanitize (face->reference_table (HB_OT_TAG_glyf)); + glyf_blob = hb_sanitize_context_t().reference_table (face); glyf_table = glyf_blob->as (); num_glyphs = MAX (1u, hb_blob_get_length (loca_blob) / (short_offset ? 2 : 4)) - 1; diff --git a/src/hb-ot-hmtx-table.hh b/src/hb-ot-hmtx-table.hh index 2c6266453..29cbc3848 100644 --- a/src/hb-ot-hmtx-table.hh +++ b/src/hb-ot-hmtx-table.hh @@ -69,7 +69,7 @@ struct hmtxvmtx inline bool subset_update_header (hb_subset_plan_t *plan, unsigned int num_hmetrics) const { - hb_blob_t *src_blob = OT::Sanitizer ().sanitize (plan->source->reference_table (H::tableTag)); + hb_blob_t *src_blob = OT::hb_sanitize_context_t().reference_table (plan->source, H::tableTag); hb_blob_t *dest_blob = hb_blob_copy_writable_or_fail(src_blob); hb_blob_destroy (src_blob); @@ -195,7 +195,7 @@ struct hmtxvmtx bool got_font_extents = false; if (T::os2Tag) { - hb_blob_t *os2_blob = Sanitizer ().sanitize (face->reference_table (T::os2Tag)); + hb_blob_t *os2_blob = hb_sanitize_context_t().reference_table (face); const os2 *os2_table = os2_blob->as (); #define USE_TYPO_METRICS (1u<<7) if (0 != (os2_table->fsSelection & USE_TYPO_METRICS)) @@ -208,7 +208,7 @@ struct hmtxvmtx hb_blob_destroy (os2_blob); } - hb_blob_t *_hea_blob = Sanitizer ().sanitize (face->reference_table (H::tableTag)); + hb_blob_t *_hea_blob = hb_sanitize_context_t().reference_table (face); const H *_hea_table = _hea_blob->as (); num_advances = _hea_table->numberOfLongMetrics; if (!got_font_extents) @@ -222,7 +222,7 @@ struct hmtxvmtx has_font_extents = got_font_extents; - blob = Sanitizer ().sanitize (face->reference_table (T::tableTag)); + blob = hb_sanitize_context_t().reference_table (face, T::tableTag); /* Cap num_metrics() and num_advances() based on table length. */ unsigned int len = hb_blob_get_length (blob); @@ -240,7 +240,7 @@ struct hmtxvmtx } table = blob->as (); - var_blob = Sanitizer ().sanitize (face->reference_table (T::variationsTag)); + var_blob = hb_sanitize_context_t().reference_table (face, T::variationsTag); var_table = var_blob->as (); } diff --git a/src/hb-ot-kern-table.hh b/src/hb-ot-kern-table.hh index b0fdea4a7..b4d810952 100644 --- a/src/hb-ot-kern-table.hh +++ b/src/hb-ot-kern-table.hh @@ -362,7 +362,7 @@ struct kern { inline void init (hb_face_t *face) { - blob = Sanitizer().sanitize (face->reference_table (HB_OT_TAG_kern)); + blob = hb_sanitize_context_t().reference_table (face); table = blob->as (); table_length = blob->length; } diff --git a/src/hb-ot-layout.cc b/src/hb-ot-layout.cc index 3bfa19127..0eba88a62 100644 --- a/src/hb-ot-layout.cc +++ b/src/hb-ot-layout.cc @@ -54,13 +54,13 @@ _hb_ot_layout_create (hb_face_t *face) if (unlikely (!layout)) return nullptr; - layout->gdef_blob = OT::Sanitizer().sanitize (face->reference_table (HB_OT_TAG_GDEF)); + layout->gdef_blob = OT::hb_sanitize_context_t().reference_table (face); layout->gdef = layout->gdef_blob->as (); - layout->gsub_blob = OT::Sanitizer().sanitize (face->reference_table (HB_OT_TAG_GSUB)); + layout->gsub_blob = OT::hb_sanitize_context_t().reference_table (face); layout->gsub = layout->gsub_blob->as (); - layout->gpos_blob = OT::Sanitizer().sanitize (face->reference_table (HB_OT_TAG_GPOS)); + layout->gpos_blob = OT::hb_sanitize_context_t().reference_table (face); layout->gpos = layout->gpos_blob->as (); layout->math.init (face); diff --git a/src/hb-ot-maxp-table.hh b/src/hb-ot-maxp-table.hh index 390b60d72..d3849fb13 100644 --- a/src/hb-ot-maxp-table.hh +++ b/src/hb-ot-maxp-table.hh @@ -100,7 +100,7 @@ struct maxp inline bool subset (hb_subset_plan_t *plan) const { - hb_blob_t *maxp_blob = OT::Sanitizer().sanitize (hb_face_reference_table (plan->source, HB_OT_TAG_maxp)); + hb_blob_t *maxp_blob = OT::hb_sanitize_context_t().reference_table (plan->source); hb_blob_t *maxp_prime_blob = hb_blob_copy_writable_or_fail (maxp_blob); hb_blob_destroy (maxp_blob); diff --git a/src/hb-ot-os2-table.hh b/src/hb-ot-os2-table.hh index c52b7eb10..5aab56c41 100644 --- a/src/hb-ot-os2-table.hh +++ b/src/hb-ot-os2-table.hh @@ -51,7 +51,7 @@ struct os2 inline bool subset (hb_subset_plan_t *plan) const { - hb_blob_t *os2_blob = OT::Sanitizer().sanitize (hb_face_reference_table (plan->source, HB_OT_TAG_os2)); + hb_blob_t *os2_blob = OT::hb_sanitize_context_t().reference_table (plan->source); hb_blob_t *os2_prime_blob = hb_blob_create_sub_blob (os2_blob, 0, -1); // TODO(grieger): move to hb_blob_copy_writable_or_fail hb_blob_destroy (os2_blob); diff --git a/src/hb-ot-post-table.hh b/src/hb-ot-post-table.hh index fed43d470..1d3058018 100644 --- a/src/hb-ot-post-table.hh +++ b/src/hb-ot-post-table.hh @@ -110,7 +110,7 @@ struct post { index_to_offset.init (); - blob = Sanitizer().sanitize (face->reference_table (HB_OT_TAG_post)); + blob = hb_sanitize_context_t().reference_table (face); const post *table = blob->as (); unsigned int table_length = blob->length; diff --git a/src/hb-subset.cc b/src/hb-subset.cc index a65b58d26..308c7eb21 100644 --- a/src/hb-subset.cc +++ b/src/hb-subset.cc @@ -78,9 +78,7 @@ template static bool _subset (hb_subset_plan_t *plan) { - OT::Sanitizer sanitizer; - - hb_blob_t *source_blob = sanitizer.sanitize (plan->source->reference_table (TableType::tableTag)); + hb_blob_t *source_blob = OT::hb_sanitize_context_t().reference_table (plan->source); const TableType *table = source_blob->as (); hb_tag_t tag = TableType::tableTag; From 740ae27d5c0f5ff87e2ff489fb49d5db1a0c95be Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Sun, 22 Jul 2018 22:40:56 -0700 Subject: [PATCH 082/106] Port sbix off of Sanitizer<> --- src/hb-ot-color-sbix-table.hh | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/hb-ot-color-sbix-table.hh b/src/hb-ot-color-sbix-table.hh index bf644a67f..dcfeef46c 100644 --- a/src/hb-ot-color-sbix-table.hh +++ b/src/hb-ot-color-sbix-table.hh @@ -96,9 +96,7 @@ struct sbix { inline void init (hb_face_t *face) { - /* XXX Using public API instead of private method to avoid link problem in dump_emoji. - * Kill that! */ - sbix_blob = OT::Sanitizer(hb_face_get_glyph_count (face)/*face->get_num_glyphs ()*/).sanitize (face->reference_table (HB_OT_TAG_sbix)); + sbix_blob = OT::hb_sanitize_context_t().reference_table (face); sbix_len = hb_blob_get_length (sbix_blob); sbix_table = sbix_blob->as (); } From 4547051f48ca6aa53309b81a768b5b44c4ab6e3b Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Sun, 22 Jul 2018 22:44:22 -0700 Subject: [PATCH 083/106] Minor --- src/hb-open-file-private.hh | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/hb-open-file-private.hh b/src/hb-open-file-private.hh index 226c48f6a..d47bff66e 100644 --- a/src/hb-open-file-private.hh +++ b/src/hb-open-file-private.hh @@ -484,8 +484,6 @@ struct ResourceForkHeader struct OpenTypeFontFile { - static const hb_tag_t tableTag = HB_TAG ('_','_','_','_'); /* Sanitizer needs this. */ - enum { CFFTag = HB_TAG ('O','T','T','O'), /* OpenType with Postscript outlines */ TrueTypeTag = HB_TAG ( 0 , 1 , 0 , 0 ), /* OpenType with TrueType outlines */ From 14f78d2b3bb1e1292efbd6a3e3f0d618179c171a Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Sun, 22 Jul 2018 22:45:26 -0700 Subject: [PATCH 084/106] . --- src/hb-aat-layout.cc | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/hb-aat-layout.cc b/src/hb-aat-layout.cc index 696dd3558..405aafccb 100644 --- a/src/hb-aat-layout.cc +++ b/src/hb-aat-layout.cc @@ -61,9 +61,7 @@ _get_morx (hb_face_t *face, hb_blob_t **blob = nullptr) // static inline void // _hb_aat_layout_create (hb_face_t *face) // { -// OT::Sanitizer sanitizer; -// sanitizer.set_num_glyphs (face->get_num_glyphs ()); -// hb_blob_t *morx_blob = sanitizer.sanitize (face->reference_table (HB_AAT_TAG_morx)); +// hb_blob_t *morx_blob = OT::hb_sanitize_context_t().reference_table (face); // morx_blob->as (); // if (0) From d6a8f64045ca3bf4c7d01520909fa0c7dfca4d64 Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Sun, 22 Jul 2018 22:47:19 -0700 Subject: [PATCH 085/106] Port dump-emoji away from Sanitizer<> --- src/dump-emoji.cc | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/dump-emoji.cc b/src/dump-emoji.cc index 99e8ef9f3..400b890ad 100644 --- a/src/dump-emoji.cc +++ b/src/dump-emoji.cc @@ -233,12 +233,10 @@ int main (int argc, char **argv) svg.dump (svg_callback); svg.fini (); - OT::Sanitizer sanitizerCOLR; - hb_blob_t* colr_blob = sanitizerCOLR.sanitize (face->reference_table (HB_OT_TAG_COLR)); + hb_blob_t* colr_blob = OT::hb_sanitize_context_t().reference_table (face); const OT::COLR *colr = colr_blob->as (); - OT::Sanitizer sanitizerCPAL; - hb_blob_t* cpal_blob = sanitizerCPAL.sanitize (face->reference_table (HB_OT_TAG_CPAL)); + hb_blob_t* cpal_blob = OT::hb_sanitize_context_t().reference_table (face); const OT::CPAL *cpal = cpal_blob->as (); cairo_font_face_t *cairo_face; From 8e3e41272b3896274459c5961aac813ef2666321 Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Sun, 22 Jul 2018 22:49:26 -0700 Subject: [PATCH 086/106] Port rest of code away from Sanitizer<> --- src/hb-face.cc | 4 ++-- src/main.cc | 3 +-- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/src/hb-face.cc b/src/hb-face.cc index c492adc24..ad44eff59 100644 --- a/src/hb-face.cc +++ b/src/hb-face.cc @@ -53,7 +53,7 @@ hb_face_count (hb_blob_t *blob) return 0; /* TODO We shouldn't be sanitizing blob. Port to run sanitizer and return if not sane. */ - hb_blob_t *sanitized = OT::Sanitizer ().sanitize (hb_blob_reference (blob)); + hb_blob_t *sanitized = OT::hb_sanitize_context_t().sanitize_blob (hb_blob_reference (blob)); const OT::OpenTypeFontFile& ot = *sanitized->as (); unsigned int ret = ot.get_face_count (); hb_blob_destroy (sanitized); @@ -191,7 +191,7 @@ hb_face_create (hb_blob_t *blob, if (unlikely (!blob)) blob = hb_blob_get_empty (); - hb_face_for_data_closure_t *closure = _hb_face_for_data_closure_create (OT::Sanitizer().sanitize (hb_blob_reference (blob)), index); + hb_face_for_data_closure_t *closure = _hb_face_for_data_closure_create (OT::hb_sanitize_context_t().sanitize_blob (hb_blob_reference (blob)), index); if (unlikely (!closure)) return hb_face_get_empty (); diff --git a/src/main.cc b/src/main.cc index 873d240a3..c6e05fc37 100644 --- a/src/main.cc +++ b/src/main.cc @@ -51,8 +51,7 @@ main (int argc, char **argv) const char *font_data = hb_blob_get_data (blob, &len); printf ("Opened font file %s: %d bytes long\n", argv[1], len); - Sanitizer sanitizer; - hb_blob_t *font_blob = sanitizer.sanitize (blob); + hb_blob_t *font_blob = hb_sanitize_context_t().sanitize_blob (blob); const OpenTypeFontFile* sanitized = font_blob->as (); if (sanitized == &Null(OpenTypeFontFile)) { From 9401829d4e93f6f433957fa2d053f3b9d42da557 Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Sun, 22 Jul 2018 22:50:58 -0700 Subject: [PATCH 087/106] Remove Sanitizer<> --- src/hb-open-type-private.hh | 16 +--------------- 1 file changed, 1 insertion(+), 15 deletions(-) diff --git a/src/hb-open-type-private.hh b/src/hb-open-type-private.hh index 9a059a4e7..c59bb6a53 100644 --- a/src/hb-open-type-private.hh +++ b/src/hb-open-type-private.hh @@ -362,20 +362,6 @@ struct hb_sanitize_context_t : }; - -/* Template to sanitize an object. */ -template -struct Sanitizer -{ - inline Sanitizer (unsigned int num_glyphs = 0) { c->set_num_glyphs (num_glyphs); } - inline hb_blob_t *sanitize (hb_blob_t *blob) { return c[0].template/*clang idiosyncrasy*/sanitize_blob (blob); } - - private: - hb_sanitize_context_t c[1]; -}; - - - /* * Serialize */ @@ -1285,7 +1271,7 @@ struct hb_table_lazy_loader_t hb_blob_t *b = (hb_blob_t *) hb_atomic_ptr_get (&blob); if (unlikely (!b)) { - b = OT::Sanitizer(face->get_num_glyphs ()).sanitize (face->reference_table (T::tableTag)); + b = OT::hb_sanitize_context_t().reference_table (face); if (!hb_atomic_ptr_cmpexch (&blob, nullptr, b)) { hb_blob_destroy (b); From c6bc7c38314ea831418fdd1434bbe5afc0875f33 Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Mon, 23 Jul 2018 11:46:46 -0700 Subject: [PATCH 088/106] Set num glyphs on sanitizer reference_table() Move out-of-class definitions of two methods to hb-static so they are accessible in libharfbuzz-subset. --- src/hb-face.cc | 20 -------------------- src/hb-open-type-private.hh | 1 + src/hb-static.cc | 22 ++++++++++++++++++++++ 3 files changed, 23 insertions(+), 20 deletions(-) diff --git a/src/hb-face.cc b/src/hb-face.cc index ad44eff59..fab2aa3a9 100644 --- a/src/hb-face.cc +++ b/src/hb-face.cc @@ -31,8 +31,6 @@ #include "hb-face-private.hh" #include "hb-blob-private.hh" #include "hb-open-file-private.hh" -#include "hb-ot-head-table.hh" -#include "hb-ot-maxp-table.hh" @@ -448,15 +446,6 @@ hb_face_get_upem (hb_face_t *face) return face->get_upem (); } -void -hb_face_t::load_upem (void) const -{ - hb_blob_t *head_blob = OT::hb_sanitize_context_t().reference_table (this); - const OT::head *head_table = head_blob->as (); - upem = head_table->get_upem (); - hb_blob_destroy (head_blob); -} - /** * hb_face_set_glyph_count: * @face: a face. @@ -492,15 +481,6 @@ hb_face_get_glyph_count (hb_face_t *face) return face->get_num_glyphs (); } -void -hb_face_t::load_num_glyphs (void) const -{ - hb_blob_t *maxp_blob = OT::hb_sanitize_context_t().reference_table (this); - const OT::maxp *maxp_table = maxp_blob->as (); - num_glyphs = maxp_table->get_num_glyphs (); - hb_blob_destroy (maxp_blob); -} - /** * hb_face_get_table_tags: * @face: a face. diff --git a/src/hb-open-type-private.hh b/src/hb-open-type-private.hh index c59bb6a53..e2a135562 100644 --- a/src/hb-open-type-private.hh +++ b/src/hb-open-type-private.hh @@ -348,6 +348,7 @@ struct hb_sanitize_context_t : template inline hb_blob_t *reference_table (const hb_face_t *face, hb_tag_t tableTag = Type::tableTag) { + set_num_glyphs (face->get_num_glyphs ()); return sanitize_blob (face->reference_table (tableTag)); } diff --git a/src/hb-static.cc b/src/hb-static.cc index ee17cd348..729b242c5 100644 --- a/src/hb-static.cc +++ b/src/hb-static.cc @@ -25,8 +25,30 @@ */ #include "hb-private.hh" +#include "hb-face-private.hh" +#include "hb-open-type-private.hh" +#include "hb-ot-head-table.hh" +#include "hb-ot-maxp-table.hh" #ifndef HB_NO_VISIBILITY hb_vector_size_impl_t const _hb_NullPool[(HB_NULL_POOL_SIZE + sizeof (hb_vector_size_impl_t) - 1) / sizeof (hb_vector_size_impl_t)] = {}; /*thread_local*/ hb_vector_size_impl_t _hb_CrapPool[(HB_NULL_POOL_SIZE + sizeof (hb_vector_size_impl_t) - 1) / sizeof (hb_vector_size_impl_t)] = {}; #endif + +void +hb_face_t::load_num_glyphs (void) const +{ + hb_blob_t *maxp_blob = OT::hb_sanitize_context_t().reference_table (this); + const OT::maxp *maxp_table = maxp_blob->as (); + num_glyphs = maxp_table->get_num_glyphs (); + hb_blob_destroy (maxp_blob); +} + +void +hb_face_t::load_upem (void) const +{ + hb_blob_t *head_blob = OT::hb_sanitize_context_t().reference_table (this); + const OT::head *head_table = head_blob->as (); + upem = head_table->get_upem (); + hb_blob_destroy (head_blob); +} From 36ed163fdd50419e4619c665a4a9dbf97f66c349 Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Mon, 23 Jul 2018 11:57:45 -0700 Subject: [PATCH 089/106] Remove unnecessary OT:: namespace specifiers --- src/hb-ot-cmap-table.hh | 30 +++++++++++++++--------------- src/hb-ot-color-sbix-table.hh | 4 ++-- src/hb-ot-color-svg-table.hh | 4 ++-- src/hb-ot-glyf-table.hh | 4 ++-- src/hb-ot-hmtx-table.hh | 2 +- src/hb-ot-maxp-table.hh | 6 +++--- src/hb-ot-os2-table.hh | 4 ++-- src/hb-ot-post-table.hh | 2 +- 8 files changed, 28 insertions(+), 28 deletions(-) diff --git a/src/hb-ot-cmap-table.hh b/src/hb-ot-cmap-table.hh index 22cdbaf33..a671da55d 100644 --- a/src/hb-ot-cmap-table.hh +++ b/src/hb-ot-cmap-table.hh @@ -894,10 +894,10 @@ struct cmap { inline void init (hb_face_t *face) { - this->blob = OT::hb_sanitize_context_t().reference_table (face); + this->blob = hb_sanitize_context_t().reference_table (face); const OT::cmap *cmap = this->blob->as (); - const OT::CmapSubtable *subtable = nullptr; - const OT::CmapSubtableFormat14 *subtable_uvs = nullptr; + const CmapSubtable *subtable = nullptr; + const CmapSubtableFormat14 *subtable_uvs = nullptr; bool symbol = false; /* 32-bit subtables. */ @@ -916,35 +916,35 @@ struct cmap if (subtable) symbol = true; } /* Meh. */ - if (!subtable) subtable = &Null(OT::CmapSubtable); + if (!subtable) subtable = &Null(CmapSubtable); /* UVS subtable. */ if (!subtable_uvs) { - const OT::CmapSubtable *st = cmap->find_subtable (0, 5); + const CmapSubtable *st = cmap->find_subtable (0, 5); if (st && st->u.format == 14) subtable_uvs = &st->u.format14; } /* Meh. */ - if (!subtable_uvs) subtable_uvs = &Null(OT::CmapSubtableFormat14); + if (!subtable_uvs) subtable_uvs = &Null(CmapSubtableFormat14); this->uvs_table = subtable_uvs; this->get_glyph_data = subtable; if (unlikely (symbol)) { - this->get_glyph_func = get_glyph_from_symbol; + this->get_glyph_func = get_glyph_from_symbol; this->get_all_codepoints_func = null_get_all_codepoints_func; } else { switch (subtable->u.format) { /* Accelerate format 4 and format 12. */ default: - this->get_glyph_func = get_glyph_from; + this->get_glyph_func = get_glyph_from; this->get_all_codepoints_func = null_get_all_codepoints_func; break; case 12: - this->get_glyph_func = get_glyph_from; - this->get_all_codepoints_func = get_all_codepoints_from; + this->get_glyph_func = get_glyph_from; + this->get_all_codepoints_func = get_all_codepoints_from; break; case 4: { @@ -977,9 +977,9 @@ struct cmap variation_selector, glyph)) { - case OT::GLYPH_VARIANT_NOT_FOUND: return false; - case OT::GLYPH_VARIANT_FOUND: return true; - case OT::GLYPH_VARIANT_USE_DEFAULT: break; + case GLYPH_VARIANT_NOT_FOUND: return false; + case GLYPH_VARIANT_FOUND: return true; + case GLYPH_VARIANT_USE_DEFAULT: break; } return get_nominal_glyph (unicode, glyph); @@ -1046,9 +1046,9 @@ struct cmap const void *get_glyph_data; hb_cmap_get_all_codepoints_func_t get_all_codepoints_func; - OT::CmapSubtableFormat4::accelerator_t format4_accel; + CmapSubtableFormat4::accelerator_t format4_accel; - const OT::CmapSubtableFormat14 *uvs_table; + const CmapSubtableFormat14 *uvs_table; hb_blob_t *blob; }; diff --git a/src/hb-ot-color-sbix-table.hh b/src/hb-ot-color-sbix-table.hh index dcfeef46c..0461afa32 100644 --- a/src/hb-ot-color-sbix-table.hh +++ b/src/hb-ot-color-sbix-table.hh @@ -96,9 +96,9 @@ struct sbix { inline void init (hb_face_t *face) { - sbix_blob = OT::hb_sanitize_context_t().reference_table (face); + sbix_blob = hb_sanitize_context_t().reference_table (face); sbix_len = hb_blob_get_length (sbix_blob); - sbix_table = sbix_blob->as (); + sbix_table = sbix_blob->as (); } inline void fini (void) diff --git a/src/hb-ot-color-svg-table.hh b/src/hb-ot-color-svg-table.hh index 9bfd266c7..3976694f8 100644 --- a/src/hb-ot-color-svg-table.hh +++ b/src/hb-ot-color-svg-table.hh @@ -96,9 +96,9 @@ struct SVG { inline void init (hb_face_t *face) { - svg_blob = OT::hb_sanitize_context_t().reference_table (face); + svg_blob = hb_sanitize_context_t().reference_table (face); svg_len = hb_blob_get_length (svg_blob); - svg = svg_blob->as (); + svg = svg_blob->as (); } inline void fini (void) diff --git a/src/hb-ot-glyf-table.hh b/src/hb-ot-glyf-table.hh index b670d792f..ce6ee1e22 100644 --- a/src/hb-ot-glyf-table.hh +++ b/src/hb-ot-glyf-table.hh @@ -103,14 +103,14 @@ struct glyf static bool _add_head_and_set_loca_version (hb_subset_plan_t *plan, bool use_short_loca) { - hb_blob_t *head_blob = OT::hb_sanitize_context_t().reference_table (plan->source); + hb_blob_t *head_blob = hb_sanitize_context_t().reference_table (plan->source); hb_blob_t *head_prime_blob = hb_blob_copy_writable_or_fail (head_blob); hb_blob_destroy (head_blob); if (unlikely (!head_prime_blob)) return false; - OT::head *head_prime = (OT::head *) hb_blob_get_data_writable (head_prime_blob, nullptr); + head *head_prime = (head *) hb_blob_get_data_writable (head_prime_blob, nullptr); head_prime->indexToLocFormat.set (use_short_loca ? 0 : 1); bool success = plan->add_table (HB_OT_TAG_head, head_prime_blob); diff --git a/src/hb-ot-hmtx-table.hh b/src/hb-ot-hmtx-table.hh index 29cbc3848..13fa9d6e0 100644 --- a/src/hb-ot-hmtx-table.hh +++ b/src/hb-ot-hmtx-table.hh @@ -69,7 +69,7 @@ struct hmtxvmtx inline bool subset_update_header (hb_subset_plan_t *plan, unsigned int num_hmetrics) const { - hb_blob_t *src_blob = OT::hb_sanitize_context_t().reference_table (plan->source, H::tableTag); + hb_blob_t *src_blob = hb_sanitize_context_t().reference_table (plan->source, H::tableTag); hb_blob_t *dest_blob = hb_blob_copy_writable_or_fail(src_blob); hb_blob_destroy (src_blob); diff --git a/src/hb-ot-maxp-table.hh b/src/hb-ot-maxp-table.hh index d3849fb13..75aac4f44 100644 --- a/src/hb-ot-maxp-table.hh +++ b/src/hb-ot-maxp-table.hh @@ -100,14 +100,14 @@ struct maxp inline bool subset (hb_subset_plan_t *plan) const { - hb_blob_t *maxp_blob = OT::hb_sanitize_context_t().reference_table (plan->source); + hb_blob_t *maxp_blob = hb_sanitize_context_t().reference_table (plan->source); hb_blob_t *maxp_prime_blob = hb_blob_copy_writable_or_fail (maxp_blob); hb_blob_destroy (maxp_blob); if (unlikely (!maxp_prime_blob)) { return false; } - OT::maxp *maxp_prime = (OT::maxp *) hb_blob_get_data (maxp_prime_blob, nullptr); + maxp *maxp_prime = (maxp *) hb_blob_get_data (maxp_prime_blob, nullptr); maxp_prime->set_num_glyphs (plan->glyphs.len); if (plan->drop_hints) @@ -118,7 +118,7 @@ struct maxp return result; } - static inline void drop_hint_fields (hb_subset_plan_t *plan, OT::maxp *maxp_prime) + static inline void drop_hint_fields (hb_subset_plan_t *plan, maxp *maxp_prime) { if (maxp_prime->version.major == 1) { diff --git a/src/hb-ot-os2-table.hh b/src/hb-ot-os2-table.hh index 5aab56c41..56bbab741 100644 --- a/src/hb-ot-os2-table.hh +++ b/src/hb-ot-os2-table.hh @@ -51,12 +51,12 @@ struct os2 inline bool subset (hb_subset_plan_t *plan) const { - hb_blob_t *os2_blob = OT::hb_sanitize_context_t().reference_table (plan->source); + hb_blob_t *os2_blob = hb_sanitize_context_t().reference_table (plan->source); hb_blob_t *os2_prime_blob = hb_blob_create_sub_blob (os2_blob, 0, -1); // TODO(grieger): move to hb_blob_copy_writable_or_fail hb_blob_destroy (os2_blob); - OT::os2 *os2_prime = (OT::os2 *) hb_blob_get_data_writable (os2_prime_blob, nullptr); + os2 *os2_prime = (os2 *) hb_blob_get_data_writable (os2_prime_blob, nullptr); if (unlikely (!os2_prime)) { hb_blob_destroy (os2_prime_blob); return false; diff --git a/src/hb-ot-post-table.hh b/src/hb-ot-post-table.hh index 1d3058018..9766f3152 100644 --- a/src/hb-ot-post-table.hh +++ b/src/hb-ot-post-table.hh @@ -85,7 +85,7 @@ struct post inline bool subset (hb_subset_plan_t *plan) const { unsigned int post_prime_length; - hb_blob_t *post_blob = OT::hb_sanitize_context_t().reference_table(plan->source); + hb_blob_t *post_blob = hb_sanitize_context_t().reference_table(plan->source); hb_blob_t *post_prime_blob = hb_blob_create_sub_blob (post_blob, 0, post::static_size); post *post_prime = (post *) hb_blob_get_data_writable (post_prime_blob, &post_prime_length); hb_blob_destroy (post_blob); From e57a638bdec378eed8e83513818c8add3ffae896 Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Mon, 23 Jul 2018 12:00:02 -0700 Subject: [PATCH 090/106] One more --- src/hb-ot-cmap-table.hh | 40 ++++++++++++++++++++-------------------- 1 file changed, 20 insertions(+), 20 deletions(-) diff --git a/src/hb-ot-cmap-table.hh b/src/hb-ot-cmap-table.hh index a671da55d..00f835285 100644 --- a/src/hb-ot-cmap-table.hh +++ b/src/hb-ot-cmap-table.hh @@ -800,37 +800,37 @@ struct cmap { hb_serialize_context_t c (dest, dest_sz); - OT::cmap *cmap = c.start_serialize (); - if (unlikely (!c.extend_min (*cmap))) + cmap *table = c.start_serialize (); + if (unlikely (!c.extend_min (*table))) { return false; } - cmap->version.set (0); + table->version.set (0); - if (unlikely (!cmap->encodingRecord.serialize (&c, /* numTables */ 3))) + if (unlikely (!table->encodingRecord.serialize (&c, /* numTables */ 3))) return false; // TODO(grieger): Convert the below to a for loop // Format 4, Plat 0 Encoding Record - EncodingRecord &format4_plat0_rec = cmap->encodingRecord[0]; + EncodingRecord &format4_plat0_rec = table->encodingRecord[0]; format4_plat0_rec.platformID.set (0); // Unicode format4_plat0_rec.encodingID.set (3); // Format 4, Plat 3 Encoding Record - EncodingRecord &format4_plat3_rec = cmap->encodingRecord[1]; + EncodingRecord &format4_plat3_rec = table->encodingRecord[1]; format4_plat3_rec.platformID.set (3); // Windows format4_plat3_rec.encodingID.set (1); // Unicode BMP // Format 12 Encoding Record - EncodingRecord &format12_rec = cmap->encodingRecord[2]; + EncodingRecord &format12_rec = table->encodingRecord[2]; format12_rec.platformID.set (3); // Windows format12_rec.encodingID.set (10); // Unicode UCS-4 // Write out format 4 sub table { - CmapSubtable &subtable = format4_plat0_rec.subtable.serialize (&c, cmap); + CmapSubtable &subtable = format4_plat0_rec.subtable.serialize (&c, table); format4_plat3_rec.subtable.set (format4_plat0_rec.subtable); subtable.u.format.set (4); @@ -841,7 +841,7 @@ struct cmap // Write out format 12 sub table. { - CmapSubtable &subtable = format12_rec.subtable.serialize (&c, cmap); + CmapSubtable &subtable = format12_rec.subtable.serialize (&c, table); subtable.u.format.set (12); CmapSubtableFormat12 &format12 = subtable.u.format12; @@ -895,24 +895,24 @@ struct cmap inline void init (hb_face_t *face) { this->blob = hb_sanitize_context_t().reference_table (face); - const OT::cmap *cmap = this->blob->as (); + const cmap *table = this->blob->as (); const CmapSubtable *subtable = nullptr; const CmapSubtableFormat14 *subtable_uvs = nullptr; bool symbol = false; /* 32-bit subtables. */ - if (!subtable) subtable = cmap->find_subtable (3, 10); - if (!subtable) subtable = cmap->find_subtable (0, 6); - if (!subtable) subtable = cmap->find_subtable (0, 4); + if (!subtable) subtable = table->find_subtable (3, 10); + if (!subtable) subtable = table->find_subtable (0, 6); + if (!subtable) subtable = table->find_subtable (0, 4); /* 16-bit subtables. */ - if (!subtable) subtable = cmap->find_subtable (3, 1); - if (!subtable) subtable = cmap->find_subtable (0, 3); - if (!subtable) subtable = cmap->find_subtable (0, 2); - if (!subtable) subtable = cmap->find_subtable (0, 1); - if (!subtable) subtable = cmap->find_subtable (0, 0); + if (!subtable) subtable = table->find_subtable (3, 1); + if (!subtable) subtable = table->find_subtable (0, 3); + if (!subtable) subtable = table->find_subtable (0, 2); + if (!subtable) subtable = table->find_subtable (0, 1); + if (!subtable) subtable = table->find_subtable (0, 0); if (!subtable) { - subtable = cmap->find_subtable (3, 0); + subtable = table->find_subtable (3, 0); if (subtable) symbol = true; } /* Meh. */ @@ -921,7 +921,7 @@ struct cmap /* UVS subtable. */ if (!subtable_uvs) { - const CmapSubtable *st = cmap->find_subtable (0, 5); + const CmapSubtable *st = table->find_subtable (0, 5); if (st && st->u.format == 14) subtable_uvs = &st->u.format14; } From e22a48ac95a60fac5e1bca26eed7f5623d73a7be Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Mon, 23 Jul 2018 13:24:26 -0700 Subject: [PATCH 091/106] One more visibility trick Should fix Windows build again. --- src/hb-common.cc | 9 +++++++++ src/hb-private.hh | 20 ++------------------ src/hb-static.cc | 4 +++- 3 files changed, 14 insertions(+), 19 deletions(-) diff --git a/src/hb-common.cc b/src/hb-common.cc index 243c2163e..8ec269eb1 100644 --- a/src/hb-common.cc +++ b/src/hb-common.cc @@ -1069,3 +1069,12 @@ hb_variation_to_string (hb_variation_t *variation, memcpy (buf, s, len); buf[len] = '\0'; } + +/* If there is no visibility control, then hb-static.cc will NOT + * define anything. Instead, we get it to define one set in here + * only, so only libharfbuzz.so defines them, not other libs. */ +#ifdef HB_NO_VISIBILITY +#undef HB_NO_VISIBILITY +#include "hb-static.cc" +#define HB_NO_VISIBILITY 1 +#endif diff --git a/src/hb-private.hh b/src/hb-private.hh index ddb256f80..37a2eb8de 100644 --- a/src/hb-private.hh +++ b/src/hb-private.hh @@ -375,16 +375,8 @@ typedef uint64_t hb_vector_size_impl_t; #define HB_NULL_POOL_SIZE 264 -#ifdef HB_NO_VISIBILITY -static -#else extern HB_INTERNAL -#endif -hb_vector_size_impl_t const _hb_NullPool[(HB_NULL_POOL_SIZE + sizeof (hb_vector_size_impl_t) - 1) / sizeof (hb_vector_size_impl_t)] -#ifdef HB_NO_VISIBILITY -= {} -#endif -; +hb_vector_size_impl_t const _hb_NullPool[(HB_NULL_POOL_SIZE + sizeof (hb_vector_size_impl_t) - 1) / sizeof (hb_vector_size_impl_t)]; /* Generic nul-content Null objects. */ template @@ -413,16 +405,8 @@ static_assert (Namespace::Type::min_size + 1 <= sizeof (_Null##Type), "Null pool * for correct operation. It only exist to catch and divert program logic bugs instead of * causing bad memory access. So, races there are not actually introducing incorrectness * in the code. Has ~12kb binary size overhead to have it, also clang build fails with it. */ -#ifdef HB_NO_VISIBILITY -static -#else extern HB_INTERNAL -#endif -/*thread_local*/ hb_vector_size_impl_t _hb_CrapPool[(HB_NULL_POOL_SIZE + sizeof (hb_vector_size_impl_t) - 1) / sizeof (hb_vector_size_impl_t)] -#ifdef HB_NO_VISIBILITY -= {} -#endif -; +/*thread_local*/ hb_vector_size_impl_t _hb_CrapPool[(HB_NULL_POOL_SIZE + sizeof (hb_vector_size_impl_t) - 1) / sizeof (hb_vector_size_impl_t)]; /* CRAP pool: Common Region for Access Protection. */ template diff --git a/src/hb-static.cc b/src/hb-static.cc index 729b242c5..bc4bf547d 100644 --- a/src/hb-static.cc +++ b/src/hb-static.cc @@ -31,9 +31,9 @@ #include "hb-ot-maxp-table.hh" #ifndef HB_NO_VISIBILITY + hb_vector_size_impl_t const _hb_NullPool[(HB_NULL_POOL_SIZE + sizeof (hb_vector_size_impl_t) - 1) / sizeof (hb_vector_size_impl_t)] = {}; /*thread_local*/ hb_vector_size_impl_t _hb_CrapPool[(HB_NULL_POOL_SIZE + sizeof (hb_vector_size_impl_t) - 1) / sizeof (hb_vector_size_impl_t)] = {}; -#endif void hb_face_t::load_num_glyphs (void) const @@ -52,3 +52,5 @@ hb_face_t::load_upem (void) const upem = head_table->get_upem (); hb_blob_destroy (head_blob); } + +#endif From 61eddbd8ef64dc66e3c42723533d53967e61c9af Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Mon, 23 Jul 2018 14:44:10 -0700 Subject: [PATCH 092/106] Fix infinite loop in loading num_glyphs within sanitizer --- src/hb-open-type-private.hh | 13 ++++++++++--- src/hb-static.cc | 4 +++- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/src/hb-open-type-private.hh b/src/hb-open-type-private.hh index e2a135562..a143cc00d 100644 --- a/src/hb-open-type-private.hh +++ b/src/hb-open-type-private.hh @@ -164,7 +164,8 @@ struct hb_sanitize_context_t : start (nullptr), end (nullptr), writable (false), edit_count (0), max_ops (0), blob (nullptr), - num_glyphs (0) {} + num_glyphs (65536), + num_glyphs_set (false) {} inline const char *get_name (void) { return "SANITIZE"; } template @@ -182,7 +183,11 @@ struct hb_sanitize_context_t : this->writable = false; } - inline void set_num_glyphs (unsigned int num_glyphs_) { num_glyphs = num_glyphs_; } + inline void set_num_glyphs (unsigned int num_glyphs_) + { + num_glyphs = num_glyphs_; + num_glyphs_set = true; + } inline unsigned int get_num_glyphs (void) { return num_glyphs; } inline void start_processing (void) @@ -348,7 +353,8 @@ struct hb_sanitize_context_t : template inline hb_blob_t *reference_table (const hb_face_t *face, hb_tag_t tableTag = Type::tableTag) { - set_num_glyphs (face->get_num_glyphs ()); + if (!num_glyphs_set) + set_num_glyphs (face->get_num_glyphs ()); return sanitize_blob (face->reference_table (tableTag)); } @@ -360,6 +366,7 @@ struct hb_sanitize_context_t : mutable int max_ops; hb_blob_t *blob; unsigned int num_glyphs; + bool num_glyphs_set; }; diff --git a/src/hb-static.cc b/src/hb-static.cc index bc4bf547d..e6920e7e0 100644 --- a/src/hb-static.cc +++ b/src/hb-static.cc @@ -38,7 +38,9 @@ hb_vector_size_impl_t const _hb_NullPool[(HB_NULL_POOL_SIZE + sizeof (hb_vector_ void hb_face_t::load_num_glyphs (void) const { - hb_blob_t *maxp_blob = OT::hb_sanitize_context_t().reference_table (this); + OT::hb_sanitize_context_t c = OT::hb_sanitize_context_t(); + c.set_num_glyphs (0); /* So we don't recurse ad infinitum. */ + hb_blob_t *maxp_blob = c.reference_table (this); const OT::maxp *maxp_table = maxp_blob->as (); num_glyphs = maxp_table->get_num_glyphs (); hb_blob_destroy (maxp_blob); From 94759d4cf8986388399026ef5204ac55ee187180 Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Mon, 23 Jul 2018 15:01:39 -0700 Subject: [PATCH 093/106] Fix visibility on mingw32 Should fix bots again. --- src/hb-private.hh | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/hb-private.hh b/src/hb-private.hh index 37a2eb8de..a0bd99425 100644 --- a/src/hb-private.hh +++ b/src/hb-private.hh @@ -161,7 +161,11 @@ struct _hb_alignof #ifndef HB_INTERNAL # if !defined(HB_NO_VISIBILITY) && !defined(__MINGW32__) && !defined(__CYGWIN__) && !defined(_MSC_VER) && !defined(__SUNPRO_CC) # define HB_INTERNAL __attribute__((__visibility__("hidden"))) -# else +# elif defined(__MINGW32__) + /* We use -export-symbols on mingw32, since it does not support visibility + * attribute. */ +# define HB_INTERNAL +#else # define HB_INTERNAL # define HB_NO_VISIBILITY 1 # endif From 85646fdadb2f102333485e07425361795b4e0412 Mon Sep 17 00:00:00 2001 From: Garret Rieger Date: Mon, 23 Jul 2018 15:37:18 -0700 Subject: [PATCH 094/106] [subset] Limit the iterations of the closure algorithm. Prevents O(n^2) run times. --- src/hb-ot-layout-common-private.hh | 7 +++++++ src/hb-ot-layout.cc | 5 ++++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/src/hb-ot-layout-common-private.hh b/src/hb-ot-layout-common-private.hh index 21caf9e95..7ff0dbebb 100644 --- a/src/hb-ot-layout-common-private.hh +++ b/src/hb-ot-layout-common-private.hh @@ -41,6 +41,13 @@ #ifndef HB_MAX_CONTEXT_LENGTH #define HB_MAX_CONTEXT_LENGTH 64 #endif +#ifndef HB_CLOSURE_MAX_STAGES +/* + * The maximum number of times a lookup can be applied during shaping. + * Used to limit the number of iterations of the closure algorithm. + */ +#define HB_CLOSURE_MAX_STAGES 8 +#endif namespace OT { diff --git a/src/hb-ot-layout.cc b/src/hb-ot-layout.cc index 0eba88a62..01ca5143d 100644 --- a/src/hb-ot-layout.cc +++ b/src/hb-ot-layout.cc @@ -971,6 +971,7 @@ hb_ot_layout_lookups_substitute_closure (hb_face_t *face, OT::hb_closure_context_t c (face, glyphs, &done_lookups); const OT::GSUB& gsub = _get_gsub (face); + unsigned int iteration_count = 0; unsigned int glyphs_length; do { @@ -985,7 +986,9 @@ hb_ot_layout_lookups_substitute_closure (hb_face_t *face, for (unsigned int i = 0; i < gsub.get_lookup_count (); i++) gsub.get_lookup (i).closure (&c, i); } - } while (glyphs_length != glyphs->get_population ()); + iteration_count++; + } while (iteration_count <= HB_CLOSURE_MAX_STAGES + && glyphs_length != glyphs->get_population ()); } /* From c38bd4025f3f6ff4c1a39cc106b8618361a0c62b Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Tue, 24 Jul 2018 09:43:27 -0700 Subject: [PATCH 095/106] [closure] Separate in and out glyphs Fixes https://github.com/harfbuzz/harfbuzz/issues/1107 --- src/hb-ot-layout-gsub-table.hh | 26 ++++++++++++++++++-------- src/hb-ot-layout-gsubgpos-private.hh | 16 +++++++++++++++- 2 files changed, 33 insertions(+), 9 deletions(-) diff --git a/src/hb-ot-layout-gsub-table.hh b/src/hb-ot-layout-gsub-table.hh index 91b898b63..eef8dc546 100644 --- a/src/hb-ot-layout-gsub-table.hh +++ b/src/hb-ot-layout-gsub-table.hh @@ -47,7 +47,7 @@ struct SingleSubstFormat1 * https://github.com/harfbuzz/harfbuzz/issues/363 */ hb_codepoint_t glyph_id = iter.get_glyph (); if (c->glyphs->has (glyph_id)) - c->glyphs->add ((glyph_id + deltaGlyphID) & 0xFFFFu); + c->out->add ((glyph_id + deltaGlyphID) & 0xFFFFu); } } @@ -132,7 +132,7 @@ struct SingleSubstFormat2 if (unlikely (iter.get_coverage () >= count)) break; /* Work around malicious fonts. https://github.com/harfbuzz/harfbuzz/issues/363 */ if (c->glyphs->has (iter.get_glyph ())) - c->glyphs->add (substitute[iter.get_coverage ()]); + c->out->add (substitute[iter.get_coverage ()]); } } @@ -263,7 +263,7 @@ struct Sequence TRACE_CLOSURE (this); unsigned int count = substitute.len; for (unsigned int i = 0; i < count; i++) - c->glyphs->add (substitute[i]); + c->out->add (substitute[i]); } inline void collect_glyphs (hb_collect_glyphs_context_t *c) const @@ -464,7 +464,7 @@ struct AlternateSubstFormat1 const AlternateSet &alt_set = this+alternateSet[iter.get_coverage ()]; unsigned int count = alt_set.len; for (unsigned int i = 0; i < count; i++) - c->glyphs->add (alt_set[i]); + c->out->add (alt_set[i]); } } } @@ -605,7 +605,7 @@ struct Ligature for (unsigned int i = 1; i < count; i++) if (!c->glyphs->has (component[i])) return; - c->glyphs->add (ligGlyph); + c->out->add (ligGlyph); } inline void collect_glyphs (hb_collect_glyphs_context_t *c) const @@ -957,7 +957,7 @@ struct ReverseChainSingleSubstFormat1 if (unlikely (iter.get_coverage () >= count)) break; /* Work around malicious fonts. https://github.com/harfbuzz/harfbuzz/issues/363 */ if (c->glyphs->has (iter.get_glyph ())) - c->glyphs->add (substitute[iter.get_coverage ()]); + c->out->add (substitute[iter.get_coverage ()]); } } @@ -1163,7 +1163,12 @@ struct SubstLookup : Lookup return_trace (HB_VOID); c->set_recurse_func (dispatch_closure_recurse_func); - return_trace (dispatch (c)); + + hb_closure_context_t::return_t ret = dispatch (c); + + c->flush (); + + return_trace (ret); } inline hb_collect_glyphs_context_t::return_t collect_glyphs (hb_collect_glyphs_context_t *c) const @@ -1265,7 +1270,12 @@ struct SubstLookup : Lookup { if (!c->should_visit_lookup (lookup_index)) return HB_VOID; - return dispatch_recurse_func (c, lookup_index); + + hb_closure_context_t::return_t ret = dispatch_recurse_func (c, lookup_index); + + c->flush (); + + return ret; } template diff --git a/src/hb-ot-layout-gsubgpos-private.hh b/src/hb-ot-layout-gsubgpos-private.hh index aed00f151..c03e03356 100644 --- a/src/hb-ot-layout-gsubgpos-private.hh +++ b/src/hb-ot-layout-gsubgpos-private.hh @@ -69,12 +69,13 @@ struct hb_closure_context_t : bool is_lookup_done (unsigned int lookup_index) { - // Have we visited this lookup with the current set of glyphs? + /* Have we visited this lookup with the current set of glyphs? */ return done_lookups->get (lookup_index) == glyphs->get_population (); } hb_face_t *face; hb_set_t *glyphs; + hb_set_t *out; recurse_func_t recurse_func; unsigned int nesting_level_left; unsigned int debug_depth; @@ -85,13 +86,26 @@ struct hb_closure_context_t : unsigned int nesting_level_left_ = HB_MAX_NESTING_LEVEL) : face (face_), glyphs (glyphs_), + out (hb_set_create ()), recurse_func (nullptr), nesting_level_left (nesting_level_left_), debug_depth (0), done_lookups (done_lookups_) {} + ~hb_closure_context_t (void) + { + flush (); + hb_set_destroy (out); + } + void set_recurse_func (recurse_func_t func) { recurse_func = func; } + void flush (void) + { + hb_set_union (glyphs, out); + hb_set_clear (out); + } + private: hb_map_t *done_lookups; }; From fb58cb4b5ca7043fa746b1a01790abf53bedfa86 Mon Sep 17 00:00:00 2001 From: Garret Rieger Date: Wed, 25 Jul 2018 13:39:17 -0700 Subject: [PATCH 096/106] [subset] Only used reachable lookups for gsub closure. --- src/hb-subset-plan.cc | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/hb-subset-plan.cc b/src/hb-subset-plan.cc index 55c4e3f61..125668272 100644 --- a/src/hb-subset-plan.cc +++ b/src/hb-subset-plan.cc @@ -56,11 +56,15 @@ _add_gid_and_children (const OT::glyf::accelerator_t &glyf, static void _gsub_closure (hb_face_t *face, hb_set_t *gids_to_retain) { - // TODO(grieger): This uses all lookups, instead collect - // the set of lookups that are relevant. - // See fontTools implementation. + hb_auto_t lookup_indices; + hb_ot_layout_collect_lookups (face, + HB_OT_TAG_GSUB, + nullptr, + nullptr, + nullptr, + &lookup_indices); hb_ot_layout_lookups_substitute_closure (face, - nullptr, + &lookup_indices, gids_to_retain); } From bf90f35302c319ec4699ccbcd1e28b15ef2ec423 Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Tue, 24 Jul 2018 18:00:14 -0700 Subject: [PATCH 097/106] [coretext] Add note --- src/hb-shaper-private.hh | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/hb-shaper-private.hh b/src/hb-shaper-private.hh index ce2d9f283..3fa532162 100644 --- a/src/hb-shaper-private.hh +++ b/src/hb-shaper-private.hh @@ -97,6 +97,10 @@ HB_SHAPER_DATA_ENSURE_FUNC(shaper, object) (hb_##object##_t *object) \ retry: \ HB_SHAPER_DATA_TYPE (shaper, object) *data = (HB_SHAPER_DATA_TYPE (shaper, object) *) hb_atomic_ptr_get (&HB_SHAPER_DATA (shaper, object)); \ if (likely (data) && !(condition)) { \ + /* Note that evaluating condition above can be dangerous if another thread + * got here first and destructed data. That's, as always, bad use pattern. + * If you modify the font (change font size), other threads must not be + * using it at the same time. */ /* Drop and recreate. */ \ /* If someone dropped it in the mean time, throw it away and don't touch it. \ * Otherwise, destruct it. */ \ From 74467b790154838e86c3ca8df0eaafe82e87f976 Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Wed, 25 Jul 2018 14:30:07 -0700 Subject: [PATCH 098/106] Fix compile --- src/hb-shaper-private.hh | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/hb-shaper-private.hh b/src/hb-shaper-private.hh index 3fa532162..8f86b4eb5 100644 --- a/src/hb-shaper-private.hh +++ b/src/hb-shaper-private.hh @@ -97,10 +97,10 @@ HB_SHAPER_DATA_ENSURE_FUNC(shaper, object) (hb_##object##_t *object) \ retry: \ HB_SHAPER_DATA_TYPE (shaper, object) *data = (HB_SHAPER_DATA_TYPE (shaper, object) *) hb_atomic_ptr_get (&HB_SHAPER_DATA (shaper, object)); \ if (likely (data) && !(condition)) { \ - /* Note that evaluating condition above can be dangerous if another thread - * got here first and destructed data. That's, as always, bad use pattern. - * If you modify the font (change font size), other threads must not be - * using it at the same time. */ + /* Note that evaluating condition above can be dangerous if another thread \ + * got here first and destructed data. That's, as always, bad use pattern. \ + * If you modify the font (change font size), other threads must not be \ + * using it at the same time. */ \ /* Drop and recreate. */ \ /* If someone dropped it in the mean time, throw it away and don't touch it. \ * Otherwise, destruct it. */ \ From 6b11fea99716e22522b563d919ef7c72fe9a3c45 Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Wed, 25 Jul 2018 16:01:37 -0700 Subject: [PATCH 099/106] [closure] Allocate out set on the stack --- src/hb-ot-layout-gsubgpos-private.hh | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/hb-ot-layout-gsubgpos-private.hh b/src/hb-ot-layout-gsubgpos-private.hh index c03e03356..747811e6a 100644 --- a/src/hb-ot-layout-gsubgpos-private.hh +++ b/src/hb-ot-layout-gsubgpos-private.hh @@ -75,7 +75,7 @@ struct hb_closure_context_t : hb_face_t *face; hb_set_t *glyphs; - hb_set_t *out; + hb_auto_t out[1]; recurse_func_t recurse_func; unsigned int nesting_level_left; unsigned int debug_depth; @@ -86,7 +86,6 @@ struct hb_closure_context_t : unsigned int nesting_level_left_ = HB_MAX_NESTING_LEVEL) : face (face_), glyphs (glyphs_), - out (hb_set_create ()), recurse_func (nullptr), nesting_level_left (nesting_level_left_), debug_depth (0), @@ -95,7 +94,6 @@ struct hb_closure_context_t : ~hb_closure_context_t (void) { flush (); - hb_set_destroy (out); } void set_recurse_func (recurse_func_t func) { recurse_func = func; } From 92b1e025c639d006f55400bf68fc23bdeaa1c716 Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Wed, 25 Jul 2018 16:58:47 -0700 Subject: [PATCH 100/106] Move some code from hb-open-type-private.hh to hb-machinery-private.hh --- src/Makefile.sources | 1 + src/hb-machinery-private.hh | 702 ++++++++++++++++++++++++++++++++++++ src/hb-open-type-private.hh | 669 +--------------------------------- 3 files changed, 706 insertions(+), 666 deletions(-) create mode 100644 src/hb-machinery-private.hh diff --git a/src/Makefile.sources b/src/Makefile.sources index 9fa926d40..fb4e4a2c4 100644 --- a/src/Makefile.sources +++ b/src/Makefile.sources @@ -16,6 +16,7 @@ HB_BASE_sources = \ hb-font.cc \ hb-map-private.hh \ hb-map.cc \ + hb-machinery-private.hh \ hb-mutex-private.hh \ hb-object-private.hh \ hb-open-file-private.hh \ diff --git a/src/hb-machinery-private.hh b/src/hb-machinery-private.hh new file mode 100644 index 000000000..5fafadbec --- /dev/null +++ b/src/hb-machinery-private.hh @@ -0,0 +1,702 @@ +/* + * Copyright © 2007,2008,2009,2010 Red Hat, Inc. + * Copyright © 2012,2018 Google, Inc. + * + * This is part of HarfBuzz, a text shaping library. + * + * Permission is hereby granted, without written agreement and without + * license or royalty fees, to use, copy, modify, and distribute this + * software and its documentation for any purpose, provided that the + * above copyright notice and the following two paragraphs appear in + * all copies of this software. + * + * IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE TO ANY PARTY FOR + * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES + * ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN + * IF THE COPYRIGHT HOLDER HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH + * DAMAGE. + * + * THE COPYRIGHT HOLDER SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, + * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS + * ON AN "AS IS" BASIS, AND THE COPYRIGHT HOLDER HAS NO OBLIGATION TO + * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. + * + * Red Hat Author(s): Behdad Esfahbod + * Google Author(s): Behdad Esfahbod + */ + +#ifndef HB_MACHINERY_PRIVATE_HH +#define HB_MACHINERY_PRIVATE_HH + +#include "hb-private.hh" + + +namespace OT { + + +/* + * Casts + */ + +/* Cast to struct T, reference to reference */ +template +static inline const Type& CastR(const TObject &X) +{ return reinterpret_cast (X); } +template +static inline Type& CastR(TObject &X) +{ return reinterpret_cast (X); } + +/* Cast to struct T, pointer to pointer */ +template +static inline const Type* CastP(const TObject *X) +{ return reinterpret_cast (X); } +template +static inline Type* CastP(TObject *X) +{ return reinterpret_cast (X); } + +/* StructAtOffset(P,Ofs) returns the struct T& that is placed at memory + * location pointed to by P plus Ofs bytes. */ +template +static inline const Type& StructAtOffset(const void *P, unsigned int offset) +{ return * reinterpret_cast ((const char *) P + offset); } +template +static inline Type& StructAtOffset(void *P, unsigned int offset) +{ return * reinterpret_cast ((char *) P + offset); } + +/* StructAfter(X) returns the struct T& that is placed after X. + * Works with X of variable size also. X must implement get_size() */ +template +static inline const Type& StructAfter(const TObject &X) +{ return StructAtOffset(&X, X.get_size()); } +template +static inline Type& StructAfter(TObject &X) +{ return StructAtOffset(&X, X.get_size()); } + + +/* + * Size checking + */ + +/* Check _assertion in a method environment */ +#define _DEFINE_INSTANCE_ASSERTION1(_line, _assertion) \ + inline void _instance_assertion_on_line_##_line (void) const \ + { \ + static_assert ((_assertion), ""); \ + ASSERT_INSTANCE_POD (*this); /* Make sure it's POD. */ \ + } +# define _DEFINE_INSTANCE_ASSERTION0(_line, _assertion) _DEFINE_INSTANCE_ASSERTION1 (_line, _assertion) +# define DEFINE_INSTANCE_ASSERTION(_assertion) _DEFINE_INSTANCE_ASSERTION0 (__LINE__, _assertion) + +/* Check that _code compiles in a method environment */ +#define _DEFINE_COMPILES_ASSERTION1(_line, _code) \ + inline void _compiles_assertion_on_line_##_line (void) const \ + { _code; } +# define _DEFINE_COMPILES_ASSERTION0(_line, _code) _DEFINE_COMPILES_ASSERTION1 (_line, _code) +# define DEFINE_COMPILES_ASSERTION(_code) _DEFINE_COMPILES_ASSERTION0 (__LINE__, _code) + + +#define DEFINE_SIZE_STATIC(size) \ + DEFINE_INSTANCE_ASSERTION (sizeof (*this) == (size)); \ + static const unsigned int static_size = (size); \ + static const unsigned int min_size = (size); \ + inline unsigned int get_size (void) const { return (size); } + +#define DEFINE_SIZE_UNION(size, _member) \ + DEFINE_INSTANCE_ASSERTION (0*sizeof(this->u._member.static_size) + sizeof(this->u._member) == (size)); \ + static const unsigned int min_size = (size) + +#define DEFINE_SIZE_MIN(size) \ + DEFINE_INSTANCE_ASSERTION (sizeof (*this) >= (size)); \ + static const unsigned int min_size = (size) + +#define DEFINE_SIZE_ARRAY(size, array) \ + DEFINE_INSTANCE_ASSERTION (sizeof (*this) == (size) + sizeof (array[0])); \ + DEFINE_COMPILES_ASSERTION ((void) array[0].static_size) \ + static const unsigned int min_size = (size) + +#define DEFINE_SIZE_ARRAY2(size, array1, array2) \ + DEFINE_INSTANCE_ASSERTION (sizeof (*this) == (size) + sizeof (this->array1[0]) + sizeof (this->array2[0])); \ + DEFINE_COMPILES_ASSERTION ((void) array1[0].static_size; (void) array2[0].static_size) \ + static const unsigned int min_size = (size) + + +/* + * Dispatch + */ + +template +struct hb_dispatch_context_t +{ + static const unsigned int max_debug_depth = MaxDebugDepth; + typedef Return return_t; + template + inline bool may_dispatch (const T *obj, const F *format) { return true; } + static return_t no_dispatch_return_value (void) { return Context::default_return_value (); } +}; + + +/* + * Sanitize + */ + +/* This limits sanitizing time on really broken fonts. */ +#ifndef HB_SANITIZE_MAX_EDITS +#define HB_SANITIZE_MAX_EDITS 32 +#endif +#ifndef HB_SANITIZE_MAX_OPS_FACTOR +#define HB_SANITIZE_MAX_OPS_FACTOR 8 +#endif +#ifndef HB_SANITIZE_MAX_OPS_MIN +#define HB_SANITIZE_MAX_OPS_MIN 16384 +#endif + +struct hb_sanitize_context_t : + hb_dispatch_context_t +{ + inline hb_sanitize_context_t (void) : + debug_depth (0), + start (nullptr), end (nullptr), + writable (false), edit_count (0), max_ops (0), + blob (nullptr), + num_glyphs (65536), + num_glyphs_set (false) {} + + inline const char *get_name (void) { return "SANITIZE"; } + template + inline bool may_dispatch (const T *obj, const F *format) + { return format->sanitize (this); } + template + inline return_t dispatch (const T &obj) { return obj.sanitize (this); } + static return_t default_return_value (void) { return true; } + static return_t no_dispatch_return_value (void) { return false; } + bool stop_sublookup_iteration (const return_t r) const { return !r; } + + inline void init (hb_blob_t *b) + { + this->blob = hb_blob_reference (b); + this->writable = false; + } + + inline void set_num_glyphs (unsigned int num_glyphs_) + { + num_glyphs = num_glyphs_; + num_glyphs_set = true; + } + inline unsigned int get_num_glyphs (void) { return num_glyphs; } + + inline void start_processing (void) + { + this->start = hb_blob_get_data (this->blob, nullptr); + this->end = this->start + this->blob->length; + assert (this->start <= this->end); /* Must not overflow. */ + this->max_ops = MAX ((unsigned int) (this->end - this->start) * HB_SANITIZE_MAX_OPS_FACTOR, + (unsigned) HB_SANITIZE_MAX_OPS_MIN); + this->edit_count = 0; + this->debug_depth = 0; + + DEBUG_MSG_LEVEL (SANITIZE, start, 0, +1, + "start [%p..%p] (%lu bytes)", + this->start, this->end, + (unsigned long) (this->end - this->start)); + } + + inline void end_processing (void) + { + DEBUG_MSG_LEVEL (SANITIZE, this->start, 0, -1, + "end [%p..%p] %u edit requests", + this->start, this->end, this->edit_count); + + hb_blob_destroy (this->blob); + this->blob = nullptr; + this->start = this->end = nullptr; + } + + inline bool check_range (const void *base, unsigned int len) const + { + const char *p = (const char *) base; + bool ok = this->max_ops-- > 0 && + this->start <= p && + p <= this->end && + (unsigned int) (this->end - p) >= len; + + DEBUG_MSG_LEVEL (SANITIZE, p, this->debug_depth+1, 0, + "check_range [%p..%p] (%d bytes) in [%p..%p] -> %s", + p, p + len, len, + this->start, this->end, + ok ? "OK" : "OUT-OF-RANGE"); + + return likely (ok); + } + + inline bool check_array (const void *base, unsigned int record_size, unsigned int len) const + { + const char *p = (const char *) base; + bool overflows = hb_unsigned_mul_overflows (len, record_size); + unsigned int array_size = record_size * len; + bool ok = !overflows && this->check_range (base, array_size); + + DEBUG_MSG_LEVEL (SANITIZE, p, this->debug_depth+1, 0, + "check_array [%p..%p] (%d*%d=%d bytes) in [%p..%p] -> %s", + p, p + (record_size * len), record_size, len, (unsigned int) array_size, + this->start, this->end, + overflows ? "OVERFLOWS" : ok ? "OK" : "OUT-OF-RANGE"); + + return likely (ok); + } + + template + inline bool check_struct (const Type *obj) const + { + return likely (this->check_range (obj, obj->min_size)); + } + + inline bool may_edit (const void *base, unsigned int len) + { + if (this->edit_count >= HB_SANITIZE_MAX_EDITS) + return false; + + const char *p = (const char *) base; + this->edit_count++; + + DEBUG_MSG_LEVEL (SANITIZE, p, this->debug_depth+1, 0, + "may_edit(%u) [%p..%p] (%d bytes) in [%p..%p] -> %s", + this->edit_count, + p, p + len, len, + this->start, this->end, + this->writable ? "GRANTED" : "DENIED"); + + return this->writable; + } + + template + inline bool try_set (const Type *obj, const ValueType &v) { + if (this->may_edit (obj, obj->static_size)) { + const_cast (obj)->set (v); + return true; + } + return false; + } + + template + inline hb_blob_t *sanitize_blob (hb_blob_t *blob) + { + bool sane; + + init (blob); + + retry: + DEBUG_MSG_FUNC (SANITIZE, start, "start"); + + start_processing (); + + if (unlikely (!start)) + { + end_processing (); + return blob; + } + + Type *t = CastP (const_cast (start)); + + sane = t->sanitize (this); + if (sane) + { + if (edit_count) + { + DEBUG_MSG_FUNC (SANITIZE, start, "passed first round with %d edits; going for second round", edit_count); + + /* sanitize again to ensure no toe-stepping */ + edit_count = 0; + sane = t->sanitize (this); + if (edit_count) { + DEBUG_MSG_FUNC (SANITIZE, start, "requested %d edits in second round; FAILLING", edit_count); + sane = false; + } + } + } + else + { + if (edit_count && !writable) { + start = hb_blob_get_data_writable (blob, nullptr); + end = start + blob->length; + + if (start) + { + writable = true; + /* ok, we made it writable by relocating. try again */ + DEBUG_MSG_FUNC (SANITIZE, start, "retry"); + goto retry; + } + } + } + + end_processing (); + + DEBUG_MSG_FUNC (SANITIZE, start, sane ? "PASSED" : "FAILED"); + if (sane) + { + blob->lock (); + return blob; + } + else + { + hb_blob_destroy (blob); + return hb_blob_get_empty (); + } + } + + template + inline hb_blob_t *reference_table (const hb_face_t *face, hb_tag_t tableTag = Type::tableTag) + { + if (!num_glyphs_set) + set_num_glyphs (face->get_num_glyphs ()); + return sanitize_blob (face->reference_table (tableTag)); + } + + mutable unsigned int debug_depth; + const char *start, *end; + private: + bool writable; + unsigned int edit_count; + mutable int max_ops; + hb_blob_t *blob; + unsigned int num_glyphs; + bool num_glyphs_set; +}; + + +/* + * Serialize + */ + +struct hb_serialize_context_t +{ + inline hb_serialize_context_t (void *start_, unsigned int size) + { + this->start = (char *) start_; + this->end = this->start + size; + + this->ran_out_of_room = false; + this->head = this->start; + this->debug_depth = 0; + } + + template + inline Type *start_serialize (void) + { + DEBUG_MSG_LEVEL (SERIALIZE, this->start, 0, +1, + "start [%p..%p] (%lu bytes)", + this->start, this->end, + (unsigned long) (this->end - this->start)); + + return start_embed (); + } + + inline void end_serialize (void) + { + DEBUG_MSG_LEVEL (SERIALIZE, this->start, 0, -1, + "end [%p..%p] serialized %d bytes; %s", + this->start, this->end, + (int) (this->head - this->start), + this->ran_out_of_room ? "RAN OUT OF ROOM" : "did not ran out of room"); + + } + + template + inline Type *copy (void) + { + assert (!this->ran_out_of_room); + unsigned int len = this->head - this->start; + void *p = malloc (len); + if (p) + memcpy (p, this->start, len); + return reinterpret_cast (p); + } + + template + inline Type *allocate_size (unsigned int size) + { + if (unlikely (this->ran_out_of_room || this->end - this->head < ptrdiff_t (size))) { + this->ran_out_of_room = true; + return nullptr; + } + memset (this->head, 0, size); + char *ret = this->head; + this->head += size; + return reinterpret_cast (ret); + } + + template + inline Type *allocate_min (void) + { + return this->allocate_size (Type::min_size); + } + + template + inline Type *start_embed (void) + { + Type *ret = reinterpret_cast (this->head); + return ret; + } + + template + inline Type *embed (const Type &obj) + { + unsigned int size = obj.get_size (); + Type *ret = this->allocate_size (size); + if (unlikely (!ret)) return nullptr; + memcpy (ret, obj, size); + return ret; + } + + template + inline Type *extend_min (Type &obj) + { + unsigned int size = obj.min_size; + assert (this->start <= (char *) &obj && (char *) &obj <= this->head && (char *) &obj + size >= this->head); + if (unlikely (!this->allocate_size (((char *) &obj) + size - this->head))) return nullptr; + return reinterpret_cast (&obj); + } + + template + inline Type *extend (Type &obj) + { + unsigned int size = obj.get_size (); + assert (this->start < (char *) &obj && (char *) &obj <= this->head && (char *) &obj + size >= this->head); + if (unlikely (!this->allocate_size (((char *) &obj) + size - this->head))) return nullptr; + return reinterpret_cast (&obj); + } + + inline void truncate (void *new_head) + { + assert (this->start < new_head && new_head <= this->head); + this->head = (char *) new_head; + } + + unsigned int debug_depth; + char *start, *end, *head; + bool ran_out_of_room; +}; + + +/* + * Supplier + */ + +template +struct Supplier +{ + inline Supplier (const Type *array, unsigned int len_, unsigned int stride_=sizeof(Type)) + { + head = array; + len = len_; + stride = stride_; + } + inline const Type operator [] (unsigned int i) const + { + if (unlikely (i >= len)) return Type (); + return * (const Type *) (const void *) ((const char *) head + stride * i); + } + + inline Supplier & operator += (unsigned int count) + { + if (unlikely (count > len)) + count = len; + len -= count; + head = (const Type *) (const void *) ((const char *) head + stride * count); + return *this; + } + + private: + inline Supplier (const Supplier &); /* Disallow copy */ + inline Supplier& operator= (const Supplier &); /* Disallow copy */ + + unsigned int len; + unsigned int stride; + const Type *head; +}; + + +/* + * Big-endian integers. + */ + +template struct BEInt; + +template +struct BEInt +{ + public: + inline void set (Type V) + { + v = V; + } + inline operator Type (void) const + { + return v; + } + private: uint8_t v; +}; +template +struct BEInt +{ + public: + inline void set (Type V) + { + v[0] = (V >> 8) & 0xFF; + v[1] = (V ) & 0xFF; + } + inline operator Type (void) const + { + return (v[0] << 8) + + (v[1] ); + } + private: uint8_t v[2]; +}; +template +struct BEInt +{ + public: + inline void set (Type V) + { + v[0] = (V >> 16) & 0xFF; + v[1] = (V >> 8) & 0xFF; + v[2] = (V ) & 0xFF; + } + inline operator Type (void) const + { + return (v[0] << 16) + + (v[1] << 8) + + (v[2] ); + } + private: uint8_t v[3]; +}; +template +struct BEInt +{ + public: + inline void set (Type V) + { + v[0] = (V >> 24) & 0xFF; + v[1] = (V >> 16) & 0xFF; + v[2] = (V >> 8) & 0xFF; + v[3] = (V ) & 0xFF; + } + inline operator Type (void) const + { + return (v[0] << 24) + + (v[1] << 16) + + (v[2] << 8) + + (v[3] ); + } + private: uint8_t v[4]; +}; + + +/* + * Lazy struct and blob loaders. + */ + +/* Logic is shared between hb_lazy_loader_t and hb_table_lazy_loader_t */ +template +struct hb_lazy_loader_t +{ + inline void init (hb_face_t *face_) + { + face = face_; + instance = nullptr; + } + + inline void fini (void) + { + if (instance && instance != &Null(T)) + { + instance->fini(); + free (instance); + } + } + + inline const T* get (void) const + { + retry: + T *p = (T *) hb_atomic_ptr_get (&instance); + if (unlikely (!p)) + { + p = (T *) calloc (1, sizeof (T)); + if (unlikely (!p)) + p = const_cast (&Null(T)); + else + p->init (face); + if (unlikely (!hb_atomic_ptr_cmpexch (const_cast(&instance), nullptr, p))) + { + if (p != &Null(T)) + p->fini (); + goto retry; + } + } + return p; + } + + inline const T* operator-> (void) const + { + return get (); + } + + private: + hb_face_t *face; + mutable T *instance; +}; + +/* Logic is shared between hb_lazy_loader_t and hb_table_lazy_loader_t */ +template +struct hb_table_lazy_loader_t +{ + inline void init (hb_face_t *face_) + { + face = face_; + blob = nullptr; + } + + inline void fini (void) + { + hb_blob_destroy (blob); + } + + inline hb_blob_t* get_blob (void) const + { + retry: + hb_blob_t *b = (hb_blob_t *) hb_atomic_ptr_get (&blob); + if (unlikely (!b)) + { + b = OT::hb_sanitize_context_t().reference_table (face); + if (!hb_atomic_ptr_cmpexch (&blob, nullptr, b)) + { + hb_blob_destroy (b); + goto retry; + } + blob = b; + } + return b; + } + + inline const T* get (void) const + { + hb_blob_t *b = get_blob (); + return b->as (); + } + + inline const T* operator-> (void) const + { + return get(); + } + + private: + hb_face_t *face; + mutable hb_blob_t *blob; +}; + + +} /* namespace OT */ + + +#endif /* HB_MACHINERY_PRIVATE_HH */ diff --git a/src/hb-open-type-private.hh b/src/hb-open-type-private.hh index a143cc00d..bae2eed81 100644 --- a/src/hb-open-type-private.hh +++ b/src/hb-open-type-private.hh @@ -32,492 +32,12 @@ #include "hb-private.hh" #include "hb-blob-private.hh" #include "hb-face-private.hh" +#include "hb-machinery-private.hh" namespace OT { - -/* - * Casts - */ - -/* Cast to struct T, reference to reference */ -template -static inline const Type& CastR(const TObject &X) -{ return reinterpret_cast (X); } -template -static inline Type& CastR(TObject &X) -{ return reinterpret_cast (X); } - -/* Cast to struct T, pointer to pointer */ -template -static inline const Type* CastP(const TObject *X) -{ return reinterpret_cast (X); } -template -static inline Type* CastP(TObject *X) -{ return reinterpret_cast (X); } - -/* StructAtOffset(P,Ofs) returns the struct T& that is placed at memory - * location pointed to by P plus Ofs bytes. */ -template -static inline const Type& StructAtOffset(const void *P, unsigned int offset) -{ return * reinterpret_cast ((const char *) P + offset); } -template -static inline Type& StructAtOffset(void *P, unsigned int offset) -{ return * reinterpret_cast ((char *) P + offset); } - -/* StructAfter(X) returns the struct T& that is placed after X. - * Works with X of variable size also. X must implement get_size() */ -template -static inline const Type& StructAfter(const TObject &X) -{ return StructAtOffset(&X, X.get_size()); } -template -static inline Type& StructAfter(TObject &X) -{ return StructAtOffset(&X, X.get_size()); } - - - -/* - * Size checking - */ - -/* Check _assertion in a method environment */ -#define _DEFINE_INSTANCE_ASSERTION1(_line, _assertion) \ - inline void _instance_assertion_on_line_##_line (void) const \ - { \ - static_assert ((_assertion), ""); \ - ASSERT_INSTANCE_POD (*this); /* Make sure it's POD. */ \ - } -# define _DEFINE_INSTANCE_ASSERTION0(_line, _assertion) _DEFINE_INSTANCE_ASSERTION1 (_line, _assertion) -# define DEFINE_INSTANCE_ASSERTION(_assertion) _DEFINE_INSTANCE_ASSERTION0 (__LINE__, _assertion) - -/* Check that _code compiles in a method environment */ -#define _DEFINE_COMPILES_ASSERTION1(_line, _code) \ - inline void _compiles_assertion_on_line_##_line (void) const \ - { _code; } -# define _DEFINE_COMPILES_ASSERTION0(_line, _code) _DEFINE_COMPILES_ASSERTION1 (_line, _code) -# define DEFINE_COMPILES_ASSERTION(_code) _DEFINE_COMPILES_ASSERTION0 (__LINE__, _code) - - -#define DEFINE_SIZE_STATIC(size) \ - DEFINE_INSTANCE_ASSERTION (sizeof (*this) == (size)); \ - static const unsigned int static_size = (size); \ - static const unsigned int min_size = (size); \ - inline unsigned int get_size (void) const { return (size); } - -#define DEFINE_SIZE_UNION(size, _member) \ - DEFINE_INSTANCE_ASSERTION (0*sizeof(this->u._member.static_size) + sizeof(this->u._member) == (size)); \ - static const unsigned int min_size = (size) - -#define DEFINE_SIZE_MIN(size) \ - DEFINE_INSTANCE_ASSERTION (sizeof (*this) >= (size)); \ - static const unsigned int min_size = (size) - -#define DEFINE_SIZE_ARRAY(size, array) \ - DEFINE_INSTANCE_ASSERTION (sizeof (*this) == (size) + sizeof (array[0])); \ - DEFINE_COMPILES_ASSERTION ((void) array[0].static_size) \ - static const unsigned int min_size = (size) - -#define DEFINE_SIZE_ARRAY2(size, array1, array2) \ - DEFINE_INSTANCE_ASSERTION (sizeof (*this) == (size) + sizeof (this->array1[0]) + sizeof (this->array2[0])); \ - DEFINE_COMPILES_ASSERTION ((void) array1[0].static_size; (void) array2[0].static_size) \ - static const unsigned int min_size = (size) - - - -/* - * Dispatch - */ - -template -struct hb_dispatch_context_t -{ - static const unsigned int max_debug_depth = MaxDebugDepth; - typedef Return return_t; - template - inline bool may_dispatch (const T *obj, const F *format) { return true; } - static return_t no_dispatch_return_value (void) { return Context::default_return_value (); } -}; - - -/* - * Sanitize - */ - -/* This limits sanitizing time on really broken fonts. */ -#ifndef HB_SANITIZE_MAX_EDITS -#define HB_SANITIZE_MAX_EDITS 32 -#endif -#ifndef HB_SANITIZE_MAX_OPS_FACTOR -#define HB_SANITIZE_MAX_OPS_FACTOR 8 -#endif -#ifndef HB_SANITIZE_MAX_OPS_MIN -#define HB_SANITIZE_MAX_OPS_MIN 16384 -#endif - -struct hb_sanitize_context_t : - hb_dispatch_context_t -{ - inline hb_sanitize_context_t (void) : - debug_depth (0), - start (nullptr), end (nullptr), - writable (false), edit_count (0), max_ops (0), - blob (nullptr), - num_glyphs (65536), - num_glyphs_set (false) {} - - inline const char *get_name (void) { return "SANITIZE"; } - template - inline bool may_dispatch (const T *obj, const F *format) - { return format->sanitize (this); } - template - inline return_t dispatch (const T &obj) { return obj.sanitize (this); } - static return_t default_return_value (void) { return true; } - static return_t no_dispatch_return_value (void) { return false; } - bool stop_sublookup_iteration (const return_t r) const { return !r; } - - inline void init (hb_blob_t *b) - { - this->blob = hb_blob_reference (b); - this->writable = false; - } - - inline void set_num_glyphs (unsigned int num_glyphs_) - { - num_glyphs = num_glyphs_; - num_glyphs_set = true; - } - inline unsigned int get_num_glyphs (void) { return num_glyphs; } - - inline void start_processing (void) - { - this->start = hb_blob_get_data (this->blob, nullptr); - this->end = this->start + this->blob->length; - assert (this->start <= this->end); /* Must not overflow. */ - this->max_ops = MAX ((unsigned int) (this->end - this->start) * HB_SANITIZE_MAX_OPS_FACTOR, - (unsigned) HB_SANITIZE_MAX_OPS_MIN); - this->edit_count = 0; - this->debug_depth = 0; - - DEBUG_MSG_LEVEL (SANITIZE, start, 0, +1, - "start [%p..%p] (%lu bytes)", - this->start, this->end, - (unsigned long) (this->end - this->start)); - } - - inline void end_processing (void) - { - DEBUG_MSG_LEVEL (SANITIZE, this->start, 0, -1, - "end [%p..%p] %u edit requests", - this->start, this->end, this->edit_count); - - hb_blob_destroy (this->blob); - this->blob = nullptr; - this->start = this->end = nullptr; - } - - inline bool check_range (const void *base, unsigned int len) const - { - const char *p = (const char *) base; - bool ok = this->max_ops-- > 0 && - this->start <= p && - p <= this->end && - (unsigned int) (this->end - p) >= len; - - DEBUG_MSG_LEVEL (SANITIZE, p, this->debug_depth+1, 0, - "check_range [%p..%p] (%d bytes) in [%p..%p] -> %s", - p, p + len, len, - this->start, this->end, - ok ? "OK" : "OUT-OF-RANGE"); - - return likely (ok); - } - - inline bool check_array (const void *base, unsigned int record_size, unsigned int len) const - { - const char *p = (const char *) base; - bool overflows = hb_unsigned_mul_overflows (len, record_size); - unsigned int array_size = record_size * len; - bool ok = !overflows && this->check_range (base, array_size); - - DEBUG_MSG_LEVEL (SANITIZE, p, this->debug_depth+1, 0, - "check_array [%p..%p] (%d*%d=%d bytes) in [%p..%p] -> %s", - p, p + (record_size * len), record_size, len, (unsigned int) array_size, - this->start, this->end, - overflows ? "OVERFLOWS" : ok ? "OK" : "OUT-OF-RANGE"); - - return likely (ok); - } - - template - inline bool check_struct (const Type *obj) const - { - return likely (this->check_range (obj, obj->min_size)); - } - - inline bool may_edit (const void *base, unsigned int len) - { - if (this->edit_count >= HB_SANITIZE_MAX_EDITS) - return false; - - const char *p = (const char *) base; - this->edit_count++; - - DEBUG_MSG_LEVEL (SANITIZE, p, this->debug_depth+1, 0, - "may_edit(%u) [%p..%p] (%d bytes) in [%p..%p] -> %s", - this->edit_count, - p, p + len, len, - this->start, this->end, - this->writable ? "GRANTED" : "DENIED"); - - return this->writable; - } - - template - inline bool try_set (const Type *obj, const ValueType &v) { - if (this->may_edit (obj, obj->static_size)) { - const_cast (obj)->set (v); - return true; - } - return false; - } - - template - inline hb_blob_t *sanitize_blob (hb_blob_t *blob) - { - bool sane; - - init (blob); - - retry: - DEBUG_MSG_FUNC (SANITIZE, start, "start"); - - start_processing (); - - if (unlikely (!start)) - { - end_processing (); - return blob; - } - - Type *t = CastP (const_cast (start)); - - sane = t->sanitize (this); - if (sane) - { - if (edit_count) - { - DEBUG_MSG_FUNC (SANITIZE, start, "passed first round with %d edits; going for second round", edit_count); - - /* sanitize again to ensure no toe-stepping */ - edit_count = 0; - sane = t->sanitize (this); - if (edit_count) { - DEBUG_MSG_FUNC (SANITIZE, start, "requested %d edits in second round; FAILLING", edit_count); - sane = false; - } - } - } - else - { - if (edit_count && !writable) { - start = hb_blob_get_data_writable (blob, nullptr); - end = start + blob->length; - - if (start) - { - writable = true; - /* ok, we made it writable by relocating. try again */ - DEBUG_MSG_FUNC (SANITIZE, start, "retry"); - goto retry; - } - } - } - - end_processing (); - - DEBUG_MSG_FUNC (SANITIZE, start, sane ? "PASSED" : "FAILED"); - if (sane) - { - blob->lock (); - return blob; - } - else - { - hb_blob_destroy (blob); - return hb_blob_get_empty (); - } - } - - template - inline hb_blob_t *reference_table (const hb_face_t *face, hb_tag_t tableTag = Type::tableTag) - { - if (!num_glyphs_set) - set_num_glyphs (face->get_num_glyphs ()); - return sanitize_blob (face->reference_table (tableTag)); - } - - mutable unsigned int debug_depth; - const char *start, *end; - private: - bool writable; - unsigned int edit_count; - mutable int max_ops; - hb_blob_t *blob; - unsigned int num_glyphs; - bool num_glyphs_set; -}; - - -/* - * Serialize - */ - - -struct hb_serialize_context_t -{ - inline hb_serialize_context_t (void *start_, unsigned int size) - { - this->start = (char *) start_; - this->end = this->start + size; - - this->ran_out_of_room = false; - this->head = this->start; - this->debug_depth = 0; - } - - template - inline Type *start_serialize (void) - { - DEBUG_MSG_LEVEL (SERIALIZE, this->start, 0, +1, - "start [%p..%p] (%lu bytes)", - this->start, this->end, - (unsigned long) (this->end - this->start)); - - return start_embed (); - } - - inline void end_serialize (void) - { - DEBUG_MSG_LEVEL (SERIALIZE, this->start, 0, -1, - "end [%p..%p] serialized %d bytes; %s", - this->start, this->end, - (int) (this->head - this->start), - this->ran_out_of_room ? "RAN OUT OF ROOM" : "did not ran out of room"); - - } - - template - inline Type *copy (void) - { - assert (!this->ran_out_of_room); - unsigned int len = this->head - this->start; - void *p = malloc (len); - if (p) - memcpy (p, this->start, len); - return reinterpret_cast (p); - } - - template - inline Type *allocate_size (unsigned int size) - { - if (unlikely (this->ran_out_of_room || this->end - this->head < ptrdiff_t (size))) { - this->ran_out_of_room = true; - return nullptr; - } - memset (this->head, 0, size); - char *ret = this->head; - this->head += size; - return reinterpret_cast (ret); - } - - template - inline Type *allocate_min (void) - { - return this->allocate_size (Type::min_size); - } - - template - inline Type *start_embed (void) - { - Type *ret = reinterpret_cast (this->head); - return ret; - } - - template - inline Type *embed (const Type &obj) - { - unsigned int size = obj.get_size (); - Type *ret = this->allocate_size (size); - if (unlikely (!ret)) return nullptr; - memcpy (ret, obj, size); - return ret; - } - - template - inline Type *extend_min (Type &obj) - { - unsigned int size = obj.min_size; - assert (this->start <= (char *) &obj && (char *) &obj <= this->head && (char *) &obj + size >= this->head); - if (unlikely (!this->allocate_size (((char *) &obj) + size - this->head))) return nullptr; - return reinterpret_cast (&obj); - } - - template - inline Type *extend (Type &obj) - { - unsigned int size = obj.get_size (); - assert (this->start < (char *) &obj && (char *) &obj <= this->head && (char *) &obj + size >= this->head); - if (unlikely (!this->allocate_size (((char *) &obj) + size - this->head))) return nullptr; - return reinterpret_cast (&obj); - } - - inline void truncate (void *new_head) - { - assert (this->start < new_head && new_head <= this->head); - this->head = (char *) new_head; - } - - unsigned int debug_depth; - char *start, *end, *head; - bool ran_out_of_room; -}; - -template -struct Supplier -{ - inline Supplier (const Type *array, unsigned int len_, unsigned int stride_=sizeof(Type)) - { - head = array; - len = len_; - stride = stride_; - } - inline const Type operator [] (unsigned int i) const - { - if (unlikely (i >= len)) return Type (); - return * (const Type *) (const void *) ((const char *) head + stride * i); - } - - inline Supplier & operator += (unsigned int count) - { - if (unlikely (count > len)) - count = len; - len -= count; - head = (const Type *) (const void *) ((const char *) head + stride * count); - return *this; - } - - private: - inline Supplier (const Supplier &); /* Disallow copy */ - inline Supplier& operator= (const Supplier &); /* Disallow copy */ - - unsigned int len; - unsigned int stride; - const Type *head; -}; - - /* * * The OpenType Font File: Data Types @@ -531,78 +51,6 @@ struct Supplier * Int types */ - -template struct BEInt; - -template -struct BEInt -{ - public: - inline void set (Type V) - { - v = V; - } - inline operator Type (void) const - { - return v; - } - private: uint8_t v; -}; -template -struct BEInt -{ - public: - inline void set (Type V) - { - v[0] = (V >> 8) & 0xFF; - v[1] = (V ) & 0xFF; - } - inline operator Type (void) const - { - return (v[0] << 8) - + (v[1] ); - } - private: uint8_t v[2]; -}; -template -struct BEInt -{ - public: - inline void set (Type V) - { - v[0] = (V >> 16) & 0xFF; - v[1] = (V >> 8) & 0xFF; - v[2] = (V ) & 0xFF; - } - inline operator Type (void) const - { - return (v[0] << 16) - + (v[1] << 8) - + (v[2] ); - } - private: uint8_t v[3]; -}; -template -struct BEInt -{ - public: - inline void set (Type V) - { - v[0] = (V >> 24) & 0xFF; - v[1] = (V >> 16) & 0xFF; - v[2] = (V >> 8) & 0xFF; - v[3] = (V ) & 0xFF; - } - inline operator Type (void) const - { - return (v[0] << 24) - + (v[1] << 16) - + (v[2] << 8) - + (v[3] ); - } - private: uint8_t v[4]; -}; - /* Integer types in big-endian order and no alignment requirement */ template struct IntType @@ -773,7 +221,6 @@ struct FixedVersion }; - /* * Template subclasses of Offset that do the dereferencing. * Use: (base+offset) @@ -839,7 +286,6 @@ static inline Type& operator + (Base &base, OffsetTo &offset) * Array Types */ - /* TODO Use it in ArrayOf, HeadlessArrayOf, and other places around the code base?? */ template struct UnsizedArrayOf @@ -921,7 +367,6 @@ struct UnsizedOffsetListOf : UnsizedOffsetArrayOf } }; - /* An array with a number of elements. */ template struct ArrayOf @@ -1074,7 +519,6 @@ struct OffsetListOf : OffsetArrayOf } }; - /* An array starting at second element. */ template struct HeadlessArrayOf @@ -1139,10 +583,7 @@ struct HeadlessArrayOf DEFINE_SIZE_ARRAY (sizeof (LenType), arrayZ); }; - -/* - * An array with sorted elements. Supports binary searching. - */ +/* An array with sorted elements. Supports binary searching. */ template struct SortedArrayOf : ArrayOf { @@ -1167,10 +608,7 @@ struct SortedArrayOf : ArrayOf } }; -/* - * Binary-search arrays - */ - +/* Binary-search arrays */ struct BinSearchHeader { inline operator uint32_t (void) const { return len; } @@ -1206,107 +644,6 @@ template struct BinSearchArrayOf : SortedArrayOf {}; -/* Lazy struct and blob loaders. */ - -/* Logic is shared between hb_lazy_loader_t and hb_table_lazy_loader_t */ -template -struct hb_lazy_loader_t -{ - inline void init (hb_face_t *face_) - { - face = face_; - instance = nullptr; - } - - inline void fini (void) - { - if (instance && instance != &Null(T)) - { - instance->fini(); - free (instance); - } - } - - inline const T* get (void) const - { - retry: - T *p = (T *) hb_atomic_ptr_get (&instance); - if (unlikely (!p)) - { - p = (T *) calloc (1, sizeof (T)); - if (unlikely (!p)) - p = const_cast (&Null(T)); - else - p->init (face); - if (unlikely (!hb_atomic_ptr_cmpexch (const_cast(&instance), nullptr, p))) - { - if (p != &Null(T)) - p->fini (); - goto retry; - } - } - return p; - } - - inline const T* operator-> (void) const - { - return get (); - } - - private: - hb_face_t *face; - mutable T *instance; -}; - -/* Logic is shared between hb_lazy_loader_t and hb_table_lazy_loader_t */ -template -struct hb_table_lazy_loader_t -{ - inline void init (hb_face_t *face_) - { - face = face_; - blob = nullptr; - } - - inline void fini (void) - { - hb_blob_destroy (blob); - } - - inline hb_blob_t* get_blob (void) const - { - retry: - hb_blob_t *b = (hb_blob_t *) hb_atomic_ptr_get (&blob); - if (unlikely (!b)) - { - b = OT::hb_sanitize_context_t().reference_table (face); - if (!hb_atomic_ptr_cmpexch (&blob, nullptr, b)) - { - hb_blob_destroy (b); - goto retry; - } - blob = b; - } - return b; - } - - inline const T* get (void) const - { - hb_blob_t *b = get_blob (); - return b->as (); - } - - inline const T* operator-> (void) const - { - return get(); - } - - private: - hb_face_t *face; - mutable hb_blob_t *blob; -}; - - } /* namespace OT */ From 3c2842cbcf8cded73d1e310379e1a4ca124a6fc2 Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Wed, 25 Jul 2018 17:07:17 -0700 Subject: [PATCH 101/106] Add hb-iter-private.hh Unused so far. --- src/Makefile.sources | 1 + src/hb-iter-private.hh | 147 ++++++++++++++++++++++++++++++++++++ src/hb-machinery-private.hh | 1 + 3 files changed, 149 insertions(+) create mode 100644 src/hb-iter-private.hh diff --git a/src/Makefile.sources b/src/Makefile.sources index fb4e4a2c4..80b8e261c 100644 --- a/src/Makefile.sources +++ b/src/Makefile.sources @@ -14,6 +14,7 @@ HB_BASE_sources = \ hb-face.cc \ hb-font-private.hh \ hb-font.cc \ + hb-iter-private.hh \ hb-map-private.hh \ hb-map.cc \ hb-machinery-private.hh \ diff --git a/src/hb-iter-private.hh b/src/hb-iter-private.hh new file mode 100644 index 000000000..a22675cd7 --- /dev/null +++ b/src/hb-iter-private.hh @@ -0,0 +1,147 @@ +/* + * Copyright © 2018 Google, Inc. + * + * This is part of HarfBuzz, a text shaping library. + * + * Permission is hereby granted, without written agreement and without + * license or royalty fees, to use, copy, modify, and distribute this + * software and its documentation for any purpose, provided that the + * above copyright notice and the following two paragraphs appear in + * all copies of this software. + * + * IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE TO ANY PARTY FOR + * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES + * ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN + * IF THE COPYRIGHT HOLDER HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH + * DAMAGE. + * + * THE COPYRIGHT HOLDER SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, + * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS + * ON AN "AS IS" BASIS, AND THE COPYRIGHT HOLDER HAS NO OBLIGATION TO + * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. + * + * Google Author(s): Behdad Esfahbod + */ + +#ifndef HB_ITER_PRIVATE_HH +#define HB_ITER_PRIVATE_HH + +#include "hb-private.hh" + + +/* Unified iterator object. + * + * The goal of this template is to make the same iterator interface + * available to all types, and make it very easy and compact to use. + * Iterator objects are small, light-weight, objects that can be + * copied by value. If the collection / object being iterated on + * is writable, then the iterator points to lvalues, otherwise it + * returns rvalues. + * + * The way to declare, initialize, and use iterators, eg.: + * + * Iter s (src); + * Iter t (dst); + * for (; s && t; s++, t++) + * *s = *t; + */ + +template +struct Iter; + +template +struct Iter +{ + inline Iter (const T &c); +}; + +template +struct Iter +{ + /* Type of items. */ + typedef T Value; + + /* Constructors. */ + inline Iter (T *array_, int length_) : + array (array_), length (MAX (length_, 0)) {} + template + inline Iter (T (&array_)[length_]) : + array (array_), length (length_) {} + + /* Emptiness. */ + inline operator bool (void) const { return bool (length); } + + /* Current item. */ + inline T &operator * (void) + { + if (unlikely (!length)) return CrapOrNull(T); + return *array; + } + inline T &operator -> (void) + { + return (operator *); + } + + /* Next. */ + inline Iter & operator ++ (void) + { + if (unlikely (!length)) return *this; + array++; + length--; + return *this; + } + /* Might return void, or a copy of pre-increment iterator. */ + inline void operator ++ (int) + { + if (unlikely (!length)) return; + array++; + length--; + } + + /* Some iterators might implement len(). */ + inline unsigned int len (void) const { return length; } + + /* Some iterators might implement fast-forward. + * Only implement it if it's constant-time. */ + inline void operator += (unsigned int n) + { + n = MIN (n, length); + array += n; + length -= n; + } + + /* Some iterators might implement random-access. + * Only implement it if it's constant-time. */ + inline Iter & operator [] (unsigned int i) + { + if (unlikely (i >= length)) return CrapOrNull(T); + return array[i]; + } + + private: + T *array; + unsigned int length; +}; + +/* XXX Remove + * Just to test these compile. */ +static inline void +m (void) +{ + const int src[10] = {}; + int dst[20]; + + Iter s (src); + Iter s2 (src, 5); + Iter t (dst); + + s2 = s; + + for (; s && t; s++, t++) + { + *t = *s; + } +} + +#endif /* HB_ITER_PRIVATE_HH */ diff --git a/src/hb-machinery-private.hh b/src/hb-machinery-private.hh index 5fafadbec..649788c16 100644 --- a/src/hb-machinery-private.hh +++ b/src/hb-machinery-private.hh @@ -30,6 +30,7 @@ #define HB_MACHINERY_PRIVATE_HH #include "hb-private.hh" +#include "hb-iter-private.hh" namespace OT { From 2e25d8f49181ab1d7fda520ae6587d293a982acf Mon Sep 17 00:00:00 2001 From: prrace Date: Fri, 27 Jul 2018 13:58:27 -0700 Subject: [PATCH 102/106] Fix unlikely leaks --- src/hb-ft.cc | 4 +++- src/hb-ot-shape.cc | 4 +++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/src/hb-ft.cc b/src/hb-ft.cc index 6670d9a60..1026d6824 100644 --- a/src/hb-ft.cc +++ b/src/hb-ft.cc @@ -496,8 +496,10 @@ reference_table (hb_face_t *face HB_UNUSED, hb_tag_t tag, void *user_data) return nullptr; error = FT_Load_Sfnt_Table (ft_face, tag, 0, buffer, &length); - if (error) + if (error) { + free ((void*)buffer); return nullptr; + } return hb_blob_create ((const char *) buffer, length, HB_MEMORY_MODE_WRITABLE, diff --git a/src/hb-ot-shape.cc b/src/hb-ot-shape.cc index 6696ad885..70c9c63c6 100644 --- a/src/hb-ot-shape.cc +++ b/src/hb-ot-shape.cc @@ -193,8 +193,10 @@ _hb_ot_shaper_shape_plan_data_create (hb_shape_plan_t *shape_plan, if (plan->shaper->data_create) { plan->data = plan->shaper->data_create (plan); - if (unlikely (!plan->data)) + if (unlikely (!plan->data)) { + free ((void*)plan); return nullptr; + } } return plan; From 7f08818c441517f73c5bea0a2a88f494dfc8fa58 Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Wed, 25 Jul 2018 17:22:05 -0700 Subject: [PATCH 103/106] Minor --- src/hb-iter-private.hh | 8 +++++--- src/hb-machinery-private.hh | 1 - 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/src/hb-iter-private.hh b/src/hb-iter-private.hh index a22675cd7..410a50f94 100644 --- a/src/hb-iter-private.hh +++ b/src/hb-iter-private.hh @@ -50,11 +50,13 @@ template struct Iter; +#if 0 template struct Iter { - inline Iter (const T &c); + explicit inline Iter (const T &c); }; +#endif template struct Iter @@ -66,7 +68,7 @@ struct Iter inline Iter (T *array_, int length_) : array (array_), length (MAX (length_, 0)) {} template - inline Iter (T (&array_)[length_]) : + explicit inline Iter (T (&array_)[length_]) : array (array_), length (length_) {} /* Emptiness. */ @@ -138,7 +140,7 @@ m (void) s2 = s; - for (; s && t; s++, t++) + for (; s && t; ++s, ++t) { *t = *s; } diff --git a/src/hb-machinery-private.hh b/src/hb-machinery-private.hh index 649788c16..653d7c6f2 100644 --- a/src/hb-machinery-private.hh +++ b/src/hb-machinery-private.hh @@ -400,7 +400,6 @@ struct hb_serialize_context_t this->start, this->end, (int) (this->head - this->start), this->ran_out_of_room ? "RAN OUT OF ROOM" : "did not ran out of room"); - } template From ecab6604e57ea2bb4e78250a7a400e15b3e86f7a Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Wed, 25 Jul 2018 17:37:38 -0700 Subject: [PATCH 104/106] [serialize] Allocate for markFilteringSet --- src/hb-ot-layout-common-private.hh | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/hb-ot-layout-common-private.hh b/src/hb-ot-layout-common-private.hh index 7ff0dbebb..dec237c8f 100644 --- a/src/hb-ot-layout-common-private.hh +++ b/src/hb-ot-layout-common-private.hh @@ -615,6 +615,14 @@ struct Lookup inline OffsetArrayOf& get_subtables (void) { return CastR > (subTable); } + inline unsigned int get_size (void) const + { + const HBUINT16 &markFilteringSet = StructAfter (subTable); + if (lookupFlag & LookupFlag::UseMarkFilteringSet) + return (const char *) &StructAfter (markFilteringSet) - (const char *) this; + return (const char *) &markFilteringSet - (const char *) this; + } + inline unsigned int get_type (void) const { return lookupType; } /* lookup_props is a 32-bit integer where the lower 16-bit is LookupFlag and @@ -657,6 +665,7 @@ struct Lookup if (unlikely (!subTable.serialize (c, num_subtables))) return_trace (false); if (lookupFlag & LookupFlag::UseMarkFilteringSet) { + if (unlikely (!c->extend (*this))) return_trace (false); HBUINT16 &markFilteringSet = StructAfter (subTable); markFilteringSet.set (lookup_props >> 16); } From 42c183f80355fe7cadac2931a23d389285c8b98c Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Fri, 27 Jul 2018 14:55:29 -0700 Subject: [PATCH 105/106] Minor --- src/hb-ft.cc | 5 +++-- src/hb-ot-shape.cc | 5 +++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/hb-ft.cc b/src/hb-ft.cc index 1026d6824..f8a6b0c46 100644 --- a/src/hb-ft.cc +++ b/src/hb-ft.cc @@ -496,8 +496,9 @@ reference_table (hb_face_t *face HB_UNUSED, hb_tag_t tag, void *user_data) return nullptr; error = FT_Load_Sfnt_Table (ft_face, tag, 0, buffer, &length); - if (error) { - free ((void*)buffer); + if (error) + { + free (buffer); return nullptr; } diff --git a/src/hb-ot-shape.cc b/src/hb-ot-shape.cc index 70c9c63c6..e40a0e94a 100644 --- a/src/hb-ot-shape.cc +++ b/src/hb-ot-shape.cc @@ -193,8 +193,9 @@ _hb_ot_shaper_shape_plan_data_create (hb_shape_plan_t *shape_plan, if (plan->shaper->data_create) { plan->data = plan->shaper->data_create (plan); - if (unlikely (!plan->data)) { - free ((void*)plan); + if (unlikely (!plan->data)) + { + free (plan); return nullptr; } } From 5edf454aa64aad461c90bd991e7eaf27668b7e6b Mon Sep 17 00:00:00 2001 From: Garret Rieger Date: Thu, 26 Jul 2018 17:42:02 -0700 Subject: [PATCH 106/106] [subset] During lookup collection remember the features we've already processed. --- src/hb-ot-layout.cc | 26 ++++++++++++++---- ...inimized-hb-subset-fuzzer-5670861909524480 | Bin 0 -> 1298 bytes ...set-get-codepoints-fuzzer-6136125075750912 | Bin 0 -> 65816 bytes 3 files changed, 21 insertions(+), 5 deletions(-) create mode 100644 test/api/fonts/clusterfuzz-testcase-minimized-hb-subset-fuzzer-5670861909524480 create mode 100644 test/api/fonts/clusterfuzz-testcase-minimized-hb-subset-get-codepoints-fuzzer-6136125075750912 diff --git a/src/hb-ot-layout.cc b/src/hb-ot-layout.cc index 01ca5143d..b38dbc384 100644 --- a/src/hb-ot-layout.cc +++ b/src/hb-ot-layout.cc @@ -663,6 +663,7 @@ _hb_ot_layout_collect_lookups_features (hb_face_t *face, unsigned int script_index, unsigned int language_index, const hb_tag_t *features, + hb_set_t *visited_features, hb_set_t *lookup_indexes /* OUT */) { if (!features) @@ -673,11 +674,15 @@ _hb_ot_layout_collect_lookups_features (hb_face_t *face, script_index, language_index, &required_feature_index, - nullptr)) - _hb_ot_layout_collect_lookups_lookups (face, - table_tag, - required_feature_index, - lookup_indexes); + nullptr) + && !visited_features->has (required_feature_index)) + { + _hb_ot_layout_collect_lookups_lookups (face, + table_tag, + required_feature_index, + lookup_indexes); + visited_features->add (required_feature_index); + } /* All features */ unsigned int feature_indices[32]; @@ -694,10 +699,14 @@ _hb_ot_layout_collect_lookups_features (hb_face_t *face, feature_indices); for (unsigned int i = 0; i < len; i++) + { + if (visited_features->has (feature_indices[i])) continue; _hb_ot_layout_collect_lookups_lookups (face, table_tag, feature_indices[i], lookup_indexes); + visited_features->add (feature_indices[i]); + } offset += len; } while (len == ARRAY_LENGTH (feature_indices)); @@ -727,6 +736,7 @@ _hb_ot_layout_collect_lookups_languages (hb_face_t *face, unsigned int script_index, const hb_tag_t *languages, const hb_tag_t *features, + hb_set_t *visited_features, hb_set_t *lookup_indexes /* OUT */) { _hb_ot_layout_collect_lookups_features (face, @@ -734,6 +744,7 @@ _hb_ot_layout_collect_lookups_languages (hb_face_t *face, script_index, HB_OT_LAYOUT_DEFAULT_LANGUAGE_INDEX, features, + visited_features, lookup_indexes); if (!languages) @@ -749,6 +760,7 @@ _hb_ot_layout_collect_lookups_languages (hb_face_t *face, script_index, language_index, features, + visited_features, lookup_indexes); } else @@ -766,6 +778,7 @@ _hb_ot_layout_collect_lookups_languages (hb_face_t *face, script_index, language_index, features, + visited_features, lookup_indexes); } } @@ -784,6 +797,7 @@ hb_ot_layout_collect_lookups (hb_face_t *face, const hb_tag_t *features, hb_set_t *lookup_indexes /* OUT */) { + hb_auto_t visited_features; if (!scripts) { /* All scripts */ @@ -796,6 +810,7 @@ hb_ot_layout_collect_lookups (hb_face_t *face, script_index, languages, features, + &visited_features, lookup_indexes); } else @@ -812,6 +827,7 @@ hb_ot_layout_collect_lookups (hb_face_t *face, script_index, languages, features, + &visited_features, lookup_indexes); } } diff --git a/test/api/fonts/clusterfuzz-testcase-minimized-hb-subset-fuzzer-5670861909524480 b/test/api/fonts/clusterfuzz-testcase-minimized-hb-subset-fuzzer-5670861909524480 new file mode 100644 index 0000000000000000000000000000000000000000..49bcb30988a73e81f8a5be7d8562ce2bddf759f1 GIT binary patch literal 1298 zcmcgrOGs2v82-+6oY65Kp+?$E(i9(+Z_P;5OcO*S%@(0{y`wY8T<0<~nQcmXEzMO# zt2XUx5fqiFshL@sB~-d-5mF1WAOs7#efKDpw3W``o^$^1|Ihb7&VL~QB*}rwhQrmA zhJZ}DX&jc=f4klfjgf7rBhdX4CQp>0&usH z_DNl;-ad9Ec`M~0VDC44fnaOPjWXbojrrU&{Ov~7f%`j|EdAq}l{uWqzOyTm*9;uB?(ws@ z1#eobLO@7vK{o3gB3B2(5eLSL78pb=P0#9nRqlksB`z{naODexva}=^cM|>B5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