mirror of
https://github.com/aljazceru/lightning.git
synced 2025-12-19 07:04:22 +01:00
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>
This commit is contained in:
committed by
Christian Decker
parent
73a5f5b313
commit
7ca00ca7d7
@@ -1,3 +1,3 @@
|
|||||||
CCAN imported from http://ccodearchive.net.
|
CCAN imported from http://ccodearchive.net.
|
||||||
|
|
||||||
CCAN version: init-2495-gc910bdce
|
CCAN version: init-2500-gcbc7cbf1
|
||||||
|
|||||||
@@ -365,6 +365,20 @@ void htable_delval_(struct htable *ht, struct htable_iter *i)
|
|||||||
ht->deleted++;
|
ht->deleted++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void *htable_pick_(const struct htable *ht, size_t seed, struct htable_iter *i)
|
||||||
|
{
|
||||||
|
void *e;
|
||||||
|
struct htable_iter unwanted;
|
||||||
|
|
||||||
|
if (!i)
|
||||||
|
i = &unwanted;
|
||||||
|
i->off = seed % ((size_t)1 << ht->bits);
|
||||||
|
e = htable_next(ht, i);
|
||||||
|
if (!e)
|
||||||
|
e = htable_first(ht, i);
|
||||||
|
return e;
|
||||||
|
}
|
||||||
|
|
||||||
struct htable *htable_check(const struct htable *ht, const char *abortstr)
|
struct htable *htable_check(const struct htable *ht, const char *abortstr)
|
||||||
{
|
{
|
||||||
void *p;
|
void *p;
|
||||||
|
|||||||
@@ -267,6 +267,19 @@ void *htable_prev_(const struct htable *htable, struct htable_iter *i);
|
|||||||
htable_delval_(htable_debug(htable, HTABLE_LOC), i)
|
htable_delval_(htable_debug(htable, HTABLE_LOC), i)
|
||||||
void htable_delval_(struct htable *ht, struct htable_iter *i);
|
void htable_delval_(struct htable *ht, struct htable_iter *i);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* htable_pick - set iterator to a random valid entry.
|
||||||
|
* @ht: the htable
|
||||||
|
* @seed: a random number to use.
|
||||||
|
* @i: the htable_iter which is output (or NULL).
|
||||||
|
*
|
||||||
|
* Usually used with htable_delval to delete a random entry. Returns
|
||||||
|
* NULL iff the table is empty, otherwise a random entry.
|
||||||
|
*/
|
||||||
|
#define htable_pick(htable, seed, i) \
|
||||||
|
htable_pick_(htable_debug(htable, HTABLE_LOC), seed, i)
|
||||||
|
void *htable_pick_(const struct htable *ht, size_t seed, struct htable_iter *i);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* htable_set_allocator - set calloc/free functions.
|
* htable_set_allocator - set calloc/free functions.
|
||||||
* @alloc: allocator to use, must zero memory!
|
* @alloc: allocator to use, must zero memory!
|
||||||
|
|||||||
@@ -35,6 +35,9 @@
|
|||||||
* bool <name>_del(struct <name> *ht, const <type> *e);
|
* bool <name>_del(struct <name> *ht, const <type> *e);
|
||||||
* bool <name>_delkey(struct <name> *ht, const <keytype> *k);
|
* bool <name>_delkey(struct <name> *ht, const <keytype> *k);
|
||||||
*
|
*
|
||||||
|
* Delete by iterator:
|
||||||
|
* bool <name>_delval(struct <name> *ht, struct <name>_iter *i);
|
||||||
|
*
|
||||||
* Find and return the (first) matching element, or NULL:
|
* Find and return the (first) matching element, or NULL:
|
||||||
* type *<name>_get(const struct @name *ht, const <keytype> *k);
|
* type *<name>_get(const struct @name *ht, const <keytype> *k);
|
||||||
*
|
*
|
||||||
@@ -48,7 +51,8 @@
|
|||||||
* type *<name>_first(const struct <name> *ht, struct <name>_iter *i);
|
* type *<name>_first(const struct <name> *ht, struct <name>_iter *i);
|
||||||
* type *<name>_next(const struct <name> *ht, struct <name>_iter *i);
|
* type *<name>_next(const struct <name> *ht, struct <name>_iter *i);
|
||||||
* type *<name>_prev(const struct <name> *ht, struct <name>_iter *i);
|
* type *<name>_prev(const struct <name> *ht, struct <name>_iter *i);
|
||||||
*
|
* type *<name>_pick(const struct <name> *ht, size_t seed,
|
||||||
|
* struct <name>_iter *i);
|
||||||
* It's currently safe to iterate over a changing hashtable, but you might
|
* It's currently safe to iterate over a changing hashtable, but you might
|
||||||
* miss an element. Iteration isn't very efficient, either.
|
* miss an element. Iteration isn't very efficient, either.
|
||||||
*
|
*
|
||||||
@@ -146,6 +150,18 @@
|
|||||||
return name##_del(ht, elem); \
|
return name##_del(ht, elem); \
|
||||||
return false; \
|
return false; \
|
||||||
} \
|
} \
|
||||||
|
static inline UNNEEDED void name##_delval(struct name *ht, \
|
||||||
|
struct name##_iter *iter) \
|
||||||
|
{ \
|
||||||
|
htable_delval(&ht->raw, &iter->i); \
|
||||||
|
} \
|
||||||
|
static inline UNNEEDED type *name##_pick(const struct name *ht, \
|
||||||
|
size_t seed, \
|
||||||
|
struct name##_iter *iter) \
|
||||||
|
{ \
|
||||||
|
/* Note &iter->i == NULL iff iter is NULL */ \
|
||||||
|
return htable_pick(&ht->raw, seed, &iter->i); \
|
||||||
|
} \
|
||||||
static inline UNNEEDED type *name##_first(const struct name *ht, \
|
static inline UNNEEDED type *name##_first(const struct name *ht, \
|
||||||
struct name##_iter *iter) \
|
struct name##_iter *iter) \
|
||||||
{ \
|
{ \
|
||||||
|
|||||||
@@ -116,7 +116,7 @@ int main(void)
|
|||||||
void *p;
|
void *p;
|
||||||
struct htable_obj_iter iter;
|
struct htable_obj_iter iter;
|
||||||
|
|
||||||
plan_tests(32);
|
plan_tests(35);
|
||||||
for (i = 0; i < NUM_VALS; i++)
|
for (i = 0; i < NUM_VALS; i++)
|
||||||
val[i].key = i;
|
val[i].key = i;
|
||||||
dne = i;
|
dne = i;
|
||||||
@@ -128,6 +128,7 @@ int main(void)
|
|||||||
|
|
||||||
/* We cannot find an entry which doesn't exist. */
|
/* We cannot find an entry which doesn't exist. */
|
||||||
ok1(!htable_obj_get(&ht, &dne));
|
ok1(!htable_obj_get(&ht, &dne));
|
||||||
|
ok1(!htable_obj_pick(&ht, 0, NULL));
|
||||||
|
|
||||||
/* Fill it, it should increase in size. */
|
/* Fill it, it should increase in size. */
|
||||||
add_vals(&ht, val, NUM_VALS);
|
add_vals(&ht, val, NUM_VALS);
|
||||||
@@ -142,6 +143,8 @@ int main(void)
|
|||||||
/* Find all. */
|
/* Find all. */
|
||||||
find_vals(&ht, val, NUM_VALS);
|
find_vals(&ht, val, NUM_VALS);
|
||||||
ok1(!htable_obj_get(&ht, &dne));
|
ok1(!htable_obj_get(&ht, &dne));
|
||||||
|
ok1(htable_obj_pick(&ht, 0, NULL));
|
||||||
|
ok1(htable_obj_pick(&ht, 0, &iter));
|
||||||
|
|
||||||
/* Walk once, should get them all. */
|
/* Walk once, should get them all. */
|
||||||
i = 0;
|
i = 0;
|
||||||
|
|||||||
@@ -105,7 +105,7 @@ int main(void)
|
|||||||
void *p;
|
void *p;
|
||||||
struct htable_iter iter;
|
struct htable_iter iter;
|
||||||
|
|
||||||
plan_tests(38);
|
plan_tests(43);
|
||||||
for (i = 0; i < NUM_VALS; i++)
|
for (i = 0; i < NUM_VALS; i++)
|
||||||
val[i] = i;
|
val[i] = i;
|
||||||
dne = i;
|
dne = i;
|
||||||
@@ -134,6 +134,12 @@ int main(void)
|
|||||||
/* Mask should be set. */
|
/* Mask should be set. */
|
||||||
ok1(check_mask(&ht, val, 1));
|
ok1(check_mask(&ht, val, 1));
|
||||||
|
|
||||||
|
/* htable_pick should always return that value */
|
||||||
|
ok1(htable_pick(&ht, 0, NULL) == val);
|
||||||
|
ok1(htable_pick(&ht, 1, NULL) == val);
|
||||||
|
ok1(htable_pick(&ht, 0, &iter) == val);
|
||||||
|
ok1(get_raw_ptr(&ht, ht.table[iter.off]) == val);
|
||||||
|
|
||||||
/* This should increase it again. */
|
/* This should increase it again. */
|
||||||
add_vals(&ht, val, 1, 1);
|
add_vals(&ht, val, 1, 1);
|
||||||
ok1(ht.bits == 2);
|
ok1(ht.bits == 2);
|
||||||
@@ -210,6 +216,7 @@ int main(void)
|
|||||||
htable_clear(&ht);
|
htable_clear(&ht);
|
||||||
|
|
||||||
ok1(htable_count(&ht) == 0);
|
ok1(htable_count(&ht) == 0);
|
||||||
|
ok1(htable_pick(&ht, 0, NULL) == NULL);
|
||||||
|
|
||||||
return exit_status();
|
return exit_status();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -131,10 +131,11 @@ void *tal_free(const tal_t *p);
|
|||||||
/**
|
/**
|
||||||
* tal_steal - change the parent of a tal-allocated pointer.
|
* tal_steal - change the parent of a tal-allocated pointer.
|
||||||
* @ctx: The new parent.
|
* @ctx: The new parent.
|
||||||
* @ptr: The tal allocated object to move.
|
* @ptr: The tal allocated object to move, or NULL.
|
||||||
*
|
*
|
||||||
* This may need to perform an allocation, in which case it may fail; thus
|
* This may need to perform an allocation, in which case it may fail; thus
|
||||||
* it can return NULL, otherwise returns @ptr.
|
* it can return NULL, otherwise returns @ptr. If @ptr is NULL, this function does
|
||||||
|
* nothing.
|
||||||
*/
|
*/
|
||||||
#if HAVE_STATEMENT_EXPR
|
#if HAVE_STATEMENT_EXPR
|
||||||
/* Weird macro avoids gcc's 'warning: value computed is not used'. */
|
/* Weird macro avoids gcc's 'warning: value computed is not used'. */
|
||||||
|
|||||||
@@ -411,7 +411,7 @@ static const struct test base_tests[] = {
|
|||||||
"int main(int argc, char *argv[]) {\n"
|
"int main(int argc, char *argv[]) {\n"
|
||||||
" (void)argc;\n"
|
" (void)argc;\n"
|
||||||
" char pad[sizeof(int *) * 1];\n"
|
" char pad[sizeof(int *) * 1];\n"
|
||||||
" strncpy(pad, argv[0], sizeof(pad));\n"
|
" memcpy(pad, argv[0], sizeof(pad));\n"
|
||||||
" int *x = (int *)pad, *y = (int *)(pad + 1);\n"
|
" int *x = (int *)pad, *y = (int *)(pad + 1);\n"
|
||||||
" return *x == *y;\n"
|
" return *x == *y;\n"
|
||||||
"}\n" },
|
"}\n" },
|
||||||
|
|||||||
Reference in New Issue
Block a user