4444
4545static GObjectClass * parent_class ;
4646
47+ #if PY_MAJOR_VERSION >= 3
48+ #define STRING_CHECK (obj ) PyUnicode_Check(obj)
49+ #define STRING_FROMSTRING (str ) PyUnicode_FromString(str)
50+ #define STRING_ASSTRING (obj ) PyUnicode_AsUTF8(obj)
51+ #define INT_CHECK (obj ) PyLong_Check(obj)
52+ #define INT_ASLONG (obj ) PyLong_AsLong(obj)
53+ #else
54+ #define STRING_CHECK (obj ) PyString_Check(obj)
55+ #define STRING_FROMSTRING (str ) PyString_FromString(str)
56+ #define STRING_ASSTRING (obj ) PyString_AsString(obj)
57+ #define INT_CHECK (obj ) PyInt_Check(obj)
58+ #define INT_ASLONG (obj ) PyInt(obj)
59+ #endif
60+
4761/* These macros assumes the following things:
4862 * a METHOD_NAME is defined with is a string
4963 * a goto label called beach
@@ -85,7 +99,7 @@ static GObjectClass *parent_class;
8599#define HANDLE_LIST (py_ret , type , type_name ) \
86100 { \
87101 Py_ssize_t i = 0; \
88- if (!PySequence_Check(py_ret) || PyString_Check (py_ret)) \
102+ if (!PySequence_Check(py_ret) || STRING_CHECK (py_ret)) \
89103 { \
90104 PyErr_SetString(PyExc_TypeError, \
91105 METHOD_NAME " must return a sequence"); \
@@ -194,7 +208,7 @@ caja_python_object_get_widget (CajaLocationWidgetProvider *provider,
194208 CHECK_OBJECT (object );
195209 CHECK_METHOD_NAME (object -> instance );
196210
197- py_uri = PyString_FromString (uri );
211+ py_uri = STRING_FROMSTRING (uri );
198212
199213 py_ret = PyObject_CallMethod (object -> instance , METHOD_PREFIX METHOD_NAME ,
200214 "(NN)" , py_uri ,
@@ -425,14 +439,14 @@ caja_python_object_update_file_info (CajaInfoProvider *provider,
425439
426440 HANDLE_RETVAL (py_ret );
427441
428- if (!PyInt_Check (py_ret ))
442+ if (!INT_CHECK (py_ret ))
429443 {
430444 PyErr_SetString (PyExc_TypeError ,
431445 METHOD_NAME " must return None or a int" );
432446 goto beach ;
433447 }
434448
435- ret = PyInt_AsLong (py_ret );
449+ ret = INT_ASLONG (py_ret );
436450
437451 beach :
438452 free_pygobject_data (file , NULL );
@@ -522,7 +536,7 @@ caja_python_object_get_type (GTypeModule *module,
522536 NULL
523537 };
524538
525- debug_enter_args ("type=%s" , PyString_AsString (PyObject_GetAttrString (type , "__name__" )));
539+ debug_enter_args ("type=%s" , STRING_ASSTRING (PyObject_GetAttrString (type , "__name__" )));
526540 info = g_new0 (GTypeInfo , 1 );
527541
528542 info -> class_size = sizeof (CajaPythonObjectClass );
@@ -534,7 +548,7 @@ caja_python_object_get_type (GTypeModule *module,
534548 Py_INCREF (type );
535549
536550 type_name = g_strdup_printf ("%s+CajaPython" ,
537- PyString_AsString (PyObject_GetAttrString (type , "__name__" )));
551+ STRING_ASSTRING (PyObject_GetAttrString (type , "__name__" )));
538552
539553 gtype = g_type_module_register_type (module ,
540554 G_TYPE_OBJECT ,
0 commit comments