Skip to content

Commit 7ca00ca

Browse files
rustyrussellcdecker
authored andcommitted
ccan: update so we can compile with -O2 on Ubuntu.
Otherwise we get a configurator failure: In file included from /usr/include/string.h:495, from configuratortest.c:2: In function ‘strncpy’, inlined from ‘main’ at configuratortest.c:6:2: /usr/include/x86_64-linux-gnu/bits/string_fortified.h:106:10: warning: ‘__builtin_strncpy’ specified bound 8 equals destination size [-Wstringop-truncation] 106 | return __builtin___strncpy_chk (__dest, __src, __len, __bos (__dest)); | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
1 parent 73a5f5b commit 7ca00ca

File tree

8 files changed

+61
-7
lines changed

8 files changed

+61
-7
lines changed

ccan/README

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
CCAN imported from http://ccodearchive.net.
22

3-
CCAN version: init-2495-gc910bdce
3+
CCAN version: init-2500-gcbc7cbf1

ccan/ccan/htable/htable.c

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -365,6 +365,20 @@ void htable_delval_(struct htable *ht, struct htable_iter *i)
365365
ht->deleted++;
366366
}
367367

368+
void *htable_pick_(const struct htable *ht, size_t seed, struct htable_iter *i)
369+
{
370+
void *e;
371+
struct htable_iter unwanted;
372+
373+
if (!i)
374+
i = &unwanted;
375+
i->off = seed % ((size_t)1 << ht->bits);
376+
e = htable_next(ht, i);
377+
if (!e)
378+
e = htable_first(ht, i);
379+
return e;
380+
}
381+
368382
struct htable *htable_check(const struct htable *ht, const char *abortstr)
369383
{
370384
void *p;

ccan/ccan/htable/htable.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -267,6 +267,19 @@ void *htable_prev_(const struct htable *htable, struct htable_iter *i);
267267
htable_delval_(htable_debug(htable, HTABLE_LOC), i)
268268
void htable_delval_(struct htable *ht, struct htable_iter *i);
269269

270+
/**
271+
* htable_pick - set iterator to a random valid entry.
272+
* @ht: the htable
273+
* @seed: a random number to use.
274+
* @i: the htable_iter which is output (or NULL).
275+
*
276+
* Usually used with htable_delval to delete a random entry. Returns
277+
* NULL iff the table is empty, otherwise a random entry.
278+
*/
279+
#define htable_pick(htable, seed, i) \
280+
htable_pick_(htable_debug(htable, HTABLE_LOC), seed, i)
281+
void *htable_pick_(const struct htable *ht, size_t seed, struct htable_iter *i);
282+
270283
/**
271284
* htable_set_allocator - set calloc/free functions.
272285
* @alloc: allocator to use, must zero memory!

ccan/ccan/htable/htable_type.h

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,9 @@
3535
* bool <name>_del(struct <name> *ht, const <type> *e);
3636
* bool <name>_delkey(struct <name> *ht, const <keytype> *k);
3737
*
38+
* Delete by iterator:
39+
* bool <name>_delval(struct <name> *ht, struct <name>_iter *i);
40+
*
3841
* Find and return the (first) matching element, or NULL:
3942
* type *<name>_get(const struct @name *ht, const <keytype> *k);
4043
*
@@ -48,7 +51,8 @@
4851
* type *<name>_first(const struct <name> *ht, struct <name>_iter *i);
4952
* type *<name>_next(const struct <name> *ht, struct <name>_iter *i);
5053
* type *<name>_prev(const struct <name> *ht, struct <name>_iter *i);
51-
*
54+
* type *<name>_pick(const struct <name> *ht, size_t seed,
55+
* struct <name>_iter *i);
5256
* It's currently safe to iterate over a changing hashtable, but you might
5357
* miss an element. Iteration isn't very efficient, either.
5458
*
@@ -146,6 +150,18 @@
146150
return name##_del(ht, elem); \
147151
return false; \
148152
} \
153+
static inline UNNEEDED void name##_delval(struct name *ht, \
154+
struct name##_iter *iter) \
155+
{ \
156+
htable_delval(&ht->raw, &iter->i); \
157+
} \
158+
static inline UNNEEDED type *name##_pick(const struct name *ht, \
159+
size_t seed, \
160+
struct name##_iter *iter) \
161+
{ \
162+
/* Note &iter->i == NULL iff iter is NULL */ \
163+
return htable_pick(&ht->raw, seed, &iter->i); \
164+
} \
149165
static inline UNNEEDED type *name##_first(const struct name *ht, \
150166
struct name##_iter *iter) \
151167
{ \

ccan/ccan/htable/test/run-type.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ int main(void)
116116
void *p;
117117
struct htable_obj_iter iter;
118118

119-
plan_tests(32);
119+
plan_tests(35);
120120
for (i = 0; i < NUM_VALS; i++)
121121
val[i].key = i;
122122
dne = i;
@@ -128,6 +128,7 @@ int main(void)
128128

129129
/* We cannot find an entry which doesn't exist. */
130130
ok1(!htable_obj_get(&ht, &dne));
131+
ok1(!htable_obj_pick(&ht, 0, NULL));
131132

132133
/* Fill it, it should increase in size. */
133134
add_vals(&ht, val, NUM_VALS);
@@ -142,6 +143,8 @@ int main(void)
142143
/* Find all. */
143144
find_vals(&ht, val, NUM_VALS);
144145
ok1(!htable_obj_get(&ht, &dne));
146+
ok1(htable_obj_pick(&ht, 0, NULL));
147+
ok1(htable_obj_pick(&ht, 0, &iter));
145148

146149
/* Walk once, should get them all. */
147150
i = 0;

ccan/ccan/htable/test/run.c

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ int main(void)
105105
void *p;
106106
struct htable_iter iter;
107107

108-
plan_tests(38);
108+
plan_tests(43);
109109
for (i = 0; i < NUM_VALS; i++)
110110
val[i] = i;
111111
dne = i;
@@ -134,6 +134,12 @@ int main(void)
134134
/* Mask should be set. */
135135
ok1(check_mask(&ht, val, 1));
136136

137+
/* htable_pick should always return that value */
138+
ok1(htable_pick(&ht, 0, NULL) == val);
139+
ok1(htable_pick(&ht, 1, NULL) == val);
140+
ok1(htable_pick(&ht, 0, &iter) == val);
141+
ok1(get_raw_ptr(&ht, ht.table[iter.off]) == val);
142+
137143
/* This should increase it again. */
138144
add_vals(&ht, val, 1, 1);
139145
ok1(ht.bits == 2);
@@ -210,6 +216,7 @@ int main(void)
210216
htable_clear(&ht);
211217

212218
ok1(htable_count(&ht) == 0);
219+
ok1(htable_pick(&ht, 0, NULL) == NULL);
213220

214221
return exit_status();
215222
}

