CCAN Archive mirror
 help / color / mirror / Atom feed
From: David Gibson <david@gibson.dropbear.id.au>
To: ccan@lists.ozlabs.org
Subject: [PATCH 4/4] objset: Use TCON_WRAP instead of TCON
Date: Sun, 23 Jul 2017 22:29:07 +1000	[thread overview]
Message-ID: <20170723122907.10686-5-david@gibson.dropbear.id.au> (raw)
In-Reply-To: <20170723122907.10686-1-david@gibson.dropbear.id.au>

TCON() uses flexible-array members which aren't allowed in the middle
of structures, except as a gcc extension.  TCON_WRAP() avoids this and so
is more portable.

This doesn't change the objset interface, only its internals.

Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
---
 ccan/objset/objset.h | 31 ++++++++++++++++++-------------
 1 file changed, 18 insertions(+), 13 deletions(-)

diff --git a/ccan/objset/objset.h b/ccan/objset/objset.h
index 2492a520..9444d48c 100644
--- a/ccan/objset/objset.h
+++ b/ccan/objset/objset.h
@@ -36,8 +36,10 @@ HTABLE_DEFINE_TYPE(void, objset_key_, objset_hashfn_, objset_eqfn_, objset_h);
  *	};
  */
 #define OBJSET_MEMBERS(type)			\
-	struct objset_h raw;			\
-	TCON(type canary)
+	TCON_WRAP(struct objset_h, type canary) objset_
+
+#define objset_raw(set)				\
+	tcon_unwrap(&(set)->objset_)
 
 /**
  * objset_init - initialize an empty objset
@@ -48,7 +50,7 @@ HTABLE_DEFINE_TYPE(void, objset_key_, objset_hashfn_, objset_eqfn_, objset_h);
  *
  *	objset_init(&set);
  */
-#define objset_init(set) objset_h_init(&(set)->raw)
+#define objset_init(set) objset_h_init(objset_raw(set))
 
 /**
  * objset_empty - is this set empty?
@@ -58,7 +60,7 @@ HTABLE_DEFINE_TYPE(void, objset_key_, objset_hashfn_, objset_eqfn_, objset_h);
  *	if (!objset_empty(&set))
  *		abort();
  */
-#define objset_empty(set) objset_empty_(&(set)->raw)
+#define objset_empty(set) objset_empty_(objset_raw(set))
 
 static inline bool objset_empty_(const struct objset_h *set)
 {
@@ -83,7 +85,7 @@ static inline bool objset_empty_(const struct objset_h *set)
  *		printf("Impossible: value was already in the set?\n");
  */
 #define objset_add(set, value)						\
-	objset_h_add(&tcon_check((set), canary, (value))->raw, (void *)(value))
+	objset_h_add(tcon_unwrap(tcon_check(&(set)->objset_, canary, (value))), (void *)(value))
 
 /**
  * objset_get - get a value from a set
@@ -96,8 +98,9 @@ static inline bool objset_empty_(const struct objset_h *set)
  *	if (objset_get(&set, val));
  *		printf("hello => %i\n", *val);
  */
-#define objset_get(set, member) \
-	tcon_cast((set), canary, objset_h_get(&(set)->raw, (member)))
+#define objset_get(set, member)					\
+	tcon_cast(&(set)->objset_, canary,			\
+		  objset_h_get(objset_raw(set), (member)))
 
 /**
  * objset_del - remove a member from the set.
@@ -112,7 +115,7 @@ static inline bool objset_empty_(const struct objset_h *set)
  *		printf("val was not in the set?\n");
  */
 #define objset_del(set, value)						\
-	objset_h_del(&tcon_check((set), canary, value)->raw,		\
+	objset_h_del(tcon_unwrap(tcon_check(&(set)->objset_, canary, value)), \
 		     (const void *)value)
 
 /**
@@ -124,7 +127,7 @@ static inline bool objset_empty_(const struct objset_h *set)
  * Example:
  *	objset_clear(&set);
  */
-#define objset_clear(set) objset_h_clear(&(set)->raw)
+#define objset_clear(set) objset_h_clear(objset_raw(set))
 
 /**
  * objset_iter - iterator reference.
@@ -149,8 +152,9 @@ struct objset_iter {
  *	if (v)
  *		printf("One value is %i\n", *v);
  */
-#define objset_first(set, i) \
-	tcon_cast((set), canary, objset_h_first(&(set)->raw, &(i)->iter))
+#define objset_first(set, i)					\
+	tcon_cast(&(set)->objset_, canary,			\
+		  objset_h_first(objset_raw(set), &(i)->iter))
 
 /**
  * objset_next - get the another element in the set
@@ -167,7 +171,8 @@ struct objset_iter {
  *			printf("Another value is %i\n", *v);
  *	}
  */
-#define objset_next(set, i) \
-	tcon_cast((set), canary, objset_h_next(&(set)->raw, &(i)->iter))
+#define objset_next(set, i)					\
+	tcon_cast(&(set)->objset_, canary,			\
+		  objset_h_next(objset_raw(set), &(i)->iter))
 
 #endif /* CCAN_OBJSET_H */
-- 
2.13.3

_______________________________________________
ccan mailing list
ccan@lists.ozlabs.org
https://lists.ozlabs.org/listinfo/ccan

  parent reply	other threads:[~2017-07-23 12:29 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-07-23 12:29 [PATCH 0/4] Replace TCON() with TCON_WRAP() David Gibson
2017-07-23 12:29 ` [PATCH 1/4] tlist: Use TCON_WRAP instead of TCON David Gibson
2017-07-23 12:29 ` [PATCH 2/4] jset: " David Gibson
2017-07-31  6:25   ` Rusty Russell
2017-08-01  5:17     ` David Gibson
2017-07-23 12:29 ` [PATCH 3/4] jmap: " David Gibson
2017-07-23 12:29 ` David Gibson [this message]
2017-07-27  7:27 ` [PATCH 0/4] Replace TCON() with TCON_WRAP() David Gibson

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20170723122907.10686-5-david@gibson.dropbear.id.au \
    --to=david@gibson.dropbear.id.au \
    --cc=ccan@lists.ozlabs.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).