aboutsummaryrefslogtreecommitdiff
path: root/contrib
diff options
context:
space:
mode:
Diffstat (limited to 'contrib')
-rw-r--r--contrib/hstore_plpython/hstore_plpython.c12
-rw-r--r--contrib/jsonb_plpython/jsonb_plpython.c27
-rw-r--r--contrib/ltree_plpython/ltree_plpython.c6
3 files changed, 16 insertions, 29 deletions
diff --git a/contrib/hstore_plpython/hstore_plpython.c b/contrib/hstore_plpython/hstore_plpython.c
index 39bad558023..889ece315df 100644
--- a/contrib/hstore_plpython/hstore_plpython.c
+++ b/contrib/hstore_plpython/hstore_plpython.c
@@ -12,10 +12,8 @@ extern void _PG_init(void);
/* Linkage to functions in plpython module */
typedef char *(*PLyObject_AsString_t) (PyObject *plrv);
static PLyObject_AsString_t PLyObject_AsString_p;
-#if PY_MAJOR_VERSION >= 3
typedef PyObject *(*PLyUnicode_FromStringAndSize_t) (const char *s, Py_ssize_t size);
static PLyUnicode_FromStringAndSize_t PLyUnicode_FromStringAndSize_p;
-#endif
/* Linkage to functions in hstore module */
typedef HStore *(*hstoreUpgrade_t) (Datum orig);
@@ -41,12 +39,10 @@ _PG_init(void)
PLyObject_AsString_p = (PLyObject_AsString_t)
load_external_function("$libdir/" PLPYTHON_LIBNAME, "PLyObject_AsString",
true, NULL);
-#if PY_MAJOR_VERSION >= 3
AssertVariableIsOfType(&PLyUnicode_FromStringAndSize, PLyUnicode_FromStringAndSize_t);
PLyUnicode_FromStringAndSize_p = (PLyUnicode_FromStringAndSize_t)
load_external_function("$libdir/" PLPYTHON_LIBNAME, "PLyUnicode_FromStringAndSize",
true, NULL);
-#endif
AssertVariableIsOfType(&hstoreUpgrade, hstoreUpgrade_t);
hstoreUpgrade_p = (hstoreUpgrade_t)
load_external_function("$libdir/hstore", "hstoreUpgrade",
@@ -102,16 +98,16 @@ hstore_to_plpython(PG_FUNCTION_ARGS)
{
PyObject *key;
- key = PyString_FromStringAndSize(HSTORE_KEY(entries, base, i),
- HSTORE_KEYLEN(entries, i));
+ key = PLyUnicode_FromStringAndSize(HSTORE_KEY(entries, base, i),
+ HSTORE_KEYLEN(entries, i));
if (HSTORE_VALISNULL(entries, i))
PyDict_SetItem(dict, key, Py_None);
else
{
PyObject *value;
- value = PyString_FromStringAndSize(HSTORE_VAL(entries, base, i),
- HSTORE_VALLEN(entries, i));
+ value = PLyUnicode_FromStringAndSize(HSTORE_VAL(entries, base, i),
+ HSTORE_VALLEN(entries, i));
PyDict_SetItem(dict, key, value);
Py_XDECREF(value);
}
diff --git a/contrib/jsonb_plpython/jsonb_plpython.c b/contrib/jsonb_plpython/jsonb_plpython.c
index 836c1787706..03bbfa87d9a 100644
--- a/contrib/jsonb_plpython/jsonb_plpython.c
+++ b/contrib/jsonb_plpython/jsonb_plpython.c
@@ -28,11 +28,9 @@ static PyObject *PLyObject_FromJsonbContainer(JsonbContainer *jsonb);
static JsonbValue *PLyObject_ToJsonbValue(PyObject *obj,
JsonbParseState **jsonb_state, bool is_elem);
-#if PY_MAJOR_VERSION >= 3
typedef PyObject *(*PLyUnicode_FromStringAndSize_t)
(const char *s, Py_ssize_t size);
static PLyUnicode_FromStringAndSize_t PLyUnicode_FromStringAndSize_p;
-#endif
/*
* Module initialize function: fetch function pointers for cross-module calls.
@@ -45,13 +43,10 @@ _PG_init(void)
PLyObject_AsString_p = (PLyObject_AsString_t)
load_external_function("$libdir/" PLPYTHON_LIBNAME, "PLyObject_AsString",
true, NULL);
-#if PY_MAJOR_VERSION >= 3
AssertVariableIsOfType(&PLyUnicode_FromStringAndSize, PLyUnicode_FromStringAndSize_t);
PLyUnicode_FromStringAndSize_p = (PLyUnicode_FromStringAndSize_t)
load_external_function("$libdir/" PLPYTHON_LIBNAME, "PLyUnicode_FromStringAndSize",
true, NULL);
-#endif
-
AssertVariableIsOfType(&PLy_elog_impl, PLy_elog_impl_t);
PLy_elog_impl_p = (PLy_elog_impl_t)
load_external_function("$libdir/" PLPYTHON_LIBNAME, "PLy_elog_impl",
@@ -65,25 +60,25 @@ _PG_init(void)
#define PLy_elog (PLy_elog_impl_p)
/*
- * PLyString_FromJsonbValue
+ * PLyUnicode_FromJsonbValue
*
* Transform string JsonbValue to Python string.
*/
static PyObject *
-PLyString_FromJsonbValue(JsonbValue *jbv)
+PLyUnicode_FromJsonbValue(JsonbValue *jbv)
{
Assert(jbv->type == jbvString);
- return PyString_FromStringAndSize(jbv->val.string.val, jbv->val.string.len);
+ return PLyUnicode_FromStringAndSize(jbv->val.string.val, jbv->val.string.len);
}
/*
- * PLyString_ToJsonbValue
+ * PLyUnicode_ToJsonbValue
*
* Transform Python string to JsonbValue.
*/
static void
-PLyString_ToJsonbValue(PyObject *obj, JsonbValue *jbvElem)
+PLyUnicode_ToJsonbValue(PyObject *obj, JsonbValue *jbvElem)
{
jbvElem->type = jbvString;
jbvElem->val.string.val = PLyObject_AsString(obj);
@@ -118,7 +113,7 @@ PLyObject_FromJsonbValue(JsonbValue *jsonbValue)
}
case jbvString:
- return PLyString_FromJsonbValue(jsonbValue);
+ return PLyUnicode_FromJsonbValue(jsonbValue);
case jbvBool:
if (jsonbValue->val.boolean)
@@ -210,7 +205,7 @@ PLyObject_FromJsonbContainer(JsonbContainer *jsonb)
if (r != WJB_KEY)
continue;
- key = PLyString_FromJsonbValue(&v);
+ key = PLyUnicode_FromJsonbValue(&v);
if (!key)
{
Py_XDECREF(result_v);
@@ -298,7 +293,7 @@ PLyMapping_ToJsonbValue(PyObject *obj, JsonbParseState **jsonb_state)
else
{
/* All others types of keys we serialize to string */
- PLyString_ToJsonbValue(key, &jbvKey);
+ PLyUnicode_ToJsonbValue(key, &jbvKey);
}
(void) pushJsonbValue(jsonb_state, WJB_KEY, &jbvKey);
@@ -415,7 +410,7 @@ PLyObject_ToJsonbValue(PyObject *obj, JsonbParseState **jsonb_state, bool is_ele
{
JsonbValue *out;
- if (!(PyString_Check(obj) || PyUnicode_Check(obj)))
+ if (!PyUnicode_Check(obj))
{
if (PySequence_Check(obj))
return PLySequence_ToJsonbValue(obj, jsonb_state);
@@ -427,8 +422,8 @@ PLyObject_ToJsonbValue(PyObject *obj, JsonbParseState **jsonb_state, bool is_ele
if (obj == Py_None)
out->type = jbvNull;
- else if (PyString_Check(obj) || PyUnicode_Check(obj))
- PLyString_ToJsonbValue(obj, out);
+ else if (PyUnicode_Check(obj))
+ PLyUnicode_ToJsonbValue(obj, out);
/*
* PyNumber_Check() returns true for booleans, so boolean check should
diff --git a/contrib/ltree_plpython/ltree_plpython.c b/contrib/ltree_plpython/ltree_plpython.c
index 1570e77dd9f..7431a1150a9 100644
--- a/contrib/ltree_plpython/ltree_plpython.c
+++ b/contrib/ltree_plpython/ltree_plpython.c
@@ -9,10 +9,8 @@ PG_MODULE_MAGIC;
extern void _PG_init(void);
/* Linkage to functions in plpython module */
-#if PY_MAJOR_VERSION >= 3
typedef PyObject *(*PLyUnicode_FromStringAndSize_t) (const char *s, Py_ssize_t size);
static PLyUnicode_FromStringAndSize_t PLyUnicode_FromStringAndSize_p;
-#endif
/*
@@ -22,12 +20,10 @@ void
_PG_init(void)
{
/* Asserts verify that typedefs above match original declarations */
-#if PY_MAJOR_VERSION >= 3
AssertVariableIsOfType(&PLyUnicode_FromStringAndSize, PLyUnicode_FromStringAndSize_t);
PLyUnicode_FromStringAndSize_p = (PLyUnicode_FromStringAndSize_t)
load_external_function("$libdir/" PLPYTHON_LIBNAME, "PLyUnicode_FromStringAndSize",
true, NULL);
-#endif
}
@@ -54,7 +50,7 @@ ltree_to_plpython(PG_FUNCTION_ARGS)
curlevel = LTREE_FIRST(in);
for (i = 0; i < in->numlevel; i++)
{
- PyList_SetItem(list, i, PyString_FromStringAndSize(curlevel->name, curlevel->len));
+ PyList_SetItem(list, i, PLyUnicode_FromStringAndSize(curlevel->name, curlevel->len));
curlevel = LEVEL_NEXT(curlevel);
}