1 From ca0aa5f6960c09e5cf5cb20249f895628fd97449 Mon Sep 17 00:00:00 2001
2 From: Heiko Becker <heirecka@exherbo.org>
3 Date: Sat, 5 Dec 2020 11:30:42 +0100
4 Subject: [PATCH] Fix build with ICU >= 68
6 ICU stopped defining the macros FALSE and TRUE in its headers with 68:
7 https://github.com/unicode-org/icu/commit/c3fe7e09d844
9 src/calibre/utils/icu.c | 6 ++++--
10 src/calibre/utils/matcher.c | 18 ++++++++----------
11 2 files changed, 12 insertions(+), 12 deletions(-)
13 diff --git a/src/calibre/utils/icu.c b/src/calibre/utils/icu.c
14 index 62d05de3101..36902dbdd25 100644
15 --- a/src/calibre/utils/icu.c
16 +++ b/src/calibre/utils/icu.c
18 #include "icu_calibre_utils.h"
25 @@ -238,14 +240,14 @@ icu_Collator_contains(icu_Collator *self, PyObject *args) {
27 a = python_to_icu(a_, &asz);
28 if (a == NULL) goto end;
29 - if (asz == 0) { found = TRUE; goto end; }
30 + if (asz == 0) { found = true; goto end; }
31 b = python_to_icu(b_, &bsz);
32 if (b == NULL) goto end;
34 search = usearch_openFromCollator(a, asz, b, bsz, self->collator, NULL, &status);
35 if (U_SUCCESS(status)) {
36 pos = usearch_first(search, &status);
37 - if (pos != USEARCH_DONE) found = TRUE;
38 + if (pos != USEARCH_DONE) found = true;
41 if (search != NULL) usearch_close(search);
42 diff --git a/src/calibre/utils/matcher.c b/src/calibre/utils/matcher.c
43 index f38a7082cee..72715cc0ae3 100644
44 --- a/src/calibre/utils/matcher.c
45 +++ b/src/calibre/utils/matcher.c
47 #define NO_PYTHON_TO_ICU32
48 #include "icu_calibre_utils.h"
53 // inline does not work with the visual studio C compiler
57 -typedef unsigned char bool;
60 #define MAX(x, y) ((x > y) ? x : y)
61 #define nullfree(x) if(x != NULL) free(x); x = NULL;
63 @@ -240,10 +238,10 @@ static bool create_searches(UStringSearch **searches, UChar *haystack, int32_t h
64 U16_FWD_1(needle, i, needle_len);
66 searches[pos] = usearch_openFromCollator(needle + pos, i - pos, haystack, haystack_len, collator, NULL, &status);
67 - if (U_FAILURE(status)) { PyErr_SetString(PyExc_ValueError, u_errorName(status)); searches[pos] = NULL; return FALSE; }
68 + if (U_FAILURE(status)) { PyErr_SetString(PyExc_ValueError, u_errorName(status)); searches[pos] = NULL; return false; }
75 static void free_searches(UStringSearch **searches, int32_t count) {
76 @@ -259,14 +257,14 @@ static bool match(UChar **items, int32_t *item_lengths, uint32_t item_count, UCh
77 int32_t i = 0, maxhl = 0;
78 int32_t r = 0, *positions = NULL;
79 MatchInfo *matches = NULL;
82 MemoryItem ***memo = NULL;
83 int32_t needle_len = u_strlen(needle);
84 UStringSearch **searches = NULL;
86 if (needle_len <= 0 || item_count <= 0) {
87 for (i = 0; i < (int32_t)item_count; i++) match_results[i].score = 0.0;
93 @@ -289,7 +287,7 @@ static bool match(UChar **items, int32_t *item_lengths, uint32_t item_count, UCh
96 for (i = 0; i < (int32_t)item_count; i++) match_results[i].score = 0.0;
102 @@ -308,7 +306,7 @@ static bool match(UChar **items, int32_t *item_lengths, uint32_t item_count, UCh
103 convert_positions(positions, final_positions + i * needle_char_len, matches[i].haystack, needle_char_len, needle_len, match_results[i].score);
110 nullfree(stack.items);
111 @@ -401,7 +399,7 @@ static PyObject *
112 Matcher_calculate_scores(Matcher *self, PyObject *args) {
113 int32_t *final_positions = NULL, *p;
114 Match *matches = NULL;
117 uint32_t i = 0, needle_char_len = 0, j = 0;
118 PyObject *items = NULL, *score = NULL, *positions = NULL, *pneedle = NULL;
119 UChar *needle = NULL;