summaryrefslogtreecommitdiff
path: root/src/pl/plpython/plpy_util.c
diff options
context:
space:
mode:
authorPeter Eisentraut2015-04-26 14:33:14 +0000
committerPeter Eisentraut2015-04-26 14:33:14 +0000
commitcac76582053ef8ea07df65fed0757f352da23705 (patch)
tree6ae01041aa61db9d686638b9d4c3ccd30d7c6487 /src/pl/plpython/plpy_util.c
parentf320cbb615e0374b18836337713239da58705cf3 (diff)
Add transforms feature
This provides a mechanism for specifying conversions between SQL data types and procedural languages. As examples, there are transforms for hstore and ltree for PL/Perl and PL/Python. reviews by Pavel Stěhule and Andres Freund
Diffstat (limited to 'src/pl/plpython/plpy_util.c')
-rw-r--r--src/pl/plpython/plpy_util.c21
1 files changed, 16 insertions, 5 deletions
diff --git a/src/pl/plpython/plpy_util.c b/src/pl/plpython/plpy_util.c
index 36958cb10f3..b6b92557678 100644
--- a/src/pl/plpython/plpy_util.c
+++ b/src/pl/plpython/plpy_util.c
@@ -142,19 +142,30 @@ PLyUnicode_AsString(PyObject *unicode)
* unicode object. Reference ownership is passed to the caller.
*/
PyObject *
-PLyUnicode_FromString(const char *s)
+PLyUnicode_FromStringAndSize(const char *s, Py_ssize_t size)
{
char *utf8string;
PyObject *o;
- utf8string = pg_server_to_any(s, strlen(s), PG_UTF8);
-
- o = PyUnicode_FromString(utf8string);
+ utf8string = pg_server_to_any(s, size, PG_UTF8);
- if (utf8string != s)
+ if (utf8string == s)
+ {
+ o = PyUnicode_FromStringAndSize(s, size);
+ }
+ else
+ {
+ o = PyUnicode_FromString(utf8string);
pfree(utf8string);
+ }
return o;
}
+PyObject *
+PLyUnicode_FromString(const char *s)
+{
+ return PLyUnicode_FromStringAndSize(s, strlen(s));
+}
+
#endif /* PY_MAJOR_VERSION >= 3 */