pygobject r870 - in trunk: . glib



Author: johan
Date: Sat Jul 26 13:23:28 2008
New Revision: 870
URL: http://svn.gnome.org/viewvc/pygobject?rev=870&view=rev

Log:
2008-07-26  Johan Dahlin  <johan gnome org>

    * glib/glibmodule.c (get_handler_priority), (pyglib_idle_add),
    (pyglib_timeout_add), (pyglib_timeout_add_seconds),
    (pyglib_io_add_watch), (pyglib_child_watch_add),
    (pyglib_markup_escape_text), (pyglib_main_depth),
    (pyglib_filename_from_utf8), (pyglib_get_application_name),
    (pyglib_get_prgname), (PYGLIB_MODULE_START):
    * glib/pygiochannel.c (py_io_channel_next),
    (py_io_channel_shutdown), (py_io_channel_get_buffer_size),
    (py_io_channel_get_buffered), (py_io_channel_get_encoding),
    (py_io_channel_read_chars), (py_io_channel_write_chars),
    (py_io_channel_write_lines), (py_io_channel_flush),
    (py_io_channel_set_flags), (py_io_channel_get_flags),
    (py_io_channel_get_buffer_condition), (py_io_channel_win32_poll),
    (py_io_channel_read_line), (py_io_channel_read_lines),
    (py_io_channel_seek), (pyglib_iochannel_register_types):
    * glib/pyglib-private.h:
    * glib/pyglib-python-compat.h:
    * glib/pyglib.c (pyglib_init), (pyglib_error_check),
    (pyglib_gerror_exception_check),
    (pyglib_register_exception_for_domain):
    Add macros for supporting additional python versions.
    Start using them for the glib module. Tested on python 2.5 and 3.0.



Added:
   trunk/glib/pyglib-python-compat.h
Modified:
   trunk/ChangeLog
   trunk/glib/Makefile.am
   trunk/glib/glibmodule.c
   trunk/glib/pygiochannel.c
   trunk/glib/pyglib-private.h
   trunk/glib/pyglib.c

Modified: trunk/glib/Makefile.am
==============================================================================
--- trunk/glib/Makefile.am	(original)
+++ trunk/glib/Makefile.am	Sat Jul 26 13:23:28 2008
@@ -21,10 +21,11 @@
 
 libpyglib_2_0_la_CFLAGS = $(GLIB_CFLAGS)
 libpyglib_2_0_la_LIBADD = $(GLIB_LIBS) $(FFI_LIBS)
-libpyglib_2_0_la_SOURCES = \
-	pyglib.c	\
-	pyglib.h	\
-	pyglib-private.h
+libpyglib_2_0_la_SOURCES = 	\
+	pyglib.c		\
+	pyglib.h		\
+	pyglib-private.h 	\
+	pyglib-python-compat.h
 
 _glib_la_CFLAGS = $(GLIB_CFLAGS)
 _glib_la_LDFLAGS = $(common_ldflags) -export-symbols-regex init_glib

Modified: trunk/glib/glibmodule.c
==============================================================================
--- trunk/glib/glibmodule.c	(original)
+++ trunk/glib/glibmodule.c	Sat Jul 26 13:23:28 2008
@@ -68,19 +68,19 @@
     }
     pos = 0;
     PyDict_Next(kwargs, &pos, &key, &val);
-    if (!PyString_Check(key)) {
+    if (!_PyUnicode_Check(key)) {
 	PyErr_SetString(PyExc_TypeError,
 			"keyword argument name is not a string");
 	return -1;
     }
 
-    if (strcmp(PyString_AsString(key), "priority") != 0) {
+    if (strcmp(_PyUnicode_AsString(key), "priority") != 0) {
 	PyErr_SetString(PyExc_TypeError,
 			"only 'priority' keyword argument accepted");
 	return -1;
     }
 
-    *priority = PyInt_AsLong(val);
+    *priority = _PyLong_AsLong(val);
     if (PyErr_Occurred()) {
 	PyErr_Clear();
 	PyErr_SetString(PyExc_ValueError, "could not get priority value");
@@ -125,7 +125,7 @@
     handler_id = g_idle_add_full(priority,
 				 _pyglib_handler_marshal, data,
 				 _pyglib_destroy_notify);
-    return PyInt_FromLong(handler_id);
+    return _PyLong_FromLong(handler_id);
 }
 
 
@@ -165,7 +165,7 @@
     handler_id = g_timeout_add_full(priority, interval,
 				    _pyglib_handler_marshal, data,
 				    _pyglib_destroy_notify);
-    return PyInt_FromLong(handler_id);
+    return _PyLong_FromLong(handler_id);
 }
 
 static PyObject *
@@ -204,7 +204,7 @@
     handler_id = g_timeout_add_seconds_full(priority, interval,
                                             _pyglib_handler_marshal, data,
                                             _pyglib_destroy_notify);
-    return PyInt_FromLong(handler_id);
+    return _PyLong_FromLong(handler_id);
 }
 
 static gboolean
