[pygobject] prefix compat macros with PYGLIB



commit 5824ff98175b749dbcfa72d24b994230b6e05377
Author: John (J5) Palmieri <johnp redhat com>
Date:   Mon Aug 9 15:16:51 2010 -0400

    prefix compat macros with PYGLIB
    
    * refactor from John Ehresman <jpe wingware com> py3k branch
    * fix up some extranious PyString calls
    * remove duplicate macros from pyglib.h that are in pyglib-python-compat.h
    * pygobject.h can't import pyglib-python-compat.h so add codepaths
      for both Py3k and legacy code instead of using macros
    
    https://bugzilla.gnome.org/show_bug.cgi?id=615872

 glib/glibmodule.c           |   48 +++++-----
 glib/pygiochannel.c         |   46 +++++-----
 glib/pyglib-python-compat.h |  153 +++++++++++++++++++++++-------
 glib/pyglib.c               |   22 ++--
 glib/pyglib.h               |   14 ---
 glib/pygoptioncontext.c     |    4 +-
 glib/pygsource.c            |   16 ++--
 glib/pygspawn.c             |   32 +++---
 gobject/gobjectmodule.c     |  216 +++++++++++++++++++++---------------------
 gobject/pygboxed.c          |    2 +-
 gobject/pygenum.c           |   84 +++++++++---------
 gobject/pygflags.c          |  122 ++++++++++++------------
 gobject/pygobject-private.h |   12 +-
 gobject/pygobject.c         |   46 +++++-----
 gobject/pygobject.h         |   23 +++++
 gobject/pygparamspec.c      |   24 +++---
 gobject/pygpointer.c        |    2 +-
 gobject/pygtype.c           |  170 +++++++++++++++++-----------------
 18 files changed, 563 insertions(+), 473 deletions(-)
---
diff --git a/glib/glibmodule.c b/glib/glibmodule.c
index f794d5d..94335a1 100644
--- a/glib/glibmodule.c
+++ b/glib/glibmodule.c
@@ -68,19 +68,19 @@ get_handler_priority(gint *priority, PyObject *kwargs)
     }
     pos = 0;
     PyDict_Next(kwargs, &pos, &key, &val);
-    if (!_PyUnicode_Check(key)) {
+    if (!PYGLIB_PyUnicode_Check(key)) {
 	PyErr_SetString(PyExc_TypeError,
 			"keyword argument name is not a string");
 	return -1;
     }
 
-    if (strcmp(_PyUnicode_AsString(key), "priority") != 0) {
+    if (strcmp(PYGLIB_PyUnicode_AsString(key), "priority") != 0) {
 	PyErr_SetString(PyExc_TypeError,
 			"only 'priority' keyword argument accepted");
 	return -1;
     }
 
-    *priority = _PyLong_AsLong(val);
+    *priority = PYGLIB_PyLong_AsLong(val);
     if (PyErr_Occurred()) {
 	PyErr_Clear();
 	PyErr_SetString(PyExc_ValueError, "could not get priority value");
@@ -135,7 +135,7 @@ pyglib_idle_add(PyObject *self, PyObject *args, PyObject *kwargs)
     handler_id = g_idle_add_full(priority,
 				 _pyglib_handler_marshal, data,
 				 _pyglib_destroy_notify);
-    return _PyLong_FromLong(handler_id);
+    return PYGLIB_PyLong_FromLong(handler_id);
 }
 
 
@@ -175,7 +175,7 @@ pyglib_timeout_add(PyObject *self, PyObject *args, PyObject *kwargs)
     handler_id = g_timeout_add_full(priority, interval,
 				    _pyglib_handler_marshal, data,
 				    _pyglib_destroy_notify);
-    return _PyLong_FromLong(handler_id);
+    return PYGLIB_PyLong_FromLong(handler_id);
 }
 
 static PyObject *
@@ -214,7 +214,7 @@ pyglib_timeout_add_seconds(PyObject *self, PyObject *args, PyObject *kwargs)
     handler_id = g_timeout_add_seconds_full(priority, interval,
                                             _pyglib_handler_marshal, data,
                                             _pyglib_destroy_notify);
-    return _PyLong_FromLong(handler_id);
+    return PYGLIB_PyLong_FromLong(handler_id);
 }
 
 static gboolean
@@ -305,7 +305,7 @@ pyglib_io_add_watch(PyObject *self, PyObject *args, PyObject *kwargs)
 				     (GDestroyNotify)_pyglib_destroy_notify);
     g_io_channel_unref(iochannel);
     
-    return _PyLong_FromLong(handler_id);
+    return PYGLIB_PyLong_FromLong(handler_id);
 }
 
 static PyObject *
@@ -385,7 +385,7 @@ pyglib_child_watch_add(PyObject *unused, PyObject *args, PyObject *kwargs)
         Py_INCREF(child_data->data);
     id = g_child_watch_add_full(priority, pid, child_watch_func,
                                 child_data, child_watch_dnotify);
-    return _PyLong_FromLong(id);
+    return PYGLIB_PyLong_FromLong(id);
 }
 
 static PyObject *
@@ -402,7 +402,7 @@ pyglib_markup_escape_text(PyObject *unused, PyObject *args, PyObject *kwargs)
         return NULL;
 
     text_out = g_markup_escape_text(text_in, text_size);
-    retval = _PyUnicode_FromString(text_out);
+    retval = PYGLIB_PyUnicode_FromString(text_out);
     g_free(text_out);
     return retval;
 }
@@ -422,7 +422,7 @@ pyglib_get_user_cache_dir(PyObject *self)
     const char *path = g_get_user_cache_dir();
 
     if (path)
-        return _PyUnicode_FromString(path);
+        return PYGLIB_PyUnicode_FromString(path);
     else {
         Py_INCREF(Py_None);
         return Py_None;
@@ -435,7 +435,7 @@ pyglib_get_user_config_dir(PyObject *self)
     const char *path = g_get_user_config_dir();
 
     if (path)
-        return _PyUnicode_FromString(path);
+        return PYGLIB_PyUnicode_FromString(path);
     else {
         Py_INCREF(Py_None);
         return Py_None;
@@ -448,7 +448,7 @@ pyglib_get_user_data_dir(PyObject *self)
     const char *path = g_get_user_data_dir();
 
     if (path)
-        return _PyUnicode_FromString(path);
+        return PYGLIB_PyUnicode_FromString(path);
     else {
         Py_INCREF(Py_None);
         return Py_None;
@@ -469,7 +469,7 @@ pyglib_get_user_special_dir(PyObject *unused, PyObject *args, PyObject *kwargs)
 
     path = g_get_user_special_dir(directory);
     if (path)
-        return _PyUnicode_FromString(path);
+        return PYGLIB_PyUnicode_FromString(path);
     else {
         Py_INCREF(Py_None);
         return Py_None;
@@ -479,7 +479,7 @@ pyglib_get_user_special_dir(PyObject *unused, PyObject *args, PyObject *kwargs)
 static PyObject *
 pyglib_main_depth(PyObject *unused)
 {
-    return _PyLong_FromLong(g_main_depth());
+    return PYGLIB_PyLong_FromLong(g_main_depth());
 }
 
 static PyObject *
@@ -535,7 +535,7 @@ pyglib_filename_from_utf8(PyObject *self, PyObject *args)
         g_free(filename);
         return NULL;
     }
-    py_filename = _PyUnicode_FromStringAndSize(filename, bytes_written);
+    py_filename = PYGLIB_PyUnicode_FromStringAndSize(filename, bytes_written);
     g_free(filename);
     return py_filename;
 }
@@ -551,19 +551,19 @@ pyglib_get_application_name(PyObject *self)
         Py_INCREF(Py_None);
         return Py_None;
     }
-    return _PyUnicode_FromString(name);
+    return PYGLIB_PyUnicode_FromString(name);
 }
 
 static PyObject*
 pyglib_set_application_name(PyObject *self, PyObject *arg)
 {
-    if (!PyString_Check(arg)) {
+    if (!PYGLIB_PyUnicode_Check(arg)) {
 	PyErr_Format(PyExc_TypeError,
 		     "first argument must be a string, not '%s'",
-		     PyString_AS_STRING(PyObject_Repr(arg)));
+		     PYGLIB_PyUnicode_AsString(PyObject_Repr(arg)));
 	return NULL;
     }
-    g_set_application_name(PyString_AS_STRING(arg));
+    g_set_application_name(PYGLIB_PyUnicode_AsString(arg));
     Py_INCREF(Py_None);
     return Py_None;
 }
@@ -578,19 +578,19 @@ pyglib_get_prgname(PyObject *self)
         Py_INCREF(Py_None);
         return Py_None;
     }
-    return _PyUnicode_FromString(name);
+    return PYGLIB_PyUnicode_FromString(name);
 }
 
 static PyObject*
 pyglib_set_prgname(PyObject *self, PyObject *arg)
 {
-    if (!PyString_Check(arg)) {
+    if (!PYGLIB_PyUnicode_Check(arg)) {
 	PyErr_Format(PyExc_TypeError,
 		     "first argument must be a string, not '%s'",
-		     PyString_AS_STRING(PyObject_Repr(arg)));
+		     PYGLIB_PyUnicode_AsString(PyObject_Repr(arg)));
 	return NULL;
     }
-    g_set_prgname(PyString_AS_STRING(arg));
+    g_set_prgname(PYGLIB_PyUnicode_AsString(arg));
     Py_INCREF(Py_None);
     return Py_None;
 }
@@ -608,7 +608,7 @@ pyglib_find_program_in_path(PyObject *unused, PyObject *args, PyObject *kwargs)
         return NULL;
 
     ret = g_find_program_in_path(program);
-    retval = _PyUnicode_FromString(ret);
+    retval = PYGLIB_PyUnicode_FromString(ret);
     g_free(ret);
     return retval;
 }
diff --git a/glib/pygiochannel.c b/glib/pygiochannel.c
index 97eb8e0..6cecd82 100644
--- a/glib/pygiochannel.c
+++ b/glib/pygiochannel.c
@@ -39,7 +39,7 @@ py_io_channel_next(PyGIOChannel *self)
         return NULL;
     }
 
-    ret_obj = _PyUnicode_FromStringAndSize(str_return, length);
+    ret_obj = PYGLIB_PyUnicode_FromStringAndSize(str_return, length);
     g_free(str_return);
     return ret_obj;
 }
@@ -94,7 +94,7 @@ py_io_channel_shutdown(PyGIOChannel* self, PyObject *args, PyObject *kwargs)
     if (pyglib_error_check(&error))
 	return NULL;
 	
-    return _PyLong_FromLong(ret);
+    return PYGLIB_PyLong_FromLong(ret);
 }
 
 /* character encoding conversion involved functions.
@@ -118,7 +118,7 @@ py_io_channel_set_buffer_size(PyGIOChannel* self, PyObject *args, PyObject *kwar
 static PyObject*
 py_io_channel_get_buffer_size(PyGIOChannel* self)
 {
-    return _PyLong_FromLong(g_io_channel_get_buffer_size(self->channel));
+    return PYGLIB_PyLong_FromLong(g_io_channel_get_buffer_size(self->channel));
 }
 
 static PyObject*
@@ -139,7 +139,7 @@ py_io_channel_set_buffered(PyGIOChannel* self, PyObject *args, PyObject *kwargs)
 static PyObject*
 py_io_channel_get_buffered(PyGIOChannel* self)
 {
-    return _PyLong_FromLong(g_io_channel_get_buffered(self->channel));
+    return PYGLIB_PyLong_FromLong(g_io_channel_get_buffered(self->channel));
 }
 
 static PyObject*
@@ -170,7 +170,7 @@ py_io_channel_get_encoding(PyGIOChannel* self)
 	return Py_None;
     }
 
-    return _PyUnicode_FromString(encoding);
+    return PYGLIB_PyUnicode_FromString(encoding);
 }
 
 #define CHUNK_SIZE (8 * 1024)
@@ -189,7 +189,7 @@ py_io_channel_read_chars(PyGIOChannel* self, PyObject *args, PyObject *kwargs)
         return NULL;
 	
     if (max_count == 0)
-	return _PyUnicode_FromString("");
+	return PYGLIB_PyUnicode_FromString("");
     
     while (status == G_IO_STATUS_NORMAL
 	   && (max_count == -1 || total_read < max_count)) {
@@ -206,16 +206,16 @@ py_io_channel_read_chars(PyGIOChannel* self, PyObject *args, PyObject *kwargs)
         }
 	
 	if ( ret_obj == NULL ) {
-	    ret_obj = _PyUnicode_FromStringAndSize((char *)NULL, buf_size);
+	    ret_obj = PYGLIB_PyUnicode_FromStringAndSize((char *)NULL, buf_size);
 	    if (ret_obj == NULL)
 		goto failure;
 	}
-	else if (buf_size + total_read > _PyUnicode_GET_SIZE(ret_obj)) {
-	    if (_PyUnicode_Resize(&ret_obj, buf_size + total_read) == -1)
+	else if (buf_size + total_read > PYGLIB_PyUnicode_GET_SIZE(ret_obj)) {
+	    if (PYGLIB_PyUnicode_Resize(&ret_obj, buf_size + total_read) == -1)
 		goto failure;
 	}
        
-        buf = _PyUnicode_AS_STRING(ret_obj) + total_read;
+        buf = PYGLIB_PyUnicode_AsString(ret_obj) + total_read;
 
         pyglib_unblock_threads();
         status = g_io_channel_read_chars(self->channel, buf, buf_size, 
@@ -227,8 +227,8 @@ py_io_channel_read_chars(PyGIOChannel* self, PyObject *args, PyObject *kwargs)
 	total_read += single_read;
     }
 	
-    if ( total_read != _PyUnicode_GET_SIZE(ret_obj) ) {
-	if (_PyUnicode_Resize(&ret_obj, total_read) == -1)
+    if ( total_read != PYGLIB_PyUnicode_GET_SIZE(ret_obj) ) {
+	if (PYGLIB_PyUnicode_Resize(&ret_obj, total_read) == -1)
 	    goto failure;
     }
     return ret_obj;
@@ -258,7 +258,7 @@ py_io_channel_write_chars(PyGIOChannel* self, PyObject *args, PyObject *kwargs)
     if (pyglib_error_check(&error))
 	return NULL;
 	
-    return _PyLong_FromLong(count);
+    return PYGLIB_PyLong_FromLong(count);
 }
 
 static PyObject*
@@ -284,13 +284,13 @@ py_io_channel_write_lines(PyGIOChannel* self, PyObject *args, PyObject *kwargs)
             PyErr_Clear();
             goto normal_exit;
         }
-        if (!_PyUnicode_Check(value)) {
+        if (!PYGLIB_PyUnicode_Check(value)) {
             PyErr_SetString(PyExc_TypeError, "glib.IOChannel.writelines must"
                             " be sequence/iterator of strings");
             Py_DECREF(iter);
             return NULL;
         }
-        _PyUnicode_AsStringAndSize(value, &buf, &buf_len);
+        PYGLIB_PyUnicode_AsStringAndSize(value, &buf, &buf_len);
         pyglib_unblock_threads();
         status = g_io_channel_write_chars(self->channel, buf, buf_len, &count, &error);
         pyglib_unblock_threads();
@@ -318,7 +318,7 @@ py_io_channel_flush(PyGIOChannel* self)
     if (pyglib_error_check(&error))
 	return NULL;
 	
-    return _PyLong_FromLong(status);
+    return PYGLIB_PyLong_FromLong(status);
 }
 
 static PyObject*
@@ -337,19 +337,19 @@ py_io_channel_set_flags(PyGIOChannel* self, PyObject *args, PyObject *kwargs)
     if (pyglib_error_check(&error))
 	return NULL;
 	
-    return _PyLong_FromLong(status);
+    return PYGLIB_PyLong_FromLong(status);
 }
 
 static PyObject*
 py_io_channel_get_flags(PyGIOChannel* self)
 {
-    return _PyLong_FromLong(g_io_channel_get_flags(self->channel));
+    return PYGLIB_PyLong_FromLong(g_io_channel_get_flags(self->channel));
 }
 
 static PyObject*
 py_io_channel_get_buffer_condition(PyGIOChannel* self)
 {
-    return _PyLong_FromLong(g_io_channel_get_buffer_condition(self->channel));
+    return PYGLIB_PyLong_FromLong(g_io_channel_get_buffer_condition(self->channel));
 }
 
 static PyObject*
@@ -500,7 +500,7 @@ py_io_channel_win32_poll(PyObject *self, PyObject *args, PyObject *kwargs)
         pyfd = PyList_GET_ITEM(pyfds, i);
         ((PyGPollFD *) pyfd)->pollfd = pollfd[i];
     }
-    return _PyLong_FromLong(result);
+    return PYGLIB_PyLong_FromLong(result);
 }
 
 static PyObject *
@@ -544,7 +544,7 @@ py_io_channel_read_line(PyGIOChannel* self, PyObject *args, PyObject *kwargs)
                                     &terminator_pos, &error);
     if (pyglib_error_check(&error))
         return NULL;
-    ret_obj = _PyUnicode_FromStringAndSize(str_return, length);
+    ret_obj = PYGLIB_PyUnicode_FromStringAndSize(str_return, length);
     g_free(str_return);
     return ret_obj;
 }
@@ -573,7 +573,7 @@ py_io_channel_read_lines(PyGIOChannel* self, PyObject *args, PyObject *kwargs)
             Py_DECREF(line);
             return NULL;
         }
-        line = _PyUnicode_FromStringAndSize(str_return, length);
+        line = PYGLIB_PyUnicode_FromStringAndSize(str_return, length);
         g_free(str_return);
         if (PyList_Append(list, line)) {
             Py_DECREF(line);
@@ -614,7 +614,7 @@ py_io_channel_seek(PyGIOChannel* self, PyObject *args, PyObject *kwargs)
     if (pyglib_error_check(&error))
 	return NULL;
 	
-    return _PyLong_FromLong(status);
+    return PYGLIB_PyLong_FromLong(status);
 }
 
 #if 0 // Not wrapped
diff --git a/glib/pyglib-python-compat.h b/glib/pyglib-python-compat.h
index 915a912..8fc28e4 100644
--- a/glib/pyglib-python-compat.h
+++ b/glib/pyglib-python-compat.h
@@ -41,31 +41,105 @@ typedef int Py_ssize_t;
 typedef inquiry lenfunc;
 #endif
 
+#if PY_VERSION_HEX < 0x03000000
+
+#define PYGLIB_INIT_FUNCTION(modname, fullpkgname, functions) \
+static int _pyglib_init_##modname(PyObject *module); \
+void init##modname(void) \
+{ \
+    PyObject *module = Py_InitModule(fullpkgname, functions); \
+    _pyglib_init_##modname(module); \
+} \
+static int _pyglib_init_##modname(PyObject *module)
+
+#else
+
+#define PYGLIB_INIT_FUNCTION(modname, fullpkgname, functions) \
+static struct PyModuleDef _##modname##module = {     \
+    PyModuleDef_HEAD_INIT,                              \
+    fullpkgname,                                        \
+    NULL,                                               \
+    -1,                                                 \
+    functions,                                          \
+    NULL,                                               \
+    NULL,                                               \
+    NULL,                                               \
+    NULL                                                \
+};                                                      \
+static int _pyglib_init_##modname(PyObject *module); \
+PyObject *PyInit_##modname(void) \
+{ \
+    PyObject *module = PyModule_Create(&_##modname##module);  \
+    if (module == NULL) \
+	return NULL; \
+    if (_pyglib_init_##modname(module) != 0 ) {\
+	Py_DECREF(module); \
+	return NULL; \
+    } \
+    return module; \
+} \
+static int _pyglib_init_##modname(PyObject *module)
+
+#endif
+
 /* Compilation on Python 2.x */
 #if PY_VERSION_HEX < 0x03000000
 #define RO READONLY
