Re: [PATCH] Keys: Add possessor permissions to keys
From: David Howells
Date: Thu Sep 22 2005 - 05:00:55 EST
Linus Torvalds <torvalds@xxxxxxxx> 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
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/