nostrdb: ccan: sync with normal versions.
This is the version of CCAN which CLN was using at the time these were taken. Unfortunately lots of whitespace has been changed, but AFAICT no source changes. Here's the command I ran (with ../ccan checked out to 1ae4c432): ``` make update-ccan CCAN_NEW="alignof array_size build_assert check_type container_of cppmagic likely list mem short_types str structeq take tal tal/str typesafe_cb utf8 endian crypto/sha256" ``` Signed-off-by: Rusty Russell <rusty@rustcorp.com.au> Signed-off-by: William Casarin <jb55@jb55.com>
This commit is contained in:
committed by
Daniel D’Aquino
parent
201cdd7edc
commit
a8d7d971b1
1
nostrdb/ccan/ccan/structeq/LICENSE
Symbolic link
1
nostrdb/ccan/ccan/structeq/LICENSE
Symbolic link
@@ -0,0 +1 @@
|
||||
../../licenses/BSD-MIT
|
||||
57
nostrdb/ccan/ccan/structeq/_info
Normal file
57
nostrdb/ccan/ccan/structeq/_info
Normal file
@@ -0,0 +1,57 @@
|
||||
#include "config.h"
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
/**
|
||||
* structeq - bitwise comparison of structs.
|
||||
*
|
||||
* This is a replacement for memcmp, which checks the argument types are the
|
||||
* same, and takes into account padding in the structure. When there is no
|
||||
* padding, it becomes a memcmp at compile time (assuming a
|
||||
* constant-optimizing compiler).
|
||||
*
|
||||
* License: BSD-MIT
|
||||
* Author: Rusty Russell <rusty@rustcorp.com.au>
|
||||
*
|
||||
* Example:
|
||||
* #include <ccan/structeq/structeq.h>
|
||||
* #include <ccan/build_assert/build_assert.h>
|
||||
* #include <assert.h>
|
||||
*
|
||||
* struct mydata {
|
||||
* int start, end;
|
||||
* };
|
||||
* // Defines mydata_eq(a, b)
|
||||
* STRUCTEQ_DEF(mydata, 0, start, end);
|
||||
*
|
||||
* int main(void)
|
||||
* {
|
||||
* struct mydata a, b;
|
||||
*
|
||||
* a.start = 100;
|
||||
* a.end = 101;
|
||||
*
|
||||
* // They are equal.
|
||||
* assert(mydata_eq(&a, &b));
|
||||
*
|
||||
* b.end++;
|
||||
* // Now they are not.
|
||||
* assert(!mydata_eq(&a, &b));
|
||||
*
|
||||
* return 0;
|
||||
* }
|
||||
*/
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
/* Expect exactly one argument */
|
||||
if (argc != 2)
|
||||
return 1;
|
||||
|
||||
if (strcmp(argv[1], "depends") == 0) {
|
||||
printf("ccan/build_assert\n");
|
||||
printf("ccan/cppmagic\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
@@ -1,8 +1,8 @@
|
||||
/* MIT (BSD) license - see LICENSE file for details */
|
||||
#ifndef CCAN_STRUCTEQ_H
|
||||
#define CCAN_STRUCTEQ_H
|
||||
#include "ccan/build_assert/build_assert.h"
|
||||
#include "ccan/cppmagic/cppmagic.h"
|
||||
#include <ccan/build_assert/build_assert.h>
|
||||
#include <ccan/cppmagic/cppmagic.h>
|
||||
#include <string.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
@@ -19,24 +19,24 @@
|
||||
* "up to or equal to that amount of padding", as padding can be
|
||||
* platform dependent.
|
||||
*/
|
||||
#define STRUCTEQ_DEF(sname, padbytes, ...) \
|
||||
#define STRUCTEQ_DEF(sname, padbytes, ...) \
|
||||
static inline bool CPPMAGIC_GLUE2(sname, _eq)(const struct sname *_a, \
|
||||
const struct sname *_b) \
|
||||
{ \
|
||||
BUILD_ASSERT(((padbytes) < 0 && \
|
||||
CPPMAGIC_JOIN(+, CPPMAGIC_MAP(STRUCTEQ_MEMBER_SIZE_, \
|
||||
__VA_ARGS__)) \
|
||||
- (padbytes) >= sizeof(*_a)) \
|
||||
|| CPPMAGIC_JOIN(+, CPPMAGIC_MAP(STRUCTEQ_MEMBER_SIZE_, \
|
||||
__VA_ARGS__)) \
|
||||
+ (padbytes) == sizeof(*_a)); \
|
||||
if (CPPMAGIC_JOIN(+, CPPMAGIC_MAP(STRUCTEQ_MEMBER_SIZE_, __VA_ARGS__)) \
|
||||
== sizeof(*_a)) \
|
||||
return memcmp(_a, _b, sizeof(*_a)) == 0; \
|
||||
else \
|
||||
return CPPMAGIC_JOIN(&&, \
|
||||
CPPMAGIC_MAP(STRUCTEQ_MEMBER_CMP_, \
|
||||
__VA_ARGS__)); \
|
||||
const struct sname *_b) \
|
||||
{ \
|
||||
BUILD_ASSERT(((padbytes) < 0 && \
|
||||
CPPMAGIC_JOIN(+, CPPMAGIC_MAP(STRUCTEQ_MEMBER_SIZE_, \
|
||||
__VA_ARGS__)) \
|
||||
- (padbytes) >= sizeof(*_a)) \
|
||||
|| CPPMAGIC_JOIN(+, CPPMAGIC_MAP(STRUCTEQ_MEMBER_SIZE_, \
|
||||
__VA_ARGS__)) \
|
||||
+ (padbytes) == sizeof(*_a)); \
|
||||
if (CPPMAGIC_JOIN(+, CPPMAGIC_MAP(STRUCTEQ_MEMBER_SIZE_, __VA_ARGS__)) \
|
||||
== sizeof(*_a)) \
|
||||
return memcmp(_a, _b, sizeof(*_a)) == 0; \
|
||||
else \
|
||||
return CPPMAGIC_JOIN(&&, \
|
||||
CPPMAGIC_MAP(STRUCTEQ_MEMBER_CMP_, \
|
||||
__VA_ARGS__)); \
|
||||
}
|
||||
|
||||
/* Helpers */
|
||||
|
||||
Reference in New Issue
Block a user