Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -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}],,
[
Expand Down
2 changes: 1 addition & 1 deletion docs/xsl/fixxref.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env python
#!/usr/bin/env python3
# -*- Mode: Python; py-indent-offset: 4 -*-

import getopt
Expand Down
26 changes: 6 additions & 20 deletions src/caja-python-object.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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"); \
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand All @@ -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,
Expand Down
20 changes: 3 additions & 17 deletions src/caja-python.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,16 +32,6 @@

#include <libcaja-extension/caja-extension-types.h>

#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},
};
Expand All @@ -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) {
Expand Down Expand Up @@ -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);
}
Expand All @@ -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;
Expand Down