diff options
Diffstat (limited to 'meta/recipes-core/systemd/systemd/0002-don-t-use-glibc-specific-qsort_r.patch')
-rw-r--r-- | meta/recipes-core/systemd/systemd/0002-don-t-use-glibc-specific-qsort_r.patch | 231 |
1 files changed, 106 insertions, 125 deletions
diff --git a/meta/recipes-core/systemd/systemd/0002-don-t-use-glibc-specific-qsort_r.patch b/meta/recipes-core/systemd/systemd/0002-don-t-use-glibc-specific-qsort_r.patch index 8e0d669e83..36e0699da9 100644 --- a/meta/recipes-core/systemd/systemd/0002-don-t-use-glibc-specific-qsort_r.patch +++ b/meta/recipes-core/systemd/systemd/0002-don-t-use-glibc-specific-qsort_r.patch | |||
@@ -1,31 +1,100 @@ | |||
1 | From d74a4de6daea5a511c2b5636bbb552c15b3a4ad9 Mon Sep 17 00:00:00 2001 | 1 | From 1eb84534dea05d41afed1d898cba212ad7d310dd Mon Sep 17 00:00:00 2001 |
2 | From: Emil Renner Berthing <systemd@esmil.dk> | 2 | From: Chen Qi <Qi.Chen@windriver.com> |
3 | Date: Thu, 18 Sep 2014 15:24:56 +0200 | 3 | Date: Mon, 25 Feb 2019 13:41:41 +0800 |
4 | Subject: [PATCH] don't use glibc-specific qsort_r | 4 | Subject: [PATCH 02/24] don't use glibc-specific qsort_r |
5 | 5 | ||
6 | Upstream-Status: Inappropriate [musl specific] | 6 | Upstream-Status: Inappropriate [musl specific] |
7 | 7 | ||
8 | Signed-off-by: Khem Raj <raj.khem@gmail.com> | 8 | Signed-off-by: Khem Raj <raj.khem@gmail.com> |
9 | [Rebased for v241] | ||
10 | Signed-off-by: Chen Qi <Qi.Chen@windriver.com> | ||
9 | --- | 11 | --- |
10 | src/basic/format-table.c | 27 ++++++++++++++++----------- | 12 | src/basic/util.h | 14 -------------- |
11 | src/basic/util.h | 7 ------- | 13 | src/libsystemd/sd-hwdb/hwdb-util.c | 19 ++++++++++++++----- |
12 | src/hwdb/hwdb.c | 18 +++++++++++------- | 14 | src/shared/format-table.c | 36 ++++++++++++++++++++++++------------ |
13 | src/udev/udevadm-hwdb.c | 16 ++++++++++------ | 15 | 3 files changed, 38 insertions(+), 31 deletions(-) |
14 | 4 files changed, 37 insertions(+), 31 deletions(-) | ||
15 | 16 | ||
16 | diff --git a/src/basic/format-table.c b/src/basic/format-table.c | 17 | diff --git a/src/basic/util.h b/src/basic/util.h |
17 | index 94e796d1ca..9b3f35c29a 100644 | 18 | index dc33d66..9f6a6ce 100644 |
18 | --- a/src/basic/format-table.c | 19 | --- a/src/basic/util.h |
19 | +++ b/src/basic/format-table.c | 20 | +++ b/src/basic/util.h |
20 | @@ -745,29 +745,29 @@ static int cell_data_compare(TableData *a, size_t index_a, TableData *b, size_t | 21 | @@ -116,20 +116,6 @@ static inline void qsort_safe(void *base, size_t nmemb, size_t size, __compar_fn |
22 | qsort_safe((p), (n), sizeof((p)[0]), (__compar_fn_t) _func_); \ | ||
23 | }) | ||
24 | |||
25 | -static inline void qsort_r_safe(void *base, size_t nmemb, size_t size, __compar_d_fn_t compar, void *userdata) { | ||
26 | - if (nmemb <= 1) | ||
27 | - return; | ||
28 | - | ||
29 | - assert(base); | ||
30 | - qsort_r(base, nmemb, size, compar, userdata); | ||
31 | -} | ||
32 | - | ||
33 | -#define typesafe_qsort_r(p, n, func, userdata) \ | ||
34 | - ({ \ | ||
35 | - int (*_func_)(const typeof(p[0])*, const typeof(p[0])*, typeof(userdata)) = func; \ | ||
36 | - qsort_r_safe((p), (n), sizeof((p)[0]), (__compar_d_fn_t) _func_, userdata); \ | ||
37 | - }) | ||
38 | - | ||
39 | /* Normal memcpy requires src to be nonnull. We do nothing if n is 0. */ | ||
40 | static inline void memcpy_safe(void *dst, const void *src, size_t n) { | ||
41 | if (n == 0) | ||
42 | diff --git a/src/libsystemd/sd-hwdb/hwdb-util.c b/src/libsystemd/sd-hwdb/hwdb-util.c | ||
43 | index f852967..b570ce1 100644 | ||
44 | --- a/src/libsystemd/sd-hwdb/hwdb-util.c | ||
45 | +++ b/src/libsystemd/sd-hwdb/hwdb-util.c | ||
46 | @@ -126,9 +126,13 @@ static void trie_free(struct trie *trie) { | ||
47 | |||
48 | DEFINE_TRIVIAL_CLEANUP_FUNC(struct trie*, trie_free); | ||
49 | |||
50 | -static int trie_values_cmp(const struct trie_value_entry *a, const struct trie_value_entry *b, struct trie *trie) { | ||
51 | - return strcmp(trie->strings->buf + a->key_off, | ||
52 | - trie->strings->buf + b->key_off); | ||
53 | +static struct trie *trie_node_add_value_trie; | ||
54 | +static int trie_values_cmp(const void *v1, const void *v2) { | ||
55 | + const struct trie_value_entry *a = v1; | ||
56 | + const struct trie_value_entry *b = v2; | ||
57 | + | ||
58 | + return strcmp(trie_node_add_value_trie->strings->buf + a->key_off, | ||
59 | + trie_node_add_value_trie->strings->buf + b->key_off); | ||
60 | } | ||
61 | |||
62 | static int trie_node_add_value(struct trie *trie, struct trie_node *node, | ||
63 | @@ -156,7 +160,10 @@ static int trie_node_add_value(struct trie *trie, struct trie_node *node, | ||
64 | .value_off = v, | ||
65 | }; | ||
66 | |||
67 | - val = typesafe_bsearch_r(&search, node->values, node->values_count, trie_values_cmp, trie); | ||
68 | + trie_node_add_value_trie = trie; | ||
69 | + val = bsearch(&search, node->values, node->values_count, sizeof(struct trie_value_entry), trie_values_cmp); | ||
70 | + trie_node_add_value_trie = NULL; | ||
71 | + | ||
72 | if (val) { | ||
73 | /* At this point we have 2 identical properties on the same match-string. | ||
74 | * Since we process files in order, we just replace the previous value. */ | ||
75 | @@ -182,7 +189,9 @@ static int trie_node_add_value(struct trie *trie, struct trie_node *node, | ||
76 | .line_number = line_number, | ||
77 | }; | ||
78 | node->values_count++; | ||
79 | - typesafe_qsort_r(node->values, node->values_count, trie_values_cmp, trie); | ||
80 | + trie_node_add_value_trie = trie; | ||
81 | + qsort(node->values, node->values_count, sizeof(struct trie_value_entry), trie_values_cmp); | ||
82 | + trie_node_add_value_trie = NULL; | ||
21 | return 0; | 83 | return 0; |
22 | } | 84 | } |
23 | 85 | ||
24 | -static int table_data_compare(const void *x, const void *y, void *userdata) { | 86 | diff --git a/src/shared/format-table.c b/src/shared/format-table.c |
87 | index 7d52980..75dbfe1 100644 | ||
88 | --- a/src/shared/format-table.c | ||
89 | +++ b/src/shared/format-table.c | ||
90 | @@ -848,31 +848,33 @@ static int cell_data_compare(TableData *a, size_t index_a, TableData *b, size_t | ||
91 | return CMP(index_a, index_b); | ||
92 | } | ||
93 | |||
94 | -static int table_data_compare(const size_t *a, const size_t *b, Table *t) { | ||
25 | +static Table *user_table; | 95 | +static Table *user_table; |
26 | +static int table_data_compare(const void *x, const void *y) { | 96 | +static int table_data_compare(const void *x, const void *y) { |
27 | const size_t *a = x, *b = y; | 97 | + const size_t *a = x, *b=y; |
28 | - Table *t = userdata; | ||
29 | size_t i; | 98 | size_t i; |
30 | int r; | 99 | int r; |
31 | 100 | ||
@@ -57,11 +126,16 @@ index 94e796d1ca..9b3f35c29a 100644 | |||
57 | 126 | ||
58 | r = cell_data_compare(d, *a, dd, *b); | 127 | r = cell_data_compare(d, *a, dd, *b); |
59 | if (r != 0) | 128 | if (r != 0) |
60 | @@ -960,7 +960,12 @@ int table_print(Table *t, FILE *f) { | 129 | - return t->reverse_map && t->reverse_map[t->sort_map[i]] ? -r : r; |
130 | + return user_table->reverse_map && user_table->reverse_map[user_table->sort_map[i]] ? -r : r; | ||
131 | } | ||
132 | |||
133 | /* Order identical lines by the order there were originally added in */ | ||
134 | @@ -1105,7 +1107,12 @@ int table_print(Table *t, FILE *f) { | ||
61 | for (i = 0; i < n_rows; i++) | 135 | for (i = 0; i < n_rows; i++) |
62 | sorted[i] = i * t->n_columns; | 136 | sorted[i] = i * t->n_columns; |
63 | 137 | ||
64 | - qsort_r_safe(sorted, n_rows, sizeof(size_t), table_data_compare, t); | 138 | - typesafe_qsort_r(sorted, n_rows, table_data_compare, t); |
65 | + if (n_rows <= 1) | 139 | + if (n_rows <= 1) |
66 | + return 0; | 140 | + return 0; |
67 | + assert(sorted); | 141 | + assert(sorted); |
@@ -71,113 +145,20 @@ index 94e796d1ca..9b3f35c29a 100644 | |||
71 | } | 145 | } |
72 | 146 | ||
73 | if (t->display_map) | 147 | if (t->display_map) |
74 | diff --git a/src/basic/util.h b/src/basic/util.h | 148 | @@ -1532,7 +1539,12 @@ int table_to_json(Table *t, JsonVariant **ret) { |
75 | index 9699d228f9..40eaf518cb 100644 | 149 | for (i = 0; i < n_rows; i++) |
76 | --- a/src/basic/util.h | 150 | sorted[i] = i * t->n_columns; |
77 | +++ b/src/basic/util.h | ||
78 | @@ -105,13 +105,6 @@ static inline void qsort_safe(void *base, size_t nmemb, size_t size, comparison_ | ||
79 | qsort_safe((p), (n), sizeof((p)[0]), (__compar_fn_t) _func_); \ | ||
80 | }) | ||
81 | |||
82 | -static inline void qsort_r_safe(void *base, size_t nmemb, size_t size, int (*compar)(const void*, const void*, void*), void *userdata) { | ||
83 | - if (nmemb <= 1) | ||
84 | - return; | ||
85 | - | ||
86 | - assert(base); | ||
87 | - qsort_r(base, nmemb, size, compar, userdata); | ||
88 | -} | ||
89 | |||
90 | /** | ||
91 | * Normal memcpy requires src to be nonnull. We do nothing if n is 0. | ||
92 | diff --git a/src/hwdb/hwdb.c b/src/hwdb/hwdb.c | ||
93 | index 317cad8a67..701d59a1eb 100644 | ||
94 | --- a/src/hwdb/hwdb.c | ||
95 | +++ b/src/hwdb/hwdb.c | ||
96 | @@ -135,13 +135,12 @@ static void trie_free(struct trie *trie) { | ||
97 | |||
98 | DEFINE_TRIVIAL_CLEANUP_FUNC(struct trie*, trie_free); | ||
99 | |||
100 | -static int trie_values_cmp(const void *v1, const void *v2, void *arg) { | ||
101 | +static struct trie *trie_node_add_value_trie; | ||
102 | +static int trie_values_cmp(const void *v1, const void *v2) { | ||
103 | const struct trie_value_entry *val1 = v1; | ||
104 | const struct trie_value_entry *val2 = v2; | ||
105 | - struct trie *trie = arg; | ||
106 | - | ||
107 | - return strcmp(trie->strings->buf + val1->key_off, | ||
108 | - trie->strings->buf + val2->key_off); | ||
109 | + return strcmp(trie_node_add_value_trie->strings->buf + val1->key_off, | ||
110 | + trie_node_add_value_trie->strings->buf + val2->key_off); | ||
111 | } | ||
112 | |||
113 | static int trie_node_add_value(struct trie *trie, struct trie_node *node, | ||
114 | @@ -166,7 +165,10 @@ static int trie_node_add_value(struct trie *trie, struct trie_node *node, | ||
115 | .value_off = v, | ||
116 | }; | ||
117 | |||
118 | - val = xbsearch_r(&search, node->values, node->values_count, sizeof(struct trie_value_entry), trie_values_cmp, trie); | ||
119 | + trie_node_add_value_trie = trie; | ||
120 | + val = bsearch(&search, node->values, node->values_count, sizeof(struct trie_value_entry), trie_values_cmp); | ||
121 | + trie_node_add_value_trie = NULL; | ||
122 | + | ||
123 | if (val) { | ||
124 | /* At this point we have 2 identical properties on the same match-string. | ||
125 | * Since we process files in order, we just replace the previous value. | ||
126 | @@ -191,7 +193,9 @@ static int trie_node_add_value(struct trie *trie, struct trie_node *node, | ||
127 | node->values[node->values_count].file_priority = file_priority; | ||
128 | node->values[node->values_count].line_number = line_number; | ||
129 | node->values_count++; | ||
130 | - qsort_r(node->values, node->values_count, sizeof(struct trie_value_entry), trie_values_cmp, trie); | ||
131 | + trie_node_add_value_trie = trie; | ||
132 | + qsort(node->values, node->values_count, sizeof(struct trie_value_entry), trie_values_cmp); | ||
133 | + trie_node_add_value_trie = NULL; | ||
134 | return 0; | ||
135 | } | ||
136 | |||
137 | diff --git a/src/udev/udevadm-hwdb.c b/src/udev/udevadm-hwdb.c | ||
138 | index 02408a4285..491d367d12 100644 | ||
139 | --- a/src/udev/udevadm-hwdb.c | ||
140 | +++ b/src/udev/udevadm-hwdb.c | ||
141 | @@ -114,13 +114,13 @@ static void trie_node_cleanup(struct trie_node *node) { | ||
142 | free(node); | ||
143 | } | ||
144 | |||
145 | -static int trie_values_cmp(const void *v1, const void *v2, void *arg) { | ||
146 | +static struct trie *trie_node_add_value_trie; | ||
147 | +static int trie_values_cmp(const void *v1, const void *v2) { | ||
148 | const struct trie_value_entry *val1 = v1; | ||
149 | const struct trie_value_entry *val2 = v2; | ||
150 | - struct trie *trie = arg; | ||
151 | |||
152 | - return strcmp(trie->strings->buf + val1->key_off, | ||
153 | - trie->strings->buf + val2->key_off); | ||
154 | + return strcmp(trie_node_add_value_trie->strings->buf + val1->key_off, | ||
155 | + trie_node_add_value_trie->strings->buf + val2->key_off); | ||
156 | } | ||
157 | |||
158 | static int trie_node_add_value(struct trie *trie, struct trie_node *node, | ||
159 | @@ -141,7 +141,9 @@ static int trie_node_add_value(struct trie *trie, struct trie_node *node, | ||
160 | .value_off = v, | ||
161 | }; | ||
162 | 151 | ||
163 | - val = xbsearch_r(&search, node->values, node->values_count, sizeof(struct trie_value_entry), trie_values_cmp, trie); | 152 | - typesafe_qsort_r(sorted, n_rows, table_data_compare, t); |
164 | + trie_node_add_value_trie = trie; | 153 | + if (n_rows <= 1) |
165 | + val = bsearch(&search, node->values, node->values_count, sizeof(struct trie_value_entry), trie_values_cmp); | 154 | + return 0; |
166 | + trie_node_add_value_trie = NULL; | 155 | + assert(sorted); |
167 | if (val) { | 156 | + user_table = t; |
168 | /* replace existing earlier key with new value */ | 157 | + qsort(sorted, n_rows, sizeof(size_t), table_data_compare); |
169 | val->value_off = v; | 158 | + user_table = NULL; |
170 | @@ -158,7 +160,9 @@ static int trie_node_add_value(struct trie *trie, struct trie_node *node, | 159 | } |
171 | node->values[node->values_count].key_off = k; | ||
172 | node->values[node->values_count].value_off = v; | ||
173 | node->values_count++; | ||
174 | - qsort_r(node->values, node->values_count, sizeof(struct trie_value_entry), trie_values_cmp, trie); | ||
175 | + trie_node_add_value_trie = trie; | ||
176 | + qsort(node->values, node->values_count, sizeof(struct trie_value_entry), trie_values_cmp); | ||
177 | + trie_node_add_value_trie = NULL; | ||
178 | return 0; | ||
179 | } | ||
180 | 160 | ||
161 | if (t->display_map) | ||
181 | -- | 162 | -- |
182 | 2.18.0 | 163 | 2.7.4 |
183 | 164 | ||