mirror of
https://github.com/postgres/postgres.git
synced 2025-04-20 00:42:27 +03:00
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
This commit is contained in:
parent
6eebfdc38b
commit
1226d932b4
@ -128,7 +128,7 @@ Datum
|
|||||||
plpython_to_hstore(PG_FUNCTION_ARGS)
|
plpython_to_hstore(PG_FUNCTION_ARGS)
|
||||||
{
|
{
|
||||||
PyObject *dict;
|
PyObject *dict;
|
||||||
volatile PyObject *items_v = NULL;
|
PyObject *volatile items = NULL;
|
||||||
int32 pcount;
|
int32 pcount;
|
||||||
HStore *out;
|
HStore *out;
|
||||||
|
|
||||||
@ -139,14 +139,13 @@ plpython_to_hstore(PG_FUNCTION_ARGS)
|
|||||||
errmsg("not a Python mapping")));
|
errmsg("not a Python mapping")));
|
||||||
|
|
||||||
pcount = PyMapping_Size(dict);
|
pcount = PyMapping_Size(dict);
|
||||||
items_v = PyMapping_Items(dict);
|
items = PyMapping_Items(dict);
|
||||||
|
|
||||||
PG_TRY();
|
PG_TRY();
|
||||||
{
|
{
|
||||||
int32 buflen;
|
int32 buflen;
|
||||||
int32 i;
|
int32 i;
|
||||||
Pairs *pairs;
|
Pairs *pairs;
|
||||||
PyObject *items = (PyObject *) items_v;
|
|
||||||
|
|
||||||
pairs = palloc(pcount * sizeof(*pairs));
|
pairs = palloc(pcount * sizeof(*pairs));
|
||||||
|
|
||||||
@ -177,14 +176,14 @@ plpython_to_hstore(PG_FUNCTION_ARGS)
|
|||||||
pairs[i].isnull = false;
|
pairs[i].isnull = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Py_DECREF(items_v);
|
Py_DECREF(items);
|
||||||
|
|
||||||
pcount = hstoreUniquePairs(pairs, pcount, &buflen);
|
pcount = hstoreUniquePairs(pairs, pcount, &buflen);
|
||||||
out = hstorePairs(pairs, pcount, buflen);
|
out = hstorePairs(pairs, pcount, buflen);
|
||||||
}
|
}
|
||||||
PG_CATCH();
|
PG_CATCH();
|
||||||
{
|
{
|
||||||
Py_DECREF(items_v);
|
Py_DECREF(items);
|
||||||
PG_RE_THROW();
|
PG_RE_THROW();
|
||||||
}
|
}
|
||||||
PG_END_TRY();
|
PG_END_TRY();
|
||||||
|
@ -237,17 +237,14 @@ PLyMapping_ToJsonbValue(PyObject *obj, JsonbParseState **jsonb_state)
|
|||||||
JsonbValue *out = NULL;
|
JsonbValue *out = NULL;
|
||||||
|
|
||||||
/* We need it volatile, since we use it after longjmp */
|
/* We need it volatile, since we use it after longjmp */
|
||||||
volatile PyObject *items_v = NULL;
|
PyObject *volatile items = NULL;
|
||||||
|
|
||||||
pcount = PyMapping_Size(obj);
|
pcount = PyMapping_Size(obj);
|
||||||
items_v = PyMapping_Items(obj);
|
items = PyMapping_Items(obj);
|
||||||
|
|
||||||
PG_TRY();
|
PG_TRY();
|
||||||
{
|
{
|
||||||
Py_ssize_t i;
|
Py_ssize_t i;
|
||||||
PyObject *items;
|
|
||||||
|
|
||||||
items = (PyObject *) items_v;
|
|
||||||
|
|
||||||
pushJsonbValue(jsonb_state, WJB_BEGIN_OBJECT, NULL);
|
pushJsonbValue(jsonb_state, WJB_BEGIN_OBJECT, NULL);
|
||||||
|
|
||||||
@ -279,7 +276,7 @@ PLyMapping_ToJsonbValue(PyObject *obj, JsonbParseState **jsonb_state)
|
|||||||
}
|
}
|
||||||
PG_CATCH();
|
PG_CATCH();
|
||||||
{
|
{
|
||||||
Py_DECREF(items_v);
|
Py_DECREF(items);
|
||||||
PG_RE_THROW();
|
PG_RE_THROW();
|
||||||
}
|
}
|
||||||
PG_END_TRY();
|
PG_END_TRY();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user