-#define _PyUnicode_Check PyString_Check
-#define _PyUnicode_AsString PyString_AsString
-#define _PyUnicode_AsStringAndSize PyString_AsStringAndSize
-#define _PyUnicode_FromString PyString_FromString
-#define _PyUnicode_FromStringAndSize PyString_FromStringAndSize
-#define _PyUnicode_FromFormat PyString_FromFormat
-#define _PyUnicode_AS_STRING PyString_AS_STRING
-#define _PyUnicode_GET_SIZE PyString_GET_SIZE
-#define _PyUnicode_Resize _PyString_Resize
-#define _PyUnicode_Type PyString_Type
-#define _PyLong_Check PyInt_Check
-#define _PyLong_FromLong PyInt_FromLong
-#define _PyLong_AsLong  PyInt_AsLong
-#define _PyLongObject PyIntObject
-#define _PyLong_Type PyInt_Type
-#define _PyLong_AS_LONG PyInt_AS_LONG
+#define PYGLIB_PyUnicode_Check PyString_Check
+#define PYGLIB_PyUnicode_AsString PyString_AsString
+#define PYGLIB_PyUnicode_AsStringAndSize PyString_AsStringAndSize
+#define PYGLIB_PyUnicode_FromString PyString_FromString
+#define PYGLIB_PyUnicode_FromStringAndSize PyString_FromStringAndSize
+#define PYGLIB_PyUnicode_FromFormat PyString_FromFormat
+#define PYGLIB_PyUnicode_AS_STRING PyString_AS_STRING
+#define PYGLIB_PyUnicode_GET_SIZE PyString_GET_SIZE
+#define PYGLIB_PyUnicode_Type PyString_Type
+
+#define PYGLIB_PyBytes_FromStringAndSize PyString_FromStringAndSize
+#define PYGLIB_PyBytes_Resize _PyString_Resize
+#define PYGLIB_PyBytes_AsString PyString_AsString
+#define PYGLIB_PyBytes_Size PyString_Size
+#define PYGLIB_PyBytes_Check PyString_Check
+
+#define PYGLIB_PyLong_Check PyInt_Check
+#define PYGLIB_PyLong_FromLong PyInt_FromLong
+#define PYGLIB_PyLong_AsLong  PyInt_AsLong
+#define PYGLIB_PyLongObject PyIntObject
+#define PYGLIB_PyLong_Type PyInt_Type
+#define PYGLIB_PyLong_AS_LONG PyInt_AS_LONG
 #define Py_TYPE(ob) (((PyObject*)(ob))->ob_type)
