Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 1226d93

Browse files
committed
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 */ Discussion: https://www.postgresql.org/message-id/flat/f747368d-9e1a-c46a-ac76-3c27da32e8e4%402ndquadrant.com
1 parent 6eebfdc commit 1226d93

File tree

2 files changed

+7
-11
lines changed

2 files changed

+7
-11
lines changed

contrib/hstore_plpython/hstore_plpython.c

+4-5
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ Datum
128128
plpython_to_hstore(PG_FUNCTION_ARGS)
129129
{
130130
PyObject *dict;
131-
volatile PyObject *items_v = NULL;
131+
PyObject *volatile items = NULL;
132132
int32 pcount;
133133
HStore *out;
134134

@@ -139,14 +139,13 @@ plpython_to_hstore(PG_FUNCTION_ARGS)
139139
errmsg("not a Python mapping")));
140140

141141
pcount = PyMapping_Size(dict);
142-
items_v = PyMapping_Items(dict);
142+
items = PyMapping_Items(dict);
143143

144144
PG_TRY();
145145
{
146146
int32 buflen;
147147
int32 i;
148148
Pairs *pairs;
149-
PyObject *items = (PyObject *) items_v;
150149

151150
pairs = palloc(pcount * sizeof(*pairs));
152151

@@ -177,14 +176,14 @@ plpython_to_hstore(PG_FUNCTION_ARGS)
177176
pairs[i].isnull = false;
178177
}
179178
}
180-
Py_DECREF(items_v);
179+
Py_DECREF(items);
181180

182181
pcount = hstoreUniquePairs(pairs, pcount, &buflen);
183182
out = hstorePairs(pairs, pcount, buflen);
184183
}
185184
PG_CATCH();
186185
{
187-
Py_DECREF(items_v);
186+
Py_DECREF(items);
188187
PG_RE_THROW();
189188
}
190189
PG_END_TRY();

contrib/jsonb_plpython/jsonb_plpython.c

+3-6
Original file line numberDiff line numberDiff line change
@@ -237,17 +237,14 @@ PLyMapping_ToJsonbValue(PyObject *obj, JsonbParseState **jsonb_state)
237237
JsonbValue *out = NULL;
238238

239239
/* We need it volatile, since we use it after longjmp */
240-
volatile PyObject *items_v = NULL;
240+
PyObject *volatile items = NULL;
241241

242242
pcount = PyMapping_Size(obj);
243-
items_v = PyMapping_Items(obj);
243+
items = PyMapping_Items(obj);
244244

245245
PG_TRY();
246246
{
247247
Py_ssize_t i;
248-
PyObject *items;
249-
250-
items = (PyObject *) items_v;
251248

252249
pushJsonbValue(jsonb_state, WJB_BEGIN_OBJECT, NULL);
253250

@@ -279,7 +276,7 @@ PLyMapping_ToJsonbValue(PyObject *obj, JsonbParseState **jsonb_state)
279276
}
280277
PG_CATCH();
281278
{
282-
Py_DECREF(items_v);
279+
Py_DECREF(items);
283280
PG_RE_THROW();
284281
}
285282
PG_END_TRY();

0 commit comments

Comments
 (0)