From 8cc8f849cc71721d8bfc3c29e3454dced762fc78 Mon Sep 17 00:00:00 2001 From: Jürgen Knödlseder Date: Wed, 17 Feb 2016 11:47:46 +0100 Subject: [PATCH] Make GFilename typemap compatible with Python 3. --- pyext/typemap_GFilename.i | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/pyext/typemap_GFilename.i b/pyext/typemap_GFilename.i index f9417d1..54fd8fc 100644 --- a/pyext/typemap_GFilename.i +++ b/pyext/typemap_GFilename.i @@ -37,8 +37,12 @@ ***************************************************************************/ %typemap(in) GFilename& (GFilename temp) { if (PyString_Check($input)) { - temp = GFilename(std::string(PyString_AsString($input))); - $1 = &temp; + temp = GFilename(std::string(PyString_AsString($input))); + $1 = &temp; + } + else if (PyUnicode_Check($input)) { + temp = GFilename(std::string(PyBytes_AS_STRING(PyUnicode_AsEncodedString($input, "utf-8", "Error ~")))); + $1 = &temp; } else { void *filename_argp1 = 0; @@ -65,6 +69,10 @@ SWIG_CheckState(SWIG_ConvertPtr($input, 0, $1_descriptor, 0))) { $1 = 1; } + else if (PyUnicode_Check($input) || + SWIG_CheckState(SWIG_ConvertPtr($input, 0, $1_descriptor, 0))) { + $1 = 1; + } else { $1 = 0; } -- libgit2 0.21.4