diff options
author | Johan Dahlin <johan@gnome.org> | 2008-07-26 13:23:28 +0000 |
---|---|---|
committer | Johan Dahlin <johan@src.gnome.org> | 2008-07-26 13:23:28 +0000 |
commit | e889e0030877bb0b3a7e83f945b8b07230973c01 (patch) | |
tree | d8dd4045f066a3e83dac29435102eeaeb4ad7986 /glib/glibmodule.c | |
parent | 83627fd48cdd1a39eec874627ef97ed560e231b8 (diff) | |
download | pygobject-e889e0030877bb0b3a7e83f945b8b07230973c01.tar.gz pygobject-e889e0030877bb0b3a7e83f945b8b07230973c01.tar.xz pygobject-e889e0030877bb0b3a7e83f945b8b07230973c01.zip |
Add macros for supporting additional python versions. Start using them for
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.
svn path=/trunk/; revision=870
Diffstat (limited to 'glib/glibmodule.c')
-rw-r--r-- | glib/glibmodule.c | 39 |
1 files changed, 18 insertions, 21 deletions
diff --git a/glib/glibmodule.c b/glib/glibmodule.c index dc7afca..9228057 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 (!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 @@ pyglib_idle_add(PyObject *self, PyObject *args, PyObject *kwargs) 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 @@ 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 PyInt_FromLong(handler_id); + return _PyLong_FromLong(handler_id); } static PyObject * @@ -204,7 +204,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 PyInt_FromLong(handler_id); + return _PyLong_FromLong(handler_id); } static gboolean @@ -294,7 +294,7 @@ pyglib_io_add_watch(PyObject *self, PyObject *args, PyObject *kwargs) (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 @@ 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 PyInt_FromLong(id); + return _PyLong_FromLong(id); } static PyObject * @@ -391,7 +391,7 @@ pyglib_markup_escape_text(PyObject *unused, PyObject *args, PyObject *kwargs) 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 @@ pyglib_get_current_time(PyObject *unused) 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 @@ pyglib_filename_from_utf8(PyObject *self, PyObject *args) 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 @@ pyglib_get_application_name(PyObject *self) Py_INCREF(Py_None); return Py_None; } - return PyString_FromString(name); + return _PyUnicode_FromString(name); } static PyObject* @@ -504,7 +504,7 @@ pyglib_get_prgname(PyObject *self) Py_INCREF(Py_None); return Py_None; } - return PyString_FromString(name); + return _PyUnicode_FromString(name); } static PyObject* @@ -520,7 +520,7 @@ pyglib_set_prgname(PyObject *self, PyObject *args) } -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 @@ pyglib_register_constants(PyObject *m) (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 @@ init_glib(void) pyglib_option_context_register_types(d); pyglib_option_group_register_types(d); } +PYGLIB_MODULE_END |