+
+#ifndef PyVarObject_HEAD_INIT
+#define PyVarObject_HEAD_INIT(base, size) \
+  PyObject_HEAD_INIT(base) \
+  size,
+#endif
+
+#define PYGLIB_MODULE_START(symbol, modname)	        \
+DL_EXPORT(void) init##symbol(void)			\
+{                                                       \
+    PyObject *module;                                   \
+    module = Py_InitModule(modname, symbol##_functions);
+#define PYGLIB_MODULE_END }
+#define PYGLIB_DEFINE_TYPE(typename, symbol, csymbol)	\
+PyTypeObject symbol = {                                 \
+    PyObject_HEAD_INIT(NULL)                            \
+    0,                                                  \
+    typename,						\
+    sizeof(csymbol),                                    \
+    0,                                                  \
+};
+#define PYGLIB_REGISTER_TYPE(d, type, name)	        \
+    if (!type.tp_alloc)                                 \
+	type.tp_alloc = PyType_GenericAlloc;            \
+    if (!type.tp_new)                                   \
+	type.tp_new = PyType_GenericNew;                \
+    if (PyType_Ready(&type))                            \
+	return;                                         \
+    PyDict_SetItemString(d, name, (PyObject *)&type);
+
 #else
-#undef PYGLIB_MODULE_START
-#undef PYGLIB_MODULE_END
-#undef PYGLIB_DEFINE_TYPE
-#undef PYGLIB_REGISTER_TYPE
+
 
 #define PYGLIB_MODULE_START(symbol, modname)	        \
     static struct PyModuleDef _##symbol##module = {     \
@@ -99,22 +173,29 @@ PyTypeObject symbol = {                                 \
 	    return;                                         \
     PyDict_SetItemString(d, name, (PyObject *)&type);
 
-#define _PyUnicode_Check PyUnicode_Check
-#define _PyUnicode_AsString PyUnicode_AsString
-#define _PyUnicode_AsStringAndSize(obj, buf, size) PyUnicode_AsStringAndSize(obj, size)
-#define _PyUnicode_FromString PyUnicode_FromString
-#define _PyUnicode_FromStringAndSize PyUnicode_FromStringAndSize
-#define _PyUnicode_FromFormat PyUnicode_FromFormat
-#define _PyUnicode_AS_STRING _PyUnicode_AsString
-#define _PyUnicode_GET_SIZE PyUnicode_GET_SIZE
-#define _PyUnicode_Resize PyUnicode_Resize
-#define _PyUnicode_Type PyUnicode_Type
-#define _PyLong_Check PyLong_Check
-#define _PyLong_FromLong PyLong_FromLong
-#define _PyLong_AsLong PyLong_AsLong
-#define _PyLong_AS_LONG PyLong_AS_LONG
-#define _PyLongObject PyLongObject
-#define _PyLong_Type PyLong_Type
+#define PYGLIB_PyUnicode_Check PyUnicode_Check
+#define PYGLIB_PyUnicode_AsString _PyUnicode_AsString
+#define PYGLIB_PyUnicode_AsStringAndSize(obj, buf, size) \
+    (((*(buf) = _PyUnicode_AsStringAndSize(obj, size)) != NULL) ? 0 : -1) 
+#define PYGLIB_PyUnicode_FromString PyUnicode_FromString
+#define PYGLIB_PyUnicode_FromStringAndSize PyUnicode_FromStringAndSize
+#define PYGLIB_PyUnicode_FromFormat PyUnicode_FromFormat
+#define PYGLIB_PyUnicode_GET_SIZE PyUnicode_GET_SIZE
+#define PYGLIB_PyUnicode_Resize PyUnicode_Resize
+#define PYGLIB_PyUnicode_Type PyUnicode_Type
+#define PYGLIB_PyLong_Check PyLong_Check
+#define PYGLIB_PyLong_FromLong PyLong_FromLong
+#define PYGLIB_PyLong_AsLong PyLong_AsLong
+#define PYGLIB_PyLong_AS_LONG(o) PyLong_AS_LONG((PyObject*)(o))
+#define PYGLIB_PyLongObject PyLongObject
+#define PYGLIB_PyLong_Type PyLong_Type
+
+#define PYGLIB_PyBytes_FromStringAndSize PyBytes_FromStringAndSize
+#define PYGLIB_PyBytes_Resize(o, len) _PyBytes_Resize(o, len)
+#define PYGLIB_PyBytes_AsString PyBytes_AsString
+#define PYGLIB_PyBytes_Size PyBytes_Size
+#define PYGLIB_PyBytes_Check PyBytes_Check
+
 #endif
 
 #endif /* __PYGLIB_PYTHON_COMPAT_H__ */
diff --git a/glib/pyglib.c b/glib/pyglib.c
index ffaae7a..76eb549 100644
--- a/glib/pyglib.c
+++ b/glib/pyglib.c
@@ -61,7 +61,7 @@ pyglib_init(void)
 	    Py_XDECREF(traceback);
 	    PyErr_Format(PyExc_ImportError,
 			 "could not import glib (error was: %s)",
-			 _PyUnicode_AsString(py_orig_exc));
+			 PYGLIB_PyUnicode_AsString(py_orig_exc));
 	    Py_DECREF(py_orig_exc);
         } else {
 	    PyErr_SetString(PyExc_ImportError,
@@ -264,7 +264,7 @@ pyglib_error_check(GError **error)
     if (exception_table != NULL)
     {
 	PyObject *item;
-	item = PyDict_GetItem(exception_table, _PyLong_FromLong((*error)->domain));
+	item = PyDict_GetItem(exception_table, PYGLIB_PyLong_FromLong((*error)->domain));
 	if (item != NULL)
 	    exc_type = item;
     }
@@ -273,19 +273,19 @@ pyglib_error_check(GError **error)
 
     if ((*error)->domain) {
 	PyObject_SetAttrString(exc_instance, "domain",
-			       d=_PyUnicode_FromString(g_quark_to_string((*error)->domain)));
+			       d=PYGLIB_PyUnicode_FromString(g_quark_to_string((*error)->domain)));
 	Py_DECREF(d);
     }
     else
 	PyObject_SetAttrString(exc_instance, "domain", Py_None);
 
     PyObject_SetAttrString(exc_instance, "code",
-			   d=_PyLong_FromLong((*error)->code));
+			   d=PYGLIB_PyLong_FromLong((*error)->code));
     Py_DECREF(d);
 
     if ((*error)->message) {
 	PyObject_SetAttrString(exc_instance, "message",
-			       d=_PyUnicode_FromString((*error)->message));
+			       d=PYGLIB_PyUnicode_FromString((*error)->message));
 	Py_DECREF(d);
     } else {
 	PyObject_SetAttrString(exc_instance, "message", Py_None);
@@ -338,28 +338,28 @@ pyglib_gerror_exception_check(GError **error)
     Py_XDECREF(traceback);
 
     py_message = PyObject_GetAttrString(value, "message");
-    if (!py_message || !_PyUnicode_Check(py_message)) {
+    if (!py_message || !PYGLIB_PyUnicode_Check(py_message)) {
         bad_gerror_message = "glib.GError instances must have a 'message' string attribute";
         goto bad_gerror;
     }
 
     py_domain = PyObject_GetAttrString(value, "domain");
-    if (!py_domain || !_PyUnicode_Check(py_domain)) {
+    if (!py_domain || !PYGLIB_PyUnicode_Check(py_domain)) {
         bad_gerror_message = "glib.GError instances must have a 'domain' string attribute";
         Py_DECREF(py_message);
         goto bad_gerror;
     }
 
     py_code = PyObject_GetAttrString(value, "code");
-    if (!py_code || !_PyLong_Check(py_code)) {
+    if (!py_code || !PYGLIB_PyLong_Check(py_code)) {
         bad_gerror_message = "glib.GError instances must have a 'code' int attribute";
         Py_DECREF(py_message);
         Py_DECREF(py_domain);
         goto bad_gerror;
     }
 
-    g_set_error(error, g_quark_from_string(_PyUnicode_AsString(py_domain)),
-                _PyLong_AsLong(py_code), "%s", _PyUnicode_AsString(py_message));
+    g_set_error(error, g_quark_from_string(PYGLIB_PyUnicode_AsString(py_domain)),
+                PYGLIB_PyLong_AsLong(py_code), PYGLIB_PyUnicode_AsString(py_message));
 
     Py_DECREF(py_message);
     Py_DECREF(py_code);
@@ -397,7 +397,7 @@ pyglib_register_exception_for_domain(gchar *name,
 	exception_table = PyDict_New();
 
     PyDict_SetItem(exception_table,
-		   _PyLong_FromLong(error_domain),
+		   PYGLIB_PyLong_FromLong(error_domain),
 		   exception);
     
     return exception;
diff --git a/glib/pyglib.h b/glib/pyglib.h
index d72b179..44ead47 100644
--- a/glib/pyglib.h
+++ b/glib/pyglib.h
@@ -67,20 +67,6 @@ PyObject* _pyglib_generic_long_richcompare(long a, long b, int op);
             PyEval_RestoreThread(_save);        \
     } G_STMT_END
 
-#define PYGLIB_MODULE_START(symbol, modname)	        \
-DL_EXPORT(void) init##symbol(void)			\
-{                                                       \
-    PyObject *module;                                   \
-    module = Py_InitModule(modname, symbol##_functions);
-#define PYGLIB_MODULE_END }
-#define PYGLIB_DEFINE_TYPE(typename, symbol, csymbol)	\
-PyTypeObject symbol = {                                 \
-    PyObject_HEAD_INIT(NULL)                            \
-    0,                                                  \
-    typename,						\
-    sizeof(csymbol),                                    \
-    0,                                                  \
-};
 #define PYGLIB_REGISTER_TYPE(d, type, name)	        \
     if (!type.tp_alloc)                                 \
 	type.tp_alloc = PyType_GenericAlloc;            \
diff --git a/glib/pygoptioncontext.c b/glib/pygoptioncontext.c
index b93026b..1d67ac5 100644
--- a/glib/pygoptioncontext.c
+++ b/glib/pygoptioncontext.c
@@ -98,7 +98,7 @@ pyg_option_context_parse(PyGOptionContext *self,
     for (pos = 0; pos < argv_length; pos++)
     {
         arg = PyList_GetItem(argv, pos);
-        argv_content[pos] = g_strdup(_PyUnicode_AsString(arg));
+        argv_content[pos] = g_strdup(PYGLIB_PyUnicode_AsString(arg));
         if (argv_content[pos] == NULL)
         {
             g_strfreev(argv_content);
@@ -126,7 +126,7 @@ pyg_option_context_parse(PyGOptionContext *self,
     new_argv = PyList_New(g_strv_length(argv_content));
     for (pos = 0; pos < argv_length; pos++)
     {
-        arg = _PyUnicode_FromString(argv_content[pos]);
+        arg = PYGLIB_PyUnicode_FromString(argv_content[pos]);
         PyList_SetItem(new_argv, pos, arg);
     }
 
diff --git a/glib/pygsource.c b/glib/pygsource.c
index 298b928..b0b87b3 100644
--- a/glib/pygsource.c
+++ b/glib/pygsource.c
@@ -82,7 +82,7 @@ source_repr(PyGSource *self, const char *type)
 	g_snprintf(buf, sizeof(buf), "<%s glib source at 0x%lx>",
 		   desc, (long) self);
 
-    return _PyUnicode_FromString(buf);
+    return PYGLIB_PyUnicode_FromString(buf);
 }
 
 static PyObject *
@@ -109,7 +109,7 @@ pyg_source_attach(PyGSource *self, PyObject *args, PyObject *kwargs)
     }
 
     id = g_source_attach(self->source, context);
-    return _PyLong_FromLong(id);
+    return PYGLIB_PyLong_FromLong(id);
 }
 
 static PyObject *
@@ -283,7 +283,7 @@ pyg_source_get_priority(PyGSource *self, void *closure)
 {
     CHECK_DESTROYED(self, NULL);
 
-    return _PyLong_FromLong(g_source_get_priority(self->source));
+    return PYGLIB_PyLong_FromLong(g_source_get_priority(self->source));
 }
 
 static int
@@ -296,12 +296,12 @@ pyg_source_set_priority(PyGSource *self, PyObject *value, void *closure)
 	return -1;
     }
 
-    if (!_PyLong_Check(value)) {
+    if (!PYGLIB_PyLong_Check(value)) {
 	PyErr_SetString(PyExc_TypeError, "type mismatch");
 	return -1;
     }
 
-    g_source_set_priority(self->source, _PyLong_AsLong(value));
+    g_source_set_priority(self->source, PYGLIB_PyLong_AsLong(value));
 
     return 0;
 }
@@ -339,7 +339,7 @@ pyg_source_get_id(PyGSource *self, void *closure)
 	return NULL;
     }
 
-    return _PyLong_FromLong(g_source_get_id(self->source));
+    return PYGLIB_PyLong_FromLong(g_source_get_id(self->source));
 }
 
 static PyGetSetDef pyg_source_getsets[] = {
@@ -426,7 +426,7 @@ pyg_source_prepare(GSource *source, gint *timeout)
     }
 
     ret = PyObject_IsTrue(PyTuple_GET_ITEM(t, 0));
-	*timeout = _PyLong_AsLong(PyTuple_GET_ITEM(t, 1));
+	*timeout = PYGLIB_PyLong_AsLong(PyTuple_GET_ITEM(t, 1));
 
 	if (*timeout == -1 && PyErr_Occurred()) {
 	    ret = FALSE;
@@ -652,7 +652,7 @@ pyg_poll_fd_dealloc(PyGPollFD *self)
 static PyObject *
 pyg_poll_fd_repr(PyGPollFD *self)
 {
-    return _PyUnicode_FromFormat("<GPollFD %d (%d) at 0x%lx>",
+    return PYGLIB_PyUnicode_FromFormat("<GPollFD %d (%d) at 0x%lx>",
 				 self->pollfd.fd, self->pollfd.events,
 				 (long)self);
 }
diff --git a/glib/pygspawn.c b/glib/pygspawn.c
index cded501..f849d5b 100644
--- a/glib/pygspawn.c
+++ b/glib/pygspawn.c
@@ -32,12 +32,12 @@ struct _PyGChildSetupData {
     PyObject *data;
 };
 
-PYGLIB_DEFINE_TYPE("glib.Pid", PyGPid_Type, _PyLongObject)
+PYGLIB_DEFINE_TYPE("glib.Pid", PyGPid_Type, PYGLIB_PyLongObject)
 
 static PyObject *
 pyg_pid_close(PyObject *self, PyObject *args, PyObject *kwargs)
 {
-    g_spawn_close_pid(_PyLong_AsLong(self));
+    g_spawn_close_pid(PYGLIB_PyLong_AsLong(self));
     Py_INCREF(Py_None);
     return Py_None;
 }
@@ -50,8 +50,8 @@ static PyMethodDef pyg_pid_methods[] = {
 static void
 pyg_pid_free(PyObject *gpid)
 {
-    g_spawn_close_pid((GPid) _PyLong_AsLong(gpid));
-    _PyLong_Type.tp_free((void *) gpid);
+    g_spawn_close_pid((GPid) PYGLIB_PyLong_AsLong(gpid));
+    PYGLIB_PyLong_Type.tp_free((void *) gpid);
 }
 
 static int
@@ -64,14 +64,14 @@ pyg_pid_tp_init(PyObject *self, PyObject *args, PyObject *kwargs)
 PyObject *
 pyg_pid_new(GPid pid)
 {
-    _PyLongObject *pygpid;
-    pygpid = PyObject_NEW(_PyLongObject, &PyGPid_Type);
+	PYGLIB_PyLongObject *pygpid;
+    pygpid = PyObject_NEW(PYGLIB_PyLongObject, &PyGPid_Type);
 
 #if PY_VERSION_HEX >= 0x03000000
-#   warning "FIXME: figure out how to subclass long"    
+#   warning "FIXME: figure out how to subclass long"
 #else
     pygpid->ob_ival = pid;
-#endif    
+#endif
     return (PyObject *) pygpid;
 }
 
@@ -149,7 +149,7 @@ pyglib_spawn_async(PyObject *object, PyObject *args, PyObject *kwargs)
     argv = g_new0(char *, len + 1);
     for (i = 0; i < len; ++i) {
         PyObject *tmp = PySequence_ITEM(pyargv, i);
-        if (!_PyUnicode_Check(tmp)) {
+        if (!PYGLIB_PyUnicode_Check(tmp)) {
             PyErr_SetString(PyExc_TypeError,
                             "glib.spawn_async: "
 			    "first argument must be a sequence of strings");
@@ -157,7 +157,7 @@ pyglib_spawn_async(PyObject *object, PyObject *args, PyObject *kwargs)
             Py_XDECREF(tmp);
             return NULL;
         }
-        argv[i] = _PyUnicode_AsString(tmp);
+        argv[i] = PYGLIB_PyUnicode_AsString(tmp);
         Py_DECREF(tmp);
     }
 
@@ -174,7 +174,7 @@ pyglib_spawn_async(PyObject *object, PyObject *args, PyObject *kwargs)
         envp = g_new0(char *, len + 1);
         for (i = 0; i < len; ++i) {
             PyObject *tmp = PySequence_ITEM(pyenvp, i);
-            if (!_PyUnicode_Check(tmp)) {
+            if (!PYGLIB_PyUnicode_Check(tmp)) {
                 PyErr_SetString(PyExc_TypeError,
                                 "glib.spawn_async: "
 				"second argument must be a sequence of strings");
@@ -183,7 +183,7 @@ pyglib_spawn_async(PyObject *object, PyObject *args, PyObject *kwargs)
 		g_free(argv);
                 return NULL;
             }
-            envp[i] = _PyUnicode_AsString(tmp);
+            envp[i] = PYGLIB_PyUnicode_AsString(tmp);
             Py_DECREF(tmp);
         }
     }
@@ -228,21 +228,21 @@ pyglib_spawn_async(PyObject *object, PyObject *args, PyObject *kwargs)
     if (envp) g_free(envp);
 
     if (standard_input)
-        pystdin = _PyLong_FromLong(*standard_input);
+        pystdin = PYGLIB_PyLong_FromLong(*standard_input);
     else {
         Py_INCREF(Py_None);
         pystdin = Py_None;
     }
 
     if (standard_output)
-        pystdout = _PyLong_FromLong(*standard_output);
+        pystdout = PYGLIB_PyLong_FromLong(*standard_output);
     else {
         Py_INCREF(Py_None);
         pystdout = Py_None;
     }
 
     if (standard_error)
-        pystderr = _PyLong_FromLong(*standard_error);
+        pystderr = PYGLIB_PyLong_FromLong(*standard_error);
     else {
         Py_INCREF(Py_None);
         pystderr = Py_None;
@@ -254,7 +254,7 @@ pyglib_spawn_async(PyObject *object, PyObject *args, PyObject *kwargs)
 void
 pyglib_spawn_register_types(PyObject *d)
 {
-    PyGPid_Type.tp_base = &_PyLong_Type;
+    PyGPid_Type.tp_base = &PYGLIB_PyLong_Type;
     PyGPid_Type.tp_flags = Py_TPFLAGS_DEFAULT;
     PyGPid_Type.tp_methods = pyg_pid_methods;
     PyGPid_Type.tp_init = pyg_pid_tp_init;
diff --git a/gobject/gobjectmodule.c b/gobject/gobjectmodule.c
index 09244b8..05a71d9 100644
--- a/gobject/gobjectmodule.c
+++ b/gobject/gobjectmodule.c
@@ -50,7 +50,7 @@ static gboolean log_handlers_disabled = FALSE;
 static void pyg_flags_add_constants(PyObject *module, GType flags_type,
 				    const gchar *strip_prefix);
 
-    
+
 /* -------------- GDK threading hooks ---------------------------- */
 
 /**
@@ -109,14 +109,14 @@ pyg_type_name (PyObject *self, PyObject *args)
 		   "use GType.name instead"))
         return NULL;
 #endif
-    
+
     if (!PyArg_ParseTuple(args, "O:gobject.type_name", &gtype))
 	return NULL;
     if ((type = pyg_type_from_object(gtype)) == 0)
 	return NULL;
     name = g_type_name(type);
     if (name)
-	return _PyUnicode_FromString(name);
+	return PYGLIB_PyUnicode_FromString(name);
     PyErr_SetString(PyExc_RuntimeError, "unknown typecode");
     return NULL;
 }
@@ -131,14 +131,14 @@ pyg_type_from_name (PyObject *self, PyObject *args)
 		   "gobject.type_from_name is deprecated; "
 		   "use GType.from_name instead"))
         return NULL;
-#endif    
+#endif
     if (!PyArg_ParseTuple(args, "s:gobject.type_from_name", &name))
 	return NULL;
     type = _pyg_type_from_name(name);
     if (type != 0)
 	return pyg_type_wrapper_new(type);
     PyErr_Format(PyExc_RuntimeError, "%s: unknown type name: %s",
-		 _PyUnicode_AsString(PyObject_Repr((PyObject*)self)),
+         PYGLIB_PyUnicode_AsString(PyObject_Repr((PyObject*)self)),
 		 name);
     return NULL;
 }
@@ -153,7 +153,7 @@ pyg_type_parent (PyObject *self, PyObject *args)
 		   "gobject.type_parent is deprecated; "
 		   "use GType.parent instead"))
         return NULL;
-#endif    
+#endif
     if (!PyArg_ParseTuple(args, "O:gobject.type_parent", &gtype))
 	return NULL;
     if ((type = pyg_type_from_object(gtype)) == 0)
@@ -175,7 +175,7 @@ pyg_type_is_a (PyObject *self, PyObject *args)
 		   "gobject.type_is_a is deprecated; "
 		   "use GType.is_a instead"))
         return NULL;
-#endif    
+#endif
     if (!PyArg_ParseTuple(args, "OO:gobject.type_is_a", &gtype, &gparent))
 	return NULL;
     if ((type = pyg_type_from_object(gtype)) == 0)
@@ -196,7 +196,7 @@ pyg_type_children (PyObject *self, PyObject *args)
 		   "gobject.type_children is deprecated; "
 		   "use GType.children instead"))
         return NULL;
-#endif    
+#endif
     if (!PyArg_ParseTuple(args, "O:gobject.type_children", &gtype))
 	return NULL;
     if ((type = pyg_type_from_object(gtype)) == 0)
@@ -227,7 +227,7 @@ pyg_type_interfaces (PyObject *self, PyObject *args)
 		   "gobject.type_interfaces is deprecated; "
 		   "use GType.interfaces instead"))
         return NULL;
-#endif    
+#endif
     if (!PyArg_ParseTuple(args, "O:gobject.type_interfaces", &gtype))
 	return NULL;
     if ((type = pyg_type_from_object(gtype)) == 0)
@@ -308,7 +308,7 @@ pyg_object_get_property (GObject *object, guint property_id,
     Py_DECREF(object_wrapper);
     Py_DECREF(py_pspec);
     Py_XDECREF(retval);
-    
+
     pyglib_gil_state_release(state);
 }
 
@@ -338,7 +338,7 @@ _pyg_signal_accumulator(GSignalInvocationHint *ihint,
 
     state = pyglib_gil_state_ensure();
     if (ihint->detail)
-        py_detail = _PyUnicode_FromString(g_quark_to_string(ihint->detail));
+        py_detail = PYGLIB_PyUnicode_FromString(g_quark_to_string(ihint->detail));
     else {
         Py_INCREF(Py_None);
         py_detail = Py_None;
@@ -497,17 +497,17 @@ add_signals (GType instance_type, PyObject *signals)
 	const gchar *signal_name;
         gchar *signal_name_canon, *c;
 
-	if (!_PyUnicode_Check(key)) {
+	if (!PYGLIB_PyUnicode_Check(key)) {
 	    PyErr_SetString(PyExc_TypeError,
 			    "__gsignals__ keys must be strings");
 	    ret = FALSE;
 	    break;
 	}
-	signal_name = _PyUnicode_AsString (key);
+	signal_name = PYGLIB_PyUnicode_AsString (key);
 
 	if (value == Py_None ||
-	    (_PyUnicode_Check(value) &&
-	     !strcmp(_PyUnicode_AsString(value), "override")))
+	    (PYGLIB_PyUnicode_Check(value) &&
+	     !strcmp(PYGLIB_PyUnicode_AsString(value), "override")))
         {
               /* canonicalize signal name, replacing '-' with '_' */
             signal_name_canon = g_strdup(signal_name);
@@ -652,14 +652,14 @@ create_property (const gchar  *prop_name,
 	{
 	    gint default_value;
 	    PyObject *pydefault;
-	    
+
 	    if (!PyArg_ParseTuple(args, "O", &pydefault))
 		return NULL;
-	    
+
 	    if (pyg_enum_get_value(prop_type, pydefault,
 				   (gint *)&default_value))
 		return NULL;
-	    
+
 	    pspec = g_param_spec_enum (prop_name, nick, blurb,
 				       prop_type, default_value, flags);
 	}
@@ -671,11 +671,11 @@ create_property (const gchar  *prop_name,
 
 	    if (!PyArg_ParseTuple(args, "O", &pydefault))
 		return NULL;
-	    
+
 	    if (pyg_flags_get_value(prop_type, pydefault,
 				    (gint *)&default_value))
 		return NULL;
-	    
+
 	    pspec = g_param_spec_flags (prop_name, nick, blurb,
 					prop_type, default_value, flags);
 	}
@@ -745,7 +745,7 @@ create_property (const gchar  *prop_name,
 	PyErr_SetString(PyExc_TypeError, buf);
 	return NULL;
     }
-    
+
     return pspec;
 }
 
@@ -764,27 +764,27 @@ pyg_param_spec_from_object (PyObject *tuple)
 	PyErr_SetString(PyExc_TypeError,
 			"paramspec tuples must be at least 4 elements long");
 	return NULL;
-    }	    
+    }
 
     slice = PySequence_GetSlice(tuple, 0, 4);
     if (!slice) {
 	return NULL;
     }
-    
+
     if (!PyArg_ParseTuple(slice, "sOzz", &prop_name, &py_prop_type, &nick, &blurb)) {
 	Py_DECREF(slice);
 	return NULL;
     }
-    
+
     Py_DECREF(slice);
-    
+
     prop_type = pyg_type_from_object(py_prop_type);
     if (!prop_type) {
 	return NULL;
     }
-    
+
     item = PyTuple_GetItem(tuple, val_length-1);
-    if (!_PyLong_Check(item)) {
+    if (!PYGLIB_PyLong_Check(item)) {
 	PyErr_SetString(PyExc_TypeError,
 			"last element in tuple must be an int");
 	return NULL;
@@ -794,7 +794,7 @@ pyg_param_spec_from_object (PyObject *tuple)
     slice = PySequence_GetSlice(tuple, 4, val_length-1);
     pspec = create_property(prop_name, prop_type,
 			    nick, blurb, slice,
-			    _PyLong_AsLong(item));
+			    PYGLIB_PyLong_AsLong(item));
 
     return pspec;
 }
@@ -816,16 +816,16 @@ add_properties (GType instance_type, PyObject *properties)
 	gint val_length;
 	PyObject *slice, *item, *py_prop_type;
 	GParamSpec *pspec;
-	
+
 	/* values are of format (type,nick,blurb, type_specific_args, flags) */
-	
-	if (!_PyUnicode_Check(key)) {
+
+	if (!PYGLIB_PyUnicode_Check(key)) {
 	    PyErr_SetString(PyExc_TypeError,
 			    "__gproperties__ keys must be strings");
 	    ret = FALSE;
 	    break;
 	}
-	prop_name = _PyUnicode_AsString (key);
+	prop_name = PYGLIB_PyUnicode_AsString (key);
 
 	if (!PyTuple_Check(value)) {
 	    PyErr_SetString(PyExc_TypeError,
@@ -839,7 +839,7 @@ add_properties (GType instance_type, PyObject *properties)
 			    "__gproperties__ values must be at least 4 elements long");
 	    ret = FALSE;
 	    break;
-	}	    
+	}
 
 	slice = PySequence_GetSlice(value, 0, 3);
 	if (!slice) {
@@ -858,40 +858,40 @@ add_properties (GType instance_type, PyObject *properties)
 	    break;
 	}
 	item = PyTuple_GetItem(value, val_length-1);
-	if (!_PyLong_Check(item)) {
+	if (!PYGLIB_PyLong_Check(item)) {
 	    PyErr_SetString(PyExc_TypeError,
 		"last element in __gproperties__ value tuple must be an int");
 	    ret = FALSE;
 	    break;
 	}
-	flags = _PyLong_AsLong(item);
+	flags = PYGLIB_PyLong_AsLong(item);
 
 	/* slice is the extra items in the tuple */
 	slice = PySequence_GetSlice(value, 3, val_length-1);
 	pspec = create_property(prop_name, prop_type, nick, blurb,
 				slice, flags);
 	Py_DECREF(slice);
-	
+
 	if (pspec) {
 	    g_object_class_install_property(oclass, 1, pspec);
 	} else {
             PyObject *type, *value, *traceback;
 	    ret = FALSE;
             PyErr_Fetch(&type, &value, &traceback);
-            if (_PyUnicode_Check(value)) {
+            if (PYGLIB_PyUnicode_Check(value)) {
                 char msg[256];
                 g_snprintf(msg, 256,
 			   "%s (while registering property '%s' for GType '%s')",
-                           _PyUnicode_AsString(value),
+               PYGLIB_PyUnicode_AsString(value),
 			   prop_name, g_type_name(instance_type));
                 Py_DECREF(value);
-                value = _PyUnicode_FromString(msg);
+                value = PYGLIB_PyUnicode_FromString(msg);
             }
             PyErr_Restore(type, value, traceback);
 	    break;
 	}
     }
-    
+
     g_type_class_unref(oclass);
     return ret;
 }
@@ -920,7 +920,7 @@ pyg_run_class_init(GType gtype, gpointer gclass, PyTypeObject *pyclass)
         if (rv)
 	    return rv;
     }
-    
+
     list = g_type_get_qdata(gtype, pygobject_class_init_key);
     for (; list; list = list->next) {
 	class_init = list->data;
@@ -928,7 +928,7 @@ pyg_run_class_init(GType gtype, gpointer gclass, PyTypeObject *pyclass)
         if (rv)
 	    return rv;
     }
-    
+
     return 0;
 }
 
@@ -954,7 +954,7 @@ _wrap_pyg_type_register(PyObject *self, PyObject *args)
         if (pyg_type_register(class, type_name))
             return NULL;
     }
- 
+
     Py_INCREF(class);
     return (PyObject *) class;
 }
@@ -966,17 +966,17 @@ get_type_name_for_class(PyTypeObject *class)
     char name_serial_str[16];
     PyObject *module;
     char *type_name = NULL;
-    
+
     /* make name for new GType */
     name_serial = 1;
     /* give up after 1000 tries, just in case.. */
-    while (name_serial < 1000) 
+    while (name_serial < 1000)
     {
 	g_free(type_name);
 	snprintf(name_serial_str, 16, "-v%i", name_serial);
 	module = PyObject_GetAttrString((PyObject *)class, "__module__");
-	if (module && _PyUnicode_Check(module)) {
-	    type_name = g_strconcat(_PyUnicode_AsString(module), ".",
+	if (module && PYGLIB_PyUnicode_Check(module)) {
+	    type_name = g_strconcat(PYGLIB_PyUnicode_AsString(module), ".",
 				    class->tp_name,
 				    name_serial > 1 ? name_serial_str : NULL,
 				    NULL);
@@ -1028,7 +1028,7 @@ pygobject__g_instance_init(GTypeInstance   *instance,
 			  pygobject_has_updated_constructor_key))
         return;
 
-    wrapper = g_object_get_qdata(object, pygobject_wrapper_key); 
+    wrapper = g_object_get_qdata(object, pygobject_wrapper_key);
     if (wrapper == NULL) {
         wrapper = pygobject_init_wrapper_get();
         if (wrapper && ((PyGObject *) wrapper)->obj == NULL) {
@@ -1160,10 +1160,10 @@ pyg_type_register(PyTypeObject *class, const char *type_name)
 
     if (type_name)
 	/* care is taken below not to free this */
-        new_type_name = (gchar *) type_name; 
+        new_type_name = (gchar *) type_name;
     else
 	new_type_name = get_type_name_for_class(class);
-    
+
     /* set class_data that will be passed to the class_init function. */
     type_info.class_data = class;
 
@@ -1334,7 +1334,7 @@ pyg_signal_new(PyObject *self, PyObject *args)
 			"argument 2 must be an object type or interface type");
 	return NULL;
     }
-    
+
     return_type = pyg_type_from_object(py_return_type);
     if (!return_type)
 	return NULL;
@@ -1368,7 +1368,7 @@ pyg_signal_new(PyObject *self, PyObject *args)
 			      return_type, n_params, param_types);
     g_free(param_types);
     if (signal_id != 0)
-	return _PyLong_FromLong(signal_id);
+	return PYGLIB_PyLong_FromLong(signal_id);
     PyErr_SetString(PyExc_RuntimeError, "could not create signal");
     return NULL;
 }
@@ -1406,16 +1406,16 @@ pyg_signal_list_names (PyObject *self, PyObject *args, PyObject *kwargs)
     } else {
         iface = g_type_default_interface_ref(itype);
     }
-    
+
     ids = g_signal_list_ids(itype, &n);
 
     list = PyTuple_New((gint)n);
     if (list != NULL) {
 	for (i = 0; i < n; i++)
 	    PyTuple_SetItem(list, i,
-			    _PyUnicode_FromString(g_signal_name(ids[i])));
+	    		PYGLIB_PyUnicode_FromString(g_signal_name(ids[i])));
     }
-    
+
     g_free(ids);
     if (class)
         g_type_class_unref(class);
@@ -1458,7 +1458,7 @@ pyg_signal_list_ids (PyObject *self, PyObject *args, PyObject *kwargs)
     } else {
         iface = g_type_default_interface_ref(itype);
     }
-    
+
     ids = g_signal_list_ids(itype, &n);
 
     list = PyTuple_New((gint)n);
@@ -1469,7 +1469,7 @@ pyg_signal_list_ids (PyObject *self, PyObject *args, PyObject *kwargs)
     }
 
     for (i = 0; i < n; i++)
-	PyTuple_SetItem(list, i, _PyLong_FromLong(ids[i]));
+	PyTuple_SetItem(list, i, PYGLIB_PyLong_FromLong(ids[i]));
     g_free(ids);
     if (class)
         g_type_class_unref(class);
@@ -1510,14 +1510,14 @@ pyg_signal_lookup (PyObject *self, PyObject *args, PyObject *kwargs)
     } else {
         iface = g_type_default_interface_ref(itype);
     }
