public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Paul Sokolovsky <pmiscml@gmail.com>
To: "H. Peter Anvin" <hpa@zytor.com>
Cc: linux-kernel@vger.kernel.org, kernel-discuss@handhelds.org,
	Anton Vorontsov <cbou@mail.ru>
Subject: Re: [RFC] Virtual methods for devices and generalized GPIO support using it
Date: Thu, 29 Mar 2007 02:52:15 +0300	[thread overview]
Message-ID: <1547009361.20070329025215@gmail.com> (raw)
In-Reply-To: <460A98B9.9040602@zytor.com>

Hello H.,

Wednesday, March 28, 2007, 7:32:57 PM, you wrote:

> Paul Sokolovsky wrote:
>> 
>> In this respect, VTABLE(), METHOD() macros serve the same purpose as 
>> container_of() and list_for_each() - they are besides offering (more) 
>> convenient syntax, also carry important annotattion and educational
>> messages, like "it's ok, and encouraged to embed one structure into 
>> another - use it!" or "list manipulation is a trivial operation for kernel,
>> and we want you to treat it as such and use in standard, easily 
>> distinguishable way".
>> 

> You realize, right, that the Linux kernel already have a much cleaner 
> way to do vtables in the kernel, without this kind of macro crappage? 
> It's called an _ops table, and is used in a patternized way:

foo->x_ops->func(foo, ...);

> ... all over the kernel.  We like it that way.

  Sure! I wrote it's nothing really new. And I hope it's clear why
those macros appeared in the first place: with the type of structures
the device virtual methods are intended to be used, there're always
pretty comprehensive member selection and typecasting is required. In
this regard, there were 3 choices:

1. Use long but explicit expressions, like

((struct dev_pdata*)pdev.dev->platform_device)->x_ops->func(dev)

2. Use temporary variables:

struct dev_pdata *tmp = (struct dev_pdata*)pdev.dev->platform_device;
tmp->x_ops->func(dev);

3. Introduce macros which would hide guts and would provide syntax
more resembling usual function call (especially for folks who remember
that preprocessor is unalienable part of C ;-) ).


     As I also noted in the original mail, macros are also nice device
for in-place annotation - to emphasize the fact that this is not just
a mundane case of pointer manipulation, but paradigmatic thing.


     By this criteria I happened to choose macros syntax. But it's still
merely a syntax, and I don't pledge for it. If there's more movement
towards using explicit low-level forms like 1) or 2) instead of
introducing new syntactic pattern, then macro syntax can be considered
to have fulfilled its introductory role and can be dropped.




>         -hpa



-- 
Best regards,
 Paul                            mailto:pmiscml@gmail.com


  reply	other threads:[~2007-03-28 23:52 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-03-27  8:36 [RFC] Virtual methods for devices and generalized GPIO support using it Paul Sokolovsky
2007-03-28 16:32 ` H. Peter Anvin
2007-03-28 23:52   ` Paul Sokolovsky [this message]
2007-03-29  0:08     ` H. Peter Anvin

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=1547009361.20070329025215@gmail.com \
    --to=pmiscml@gmail.com \
    --cc=cbou@mail.ru \
    --cc=hpa@zytor.com \
    --cc=kernel-discuss@handhelds.org \
    --cc=linux-kernel@vger.kernel.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