bug-hurd
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH 03/11] include: add lock-less reference counting primitives


From: Samuel Thibault
Subject: Re: [PATCH 03/11] include: add lock-less reference counting primitives
Date: Tue, 13 May 2014 14:11:53 +0200
User-agent: Mutt/1.5.21+34 (58baf7c9f32f) (2010-12-30)

Richard Braun, le Tue 13 May 2014 14:01:59 +0200, a écrit :
> On Tue, May 13, 2014 at 12:56:03PM +0200, Samuel Thibault wrote:
> > > > AIUI this cast is a case of type-puning.  Why not making refcounts_t the
> > > > union itself?  That way would be clearly safe with gcc's extension.
> > > 
> > > As stated in the comment for refcounts_t, I like the idea of using the
> > > type system to enforce the use of the accessor functions.
> > 
> > I understand, but type-puning will break with smart compilers.  We do
> > have had bugs like that in the past.
> 
> I agree, you should directly use the proper type here, or maybe void *
> but I don't see the point.

Ah, yes, since only that code is supposed to touch the memory, it
doesn't matter that the type is punned for the rest of the code. It
still looks quite odd to cast the pointer, I'd rather make the functions
directly take the union.

Letting the user have a mere integer is actually asking for seeing him
increment it by hand; rather give him a union for which he'll have to
look at the header file to know the fields names, and then he'll notice
the fat "don't access these directly" warning :)

Samuel



reply via email to

[Prev in Thread] Current Thread [Next in Thread]