@@ -294,7 +294,7 @@
 				     (GDestroyNotify)_pyglib_destroy_notify);
     g_io_channel_unref(iochannel);
     
-    return PyInt_FromLong(handler_id);
+    return _PyLong_FromLong(handler_id);
 }
 
 static PyObject *
@@ -374,7 +374,7 @@
         Py_INCREF(child_data->data);
     id = g_child_watch_add_full(priority, pid, child_watch_func,
                                 child_data, child_watch_dnotify);
-    return PyInt_FromLong(id);
+    return _PyLong_FromLong(id);
 }
 
 static PyObject *
@@ -391,7 +391,7 @@
         return NULL;
 
     text_out = g_markup_escape_text(text_in, text_size);
-    retval = PyString_FromString(text_out);
+    retval = _PyUnicode_FromString(text_out);
     g_free(text_out);
     return retval;
 }
@@ -410,7 +410,7 @@
 static PyObject *
 pyglib_main_depth(PyObject *unused)
 {
-    return PyInt_FromLong(g_main_depth());
+    return _PyLong_FromLong(g_main_depth());
 }
 
 static PyObject *
@@ -463,7 +463,7 @@
         g_free(filename);
         return NULL;
     }
-    py_filename = PyString_FromStringAndSize(filename, bytes_written);
+    py_filename = _PyUnicode_FromStringAndSize(filename, bytes_written);
     g_free(filename);
     return py_filename;
 }
@@ -479,7 +479,7 @@
         Py_INCREF(Py_None);
         return Py_None;
     }
-    return PyString_FromString(name);
+    return _PyUnicode_FromString(name);
 }
 
 static PyObject*
@@ -504,7 +504,7 @@
         Py_INCREF(Py_None);
         return Py_None;
     }
-    return PyString_FromString(name);
+    return _PyUnicode_FromString(name);
 }
 
 static PyObject*
@@ -520,7 +520,7 @@
 }
 
 
-static PyMethodDef pyglib_functions[] = {
+static PyMethodDef _glib_functions[] = {
     { "spawn_async",
       (PyCFunction)pyglib_spawn_async, METH_VARARGS|METH_KEYWORDS },
     { "main_context_default",
@@ -710,15 +710,11 @@
 			       (char*) g_quark_to_string(G_OPTION_ERROR));
 }
 
-DL_EXPORT(void)
-init_glib(void)
+PYGLIB_MODULE_START(_glib, "glib._glib")
 {
-    PyObject *m, *d;
+    PyObject *d = PyModule_GetDict(module);
 
-    m = Py_InitModule("glib._glib", pyglib_functions);
-    pyglib_register_constants(m);
-
-    d = PyModule_GetDict(m);
+    pyglib_register_constants(module);
     pyglib_register_api(d);
     pyglib_register_error(d);
     pyglib_register_version_tuples(d);
@@ -730,3 +726,4 @@
     pyglib_option_context_register_types(d);
     pyglib_option_group_register_types(d);
 }
+PYGLIB_MODULE_END

Modified: trunk/glib/pygiochannel.c
==============================================================================
--- trunk/glib/pygiochannel.c	(original)
+++ trunk/glib/pygiochannel.c	Sat Jul 26 13:23:28 2008
@@ -17,6 +17,8 @@
     int softspace;         /* to make print >> chan, "foo" ... work */
 } PyGIOChannel;
 
