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 | 164 |
1 files changed, 0 insertions, 164 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 deleted file mode 100644 index d856bcb583..0000000000 --- a/meta/recipes-core/systemd/systemd/0002-don-t-use-glibc-specific-qsort_r.patch +++ /dev/null | |||
@@ -1,164 +0,0 @@ | |||
1 | From 66ece0b870b3a34fdabc48b88437e6cc354e9fce Mon Sep 17 00:00:00 2001 | ||
2 | From: Chen Qi <Qi.Chen@windriver.com> | ||
3 | Date: Mon, 25 Feb 2019 13:41:41 +0800 | ||
4 | Subject: [PATCH 02/26] don't use glibc-specific qsort_r | ||
5 | |||
6 | Upstream-Status: Inappropriate [musl specific] | ||
7 | |||
8 | Signed-off-by: Khem Raj <raj.khem@gmail.com> | ||
9 | [Rebased for v241] | ||
10 | Signed-off-by: Chen Qi <Qi.Chen@windriver.com> | ||
11 | [Rebased for v242] | ||
12 | Signed-off-by: Andrej Valek <andrej.valek@siemens.com> | ||
13 | [Rebased for v247] | ||
14 | Signed-off-by: Luca Boccassi <luca.boccassi@microsoft.com> | ||
15 | --- | ||
16 | src/basic/sort-util.h | 14 ------------ | ||
17 | src/libsystemd/sd-hwdb/hwdb-util.c | 19 +++++++++++----- | ||
18 | src/shared/format-table.c | 36 ++++++++++++++++++++---------- | ||
19 | 3 files changed, 38 insertions(+), 31 deletions(-) | ||
20 | |||
21 | diff --git a/src/basic/sort-util.h b/src/basic/sort-util.h | ||
22 | index 1d194a1f04..3394c9eb72 100644 | ||
23 | --- a/src/basic/sort-util.h | ||
24 | +++ b/src/basic/sort-util.h | ||
25 | @@ -54,17 +54,3 @@ static inline void _qsort_safe(void *base, size_t nmemb, size_t size, __compar_f | ||
26 | int (*_func_)(const typeof(p[0])*, const typeof(p[0])*) = func; \ | ||
27 | _qsort_safe((p), (n), sizeof((p)[0]), (__compar_fn_t) _func_); \ | ||
28 | }) | ||
29 | - | ||
30 | -static inline void qsort_r_safe(void *base, size_t nmemb, size_t size, __compar_d_fn_t compar, void *userdata) { | ||
31 | - if (nmemb <= 1) | ||
32 | - return; | ||
33 | - | ||
34 | - assert(base); | ||
35 | - qsort_r(base, nmemb, size, compar, userdata); | ||
36 | -} | ||
37 | - | ||
38 | -#define typesafe_qsort_r(p, n, func, userdata) \ | ||
39 | - ({ \ | ||
40 | - int (*_func_)(const typeof(p[0])*, const typeof(p[0])*, typeof(userdata)) = func; \ | ||
41 | - qsort_r_safe((p), (n), sizeof((p)[0]), (__compar_d_fn_t) _func_, userdata); \ | ||
42 | - }) | ||
43 | diff --git a/src/libsystemd/sd-hwdb/hwdb-util.c b/src/libsystemd/sd-hwdb/hwdb-util.c | ||
44 | index 4c94ba9c88..95495dba6d 100644 | ||
45 | --- a/src/libsystemd/sd-hwdb/hwdb-util.c | ||
46 | +++ b/src/libsystemd/sd-hwdb/hwdb-util.c | ||
47 | @@ -126,9 +126,13 @@ static void trie_free(struct trie *trie) { | ||
48 | |||
49 | DEFINE_TRIVIAL_CLEANUP_FUNC(struct trie*, trie_free); | ||
50 | |||
51 | -static int trie_values_cmp(const struct trie_value_entry *a, const struct trie_value_entry *b, struct trie *trie) { | ||
52 | - return strcmp(trie->strings->buf + a->key_off, | ||
53 | - trie->strings->buf + b->key_off); | ||
54 | +static struct trie *trie_node_add_value_trie; | ||
55 | +static int trie_values_cmp(const void *v1, const void *v2) { | ||
56 | + const struct trie_value_entry *a = v1; | ||
57 | + const struct trie_value_entry *b = v2; | ||
58 | + | ||
59 | + return strcmp(trie_node_add_value_trie->strings->buf + a->key_off, | ||
60 | + trie_node_add_value_trie->strings->buf + b->key_off); | ||
61 | } | ||
62 | |||
63 | static int trie_node_add_value(struct trie *trie, struct trie_node *node, | ||
64 | @@ -156,7 +160,10 @@ static int trie_node_add_value(struct trie *trie, struct trie_node *node, | ||
65 | .value_off = v, | ||
66 | }; | ||
67 | |||
68 | - val = typesafe_bsearch_r(&search, node->values, node->values_count, trie_values_cmp, trie); | ||
69 | + trie_node_add_value_trie = trie; | ||
70 | + val = bsearch(&search, node->values, node->values_count, sizeof(struct trie_value_entry), trie_values_cmp); | ||
71 | + trie_node_add_value_trie = NULL; | ||
72 | + | ||
73 | if (val) { | ||
74 | /* At this point we have 2 identical properties on the same match-string. | ||
75 | * Since we process files in order, we just replace the previous value. */ | ||
76 | @@ -182,7 +189,9 @@ static int trie_node_add_value(struct trie *trie, struct trie_node *node, | ||
77 | .line_number = line_number, | ||
78 | }; | ||
79 | node->values_count++; | ||
80 | - typesafe_qsort_r(node->values, node->values_count, trie_values_cmp, trie); | ||
81 | + trie_node_add_value_trie = trie; | ||
82 | + qsort(node->values, node->values_count, sizeof(struct trie_value_entry), trie_values_cmp); | ||
83 | + trie_node_add_value_trie = NULL; | ||
84 | return 0; | ||
85 | } | ||
86 | |||
87 | diff --git a/src/shared/format-table.c b/src/shared/format-table.c | ||
88 | index a13a198b7a..bce10bc607 100644 | ||
89 | --- a/src/shared/format-table.c | ||
90 | +++ b/src/shared/format-table.c | ||
91 | @@ -1243,30 +1243,32 @@ static int cell_data_compare(TableData *a, size_t index_a, TableData *b, size_t | ||
92 | return CMP(index_a, index_b); | ||
93 | } | ||
94 | |||
95 | -static int table_data_compare(const size_t *a, const size_t *b, Table *t) { | ||
96 | +static Table *user_table; | ||
97 | +static int table_data_compare(const void *x, const void *y) { | ||
98 | + const size_t *a = x, *b=y; | ||
99 | int r; | ||
100 | |||
101 | - assert(t); | ||
102 | - assert(t->sort_map); | ||
103 | + assert(user_table); | ||
104 | + assert(user_table->sort_map); | ||
105 | |||
106 | /* Make sure the header stays at the beginning */ | ||
107 | - if (*a < t->n_columns && *b < t->n_columns) | ||
108 | + if (*a < user_table->n_columns && *b < user_table->n_columns) | ||
109 | return 0; | ||
110 | - if (*a < t->n_columns) | ||
111 | + if (*a < user_table->n_columns) | ||
112 | return -1; | ||
113 | - if (*b < t->n_columns) | ||
114 | + if (*b < user_table->n_columns) | ||
115 | return 1; | ||
116 | |||
117 | /* Order other lines by the sorting map */ | ||
118 | - for (size_t i = 0; i < t->n_sort_map; i++) { | ||
119 | + for (size_t i = 0; i < user_table->n_sort_map; i++) { | ||
120 | TableData *d, *dd; | ||
121 | |||
122 | - d = t->data[*a + t->sort_map[i]]; | ||
123 | - dd = t->data[*b + t->sort_map[i]]; | ||
124 | + d = user_table->data[*a + user_table->sort_map[i]]; | ||
125 | + dd = user_table->data[*b + user_table->sort_map[i]]; | ||
126 | |||
127 | r = cell_data_compare(d, *a, dd, *b); | ||
128 | if (r != 0) | ||
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 | @@ -1844,7 +1846,12 @@ int table_print(Table *t, FILE *f) { | ||
135 | for (size_t i = 0; i < n_rows; i++) | ||
136 | sorted[i] = i * t->n_columns; | ||
137 | |||
138 | - typesafe_qsort_r(sorted, n_rows, table_data_compare, t); | ||
139 | + if (n_rows <= 1) | ||
140 | + return 0; | ||
141 | + assert(sorted); | ||
142 | + user_table = t; | ||
143 | + qsort(sorted, n_rows, sizeof(size_t), table_data_compare); | ||
144 | + user_table = NULL; | ||
145 | } | ||
146 | |||
147 | if (t->display_map) | ||
148 | @@ -2440,7 +2447,12 @@ int table_to_json(Table *t, JsonVariant **ret) { | ||
149 | for (size_t i = 0; i < n_rows; i++) | ||
150 | sorted[i] = i * t->n_columns; | ||
151 | |||
152 | - typesafe_qsort_r(sorted, n_rows, table_data_compare, t); | ||
153 | + if (n_rows <= 1) | ||
154 | + return 0; | ||
155 | + assert(sorted); | ||
156 | + user_table = t; | ||
157 | + qsort(sorted, n_rows, sizeof(size_t), table_data_compare); | ||
158 | + user_table = NULL; | ||
159 | } | ||
160 | |||
161 | if (t->display_map) | ||
162 | -- | ||
163 | 2.27.0 | ||
164 | |||