diff --git a/glib/Makefile.am b/glib/Makefile.am
index b471259..65a0e9d 100644
--- a/glib/Makefile.am
+++ b/glib/Makefile.am
@@ -2,7 +2,7 @@ AUTOMAKE_OPTIONS = 1.7
 INCLUDES = $(PYTHON_INCLUDES) $(GLIB_CFLAGS) -DPY_SSIZE_T_CLEAN
 
 pkgincludedir = $(includedir)/pygtk-2.0
-pkginclude_HEADERS = pyglib.h
+pkginclude_HEADERS = pyglib.h pyglib-python-compat.h
 
 lib_LTLIBRARIES = libpyglib-2.0.la
 
diff --git a/glib/glibmodule.c b/glib/glibmodule.c
index 5591d36..80f582f 100644
--- a/glib/glibmodule.c
+++ b/glib/glibmodule.c
@@ -547,13 +547,13 @@ pyglib_get_application_name(PyObject *self)
 static PyObject*
 pyglib_set_application_name(PyObject *self, PyObject *arg)
 {
-    if (!PyString_Check(arg)) {
+    if (!_PyUnicode_Check(arg)) {
 	PyErr_Format(PyExc_TypeError,
 		     "first argument must be a string, not '%s'",
-		     PyString_AS_STRING(PyObject_Repr(arg)));
+		     _PyUnicode_AS_STRING(PyObject_Repr(arg)));
 	return NULL;
     }
-    g_set_application_name(PyString_AS_STRING(arg));
+    g_set_application_name(_PyUnicode_AS_STRING(arg));
     Py_INCREF(Py_None);
     return Py_None;
 }
@@ -574,13 +574,13 @@ pyglib_get_prgname(PyObject *self)
 static PyObject*
 pyglib_set_prgname(PyObject *self, PyObject *arg)
 {
-    if (!PyString_Check(arg)) {
+    if (!_PyUnicode_Check(arg)) {
 	PyErr_Format(PyExc_TypeError,
 		     "first argument must be a string, not '%s'",
-		     PyString_AS_STRING(PyObject_Repr(arg)));
+		     _PyUnicode_AS_STRING(PyObject_Repr(arg)));
 	return NULL;
     }
-    g_set_prgname(PyString_AS_STRING(arg));
+    g_set_prgname(_PyUnicode_AS_STRING(arg));
     Py_INCREF(Py_None);
     return Py_None;
 }
diff --git a/glib/option.py b/glib/option.py
index 027752f..791380f 100644
--- a/glib/option.py
+++ b/glib/option.py
@@ -34,6 +34,11 @@ import optparse
 from optparse import OptParseError, OptionError, OptionValueError, \
                      BadOptionError, OptionConflictError
 
+try:
+    basestring
+except NameError:
+    basestring = str
+
 import glib
 _glib = sys.modules['glib._glib']
 
diff --git a/glib/pygiochannel.c b/glib/pygiochannel.c
index 70cdf57..e557a0b 100644
--- a/glib/pygiochannel.c
+++ b/glib/pygiochannel.c
@@ -52,6 +52,34 @@ py_io_channel_compare(PyGIOChannel *self, PyGIOChannel *v)
 }
 
 static PyObject*
