Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Couple of python binding cleanups #711

Merged
merged 3 commits into from May 27, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
13 changes: 13 additions & 0 deletions python/header-py.c
Expand Up @@ -419,6 +419,19 @@ static PyObject * hdr_iternext(hdrObject *s)
return res;
}

PyObject * utf8FromString(const char *s)
{
/* In Python 3, we return all strings as surrogate-escaped utf-8 */
#if PY_MAJOR_VERSION >= 3
if (s != NULL)
return PyUnicode_DecodeUTF8(s, strlen(s), "surrogateescape");
#else
if (s != NULL)
return PyBytes_FromString(s);
#endif
Py_RETURN_NONE;
}

int utf8FromPyObject(PyObject *item, PyObject **str)
{
PyObject *res = NULL;
Expand Down
13 changes: 1 addition & 12 deletions python/rpmsystem-py.h
Expand Up @@ -19,17 +19,6 @@
#define PyInt_AsSsize_t PyLong_AsSsize_t
#endif

static inline PyObject * utf8FromString(const char *s)
{
/* In Python 3, we return all strings as surrogate-escaped utf-8 */
#if PY_MAJOR_VERSION >= 3
if (s != NULL)
return PyUnicode_DecodeUTF8(s, strlen(s), "surrogateescape");
#else
if (s != NULL)
return PyBytes_FromString(s);
#endif
Py_RETURN_NONE;
}
PyObject * utf8FromString(const char *s);

#endif /* H_SYSTEM_PYTHON */