ccan/ccan/tal/tal.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -131,10 +131,11 @@ void *tal_free(const tal_t *p);
131131
/**
132132
* tal_steal - change the parent of a tal-allocated pointer.
133133
* @ctx: The new parent.
134-
* @ptr: The tal allocated object to move.
134+
* @ptr: The tal allocated object to move, or NULL.
135135
*
136136
* This may need to perform an allocation, in which case it may fail; thus
137-
* it can return NULL, otherwise returns @ptr.
137+
* it can return NULL, otherwise returns @ptr. If @ptr is NULL, this function does
138+
* nothing.
138139
*/
139140
#if HAVE_STATEMENT_EXPR
140141
/* Weird macro avoids gcc's 'warning: value computed is not used'. */

ccan/tools/configurator/configurator.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -411,7 +411,7 @@ static const struct test base_tests[] = {
411411
"int main(int argc, char *argv[]) {\n"
412412
" (void)argc;\n"
413413
" char pad[sizeof(int *) * 1];\n"
414-
" strncpy(pad, argv[0], sizeof(pad));\n"
414+
" memcpy(pad, argv[0], sizeof(pad));\n"
415415
" int *x = (int *)pad, *y = (int *)(pad + 1);\n"
416416
" return *x == *y;\n"
417417
"}\n" },

0 commit comments

Comments
 (0)