+py_io_channel_richcompare(PyGIOChannel *self, PyGIOChannel *other,
+                          int op)
+{
+    PyObject *res;
+
+    switch (op) {
+
+      case Py_EQ:
+	 res = (self->channel == other->channel) ? Py_True : Py_NotImplemented;
+	 Py_INCREF(res);
+	 break;
+
+      case Py_NE:
+	 res = (self->channel != other->channel) ? Py_True : Py_NotImplemented;
+	 Py_INCREF(res);
+	 break;
+
+      default:
+	  res = Py_NotImplemented;
+	  Py_INCREF(res);
+	  break;
+    }
+
+    return res;
+}
+
+
+static PyObject*
 py_io_channel_get_iter(PyObject *self)
 {
     Py_INCREF(self);
@@ -774,7 +802,8 @@ pyglib_iochannel_register_types(PyObject *d)
     PyGIOChannel_Type.tp_members = py_io_channel_members;
     PyGIOChannel_Type.tp_methods = py_io_channel_methods;
     PyGIOChannel_Type.tp_hash = (hashfunc)py_io_channel_hash;
-    PyGIOChannel_Type.tp_compare = (cmpfunc)py_io_channel_compare;
+    _PyRegister_Compare_Slot(PyGIOChannel_Type, py_io_channel_compare,
+                             py_io_channel_richcompare);
     PyGIOChannel_Type.tp_iter = (getiterfunc)py_io_channel_get_iter;
     PyGIOChannel_Type.tp_iternext = (iternextfunc)py_io_channel_next;
 
diff --git a/glib/pyglib-private.h b/glib/pyglib-private.h
index 8b033e1..c535fee 100644
--- a/glib/pyglib-private.h
+++ b/glib/pyglib-private.h
@@ -25,8 +25,6 @@
 #include <Python.h>
 #include <glib.h>
 
-#include <pyglib-python-compat.h>
-
 G_BEGIN_DECLS
 
 struct _PyGLib_Functions {
diff --git a/glib/pyglib-python-compat.h b/glib/pyglib-python-compat.h
index 915a912..7a07d7e 100644
--- a/glib/pyglib-python-compat.h
+++ b/glib/pyglib-python-compat.h
@@ -44,7 +44,14 @@ typedef inquiry lenfunc;
 /* Compilation on Python 2.x */
 #if PY_VERSION_HEX < 0x03000000
 #define RO READONLY
+#define _PyBytes_FromString PyString_FromString
+#define _PyBytes_FromStringAndSize PyString_FromStringAndSize
+#define _PyBytes_AsString PyString_AsString
+#define _PyBytes_AS_STRING PyString_AsString
+#define _PyBytes_Resize _PyString_Resize
+#define _PyBytes_GET_SIZE PyString_GET_SIZE
 #define _PyUnicode_Check PyString_Check
+#define _PyBytes_Check PyString_Check
 #define _PyUnicode_AsString PyString_AsString
 #define _PyUnicode_AsStringAndSize PyString_AsStringAndSize
 #define _PyUnicode_FromString PyString_FromString
@@ -60,7 +67,13 @@ typedef inquiry lenfunc;
 #define _PyLongObject PyIntObject
 #define _PyLong_Type PyInt_Type
 #define _PyLong_AS_LONG PyInt_AS_LONG
+#define _PyObject_Cmp(ob1, ob2) \
+    PyObject_Cmp(ob1, ob2, &res)
+#define _PyRegister_Compare_Slot(type, compare, richcompare) \
+    type.tp_compare = (cmpfunc) compare;                     \
+    type.tp_richcompare = (richcmpfunc) richcompare;
 #define Py_TYPE(ob) (((PyObject*)(ob))->ob_type)
+#define PyVarObject_HEAD_INIT(x,n) PyObject_HEAD_INIT(x) n,
 #else
 #undef PYGLIB_MODULE_START
 #undef PYGLIB_MODULE_END
@@ -99,9 +112,14 @@ PyTypeObject symbol = {                                 \
 	    return;                                         \
     PyDict_SetItemString(d, name, (PyObject *)&type);
 
+#define _PyBytes_FromStringAndSize PyBytes_FromStringAndSize
+#define _PyBytes_FromString PyBytes_FromString
+#define _PyBytes_AsString PyBytes_AsString
+#define _PyBytes_AS_STRING _PyBytes_AsString
+#define _PyBytes_GET_SIZE PyBytes_GET_SIZE
+#define _PyBytes_Check PyBytes_Check
 #define _PyUnicode_Check PyUnicode_Check
-#define _PyUnicode_AsString PyUnicode_AsString
-#define _PyUnicode_AsStringAndSize(obj, buf, size) PyUnicode_AsStringAndSize(obj, size)
+#define _PyUnicode_AsStringAndSize(obj, buf, size) *buf = _PyUnicode_AsStringAndSize(obj, size)
 #define _PyUnicode_FromString PyUnicode_FromString
 #define _PyUnicode_FromStringAndSize PyUnicode_FromStringAndSize
 #define _PyUnicode_FromFormat PyUnicode_FromFormat
@@ -115,6 +133,10 @@ PyTypeObject symbol = {                                 \
 #define _PyLong_AS_LONG PyLong_AS_LONG
 #define _PyLongObject PyLongObject
 #define _PyLong_Type PyLong_Type
+#define _PyObject_Cmp(ob1, ob2) \
+    PyObject_RichCompare(ob1, ob2, Py_EQ) == Py_True ? 0 : -1
+#define _PyRegister_Compare_Slot(type, compare, richcompare) \
+    type.tp_richcompare = (richcmpfunc) richcompare;
 #endif
 
 #endif /* __PYGLIB_PYTHON_COMPAT_H__ */
diff --git a/glib/pyglib.h b/glib/pyglib.h
index 84bb36c..4426c4b 100644
--- a/glib/pyglib.h
+++ b/glib/pyglib.h
@@ -23,7 +23,6 @@
 #define __PYGLIB_H__
 
 #include <Python.h>
-
 #include <glib.h>
 
 G_BEGIN_DECLS
@@ -73,8 +72,7 @@ DL_EXPORT(void) init##symbol(void)			\
 #define PYGLIB_MODULE_END }
 #define PYGLIB_DEFINE_TYPE(typename, symbol, csymbol)	\
 PyTypeObject symbol = {                                 \
-    PyObject_HEAD_INIT(NULL)                            \
-    0,                                                  \
+    PyVarObject_HEAD_INIT(NULL, 0)                      \
     typename,						\
     sizeof(csymbol),                                    \
     0,                                                  \
@@ -88,6 +86,8 @@ PyTypeObject symbol = {                                 \
 	return;                                         \
     PyDict_SetItemString(d, name, (PyObject *)&type);
 
+#include "pyglib-python-compat.h"
+
 G_END_DECLS
 
 #endif /* __PYGLIB_H__ */
diff --git a/glib/pygmaincontext.c b/glib/pygmaincontext.c
index 186215a..95c536b 100644
--- a/glib/pygmaincontext.c
+++ b/glib/pygmaincontext.c
@@ -59,6 +59,33 @@ pyg_main_context_compare(PyGMainContext *self, PyGMainContext *v)
     return 1;
 }
 
+static PyObject*
+pyg_main_context_richcompare(PyGMainContext *self, PyGMainContext *other,
+                             int op)
+{
+    PyObject *res;
+
+    switch (op) {
+
+      case Py_EQ:
+	 res = (self->context == other->context) ? Py_True : Py_NotImplemented;
+	 Py_INCREF(res);
+	 break;
+
+      case Py_NE:
+	 res = (self->context != other->context) ? Py_True : Py_NotImplemented;
+	 Py_INCREF(res);
+	 break;
+
+      default:
+	  res = Py_NotImplemented;
+	  Py_INCREF(res);
+	  break;
+    }
+
+    return res;
+}
+
 static PyObject *
 _wrap_g_main_context_iteration (PyGMainContext *self, PyObject *args)
 {
@@ -91,7 +118,8 @@ void
 pyglib_maincontext_register_types(PyObject *d)
 {
     PyGMainContext_Type.tp_dealloc = (destructor)pyg_main_context_dealloc;
-    PyGMainContext_Type.tp_compare = (cmpfunc)pyg_main_context_compare;
+    _PyRegister_Compare_Slot(PyGMainContext_Type, pyg_main_context_compare,
+                             pyg_main_context_richcompare);
     PyGMainContext_Type.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE;
     PyGMainContext_Type.tp_methods = _PyGMainContext_methods;
     PyGMainContext_Type.tp_init = (initproc)pyg_main_context_init;
diff --git a/glib/pygmainloop.c b/glib/pygmainloop.c
index 3f4cf3d..3ece519 100644
--- a/glib/pygmainloop.c
+++ b/glib/pygmainloop.c
@@ -287,6 +287,34 @@ pyg_main_loop_compare(PyGMainLoop *self, PyGMainLoop *v)
     return 1;
 }
 
+static PyObject*
+pyg_main_loop_richcompare(PyGMainLoop *self, PyGMainLoop *other,
+                          int op)
+{
+    PyObject *res;
+
+    switch (op) {
+
+      case Py_EQ:
+	 res = (self->loop == other->loop) ? Py_True : Py_NotImplemented;
+	 Py_INCREF(res);
+	 break;
+
+      case Py_NE:
+	 res = (self->loop != other->loop) ? Py_True : Py_NotImplemented;
+	 Py_INCREF(res);
+	 break;
+
+      default:
+	  res = Py_NotImplemented;
+	  Py_INCREF(res);
+	  break;
+    }
+
+    return res;
+}
+
+
 static PyObject *
 _wrap_g_main_loop_get_context (PyGMainLoop *loop)
 {
@@ -340,7 +368,8 @@ void
 pyglib_mainloop_register_types(PyObject *d)
 {
     PyGMainLoop_Type.tp_dealloc = (destructor)pyg_main_loop_dealloc;
-    PyGMainLoop_Type.tp_compare = (cmpfunc)pyg_main_loop_compare;
+    _PyRegister_Compare_Slot(PyGMainLoop_Type, pyg_main_loop_compare,
+                             pyg_main_loop_richcompare);
     PyGMainLoop_Type.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE;
     PyGMainLoop_Type.tp_methods = _PyGMainLoop_methods;
     PyGMainLoop_Type.tp_init = (initproc)pyg_main_loop_init;
diff --git a/glib/pygoptioncontext.c b/glib/pygoptioncontext.c
index 92ba901..32d7a2b 100644
--- a/glib/pygoptioncontext.c
+++ b/glib/pygoptioncontext.c
@@ -287,6 +287,33 @@ pyg_option_get_context(PyGOptionContext *self)
     return PyCObject_FromVoidPtr(self->context, NULL);
 }
 
+static PyObject*
+pyg_option_context_richcompare(PyGOptionContext *self, PyGOptionContext *other,
+                               int op)
+{
+    PyObject *res;
+
+    switch (op) {
+
+      case Py_EQ:
+	 res = (self->context == other->context) ? Py_True : Py_NotImplemented;
+	 Py_INCREF(res);
+	 break;
+
+      case Py_NE:
+	 res = (self->context != other->context) ? Py_True : Py_NotImplemented;
+	 Py_INCREF(res);
+	 break;
+
+      default:
+	  res = Py_NotImplemented;
+	  Py_INCREF(res);
+	  break;
+    }
+
+    return res;
+}
+
 static PyMethodDef pyg_option_context_methods[] = {
     { "parse", (PyCFunction)pyg_option_context_parse, METH_VARARGS | METH_KEYWORDS },
     { "set_help_enabled", (PyCFunction)pyg_option_context_set_help_enabled, METH_VARARGS | METH_KEYWORDS },
@@ -304,7 +331,8 @@ void
 pyglib_option_context_register_types(PyObject *d)
 {
     PyGOptionContext_Type.tp_dealloc = (destructor)pyg_option_context_dealloc;
-    PyGOptionContext_Type.tp_compare = (cmpfunc)pyg_option_context_compare;
+    _PyRegister_Compare_Slot(PyGOptionContext_Type, pyg_option_context_compare,
+                             pyg_option_context_richcompare);
     PyGOptionContext_Type.tp_flags = Py_TPFLAGS_DEFAULT;
     PyGOptionContext_Type.tp_methods = pyg_option_context_methods;
     PyGOptionContext_Type.tp_init = (initproc)pyg_option_context_init;
diff --git a/glib/pygoptiongroup.c b/glib/pygoptiongroup.c
index 70e4529..3cb2a3e 100644
--- a/glib/pygoptiongroup.c
+++ b/glib/pygoptiongroup.c
@@ -252,6 +252,33 @@ pyg_option_group_compare(PyGOptionGroup *self, PyGOptionGroup *group)
     return -1;
 }
 
+static PyObject*
+pyg_option_group_richcompare(PyGOptionGroup *self, PyGOptionGroup *other,
+                             int op)
+{
+    PyObject *res;
+
+    switch (op) {
+
+      case Py_EQ:
+	 res = (self->group == other->group) ? Py_True : Py_NotImplemented;
+	 Py_INCREF(res);
+	 break;
+
+      case Py_NE:
+	 res = (self->group != other->group) ? Py_True : Py_NotImplemented;
+	 Py_INCREF(res);
+	 break;
+
+      default:
+	  res = Py_NotImplemented;
+	  Py_INCREF(res);
+	  break;
+    }
+
+    return res;
+}
+
 static PyMethodDef pyg_option_group_methods[] = {
     { "add_entries", (PyCFunction)pyg_option_group_add_entries, METH_VARARGS | METH_KEYWORDS },
     { "set_translation_domain", (PyCFunction)pyg_option_group_set_translation_domain, METH_VARARGS | METH_KEYWORDS },
@@ -262,7 +289,8 @@ void
 pyglib_option_group_register_types(PyObject *d)
 {
     PyGOptionGroup_Type.tp_dealloc = (destructor)pyg_option_group_dealloc;
-    PyGOptionGroup_Type.tp_compare = (cmpfunc)pyg_option_group_compare;
+    _PyRegister_Compare_Slot(PyGOptionGroup_Type, pyg_option_group_compare,
+                             pyg_option_group_richcompare);
     PyGOptionGroup_Type.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE;
     PyGOptionGroup_Type.tp_methods = pyg_option_group_methods;
     PyGOptionGroup_Type.tp_init = (initproc)pyg_option_group_init;
diff --git a/glib/pygsource.c b/glib/pygsource.c
index 298b928..4c27371 100644
--- a/glib/pygsource.c
+++ b/glib/pygsource.c
@@ -255,11 +255,11 @@ pyg_source_get_current_time(PyGSource *self)
 }
 
 static PyMethodDef pyg_source_methods[] = {
-    { "attach", (PyCFunction)pyg_source_attach, METH_KEYWORDS },
+    { "attach", (PyCFunction)pyg_source_attach, METH_VARARGS | METH_KEYWORDS },
     { "destroy", (PyCFunction)pyg_source_destroy, METH_NOARGS },
     { "set_callback", (PyCFunction)pyg_source_set_callback, METH_VARARGS },
     { "get_context", (PyCFunction)pyg_source_get_context, METH_NOARGS },
-    { "add_poll", (PyCFunction)pyg_source_add_poll, METH_KEYWORDS },
+    { "add_poll", (PyCFunction)pyg_source_add_poll, METH_VARARGS | METH_KEYWORDS },
     { "remove_poll", (PyCFunction)pyg_source_remove_poll, METH_KEYWORDS },
     { "get_current_time", (PyCFunction)pyg_source_get_current_time, METH_NOARGS },
     { NULL, NULL, 0 }
