Re: [PATCH] Keys: Add possessor permissions to keys

David Howells
2005-09-22T10:00:35Z

Linus Torvalds <torvalds@osdl.org> wrote:

> > hrmph. Of course it's a reasonable trick from a performance and
> > convenience and resource consumption POV. But it's a new idiom and the
> > threshold for new idioms is non-zero. We use it in struct page, but struct
> > page is special.
>
> Hmm.. I don't feel it is that new, but maybe that's because I've used that
> trick in other places. I think it's pretty common in a "type-safe C" way,
> and it should probably be encouraged. A unique pointer type for special
> usages, that you can't dereference even by mistake..

It's something that C isn't particularly good at. C++ is better at this as you
can define a class and overload the -> operator and the unary * operator if
you're feeling particularly evil or adventurous. But C it is...

> But adding a few comments might certainly be worth it. If only to teach
> others the trick.

Maybe there should be some naming convention for quasi-pointers like this? I
could typedef it, for instance, and hang comments appropriate to its nature of
the typedef. Perhaps:

typedef struct __key_ref_with_possession_attribute *key_ref;

And then give its accessor functions capital letters to make them stand out,
though that might give the false impression that they're actually preprocessor
macros.

Or perhaps I should rename two of the functions:

key_mkref() -> construct_key_ref()
key_deref() -> convert_key_ref_to_ptr() or extract_key_ptr()

Would that serve in lieu of commenting every time I use these things?

David