From 047c35bf0aaec2601d6e26e5ab479eeccc58f640 Mon Sep 17 00:00:00 2001 From: Patrick Monnerat Date: Sat, 19 Jan 2019 01:20:47 +0100 Subject: Implement Python 3 C API compatibility using conditional and macros. The updated sources are still compatible with Python 2. --- src/caja-python.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) (limited to 'src/caja-python.c') diff --git a/src/caja-python.c b/src/caja-python.c index 7f13e36..4a310a4 100644 --- a/src/caja-python.c +++ b/src/caja-python.c @@ -31,6 +31,12 @@ #include +#if PY_MAJOR_VERSION >= 3 +#define STRING_FROMSTRING(str) PyUnicode_FromString(str) +#else +#define STRING_FROMSTRING(str) PyString_FromString(str) +#endif + static const GDebugKey caja_python_debug_keys[] = { {"misc", CAJA_PYTHON_DEBUG_MISC}, }; @@ -145,7 +151,7 @@ caja_python_load_dir (GTypeModule *module, /* sys.path.insert(0, dirname) */ sys_path = PySys_GetObject("path"); - py_path = PyString_FromString(dirname); + py_path = STRING_FROMSTRING(dirname); PyList_Insert(sys_path, 0, py_path); Py_DECREF(py_path); } @@ -159,7 +165,11 @@ caja_python_init_python (void) { PyObject *gi, *require_version, *args, *caja; GModule *libpython; +#if PY_MAJOR_VERSION >= 3 + wchar_t *argv[] = { L"caja", NULL }; +#else char *argv[] = { "caja", NULL }; +#endif if (Py_IsInitialized()) return TRUE; -- cgit v1.2.1