pango: use bsearch() implementation from Musl libc

See https://github.com/termux/termux-packages/issues/4284.

Note: bsearch implementation in Bionic didn't changed since
Thu Feb 20 14:15:09 2014, though issue #4284 is not reproducible
on recent Android versions. Patch is applied for both branches.
This commit is contained in:
Leonid Pliushch 2019-09-23 14:20:20 +03:00
parent 9ff63910c4
commit 00f317de48
2 changed files with 89 additions and 0 deletions

View File

@ -0,0 +1,88 @@
diff -uNr pango-1.44.6/pango/musl_bsearch.h pango-1.44.6.mod/pango/musl_bsearch.h
--- pango-1.44.6/pango/musl_bsearch.h 1970-01-01 03:00:00.000000000 +0300
+++ pango-1.44.6.mod/pango/musl_bsearch.h 2019-09-23 14:15:30.721769563 +0300
@@ -0,0 +1,23 @@
+#include <stdlib.h>
+//
+// bsearch() implementation from Musl libc.
+//
+
+static void *musl_bsearch(const void *key, const void *base, size_t nel, size_t width, int (*cmp)(const void *, const void *))
+{
+ void *try;
+ int sign;
+ while (nel > 0) {
+ try = (char *)base + width*(nel/2);
+ sign = cmp(key, try);
+ if (sign < 0) {
+ nel /= 2;
+ } else if (sign > 0) {
+ base = (char *)try + width;
+ nel -= nel/2+1;
+ } else {
+ return try;
+ }
+ }
+ return NULL;
+}
diff -uNr pango-1.44.6/pango/pango-color.c pango-1.44.6.mod/pango/pango-color.c
--- pango-1.44.6/pango/pango-color.c 2019-09-03 15:11:42.000000000 +0300
+++ pango-1.44.6.mod/pango/pango-color.c 2019-09-23 14:15:01.798237443 +0300
@@ -144,6 +144,7 @@
*/
#include "pango-color-table.h"
+#include "musl_bsearch.h"
#define ISUPPER(c) ((c) >= 'A' && (c) <= 'Z')
#define TOLOWER(c) (ISUPPER (c) ? (c) - 'A' + 'a' : (c))
@@ -175,7 +176,7 @@
{
ColorEntry *found;
- found = bsearch (name, color_entries, G_N_ELEMENTS (color_entries),
+ found = musl_bsearch (name, color_entries, G_N_ELEMENTS (color_entries),
sizeof (ColorEntry),
compare_xcolor_entries);
if (found == NULL)
diff -uNr pango-1.44.6/pango/pango-emoji.c pango-1.44.6.mod/pango/pango-emoji.c
--- pango-1.44.6/pango/pango-emoji.c 2019-09-03 15:11:42.000000000 +0300
+++ pango-1.44.6.mod/pango/pango-emoji.c 2019-09-23 14:14:46.718134698 +0300
@@ -51,7 +51,7 @@
#include "pango-emoji-private.h"
#include "pango-emoji-table.h"
-
+#include "musl_bsearch.h"
static int
interval_compare (const void *key, const void *elt)
@@ -78,7 +78,7 @@
return FALSE; \
*/ \
\
- if (bsearch (GUINT_TO_POINTER (ch), \
+ if (musl_bsearch (GUINT_TO_POINTER (ch), \
_pango_##name##_table, \
G_N_ELEMENTS (_pango_##name##_table), \
sizeof _pango_##name##_table[0], \
diff -uNr pango-1.44.6/pango/pango-language.c pango-1.44.6.mod/pango/pango-language.c
--- pango-1.44.6/pango/pango-language.c 2019-09-03 15:11:42.000000000 +0300
+++ pango-1.44.6.mod/pango/pango-language.c 2019-09-23 14:14:16.651265104 +0300
@@ -28,6 +28,7 @@
#include "pango-language.h"
#include "pango-impl-utils.h"
+#include "musl_bsearch.h"
#ifdef HAVE_CORE_TEXT
#include <CoreFoundation/CoreFoundation.h>
@@ -467,7 +468,7 @@
lang_str = pango_language_to_string (language);
- record = bsearch (lang_str,
+ record = musl_bsearch (lang_str,
records, num_records, record_size,
lang_compare_first_component);
if (!record)

View File

@ -2,6 +2,7 @@ TERMUX_PKG_HOMEPAGE=https://www.pango.org/
TERMUX_PKG_DESCRIPTION="Library for laying out and rendering text"
TERMUX_PKG_LICENSE="LGPL-2.0"
TERMUX_PKG_VERSION=1.44.6
TERMUX_PKG_REVISION=1
TERMUX_PKG_SRCURL=https://ftp.gnome.org/pub/GNOME/sources/pango/${TERMUX_PKG_VERSION:0:4}/pango-${TERMUX_PKG_VERSION}.tar.xz
TERMUX_PKG_SHA256=3e1e41ba838737e200611ff001e3b304c2ca4cdbba63d200a20db0b0ddc0f86c
TERMUX_PKG_EXTRA_CONFIGURE_ARGS="-Dintrospection=false"