diff options
Diffstat (limited to 'src/pl/plpython/plpy_util.c')
-rw-r--r-- | src/pl/plpython/plpy_util.c | 21 |
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 */ |