summaryrefslogtreecommitdiffstats
path: root/libshiboken/conversions.h
diff options
context:
space:
mode:
authorRenato Filho <renato.filho@openbossa.org>2010-07-27 10:07:18 -0300
committerRenato Filho <renato.filho@openbossa.org>2010-07-27 10:08:29 -0300
commit1b4094837f983d6273a81daffc5bbffedc82cf2c (patch)
treeb780d13e3aa566df6e9287584f96023fb4f71bac /libshiboken/conversions.h
parent8a16ff951633c3755cf370228709afaf416b0407 (diff)
downloadshiboken-1b4094837f983d6273a81daffc5bbffedc82cf2c.tar.gz
shiboken-1b4094837f983d6273a81daffc5bbffedc82cf2c.tar.xz
shiboken-1b4094837f983d6273a81daffc5bbffedc82cf2c.zip
Fix char* converter
Fix tests. Created warnning about return last ref of python object. Reviewer: Marcelo Lira <marcelo.lira@openbossa.org> Luciano Wolf <luciano.wolf@openbossa.org>
Diffstat (limited to 'libshiboken/conversions.h')
-rw-r--r--libshiboken/conversions.h26
1 files changed, 25 insertions, 1 deletions
diff --git a/libshiboken/conversions.h b/libshiboken/conversions.h
index 1cb4f913..4b6d8e38 100644
--- a/libshiboken/conversions.h
+++ b/libshiboken/conversions.h
@@ -523,8 +523,32 @@ struct Converter_CString
}
};
-template <> struct Converter<char*> : Converter_CString<char*> {};
template <> struct Converter<const char*> : Converter_CString<const char*> {};
+template <> struct Converter<char*> : Converter_CString<char*>
+{
+ static inline char* toCpp(PyObject* pyobj)
+ {
+ if (pyobj == Py_None)
+ return 0;
+ return strdup(PyString_AsString(pyobj));
+ }
+};
+
+template <> struct Converter<std::string> : Converter_CString<std::string>
+{
+ static inline PyObject* toPython(void* cppobj) { return toPython(*reinterpret_cast<std::string*>(cppobj)); }
+ static inline PyObject* toPython(std::string cppObj)
+ {
+ return PyString_FromString(cppObj.c_str());
+ }
+
+ static inline std::string toCpp(PyObject* pyobj)
+ {
+ if (pyobj == Py_None)
+ return 0;
+ return std::string(PyString_AsString(pyobj));
+ }
+};
// C++ containers -------------------------------------------------------------
// The following container converters are meant to be used for pairs, lists and maps