All of lore.kernel.org
 help / color / mirror / Atom feed
* more cleanup -- using FIELD_SIZEOF() macro
@ 2008-02-10 11:39 Robert P. J. Day
  2008-02-10 20:56 ` Julia Lawall
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: Robert P. J. Day @ 2008-02-10 11:39 UTC (permalink / raw)
  To: kernel-janitors


  the header file include/linux/kernel.h defines:

  #define FIELD_SIZEOF(t, f) (sizeof(((t*)0)->f))

which is a much more pleasant way of calculating the size of a
structure member.  and there's plenty of places in the tree where that
change can be made, which you can see if you search for the
appropriate pattern:

$ grep -Er "sizeof ?\( ?\( ?\([^\*]*[^ ] ?\*\) ?0 ?\)->[^\)]+\)" *

rday
--


====================================
Robert P. J. Day
Linux Consulting, Training and Annoying Kernel Pedantry
Waterloo, Ontario, CANADA

Home page:                                         http://crashcourse.ca
Fedora Cookbook:    http://crashcourse.ca/wiki/index.php/Fedora_Cookbook
====================================

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: more cleanup -- using FIELD_SIZEOF() macro
  2008-02-10 11:39 more cleanup -- using FIELD_SIZEOF() macro Robert P. J. Day
@ 2008-02-10 20:56 ` Julia Lawall
  2008-02-10 22:14 ` Randy Dunlap
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: Julia Lawall @ 2008-02-10 20:56 UTC (permalink / raw)
  To: kernel-janitors

On Sun, 10 Feb 2008, Robert P. J. Day wrote:

> 
>   the header file include/linux/kernel.h defines:
> 
>   #define FIELD_SIZEOF(t, f) (sizeof(((t*)0)->f))
> 
> which is a much more pleasant way of calculating the size of a
> structure member.  and there's plenty of places in the tree where that
> change can be made, which you can see if you search for the
> appropriate pattern:
> 
> $ grep -Er "sizeof ?\( ?\( ?\([^\*]*[^ ] ?\*\) ?0 ?\)->[^\)]+\)" *

What about these (also in kernel.h)?

#define DIV_ROUND_UP(n,d) (((n) + (d) - 1) / (d))
#define roundup(x, y) ((((x) + ((y) - 1)) / (y)) * (y))

julia


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: more cleanup -- using FIELD_SIZEOF() macro
  2008-02-10 11:39 more cleanup -- using FIELD_SIZEOF() macro Robert P. J. Day
  2008-02-10 20:56 ` Julia Lawall
@ 2008-02-10 22:14 ` Randy Dunlap
  2008-02-10 22:22 ` Julia Lawall
  2008-02-10 23:54 ` Robert P. J. Day
  3 siblings, 0 replies; 5+ messages in thread
From: Randy Dunlap @ 2008-02-10 22:14 UTC (permalink / raw)
  To: kernel-janitors

On Sun, 10 Feb 2008 21:56:38 +0100 (CET) Julia Lawall wrote:

> On Sun, 10 Feb 2008, Robert P. J. Day wrote:
> 
> > 
> >   the header file include/linux/kernel.h defines:
> > 
> >   #define FIELD_SIZEOF(t, f) (sizeof(((t*)0)->f))
> > 
> > which is a much more pleasant way of calculating the size of a
> > structure member.  and there's plenty of places in the tree where that
> > change can be made, which you can see if you search for the
> > appropriate pattern:
> > 
> > $ grep -Er "sizeof ?\( ?\( ?\([^\*]*[^ ] ?\*\) ?0 ?\)->[^\)]+\)" *
> 
> What about these (also in kernel.h)?
> 
> #define DIV_ROUND_UP(n,d) (((n) + (d) - 1) / (d))
> #define roundup(x, y) ((((x) + ((y) - 1)) / (y)) * (y))

What about them?  What is your question?

---
~Randy

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: more cleanup -- using FIELD_SIZEOF() macro
  2008-02-10 11:39 more cleanup -- using FIELD_SIZEOF() macro Robert P. J. Day
  2008-02-10 20:56 ` Julia Lawall
  2008-02-10 22:14 ` Randy Dunlap
@ 2008-02-10 22:22 ` Julia Lawall
  2008-02-10 23:54 ` Robert P. J. Day
  3 siblings, 0 replies; 5+ messages in thread
From: Julia Lawall @ 2008-02-10 22:22 UTC (permalink / raw)
  To: kernel-janitors

On Sun, 10 Feb 2008, Randy Dunlap wrote:

> On Sun, 10 Feb 2008 21:56:38 +0100 (CET) Julia Lawall wrote:
> 
> > On Sun, 10 Feb 2008, Robert P. J. Day wrote:
> > 
> > > 
> > >   the header file include/linux/kernel.h defines:
> > > 
> > >   #define FIELD_SIZEOF(t, f) (sizeof(((t*)0)->f))
> > > 
> > > which is a much more pleasant way of calculating the size of a
> > > structure member.  and there's plenty of places in the tree where that
> > > change can be made, which you can see if you search for the
> > > appropriate pattern:
> > > 
> > > $ grep -Er "sizeof ?\( ?\( ?\([^\*]*[^ ] ?\*\) ?0 ?\)->[^\)]+\)" *
> > 
> > What about these (also in kernel.h)?
> > 
> > #define DIV_ROUND_UP(n,d) (((n) + (d) - 1) / (d))
> > #define roundup(x, y) ((((x) + ((y) - 1)) / (y)) * (y))
> 
> What about them?  What is your question?

Sorry for not being more clear.  The original suggestion was to replace 
occurrences of a macro by a call to the macro itself.  These two macros 
are defined on the two lines after the definition of FIELD_SIZEOF.  There 
are many occurrences of expressions of the form (((n) + (d) - 1) / (d)) 
and ((((x) + ((y) - 1)) / (y)) * (y)), so I was wondering if it would be 
interesting to replace them as well.

julia


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: more cleanup -- using FIELD_SIZEOF() macro
  2008-02-10 11:39 more cleanup -- using FIELD_SIZEOF() macro Robert P. J. Day
                   ` (2 preceding siblings ...)
  2008-02-10 22:22 ` Julia Lawall
@ 2008-02-10 23:54 ` Robert P. J. Day
  3 siblings, 0 replies; 5+ messages in thread