-    
+
     id = g_signal_lookup(signal_name, itype);
 
     if (class)
         g_type_class_unref(class);
     else
        g_type_default_interface_unref(iface);
-    return _PyLong_FromLong(id);
+    return PYGLIB_PyLong_FromLong(id);
 }
 
 static PyObject *
@@ -1532,7 +1532,7 @@ pyg_signal_name (PyObject *self, PyObject *args, PyObject *kwargs)
 	return NULL;
     signal_name = g_signal_name(id);
     if (signal_name)
-        return _PyUnicode_FromString(signal_name);
+        return PYGLIB_PyUnicode_FromString(signal_name);
 
     Py_INCREF(Py_None);
     return Py_None;
@@ -1582,7 +1582,7 @@ pyg_signal_query (PyObject *self, PyObject *args, PyObject *kwargs)
                             "Usage: one of:\n"
                             "  gobject.signal_query(name, type)\n"
                             "  gobject.signal_query(signal_id)");
-             
+
 	return NULL;
         }
     }
@@ -1605,10 +1605,10 @@ pyg_signal_query (PyObject *self, PyObject *args, PyObject *kwargs)
         goto done;
     }
 
-    PyTuple_SET_ITEM(py_query, 0, _PyLong_FromLong(query.signal_id));
-    PyTuple_SET_ITEM(py_query, 1, _PyUnicode_FromString(query.signal_name));
+    PyTuple_SET_ITEM(py_query, 0, PYGLIB_PyLong_FromLong(query.signal_id));
+    PyTuple_SET_ITEM(py_query, 1, PYGLIB_PyUnicode_FromString(query.signal_name));
     PyTuple_SET_ITEM(py_query, 2, pyg_type_wrapper_new(query.itype));
-    PyTuple_SET_ITEM(py_query, 3, _PyLong_FromLong(query.signal_flags));
+    PyTuple_SET_ITEM(py_query, 3, PYGLIB_PyLong_FromLong(query.signal_flags));
     PyTuple_SET_ITEM(py_query, 4, pyg_type_wrapper_new(query.return_type));
     for (i = 0; i < query.n_params; i++) {
         PyTuple_SET_ITEM(params_list, i,
@@ -1663,7 +1663,7 @@ pyg_object_class_list_properties (PyObject *self, PyObject *args)
                         "type must be derived from GObject or an interface");
 	return NULL;
     }
