Index: glib/pyglib.c
===================================================================
--- glib/pyglib.c	(revision 934)
+++ glib/pyglib.c	(working copy)
@@ -496,7 +496,82 @@
     return PyFloat_FromDouble(ret);
 }
 
+/**
+ * pyglib_pylist_from_glist:
+ * @list: a GList to build a Python list from
+ * @pointer_to_object: function transforming list data to Python objects
+ *
+ * The transformer must create a new Python objects or return a new
+ * reference to existing object.
+ *
+ * Returns: a new Python list
+ */
+PyObject *
+pyglib_pylist_from_glist(GList *list,
+			 PyGLibPointerToPyObjectFunc pointer_to_object)
+{
+    PyObject *result = PyList_New(list ? g_list_length(list) : 0);
+    int k;
 
+    if (!result)
+	return NULL;
+
+    for (k = 0; list; ++k, list = list->next) {
+	PyObject *item = pointer_to_object(list->data);
+
+	if (!item) {
+	    if (!PyErr_Occurred()) {
+		PyErr_SetString(PyExc_RuntimeError,
+				"internal error: cannot convert C object to Python");
+	    }
+	    Py_DECREF(result);
+	    return NULL;
+	}
+
+	if (PyList_SetItem(result, k, item) == -1) {
+	    Py_DECREF(result);
+	    return NULL;
+	}
+    }
+
+    return result;
+}
+
+/**
+ * pyglib_convert_glist_to_pylist:
+ * @list: a GList to build a Python list from
+ * @pointer_to_object: function transforming list data to Python objects
+ * @free_item: optional function to free a C object (e.g. g_free)
+ * @user_data: optional second argument for free_item
+ *
+ * The transformer must create a new Python objects or return a new
+ * reference to existing object.  GList will get freed regardless of
+ * whether Python list was successfully built or not.  If not NULL,
+ * free_item is called on each item in the list before the list itself
+ * is freed.
+ *
+ * Returns: a new Python list
+ */
+PyObject *
+pyglib_convert_glist_to_pylist(GList *list,
+			       PyGLibPointerToPyObjectFunc pointer_to_object,
+			       GFunc free_item,
+			       gpointer user_data)
+{
+    PyObject *result = pyglib_pylist_from_glist(list, pointer_to_object);
+
+    if (list) {
+	/* It is legal for `free_item' to be NULL. */
+	if (free_item)
+	    g_list_foreach(list, free_item, user_data);
+
+	g_list_free(list);
+    }
+
+    return result;
+}
+
+
 /****** Private *****/
 
 /**
Index: glib/pyglib.h
===================================================================
--- glib/pyglib.h	(revision 934)
+++ glib/pyglib.h	(working copy)
@@ -29,6 +29,7 @@
 G_BEGIN_DECLS
 
 typedef void (*PyGLibThreadBlockFunc) (void);
+typedef PyObject * (*PyGLibPointerToPyObjectFunc) (gpointer data);
 
 void pyglib_init(void);
 void pyglib_init_internal(PyObject *api);
@@ -49,6 +50,14 @@
 PyObject * pyglib_option_group_new(GOptionGroup *group);
 GOptionGroup * pyglib_option_group_transfer_group(PyObject *self);
 PyObject * pyglib_float_from_timeval(GTimeVal timeval);
+PyObject * pyglib_pylist_from_glist
+            (GList *list,
+	     PyGLibPointerToPyObjectFunc pointer_to_object);
+PyObject * pyglib_convert_glist_to_pylist
+            (GList *list,
+	     PyGLibPointerToPyObjectFunc pointer_to_object,
+	     GFunc free_item,
+	     gpointer user_data);
 
 #define pyglib_begin_allow_threads		\
     G_STMT_START {                              \
Index: gio/gio.override
===================================================================
--- gio/gio.override	(revision 934)
+++ gio/gio.override	(working copy)
@@ -121,67 +121,39 @@
 static PyObject *
 _wrap_g_drive_get_volumes (PyGObject *self)
 {
-  GList *list, *l;
-  PyObject *ret;
-
-  list = g_drive_get_volumes (G_DRIVE (self->obj));
-
-  ret = PyList_New(0);
-  for (l = list; l; l = l->next) {
-    GVolume *volume = l->data;
-    PyObject *item = pygobject_new((GObject *)volume);
-    PyList_Append(ret, item);
-    Py_DECREF(item);
-  }
-  g_list_free(list);
-
-  return ret;
+    GList *volumes = g_volume_monitor_get_connected_drives (G_VOLUME_MONITOR (self->obj));
+    return pyglib_convert_glist_to_pylist(volumes,
+					  (PyGLibPointerToPyObjectFunc) pygobject_new,
+					  (GFunc) g_object_unref,
+					  NULL);
 }
 %%
 override g_app_info_get_all noargs
 static PyObject *
 _wrap_g_app_info_get_all (PyGObject *self)
 {
-  GList *list, *l;
-  PyObject *ret;
-
-  list = g_app_info_get_all ();
-
-  ret = PyList_New(0);
-  for (l = list; l; l = l->next) {
-    GObject *obj = l->data;
-    PyObject *item = pygobject_new(obj);
-    PyList_Append(ret, item);
-    Py_DECREF(item);
-  }
-  g_list_free(list);
-
-  return ret;
+    GList *app_infos = g_app_info_get_all ();
+    return pyglib_convert_glist_to_pylist(app_infos,
+					  (PyGLibPointerToPyObjectFunc) pygobject_new,
+					  NULL,  /* Apparently we don't need to unref. */
+					  NULL);
 }
 %%
 override g_app_info_get_all_for_type args
 static PyObject *
 _wrap_g_app_info_get_all_for_type (PyGObject *self, PyObject *args)
 {
-  GList *list, *l;
-  PyObject *ret;
-  gchar *type;
+    GList *app_infos;
+    gchar *type;
 
-  if (!PyArg_ParseTuple (args, "s:app_info_get_all_for_type", &type))
-    return NULL;
+    if (!PyArg_ParseTuple (args, "s:app_info_get_all_for_type", &type))
+	return NULL;
 
-  list = g_app_info_get_all_for_type (type);
-
-  ret = PyList_New(0);
-  for (l = list; l; l = l->next) {
-    GObject *obj = l->data;
-    PyObject *item = pygobject_new(obj);
-    PyList_Append(ret, item);
-    Py_DECREF(item);
-  }
-  g_list_free(list);
-
-  return ret;
+    app_infos = g_app_info_get_all_for_type (type);
+    return pyglib_convert_glist_to_pylist(app_infos,
+					  (PyGLibPointerToPyObjectFunc) pygobject_new,
+					  NULL,  /* Apparently we don't need to unref. */
+					  NULL);
 }
 %%
 override g_content_type_guess kwargs
