From 8a6ccef47b310ff70b6f42e625b6739363265648 Mon Sep 17 00:00:00 2001 From: monsta Date: Thu, 26 Dec 2019 00:57:11 +0300 Subject: drop Python 2 support (#50) it's going EOL in 2020 --- configure.ac | 2 +- docs/xsl/fixxref.py | 2 +- src/caja-python-object.c | 26 ++++++-------------------- src/caja-python.c | 20 +++----------------- 4 files changed, 11 insertions(+), 39 deletions(-) diff --git a/configure.ac b/configure.ac index 233eb8f..a4f3f1e 100644 --- a/configure.ac +++ b/configure.ac @@ -35,7 +35,7 @@ GTK_DOC_CHECK(1.9) dnl ************************************************** dnl * Check for Python dnl ************************************************** -AM_PATH_PYTHON([2.7]) +AM_PATH_PYTHON([3.6]) PYTHON_PKG="python-${PYTHON_VERSION}-embed" PKG_CHECK_MODULES([PYTHON], [${PYTHON_PKG}],, [ diff --git a/docs/xsl/fixxref.py b/docs/xsl/fixxref.py index e476529..b891c71 100755 --- a/docs/xsl/fixxref.py +++ b/docs/xsl/fixxref.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python +#!/usr/bin/env python3 # -*- Mode: Python; py-indent-offset: 4 -*- import getopt diff --git a/src/caja-python-object.c b/src/caja-python-object.c index 7820d10..8d13c79 100644 --- a/src/caja-python-object.c +++ b/src/caja-python-object.c @@ -44,20 +44,6 @@ static GObjectClass *parent_class; -#if PY_MAJOR_VERSION >= 3 -#define STRING_CHECK(obj) PyUnicode_Check(obj) -#define STRING_FROMSTRING(str) PyUnicode_FromString(str) -#define STRING_ASSTRING(obj) PyUnicode_AsUTF8(obj) -#define INT_CHECK(obj) PyLong_Check(obj) -#define INT_ASLONG(obj) PyLong_AsLong(obj) -#else -#define STRING_CHECK(obj) PyString_Check(obj) -#define STRING_FROMSTRING(str) PyString_FromString(str) -#define STRING_ASSTRING(obj) PyString_AsString(obj) -#define INT_CHECK(obj) PyInt_Check(obj) -#define INT_ASLONG(obj) PyInt_AsLong(obj) -#endif - /* These macros assumes the following things: * a METHOD_NAME is defined with is a string * a goto label called beach @@ -99,7 +85,7 @@ static GObjectClass *parent_class; #define HANDLE_LIST(py_ret, type, type_name) \ { \ Py_ssize_t i = 0; \ - if (!PySequence_Check(py_ret) || STRING_CHECK(py_ret)) \ + if (!PySequence_Check(py_ret) || PyUnicode_Check(py_ret)) \ { \ PyErr_SetString(PyExc_TypeError, \ METHOD_NAME " must return a sequence"); \ @@ -208,7 +194,7 @@ caja_python_object_get_widget (CajaLocationWidgetProvider *provider, CHECK_OBJECT(object); CHECK_METHOD_NAME(object->instance); - py_uri = STRING_FROMSTRING(uri); + py_uri = PyUnicode_FromString(uri); py_ret = PyObject_CallMethod(object->instance, METHOD_PREFIX METHOD_NAME, "(NN)", py_uri, @@ -453,14 +439,14 @@ caja_python_object_update_file_info (CajaInfoProvider *provider, HANDLE_RETVAL(py_ret); - if (!INT_CHECK(py_ret)) + if (!PyLong_Check(py_ret)) { PyErr_SetString(PyExc_TypeError, METHOD_NAME " must return None or a int"); goto beach; } - ret = INT_ASLONG(py_ret); + ret = PyLong_AsLong(py_ret); if (!*handle && ret == CAJA_OPERATION_IN_PROGRESS) ret = CAJA_OPERATION_FAILED; @@ -553,7 +539,7 @@ caja_python_object_get_type (GTypeModule *module, NULL }; - debug_enter_args("type=%s", STRING_ASSTRING(PyObject_GetAttrString(type, "__name__"))); + debug_enter_args("type=%s", PyUnicode_AsUTF8(PyObject_GetAttrString(type, "__name__"))); info = g_new0 (GTypeInfo, 1); info->class_size = sizeof (CajaPythonObjectClass); @@ -565,7 +551,7 @@ caja_python_object_get_type (GTypeModule *module, Py_INCREF(type); type_name = g_strdup_printf("%s+CajaPython", - STRING_ASSTRING(PyObject_GetAttrString(type, "__name__"))); + PyUnicode_AsUTF8(PyObject_GetAttrString(type, "__name__"))); gtype = g_type_module_register_type (module, G_TYPE_OBJECT, diff --git a/src/caja-python.c b/src/caja-python.c index af154d9..f0aa55c 100644 --- a/src/caja-python.c +++ b/src/caja-python.c @@ -32,16 +32,6 @@ #include -#if PY_MAJOR_VERSION >= 3 -#define STRING_FROMSTRING(str) PyUnicode_FromString(str) -#define INT_FROMSSIZE_T(val) PyLong_FromSsize_t(val) -#define INT_ASSSIZE_T(obj) PyLong_AsSsize_t(obj) -#else -#define STRING_FROMSTRING(str) PyString_FromString(str) -#define INT_FROMSSIZE_T(val) PyInt_FromSsize_t(val) -#define INT_ASSSIZE_T(obj) PyInt_AsSsize_t(obj) -#endif - static const GDebugKey caja_python_debug_keys[] = { {"misc", CAJA_PYTHON_DEBUG_MISC}, }; @@ -58,13 +48,13 @@ static GList *all_pyfiles = NULL; static PyObject * caja_operationhandle_get_handle(PyGBoxed *self, void *closure) { - return INT_FROMSSIZE_T((Py_ssize_t) (size_t) self->boxed); + return PyLong_FromSsize_t((Py_ssize_t) (size_t) self->boxed); } static int caja_operationhandle_set_handle(PyGBoxed *self, PyObject *value, void *closure) { - Py_ssize_t val = INT_ASSSIZE_T(value); + Py_ssize_t val = PyLong_AsSsize_t(value); if (!PyErr_Occurred()) { if (val) { @@ -187,7 +177,7 @@ caja_python_load_dir (GTypeModule *module, /* sys.path.insert(0, dirname) */ sys_path = PySys_GetObject("path"); - py_path = STRING_FROMSTRING(dirname); + py_path = PyUnicode_FromString(dirname); PyList_Insert(sys_path, 0, py_path); Py_DECREF(py_path); } @@ -201,11 +191,7 @@ caja_python_init_python (void) { PyObject *gi, *require_version, *args, *caja, *descr; 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