+PYGLIB_DEFINE_TYPE("gobject.IOChannel", PyGIOChannel_Type, PyGIOChannel)
+
 static PyObject*
 py_io_channel_next(PyGIOChannel *self)
 {
@@ -36,10 +38,9 @@
         return NULL;
     }
 
-    ret_obj = PyString_FromStringAndSize(str_return, length);
+    ret_obj = _PyUnicode_FromStringAndSize(str_return, length);
     g_free(str_return);
     return ret_obj;
-
 }
 
 static int
@@ -86,7 +87,7 @@
     if (pyglib_error_check(&error))
 	return NULL;
 	
-    return PyInt_FromLong(ret);
+    return _PyLong_FromLong(ret);
 }
 
 /* character encoding conversion involved functions.
@@ -118,7 +119,7 @@
 	
     size = g_io_channel_get_buffer_size(self->channel);
     
-    return PyInt_FromLong(size);
+    return _PyLong_FromLong(size);
 }
 
 static PyObject*
@@ -147,7 +148,7 @@
 	
     buffered = g_io_channel_get_buffered(self->channel);
     
-    return PyInt_FromLong(buffered);
+    return _PyLong_FromLong(buffered);
 }
 
 static PyObject*
@@ -184,7 +185,7 @@
 	return Py_None;
     }
 
-    return PyString_FromString(encoding);
+    return _PyUnicode_FromString(encoding);
 }
 
 #define CHUNK_SIZE (8 * 1024)
@@ -203,7 +204,7 @@
         return NULL;
 	
     if (max_count == 0)
-	return PyString_FromString("");
+	return _PyUnicode_FromString("");
     
     while (status == G_IO_STATUS_NORMAL
 	   && (max_count == -1 || total_read < max_count)) {
@@ -220,16 +221,16 @@
         }
 	
 	if ( ret_obj == NULL ) {
-	    ret_obj = PyString_FromStringAndSize((char *)NULL, buf_size);
+	    ret_obj = _PyUnicode_FromStringAndSize((char *)NULL, buf_size);
 	    if (ret_obj == NULL)
 		goto failure;
 	}
-	else if (buf_size + total_read > PyString_GET_SIZE(ret_obj)) {
-	    if (_PyString_Resize(&ret_obj, buf_size + total_read) == -1)
+	else if (buf_size + total_read > _PyUnicode_GET_SIZE(ret_obj)) {
+	    if (_PyUnicode_Resize(&ret_obj, buf_size + total_read) == -1)
 		goto failure;
 	}
        
-        buf = PyString_AS_STRING(ret_obj) + total_read;
+        buf = _PyUnicode_AS_STRING(ret_obj) + total_read;
 
         pyglib_unblock_threads();
         status = g_io_channel_read_chars(self->channel, buf, buf_size, 
@@ -241,8 +242,8 @@
 	total_read += single_read;
     }
 	
-    if ( total_read != PyString_GET_SIZE(ret_obj) ) {
-	if (_PyString_Resize(&ret_obj, total_read) == -1)
+    if ( total_read != _PyUnicode_GET_SIZE(ret_obj) ) {
+	if (_PyUnicode_Resize(&ret_obj, total_read) == -1)
 	    goto failure;
     }
     return ret_obj;
@@ -272,7 +273,7 @@
     if (pyglib_error_check(&error))
 	return NULL;
 	
-    return PyInt_FromLong(count);
+    return _PyLong_FromLong(count);
 }
 
 static PyObject*
@@ -298,13 +299,13 @@
             PyErr_Clear();
             goto normal_exit;
         }
-        if (!PyString_Check(value)) {
+        if (!_PyUnicode_Check(value)) {
             PyErr_SetString(PyExc_TypeError, "gobject.IOChannel.writelines must"
                             " be sequence/iterator of strings");
             Py_DECREF(iter);
             return NULL;
         }
-        PyString_AsStringAndSize(value, &buf, &buf_len);
+        _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();
@@ -337,7 +338,7 @@
     if (pyglib_error_check(&error))
 	return NULL;
 	
-    return PyInt_FromLong(status);
+    return _PyLong_FromLong(status);
 }
 
 static PyObject*
@@ -356,7 +357,7 @@
     if (pyglib_error_check(&error))
 	return NULL;
 	
-    return PyInt_FromLong(status);
+    return _PyLong_FromLong(status);
 }
 
 static PyObject*
@@ -370,7 +371,7 @@
         return NULL;
 	
     flags = g_io_channel_get_flags(self->channel);
-    return PyInt_FromLong(flags);
+    return _PyLong_FromLong(flags);
 }
 
 static PyObject*
@@ -384,7 +385,7 @@
         return NULL;
 	
     cond = g_io_channel_get_buffer_condition(self->channel);
-    return PyInt_FromLong(cond);
+    return _PyLong_FromLong(cond);
 }
 
 static PyObject*
@@ -535,7 +536,7 @@
         pyfd = PyList_GET_ITEM(pyfds, i);
         ((PyGPollFD *) pyfd)->pollfd = pollfd[i];
     }
-    return PyInt_FromLong(result);
+    return _PyLong_FromLong(result);
 }
 
 static PyObject *
@@ -579,7 +580,7 @@
                                     &terminator_pos, &error);
     if (pyglib_error_check(&error))
         return NULL;
-    ret_obj = PyString_FromStringAndSize(str_return, length);
+    ret_obj = _PyUnicode_FromStringAndSize(str_return, length);
     g_free(str_return);
     return ret_obj;
 }
@@ -608,7 +609,7 @@
             Py_DECREF(line);
             return NULL;
         }
-        line = PyString_FromStringAndSize(str_return, length);
+        line = _PyUnicode_FromStringAndSize(str_return, length);
         g_free(str_return);
         if (PyList_Append(list, line)) {
             Py_DECREF(line);
@@ -649,7 +650,7 @@
     if (pyglib_error_check(&error))
 	return NULL;
 	
-    return PyInt_FromLong(status);
+    return _PyLong_FromLong(status);
 }
 
 #if 0 // Not wrapped
@@ -764,55 +765,18 @@
     return 0;
 }
 
-
-PyTypeObject PyGIOChannel_Type = {
-    PyObject_HEAD_INIT(NULL)
-    0,					/* ob_size */
-    "gobject.IOChannel",		/* tp_name */
-    sizeof(PyGIOChannel),		/* tp_basicsize */
-    0,					/* tp_itemsize */
-    /* methods */
-    (destructor)py_io_channel_dealloc,	/* tp_dealloc */
-    (printfunc)0,			/* tp_print */
-    (getattrfunc)NULL,             	/* tp_getattr */
-    (setattrfunc)0,			/* tp_setattr */
-    (cmpfunc)py_io_channel_compare,	/* tp_compare */
-    (reprfunc)0,			/* tp_repr */
-    0,					/* tp_as_number */
-    0,					/* tp_as_sequence */
-    0,					/* tp_as_mapping */
-    (hashfunc)py_io_channel_hash,	/* tp_hash */
-    (ternaryfunc)0,			/* tp_call */
-    (reprfunc)0,			/* tp_str */
-    (getattrofunc)0,			/* tp_getattro */
-    (setattrofunc)0,			/* tp_setattro */
-    0,					/* tp_as_buffer */
-    Py_TPFLAGS_DEFAULT,			/* tp_flags */
-    NULL, /* Documentation string */
-    (traverseproc)0,			/* tp_traverse */
-    (inquiry)0,				/* tp_clear */
-    (richcmpfunc)0,			/* tp_richcompare */
-    0,					/* tp_weaklistoffset */
-    (getiterfunc)py_io_channel_get_iter,/* tp_iter */
-    (iternextfunc)py_io_channel_next,   /* tp_iternext */
-    py_io_channel_methods,		/* tp_methods */
-    py_io_channel_members,		/* tp_members */
-    NULL,				/* tp_getset */
-    (PyTypeObject *)0,			/* tp_base */
-    (PyObject *)0,			/* tp_dict */
-    0,					/* tp_descr_get */
-    0,					/* tp_descr_set */
-    0,					/* tp_dictoffset */
-    (initproc)py_io_channel_init,	/* tp_init */
-    (allocfunc)0,			/* tp_alloc */
-    (newfunc)0,				/* tp_new */
-    0,					/* tp_free */
-    (inquiry)0,				/* tp_is_gc */
-    (PyObject *)0,			/* tp_bases */
-};
-
 void
 pyglib_iochannel_register_types(PyObject *d)
 {
+    PyGIOChannel_Type.tp_init = (initproc)py_io_channel_init;
+    PyGIOChannel_Type.tp_dealloc = (destructor)py_io_channel_dealloc;
+    PyGIOChannel_Type.tp_flags = Py_TPFLAGS_DEFAULT;
+    PyGIOChannel_Type.tp_members = py_io_channel_members;
+    PyGIOChannel_Type.tp_methods = py_io_channel_methods;
+    PyGIOChannel_Type.tp_hash = (hashfunc)py_io_channel_hash;
+    PyGIOChannel_Type.tp_compare = (cmpfunc)py_io_channel_compare;
+    PyGIOChannel_Type.tp_iter = (getiterfunc)py_io_channel_get_iter;
+    PyGIOChannel_Type.tp_iternext = (iternextfunc)py_io_channel_next;
+
     PYGLIB_REGISTER_TYPE(d, PyGIOChannel_Type, "IOChannel");
 }

