pygobject r875 - in trunk: . glib gobject
- From: johan svn gnome org
- To: svn-commits-list gnome org
- Subject: pygobject r875 - in trunk: . glib gobject
- Date: Sat, 26 Jul 2008 14:46:58 +0000 (UTC)
Author: johan
Date: Sat Jul 26 14:46:58 2008
New Revision: 875
URL: http://svn.gnome.org/viewvc/pygobject?rev=875&view=rev
Log:
2008-07-26 Johan Dahlin <johan gnome org>
reviewed by: <delete if not using a buddy>
* glib/pyglib-python-compat.h:
* glib/pyglib.h:
Make a few macros public
* gobject/Makefile.am:
* gobject/gobjectmodule.c (init_gobject):
* gobject/pyginterface.c (pyg_interface_init),
(pyg_interface_free), (pyg_register_interface),
(pyg_register_interface_info), (pyg_lookup_interface_info),
(pygobject_interface_register_types):
* gobject/pyginterface.h:
* gobject/pygobject-private.h:
* gobject/pygobject.c:
Move GInterface wrapper into its own file
Added:
trunk/gobject/pyginterface.c
trunk/gobject/pyginterface.h
Modified:
trunk/ChangeLog
trunk/glib/pyglib-python-compat.h
trunk/glib/pyglib.h
trunk/gobject/Makefile.am
trunk/gobject/gobjectmodule.c
trunk/gobject/pygobject-private.h
trunk/gobject/pygobject.c
Modified: trunk/glib/pyglib-python-compat.h
==============================================================================
--- trunk/glib/pyglib-python-compat.h (original)
+++ trunk/glib/pyglib-python-compat.h Sat Jul 26 14:46:58 2008
@@ -28,27 +28,6 @@
/* 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
@@ -66,6 +45,11 @@
#define _PyLongObject PyIntObject
#define _PyLong_Type PyInt_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 = { \
PyModuleDef_HEAD_INIT, \
Modified: trunk/glib/pyglib.h
==============================================================================
--- trunk/glib/pyglib.h (original)
+++ trunk/glib/pyglib.h Sat Jul 26 14:46:58 2008
@@ -60,6 +60,27 @@
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) \
+};
+#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);
G_END_DECLS
Modified: trunk/gobject/Makefile.am
==============================================================================
--- trunk/gobject/Makefile.am (original)
+++ trunk/gobject/Makefile.am Sat Jul 26 14:46:58 2008
@@ -47,6 +47,8 @@
pygboxed.c \
pygenum.c \
pygflags.c \
+ pyginterface.c \
+ pyginterface.h \
pygobject.c \
pygobject.h \
pygobject-private.h \
Modified: trunk/gobject/gobjectmodule.c
==============================================================================
--- trunk/gobject/gobjectmodule.c (original)
+++ trunk/gobject/gobjectmodule.c Sat Jul 26 14:46:58 2008
@@ -24,10 +24,11 @@
# include <config.h>
#endif
+#include <gobject/gvaluecollector.h>
+#include <pyglib.h>
#include "pygobject-private.h"
#include "pythread.h"
-#include <pyglib.h>
-#include <gobject/gvaluecollector.h>
+#include "pyginterface.h"
#ifdef HAVE_FFI_H
#include "ffi-marshaller.h"
@@ -40,9 +41,7 @@
static GHashTable *log_handlers = NULL;
static gboolean log_handlers_disabled = FALSE;
-GQuark pyginterface_type_key;
GQuark pygobject_class_init_key;
-GQuark pyginterface_info_key;
GQuark pygboxed_type_key;
GQuark pygobject_class_key;
GQuark pygobject_wrapper_key;
@@ -83,12 +82,6 @@
unblock_threads_func);
}
-static void
-object_free(PyObject *op)
-{
- PyObject_FREE(op);
-}
-
/**
* pyg_destroy_notify:
* @user_data: a PyObject pointer.
@@ -133,116 +126,6 @@
}
-/* ---------------- GInterface functions -------------------- */
-
-static int
-pyg_interface_init(PyObject *self, PyObject *args, PyObject *kwargs)
-{
- gchar buf[512];
-
- if (!PyArg_ParseTuple(args, ":GInterface.__init__"))
- return -1;
-
- g_snprintf(buf, sizeof(buf), "%s can not be constructed", self->ob_type->tp_name);
- PyErr_SetString(PyExc_NotImplementedError, buf);
- return -1;
-}
-
-PyTypeObject PyGInterface_Type = {
- PyObject_HEAD_INIT(NULL)
- 0, /* ob_size */
- "gobject.GInterface", /* tp_name */
- sizeof(PyObject), /* tp_basicsize */
- 0, /* tp_itemsize */
- /* methods */
- (destructor)0, /* tp_dealloc */
- (printfunc)0, /* tp_print */
- (getattrfunc)0, /* tp_getattr */
- (setattrfunc)0, /* tp_setattr */
- (cmpfunc)0, /* tp_compare */
- (reprfunc)0, /* tp_repr */
- 0, /* tp_as_number */
- 0, /* tp_as_sequence */
- 0, /* tp_as_mapping */
- (hashfunc)0, /* 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 | Py_TPFLAGS_BASETYPE, /* tp_flags */
- NULL, /* Documentation string */
- (traverseproc)0, /* tp_traverse */
- (inquiry)0, /* tp_clear */
- (richcmpfunc)0, /* tp_richcompare */
- 0, /* tp_weaklistoffset */
- (getiterfunc)0, /* tp_iter */
- (iternextfunc)0, /* tp_iternext */
- 0, /* tp_methods */
- 0, /* tp_members */
- 0, /* tp_getset */
- (PyTypeObject *)0, /* tp_base */
- (PyObject *)0, /* tp_dict */
- 0, /* tp_descr_get */
- 0, /* tp_descr_set */
- 0, /* tp_dictoffset */
- (initproc)pyg_interface_init, /* tp_init */
- (allocfunc)0, /* tp_alloc */
- (newfunc)0, /* tp_new */
- (freefunc)object_free, /* tp_free */
- (inquiry)0, /* tp_is_gc */
- (PyObject *)0, /* tp_bases */
-};
-
-/**
- * pyg_register_interface:
- * @dict: a module dictionary.
- * @class_name: the class name for the wrapper class.
- * @gtype: the GType of the interface.
- * @type: the wrapper class for the interface.
- *
- * Registers a Python class as the wrapper for a GInterface. As a
- * convenience it will also place a reference to the wrapper class in
- * the provided module dictionary.
- */
-static void
-pyg_register_interface(PyObject *dict, const gchar *class_name,
- GType gtype, PyTypeObject *type)
-{
- PyObject *o;
-
- type->ob_type = &PyType_Type;
- type->tp_base = &PyGInterface_Type;
-
- if (PyType_Ready(type) < 0) {
- g_warning("could not ready `%s'", type->tp_name);
- return;
- }
-
- if (gtype) {
- o = pyg_type_wrapper_new(gtype);
- PyDict_SetItemString(type->tp_dict, "__gtype__", o);
- Py_DECREF(o);
- }
-
- g_type_set_qdata(gtype, pyginterface_type_key, type);
-
- PyDict_SetItemString(dict, (char *)class_name, (PyObject *)type);
-
-}
-
-static void
-pyg_register_interface_info(GType gtype, const GInterfaceInfo *info)
-{
- g_type_set_qdata(gtype, pyginterface_info_key, (gpointer) info);
-}
-
-static const GInterfaceInfo *
-pyg_lookup_interface_info(GType gtype)
-{
- return g_type_get_qdata(gtype, pyginterface_info_key);
-}
-
/* ---------------- gobject module functions -------------------- */
static PyObject *
@@ -2702,8 +2585,6 @@
pygobject_class_key = g_quark_from_static_string("PyGObject::class");
pygobject_class_init_key = g_quark_from_static_string("PyGObject::class-init");
pygobject_wrapper_key = g_quark_from_static_string("PyGObject::wrapper");
- pyginterface_type_key = g_quark_from_static_string("PyGInterface::type");
- pyginterface_info_key = g_quark_from_static_string("PyGInterface::info");
pygpointer_class_key = g_quark_from_static_string("PyGPointer::class");
pygobject_has_updated_constructor_key =\
g_quark_from_static_string("PyGObject::has-updated-constructor");
@@ -2736,13 +2617,9 @@
PyDict_SetItemString(PyGObject_Type.tp_dict, "__module__",
o=PyString_FromString("gobject._gobject"));
Py_DECREF(o);
-
- REGISTER_GTYPE(d, PyGInterface_Type, "GInterface", G_TYPE_INTERFACE);
- PyDict_SetItemString(PyGInterface_Type.tp_dict, "__doc__",
- pyg_object_descr_doc_get());
- PyDict_SetItemString(PyGInterface_Type.tp_dict, "__gdoc__",
- pyg_object_descr_doc_get());
+ pygobject_interface_register_types(d);
+
REGISTER_GTYPE(d, PyGBoxed_Type, "GBoxed", G_TYPE_BOXED);
REGISTER_GTYPE(d, PyGPointer_Type, "GPointer", G_TYPE_POINTER);
PyGEnum_Type.tp_base = &PyInt_Type;
Added: trunk/gobject/pyginterface.c
==============================================================================
--- (empty file)
+++ trunk/gobject/pyginterface.c Sat Jul 26 14:46:58 2008
@@ -0,0 +1,121 @@
+/* -*- Mode: C; c-basic-offset: 4 -*-
+ * pygtk- Python bindings for the GTK toolkit.
+ * Copyright (C) 1998-2003 James Henstridge
+ * 2004-2008 Johan Dahlin
+ * pyginterface.c: wrapper for the gobject library.
+ *
+ * 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
+ */
+
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif
+
+#include <Python.h>
+#include "pyglib.h"
+#include "pygobject-private.h"
+
+GQuark pyginterface_type_key;
+GQuark pyginterface_info_key;
+
+PYGLIB_DEFINE_TYPE("gobject.GInterface", PyGInterface_Type, PyObject)
+
+static int
+pyg_interface_init(PyObject *self, PyObject *args, PyObject *kwargs)
+{
+ gchar buf[512];
+
+ if (!PyArg_ParseTuple(args, ":GInterface.__init__"))
+ return -1;
+
+ g_snprintf(buf, sizeof(buf), "%s can not be constructed", self->ob_type->tp_name);
+ PyErr_SetString(PyExc_NotImplementedError, buf);
+ return -1;
+}
+
+static void
+pyg_interface_free(PyObject *op)
+{
+ PyObject_FREE(op);
+}
+
+/**
+ * pyg_register_interface:
+ * @dict: a module dictionary.
+ * @class_name: the class name for the wrapper class.
+ * @gtype: the GType of the interface.
+ * @type: the wrapper class for the interface.
+ *
+ * Registers a Python class as the wrapper for a GInterface. As a
+ * convenience it will also place a reference to the wrapper class in
+ * the provided module dictionary.
+ */
+void
+pyg_register_interface(PyObject *dict, const gchar *class_name,
+ GType gtype, PyTypeObject *type)
+{
+ PyObject *o;
+
+ type->ob_type = &PyType_Type;
+ type->tp_base = &PyGInterface_Type;
+
+ if (PyType_Ready(type) < 0) {
+ g_warning("could not ready `%s'", type->tp_name);
+ return;
+ }
+
+ if (gtype) {
+ o = pyg_type_wrapper_new(gtype);
+ PyDict_SetItemString(type->tp_dict, "__gtype__", o);
+ Py_DECREF(o);
+ }
+
+ g_type_set_qdata(gtype, pyginterface_type_key, type);
+
+ PyDict_SetItemString(dict, (char *)class_name, (PyObject *)type);
+
+}
+
+void
+pyg_register_interface_info(GType gtype, const GInterfaceInfo *info)
+{
+ g_type_set_qdata(gtype, pyginterface_info_key, (gpointer) info);
+}
+
+const GInterfaceInfo *
+pyg_lookup_interface_info(GType gtype)
+{
+ return g_type_get_qdata(gtype, pyginterface_info_key);
+}
+
+void
+pygobject_interface_register_types(PyObject *d)
+{
+ pyginterface_type_key = g_quark_from_static_string("PyGInterface::type");
+ pyginterface_info_key = g_quark_from_static_string("PyGInterface::info");
+
+ PyGInterface_Type.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE;
+ PyGInterface_Type.tp_init = (initproc)pyg_interface_init;
+ PyGInterface_Type.tp_free = (freefunc)pyg_interface_free;
+
+ PYGOBJECT_REGISTER_GTYPE(d, PyGInterface_Type, "GInterface", G_TYPE_INTERFACE)
+
+ PyDict_SetItemString(PyGInterface_Type.tp_dict, "__doc__",
+ pyg_object_descr_doc_get());
+ PyDict_SetItemString(PyGInterface_Type.tp_dict, "__gdoc__",
+ pyg_object_descr_doc_get());
+
+}
Added: trunk/gobject/pyginterface.h
==============================================================================
--- (empty file)
+++ trunk/gobject/pyginterface.h Sat Jul 26 14:46:58 2008
@@ -0,0 +1,40 @@
+/* -*- Mode: C; c-basic-offset: 4 -*-
+ * pygtk- Python bindings for the GTK toolkit.
+ * Copyright (C) 1998-2003 James Henstridge
+ * 2004-2008 Johan Dahlin
+ * pyginterface.c: wrapper for the gobject library.
+ *
+ * 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 __PYGOBJECT_INTERFACE_H__
+#define __PYGOBJECT_INTERFACE_H__
+
+extern GQuark pyginterface_type_key;
+extern GQuark pyginterface_info_key;
+
+extern PyTypeObject PyGInterface_Type;
+
+void pyg_register_interface(PyObject *dict,
+ const gchar *class_name,
+ GType gtype,
+ PyTypeObject *type);
+const GInterfaceInfo * pyg_lookup_interface_info(GType gtype);
+void pyg_register_interface_info(GType gtype, const
+ GInterfaceInfo *info);
+void pygobject_interface_register_types(PyObject *d);
+
+#endif /* __PYGOBJECT_INTERFACE_H__ */
Modified: trunk/gobject/pygobject-private.h
==============================================================================
--- trunk/gobject/pygobject-private.h (original)
+++ trunk/gobject/pygobject-private.h Sat Jul 26 14:46:58 2008
@@ -27,6 +27,14 @@
typedef inquiry lenfunc;
#endif
+#define PYGOBJECT_REGISTER_GTYPE(d, type, name, gtype) \
+ { \
+ PyObject *o; \
+ PYGLIB_REGISTER_TYPE(d, type, name); \
+ PyDict_SetItemString(type.tp_dict, "__gtype__", \
+ o=pyg_type_wrapper_new(gtype)); \
+ Py_DECREF(o); \
+}
/* from gobjectmodule.c */
extern struct _PyGObject_Functions pygobject_api_functions;
@@ -141,7 +149,6 @@
/* from pygobject.h */
extern PyTypeObject PyGObject_Type;
-extern PyTypeObject PyGInterface_Type;
extern PyTypeObject PyGProps_Type;
extern PyTypeObject PyGPropsDescr_Type;
extern PyTypeObject PyGPropsIter_Type;
Modified: trunk/gobject/pygobject.c
==============================================================================
--- trunk/gobject/pygobject.c (original)
+++ trunk/gobject/pygobject.c Sat Jul 26 14:46:58 2008
@@ -22,6 +22,7 @@
#include <pyglib.h>
#include "pygobject-private.h"
+#include "pyginterface.h"
static void pygobject_dealloc(PyGObject *self);
static int pygobject_traverse(PyGObject *self, visitproc visit, void *arg);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]