/* 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);
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",
{
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);
}
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.
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",
#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);
}
case jbvString:
- return PLyString_FromJsonbValue(jsonbValue);
+ return PLyUnicode_FromJsonbValue(jsonbValue);
case jbvBool:
if (jsonbValue->val.boolean)
if (r != WJB_KEY)
continue;
- key = PLyString_FromJsonbValue(&v);
+ key = PLyUnicode_FromJsonbValue(&v);
if (!key)
{
Py_XDECREF(result_v);
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);
{
JsonbValue *out;
- if (!(PyString_Check(obj) || PyUnicode_Check(obj)))
+ if (!PyUnicode_Check(obj))
{
if (PySequence_Check(obj))
return PLySequence_ToJsonbValue(obj, jsonb_state);
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
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
/*
_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
}
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);
}
.tp_name = "PLyCursor",
.tp_basicsize = sizeof(PLyCursorObject),
.tp_dealloc = PLy_cursor_dealloc,
- .tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HAVE_ITER,
+ .tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE,
.tp_doc = PLy_cursor_doc,
.tp_iter = PyObject_SelfIter,
.tp_iternext = PLy_cursor_iternext,
if (args)
{
- if (!PySequence_Check(args) || PyString_Check(args) || PyUnicode_Check(args))
+ if (!PySequence_Check(args) || PyUnicode_Check(args))
{
PLy_exception_set(PyExc_TypeError, "plpy.cursor takes a sequence as its second argument");
return NULL;
if (!so)
PLy_elog(ERROR, "could not execute plan");
- sv = PyString_AsString(so);
+ sv = PLyUnicode_AsString(so);
PLy_exception_set_plural(PyExc_TypeError,
"Expected sequence of %d argument, got %d: %s",
"Expected sequence of %d arguments, got %d: %s",
SPI_cursor_fetch(portal, true, count);
Py_DECREF(ret->status);
- ret->status = PyInt_FromLong(SPI_OK_FETCH);
+ ret->status = PyLong_FromLong(SPI_OK_FETCH);
Py_DECREF(ret->nrows);
ret->nrows = PyLong_FromUnsignedLongLong(SPI_processed);
e_type_o = PyObject_GetAttrString(e, "__name__");
e_module_o = PyObject_GetAttrString(e, "__module__");
if (e_type_o)
- e_type_s = PyString_AsString(e_type_o);
+ e_type_s = PLyUnicode_AsString(e_type_o);
if (e_type_s)
- e_module_s = PyString_AsString(e_module_o);
+ e_module_s = PLyUnicode_AsString(e_module_o);
if (v && ((vob = PyObject_Str(v)) != NULL))
- vstr = PyString_AsString(vob);
+ vstr = PLyUnicode_AsString(vob);
else
vstr = "unknown";
initStringInfo(&xstr);
if (!e_type_s || !e_module_s)
{
- if (PyString_Check(e))
- /* deprecated string exceptions */
- appendStringInfoString(&xstr, PyString_AsString(e));
- else
- /* shouldn't happen */
- appendStringInfoString(&xstr, "unrecognized exception");
+ /* shouldn't happen */
+ appendStringInfoString(&xstr, "unrecognized exception");
}
/* mimics behavior of traceback.format_exception_only */
else if (strcmp(e_module_s, "builtins") == 0
if (*tb_depth == 1)
fname = "<module>";
else
- fname = PyString_AsString(name);
+ fname = PLyUnicode_AsString(name);
proname = PLy_procedure_name(exec_ctx->curr_proc);
- plain_filename = PyString_AsString(filename);
- plain_lineno = PyInt_AsLong(lineno);
+ plain_filename = PLyUnicode_AsString(filename);
+ plain_lineno = PyLong_AsLong(lineno);
if (proname == NULL)
appendStringInfo(&tbstr, "\n PL/Python anonymous code block, line %ld, in %s",
if (sqlstate == NULL)
return;
- buffer = PyString_AsString(sqlstate);
+ buffer = PLyUnicode_AsString(sqlstate);
if (strlen(buffer) == 5 &&
strspn(buffer, "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ") == 5)
{
val = PyObject_GetAttrString(obj, attrname);
if (val != NULL && val != Py_None)
{
- *str = pstrdup(PyString_AsString(val));
+ *str = pstrdup(PLyUnicode_AsString(val));
}
Py_XDECREF(val);
}
if (str != NULL)
{
- val = PyString_FromString(str);
+ val = PLyUnicode_FromString(str);
if (!val)
return false;
}
/* trigger subhandler
*
* the python function is expected to return Py_None if the tuple is
- * acceptable and unmodified. Otherwise it should return a PyString
+ * acceptable and unmodified. Otherwise it should return a PyUnicode
* object who's value is SKIP, or MODIFY. SKIP means don't perform
* this action. MODIFY means the tuple has been modified, so update
* tuple and perform action. SKIP and MODIFY assume the trigger fires
{
char *srv;
- if (PyString_Check(plrv))
- srv = PyString_AsString(plrv);
- else if (PyUnicode_Check(plrv))
+ if (PyUnicode_Check(plrv))
srv = PLyUnicode_AsString(plrv);
else
{
if (!pltdata)
return NULL;
- pltname = PyString_FromString(tdata->tg_trigger->tgname);
+ pltname = PLyUnicode_FromString(tdata->tg_trigger->tgname);
PyDict_SetItemString(pltdata, "name", pltname);
Py_DECREF(pltname);
stroid = DatumGetCString(DirectFunctionCall1(oidout,
ObjectIdGetDatum(tdata->tg_relation->rd_id)));
- pltrelid = PyString_FromString(stroid);
+ pltrelid = PLyUnicode_FromString(stroid);
PyDict_SetItemString(pltdata, "relid", pltrelid);
Py_DECREF(pltrelid);
pfree(stroid);
stroid = SPI_getrelname(tdata->tg_relation);
- plttablename = PyString_FromString(stroid);
+ plttablename = PLyUnicode_FromString(stroid);
PyDict_SetItemString(pltdata, "table_name", plttablename);
Py_DECREF(plttablename);
pfree(stroid);
stroid = SPI_getnspname(tdata->tg_relation);
- plttableschema = PyString_FromString(stroid);
+ plttableschema = PLyUnicode_FromString(stroid);
PyDict_SetItemString(pltdata, "table_schema", plttableschema);
Py_DECREF(plttableschema);
pfree(stroid);
if (TRIGGER_FIRED_BEFORE(tdata->tg_event))
- pltwhen = PyString_FromString("BEFORE");
+ pltwhen = PLyUnicode_FromString("BEFORE");
else if (TRIGGER_FIRED_AFTER(tdata->tg_event))
- pltwhen = PyString_FromString("AFTER");
+ pltwhen = PLyUnicode_FromString("AFTER");
else if (TRIGGER_FIRED_INSTEAD(tdata->tg_event))
- pltwhen = PyString_FromString("INSTEAD OF");
+ pltwhen = PLyUnicode_FromString("INSTEAD OF");
else
{
elog(ERROR, "unrecognized WHEN tg_event: %u", tdata->tg_event);
if (TRIGGER_FIRED_FOR_ROW(tdata->tg_event))
{
- pltlevel = PyString_FromString("ROW");
+ pltlevel = PLyUnicode_FromString("ROW");
PyDict_SetItemString(pltdata, "level", pltlevel);
Py_DECREF(pltlevel);
if (TRIGGER_FIRED_BY_INSERT(tdata->tg_event))
{
- pltevent = PyString_FromString("INSERT");
+ pltevent = PLyUnicode_FromString("INSERT");
PyDict_SetItemString(pltdata, "old", Py_None);
pytnew = PLy_input_from_tuple(&proc->result_in,
}
else if (TRIGGER_FIRED_BY_DELETE(tdata->tg_event))
{
- pltevent = PyString_FromString("DELETE");
+ pltevent = PLyUnicode_FromString("DELETE");
PyDict_SetItemString(pltdata, "new", Py_None);
pytold = PLy_input_from_tuple(&proc->result_in,
}
else if (TRIGGER_FIRED_BY_UPDATE(tdata->tg_event))
{
- pltevent = PyString_FromString("UPDATE");
+ pltevent = PLyUnicode_FromString("UPDATE");
pytnew = PLy_input_from_tuple(&proc->result_in,
tdata->tg_newtuple,
}
else if (TRIGGER_FIRED_FOR_STATEMENT(tdata->tg_event))
{
- pltlevel = PyString_FromString("STATEMENT");
+ pltlevel = PLyUnicode_FromString("STATEMENT");
PyDict_SetItemString(pltdata, "level", pltlevel);
Py_DECREF(pltlevel);
*rv = NULL;
if (TRIGGER_FIRED_BY_INSERT(tdata->tg_event))
- pltevent = PyString_FromString("INSERT");
+ pltevent = PLyUnicode_FromString("INSERT");
else if (TRIGGER_FIRED_BY_DELETE(tdata->tg_event))
- pltevent = PyString_FromString("DELETE");
+ pltevent = PLyUnicode_FromString("DELETE");
else if (TRIGGER_FIRED_BY_UPDATE(tdata->tg_event))
- pltevent = PyString_FromString("UPDATE");
+ pltevent = PLyUnicode_FromString("UPDATE");
else if (TRIGGER_FIRED_BY_TRUNCATE(tdata->tg_event))
- pltevent = PyString_FromString("TRUNCATE");
+ pltevent = PLyUnicode_FromString("TRUNCATE");
else
{
elog(ERROR, "unrecognized OP tg_event: %u", tdata->tg_event);
}
for (i = 0; i < tdata->tg_trigger->tgnargs; i++)
{
- pltarg = PyString_FromString(tdata->tg_trigger->tgargs[i]);
+ pltarg = PLyUnicode_FromString(tdata->tg_trigger->tgargs[i]);
/*
* stolen, don't Py_DECREF
PLyObToDatum *att;
platt = PyList_GetItem(plkeys, i);
- if (PyString_Check(platt))
- plattstr = PyString_AsString(platt);
- else if (PyUnicode_Check(platt))
+ if (PyUnicode_Check(platt))
plattstr = PLyUnicode_AsString(platt);
else
{
* exported functions
*/
-#if PY_MAJOR_VERSION >= 3
-/* Use separate names to reduce confusion */
-#define plpython_validator plpython3_validator
-#define plpython_call_handler plpython3_call_handler
-#define plpython_inline_handler plpython3_inline_handler
-#endif
-
extern void _PG_init(void);
PG_MODULE_MAGIC;
-PG_FUNCTION_INFO_V1(plpython_validator);
-PG_FUNCTION_INFO_V1(plpython_call_handler);
-PG_FUNCTION_INFO_V1(plpython_inline_handler);
-
-#if PY_MAJOR_VERSION < 3
-/* Define aliases plpython2_call_handler etc */
-PG_FUNCTION_INFO_V1(plpython2_validator);
-PG_FUNCTION_INFO_V1(plpython2_call_handler);
-PG_FUNCTION_INFO_V1(plpython2_inline_handler);
-#endif
+PG_FUNCTION_INFO_V1(plpython3_validator);
+PG_FUNCTION_INFO_V1(plpython3_call_handler);
+PG_FUNCTION_INFO_V1(plpython3_inline_handler);
static bool PLy_procedure_is_trigger(Form_pg_proc procStruct);
* the actual failure for later, so that operations like pg_restore can
* load more than one plpython library so long as they don't try to do
* anything much with the language.
+ *
+ * While we only support Python 3 these days, somebody might create an
+ * out-of-tree version adding back support for Python 2. Conflicts with
+ * such an extension should be detected.
*/
bitmask_ptr = (int **) find_rendezvous_variable("plpython_version_bitmask");
if (!(*bitmask_ptr)) /* am I the first? */
if (inited)
return;
-#if PY_MAJOR_VERSION >= 3
PyImport_AppendInittab("plpy", PyInit_plpy);
-#endif
Py_Initialize();
-#if PY_MAJOR_VERSION >= 3
PyImport_ImportModule("plpy");
-#endif
PLy_init_interp();
PLy_init_plpy();
if (PyErr_Occurred())
}
Datum
-plpython_validator(PG_FUNCTION_ARGS)
+plpython3_validator(PG_FUNCTION_ARGS)
{
Oid funcoid = PG_GETARG_OID(0);
HeapTuple tuple;
PG_RETURN_VOID();
}
-#if PY_MAJOR_VERSION < 3
-Datum
-plpython2_validator(PG_FUNCTION_ARGS)
-{
- /* call plpython validator with our fcinfo so it gets our oid */
- return plpython_validator(fcinfo);
-}
-#endif /* PY_MAJOR_VERSION < 3 */
-
Datum
-plpython_call_handler(PG_FUNCTION_ARGS)
+plpython3_call_handler(PG_FUNCTION_ARGS)
{
bool nonatomic;
Datum retval;
return retval;
}
-#if PY_MAJOR_VERSION < 3
Datum
-plpython2_call_handler(PG_FUNCTION_ARGS)
-{
- return plpython_call_handler(fcinfo);
-}
-#endif /* PY_MAJOR_VERSION < 3 */
-
-Datum
-plpython_inline_handler(PG_FUNCTION_ARGS)
+plpython3_inline_handler(PG_FUNCTION_ARGS)
{
LOCAL_FCINFO(fake_fcinfo, 0);
InlineCodeBlock *codeblock = (InlineCodeBlock *) DatumGetPointer(PG_GETARG_DATUM(0));
PG_RETURN_VOID();
}
-#if PY_MAJOR_VERSION < 3
-Datum
-plpython2_inline_handler(PG_FUNCTION_ARGS)
-{
- return plpython_inline_handler(fcinfo);
-}
-#endif /* PY_MAJOR_VERSION < 3 */
-
static bool
PLy_procedure_is_trigger(Form_pg_proc procStruct)
{
{
Py_INCREF(Py_True);
return Py_True;
- /* return PyInt_FromLong(self->status); */
+ /* return PyLong_FromLong(self->status); */
}
return NULL;
}
{NULL, NULL, 0, NULL}
};
-#if PY_MAJOR_VERSION >= 3
static PyModuleDef PLy_module = {
PyModuleDef_HEAD_INIT,
.m_name = "plpy",
return m;
}
-#endif /* PY_MAJOR_VERSION >= 3 */
void
PLy_init_plpy(void)
*main_dict,
*plpy_mod;
-#if PY_MAJOR_VERSION < 3
- PyObject *plpy;
-#endif
-
/*
* initialize plpy module
*/
PLy_subtransaction_init_type();
PLy_cursor_init_type();
-#if PY_MAJOR_VERSION >= 3
PyModule_Create(&PLy_module);
- /* for Python 3 we initialized the exceptions in PyInit_plpy */
-#else
- plpy = Py_InitModule("plpy", PLy_methods);
- PLy_add_exceptions(plpy);
-#endif
/* PyDict_SetItemString(plpy, "PlanType", (PyObject *) &PLy_PlanType); */
PyObject *excmod;
HASHCTL hash_ctl;
-#if PY_MAJOR_VERSION < 3
- excmod = Py_InitModule("spiexceptions", PLy_exc_methods);
-#else
excmod = PyModule_Create(&PLy_exc_module);
-#endif
if (excmod == NULL)
PLy_elog(ERROR, "could not create the spiexceptions module");
if (dict == NULL)
PLy_elog(ERROR, NULL);
- sqlstate = PyString_FromString(unpack_sql_state(exception_map[i].sqlstate));
+ sqlstate = PLyUnicode_FromString(unpack_sql_state(exception_map[i].sqlstate));
if (sqlstate == NULL)
PLy_elog(ERROR, "could not generate SPI exceptions");
return NULL;
quoted = quote_literal_cstr(str);
- ret = PyString_FromString(quoted);
+ ret = PLyUnicode_FromString(quoted);
pfree(quoted);
return ret;
return NULL;
if (str == NULL)
- return PyString_FromString("NULL");
+ return PLyUnicode_FromString("NULL");
quoted = quote_literal_cstr(str);
- ret = PyString_FromString(quoted);
+ ret = PLyUnicode_FromString(quoted);
pfree(quoted);
return ret;
return NULL;
quoted = quote_identifier(str);
- ret = PyString_FromString(quoted);
+ ret = PLyUnicode_FromString(quoted);
return ret;
}
{
char *str;
- str = pstrdup(PyString_AsString(so));
+ str = pstrdup(PLyUnicode_AsString(so));
Py_DECREF(so);
return str;
else
so = PyObject_Str(args);
- if (so == NULL || ((message = PyString_AsString(so)) == NULL))
+ if (so == NULL || ((message = PLyUnicode_AsString(so)) == NULL))
{
level = ERROR;
message = dgettext(TEXTDOMAIN, "could not parse error message in plpy.elog");
{
while (PyDict_Next(kw, &pos, &key, &value))
{
- char *keyword = PyString_AsString(key);
+ char *keyword = PLyUnicode_AsString(key);
if (strcmp(keyword, "message") == 0)
{
extern HTAB *PLy_spi_exceptions;
-#if PY_MAJOR_VERSION >= 3
PyMODINIT_FUNC PyInit_plpy(void);
-#endif
extern void PLy_init_plpy(void);
#endif /* PLPY_PLPYMODULE_H */
Py_INCREF(Py_None);
ob->status = Py_None;
- ob->nrows = PyInt_FromLong(-1);
+ ob->nrows = PyLong_FromLong(-1);
ob->rows = PyList_New(0);
ob->tupdesc = NULL;
if (!ob->rows)
{
Form_pg_attribute attr = TupleDescAttr(ob->tupdesc, i);
- PyList_SET_ITEM(list, i, PyString_FromString(NameStr(attr->attname)));
+ PyList_SET_ITEM(list, i, PLyUnicode_FromString(NameStr(attr->attname)));
}
return list;
{
Form_pg_attribute attr = TupleDescAttr(ob->tupdesc, i);
- PyList_SET_ITEM(list, i, PyInt_FromLong(attr->atttypid));
+ PyList_SET_ITEM(list, i, PyLong_FromLong(attr->atttypid));
}
return list;
{
Form_pg_attribute attr = TupleDescAttr(ob->tupdesc, i);
- PyList_SET_ITEM(list, i, PyInt_FromLong(attr->atttypmod));
+ PyList_SET_ITEM(list, i, PyLong_FromLong(attr->atttypmod));
}
return list;
{
PLyResultObject *ob = (PLyResultObject *) arg;
-#if PY_MAJOR_VERSION >= 3
return PyUnicode_FromFormat("<%s status=%S nrows=%S rows=%S>",
Py_TYPE(ob)->tp_name,
ob->status,
ob->nrows,
ob->rows);
-#else
- return PyString_FromFormat("<%s status=%ld nrows=%ld rows=%s>",
- ob->ob_type->tp_name,
- PyInt_AsLong(ob->status),
- PyInt_AsLong(ob->nrows),
- PyString_AsString(PyObject_Str(ob->rows)));
-#endif
}
static PyObject *
int32 typmod;
optr = PySequence_GetItem(list, i);
- if (PyString_Check(optr))
- sptr = PyString_AsString(optr);
- else if (PyUnicode_Check(optr))
+ if (PyUnicode_Check(optr))
sptr = PLyUnicode_AsString(optr);
else
{
if (list != NULL)
{
- if (!PySequence_Check(list) || PyString_Check(list) || PyUnicode_Check(list))
+ if (!PySequence_Check(list) || PyUnicode_Check(list))
{
PLy_exception_set(PyExc_TypeError, "plpy.execute takes a sequence as its second argument");
return NULL;
if (!so)
PLy_elog(ERROR, "could not execute plan");
- sv = PyString_AsString(so);
+ sv = PLyUnicode_AsString(so);
PLy_exception_set_plural(PyExc_TypeError,
"Expected sequence of %d argument, got %d: %s",
"Expected sequence of %d arguments, got %d: %s",
return NULL;
}
Py_DECREF(result->status);
- result->status = PyInt_FromLong(status);
+ result->status = PyLong_FromLong(status);
if (status > 0 && tuptable == NULL)
{
static PyObject *PLyFloat_FromFloat4(PLyDatumToOb *arg, Datum d);
static PyObject *PLyFloat_FromFloat8(PLyDatumToOb *arg, Datum d);
static PyObject *PLyDecimal_FromNumeric(PLyDatumToOb *arg, Datum d);
-static PyObject *PLyInt_FromInt16(PLyDatumToOb *arg, Datum d);
-static PyObject *PLyInt_FromInt32(PLyDatumToOb *arg, Datum d);
+static PyObject *PLyLong_FromInt16(PLyDatumToOb *arg, Datum d);
+static PyObject *PLyLong_FromInt32(PLyDatumToOb *arg, Datum d);
static PyObject *PLyLong_FromInt64(PLyDatumToOb *arg, Datum d);
static PyObject *PLyLong_FromOid(PLyDatumToOb *arg, Datum d);
static PyObject *PLyBytes_FromBytea(PLyDatumToOb *arg, Datum d);
-static PyObject *PLyString_FromScalar(PLyDatumToOb *arg, Datum d);
+static PyObject *PLyUnicode_FromScalar(PLyDatumToOb *arg, Datum d);
static PyObject *PLyObject_FromTransform(PLyDatumToOb *arg, Datum d);
static PyObject *PLyList_FromArray(PLyDatumToOb *arg, Datum d);
static PyObject *PLyList_FromArray_recurse(PLyDatumToOb *elm, int *dims, int ndim, int dim,
Datum *elems, bool *nulls, int *currelem);
/* conversion from Python objects to composite Datums */
-static Datum PLyString_ToComposite(PLyObToDatum *arg, PyObject *string, bool inarray);
+static Datum PLyUnicode_ToComposite(PLyObToDatum *arg, PyObject *string, bool inarray);
static Datum PLyMapping_ToComposite(PLyObToDatum *arg, TupleDesc desc, PyObject *mapping);
static Datum PLySequence_ToComposite(PLyObToDatum *arg, TupleDesc desc, PyObject *sequence);
static Datum PLyGenericObject_ToComposite(PLyObToDatum *arg, TupleDesc desc, PyObject *object, bool inarray);
arg->func = PLyDecimal_FromNumeric;
break;
case INT2OID:
- arg->func = PLyInt_FromInt16;
+ arg->func = PLyLong_FromInt16;
break;
case INT4OID:
- arg->func = PLyInt_FromInt32;
+ arg->func = PLyLong_FromInt32;
break;
case INT8OID:
arg->func = PLyLong_FromInt64;
arg->func = PLyBytes_FromBytea;
break;
default:
- arg->func = PLyString_FromScalar;
+ arg->func = PLyUnicode_FromScalar;
getTypeOutputInfo(typeOid, &typoutput, &typisvarlena);
fmgr_info_cxt(typoutput, &arg->u.scalar.typfunc, arg_mcxt);
break;
}
static PyObject *
-PLyInt_FromInt16(PLyDatumToOb *arg, Datum d)
+PLyLong_FromInt16(PLyDatumToOb *arg, Datum d)
{
- return PyInt_FromLong(DatumGetInt16(d));
+ return PyLong_FromLong(DatumGetInt16(d));
}
static PyObject *
-PLyInt_FromInt32(PLyDatumToOb *arg, Datum d)
+PLyLong_FromInt32(PLyDatumToOb *arg, Datum d)
{
- return PyInt_FromLong(DatumGetInt32(d));
+ return PyLong_FromLong(DatumGetInt32(d));
}
static PyObject *
* Generic input conversion using a SQL type's output function.
*/
static PyObject *
-PLyString_FromScalar(PLyDatumToOb *arg, Datum d)
+PLyUnicode_FromScalar(PLyDatumToOb *arg, Datum d)
{
char *x = OutputFunctionCall(&arg->u.scalar.typfunc, d);
- PyObject *r = PyString_FromString(x);
+ PyObject *r = PLyUnicode_FromString(x);
pfree(x);
return r;
* The string conversion case doesn't require a tupdesc, nor per-field
* conversion data, so just go for it if that's the case to use.
*/
- if (PyString_Check(plrv) || PyUnicode_Check(plrv))
- return PLyString_ToComposite(arg, plrv, inarray);
+ if (PyUnicode_Check(plrv))
+ return PLyUnicode_ToComposite(arg, plrv, inarray);
/*
* If we're dealing with a named composite type, we must look up the
else if (PyFloat_Check(plrv))
{
/* use repr() for floats, str() is lossy */
-#if PY_MAJOR_VERSION >= 3
PyObject *s = PyObject_Repr(plrv);
plrv_bo = PLyUnicode_Bytes(s);
Py_XDECREF(s);
-#else
- plrv_bo = PyObject_Repr(plrv);
-#endif
}
else
{
-#if PY_MAJOR_VERSION >= 3
PyObject *s = PyObject_Str(plrv);
plrv_bo = PLyUnicode_Bytes(s);
Py_XDECREF(s);
-#else
- plrv_bo = PyObject_Str(plrv);
-#endif
}
if (!plrv_bo)
PLy_elog(ERROR, "could not create string representation of Python object");
* Convert a Python string to composite, using record_in.
*/
static Datum
-PLyString_ToComposite(PLyObToDatum *arg, PyObject *string, bool inarray)
+PLyUnicode_ToComposite(PLyObToDatum *arg, PyObject *string, bool inarray)
{
char *str;
* Convert a Python unicode object to a C string in PostgreSQL server
* encoding. No Python object reference is passed out of this
* function. The result is palloc'ed.
- *
- * Note that this function is disguised as PyString_AsString() when
- * using Python 3. That function returns a pointer into the internal
- * memory of the argument, which isn't exactly the interface of this
- * function. But in either case you get a rather short-lived
- * reference that you ought to better leave alone.
*/
char *
PLyUnicode_AsString(PyObject *unicode)
return rv;
}
-#if PY_MAJOR_VERSION >= 3
/*
* Convert a C string in the PostgreSQL server encoding to a Python
* unicode object. Reference ownership is passed to the caller.
{
return PLyUnicode_FromStringAndSize(s, strlen(s));
}
-
-#endif /* PY_MAJOR_VERSION >= 3 */
extern PyObject *PLyUnicode_Bytes(PyObject *unicode);
extern char *PLyUnicode_AsString(PyObject *unicode);
-#if PY_MAJOR_VERSION >= 3
extern PyObject *PLyUnicode_FromString(const char *s);
extern PyObject *PLyUnicode_FromStringAndSize(const char *s, Py_ssize_t size);
-#endif
#endif /* PLPY_UTIL_H */
#include <Python.h>
#endif
-/*
- * Python 2/3 strings/unicode/bytes handling. Python 2 has strings
- * and unicode, Python 3 has strings, which are unicode on the C
- * level, and bytes. The porting convention, which is similarly used
- * in Python 2.6, is that "Unicode" is always unicode, and "Bytes" are
- * bytes in Python 3 and strings in Python 2. Since we keep
- * supporting Python 2 and its usual strings, we provide a
- * compatibility layer for Python 3 that when asked to convert a C
- * string to a Python string it converts the C string from the
- * PostgreSQL server encoding to a Python Unicode object.
- */
-#if PY_MAJOR_VERSION >= 3
-#define PyString_Check(x) 0
-#define PyString_AsString(x) PLyUnicode_AsString(x)
-#define PyString_FromString(x) PLyUnicode_FromString(x)
-#define PyString_FromStringAndSize(x, size) PLyUnicode_FromStringAndSize(x, size)
-#endif
-
-/*
- * Python 3 only has long.
- */
-#if PY_MAJOR_VERSION >= 3
-#define PyInt_FromLong(x) PyLong_FromLong(x)
-#define PyInt_AsLong(x) PyLong_AsLong(x)
-#endif
-
-/* Python 3 removed the Py_TPFLAGS_HAVE_ITER flag */
-#if PY_MAJOR_VERSION >= 3
-#define Py_TPFLAGS_HAVE_ITER 0
-#endif
-
/* define our text domain for translations */
#undef TEXTDOMAIN
#define TEXTDOMAIN PG_TEXTDOMAIN("plpython")
#define printf(...) pg_printf(__VA_ARGS__)
/*
- * Used throughout, and also by the Python 2/3 porting layer, so it's easier to
- * just include it everywhere.
+ * Used throughout, so it's easier to just include it everywhere.
*/
#include "plpy_util.h"