Modified: trunk/glib/pyglib-private.h
==============================================================================
--- trunk/glib/pyglib-private.h	(original)
+++ trunk/glib/pyglib-private.h	Sat Jul 26 13:23:28 2008
@@ -25,12 +25,9 @@
 #include <Python.h>
 #include <glib.h>
 
-G_BEGIN_DECLS
+#include <pyglib-python-compat.h>
 
-/* Compilation on Python 2.4 */
-#if PY_VERSION_HEX < 0x02050000
-typedef int Py_ssize_t;
-#endif
+G_BEGIN_DECLS
 
 struct _PyGLib_Functions {
     gboolean threads_enabled;
@@ -39,16 +36,6 @@
     PyGLibThreadBlockFunc unblock_threads;
 };
 
-#define PYGLIB_REGISTER_TYPE(d, type, name)	\
-    type.ob_type = &PyType_Type; \
-    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);
-
 gboolean _pyglib_handler_marshal(gpointer user_data);
 void _pyglib_destroy_notify(gpointer user_data);
 

Added: trunk/glib/pyglib-python-compat.h
==============================================================================
--- (empty file)
+++ trunk/glib/pyglib-python-compat.h	Sat Jul 26 13:23:28 2008
@@ -0,0 +1,110 @@
+/* -*- Mode: C; c-basic-offset: 4 -*-
+ * pyglib - Python bindings for GLib toolkit.
+ * Copyright (C) 2008  Johan Dahlin
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
+ * USA
+ */
+
+#ifndef __PYGLIB_PYTHON_COMPAT_H__
+#define __PYGLIB_PYTHON_COMPAT_H__
+
+/* Compilation on Python 2.4 */
+#if PY_VERSION_HEX < 0x02050000
+typedef int Py_ssize_t;
+#endif
+
+/* Compilation on Python 2.x */
+#if PY_VERSION_HEX < 0x03000000
+#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)                                     \
+};
+#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);
+
+#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_AS_STRING PyString_AS_STRING
+#define _PyUnicode_GET_SIZE PyString_GET_SIZE
+#define _PyUnicode_Resize _PyString_Resize
+#define _PyLong_Check PyInt_Check
+#define _PyLong_FromLong PyInt_FromLong
+#define _PyLong_AsLong  PyInt_AsLong
+#else
+#define PYGLIB_MODULE_START(symbol, modname)	        \
+    static struct PyModuleDef _##symbol##module = {     \
+    PyModuleDef_HEAD_INIT,                              \
+    modname,                                            \
+    NULL,                                               \
+    -1,                                                 \
+    symbol##_functions,                                 \
+    NULL,                                               \
+    NULL,                                               \
+    NULL,                                               \
+    NULL                                                \
+};                                                      \
+PyMODINIT_FUNC PyInit_##symbol(void)                    \
+{                                                       \
+    PyObject *module;                                   \
+    module = PyModule_Create(&_##symbol##module);
+#define PYGLIB_MODULE_END return module; }
+#define PYGLIB_DEFINE_TYPE(typename, symbol, csymbol)	\
+PyTypeObject symbol = {                                 \
+    PyVarObject_HEAD_INIT(NULL, 0)                      \
+    typename,                                           \
+    sizeof(csymbol)                                     \
+};
+#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);
+
+#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_AS_STRING _PyUnicode_AsString
+#define _PyUnicode_GET_SIZE PyUnicode_GET_SIZE
+#define _PyUnicode_Resize PyUnicode_Resize
+#define _PyLong_Check PyLong_Check
+#define _PyLong_FromLong PyLong_FromLong
+#define _PyLong_AsLong PyLong_AsLong
+#endif
+
+#endif /* __PYGLIB_PYTHON_COMPAT_H__ */

Modified: trunk/glib/pyglib.c
==============================================================================
--- trunk/glib/pyglib.c	(original)
+++ trunk/glib/pyglib.c	Sat Jul 26 13:23:28 2008
@@ -61,7 +61,7 @@
 	    Py_XDECREF(traceback);
 	    PyErr_Format(PyExc_ImportError,
 			 "could not import glib (error was: %s)",
-			 PyString_AsString(py_orig_exc));
+			 _PyUnicode_AsString(py_orig_exc));
 	    Py_DECREF(py_orig_exc);
         } else
 	    PyErr_SetString(PyExc_ImportError,
@@ -232,23 +232,23 @@
     if (exception_table != NULL)
     {
 	PyObject *item;
-	item = PyDict_GetItem(exception_table, PyInt_FromLong((*error)->domain));
+	item = PyDict_GetItem(exception_table, _PyLong_FromLong((*error)->domain));
 	if (item != NULL)
 	    exc_type = item;
     }
 
     exc_instance = PyObject_CallFunction(exc_type, "z", (*error)->message);
     PyObject_SetAttrString(exc_instance, "domain",
-			   d=PyString_FromString(g_quark_to_string((*error)->domain)));
+			   d=_PyUnicode_FromString(g_quark_to_string((*error)->domain)));
     Py_DECREF(d);
 
     PyObject_SetAttrString(exc_instance, "code",
-			   d=PyInt_FromLong((*error)->code));
+			   d=_PyLong_FromLong((*error)->code));
     Py_DECREF(d);
 
     if ((*error)->message) {
 	PyObject_SetAttrString(exc_instance, "message",
-			       d=PyString_FromString((*error)->message));
+			       d=_PyUnicode_FromString((*error)->message));
 	Py_DECREF(d);
     } else {
 	PyObject_SetAttrString(exc_instance, "message", Py_None);
@@ -301,28 +301,28 @@
     Py_XDECREF(traceback);
 
     py_message = PyObject_GetAttrString(value, "message");
-    if (!py_message || !PyString_Check(py_message)) {
+    if (!py_message || !_PyUnicode_Check(py_message)) {
         bad_gerror_message = "gobject.GError instances must have a 'message' string attribute";
         goto bad_gerror;
     }
 
     py_domain = PyObject_GetAttrString(value, "domain");
-    if (!py_domain || !PyString_Check(py_domain)) {
+    if (!py_domain || !_PyUnicode_Check(py_domain)) {
         bad_gerror_message = "gobject.GError instances must have a 'domain' string attribute";
         Py_DECREF(py_message);
         goto bad_gerror;
     }
 
     py_code = PyObject_GetAttrString(value, "code");
-    if (!py_code || !PyInt_Check(py_code)) {
+    if (!py_code || !_PyLong_Check(py_code)) {
         bad_gerror_message = "gobject.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(PyString_AsString(py_domain)),
-                PyInt_AsLong(py_code), PyString_AsString(py_message));
+    g_set_error(error, g_quark_from_string(_PyUnicode_AsString(py_domain)),
+                _PyLong_AsLong(py_code), _PyUnicode_AsString(py_message));
 
     Py_DECREF(py_message);
     Py_DECREF(py_code);
@@ -360,7 +360,7 @@
 	exception_table = PyDict_New();
 
     PyDict_SetItem(exception_table,
-		   PyInt_FromLong(error_domain),
+		   _PyLong_FromLong(error_domain),
 		   exception);
     
     return exception;



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