CCAN Archive mirror
 help / color / mirror / Atom feed
From: David Gibson <david@gibson.dropbear.id.au>
To: Rusty Russell <rusty@rustcorp.com.au>
Cc: ccan@lists.ozlabs.org
Subject: Re: [PATCH 2/4] jset: Use TCON_WRAP instead of TCON
Date: Tue, 1 Aug 2017 15:17:26 +1000	[thread overview]
Message-ID: <20170801051726.GN2652@umbus.fritz.box> (raw)
In-Reply-To: <87y3r5p1h1.fsf@rustcorp.com.au>


[-- Attachment #1.1: Type: text/plain, Size: 6941 bytes --]

On Mon, Jul 31, 2017 at 03:55:14PM +0930, Paul 'Rusty' Russell wrote:
> OK, these all look good.
> 
> Please apply!

Done.

> Rusty.
> 
> David Gibson <david@gibson.dropbear.id.au> writes:
> > 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 jset interface, only its internals.
> >
> > Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
> > ---
> >  ccan/jset/jset.h     | 45 ++++++++++++++++++++++++++++-----------------
> >  ccan/jset/test/run.c |  9 +++++----
> >  2 files changed, 33 insertions(+), 21 deletions(-)
> >
> > diff --git a/ccan/jset/jset.h b/ccan/jset/jset.h
> > index ba72f097..904982d6 100644
> > --- a/ccan/jset/jset.h
> > +++ b/ccan/jset/jset.h
> > @@ -30,8 +30,7 @@ struct jset {
> >   *	};
> >   */
> >  #define JSET_MEMBERS(type)			\
> > -	struct jset raw;			\
> > -	TCON(type canary)
> > +	TCON_WRAP(struct jset, type canary) jset_
> >  
> >  /**
> >   * jset_new - create a new, empty jset.
> > @@ -47,6 +46,14 @@ struct jset {
> >   */
> >  #define jset_new(type) ((type *)jset_new_(sizeof(type)))
> >  
> > +
> > +/**
> > + * jset_raw_ - unwrap the typed set (without type checking)
> > + * @set: the typed jset
> > + */
> > +#define jset_raw_(set)	(tcon_unwrap(&(set)->jset_))
> > +
> > +
> >  /**
> >   * jset_free - destroy a jset.
> >   * @set: the set returned from jset_new.
> > @@ -54,7 +61,7 @@ struct jset {
> >   * Example:
> >   *	jset_free(set);
> >   */
> > -#define jset_free(set) jset_free_(&(set)->raw)
> > +#define jset_free(set) jset_free_(jset_raw_(set))
> >  
> >  /**
> >   * jset_error - test for an error in the a previous jset_ operation.
> > @@ -74,8 +81,8 @@ struct jset {
> >   *	if (errstr)
> >   *		errx(1, "Woah, error on newly created set?! %s", errstr);
> >   */
> > -#define jset_error(set) \
> > -	jset_error_(&(set)->raw)
> > +#define jset_error(set) jset_error_(jset_raw_(set))
> > +
> >  
> >  /**
> >   * jset_raw - unwrap the typed set and check the type
> > @@ -86,7 +93,9 @@ struct jset {
> >   * variable is of an unexpected type.  It is used internally where we
> >   * need to access the raw underlying jset.
> >   */
> > -#define jset_raw(set, expr) (&tcon_check((set), canary, (expr))->raw)
> > +#define jset_raw(set, expr) \
> > +	(tcon_unwrap(tcon_check(&(set)->jset_, canary, (expr))))
> > +
> >  
> >  /**
> >   * jset_test - test a bit in the bitset.
> > @@ -137,8 +146,8 @@ struct jset {
> >   *	// We expect 1000 entries.
> >   *	assert(jset_count(set) == 1000);
> >   */
> > -#define jset_count(set)				\
> > -	jset_popcount_(&(set)->raw, 0, -1UL)
> > +#define jset_count(set)	\
> > +	jset_popcount_(jset_raw_(set), 0, -1UL)
> >  
> >  /**
> >   * jset_popcount - get population of (some part of) bitset.
> > @@ -186,7 +195,7 @@ struct jset {
> >   *	}
> >   */
> >  #define jset_nth(set, n, invalid)					\
> > -	tcon_cast((set), canary,					\
> > +	tcon_cast(&(set)->jset_, canary,				\
> >  		  jset_nth_(jset_raw((set), (invalid)),			\
> >  			    (n), (unsigned long)(invalid)))
> >  
> > @@ -205,7 +214,7 @@ struct jset {
> >   *	printf("\n");
> >   */
> >  #define jset_first(set)						\
> > -	tcon_cast((set), canary, jset_first_(&(set)->raw))
> > +	tcon_cast(&(set)->jset_, canary, jset_first_(jset_raw_(set)))
> >  
> >  /**
> >   * jset_next - return the next bit which is set (must not contain 0).
> > @@ -216,7 +225,8 @@ struct jset {
> >   * jset_first.
> >   */
> >  #define jset_next(set, prev)						\
> > -	tcon_cast((set), canary, jset_next_(&(set)->raw, (unsigned long)(prev)))
> > +	tcon_cast(&(set)->jset_, canary,				\
> > +		  jset_next_(jset_raw_(set), (unsigned long)(prev)))
> >  
> >  /**
> >   * jset_last - return the last bit which is set (must not contain 0).
> > @@ -230,7 +240,7 @@ struct jset {
> >   *	printf("\n");
> >   */
> >  #define jset_last(set)						\
> > -	tcon_cast((set), canary, jset_last_(&(set)->raw))
> > +	tcon_cast(&(set)->jset_, canary, jset_last_(jset_raw_(set)))
> >  
> >  /**
> >   * jset_prev - return the previous bit which is set (must not contain 0).
> > @@ -241,7 +251,8 @@ struct jset {
> >   * jset_last.
> >   */
> >  #define jset_prev(set, prev)						\
> > -	tcon_cast((set), canary, jset_prev_(&(set)->raw, (unsigned long)(prev)))
> > +	tcon_cast(&(set)->jset_, canary,				\
> > +		  jset_prev_(jset_raw_(set), (unsigned long)(prev)))
> >  
> >  /**
> >   * jset_first_clear - return the first bit which is unset
> > @@ -251,17 +262,17 @@ struct jset {
> >   * set is full.
> >   */
> >  #define jset_first_clear(set)						\
> > -	tcon_cast((set), canary, jset_next_clear_(&(set)->raw, 0))
> > +	tcon_cast(&(set)->jset_, canary, jset_next_clear_(jset_raw_(set), 0))
> >  
> >  #define jset_next_clear(set, prev)					\
> > -	tcon_cast((set), canary, jset_next_clear_(&(set)->raw,		\
> > +	tcon_cast(&(set)->jset_, canary, jset_next_clear_(jset_raw_(set), \
> >  						  (unsigned long)(prev)))
> >  
> >  #define jset_last_clear(set)					\
> > -	tcon_cast((set), canary, jset_last_clear_(&(set)->raw))
> > +	tcon_cast(&(set)->jset_, canary, jset_last_clear_(jset_raw_(set)))
> >  
> >  #define jset_prev_clear(set, prev)					\
> > -	tcon_cast((set), canary, jset_prev_clear_(&(set)->raw,		\
> > +	tcon_cast(&(set)->jset_, canary, jset_prev_clear_(jset_raw_(set), \
> >  						  (unsigned long)(prev)))
> >  
> >  /* Raw functions */
> > diff --git a/ccan/jset/test/run.c b/ccan/jset/test/run.c
> > index a0fb8a8c..425546fd 100644
> > --- a/ccan/jset/test/run.c
> > +++ b/ccan/jset/test/run.c
> > @@ -34,7 +34,8 @@ int main(int argc, char *argv[])
> >  		jset_set(set, 1 + (i << 4));
> >  
> >  	/* This only take 1.7MB on my 32-bit system. */
> > -	diag("%u bytes memory used\n", (unsigned)Judy1MemUsed(set->raw.judy));
> > +	diag("%u bytes memory used\n",
> > +	     (unsigned)Judy1MemUsed(jset_raw_(set)->judy));
> >  
> >  	ok1(jset_popcount(set, 0, -1) == 1000000);
> >  	ok1(jset_nth(set, 0, -1) == 1);
> > @@ -53,13 +54,13 @@ int main(int argc, char *argv[])
> >  	ok1(jset_error(set) == NULL);
> >  
> >  	/* Test error handling */
> > -	JU_ERRNO(&set->raw.err) = 100;
> > -	JU_ERRID(&set->raw.err) = 991;
> > +	JU_ERRNO(&jset_raw_(set)->err) = 100;
> > +	JU_ERRID(&jset_raw_(set)->err) = 991;
> >  	err = jset_error(set);
> >  	ok1(err);
> >  	ok1(strstr(err, "100"));
> >  	ok1(strstr(err, "991"));
> > -	ok1(err == set->raw.errstr);
> > +	ok1(err == jset_raw_(set)->errstr);
> >  	jset_free(set);
> >  
> >  	return exit_status();
> 

-- 
David Gibson			| I'll have my music baroque, and my code
david AT gibson.dropbear.id.au	| minimalist, thank you.  NOT _the_ _other_
				| _way_ _around_!
http://www.ozlabs.org/~dgibson

[-- Attachment #1.2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

[-- Attachment #2: Type: text/plain, Size: 127 bytes --]

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

  reply	other threads:[~2017-08-01  5:17 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 [this message]
2017-07-23 12:29 ` [PATCH 3/4] jmap: " David Gibson
2017-07-23 12:29 ` [PATCH 4/4] objset: " David Gibson
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=20170801051726.GN2652@umbus.fritz.box \
    --to=david@gibson.dropbear.id.au \
    --cc=ccan@lists.ozlabs.org \
    --cc=rusty@rustcorp.com.au \
    /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).