Re: Is this non-volatile pointer access OK? - Mailing list pgsql-hackers

From Peter Eisentraut
Subject Re: Is this non-volatile pointer access OK?
Date
Msg-id 1346721671.30124.7.camel@vanquo.pezone.net
Whole thread Raw
In response to Re: Is this non-volatile pointer access OK?  (Peter Geoghegan <peter@2ndquadrant.com>)
List pgsql-hackers
On Mon, 2012-09-03 at 11:14 +0100, Peter Geoghegan wrote:
> Come to think of it, the whole convention of using a lower-case
> variant of the original pointer variable name seems like a foot-gun,
> given the harmful and indeed very subtle consequences of making this
> error.

With some inventive macro magic, you could probably make this safer.
I'm thinking something along the lines of replacing

SpinLockAcquire(&xlogctl->info_lck);

with

SpinLockAcquire(XLogCtl, info_lck);

which expands to

{   volatile typeof(XLogCtl) *XLogCtl_volatile = XLogCtl;   void *XLogCtl = NULL;  // compiler error or crash at run
timeif used   OldSpinLockAcquire(XLogCtl_volatile->info_lock);   ...
 

and then something corresponding for SpinLockRelease.

This will likely only work with modern compilers, but it could give you
some amount of static checking against this problem.





pgsql-hackers by date:

Previous
From: Heikki Linnakangas
Date:
Subject: Re: Cascading replication and recovery_target_timeline='latest'
Next
From: Bruce Momjian
Date:
Subject: Re: Yet another failure mode in pg_upgrade