From: Robert P. J. Day @ 2008-02-10 23:54 UTC (permalink / raw)
  To: kernel-janitors

On Sun, 10 Feb 2008, Julia Lawall wrote:

> On Sun, 10 Feb 2008, Randy Dunlap wrote:
>
> > On Sun, 10 Feb 2008 21:56:38 +0100 (CET) Julia Lawall wrote:
> >
> > > On Sun, 10 Feb 2008, Robert P. J. Day wrote:
> > >
> > > >
> > > >   the header file include/linux/kernel.h defines:
> > > >
> > > >   #define FIELD_SIZEOF(t, f) (sizeof(((t*)0)->f))
> > > >
> > > > which is a much more pleasant way of calculating the size of a
> > > > structure member.  and there's plenty of places in the tree where that
> > > > change can be made, which you can see if you search for the
> > > > appropriate pattern:
> > > >
> > > > $ grep -Er "sizeof ?\( ?\( ?\([^\*]*[^ ] ?\*\) ?0 ?\)->[^\)]+\)" *
> > >
> > > What about these (also in kernel.h)?
> > >
> > > #define DIV_ROUND_UP(n,d) (((n) + (d) - 1) / (d))
> > > #define roundup(x, y) ((((x) + ((y) - 1)) / (y)) * (y))
> >
> > What about them?  What is your question?
>
> Sorry for not being more clear.  The original suggestion was to
> replace occurrences of a macro by a call to the macro itself.
> These two macros are defined on the two lines after the definition
> of FIELD_SIZEOF.  There are many occurrences of expressions of the
> form (((n) + (d) - 1) / (d)) and ((((x) + ((y) - 1)) / (y)) * (y)),
> so I was wondering if it would be interesting to replace them as
> well.

stuff like that is simply an ongoing chore -- if you see potential
simplifications, submit a patch.

having said that, i have to confess that i *despise* those two roundup
macro definitions.  surely there could have been a more consistent
design for those.  gack.  barf.

rday

p.s.  what i would like to see is a breakout of some of the content of
kernel.h into smaller, more targeted header files.  it's pretty silly
for the kernel source tree to have a header file named "kernel.h".
i'd think it would make *far* more sense to have smaller,
kernel-specific headers like stdint.h, align.h and so on.

p.p.s.  another obvious cleanup is, given the macros in kernel.h, to
peruse the source tree and remove the numerous redefinitions of those
same macros.

--
====================================
Robert P. J. Day
Linux Consulting, Training and Annoying Kernel Pedantry
Waterloo, Ontario, CANADA

Home page:                                         http://crashcourse.ca
Fedora Cookbook:    http://crashcourse.ca/wiki/index.php/Fedora_Cookbook
====================================

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2008-02-10 23:54 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-02-10 11:39 more cleanup -- using FIELD_SIZEOF() macro Robert P. J. Day
2008-02-10 20:56 ` Julia Lawall
2008-02-10 22:14 ` Randy Dunlap
2008-02-10 22:22 ` Julia Lawall
2008-02-10 23:54 ` Robert P. J. Day

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.