0001-Fix-volatile-vs.-pointer-confusion.patch

text/plain

Filename: 0001-Fix-volatile-vs.-pointer-confusion.patch
Type: text/plain
Part: 0
Message: Fix volatile vs. pointer confusion

Patch

Format: format-patch
Series: patch 0001
Subject: Fix volatile vs. pointer confusion
File+
contrib/hstore_plpython/hstore_plpython.c 4 5
contrib/jsonb_plpython/jsonb_plpython.c 3 6
From 1bb6acf63cf796d0659283c7ea5220385f7de181 Mon Sep 17 00:00:00 2001
From: Peter Eisentraut <peter@eisentraut.org>
Date: Mon, 11 Mar 2019 08:18:55 +0100
Subject: [PATCH] Fix volatile vs. pointer confusion

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 */
---
 contrib/hstore_plpython/hstore_plpython.c | 9 ++++-----
 contrib/jsonb_plpython/jsonb_plpython.c   | 9 +++------
 2 files changed, 7 insertions(+), 11 deletions(-)

diff --git a/contrib/hstore_plpython/hstore_plpython.c b/contrib/hstore_plpython/hstore_plpython.c
index 2f24090ff3..93c39d294d 100644
--- a/contrib/hstore_plpython/hstore_plpython.c
+++ b/contrib/hstore_plpython/hstore_plpython.c
@@ -128,7 +128,7 @@ Datum
 plpython_to_hstore(PG_FUNCTION_ARGS)
 {
 	PyObject   *dict;
-	volatile PyObject *items_v = NULL;
+	PyObject *volatile items = NULL;
 	int32		pcount;
 	HStore	   *out;
 
@@ -139,14 +139,13 @@ plpython_to_hstore(PG_FUNCTION_ARGS)
 				 errmsg("not a Python mapping")));
 
 	pcount = PyMapping_Size(dict);
-	items_v = PyMapping_Items(dict);
+	items = PyMapping_Items(dict);
 
 	PG_TRY();
 	{
 		int32		buflen;
 		int32		i;
 		Pairs	   *pairs;
-		PyObject   *items = (PyObject *) items_v;
 
 		pairs = palloc(pcount * sizeof(*pairs));
 
@@ -177,14 +176,14 @@ plpython_to_hstore(PG_FUNCTION_ARGS)
 				pairs[i].isnull = false;
 			}
 		}
-		Py_DECREF(items_v);
+		Py_DECREF(items);
 
 		pcount = hstoreUniquePairs(pairs, pcount, &buflen);
 		out = hstorePairs(pairs, pcount, buflen);
 	}
 	PG_CATCH();
 	{
-		Py_DECREF(items_v);
+		Py_DECREF(items);
 		PG_RE_THROW();
 	}
 	PG_END_TRY();
diff --git a/contrib/jsonb_plpython/jsonb_plpython.c b/contrib/jsonb_plpython/jsonb_plpython.c
index f44d364c97..1bc984d5c4 100644
--- a/contrib/jsonb_plpython/jsonb_plpython.c
+++ b/contrib/jsonb_plpython/jsonb_plpython.c
@@ -237,17 +237,14 @@ PLyMapping_ToJsonbValue(PyObject *obj, JsonbParseState **jsonb_state)
 	JsonbValue *out = NULL;
 
 	/* We need it volatile, since we use it after longjmp */
-	volatile PyObject *items_v = NULL;
+	PyObject *volatile items = NULL;
 
 	pcount = PyMapping_Size(obj);
-	items_v = PyMapping_Items(obj);
+	items = PyMapping_Items(obj);
 
 	PG_TRY();
 	{
 		Py_ssize_t	i;
-		PyObject   *items;
-
-		items = (PyObject *) items_v;
 
 		pushJsonbValue(jsonb_state, WJB_BEGIN_OBJECT, NULL);
 
@@ -279,7 +276,7 @@ PLyMapping_ToJsonbValue(PyObject *obj, JsonbParseState **jsonb_state)
 	}
 	PG_CATCH();
 	{
-		Py_DECREF(items_v);
+		Py_DECREF(items);
 		PG_RE_THROW();
 	}
 	PG_END_TRY();
-- 
2.21.0