Em Segunda-feira 1. Mar?o 2010, ?s 21.57.19, Stefan Teleman escreveu:
> On Mon, Mar 1, 2010 at 15:29, Thiago Macieira <thiago at kde.org> wrote:
> > Hi Stefan
> >
> > I understand quite well what aliasing means and I still think that this
> > is a compiler bug.
>
> Hi Thiago,
>
> I understand unions.
>
> Please read this thread. There's a post by Paul Floyd which contains a
> link explaining why the GCC developers believe that this GCC specific
> feature, and also why it is non-portable. If you disagree with the GCC
> deveopers, you could discuss it with them.
Thanks, after rereading the GCC link I see that the union access is a GCC
extension. When I just skimmed through the thread and the link, I missed this
important fact (I've always assumed that it was the proper behaviour, so I
never bothered to confirm it)
So, yes, you're right, it's not permitted to access the stored value of type
QMutex* through anything other than a type of QMutex* (signed/unsigned doesn't
apply to pointers, aggregates won't help you set the bit and character type
won't help because of endianness).
However, I'm actually glad of the GCC extension. If you look at the atomic
functions implemented for many platforms, it's necessary to do some casting.
> Also, please read the Trolltech code in src/corelib/thread/qmutex.h :
>
> inline QMutex *mutex() const
> {
> return reinterpret_cast<QMutex *>(val & ~quintptr(1u));
> }
That's to return the mutex whether it's locked or not. The idea was that it
was not necessary in the lock and unlock functions because we knew whether the
mutex was locked or not at that point. So the pointer magic wasn't necessary.
Anyway, can you try the attached patch?
--
Thiago Macieira - thiago (AT) macieira.info - thiago (AT) kde.org
Senior Product Manager - Nokia, Qt Development Frameworks
PGP/GPG: 0x6EF45358; fingerprint:
E067 918B B660 DBD1 105C 966C 33F5 F005 6EF4 5358
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0001-Fix-strict-aliasing-breakage-with-SunCC-the-union-tr.patch
Type: text/x-patch
Size: 1937 bytes
Desc: not available
URL:
<http://mail.opensolaris.org/pipermail/kde-discuss/attachments/20100301/d5acaa95/attachment.bin>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 190 bytes
Desc: This is a digitally signed message part.
URL:
<http://mail.opensolaris.org/pipermail/kde-discuss/attachments/20100301/d5acaa95/attachment-0001.bin>