Fix volatile vs. pointer confusion

Started by Peter Eisentrautabout 7 years ago6 messageshackers
Jump to latest
#1Peter Eisentraut
peter_e@gmx.net

Variables used after a longjmp() need to be declared volatile. In
case of a pointer, it's the pointer itself that needs to be declared
volatile, not the pointed-to value. So we need

PyObject *volatile items;

instead of

volatile PyObject *items; /* wrong */

Attached patch fixes a couple of cases of that. Most instances were
already correct.

--
Peter Eisentraut http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services

Attachments:

0001-Fix-volatile-vs.-pointer-confusion.patchtext/plain; charset=UTF-8; name=0001-Fix-volatile-vs.-pointer-confusion.patch; x-mac-creator=0; x-mac-type=0Download+7-12
#2Michael Paquier
michael@paquier.xyz
In reply to: Peter Eisentraut (#1)
Re: Fix volatile vs. pointer confusion

On Mon, Mar 11, 2019 at 08:23:39AM +0100, Peter Eisentraut wrote:

Attached patch fixes a couple of cases of that. Most instances were
already correct.

It seems to me that you should look at that:
/messages/by-id/20190308055911.GG4099@paquier.xyz
They treat about the same subject, and a patch has been sent for this
CF.
--
Michael

#3Alvaro Herrera
alvherre@2ndquadrant.com
In reply to: Peter Eisentraut (#1)
Re: Fix volatile vs. pointer confusion

On 2019-Mar-11, Peter Eisentraut wrote:

Variables used after a longjmp() need to be declared volatile. In
case of a pointer, it's the pointer itself that needs to be declared
volatile, not the pointed-to value. So we need

PyObject *volatile items;

instead of

volatile PyObject *items; /* wrong */

Looking at recently committed 2e616dee9e60, we have introduced this:

+       volatile xmlBufferPtr buf = NULL;
+       volatile xmlNodePtr cur_copy = NULL;

where the pointer-ness nature of the object is inside the typedef. I
*suppose* that this is correct as written. There are a few occurrences
of this pattern in eg. contrib/xml2.

--
�lvaro Herrera https://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services

#4Peter Eisentraut
peter_e@gmx.net
In reply to: Michael Paquier (#2)
Re: Fix volatile vs. pointer confusion

On 2019-03-11 09:31, Michael Paquier wrote:

On Mon, Mar 11, 2019 at 08:23:39AM +0100, Peter Eisentraut wrote:

Attached patch fixes a couple of cases of that. Most instances were
already correct.

It seems to me that you should look at that:
/messages/by-id/20190308055911.GG4099@paquier.xyz
They treat about the same subject, and a patch has been sent for this
CF.

I'm aware of that patch and have been looking at it. But it's not
directly related to this issue.

--
Peter Eisentraut http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services

#5Peter Eisentraut
peter_e@gmx.net
In reply to: Alvaro Herrera (#3)
Re: Fix volatile vs. pointer confusion

On 2019-03-11 12:57, Alvaro Herrera wrote:

Looking at recently committed 2e616dee9e60, we have introduced this:

+       volatile xmlBufferPtr buf = NULL;
+       volatile xmlNodePtr cur_copy = NULL;

where the pointer-ness nature of the object is inside the typedef. I
*suppose* that this is correct as written. There are a few occurrences
of this pattern in eg. contrib/xml2.

I think this is correct, but I don't want to wreck my sanity trying to
understand the syntax-level details of why.

--
Peter Eisentraut http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services

#6Peter Eisentraut
peter_e@gmx.net
In reply to: Peter Eisentraut (#1)
Re: Fix volatile vs. pointer confusion

On 2019-03-11 08:23, Peter Eisentraut wrote:

Variables used after a longjmp() need to be declared volatile. In
case of a pointer, it's the pointer itself that needs to be declared
volatile, not the pointed-to value. So we need

PyObject *volatile items;

instead of

volatile PyObject *items; /* wrong */

Attached patch fixes a couple of cases of that. Most instances were
already correct.

Committed.

I'll wait for the build farm to see if there are any new compiler
warnings because of this, then backpatch.

--
Peter Eisentraut http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services