@@ -289,3 +261,13 @@
 
     return ret;
 }
+%%
+override g_content_types_get_registered noargs
+static PyObject *
+_wrap_g_content_types_get_registered(PyObject *self)
+{
+    return pyglib_convert_glist_to_pylist(g_content_types_get_registered(),
+					  (PyGLibPointerToPyObjectFunc) PyString_FromString,
+					  (GFunc) g_free,
+					  NULL);
+}
Index: gio/gvolumemonitor.override
===================================================================
--- gio/gvolumemonitor.override	(revision 934)
+++ gio/gvolumemonitor.override	(working copy)
@@ -24,61 +24,31 @@
 static PyObject *
 _wrap_g_volume_monitor_get_connected_drives (PyGObject *self)
 {
-  GList *list, *l;
-  PyObject *ret;
-  
-  list = g_volume_monitor_get_connected_drives (G_VOLUME_MONITOR (self->obj));
-
-  ret = PyList_New(0);
-  for (l = list; l; l = l->next) {
-    GDrive *drive = l->data;
-    PyObject *item = pygobject_new((GObject *)drive);
-    PyList_Append(ret, item);
-    Py_DECREF(item);
-  }
-  g_list_free(list);
-  
-  return ret;
+    GList *drives = g_volume_monitor_get_connected_drives (G_VOLUME_MONITOR (self->obj));
+    return pyglib_convert_glist_to_pylist(drives,
+					  (PyGLibPointerToPyObjectFunc) pygobject_new,
+					  (GFunc) g_object_unref,
+					  NULL);
 }
 %%
 override g_volume_monitor_get_volumes noargs
 static PyObject *
 _wrap_g_volume_monitor_get_volumes (PyGObject *self)
 {
-  GList *list, *l;
-  PyObject *ret;
-  
-  list = g_volume_monitor_get_volumes (G_VOLUME_MONITOR (self->obj));
-
-  ret = PyList_New(0);
-  for (l = list; l; l = l->next) {
-    GVolume *volume = l->data;
-    PyObject *item = pygobject_new((GObject *)volume);
-    PyList_Append(ret, item);
-    Py_DECREF(item);
-  }
-  g_list_free(list);
-  
-  return ret;
+    GList *volumes = g_volume_monitor_get_volumes (G_VOLUME_MONITOR (self->obj));
+    return pyglib_convert_glist_to_pylist(volumes,
+					  (PyGLibPointerToPyObjectFunc) pygobject_new,
+					  (GFunc) g_object_unref,
+					  NULL);
 }
 %%
 override g_volume_monitor_get_mounts noargs
 static PyObject *
 _wrap_g_volume_monitor_get_mounts (PyGObject *self)
 {
-  GList *list, *l;
-  PyObject *ret;
-  
-  list = g_volume_monitor_get_mounts (G_VOLUME_MONITOR (self->obj));
-
-  ret = PyList_New(0);
-  for (l = list; l; l = l->next) {
-    GMount *mount = l->data;
-    PyObject *item = pygobject_new((GObject *)mount);
-    PyList_Append(ret, item);
-    Py_DECREF(item);
-  }
-  g_list_free(list);
-  
-  return ret;
+    GList *mounts = g_volume_monitor_get_mounts (G_VOLUME_MONITOR (self->obj));
+    return pyglib_convert_glist_to_pylist(mounts,
+					  (PyGLibPointerToPyObjectFunc) pygobject_new,
+					  (GFunc) g_object_unref,
+					  NULL);
 }
Index: gio/gfileenumerator.override
===================================================================
--- gio/gfileenumerator.override	(revision 934)
+++ gio/gfileenumerator.override	(working copy)
@@ -111,9 +111,8 @@
 {
     static char *kwlist[] = { "result", NULL };
     PyGObject *result;
-    GList *next_files, *l;
+    GList *next_files;
     GError *error = NULL;
-    PyObject *ret;
     
     if (!PyArg_ParseTupleAndKeywords(args, kwargs,
 				     "O!:GFileEnumerator.next_files_finish",
@@ -127,14 +126,8 @@
     if (pyg_error_check(&error))
         return NULL;
 
-    ret = PyList_New(0);
-    for (l = next_files; l; l = l->next) {
-	GFileInfo *file_info = l->data;
-	PyObject *item = pygobject_new((GObject *)file_info);
-	PyList_Append(ret, item);
-	Py_DECREF(item);
-    }
-    g_list_free(next_files);
-
-    return ret;
+    return pyglib_convert_glist_to_pylist(next_files,
+					  (PyGLibPointerToPyObjectFunc) pygobject_new,
+					  (GFunc) g_object_unref,
+					  NULL);
 }