-        
+
     list = PyTuple_New(nprops);
     if (list == NULL) {
 	g_free(specs);
@@ -1719,7 +1719,7 @@ pyg_object_new (PyGObject *self, PyObject *args, PyObject *kwargs)
 	params = g_new0(GParameter, PyDict_Size(kwargs));
 	while (PyDict_Next (kwargs, &pos, &key, &value)) {
 	    GParamSpec *pspec;
-	    const gchar *key_str = _PyUnicode_AsString (key);
+	    const gchar *key_str = PYGLIB_PyUnicode_AsString (key);
 
 	    pspec = g_object_class_find_property (class, key_str);
 	    if (!pspec) {
@@ -1754,7 +1754,7 @@ pyg_object_new (PyGObject *self, PyObject *args, PyObject *kwargs)
     }
     g_free(params);
     g_type_class_unref(class);
-    
+
     if (obj) {
 	self = (PyGObject *) pygobject_new_full((GObject *)obj, FALSE, NULL);
         g_object_unref(obj);
@@ -1785,7 +1785,7 @@ pyg_handler_marshal(gpointer user_data)
 	res = PyObject_IsTrue(ret);
 	Py_DECREF(ret);
     }
-    
+
     pyglib_gil_state_release(state);
 
     return res;
@@ -1808,7 +1808,7 @@ pyg_threads_init (PyObject *unused, PyObject *args, PyObject *kwargs)
 {
     if (!pyglib_enable_threads())
         return NULL;
-    
+
     Py_INCREF(Py_None);
     return Py_None;
 }
@@ -1857,7 +1857,7 @@ marshal_emission_hook(GSignalInvocationHint *ihint,
 
     for (i = 0; i < n_param_values; i++) {
 	PyObject *item = pyg_value_as_pyobject(&param_values[i], FALSE);
-	
+
 	/* error condition */
 	if (!item) {
 	    goto out;
@@ -1877,7 +1877,7 @@ marshal_emission_hook(GSignalInvocationHint *ihint,
     if (retobj == NULL) {
         PyErr_Print();
     }
-    
+
     retval = (retobj == Py_True ? TRUE : FALSE);
     Py_XDECREF(retobj);
 out:
@@ -1910,7 +1910,7 @@ pyg_add_emission_hook(PyGObject *self, PyObject *args)
 	return NULL;
     }
     Py_DECREF(first);
-    
+
     if ((gtype = pyg_type_from_object(pygtype)) == 0) {
 	return NULL;
     }
@@ -1921,7 +1921,7 @@ pyg_add_emission_hook(PyGObject *self, PyObject *args)
 
     if (!g_signal_parse_name(name, gtype, &sigid, &detail, TRUE)) {
 	PyErr_Format(PyExc_TypeError, "%s: unknown signal name: %s",
-		     _PyUnicode_AsString(PyObject_Repr((PyObject*)self)),
+			PYGLIB_PyUnicode_AsString(PyObject_Repr((PyObject*)self)),
 		     name);
 	return NULL;
     }
@@ -1932,12 +1932,12 @@ pyg_add_emission_hook(PyGObject *self, PyObject *args)
     data = Py_BuildValue("(ON)", callback, extra_args);
     if (data == NULL)
       return NULL;
-    
+
     hook_id = g_signal_add_emission_hook(sigid, detail,
 					 marshal_emission_hook,
 					 data,
 					 (GDestroyNotify)pyg_destroy_notify);
-        
+
     return PyLong_FromUnsignedLong(hook_id);
 }
 
@@ -1949,24 +1949,24 @@ pyg_remove_emission_hook(PyGObject *self, PyObject *args)
     guint signal_id;
     gulong hook_id;
     GType gtype;
-    
+
     if (!PyArg_ParseTuple(args, "Osk:gobject.remove_emission_hook",
 			  &pygtype, &name, &hook_id))
 	return NULL;
-    
+
     if ((gtype = pyg_type_from_object(pygtype)) == 0) {
 	return NULL;
     }
-    
+
     if (!g_signal_parse_name(name, gtype, &signal_id, NULL, TRUE)) {
 	PyErr_Format(PyExc_TypeError, "%s: unknown signal name: %s",
-		     _PyUnicode_AsString(PyObject_Repr((PyObject*)self)),
-		     name);
+                 PYGLIB_PyUnicode_AsString(PyObject_Repr((PyObject*)self)),
+                 name);
 	return NULL;
     }
 
     g_signal_remove_emission_hook(signal_id, hook_id);
-    
+
     Py_INCREF(Py_None);
     return Py_None;
 }
@@ -2042,7 +2042,7 @@ pyg_constant_strip_prefix(const gchar *name, const gchar *strip_prefix)
 {
     gint prefix_len;
     guint i;
-    
+
     prefix_len = strlen(strip_prefix);
 
     /* Check so name starts with strip_prefix, if it doesn't:
@@ -2162,7 +2162,7 @@ pyg_error_check(GError **error)
 		   "pyg_error_check is deprecated, use "
 		   "pyglib_error_check instead"))
         return NULL;
-#endif    
+#endif
     return pyglib_error_check(error);
 }
 
@@ -2187,7 +2187,7 @@ pyg_gerror_exception_check(GError **error)
 		   "pyg_gerror_exception_check is deprecated, use "
 		   "pyglib_gerror_exception_check instead"))
         return NULL;
-#endif    
+#endif
     return pyglib_gerror_exception_check(error);
 }
 
@@ -2202,9 +2202,9 @@ pyg_gerror_exception_check(GError **error)
  * arguments/properties
  * @nparams: output parameter to contain actual number of arguments found
  * @py_args: array of PyObject* containing the actual constructor arguments
- * 
+ *
  * Parses an array of PyObject's and creates a GParameter array
- * 
+ *
  * Return value: %TRUE if all is successful, otherwise %FALSE and
  * python exception set.
  **/
@@ -2298,9 +2298,9 @@ pygobject_construct(PyGObject *self, const char *first_property_name, ...)
 
         if (!pspec)
 	{
-            g_warning("%s: object class `%s' has no property named `%s'", 
-                      G_STRFUNC, 
-                      g_type_name(object_type), 
+            g_warning("%s: object class `%s' has no property named `%s'",
+                      G_STRFUNC,
+                      g_type_name(object_type),
                       name);
             break;
 	}
@@ -2347,12 +2347,12 @@ pyg_integer_richcompare(PyObject *v, PyObject *w, int op)
     gboolean t;
 
     switch (op) {
-    case Py_EQ: t = _PyLong_AS_LONG(v) == _PyLong_AS_LONG(w); break;
-    case Py_NE: t = _PyLong_AS_LONG(v) != _PyLong_AS_LONG(w); break;
-    case Py_LE: t = _PyLong_AS_LONG(v) <= _PyLong_AS_LONG(w); break;
-    case Py_GE: t = _PyLong_AS_LONG(v) >= _PyLong_AS_LONG(w); break;
-    case Py_LT: t = _PyLong_AS_LONG(v) <  _PyLong_AS_LONG(w); break;
-    case Py_GT: t = _PyLong_AS_LONG(v) >  _PyLong_AS_LONG(w); break;
+    case Py_EQ: t = PYGLIB_PyLong_AS_LONG(v) == PYGLIB_PyLong_AS_LONG(w); break;
+    case Py_NE: t = PYGLIB_PyLong_AS_LONG(v) != PYGLIB_PyLong_AS_LONG(w); break;
+    case Py_LE: t = PYGLIB_PyLong_AS_LONG(v) <= PYGLIB_PyLong_AS_LONG(w); break;
+    case Py_GE: t = PYGLIB_PyLong_AS_LONG(v) >= PYGLIB_PyLong_AS_LONG(w); break;
+    case Py_LT: t = PYGLIB_PyLong_AS_LONG(v) <  PYGLIB_PyLong_AS_LONG(w); break;
+    case Py_GT: t = PYGLIB_PyLong_AS_LONG(v) >  PYGLIB_PyLong_AS_LONG(w); break;
     default: g_assert_not_reached();
     }
 
@@ -2380,7 +2380,7 @@ _log_func(const gchar *log_domain,
 }
 
 static void
-add_warning_redirection(const char *domain, 
+add_warning_redirection(const char *domain,
                         PyObject   *warning)
 {
     g_return_if_fail(domain != NULL);
@@ -2390,7 +2390,7 @@ add_warning_redirection(const char *domain,
     {
 	guint handler;
 	gpointer old_handler;
-	
+
 	if (!log_handlers)
 	    log_handlers = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, NULL);
 
@@ -2415,7 +2415,7 @@ static void
 disable_warning_redirections(void)
 {
     log_handlers_disabled = TRUE;
-    
+
     if (log_handlers)
     {
 	g_hash_table_foreach(log_handlers, remove_handler, NULL);
@@ -2457,7 +2457,7 @@ struct _PyGObject_Functions pygobject_api_functions = {
 
   pyg_enum_add_constants,
   pyg_flags_add_constants,
-  
+
   pyg_constant_strip_prefix,
 
   pyg_error_check,
@@ -2478,7 +2478,7 @@ struct _PyGObject_Functions pygobject_api_functions = {
   &PyGEnum_Type,
   pyg_enum_add,
   pyg_enum_from_gtype,
-  
+
   &PyGFlags_Type,
   pyg_flags_add,
   pyg_flags_from_gtype,
@@ -2494,15 +2494,15 @@ struct _PyGObject_Functions pygobject_api_functions = {
   pygobject_constructv,
   pygobject_construct,
   pyg_set_object_has_new_constructor,
-  
+
   add_warning_redirection,
   disable_warning_redirections,
-  
+
   pyg_type_register_custom_callback,
   pyg_gerror_exception_check,
 
   pyglib_option_group_new
-  
+
 };
 
 /* for addon libraries ... */
@@ -2510,7 +2510,7 @@ static void
 pygobject_register_api(PyObject *d)
 {
     PyObject *api;
-    
+
     api = PyCObject_FromVoidPtr(&pygobject_api_functions,NULL);
     PyDict_SetItemString(d, "_PyGObject_API", api);
     Py_DECREF(api);
@@ -2548,8 +2548,8 @@ pygobject_register_constants(PyObject *m)
     PyModule_AddObject(m,       "G_MAXSIZE", PyLong_FromUnsignedLongLong(G_MAXSIZE));
     PyModule_AddObject(m,       "G_MAXSSIZE", PyLong_FromUnsignedLongLong(G_MAXSSIZE));
 #elif PY_VERSION_HEX < 0x02060000 /* 2.5 */
-    PyModule_AddObject(m,       "G_MAXSIZE", _PyLong_FromSize_t(G_MAXSIZE));
-    PyModule_AddObject(m,       "G_MAXSSIZE", _PyLong_FromSsize_t(G_MAXSSIZE));
+    PyModule_AddObject(m,       "G_MAXSIZE", PYGLIB_PyLong_FromSize_t(G_MAXSIZE));
+    PyModule_AddObject(m,       "G_MAXSSIZE", PYGLIB_PyLong_FromSsize_t(G_MAXSSIZE));
 #else /* 2.6+ */
     PyModule_AddObject(m,       "G_MAXSIZE", PyLong_FromSize_t(G_MAXSIZE));
     PyModule_AddObject(m,       "G_MAXSSIZE", PyLong_FromSsize_t(G_MAXSSIZE));
@@ -2588,7 +2588,7 @@ static void
 pygobject_register_features(PyObject *d)
 {
     PyObject *features;
-    
+
     features = PyDict_New();
 #ifdef HAVE_FFI_H
     PyDict_SetItemString(features, "generic-c-marshaller", Py_True);
@@ -2648,7 +2648,7 @@ PYGLIB_MODULE_START(_gobject, "gobject._gobject")
     pygobject_pointer_register_types(d);
     pygobject_enum_register_types(d);
     pygobject_flags_register_types(d);
-    
+
       /* signal registration recognizes this special accumulator 'constant' */
     _pyg_signal_accumulator_true_handled_func = \
         PyDict_GetItemString(d, "signal_accumulator_true_handled");
diff --git a/gobject/pygboxed.c b/gobject/pygboxed.c
index 9a71afe..a00386b 100644
--- a/gobject/pygboxed.c
+++ b/gobject/pygboxed.c
@@ -74,7 +74,7 @@ pyg_boxed_repr(PyGBoxed *self)
 
     g_snprintf(buf, sizeof(buf), "<%s at 0x%lx>", g_type_name(self->gtype),
 	       (long)self->boxed);
-    return _PyUnicode_FromString(buf);
+    return PYGLIB_PyUnicode_FromString(buf);
 }
 
 static int
diff --git a/gobject/pygenum.c b/gobject/pygenum.c
index a09ab98..71d8e11 100644
--- a/gobject/pygenum.c
+++ b/gobject/pygenum.c
@@ -39,7 +39,7 @@ pyg_enum_richcompare(PyGEnum *self, PyObject *other, int op)
 {
     static char warning[256];
 
-    if (!_PyLong_Check(other)) {
+    if (!PYGLIB_PyLong_Check(other)) {
 	Py_INCREF(Py_NotImplemented);
 	return Py_NotImplemented;
     }
@@ -61,22 +61,22 @@ pyg_enum_repr(PyGEnum *self)
   const char *value;
   guint index;
   static char tmp[256];
-  
+
   enum_class = g_type_class_ref(self->gtype);
   g_assert(G_IS_ENUM_CLASS(enum_class));
 
   for (index = 0; index < enum_class->n_values; index++)
-      if (_PyLong_AS_LONG(self) == enum_class->values[index].value)
+      if (PYGLIB_PyLong_AS_LONG(self) == enum_class->values[index].value)
           break;
   value = enum_class->values[index].value_name;
   if (value)
       sprintf(tmp, "<enum %s of type %s>", value, g_type_name(self->gtype));
   else
-      sprintf(tmp, "<enum %ld of type %s>", _PyLong_AS_LONG(self), g_type_name(self->gtype));
+      sprintf(tmp, "<enum %ld of type %s>", PYGLIB_PyLong_AS_LONG(self), g_type_name(self->gtype));
 
   g_type_class_unref(enum_class);
 
-  return _PyUnicode_FromString(tmp);
+  return PYGLIB_PyUnicode_FromString(tmp);
 }
 
 static PyObject *
@@ -90,18 +90,18 @@ pyg_enum_new(PyTypeObject *type, PyObject *args, PyObject *kwargs)
 
     if (!PyArg_ParseTupleAndKeywords(args, kwargs, "l", kwlist, &value))
 	return NULL;
-    
+
     pytc = PyObject_GetAttrString((PyObject *)type, "__gtype__");
     if (!pytc)
 	return NULL;
-    
+
     if (!PyObject_TypeCheck(pytc, &PyGTypeWrapper_Type)) {
 	Py_DECREF(pytc);
 	PyErr_SetString(PyExc_TypeError,
 			"__gtype__ attribute not a typecode");
 	return NULL;
     }
-    
+
     gtype = pyg_type_from_object(pytc);
     Py_DECREF(pytc);
 
@@ -133,8 +133,8 @@ pyg_enum_new(PyTypeObject *type, PyObject *args, PyObject *kwargs)
     }
 
     g_type_class_unref(eclass);
-    
-    intvalue = _PyLong_FromLong(value);
+
+    intvalue = PYGLIB_PyLong_FromLong(value);
     ret = PyDict_GetItem(values, intvalue);
     Py_DECREF(intvalue);
     Py_DECREF(values);
@@ -142,7 +142,7 @@ pyg_enum_new(PyTypeObject *type, PyObject *args, PyObject *kwargs)
         Py_INCREF(ret);
     else
 	PyErr_Format(PyExc_ValueError, "invalid enum value: %ld", value);
-    
+
     return ret;
 }
 
@@ -164,27 +164,27 @@ pyg_enum_from_gtype (GType gtype, int value)
     if (!pyclass)
         pyclass = pyg_enum_add(NULL, g_type_name(gtype), NULL, gtype);
     if (!pyclass)
-	return _PyLong_FromLong(value);
-    
+	return PYGLIB_PyLong_FromLong(value);
+
     values = PyDict_GetItemString(((PyTypeObject *)pyclass)->tp_dict,
 				  "__enum_values__");
-    intvalue = _PyLong_FromLong(value);
+    intvalue = PYGLIB_PyLong_FromLong(value);
     retval = PyDict_GetItem(values, intvalue);
     Py_DECREF(intvalue);
     if (!retval) {
 	PyErr_Clear();
 	retval = ((PyTypeObject *)pyclass)->tp_alloc((PyTypeObject *)pyclass, 0);
 	g_assert(retval != NULL);
-	
+
 #if PY_VERSION_HEX >= 0x03000000
-#   warning "FIXME: figure out how to subclass long"    
+#   warning "FIXME: figure out how to subclass long"
 #else
-	((_PyLongObject*)retval)->ob_ival = value;
-#endif    
+	((PYGLIB_PyLongObject*)retval)->ob_ival = value;
+#endif
 	((PyGFlags*)retval)->gtype = gtype;
 	//return _PyLong_FromLong(value);
     }
-    
+
     Py_INCREF(retval);
     return retval;
 }
@@ -199,14 +199,14 @@ pyg_enum_add (PyObject *   module,
     PyObject *instance_dict, *stub, *values, *o;
     GEnumClass *eclass;
     int i;
-    
+
     g_return_val_if_fail(typename != NULL, NULL);
     if (!g_type_is_a(gtype, G_TYPE_ENUM)) {
         g_warning("Trying to register gtype '%s' as enum when in fact it is of type '%s'",
                   g_type_name(gtype), g_type_name(G_TYPE_FUNDAMENTAL(gtype)));
         return NULL;
     }
-    
+
     state = pyglib_gil_state_ensure();
 
     instance_dict = PyDict_New();
@@ -226,8 +226,8 @@ pyg_enum_add (PyObject *   module,
     if (module)
 	PyDict_SetItemString(((PyTypeObject *)stub)->tp_dict,
 			     "__module__",
-			     _PyUnicode_FromString(PyModule_GetName(module)));
-    
+			     PYGLIB_PyUnicode_FromString(PyModule_GetName(module)));
+
     g_type_set_qdata(gtype, pygenum_class_key, stub);
 
     o = pyg_type_wrapper_new(gtype);
@@ -246,19 +246,19 @@ pyg_enum_add (PyObject *   module,
     values = PyDict_New();
     for (i = 0; i < eclass->n_values; i++) {
 	PyObject *item, *intval;
-      
+
 	item = ((PyTypeObject *)stub)->tp_alloc((PyTypeObject *)stub, 0);
 #if PY_VERSION_HEX >= 0x03000000
-#   warning "FIXME: figure out how to subclass long"    
+#   warning "FIXME: figure out how to subclass long"
 #else
-	((_PyLongObject*)item)->ob_ival = eclass->values[i].value;
-#endif    
+	((PYGLIB_PyLongObject*)item)->ob_ival = eclass->values[i].value;
+#endif
 	((PyGEnum*)item)->gtype = gtype;
-	
-        intval = _PyLong_FromLong(eclass->values[i].value);
+
+        intval = PYGLIB_PyLong_FromLong(eclass->values[i].value);
 	PyDict_SetItem(values, intval, item);
         Py_DECREF(intval);
-	
+
 	if (module) {
 	    char *prefix;
 
@@ -269,13 +269,13 @@ pyg_enum_add (PyObject *   module,
 	    Py_INCREF(item);
 	}
     }
-    
+
     PyDict_SetItemString(((PyTypeObject *)stub)->tp_dict,
 			 "__enum_values__", values);
     Py_DECREF(values);
 
     g_type_class_unref(eclass);
-    
+
     pyglib_gil_state_release(state);
     return stub;
 }
@@ -286,7 +286,7 @@ pyg_enum_reduce(PyObject *self, PyObject *args)
     if (!PyArg_ParseTuple(args, ":GEnum.__reduce__"))
         return NULL;
 
-    return Py_BuildValue("(O(i)O)", Py_TYPE(self), _PyLong_AsLong(self),
+    return Py_BuildValue("(O(i)O)", Py_TYPE(self), PYGLIB_PyLong_AsLong(self),
                          PyObject_GetAttrString(self, "__dict__"));
 }
 
@@ -296,13 +296,13 @@ pyg_enum_get_value_name(PyGEnum *self, void *closure)
   GEnumClass *enum_class;
   GEnumValue *enum_value;
   PyObject *retval;
-  
+
   enum_class = g_type_class_ref(self->gtype);
   g_assert(G_IS_ENUM_CLASS(enum_class));
-  
-  enum_value = g_enum_get_value(enum_class, _PyLong_AS_LONG(self));
 
-  retval = _PyUnicode_FromString(enum_value->value_name);
+  enum_value = g_enum_get_value(enum_class, PYGLIB_PyLong_AS_LONG(self));
+
+  retval = PYGLIB_PyUnicode_FromString(enum_value->value_name);
   g_type_class_unref(enum_class);
 
   return retval;
@@ -314,13 +314,13 @@ pyg_enum_get_value_nick(PyGEnum *self, void *closure)
   GEnumClass *enum_class;
   GEnumValue *enum_value;
   PyObject *retval;
-  
+
   enum_class = g_type_class_ref(self->gtype);
   g_assert(G_IS_ENUM_CLASS(enum_class));
-  
-  enum_value = g_enum_get_value(enum_class, _PyLong_AS_LONG(self));
 
-  retval = _PyUnicode_FromString(enum_value->value_nick);
+  enum_value = g_enum_get_value(enum_class, PYGLIB_PyLong_AS_LONG(self));
+
+  retval = PYGLIB_PyUnicode_FromString(enum_value->value_nick);
   g_type_class_unref(enum_class);
 
   return retval;
@@ -343,7 +343,7 @@ pygobject_enum_register_types(PyObject *d)
 {
     pygenum_class_key        = g_quark_from_static_string("PyGEnum::class");
 
-    PyGEnum_Type.tp_base = &_PyLong_Type;
+    PyGEnum_Type.tp_base = &PYGLIB_PyLong_Type;
     PyGEnum_Type.tp_repr = (reprfunc)pyg_enum_repr;
     PyGEnum_Type.tp_str = (reprfunc)pyg_enum_repr;
     PyGEnum_Type.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE;
diff --git a/gobject/pygflags.c b/gobject/pygflags.c
index 7bcd294..c14e42f 100644
--- a/gobject/pygflags.c
+++ b/gobject/pygflags.c
@@ -40,7 +40,7 @@ pyg_flags_richcompare(PyGFlags *self, PyObject *other, int op)
 {
     static char warning[256];
 
-    if (!_PyLong_Check(other)) {
+    if (!PYGLIB_PyLong_Check(other)) {
         Py_INCREF(Py_NotImplemented);
         return Py_NotImplemented;
     }
@@ -64,7 +64,7 @@ generate_repr(GType gtype, int value)
 
     flags_class = g_type_class_ref(gtype);
     g_assert(G_IS_FLAGS_CLASS(flags_class));
-  
+
     for (i = 0; i < flags_class->n_values; i++) {
 	/* Some types (eg GstElementState in GStreamer 0.8) has flags with 0 values,
          * we're just ignore them for now otherwise they'll always show up
@@ -82,31 +82,31 @@ generate_repr(GType gtype, int value)
 	    }
 	}
     }
-    
+
     g_type_class_unref(flags_class);
 
     return retval;
 }
-	    
+
 static PyObject *
 pyg_flags_repr(PyGFlags *self)
 {
     char *tmp, *retval;
     PyObject *pyretval;
-  
-    tmp = generate_repr(self->gtype, _PyLong_AS_LONG(self));
+
+    tmp = generate_repr(self->gtype, PYGLIB_PyLong_AS_LONG(self));
 
     if (tmp)
         retval = g_strdup_printf("<flags %s of type %s>", tmp,
                                  g_type_name(self->gtype));
     else
-        retval = g_strdup_printf("<flags %ld of type %s>", _PyLong_AS_LONG(self),
+        retval = g_strdup_printf("<flags %ld of type %s>", PYGLIB_PyLong_AS_LONG(self),
                                  g_type_name(self->gtype));
     g_free(tmp);
-    
-    pyretval = _PyUnicode_FromString(retval);
+
+    pyretval = PYGLIB_PyUnicode_FromString(retval);
     g_free(retval);
-  
+
     return pyretval;
 }
 
@@ -118,21 +118,21 @@ pyg_flags_new(PyTypeObject *type, PyObject *args, PyObject *kwargs)
     PyObject *pytc, *values, *ret, *pyint;
     GType gtype;
     GFlagsClass *eclass;
-    
+
     if (!PyArg_ParseTupleAndKeywords(args, kwargs, "l", kwlist, &value))
 	return NULL;
-    
+
     pytc = PyObject_GetAttrString((PyObject *)type, "__gtype__");
     if (!pytc)
 	return NULL;
-    
+
     if (!PyObject_TypeCheck(pytc, &PyGTypeWrapper_Type)) {
 	Py_DECREF(pytc);
 	PyErr_SetString(PyExc_TypeError,
 			"__gtype__ attribute not a typecode");
 	return NULL;
     }
-    
+
     gtype = pyg_type_from_object(pytc);
     Py_DECREF(pytc);
 
@@ -143,7 +143,7 @@ pyg_flags_new(PyTypeObject *type, PyObject *args, PyObject *kwargs)
 	g_type_class_unref(eclass);
 	return NULL;
     }
-    
+
     if (!PyDict_Check(values) || PyDict_Size(values) != eclass->n_values) {
 	PyErr_SetString(PyExc_TypeError, "__flags_values__ badly formed");
 	Py_DECREF(values);
@@ -152,8 +152,8 @@ pyg_flags_new(PyTypeObject *type, PyObject *args, PyObject *kwargs)
     }
 
     g_type_class_unref(eclass);
-    
-    pyint = _PyLong_FromLong(value);
+
+    pyint = PYGLIB_PyLong_FromLong(value);
     ret = PyDict_GetItem(values, pyint);
     Py_DECREF(pyint);
     Py_DECREF(values);
@@ -171,7 +171,7 @@ pyg_flags_from_gtype (GType gtype, int value)
     PyObject *pyclass, *values, *retval, *pyint;
 
     g_return_val_if_fail(gtype != G_TYPE_INVALID, NULL);
-    
+
     /* Get a wrapper class by:
      * 1. check for one attached to the gtype
      * 2. lookup one in a typelib
@@ -183,11 +183,11 @@ pyg_flags_from_gtype (GType gtype, int value)
     if (!pyclass)
         pyclass = pyg_flags_add(NULL, g_type_name(gtype), NULL, gtype);
     if (!pyclass)
-	return _PyLong_FromLong(value);
-    
+	return PYGLIB_PyLong_FromLong(value);
+
     values = PyDict_GetItemString(((PyTypeObject *)pyclass)->tp_dict,
 				  "__flags_values__");
-    pyint = _PyLong_FromLong(value);
+    pyint = PYGLIB_PyLong_FromLong(value);
     retval = PyDict_GetItem(values, pyint);
     Py_DECREF(pyint);
 
@@ -196,12 +196,12 @@ pyg_flags_from_gtype (GType gtype, int value)
 
 	retval = ((PyTypeObject *)pyclass)->tp_alloc((PyTypeObject *)pyclass, 0);
 	g_assert(retval != NULL);
-	
+
 #if PY_VERSION_HEX >= 0x03000000
-#   warning "FIXME: figure out how to subclass long"    
+#   warning "FIXME: figure out how to subclass long"
 #else
-	((_PyLongObject*)retval)->ob_ival = value;
-#endif    
+	((PYGLIB_PyLongObject*)retval)->ob_ival = value;
+#endif
 	((PyGFlags*)retval)->gtype = gtype;
     } else {
 	Py_INCREF(retval);
@@ -226,7 +226,7 @@ pyg_flags_add (PyObject *   module,
                   g_type_name(gtype), g_type_name(G_TYPE_FUNDAMENTAL(gtype)));
         return NULL;
     }
-    
+
     state = pyglib_gil_state_ensure();
 
     instance_dict = PyDict_New();
@@ -239,15 +239,15 @@ pyg_flags_add (PyObject *   module,
 	pyglib_gil_state_release(state);
         return NULL;
     }
-    
+
     ((PyTypeObject *)stub)->tp_flags &= ~Py_TPFLAGS_BASETYPE;
     ((PyTypeObject *)stub)->tp_new = pyg_flags_new;
 
     if (module) {
         PyDict_SetItemString(((PyTypeObject *)stub)->tp_dict,
                              "__module__",
-                             _PyUnicode_FromString(PyModule_GetName(module)));
-    
+                             PYGLIB_PyUnicode_FromString(PyModule_GetName(module)));
+
           /* Add it to the module name space */
         PyModule_AddObject(module, (char*)typename, stub);
         Py_INCREF(stub);
@@ -257,37 +257,37 @@ pyg_flags_add (PyObject *   module,
     o = pyg_type_wrapper_new(gtype);
     PyDict_SetItemString(((PyTypeObject *)stub)->tp_dict, "__gtype__", o);
     Py_DECREF(o);
-    
+
     /* Register flag values */
     eclass = G_FLAGS_CLASS(g_type_class_ref(gtype));
 
     values = PyDict_New();
     for (i = 0; i < eclass->n_values; i++) {
       PyObject *item, *intval;
-      
+
       item = ((PyTypeObject *)stub)->tp_alloc((PyTypeObject *)stub, 0);
 #if PY_VERSION_HEX >= 0x03000000
-#   warning "FIXME: figure out how to subclass long"    
+#   warning "FIXME: figure out how to subclass long"
 #else
-      ((_PyLongObject*)item)->ob_ival = eclass->values[i].value;
-#endif    
+      ((PYGLIB_PyLongObject*)item)->ob_ival = eclass->values[i].value;
+#endif
       ((PyGFlags*)item)->gtype = gtype;
-            
-      intval = _PyLong_FromLong(eclass->values[i].value);
+
+      intval = PYGLIB_PyLong_FromLong(eclass->values[i].value);
       PyDict_SetItem(values, intval, item);
       Py_DECREF(intval);
 
       if (module) {
 	  char *prefix;
-	  
+
 	  prefix = g_strdup(pyg_constant_strip_prefix(eclass->values[i].value_name, strip_prefix));
 	  PyModule_AddObject(module, prefix, item);
 	  g_free(prefix);
-	  
+
 	  Py_INCREF(item);
       }
     }
-    
+
     PyDict_SetItemString(((PyTypeObject *)stub)->tp_dict,
 			 "__flags_values__", values);
     Py_DECREF(values);
@@ -303,32 +303,32 @@ static PyObject *
 pyg_flags_and(PyGFlags *a, PyGFlags *b)
 {
 	if (!PyGFlags_Check(a) || !PyGFlags_Check(b))
-		return _PyLong_Type.tp_as_number->nb_and((PyObject*)a,
+		return PYGLIB_PyLong_Type.tp_as_number->nb_and((PyObject*)a,
 						       (PyObject*)b);
-	
+
 	return pyg_flags_from_gtype(a->gtype,
-				    _PyLong_AS_LONG(a) & _PyLong_AS_LONG(b));
+				    PYGLIB_PyLong_AS_LONG(a) & PYGLIB_PyLong_AS_LONG(b));
 }
 
 static PyObject *
 pyg_flags_or(PyGFlags *a, PyGFlags *b)
 {
 	if (!PyGFlags_Check(a) || !PyGFlags_Check(b))
-		return _PyLong_Type.tp_as_number->nb_or((PyObject*)a,
+		return PYGLIB_PyLong_Type.tp_as_number->nb_or((PyObject*)a,
 						      (PyObject*)b);
 
-	return pyg_flags_from_gtype(a->gtype, _PyLong_AS_LONG(a) | _PyLong_AS_LONG(b));
+	return pyg_flags_from_gtype(a->gtype, PYGLIB_PyLong_AS_LONG(a) | PYGLIB_PyLong_AS_LONG(b));
 }
 
 static PyObject *
 pyg_flags_xor(PyGFlags *a, PyGFlags *b)
 {
 	if (!PyGFlags_Check(a) || !PyGFlags_Check(b))
-		return _PyLong_Type.tp_as_number->nb_xor((PyObject*)a,
+		return PYGLIB_PyLong_Type.tp_as_number->nb_xor((PyObject*)a,
 						       (PyObject*)b);
 
 	return pyg_flags_from_gtype(a->gtype,
-				    _PyLong_AS_LONG(a) ^ _PyLong_AS_LONG(b));
+				    PYGLIB_PyLong_AS_LONG(a) ^ PYGLIB_PyLong_AS_LONG(b));
 
 }
 
@@ -348,12 +348,12 @@ pyg_flags_get_first_value_name(PyGFlags *self, void *closure)
   GFlagsClass *flags_class;
   GFlagsValue *flags_value;
   PyObject *retval;
-  
+
   flags_class = g_type_class_ref(self->gtype);
   g_assert(G_IS_FLAGS_CLASS(flags_class));
-  flags_value = g_flags_get_first_value(flags_class, _PyLong_AS_LONG(self));
+  flags_value = g_flags_get_first_value(flags_class, PYGLIB_PyLong_AS_LONG(self));
   if (flags_value)
-      retval = _PyUnicode_FromString(flags_value->value_name);
+      retval = PYGLIB_PyUnicode_FromString(flags_value->value_name);
   else {
       retval = Py_None;
       Py_INCREF(Py_None);
@@ -369,13 +369,13 @@ pyg_flags_get_first_value_nick(PyGFlags *self, void *closure)
   GFlagsClass *flags_class;
   GFlagsValue *flags_value;
   PyObject *retval;
-  
+
   flags_class = g_type_class_ref(self->gtype);
   g_assert(G_IS_FLAGS_CLASS(flags_class));
 
-  flags_value = g_flags_get_first_value(flags_class, _PyLong_AS_LONG(self));
+  flags_value = g_flags_get_first_value(flags_class, PYGLIB_PyLong_AS_LONG(self));
   if (flags_value)
-      retval = _PyUnicode_FromString(flags_value->value_nick);
+      retval = PYGLIB_PyUnicode_FromString(flags_value->value_nick);
   else {
       retval = Py_None;
       Py_INCREF(Py_None);
@@ -391,14 +391,14 @@ pyg_flags_get_value_names(PyGFlags *self, void *closure)
   GFlagsClass *flags_class;
   PyObject *retval;
   int i;
-  
+
   flags_class = g_type_class_ref(self->gtype);
   g_assert(G_IS_FLAGS_CLASS(flags_class));
-  
+
   retval = PyList_New(0);
   for (i = 0; i < flags_class->n_values; i++)
-      if ((_PyLong_AS_LONG(self) & flags_class->values[i].value) == flags_class->values[i].value)
-	  PyList_Append(retval, _PyUnicode_FromString(flags_class->values[i].value_name));
+      if ((PYGLIB_PyLong_AS_LONG(self) & flags_class->values[i].value) == flags_class->values[i].value)
+	  PyList_Append(retval, PYGLIB_PyUnicode_FromString(flags_class->values[i].value_name));
 
   g_type_class_unref(flags_class);
 
@@ -411,14 +411,14 @@ pyg_flags_get_value_nicks(PyGFlags *self, void *closure)
   GFlagsClass *flags_class;
   PyObject *retval;
   int i;
-  
+
   flags_class = g_type_class_ref(self->gtype);
   g_assert(G_IS_FLAGS_CLASS(flags_class));
-  
+
   retval = PyList_New(0);
   for (i = 0; i < flags_class->n_values; i++)
-      if ((_PyLong_AS_LONG(self) & flags_class->values[i].value) == flags_class->values[i].value)
-	  PyList_Append(retval, _PyUnicode_FromString(flags_class->values[i].value_nick));
+      if ((PYGLIB_PyLong_AS_LONG(self) & flags_class->values[i].value) == flags_class->values[i].value)
+	  PyList_Append(retval, PYGLIB_PyUnicode_FromString(flags_class->values[i].value_nick));
 
   g_type_class_unref(flags_class);
 
@@ -479,7 +479,7 @@ pygobject_flags_register_types(PyObject *d)
 {
     pygflags_class_key = g_quark_from_static_string("PyGFlags::class");
 
-    PyGFlags_Type.tp_base = &_PyLong_Type;
+    PyGFlags_Type.tp_base = &PYGLIB_PyLong_Type;
     PyGFlags_Type.tp_repr = (reprfunc)pyg_flags_repr;
     PyGFlags_Type.tp_as_number = &pyg_flags_as_number;
     PyGFlags_Type.tp_str = (reprfunc)pyg_flags_repr;
diff --git a/gobject/pygobject-private.h b/gobject/pygobject-private.h
index 2a09eed..26cb5f2 100644
--- a/gobject/pygobject-private.h
+++ b/gobject/pygobject-private.h
@@ -113,10 +113,10 @@ void      pyg_register_gtype_custom(GType gtype,
 int       pyg_value_from_pyobject(GValue *value, PyObject *obj);
 PyObject *pyg_value_as_pyobject(const GValue *value, gboolean copy_boxed);
 int       pyg_param_gvalue_from_pyobject(GValue* value,
-                                         PyObject* py_obj, 
+                                         PyObject* py_obj,
                                          const GParamSpec* pspec);
 PyObject *pyg_param_gvalue_as_pyobject(const GValue* gvalue,
-                                       gboolean copy_boxed, 
+                                       gboolean copy_boxed,
                                        const GParamSpec* pspec);
 
 GClosure *pyg_closure_new(PyObject *callback, PyObject *extra_args, PyObject *swap_data);
@@ -175,14 +175,14 @@ const gchar * pyg_constant_strip_prefix(const gchar *name, const gchar *strip_pr
 
 /* pygflags */
 typedef struct {
-    _PyLongObject parent;
+	PYGLIB_PyLongObject parent;
     GType gtype;
 } PyGFlags;
 
 extern PyTypeObject PyGFlags_Type;
 
 #define PyGFlags_Check(x) (g_type_is_a(((PyGFlags*)x)->gtype, G_TYPE_FLAGS))
-			   
+
 extern PyObject * pyg_flags_add        (PyObject *   module,
 					const char * type_name,
 					const char * strip_prefix,
@@ -194,7 +194,7 @@ extern PyObject * pyg_flags_from_gtype (GType        gtype,
 #define PyGEnum_Check(x) (g_type_is_a(((PyGFlags*)x)->gtype, G_TYPE_ENUM))
 
 typedef struct {
-    _PyLongObject parent;
+	PYGLIB_PyLongObject parent;
     GType gtype;
 } PyGEnum;
 
@@ -221,7 +221,7 @@ extern PyTypeObject PyGObjectWeakRef_Type;
 static inline PyGObjectData *
 pyg_object_peek_inst_data(GObject *obj)
 {
-    return ((PyGObjectData *) 
+    return ((PyGObjectData *)
             g_object_get_qdata(obj, pygobject_instance_data_key));
 }
 
diff --git a/gobject/pygobject.c b/gobject/pygobject.c
index 46db8e1..ebb8136 100644
--- a/gobject/pygobject.c
+++ b/gobject/pygobject.c
@@ -255,7 +255,7 @@ build_parameter_list(GObjectClass *class)
 	name = g_strdup(g_param_spec_get_name(props[i]));
 	/* hyphens cannot belong in identifiers */
 	g_strdelimit(name, "-", '_');
-	prop_str = _PyUnicode_FromString(name);
+	prop_str = PYGLIB_PyUnicode_FromString(name);
 	
 	PyList_SetItem(props_list, i, prop_str);
 	g_free(name);
@@ -276,7 +276,7 @@ PyGProps_getattro(PyGProps *self, PyObject *attr)
     GValue value = { 0, };
     PyObject *ret;
 
-    attr_name = _PyUnicode_AsString(attr);
+    attr_name = PYGLIB_PyUnicode_AsString(attr);
     if (!attr_name) {
         PyErr_Clear();
         return PyObject_GenericGetAttr((PyObject *)self, attr);
@@ -375,7 +375,7 @@ PyGProps_setattro(PyGProps *self, PyObject *attr, PyObject *pvalue)
 	return -1;
     }
 
-    attr_name = _PyUnicode_AsString(attr);
+    attr_name = PYGLIB_PyUnicode_AsString(attr);
     if (!attr_name) {
         PyErr_Clear();
         return PyObject_GenericSetAttr((PyObject *)self, attr, pvalue);
@@ -554,7 +554,7 @@ pygobject_register_class(PyObject *dict, const gchar *type_name,
      */
     s = strrchr(type->tp_name, '.');
     if (s != NULL) {
-	mod_name = _PyUnicode_FromStringAndSize(type->tp_name, (int)(s - type->tp_name));
+	mod_name = PYGLIB_PyUnicode_FromStringAndSize(type->tp_name, (int)(s - type->tp_name));
 	PyDict_SetItemString(type->tp_dict, "__module__", mod_name);
 	Py_DECREF(mod_name);
     }
@@ -1080,7 +1080,7 @@ pygobject_repr(PyGObject *self)
 	       (long)self,
 	       self->obj ? G_OBJECT_TYPE_NAME(self->obj) : "uninitialized",
                (long)self->obj);
-    return _PyUnicode_FromString(buf);
+    return PYGLIB_PyUnicode_FromString(buf);
 }
 
 
@@ -1175,7 +1175,7 @@ pygobject_init(PyGObject *self, PyObject *args, PyObject *kwargs)
 	params = g_new0(GParameter, PyDict_Size(kwargs));
 	while (PyDict_Next (kwargs, &pos, &key, &value)) {
 	    GParamSpec *pspec;
-	    gchar *key_str = _PyUnicode_AsString(key);
+	    gchar *key_str = PYGLIB_PyUnicode_AsString(key);
 
 	    pspec = g_object_class_find_property (class, key_str);
 	    if (!pspec) {
@@ -1283,13 +1283,13 @@ pygobject_get_properties(PyGObject *self, PyObject *args)
         GValue value = { 0 };
         PyObject *item;
 
-        if (!_PyUnicode_Check(py_property)) {
+        if (!PYGLIB_PyUnicode_Check(py_property)) {
             PyErr_SetString(PyExc_TypeError,
                             "Expected string argument for property.");
             return NULL;
         }
 
-        property_name = _PyUnicode_AsString(py_property);
+        property_name = PYGLIB_PyUnicode_AsString(py_property);
 
         pspec = g_object_class_find_property(G_OBJECT_GET_CLASS(self->obj),
 					 property_name);
@@ -1365,7 +1365,7 @@ pygobject_set_properties(PyGObject *self, PyObject *args, PyObject *kwargs)
     pos = 0;
 
     while (kwargs && PyDict_Next (kwargs, &pos, &key, &value)) {
-	gchar *key_str = _PyUnicode_AsString(key);
+	gchar *key_str = PYGLIB_PyUnicode_AsString(key);
 	GParamSpec *pspec;
 
 	pspec = g_object_class_find_property(class, key_str);
@@ -1502,7 +1502,7 @@ pygobject_connect(PyGObject *self, PyObject *args)
     if (!g_signal_parse_name(name, G_OBJECT_TYPE(self->obj),
 			     &sigid, &detail, TRUE)) {
 	PyErr_Format(PyExc_TypeError, "%s: unknown signal name: %s",
-		     _PyUnicode_AsString(PyObject_Repr((PyObject*)self)),
+		     PYGLIB_PyUnicode_AsString(PyObject_Repr((PyObject*)self)),
 		     name);
 	return NULL;
     }
@@ -1551,7 +1551,7 @@ pygobject_connect_after(PyGObject *self, PyObject *args)
     if (!g_signal_parse_name(name, G_OBJECT_TYPE(self->obj),
 			     &sigid, &detail, TRUE)) {
 	PyErr_Format(PyExc_TypeError, "%s: unknown signal name: %s",
-		     _PyUnicode_AsString(PyObject_Repr((PyObject*)self)),
+		     PYGLIB_PyUnicode_AsString(PyObject_Repr((PyObject*)self)),
 		     name);
 	return NULL;
     }
@@ -1600,7 +1600,7 @@ pygobject_connect_object(PyGObject *self, PyObject *args)
     if (!g_signal_parse_name(name, G_OBJECT_TYPE(self->obj),
 			     &sigid, &detail, TRUE)) {
 	PyErr_Format(PyExc_TypeError, "%s: unknown signal name: %s",
-		     _PyUnicode_AsString(PyObject_Repr((PyObject*)self)),
+		     PYGLIB_PyUnicode_AsString(PyObject_Repr((PyObject*)self)),
 		     name);
 	return NULL;
     }
@@ -1649,7 +1649,7 @@ pygobject_connect_object_after(PyGObject *self, PyObject *args)
     if (!g_signal_parse_name(name, G_OBJECT_TYPE(self->obj),
 			     &sigid, &detail, TRUE)) {
 	PyErr_Format(PyExc_TypeError, "%s: unknown signal name: %s",
-		     _PyUnicode_AsString(PyObject_Repr((PyObject*)self)),
+		     PYGLIB_PyUnicode_AsString(PyObject_Repr((PyObject*)self)),
 		     name);
 	return NULL;
     }
@@ -1748,7 +1748,7 @@ pygobject_emit(PyGObject *self, PyObject *args)
     if (!g_signal_parse_name(name, G_OBJECT_TYPE(self->obj),
 			     &signal_id, &detail, TRUE)) {
 	PyErr_Format(PyExc_TypeError, "%s: unknown signal name: %s",
-		     _PyUnicode_AsString(PyObject_Repr((PyObject*)self)),
+		     PYGLIB_PyUnicode_AsString(PyObject_Repr((PyObject*)self)),
 		     name);
 	return NULL;
     }
@@ -1824,7 +1824,7 @@ pygobject_stop_emission(PyGObject *self, PyObject *args)
     if (!g_signal_parse_name(signal, G_OBJECT_TYPE(self->obj),
 			     &signal_id, &detail, TRUE)) {
 	PyErr_Format(PyExc_TypeError, "%s: unknown signal name: %s",
-		     _PyUnicode_AsString(PyObject_Repr((PyObject*)self)),
+		     PYGLIB_PyUnicode_AsString(PyObject_Repr((PyObject*)self)),
 		     signal);
 	return NULL;
     }
@@ -1972,7 +1972,7 @@ pygobject_disconnect_by_func(PyGObject *self, PyObject *args)
     closure = gclosure_from_pyfunc(self, pyfunc);
     if (!closure) {
 	PyErr_Format(PyExc_TypeError, "nothing connected to %s",
-		     _PyUnicode_AsString(PyObject_Repr((PyObject*)pyfunc)));
+		     PYGLIB_PyUnicode_AsString(PyObject_Repr((PyObject*)pyfunc)));
 	return NULL;
     }
     
@@ -1981,7 +1981,7 @@ pygobject_disconnect_by_func(PyGObject *self, PyObject *args)
 						  0, 0,
 						  closure,
 						  NULL, NULL);
-    return _PyLong_FromLong(retval);
+    return PYGLIB_PyLong_FromLong(retval);
 }
 
 static PyObject *
@@ -2004,7 +2004,7 @@ pygobject_handler_block_by_func(PyGObject *self, PyObject *args)
     closure = gclosure_from_pyfunc(self, pyfunc);
     if (!closure) {
 	PyErr_Format(PyExc_TypeError, "nothing connected to %s",
-		     _PyUnicode_AsString(PyObject_Repr((PyObject*)pyfunc)));
+		     PYGLIB_PyUnicode_AsString(PyObject_Repr((PyObject*)pyfunc)));
 	return NULL;
     }
     
@@ -2013,7 +2013,7 @@ pygobject_handler_block_by_func(PyGObject *self, PyObject *args)
 					     0, 0,
 					     closure,
 					     NULL, NULL);
-    return _PyLong_FromLong(retval);
+    return PYGLIB_PyLong_FromLong(retval);
 }
 
 static PyObject *
@@ -2036,7 +2036,7 @@ pygobject_handler_unblock_by_func(PyGObject *self, PyObject *args)
     closure = gclosure_from_pyfunc(self, pyfunc);
     if (!closure) {
 	PyErr_Format(PyExc_TypeError, "nothing connected to %s",
-		     _PyUnicode_AsString(PyObject_Repr((PyObject*)pyfunc)));
+		     PYGLIB_PyUnicode_AsString(PyObject_Repr((PyObject*)pyfunc)));
 	return NULL;
     }
     
@@ -2045,7 +2045,7 @@ pygobject_handler_unblock_by_func(PyGObject *self, PyObject *args)
 					       0, 0,
 					       closure,
 					       NULL, NULL);
-    return _PyLong_FromLong(retval);
+    return PYGLIB_PyLong_FromLong(retval);
 }
 
 static PyMethodDef pygobject_methods[] = {
@@ -2100,7 +2100,7 @@ pygobject_get_dict(PyGObject *self, void *closure)
 static PyObject *
 pygobject_get_refcount(PyGObject *self, void *closure)
 {
-    return _PyLong_FromLong(self->obj->ref_count);
+    return PYGLIB_PyLong_FromLong(self->obj->ref_count);
 }
 
 static int
@@ -2336,7 +2336,7 @@ pygobject_object_register_types(PyObject *d)
     descr = PyObject_New(PyObject, &PyGPropsDescr_Type);
     PyDict_SetItemString(PyGObject_Type.tp_dict, "props", descr);
     PyDict_SetItemString(PyGObject_Type.tp_dict, "__module__",
-                        o=_PyUnicode_FromString("gobject._gobject"));
+                        o=PYGLIB_PyUnicode_FromString("gobject._gobject"));
     Py_DECREF(o);
 
     /* GPropsIter */
diff --git a/gobject/pygobject.h b/gobject/pygobject.h
index 85d8bca..e75c890 100644
--- a/gobject/pygobject.h
+++ b/gobject/pygobject.h
@@ -317,9 +317,32 @@ pygobject_init(int req_major, int req_minor, int req_micro)
             Py_XDECREF(type);
             Py_XDECREF(value);
             Py_XDECREF(traceback);
+
+
+#if PY_VERSION_HEX < 0x03000000
             PyErr_Format(PyExc_ImportError,
                          "could not import gobject (error was: %s)",
                          PyString_AsString(py_orig_exc));
+#else
+            {
+                /* Can not use PyErr_Format because it doesn't have
+                 * a format string for dealing with PyUnicode objects
+                 * like PyUnicode_FromFormat has
+                 */
+                PyObject *errmsg = PyUnicode_FromFormat("could not import gobject (error was: %U)",
+                                                        py_orig_exc);
+
+                if (errmsg) {
+                   PyErr_SetObject(PyExc_ImportError,
+                                   errmsg);
+                   Py_DECREF(errmsg);
+                }
+                /* if errmsg is NULL then we might have OOM
+                 * PyErr should already be set and trying to
+                 * return our own error would be futile
+                 */
+            }
+#endif
             Py_DECREF(py_orig_exc);
         } else {
             PyErr_SetString(PyExc_ImportError,
diff --git a/gobject/pygparamspec.c b/gobject/pygparamspec.c
index 97910b1..7743629 100644
--- a/gobject/pygparamspec.c
+++ b/gobject/pygparamspec.c
@@ -59,7 +59,7 @@ pyg_param_spec_repr(PyGParamSpec *self)
     g_snprintf(buf, sizeof(buf), "<%s '%s'>",
 	       G_PARAM_SPEC_TYPE_NAME(self->pspec),
 	       g_param_spec_get_name(self->pspec));
-    return _PyUnicode_FromString(buf);
+    return PYGLIB_PyUnicode_FromString(buf);
 }
 
 static void
@@ -126,7 +126,7 @@ pyg_param_spec_getattr(PyGParamSpec *self, const gchar *attr)
     } else if (!strcmp(attr, "blurb") || !strcmp(attr, "__doc__")) {
 	return Py_BuildValue("s", g_param_spec_get_blurb(pspec));
     } else if (!strcmp(attr, "flags")) {
-	return _PyLong_FromLong(pspec->flags);
+	return PYGLIB_PyLong_FromLong(pspec->flags);
     } else if (!strcmp(attr, "value_type")) {
 	return pyg_type_wrapper_new(pspec->value_type);
     } else if (!strcmp(attr, "owner_type")) {
@@ -140,12 +140,12 @@ pyg_param_spec_getattr(PyGParamSpec *self, const gchar *attr)
 				 "maximum", "minimum", "name", "nick",
 				 "owner_type", "value_type");
 	} else if (!strcmp(attr, "default_value")) {
-	    return _PyUnicode_FromFormat(
+	    return PYGLIB_PyUnicode_FromFormat(
 		"%c", G_PARAM_SPEC_CHAR(pspec)->default_value);
 	} else if (!strcmp(attr, "minimum")) {
-	    return _PyLong_FromLong(G_PARAM_SPEC_CHAR(pspec)->minimum);
+	    return PYGLIB_PyLong_FromLong(G_PARAM_SPEC_CHAR(pspec)->minimum);
 	} else if (!strcmp(attr, "maximum")) {
-	    return _PyLong_FromLong(G_PARAM_SPEC_CHAR(pspec)->maximum);
+	    return PYGLIB_PyLong_FromLong(G_PARAM_SPEC_CHAR(pspec)->maximum);
 	}
     } else if (G_IS_PARAM_SPEC_UCHAR(pspec)) {
 	if (!strcmp(attr, "__members__")) {
@@ -155,12 +155,12 @@ pyg_param_spec_getattr(PyGParamSpec *self, const gchar *attr)
 				 "name", "nick", "owner_type",
 				 "value_type");
 	} else if (!strcmp(attr, "default_value")) {
-	    return _PyUnicode_FromFormat(
+	    return PYGLIB_PyUnicode_FromFormat(
 		"%c", G_PARAM_SPEC_UCHAR(pspec)->default_value);
 	} else if (!strcmp(attr, "minimum")) {
-	    return _PyLong_FromLong(G_PARAM_SPEC_UCHAR(pspec)->minimum);
+	    return PYGLIB_PyLong_FromLong(G_PARAM_SPEC_UCHAR(pspec)->minimum);
 	} else if (!strcmp(attr, "maximum")) {
-	    return _PyLong_FromLong(G_PARAM_SPEC_UCHAR(pspec)->maximum);
+	    return PYGLIB_PyLong_FromLong(G_PARAM_SPEC_UCHAR(pspec)->maximum);
 	}
     } else if (G_IS_PARAM_SPEC_BOOLEAN(pspec)) {
 	if (!strcmp(attr, "__members__")) {
@@ -178,11 +178,11 @@ pyg_param_spec_getattr(PyGParamSpec *self, const gchar *attr)
 				 "flags", "maximum", "minimum", "name",
 				 "nick", "owner_type", "value_type");
 	} else if (!strcmp(attr, "default_value")) {
-	    return _PyLong_FromLong(G_PARAM_SPEC_INT(pspec)->default_value);
+	    return PYGLIB_PyLong_FromLong(G_PARAM_SPEC_INT(pspec)->default_value);
 	} else if (!strcmp(attr, "minimum")) {
-	    return _PyLong_FromLong(G_PARAM_SPEC_INT(pspec)->minimum);
+	    return PYGLIB_PyLong_FromLong(G_PARAM_SPEC_INT(pspec)->minimum);
 	} else if (!strcmp(attr, "maximum")) {
-	    return _PyLong_FromLong(G_PARAM_SPEC_INT(pspec)->maximum);
+	    return PYGLIB_PyLong_FromLong(G_PARAM_SPEC_INT(pspec)->maximum);
 	}
     } else if (G_IS_PARAM_SPEC_UINT(pspec)) {
 	if (!strcmp(attr, "__members__")) {
@@ -258,7 +258,7 @@ pyg_param_spec_getattr(PyGParamSpec *self, const gchar *attr)
 				 "flags", "name", "nick", "owner_type",
 				 "value_type");
 	} else if (!strcmp(attr, "default_value")) {
-	    return _PyUnicode_FromFormat(
+	    return PYGLIB_PyUnicode_FromFormat(
 		"%c", G_PARAM_SPEC_UNICHAR(pspec)->default_value);
 	}
     } else if (G_IS_PARAM_SPEC_ENUM(pspec)) {
diff --git a/gobject/pygpointer.c b/gobject/pygpointer.c
index a894351..fbe3e10 100644
--- a/gobject/pygpointer.c
+++ b/gobject/pygpointer.c
@@ -67,7 +67,7 @@ pyg_pointer_repr(PyGPointer *self)
 
     g_snprintf(buf, sizeof(buf), "<%s at 0x%lx>", g_type_name(self->gtype),
 	       (long)self->pointer);
-    return _PyUnicode_FromString(buf);
+    return PYGLIB_PyUnicode_FromString(buf);
 }
 
 static int
diff --git a/gobject/pygtype.c b/gobject/pygtype.c
index 2e78ffb..1d8d6e8 100644
--- a/gobject/pygtype.c
+++ b/gobject/pygtype.c
@@ -75,7 +75,7 @@ pyg_type_wrapper_repr(PyGTypeWrapper *self)
 
     g_snprintf(buf, sizeof(buf), "<GType %s (%lu)>",
 	       name?name:"invalid", (unsigned long int) self->type);
-    return _PyUnicode_FromString(buf);
+    return PYGLIB_PyUnicode_FromString(buf);
 }
 
 static void
@@ -148,7 +148,7 @@ static PyObject *
 _wrap_g_type_wrapper__get_name(PyGTypeWrapper *self, void *closure)
 {
    const char *name = g_type_name(self->type);
-   return _PyUnicode_FromString(name ? name : "invalid");
+   return PYGLIB_PyUnicode_FromString(name ? name : "invalid");
 }
 
 static PyObject *
@@ -169,14 +169,14 @@ _wrap_g_type_wrapper__get_children(PyGTypeWrapper *self, void *closure)
   guint n_children, i;
   GType *children;
   PyObject *retval;
-    
+
   children = g_type_children(self->type, &n_children);
 
   retval = PyList_New(n_children);
   for (i = 0; i < n_children; i++)
       PyList_SetItem(retval, i, pyg_type_wrapper_new(children[i]));
   g_free(children);
-  
+
   return retval;
 }
 
@@ -186,21 +186,21 @@ _wrap_g_type_wrapper__get_interfaces(PyGTypeWrapper *self, void *closure)
   guint n_interfaces, i;
   GType *interfaces;
   PyObject *retval;
-    
+
   interfaces = g_type_interfaces(self->type, &n_interfaces);
 
   retval = PyList_New(n_interfaces);
   for (i = 0; i < n_interfaces; i++)
       PyList_SetItem(retval, i, pyg_type_wrapper_new(interfaces[i]));
   g_free(interfaces);
-  
+
   return retval;
 }
 
 static PyObject *
 _wrap_g_type_wrapper__get_depth(PyGTypeWrapper *self, void *closure)
 {
-  return _PyLong_FromLong(g_type_depth(self->type));
+  return PYGLIB_PyLong_FromLong(g_type_depth(self->type));
 }
 
 static PyGetSetDef _PyGTypeWrapper_getsets[] = {
@@ -273,7 +273,7 @@ _wrap_g_type_from_name(PyGTypeWrapper *_, PyObject *args)
 {
     char *type_name;
     GType type;
-    
+
     if (!PyArg_ParseTuple(args, "s:GType.from_name", &type_name))
 	return NULL;
 
@@ -296,7 +296,7 @@ _wrap_g_type_is_a(PyGTypeWrapper *self, PyObject *args)
 	return NULL;
     else if ((parent = pyg_type_from_object(gparent)) == 0)
 	return NULL;
-    
+
     return PyBool_FromLong(g_type_is_a(self->type, parent));
 }
 
@@ -314,14 +314,14 @@ static PyMethodDef _PyGTypeWrapper_methods[] = {
     { "is_a", (PyCFunction)_wrap_g_type_is_a, METH_VARARGS },
     { NULL,  0, 0 }
 };
-    
+
 static int
 pyg_type_wrapper_init(PyGTypeWrapper *self, PyObject *args, PyObject *kwargs)
 {
     static char *kwlist[] = { "object", NULL };
     PyObject *py_object;
     GType type;
-    
+
     if (!PyArg_ParseTupleAndKeywords(args, kwargs,
 				     "O:GType.__init__",
 				     kwlist, &py_object))
@@ -384,7 +384,7 @@ pyg_type_from_object(PyObject *obj)
     if (PyType_Check(obj)) {
 	PyTypeObject *tp = (PyTypeObject *)obj;
 
-	if (tp == &_PyLong_Type)
+	if (tp == &PYGLIB_PyLong_Type)
 	    return G_TYPE_INT;
 	else if (tp == &PyBool_Type)
 	    return G_TYPE_BOOLEAN;
@@ -392,7 +392,7 @@ pyg_type_from_object(PyObject *obj)
 	    return G_TYPE_LONG;
 	else if (tp == &PyFloat_Type)
 	    return G_TYPE_DOUBLE;
-	else if (tp == &_PyUnicode_Type)
+	else if (tp == &PYGLIB_PyUnicode_Type)
 	    return G_TYPE_STRING;
 	else if (tp == &PyBaseObject_Type)
 	    return PY_TYPE_OBJECT;
@@ -403,9 +403,9 @@ pyg_type_from_object(PyObject *obj)
     }
 
     /* handle strings */
-    if (_PyUnicode_Check(obj)) {
-	gchar *name = _PyUnicode_AsString(obj);
-	
+    if (PYGLIB_PyUnicode_Check(obj)) {
+	gchar *name = PYGLIB_PyUnicode_AsString(obj);
+
 	type = _pyg_type_from_name(name);
 	if (type != 0) {
 	    return type;
@@ -454,8 +454,8 @@ pyg_enum_get_value(GType enum_type, PyObject *obj, gint *val)
     if (!obj) {
 	*val = 0;
 	res = 0;
-    } else if (_PyLong_Check(obj)) {
-	*val = _PyLong_AsLong(obj);
+    } else if (PYGLIB_PyLong_Check(obj)) {
+	*val = PYGLIB_PyLong_AsLong(obj);
 	res = 0;
 
 	if (PyObject_TypeCheck(obj, &PyGEnum_Type) && ((PyGEnum *) obj)->gtype != enum_type) {
@@ -473,10 +473,10 @@ pyg_enum_get_value(GType enum_type, PyObject *obj, gint *val)
 		      g_type_name(enum_type),
 		      g_type_name(((PyGEnum *) obj)->gtype));
 	}
-    } else if (_PyUnicode_Check(obj)) {
+    } else if (PYGLIB_PyUnicode_Check(obj)) {
 	GEnumValue *info;
-	char *str = _PyUnicode_AsString(obj);
-	
+	char *str = PYGLIB_PyUnicode_AsString(obj);
+
 	if (enum_type != G_TYPE_NONE)
 	    eclass = G_ENUM_CLASS(g_type_class_ref(enum_type));
 	else {
@@ -527,15 +527,15 @@ pyg_flags_get_value(GType flag_type, PyObject *obj, gint *val)
     if (!obj) {
 	*val = 0;
 	res = 0;
-    } else if (_PyLong_Check(obj)) {
-	*val = _PyLong_AsLong(obj);
+    } else if (PYGLIB_PyLong_Check(obj)) {
+	*val = PYGLIB_PyLong_AsLong(obj);
 	res = 0;
     } else if (PyLong_Check(obj)) {
         *val = PyLong_AsLongLong(obj);
         res = 0;
-    } else if (_PyUnicode_Check(obj)) {
+    } else if (PYGLIB_PyUnicode_Check(obj)) {
 	GFlagsValue *info;
-	char *str = _PyUnicode_AsString(obj);
+	char *str = PYGLIB_PyUnicode_AsString(obj);
 
 	if (flag_type != G_TYPE_NONE)
 	    fclass = G_FLAGS_CLASS(g_type_class_ref(flag_type));
@@ -545,7 +545,7 @@ pyg_flags_get_value(GType flag_type, PyObject *obj, gint *val)
 	}
 	info = g_flags_get_value_by_name(fclass, str);
 	g_type_class_unref(fclass);
-	
+
 	if (!info)
 	    info = g_flags_get_value_by_nick(fclass, str);
 	if (info) {
@@ -571,7 +571,7 @@ pyg_flags_get_value(GType flag_type, PyObject *obj, gint *val)
 
 	for (i = 0; i < len; i++) {
 	    PyObject *item = PyTuple_GetItem(obj, i);
-	    char *str = _PyUnicode_AsString(item);
+	    char *str = PYGLIB_PyUnicode_AsString(item);
 	    GFlagsValue *info = g_flags_get_value_by_name(fclass, str);
 
 	    if (!info)
@@ -658,7 +658,7 @@ pyg_value_array_from_pyobject(GValue *value,
 
     if (pspec && pspec->fixed_n_elements > 0 && len != pspec->fixed_n_elements)
 	return -1;
-	    
+
     value_array = g_value_array_new(len);
 
     for (i = 0; i < len; ++i) {
@@ -746,7 +746,7 @@ pyg_value_from_pyobject(GValue *value, PyObject *obj)
 	break;
     case G_TYPE_CHAR:
 	if ((tmp = PyObject_Str(obj)))
-	    g_value_set_char(value, _PyUnicode_AsString(tmp)[0]);
+	    g_value_set_char(value, PYGLIB_PyUnicode_AsString(tmp)[0]);
 	else {
 	    PyErr_Clear();
 	    return -1;
@@ -754,15 +754,15 @@ pyg_value_from_pyobject(GValue *value, PyObject *obj)
 	Py_DECREF(tmp);
 	break;
     case G_TYPE_UCHAR:
-	if (_PyLong_Check(obj)) {
-	    glong val; 
-	    val = _PyLong_AsLong(obj);
+	if (PYGLIB_PyLong_Check(obj)) {
+	    glong val;
+	    val = PYGLIB_PyLong_AsLong(obj);
 	    if (val >= 0 && val <= 255)
-	      g_value_set_uchar(value, (guchar)_PyLong_AsLong (obj));
+	      g_value_set_uchar(value, (guchar)PYGLIB_PyLong_AsLong (obj));
 	    else
 	      return -1;
 	} else if ((tmp = PyObject_Str(obj))) {
-	    g_value_set_uchar(value, _PyUnicode_AsString(tmp)[0]);
+	    g_value_set_uchar(value, PYGLIB_PyUnicode_AsString(tmp)[0]);
 	    Py_DECREF(tmp);
 	} else {
 	    PyErr_Clear();
@@ -773,14 +773,14 @@ pyg_value_from_pyobject(GValue *value, PyObject *obj)
 	g_value_set_boolean(value, PyObject_IsTrue(obj));
 	break;
     case G_TYPE_INT:
-	g_value_set_int(value, _PyLong_AsLong(obj));
+	g_value_set_int(value, PYGLIB_PyLong_AsLong(obj));
 	break;
     case G_TYPE_UINT:
 	{
-	    if (_PyLong_Check(obj)) {
+	    if (PYGLIB_PyLong_Check(obj)) {
 		glong val;
 
-		val = _PyLong_AsLong(obj);
+		val = PYGLIB_PyLong_AsLong(obj);
 		if (val >= 0 && val <= G_MAXUINT)
 		    g_value_set_uint(value, (guint)val);
 		else
@@ -791,14 +791,14 @@ pyg_value_from_pyobject(GValue *value, PyObject *obj)
 	}
 	break;
     case G_TYPE_LONG:
-	g_value_set_long(value, _PyLong_AsLong(obj));
+	g_value_set_long(value, PYGLIB_PyLong_AsLong(obj));
 	break;
     case G_TYPE_ULONG:
 	{
-	    if (_PyLong_Check(obj)) {
+	    if (PYGLIB_PyLong_Check(obj)) {
 		glong val;
 
-		val = _PyLong_AsLong(obj);
+		val = PYGLIB_PyLong_AsLong(obj);
 		if (val >= 0)
 		    g_value_set_ulong(value, (gulong)val);
 		else
@@ -857,7 +857,7 @@ pyg_value_from_pyobject(GValue *value, PyObject *obj)
 	if (obj == Py_None)
 	    g_value_set_string(value, NULL);
 	else if ((tmp = PyObject_Str(obj))) {
-	    g_value_set_string(value, _PyUnicode_AsString(tmp));
+	    g_value_set_string(value, PYGLIB_PyUnicode_AsString(tmp));
 	    Py_DECREF(tmp);
 	} else {
 	    PyErr_Clear();
@@ -887,8 +887,8 @@ pyg_value_from_pyobject(GValue *value, PyObject *obj)
 	    g_value_set_boxed(value, pyg_boxed_get(obj, gpointer));
         else if (G_VALUE_HOLDS(value, G_TYPE_VALUE)) {
             GType type;
-            GValue *n_value; 
-            
+            GValue *n_value;
+
             type = pyg_type_from_object((PyObject*)Py_TYPE(obj));
             if (G_UNLIKELY (! type)) {
                 PyErr_Clear();
@@ -902,12 +902,12 @@ pyg_value_from_pyobject(GValue *value, PyObject *obj)
         else if (PySequence_Check(obj) &&
 		   G_VALUE_HOLDS(value, G_TYPE_VALUE_ARRAY))
 	    return pyg_value_array_from_pyobject(value, obj, NULL);
-	else if (_PyUnicode_Check(obj) &&
+	else if (PYGLIB_PyUnicode_Check(obj) &&
                  G_VALUE_HOLDS(value, G_TYPE_GSTRING)) {
             GString *string;
             char *buffer;
             Py_ssize_t len;
-            if (_PyUnicode_AsStringAndSize(obj, &buffer, &len))
+            if (PYGLIB_PyUnicode_AsStringAndSize(obj, &buffer, &len))
                 return -1;
             string = g_string_new_len(buffer, len);
 	    g_value_set_boxed(value, string);
@@ -977,17 +977,17 @@ pyg_value_as_pyobject(const GValue *value, gboolean copy_boxed)
 	    break;
     case G_TYPE_CHAR: {
 	gint8 val = g_value_get_char(value);
-	return _PyUnicode_FromStringAndSize((char *)&val, 1);
+	return PYGLIB_PyUnicode_FromStringAndSize((char *)&val, 1);
     }
     case G_TYPE_UCHAR: {
 	guint8 val = g_value_get_uchar(value);
-	return _PyUnicode_FromStringAndSize((char *)&val, 1);
+	return PYGLIB_PyUnicode_FromStringAndSize((char *)&val, 1);
     }
     case G_TYPE_BOOLEAN: {
 	return PyBool_FromLong(g_value_get_boolean(value));
     }
     case G_TYPE_INT:
-	return _PyLong_FromLong(g_value_get_int(value));
+	return PYGLIB_PyLong_FromLong(g_value_get_int(value));
     case G_TYPE_UINT:
 	{
 	    /* in Python, the Int object is backed by a long.  If a
@@ -995,19 +995,19 @@ pyg_value_as_pyobject(const GValue *value, gboolean copy_boxed)
 	       an Int.  Otherwise, use a Long object to avoid overflow.
 	       This matches the ULongArg behavior in codegen/argtypes.h */
 #if (G_MAXUINT <= G_MAXLONG)
-	    return _PyLong_FromLong((glong) g_value_get_uint(value));
+	    return PYGLIB_PyLong_FromLong((glong) g_value_get_uint(value));
 #else
 	    return PyLong_FromUnsignedLong((gulong) g_value_get_uint(value));
 #endif
 	}
     case G_TYPE_LONG:
-	return _PyLong_FromLong(g_value_get_long(value));
+	return PYGLIB_PyLong_FromLong(g_value_get_long(value));
     case G_TYPE_ULONG:
 	{
 	    gulong val = g_value_get_ulong(value);
 
 	    if (val <= G_MAXLONG)
-		return _PyLong_FromLong((glong) val);
+		return PYGLIB_PyLong_FromLong((glong) val);
 	    else
 		return PyLong_FromUnsignedLong(val);
 	}
@@ -1016,7 +1016,7 @@ pyg_value_as_pyobject(const GValue *value, gboolean copy_boxed)
 	    gint64 val = g_value_get_int64(value);
 
 	    if (G_MINLONG <= val && val <= G_MAXLONG)
-		return _PyLong_FromLong((glong) val);
+		return PYGLIB_PyLong_FromLong((glong) val);
 	    else
 		return PyLong_FromLongLong(val);
 	}
@@ -1025,7 +1025,7 @@ pyg_value_as_pyobject(const GValue *value, gboolean copy_boxed)
 	    guint64 val = g_value_get_uint64(value);
 
 	    if (val <= G_MAXLONG)
-		return _PyLong_FromLong((glong) val);
+		return PYGLIB_PyLong_FromLong((glong) val);
 	    else
 		return PyLong_FromUnsignedLongLong(val);
 	}
@@ -1042,7 +1042,7 @@ pyg_value_as_pyobject(const GValue *value, gboolean copy_boxed)
 	    const gchar *str = g_value_get_string(value);
 
 	    if (str)
-		return _PyUnicode_FromString(str);
+		return PYGLIB_PyUnicode_FromString(str);
 	    Py_INCREF(Py_None);
 	    return Py_None;
 	}
@@ -1072,9 +1072,9 @@ pyg_value_as_pyobject(const GValue *value, gboolean copy_boxed)
 	    return ret;
 	} else if (G_VALUE_HOLDS(value, G_TYPE_GSTRING)) {
 	    GString *string = (GString *) g_value_get_boxed(value);
-	    PyObject *ret = _PyUnicode_FromStringAndSize(string->str, string->len);
+	    PyObject *ret = PYGLIB_PyUnicode_FromStringAndSize(string->str, string->len);
 	    return ret;
-	}	    
+	}
 	bm = pyg_type_lookup(G_VALUE_TYPE(value));
 	if (bm) {
 	    return bm->fromvalue(value);
@@ -1171,18 +1171,18 @@ pyg_closure_marshal(GClosure *closure,
 	    PyErr_Print();
 	goto out;
     }
-    
+
     if (return_value && pyg_value_from_pyobject(return_value, ret) != 0) {
 	PyErr_SetString(PyExc_TypeError,
 			"can't convert return value to desired type");
-	
+
 	if (pc->exception_handler)
 	    pc->exception_handler(return_value, n_param_values, param_values);
 	else
 	    PyErr_Print();
     }
     Py_DECREF(ret);
-    
+
  out:
     Py_DECREF(params);
     pyglib_gil_state_release(state);
@@ -1234,7 +1234,7 @@ pyg_closure_new(PyObject *callback, PyObject *extra_args, PyObject *swap_data)
  * @handler: the handler to call when an exception occurs or NULL for none
  *
  * Sets the handler to call when an exception occurs during closure invocation.
- * The handler is responsible for providing a proper return value to the 
+ * The handler is responsible for providing a proper return value to the
  * closure invocation. If @handler is %NULL, the default handler will be used.
  * The default handler prints the exception to stderr and doesn't touch the
  * closure's return value.
@@ -1244,7 +1244,7 @@ pyg_closure_set_exception_handler(GClosure *closure,
 				  PyClosureExceptionHandler handler)
 {
     PyGClosure *pygclosure;
-    
+
     g_return_if_fail(closure != NULL);
 
     pygclosure = (PyGClosure *)closure;
@@ -1279,7 +1279,7 @@ pyg_signal_class_closure_marshal(GClosure *closure,
     guint i, len;
 
     state = pyglib_gil_state_ensure();
-    
+
     g_return_if_fail(invocation_hint != NULL);
     /* get the object passed as the first argument to the closure */
     object = g_value_get_object(&param_values[0]);
@@ -1325,10 +1325,10 @@ pyg_signal_class_closure_marshal(GClosure *closure,
     }
 
     ret = PyObject_CallObject(method, params);
-    
+
     /* Copy boxed values if others ref them, this needs to be done regardless of
        exception status. */
-    len = PyTuple_Size(params);    
+    len = PyTuple_Size(params);
     for (i = 0; i < len; i++) {
 	PyObject *item = PyTuple_GetItem(params, i);
 	if (item != NULL && PyObject_TypeCheck(item, &PyGBoxed_Type)
@@ -1478,7 +1478,7 @@ add_property_docs(GType gtype, GString *string)
 			       g_type_name(props[i]->value_type),
 			       g_param_spec_get_nick(props[i]));
 
-	/* g_string_append_printf crashes on win32 if the third 
+	/* g_string_append_printf crashes on win32 if the third
 	   argument is NULL. */
 	blurb=g_param_spec_get_blurb(props[i]);
 	if (blurb)
@@ -1528,7 +1528,7 @@ object_doc_descr_get(PyObject *self, PyObject *obj, PyObject *type)
             g_array_append_val(parents, parent);
             parent = g_type_next_base(gtype, parent);
         }
-        
+
         for (iparent = parents->len - 1; iparent >= 0; --iparent) {
 	    GType *interfaces;
 	    guint n_interfaces, i;
@@ -1546,7 +1546,7 @@ object_doc_descr_get(PyObject *self, PyObject *obj, PyObject *type)
         g_array_free(parents, TRUE);
     }
 
-    pystring = _PyUnicode_FromStringAndSize(string->str, string->len);
+    pystring = PYGLIB_PyUnicode_FromStringAndSize(string->str, string->len);
     g_string_free(string, TRUE);
     return pystring;
 }
@@ -1596,7 +1596,7 @@ int pyg_pyobj_to_unichar_conv(PyObject* py_obj, void* ptr)
     gunichar* u = ptr;
     const Py_UNICODE* uni_buffer;
     PyObject* tmp_uni = NULL;
-    
+
     if (PyUnicode_Check(py_obj)) {
 	tmp_uni = py_obj;
 	Py_INCREF(tmp_uni);
@@ -1606,7 +1606,7 @@ int pyg_pyobj_to_unichar_conv(PyObject* py_obj, void* ptr)
 	if (tmp_uni == NULL)
 	    goto failure;
     }
-    
+
     if ( PyUnicode_GetSize(tmp_uni) != 1) {
 	PyErr_SetString(PyExc_ValueError, "unicode character value must be 1 character uniode string");
 	goto failure;
@@ -1615,24 +1615,24 @@ int pyg_pyobj_to_unichar_conv(PyObject* py_obj, void* ptr)
     if ( uni_buffer == NULL)
 	goto failure;
     *u = uni_buffer[0];
-    
+
     Py_DECREF(tmp_uni);
     return 1;
-    
+
   failure:
     Py_XDECREF(tmp_uni);
     return 0;
 }
 
 
-int 
-pyg_param_gvalue_from_pyobject(GValue* value, 
-                               PyObject* py_obj, 
+int
+pyg_param_gvalue_from_pyobject(GValue* value,
+                               PyObject* py_obj,
 			       const GParamSpec* pspec)
 {
     if (G_IS_PARAM_SPEC_UNICHAR(pspec)) {
 	gunichar u;
-	
+
 	if (!pyg_pyobj_to_unichar_conv(py_obj, &u)) {
 	    PyErr_Clear();
 	    return -1;
@@ -1648,15 +1648,15 @@ pyg_param_gvalue_from_pyobject(GValue* value,
     }
 }
 
-PyObject* 
+PyObject*
 pyg_param_gvalue_as_pyobject(const GValue* gvalue,
-                             gboolean copy_boxed, 
+                             gboolean copy_boxed,
 			     const GParamSpec* pspec)
 {
     if (G_IS_PARAM_SPEC_UNICHAR(pspec)) {
 	gunichar u;
 	Py_UNICODE uni_buffer[2] = { 0, 0 };
-	
+
 	u = g_value_get_uint(gvalue);
 	uni_buffer[0] = u;
 	return PyUnicode_FromUnicode(uni_buffer, 1);
@@ -1677,7 +1677,7 @@ typedef struct {
     gpointer data;
 } CustomTypeData;
 
-void 
+void
 pyg_type_register_custom_callback(const gchar *typename,
 				  PyGTypeRegistrationFunction callback,
 				  gpointer user_data)
@@ -1702,7 +1702,7 @@ pyg_type_get_custom(const gchar *name)
 {
     CustomTypeData *data;
     PyTypeObject *retval;
-    
+
     if (!custom_type_registration)
 	return NULL;
 
@@ -1727,7 +1727,7 @@ _pyg_type_from_name(const gchar *name)
 	pyg_type_get_custom(name);
 	type = g_type_from_name(name);
     }
-    
+
     return type;
 }
 
@@ -1744,7 +1744,7 @@ _pyg_strv_from_gvalue(const GValue *value)
     }
     py_argv = PyList_New(argc);
     for (i = 0; i < argc; ++i)
-	PyList_SET_ITEM(py_argv, i, _PyUnicode_FromString(argv[i]));
+	PyList_SET_ITEM(py_argv, i, PYGLIB_PyUnicode_FromString(argv[i]));
     return py_argv;
 }
 
@@ -1759,11 +1759,11 @@ _pyg_strv_to_gvalue(GValue *value, PyObject *obj)
 
     argc = PySequence_Length(obj);
     for (i = 0; i < argc; ++i)
-	if (!_PyUnicode_Check(PySequence_Fast_GET_ITEM(obj, i)))
+	if (!PYGLIB_PyUnicode_Check(PySequence_Fast_GET_ITEM(obj, i)))
 	    return -1;
     argv = g_new(gchar *, argc + 1);
     for (i = 0; i < argc; ++i)
-	argv[i] = g_strdup(_PyUnicode_AsString(PySequence_Fast_GET_ITEM(obj, i)));
+	argv[i] = g_strdup(PYGLIB_PyUnicode_AsString(PySequence_Fast_GET_ITEM(obj, i)));
     argv[i] = NULL;
     g_value_take_boxed(value, argv);
     return 0;
@@ -1786,7 +1786,7 @@ pygobject_type_register_types(PyObject *d)
     PyGObjectDoc_Type.tp_dealloc = (destructor)object_doc_dealloc;
     PyGObjectDoc_Type.tp_flags = Py_TPFLAGS_DEFAULT;
     PyGObjectDoc_Type.tp_descr_get = (descrgetfunc)object_doc_descr_get;
-    
+
     pyg_register_gtype_custom(G_TYPE_STRV,
 			      _pyg_strv_from_gvalue,
 			      _pyg_strv_to_gvalue);



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]