mirror of
https://github.com/postgres/postgres.git
synced 2025-06-13 07:41:39 +03:00
plpython: Code cleanup related to removal of Python 2 support.
Since 19252e8ec9
we reject Python 2 during build configuration. Now that the
dust on the buildfarm has settled, remove Python 2 specific code, including
the "Python 2/3 porting layer".
The code to detect conflicts between plpython using Python 2 and 3 is not
removed, in case somebody creates an out-of-tree version adding back support
for Python 2.
Reviewed-By: Peter Eisentraut <peter@eisentraut.org>
Reviewed-By: Tom Lane <tgl@sss.pgh.pa.us>
Discussion: https://postgr.es/m/20211031184548.g4sxfe47n2kyi55r@alap3.anarazel.de
This commit is contained in:
@ -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
|
||||
|
Reference in New Issue
Block a user