[pygobject/gsoc2009: 33/160] Move girepository to gi and reorganize files



commit 58d0d67a6b8977bf3fb69d08d2fa591f113a0635
Author: Simon van der Linden <svdlinden src gnome org>
Date:   Tue Jul 14 14:49:19 2009 +0200

    Move girepository to gi and reorganize files

 Makefile.am                                        |    2 +-
 configure.ac                                       |    3 +-
 gi/Makefile.am                                     |   64 ++++
 {girepository => gi}/__init__.py                   |    8 +-
 gi/gimodule.c                                      |   69 ++++
 {girepository => gi}/importer.py                   |   14 +-
 {girepository => gi}/module.py                     |   19 +-
 {girepository => gi}/overrides/Gdk.py              |    0
 {girepository => gi}/overrides/Gtk.py              |    0
 gi/overrides/Makefile.am                           |   13 +
 {girepository => gi}/overrides/__init__.py         |    0
 girepository/bank-argument.c => gi/pygargument.c   |   15 +-
 gi/pygargument.h                                   |   52 +++
 gi/pygi-private.h                                  |   42 ++
 gi/pygi.h                                          |   45 +++
 girepository/bank-info.c => gi/pygiinfo.c          |  399 ++++++++++++--------
 gi/pygiinfo.h                                      |   40 ++
 .../bank-repository.c => gi/pygirepository.c       |  113 +++---
 gi/pygirepository.h                                |   33 ++
 {girepository => gi}/repository.py                 |   11 +-
 girepository/btypes.py => gi/types.py              |   23 +-
 girepository/Makefile.am                           |   55 ---
 girepository/bank.c                                |  157 --------
 girepository/bank.h                                |   94 -----
 tests/test_girepository.py                         |    3 +-
 25 files changed, 721 insertions(+), 553 deletions(-)
---
diff --git a/Makefile.am b/Makefile.am
index 41e29af..dbc878f 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -1,7 +1,7 @@
 ACLOCAL_AMFLAGS = -I m4
 AUTOMAKE_OPTIONS = 1.7
 
-SUBDIRS = docs codegen glib gobject gio girepository examples tests
+SUBDIRS = docs codegen glib gobject gio gi examples tests
 
 PLATFORM_VERSION = 2.0
 
diff --git a/configure.ac b/configure.ac
index ed1f1a3..c4126f8 100644
--- a/configure.ac
+++ b/configure.ac
@@ -237,7 +237,8 @@ AC_CONFIG_FILES(
   glib/Makefile
   gobject/Makefile
   gio/Makefile
-  girepository/Makefile
+  gi/Makefile
+  gi/overrides/Makefile
   examples/Makefile
   tests/Makefile
   PKG-INFO)
diff --git a/gi/Makefile.am b/gi/Makefile.am
new file mode 100644
index 0000000..f48d610
--- /dev/null
+++ b/gi/Makefile.am
@@ -0,0 +1,64 @@
+AUTOMAKE_OPTIONS = 1.7
+
+SUBDIRS = overrides
+
+PLATFORM_VERSION = 2.0
+
+INCLUDES = \
+	-I$(top_srcdir)/gobject \
+	$(PYTHON_INCLUDES) \
+	$(PYGOBJECT_CFLAGS) \
+	$(GOBJECT_INTROSPECTION_CFLAGS)
+
+pkginclude_HEADERS = pygi.h
+
+# gi extension modules
+pkgpyexecdir = $(pyexecdir)/gtk-2.0/gi
+
+# gi python scripts
+pygidir = $(pkgpyexecdir)
+pygi_PYTHON = \
+	types.py \
+	repository.py \
+	module.py \
+	importer.py \
+	__init__.py
+
+# gi overrides extension modules
+pygioverridesdir = $(pkgpyexecdir)/overrides
+
+# gi overrides scripts
+pygioverrides_PYTHON = \
+	$(srcdir)/overrides/
+
+# linker flags
+common_ldflags = -module -avoid-version
+if PLATFORM_WIN32
+common_ldflags += -no-undefined
+endif
+
+# repo module
+_gi_la_CFLAGS = -O0
+_gi_la_LDFLAGS = $(common_ldflags) -export-symbols-regex init_gi
+_gi_la_LIBADD = $(GOBJECT_INTROSPECTION_LIBS)
+_gi_la_SOURCES = \
+	pygirepository.c \
+	pygirepository.h \
+	pygiinfo.c \
+	pygiinfo.h \
+	pygargument.c \
+	pygargument.h \
+	pygi.h \
+	pygi-private.h \
+	gimodule.c
+
+if BUILD_GOBJECT_INTROSPECTION
+pygi_LTLIBRARIES = _gi.la
+
+all: $(pygi_LTLIBRARIES:.la=.so)
+clean-local:
+	rm -f $(pygi_LTLIBRARIES:.la=.so)
+.la.so:
+	$(LN_S) .libs/$@ $@ || true
+endif
+
diff --git a/girepository/__init__.py b/gi/__init__.py
similarity index 88%
rename from girepository/__init__.py
rename to gi/__init__.py
index f2e58bf..b860987 100644
--- a/girepository/__init__.py
+++ b/gi/__init__.py
@@ -1,6 +1,7 @@
 # -*- Mode: Python; py-indent-offset: 4 -*-
+# vim: tabstop=4 shiftwidth=4 expandtab
 #
-# Copyright (C) 2005, 2007  Johan Dahlin <johan gnome org>
+# Copyright (C) 2005-2009 Johan Dahlin <johan gnome org>
 #
 # This library is free software; you can redistribute it and/or
 # modify it under the terms of the GNU Lesser General Public
@@ -14,11 +15,12 @@
 #
 # 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., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
-#
+# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301
+# USA
 
 from .importer import install_importhook
 
 install_importhook()
 
 del install_importhook
+
diff --git a/gi/gimodule.c b/gi/gimodule.c
new file mode 100644
index 0000000..d64aee2
--- /dev/null
+++ b/gi/gimodule.c
@@ -0,0 +1,69 @@
+/* -*- Mode: C; c-basic-offset: 4 -*-
+ * vim: tabstop=4 shiftwidth=4 expandtab
+ *
+ * Copyright (C) 2005-2009 Johan Dahlin <johan gnome org>
+ *
+ *   gimodule.c: wrapper for the gobject-introspection 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., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301
+ * USA
+ */
+
+#include "pygi-private.h"
+
+#include <pygobject.h>
+
+static PyObject *
+_wrap_set_object_has_new_constructor(PyObject *self, PyObject *args)
+{
+    PyObject *py_g_type;
+    GType g_type;
+
+    if (!PyArg_ParseTuple(args, "O:setObjectHasNewConstructor", &py_g_type)) {
+        return NULL;
+    }
+
+    g_type = pyg_type_from_object(py_g_type);
+    pyg_set_object_has_new_constructor(g_type);
+
+    Py_INCREF(Py_None);
+    return Py_None;
+}
+
+static PyMethodDef _pygi_functions[] = {
+    { "setObjectHasNewConstructor", (PyCFunction)_wrap_set_object_has_new_constructor, METH_VARARGS },
+    { NULL, NULL, 0 }
+};
+
+PyMODINIT_FUNC
+init_gi(void)
+{
+    PyObject *m;
+
+    m = Py_InitModule("_gi", _pygi_functions);
+    if (m == NULL) {
+        return;
+    }
+
+    g_type_init();
+    if (pygobject_init(-1, -1, -1) == NULL) {
+        return;
+    }
+
+    pygi_repository_register_types(m);
+    pygi_info_register_types(m);
+    pygi_info_register_constants(m);
+}
+
diff --git a/girepository/importer.py b/gi/importer.py
similarity index 86%
rename from girepository/importer.py
rename to gi/importer.py
index 0433241..35950ff 100644
--- a/girepository/importer.py
+++ b/gi/importer.py
@@ -1,6 +1,9 @@
 # -*- Mode: Python; py-indent-offset: 4 -*-
+# vim: tabstop=4 shiftwidth=4 expandtab
 #
-# Copyright (C) 2005,2007 Johan Dahlin <johan gnome org>
+# Copyright (C) 2005-2009 Johan Dahlin <johan gnome org>
+#
+#   importer.py: dynamic importer for introspected libraries.
 #
 # This library is free software; you can redistribute it and/or
 # modify it under the terms of the GNU Lesser General Public
@@ -14,13 +17,13 @@
 #
 # 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., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
-#
+# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301
+# USA
 
-import os
 import sys
 
 from .repository import repository
+from .module import DynamicModule
 
 class DynamicImporter(object):
     def __init__(self, name, path):
@@ -40,8 +43,7 @@ class DynamicImporter(object):
         if module is not None:
             return module
 
-        from .module import DynamicModule
-        module_name = 'girepository.overrides.%s' % (name,)
+        module_name = 'gi.overrides.%s' % (name,)
         try:
             module = __import__(module_name, {}, {}, ['%sModule' % (name,)])
             modtype = getattr(module, name + 'Module')
diff --git a/girepository/module.py b/gi/module.py
similarity index 95%
rename from girepository/module.py
rename to gi/module.py
index d8a086f..00020d6 100644
--- a/girepository/module.py
+++ b/gi/module.py
@@ -1,6 +1,9 @@
 # -*- Mode: Python; py-indent-offset: 4 -*-
+# vim: tabstop=4 shiftwidth=4 expandtab
 #
-# Copyright (C) 2007 Johan Dahlin <johan gnome org>
+# Copyright (C) 2007-2009 Johan Dahlin <johan gnome org>
+#
+#   module.py: dynamic module for introspected libraries.
 #
 # This library is free software; you can redistribute it and/or
 # modify it under the terms of the GNU Lesser General Public
@@ -14,8 +17,8 @@
 #
 # 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., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
-#
+# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301
+# USA
 
 import os
 
@@ -26,11 +29,7 @@ from gobject import \
     GEnum
 
 from .repository import repository
-from .btypes import \
-    GObjectIntrospectionMeta, \
-    GIStruct, \
-    Function
-from .repo import \
+from ._gi import \
     UnresolvedInfo, \
     FunctionInfo, \
     RegisteredTypeInfo, \
@@ -39,6 +38,10 @@ from .repo import \
     InterfaceInfo, \
     StructInfo, \
     BoxedInfo
+from .types import \
+    GObjectIntrospectionMeta, \
+    GIStruct, \
+    Function
 
 
 def get_parent_for_object(object_info):
diff --git a/girepository/overrides/Gdk.py b/gi/overrides/Gdk.py
similarity index 100%
rename from girepository/overrides/Gdk.py
rename to gi/overrides/Gdk.py
diff --git a/girepository/overrides/Gtk.py b/gi/overrides/Gtk.py
similarity index 100%
rename from girepository/overrides/Gtk.py
rename to gi/overrides/Gtk.py
diff --git a/gi/overrides/Makefile.am b/gi/overrides/Makefile.am
new file mode 100644
index 0000000..02bbd3b
--- /dev/null
+++ b/gi/overrides/Makefile.am
@@ -0,0 +1,13 @@
+AUTOMAKE_OPTIONS = 1.7
+PLATFORM_VERSION = 2.0
+
+# gi-overrides extension modules
+pkgpyexecdir = $(pyexecdir)/gtk-2.0/gi/overrides
+
+# gi-overrides python scripts
+pygioverridesdir = $(pkgpyexecdir)
+pygioverrides_PYTHON = \
+	Gtk.py \
+	Gdk.py \
+	__init__.py
+
diff --git a/girepository/overrides/__init__.py b/gi/overrides/__init__.py
similarity index 100%
rename from girepository/overrides/__init__.py
rename to gi/overrides/__init__.py
diff --git a/girepository/bank-argument.c b/gi/pygargument.c
similarity index 99%
rename from girepository/bank-argument.c
rename to gi/pygargument.c
index 0c2859e..bdd000f 100644
--- a/girepository/bank-argument.c
+++ b/gi/pygargument.c
@@ -1,7 +1,9 @@
 /* -*- Mode: C; c-basic-offset: 4 -*-
- * vim: set ts=8 sts=4 sw=4 et ai cindent :
+ * vim: tabstop=4 shiftwidth=4 expandtab
  *
- * Copyright (C) 2005  Johan Dahlin <johan gnome org>
+ * Copyright (C) 2005-2009 Johan Dahlin <johan gnome org>
+ *
+ *   pygargument.c: GArgument - PyObject conversion fonctions.
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
@@ -15,12 +17,15 @@
  *
  * 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., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
+ * USA
  */
 
-#include "bank.h"
-#include <pygobject.h>
+#include "pygi-private.h"
+
 #include <string.h>
+#include <pygobject.h>
+
 
 GQuark
 pyg_argument_from_pyobject_error_quark(void)
diff --git a/gi/pygargument.h b/gi/pygargument.h
new file mode 100644
index 0000000..e4fae41
--- /dev/null
+++ b/gi/pygargument.h
@@ -0,0 +1,52 @@
+/* -*- Mode: C; c-basic-offset: 4 -*-
+ * vim: tabstop=4 shiftwidth=4 expandtab
+ *
+ * Copyright (C) 2005-2009 Johan Dahlin <johan gnome org>
+ *
+ * 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
+ * USA
+ */
+
+#ifndef __PYG_ARGUMENT_H__
+#define __PYG_ARGUMENT_H__
+
+#include <Python.h>
+
+#include <girepository.h>
+
+G_BEGIN_DECLS
+
+GArgument pyg_argument_from_pyobject(PyObject *object,
+				     GITypeInfo *info);
+PyObject*  pyg_argument_to_pyobject(GArgument *arg,
+				    GITypeInfo *info);
+
+PyObject* pyg_array_to_pyobject(gpointer items, gsize length, GITypeInfo *info);
+gpointer pyg_array_from_pyobject(PyObject *object, GITypeInfo *type_info, gsize *length);
+
+#define PyG_ARGUMENT_FROM_PYOBJECT_ERROR pyg_argument_from_pyobject_error_quark()
+GQuark pyg_argument_from_pyobject_error_quark(void);
+
+typedef enum {
+    PyG_ARGUMENT_FROM_PYOBJECT_ERROR_TYPE,
+    PyG_ARGUMENT_FROM_PYOBJECT_ERROR_VALUE,
+    PyG_ARGUMENT_FROM_PYOBJECT_ERROR_SIZE
+} PyGArgumentFromPyObjectError;
+
+gboolean pyg_argument_from_pyobject_check(PyObject *object, GITypeInfo *type_info, GError **error);
+
+G_END_DECLS
+
+#endif /* __PYG_ARGUMENT_H__ */
diff --git a/gi/pygi-private.h b/gi/pygi-private.h
new file mode 100644
index 0000000..652aab5
--- /dev/null
+++ b/gi/pygi-private.h
@@ -0,0 +1,42 @@
+#ifndef __PYGI_PRIVATE_H__
+#define __PYGI_PRIVATE_H__
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <Python.h>
+
+#include "pygi.h"
+
+#include "pygirepository.h"
+#include "pygiinfo.h"
+#include "pygargument.h"
+
+extern PyTypeObject PyGIRepository_Type;
+
+extern PyTypeObject PyGIBaseInfo_Type;
+extern PyTypeObject PyGICallableInfo_Type;
+extern PyTypeObject PyGIFunctionInfo_Type;
+extern PyTypeObject PyGICallbackInfo_Type;
+extern PyTypeObject PyGIRegisteredTypeInfo_Type;
+extern PyTypeObject PyGIStructInfo_Type;
+extern PyTypeObject PyGIUnionInfo_Type;
+extern PyTypeObject PyGIEnumInfo_Type;
+extern PyTypeObject PyGIObjectInfo_Type;
+extern PyTypeObject PyGIBoxedInfo_Type;
+extern PyTypeObject PyGIInterfaceInfo_Type;
+extern PyTypeObject PyGIConstantInfo_Type;
+extern PyTypeObject PyGIValueInfo_Type;
+extern PyTypeObject PyGISignalInfo_Type;
+extern PyTypeObject PyGIVFuncInfo_Type;
+extern PyTypeObject PyGIPropertyInfo_Type;
+extern PyTypeObject PyGIFieldInfo_Type;
+extern PyTypeObject PyGIArgInfo_Type;
+extern PyTypeObject PyGITypeInfo_Type;
+#if 0
+extern PyTypeObject PyGIErrorDomainInfo_Type;
+#endif
+extern PyTypeObject PyGIUnresolvedInfo_Type;
+
+#endif /* __PYGI_PRIVATE_H__ */
diff --git a/gi/pygi.h b/gi/pygi.h
new file mode 100644
index 0000000..10eee4e
--- /dev/null
+++ b/gi/pygi.h
@@ -0,0 +1,45 @@
+/* -*- Mode: C; c-basic-offset: 4 -*-
+ * vim: tabstop=4 shiftwidth=4 expandtab
+ *
+ * Copyright (C) 2005-2009 Johan Dahlin <johan gnome org>
+ *
+ * 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
+ * USA
+ */
+
+#ifndef __PYGI_H__
+#define __PYGI_H__
+
+#include <Python.h>
+
+#include <girepository.h>
+
+G_BEGIN_DECLS
+
+typedef struct {
+    PyObject_HEAD
+    GIRepository *repository;
+} PyGIRepository;
+
+typedef struct {
+    PyObject_HEAD
+    GIBaseInfo *info;
+    PyObject *instance_dict;
+    PyObject *weakreflist;
+} PyGIBaseInfo;
+
+G_END_DECLS
+
+#endif /* __PYGI_H__ */
diff --git a/girepository/bank-info.c b/gi/pygiinfo.c
similarity index 81%
rename from girepository/bank-info.c
rename to gi/pygiinfo.c
index b3fcebe..84d73be 100644
--- a/girepository/bank-info.c
+++ b/gi/pygiinfo.c
@@ -1,7 +1,9 @@
 /* -*- Mode: C; c-basic-offset: 4 -*-
- * vim: set ts=8 sts=4 sw=4 et ai cindent :
+ * vim: tabstop=4 shiftwidth=4 expandtab
  *
- * Copyright (C) 2005  Johan Dahlin <johan gnome org>
+ * Copyright (C) 2005-2009 Johan Dahlin <johan gnome org>
+ *
+ *   pygiinfo.c: GI.*Info wrappers.
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
@@ -15,168 +17,173 @@
  *
  * 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., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
+ * USA
  */
 
-#include "bank.h"
-#include <pygobject.h>
-
-static PyTypeObject *PyGObject_Type = NULL;
+#include "pygi-private.h"
 
-static void      pyg_base_info_dealloc(PyGIBaseInfo *self);
-static void      pyg_base_info_free(PyObject *op);
-static PyObject* pyg_base_info_repr(PyGIBaseInfo *self);
-static int       pyg_base_info_traverse(PyGIBaseInfo *self,
-                                        visitproc visit,
-                                        void *arg);
-static void      pyg_base_info_clear(PyGIBaseInfo *self);
+#include <pygobject.h>
 
-static PyObject *
-_wrap_g_object_info_get_methods(PyGIBaseInfo *self);
-
-#define NEW_CLASS(name, cname) \
-static PyMethodDef _Py##cname##_methods[];    \
-PyTypeObject Py##cname##_Type = {             \
-    PyObject_HEAD_INIT(NULL)                  \
-    0,                                        \
-    "bank." name,                             \
-    sizeof(PyGIBaseInfo),                     \
-    0, 0, 0, 0, 0, 0, 0, 0, 0, 0,             \
-    0, 0, 0, 0, 0, 0,                         \
-    Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, \
-    NULL, 0, 0, 0,                            \
-    offsetof(PyGIBaseInfo, weakreflist),      \
-    0, 0,                                     \
-    _Py##cname##_methods,                     \
-    0, 0, NULL, NULL, 0, 0,                   \
-    offsetof(PyGIBaseInfo, instance_dict)     \
+#define PYGIINFO_DEFINE_TYPE(name, cname) \
+static PyMethodDef _Py##cname##_methods[]; \
+PyTypeObject Py##cname##_Type = { \
+    PyObject_HEAD_INIT(NULL) \
+    0, \
+    "gi." name,                               /* tp_name */ \
+    sizeof(PyGIBaseInfo),                     /* tp_basicsize */ \
+    0,                                        /* tp_itemsize */ \
+    (destructor)NULL,                         /* tp_dealloc */ \
+    (printfunc)NULL,                          /* tp_print */ \
+    (getattrfunc)NULL,                        /* tp_getattr */ \
+    (setattrfunc)NULL,                        /* tp_setattr */ \
+    (cmpfunc)NULL,                            /* tp_compare */ \
+    (reprfunc)NULL,                           /* tp_repr */ \
+    NULL,                                     /* tp_as_number */ \
+    NULL,                                     /* tp_as_sequence */ \
+    NULL,                                     /* tp_as_mapping */ \
+    (hashfunc)NULL,                           /* tp_hash */ \
+    (ternaryfunc)NULL,                        /* tp_call */ \
+    (reprfunc)NULL,                           /* tp_str */ \
+    (getattrofunc)NULL,                       /* tp_getattro */ \
+    (setattrofunc)NULL,                       /* tp_setattro */ \
+    NULL,                                     /* tp_as_buffer */ \
+    Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */ \
+    NULL,                                     /* tp_doc */ \
+    (traverseproc)NULL,                       /* tp_traverse */ \
+    (inquiry)NULL,                            /* tp_clear */ \
+    (richcmpfunc)NULL,                        /* tp_richcompare */ \
+    offsetof(PyGIBaseInfo, weakreflist),      /* tp_weaklistoffset */ \
+    (getiterfunc)NULL,                        /* tp_iter */ \
+    (iternextfunc)NULL,                       /* tp_iternext */ \
+    _Py##cname##_methods,                     /* tp_methods */ \
+    NULL,                                     /* tp_members */ \
+    NULL,                                     /* tp_getset */ \
+    NULL,                                     /* tp_base */ \
+    NULL,                                     /* tp_dict */ \
+    (descrgetfunc)NULL,                       /* tp_descr_get */ \
+    (descrsetfunc)NULL,                       /* tp_descr_set */ \
+    offsetof(PyGIBaseInfo, instance_dict),    /* tp_dictoffset */ \
 }
 
-static PyMethodDef _PyGIBaseInfo_methods[];
-static PyGetSetDef _PyGIBaseInfo_getsets[];
 
-PyTypeObject PyGIBaseInfo_Type = {
-    PyObject_HEAD_INIT(NULL)
-    0,
-    "bank.BaseInfo",
-    sizeof(PyGIBaseInfo),
-    0,
-    /* methods */
-    (destructor)pyg_base_info_dealloc,
-    (printfunc)0,
-    (getattrfunc)0,
-    (setattrfunc)0,
-    (cmpfunc)0,
-    (reprfunc)pyg_base_info_repr,
-    0,
-    0,
-    0,
-    (hashfunc)0,
-    (ternaryfunc)0,
-    (reprfunc)0,
-    (getattrofunc)0,
-    (setattrofunc)0,
-    0,
-    Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE |
-    Py_TPFLAGS_HAVE_GC,
-    NULL,
-    (traverseproc)pyg_base_info_traverse,
-    (inquiry)pyg_base_info_clear,
-    (richcmpfunc)0,
-    offsetof(PyGIBaseInfo, weakreflist),
-    (getiterfunc)0,
-    (iternextfunc)0,
-    _PyGIBaseInfo_methods,
-    0,
-    _PyGIBaseInfo_getsets,
-    NULL,
-    NULL,
-    (descrgetfunc)0,
-    (descrsetfunc)0,
-    offsetof(PyGIBaseInfo, instance_dict),
-    (initproc)0,
-    (allocfunc)0,                       /* tp_alloc */
-    (newfunc)0,                         /* tp_new */
-    (freefunc)pyg_base_info_free,       /* tp_free */
-    (inquiry)0,                         /* tp_is_gc */
-    (PyObject *)0,                      /* tp_bases */
-};
+/* BaseInfo */
 
-static PyObject *
-pyg_base_info_repr(PyGIBaseInfo *self)
+static void
+pygi_base_info_clear(PyGIBaseInfo *self)
 {
-    gchar buf[256];
+    PyObject_GC_UnTrack((PyObject *)self);
 
-    g_snprintf(buf, sizeof(buf),
-               "<%s object (%s) at 0x%lx>",
-               self->ob_type->tp_name,
-               g_base_info_get_name(self->info), (long)self);
-    return PyString_FromString(buf);
+    Py_CLEAR(self->instance_dict);
+
+    if (self->info) {
+        g_base_info_unref(self->info);
+        self->info = NULL;
+    }
+
+    PyObject_GC_Del(self);
 }
 
 static void
-pyg_base_info_dealloc(PyGIBaseInfo *self)
+pygi_base_info_dealloc(PyGIBaseInfo *self)
 {
     PyObject_ClearWeakRefs((PyObject *)self);
-    pyg_base_info_clear(self);
+    pygi_base_info_clear(self);
 }
 
 static int
-pyg_base_info_traverse(PyGIBaseInfo *self,
-                       visitproc visit,
-                       void *arg)
+pygi_base_info_traverse(PyGIBaseInfo *self, visitproc visit, void *data)
 {
-    int ret = 0;
-
-    if (self->instance_dict)
-        ret = visit(self->instance_dict, arg);
-
-    if (ret != 0)
-        return ret;
-
+    if (self->instance_dict) {
+        return visit(self->instance_dict, data);
+    }
     return 0;
-
 }
 
 static void
-pyg_base_info_clear(PyGIBaseInfo *self)
+pygi_base_info_free(PyObject *self)
 {
-    PyObject_GC_UnTrack((PyObject *)self);
-
-    Py_CLEAR(self->instance_dict);
-
-    if (self->info) {
-        g_base_info_unref(self->info);
-        self->info = NULL;
-    }
-
     PyObject_GC_Del(self);
 }
 
-static void
-pyg_base_info_free(PyObject *op)
+static PyObject *
+pygi_base_info_repr(PyGIBaseInfo *self)
 {
-    PyObject_GC_Del(op);
+    gchar buf[256];
+
+    g_snprintf(buf, sizeof(buf),
+               "<%s object (%s) at 0x%lx>",
+               self->ob_type->tp_name,
+               g_base_info_get_name(self->info), (long)self);
+    return PyString_FromString(buf);
 }
 
+static PyMethodDef _PyGIBaseInfo_methods[];
+static PyGetSetDef _PyGIBaseInfo_getsets[];
+
+PyTypeObject PyGIBaseInfo_Type = {
+    PyObject_HEAD_INIT(NULL)
+    0,
+    "gi.BaseInfo",                             /* tp_name */
+    sizeof(PyGIBaseInfo),                      /* tp_basicsize */
+    0,                                         /* tp_itemsize */
+    (destructor)pygi_base_info_dealloc,        /* tp_dealloc */
+    (printfunc)NULL,                           /* tp_print */
+    (getattrfunc)NULL,                         /* tp_getattr */
+    (setattrfunc)NULL,                         /* tp_setattr */
+    (cmpfunc)NULL,                             /* tp_compare */
+    (reprfunc)pygi_base_info_repr,             /* tp_repr */
+    NULL,                                      /* tp_as_number */
+    NULL,                                      /* tp_as_sequence */
+    NULL,                                      /* tp_as_mapping */
+    (hashfunc)NULL,                            /* tp_hash */
+    (ternaryfunc)NULL,                         /* tp_call */
+    (reprfunc)NULL,                            /* tp_str */
+    (getattrofunc)NULL,                        /* tp_getattro */
+    (setattrofunc)NULL,                        /* tp_setattro */
+    NULL,                                      /* tp_as_buffer */
+    Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE |
+        Py_TPFLAGS_HAVE_GC,                    /* tp_flags */
+    NULL,                                      /* tp_doc */
+    (traverseproc)pygi_base_info_traverse,     /* tp_traverse */
+    (inquiry)pygi_base_info_clear,             /* tp_clear */
+    (richcmpfunc)NULL,                         /* tp_richcompare */
+    offsetof(PyGIBaseInfo, weakreflist),       /* tp_weaklistoffset */
+    (getiterfunc)NULL,                         /* tp_iter */
+    (iternextfunc)NULL,                        /* tp_iternext */
+    _PyGIBaseInfo_methods,                     /* tp_methods */
+    NULL,                                      /* tp_members */
+    _PyGIBaseInfo_getsets,                     /* tp_getset */
+    NULL,                                      /* tp_base */
+    NULL,                                      /* tp_dict */
+    (descrgetfunc)NULL,                        /* tp_descr_get */
+    (descrsetfunc)NULL,                        /* tp_descr_set */
+    offsetof(PyGIBaseInfo, instance_dict),     /* tp_dictoffset */
+    (initproc)NULL,                            /* tp_init */
+    (allocfunc)NULL,                           /* tp_alloc */
+    (newfunc)NULL,                             /* tp_new */
+    (freefunc)pygi_base_info_free,             /* tp_free */
+};
 
 static PyObject *
-pyg_base_info_get_dict(PyGIBaseInfo *self, void *closure)
+pygi_base_info_get_dict(PyGIBaseInfo *self, void *closure)
 {
     if (self->instance_dict == NULL) {
         self->instance_dict = PyDict_New();
-        if (self->instance_dict == NULL)
+        if (self->instance_dict == NULL) {
             return NULL;
+        }
     }
     Py_INCREF(self->instance_dict);
     return self->instance_dict;
 }
 
 static PyGetSetDef _PyGIBaseInfo_getsets[] = {
-    { "__dict__", (getter)pyg_base_info_get_dict, (setter)0 },
+    { "__dict__", (getter)pygi_base_info_get_dict, (setter)0 },
     { NULL, 0, 0 }
 };
 
+
 static PyObject *
 _wrap_g_base_info_get_name(PyGIBaseInfo *self)
 {
@@ -268,6 +275,13 @@ pyg_info_new(void *info)
     return (PyObject*)self;
 }
 
+static PyMethodDef _PyGIBaseInfo_methods[] = {
+    { "getName", (PyCFunction)_wrap_g_base_info_get_name, METH_NOARGS },
+    { "getType", (PyCFunction)_wrap_g_base_info_get_type, METH_NOARGS },
+    { "getNamespace", (PyCFunction)_wrap_g_base_info_get_namespace, METH_NOARGS },
+    { NULL, NULL, 0 }
+};
+
 GIBaseInfo *
 pyg_base_info_from_object(PyObject *object)
 {
@@ -294,17 +308,8 @@ pyg_base_info_from_object(PyObject *object)
     return info;
 }
 
-
-static PyMethodDef _PyGIBaseInfo_methods[] = {
-    { "getName", (PyCFunction)_wrap_g_base_info_get_name, METH_NOARGS },
-    { "getType", (PyCFunction)_wrap_g_base_info_get_type, METH_NOARGS },
-    { "getNamespace", (PyCFunction)_wrap_g_base_info_get_namespace, METH_NOARGS },
-    { NULL, NULL, 0 }
-};
-
-
 /* CallableInfo */
-NEW_CLASS("CallableInfo", GICallableInfo);
+PYGIINFO_DEFINE_TYPE("CallableInfo", GICallableInfo);
 
 static PyObject *
 _wrap_g_callable_info_get_args(PyGIBaseInfo *self)
@@ -338,7 +343,7 @@ static PyMethodDef _PyGICallableInfo_methods[] = {
 };
 
 /* FunctionInfo */
-NEW_CLASS("FunctionInfo", GIFunctionInfo);
+PYGIINFO_DEFINE_TYPE("FunctionInfo", GIFunctionInfo);
 
 static PyObject *
 _wrap_g_function_info_is_constructor(PyGIBaseInfo *self)
@@ -479,21 +484,14 @@ _wrap_g_function_info_invoke(PyGIBaseInfo *self, PyObject *args)
             py_arg = PyTuple_GetItem(args, py_args_pos);
             g_assert(py_arg != NULL);
 
-            if (PyGObject_Type == NULL) {
-                PyObject *module;
-                if ((module = PyImport_ImportModule("gobject")) != NULL) {
-                    PyGObject_Type = (PyTypeObject *)PyObject_GetAttrString(module, "GObject");
-                }
-            }
-
             if (!PyType_Check(py_arg)) {
                 PyErr_Format(PyExc_TypeError, "%s.%s() argument %zd: Must be type, not %s",
                     g_base_info_get_namespace(self->info), g_base_info_get_name(self->info),
                     py_args_pos, ((PyTypeObject *)py_arg)->tp_name);
-            } else if (!PyType_IsSubtype((PyTypeObject *)py_arg, PyGObject_Type)) {
+            } else if (!PyType_IsSubtype((PyTypeObject *)py_arg, &PyGObject_Type)) {
                 PyErr_Format(PyExc_TypeError, "%s.%s() argument %zd: Must be a non-strict subclass of %s",
                     g_base_info_get_namespace(self->info), g_base_info_get_name(self->info),
-                    py_args_pos, PyGObject_Type->tp_name);
+                    py_args_pos, PyGObject_Type.tp_name);
             } else {
                 GIBaseInfo *interface_info;
                 GType interface_g_type;
@@ -1064,14 +1062,14 @@ static PyMethodDef _PyGIFunctionInfo_methods[] = {
 };
 
 /* GICallbackInfo */
-NEW_CLASS("CallbackInfo", GICallbackInfo);
+PYGIINFO_DEFINE_TYPE("CallbackInfo", GICallbackInfo);
 
 static PyMethodDef _PyGICallbackInfo_methods[] = {
     { NULL, NULL, 0 }
 };
 
 /* RegisteredTypeInfo */
-NEW_CLASS("RegisteredTypeInfo", GIRegisteredTypeInfo);
+PYGIINFO_DEFINE_TYPE("RegisteredTypeInfo", GIRegisteredTypeInfo);
 
 static PyObject *
 _wrap_g_registered_type_info_get_g_type (PyGIBaseInfo* self)
@@ -1088,7 +1086,7 @@ static PyMethodDef _PyGIRegisteredTypeInfo_methods[] = {
 };
 
 /* GIStructInfo */
-NEW_CLASS("StructInfo", GIStructInfo);
+PYGIINFO_DEFINE_TYPE("StructInfo", GIStructInfo);
 
 static PyObject *
 _wrap_g_struct_info_get_fields(PyGIBaseInfo *self)
@@ -1149,14 +1147,14 @@ static PyMethodDef _PyGIStructInfo_methods[] = {
 };
 
 /* GIUnionInfo */
-NEW_CLASS("UnionInfo", GIUnionInfo);
+PYGIINFO_DEFINE_TYPE("UnionInfo", GIUnionInfo);
 
 static PyMethodDef _PyGIUnionInfo_methods[] = {
     { NULL, NULL, 0 }
 };
 
 /* EnumInfo */
-NEW_CLASS("EnumInfo", GIEnumInfo);
+PYGIINFO_DEFINE_TYPE("EnumInfo", GIEnumInfo);
 
 static PyObject *
 _wrap_g_enum_info_get_values(PyGIBaseInfo *self)
@@ -1185,14 +1183,14 @@ static PyMethodDef _PyGIEnumInfo_methods[] = {
 };
 
 /* BoxedInfo */
-NEW_CLASS("BoxedInfo", GIBoxedInfo);
+PYGIINFO_DEFINE_TYPE("BoxedInfo", GIBoxedInfo);
 
 static PyMethodDef _PyGIBoxedInfo_methods[] = {
     { NULL, NULL, 0 }
 };
 
 /* ObjectInfo */
-NEW_CLASS("ObjectInfo", GIObjectInfo);
+PYGIINFO_DEFINE_TYPE("ObjectInfo", GIObjectInfo);
 
 static PyObject *
 _wrap_g_object_info_get_parent(PyGIBaseInfo *self)
@@ -1297,7 +1295,7 @@ static PyMethodDef _PyGIObjectInfo_methods[] = {
 
 
 /* GIInterfaceInfo */
-NEW_CLASS("InterfaceInfo", GIInterfaceInfo);
+PYGIINFO_DEFINE_TYPE("InterfaceInfo", GIInterfaceInfo);
 
 static PyObject *
 _wrap_g_interface_info_get_methods(PyGIBaseInfo *self)
@@ -1384,7 +1382,7 @@ static PyMethodDef _PyGIInterfaceInfo_methods[] = {
 
 
 /* GIConstantInfo */
-NEW_CLASS("ConstantInfo", GIConstantInfo);
+PYGIINFO_DEFINE_TYPE("ConstantInfo", GIConstantInfo);
 
 static PyMethodDef _PyGIConstantInfo_methods[] = {
     { NULL, NULL, 0 }
@@ -1392,7 +1390,7 @@ static PyMethodDef _PyGIConstantInfo_methods[] = {
 
 
 /* GIValueInfo */
-NEW_CLASS("ValueInfo", GIValueInfo);
+PYGIINFO_DEFINE_TYPE("ValueInfo", GIValueInfo);
 
 static PyObject *
 _wrap_g_value_info_get_value(PyGIBaseInfo *self)
@@ -1414,7 +1412,7 @@ static PyMethodDef _PyGIValueInfo_methods[] = {
 
 
 /* GISignalInfo */
-NEW_CLASS("SignalInfo", GISignalInfo);
+PYGIINFO_DEFINE_TYPE("SignalInfo", GISignalInfo);
 
 static PyMethodDef _PyGISignalInfo_methods[] = {
     { NULL, NULL, 0 }
@@ -1422,21 +1420,21 @@ static PyMethodDef _PyGISignalInfo_methods[] = {
 
 
 /* GIVFuncInfo */
-NEW_CLASS("VFuncInfo", GIVFuncInfo);
+PYGIINFO_DEFINE_TYPE("VFuncInfo", GIVFuncInfo);
 
 static PyMethodDef _PyGIVFuncInfo_methods[] = {
     { NULL, NULL, 0 }
 };
 
 /* GIPropertyInfo */
-NEW_CLASS("PropertyInfo", GIPropertyInfo);
+PYGIINFO_DEFINE_TYPE("PropertyInfo", GIPropertyInfo);
 
 static PyMethodDef _PyGIPropertyInfo_methods[] = {
     { NULL, NULL, 0 }
 };
 
 /* GIFieldInfo */
-NEW_CLASS("FieldInfo", GIFieldInfo);
+PYGIINFO_DEFINE_TYPE("FieldInfo", GIFieldInfo);
 
 static PyObject *
 _wrap_g_field_info_get_value(PyGIBaseInfo *self, PyObject *args)
@@ -1675,7 +1673,7 @@ static PyMethodDef _PyGIFieldInfo_methods[] = {
 };
 
 /* ArgInfo */
-NEW_CLASS("ArgInfo", GIArgInfo);
+PYGIINFO_DEFINE_TYPE("ArgInfo", GIArgInfo);
 
 static PyObject *
 _wrap_g_arg_info_get_type(PyGIBaseInfo *self)
@@ -1696,7 +1694,7 @@ static PyMethodDef _PyGIArgInfo_methods[] = {
 };
 
 /* TypeInfo */
-NEW_CLASS("TypeInfo", GITypeInfo);
+PYGIINFO_DEFINE_TYPE("TypeInfo", GITypeInfo);
 
 static PyObject *
 _wrap_g_type_info_get_tag(PyGIBaseInfo *self)
@@ -1734,10 +1732,99 @@ GIErrorDomainInfo
 #endif
 
 /* GIUnresolvedInfo */
-NEW_CLASS("UnresolvedInfo", GIUnresolvedInfo);
+PYGIINFO_DEFINE_TYPE("UnresolvedInfo", GIUnresolvedInfo);
 
 static PyMethodDef _PyGIUnresolvedInfo_methods[] = {
     { NULL, NULL, 0 }
 };
 
+void
+pygi_info_register_types(PyObject *m)
+{
+#define REGISTER_TYPE(m, type, name) \
+    type.ob_type = &PyType_Type; \
+    type.tp_alloc = PyType_GenericAlloc; \
+    type.tp_new = PyType_GenericNew; \
+    if (PyType_Ready(&type)) \
+        return; \
+    if (PyModule_AddObject(m, name, (PyObject *)&type)) \
+        return; \
+    Py_INCREF(&type)
+
+#define REGISTER_SUBTYPE(m, type, name, base) \
+    type.tp_base = &base; \
+    REGISTER_TYPE(m, type, name)
+
+    REGISTER_TYPE(m, PyGIBaseInfo_Type, "BaseInfo");
+
+    REGISTER_SUBTYPE(m, PyGIUnresolvedInfo_Type, "UnresolvedInfo", PyGIBaseInfo_Type);
+    REGISTER_SUBTYPE(m, PyGICallableInfo_Type, "CallableInfo", PyGIBaseInfo_Type);
+    REGISTER_SUBTYPE(m, PyGIRegisteredTypeInfo_Type, "RegisteredTypeInfo", PyGIBaseInfo_Type);
+    REGISTER_SUBTYPE(m, PyGIConstantInfo_Type, "ConstantInfo", PyGIBaseInfo_Type);
+    REGISTER_SUBTYPE(m, PyGIValueInfo_Type, "ValueInfo", PyGIBaseInfo_Type);
+    REGISTER_SUBTYPE(m, PyGIPropertyInfo_Type, "PropertyInfo", PyGIBaseInfo_Type);
+    REGISTER_SUBTYPE(m, PyGIFieldInfo_Type, "FieldInfo", PyGIBaseInfo_Type);
+    REGISTER_SUBTYPE(m, PyGIArgInfo_Type, "ArgInfo", PyGIBaseInfo_Type);
+    REGISTER_SUBTYPE(m, PyGITypeInfo_Type, "TypeInfo", PyGIBaseInfo_Type);
+
+    REGISTER_SUBTYPE(m, PyGIFunctionInfo_Type, "FunctionInfo", PyGICallableInfo_Type);
+    REGISTER_SUBTYPE(m, PyGICallbackInfo_Type, "CallbackInfo", PyGICallableInfo_Type);
+    REGISTER_SUBTYPE(m, PyGISignalInfo_Type, "SignalInfo", PyGICallableInfo_Type);
+    REGISTER_SUBTYPE(m, PyGIVFuncInfo_Type, "VFuncInfo", PyGICallableInfo_Type);
+
+    REGISTER_SUBTYPE(m, PyGIStructInfo_Type, "StructInfo", PyGIRegisteredTypeInfo_Type);
+    REGISTER_SUBTYPE(m, PyGIEnumInfo_Type, "EnumInfo", PyGIRegisteredTypeInfo_Type);
+    REGISTER_SUBTYPE(m, PyGIObjectInfo_Type, "ObjectInfo", PyGIRegisteredTypeInfo_Type);
+    REGISTER_SUBTYPE(m, PyGIBoxedInfo_Type, "BoxedInfo", PyGIRegisteredTypeInfo_Type);
+    REGISTER_SUBTYPE(m, PyGIInterfaceInfo_Type, "InterfaceInfo", PyGIRegisteredTypeInfo_Type);
+    REGISTER_SUBTYPE(m, PyGIUnionInfo_Type, "UnionInfo", PyGIRegisteredTypeInfo_Type);
+
+#undef REGISTER_SUBTYPE
+#undef REGISTER_TYPE
+}
+
+void
+pygi_info_register_constants(PyObject *m)
+{
+    PyModule_AddIntConstant(m, "TYPE_TAG_VOID", GI_TYPE_TAG_VOID);
+    PyModule_AddIntConstant(m, "TYPE_TAG_BOOLEAN", GI_TYPE_TAG_BOOLEAN);
+    PyModule_AddIntConstant(m, "TYPE_TAG_INT8", GI_TYPE_TAG_INT8);
+    PyModule_AddIntConstant(m, "TYPE_TAG_UINT8", GI_TYPE_TAG_UINT8);
+    PyModule_AddIntConstant(m, "TYPE_TAG_INT16", GI_TYPE_TAG_INT16);
+    PyModule_AddIntConstant(m, "TYPE_TAG_UINT16", GI_TYPE_TAG_UINT16);
+    PyModule_AddIntConstant(m, "TYPE_TAG_INT32", GI_TYPE_TAG_INT32);
+    PyModule_AddIntConstant(m, "TYPE_TAG_UINT32", GI_TYPE_TAG_UINT32);
+    PyModule_AddIntConstant(m, "TYPE_TAG_INT64", GI_TYPE_TAG_INT64);
+    PyModule_AddIntConstant(m, "TYPE_TAG_UINT64", GI_TYPE_TAG_UINT64);
+#if 0
+    /* FIXME: Removed from metadata format, fix properly by introducing
+       special-case struct */
+    PyModule_AddIntConstant(m, "TYPE_TAG_GSTRING", GI_TYPE_TAG_GSTRING);
+#endif
+    PyModule_AddIntConstant(m, "TYPE_TAG_SHORT", GI_TYPE_TAG_SHORT);
+    PyModule_AddIntConstant(m, "TYPE_TAG_USHORT", GI_TYPE_TAG_USHORT);
+    PyModule_AddIntConstant(m, "TYPE_TAG_INT", GI_TYPE_TAG_INT);
+    PyModule_AddIntConstant(m, "TYPE_TAG_UINT", GI_TYPE_TAG_UINT);
+    PyModule_AddIntConstant(m, "TYPE_TAG_LONG", GI_TYPE_TAG_LONG);
+    PyModule_AddIntConstant(m, "TYPE_TAG_ULONG", GI_TYPE_TAG_ULONG);
+    PyModule_AddIntConstant(m, "TYPE_TAG_SSIZE", GI_TYPE_TAG_SSIZE);
+    PyModule_AddIntConstant(m, "TYPE_TAG_SIZE", GI_TYPE_TAG_SIZE);
+    PyModule_AddIntConstant(m, "TYPE_TAG_FLOAT", GI_TYPE_TAG_FLOAT);
+    PyModule_AddIntConstant(m, "TYPE_TAG_DOUBLE", GI_TYPE_TAG_DOUBLE);
+    PyModule_AddIntConstant(m, "TYPE_TAG_TIME_T", GI_TYPE_TAG_TIME_T);
+    PyModule_AddIntConstant(m, "TYPE_TAG_GTYPE", GI_TYPE_TAG_GTYPE);
+    PyModule_AddIntConstant(m, "TYPE_TAG_UTF8", GI_TYPE_TAG_UTF8);
+    PyModule_AddIntConstant(m, "TYPE_TAG_FILENAME", GI_TYPE_TAG_FILENAME);
+    PyModule_AddIntConstant(m, "TYPE_TAG_ARRAY", GI_TYPE_TAG_ARRAY);
+    PyModule_AddIntConstant(m, "TYPE_TAG_INTERFACE", GI_TYPE_TAG_INTERFACE);
+    PyModule_AddIntConstant(m, "TYPE_TAG_GLIST", GI_TYPE_TAG_GLIST);
+    PyModule_AddIntConstant(m, "TYPE_TAG_GSLIST", GI_TYPE_TAG_GSLIST);
+    PyModule_AddIntConstant(m, "TYPE_TAG_GHASH", GI_TYPE_TAG_GHASH);
+    PyModule_AddIntConstant(m, "TYPE_TAG_ERROR", GI_TYPE_TAG_ERROR);
+
+    PyModule_AddIntConstant(m, "DIRECTION_IN", GI_DIRECTION_IN);
+    PyModule_AddIntConstant(m, "DIRECTION_OUT", GI_DIRECTION_OUT);
+    PyModule_AddIntConstant(m, "DIRECTION_INOUT", GI_DIRECTION_INOUT);
+}
 
+#undef PYGIINFO_DEFINE_TYPE
diff --git a/gi/pygiinfo.h b/gi/pygiinfo.h
new file mode 100644
index 0000000..48dca49
--- /dev/null
+++ b/gi/pygiinfo.h
@@ -0,0 +1,40 @@
+/* -*- Mode: C; c-basic-offset: 4 -*-
+ * vim: tabstop=4 shiftwidth=4 expandtab
+ *
+ * Copyright (C) 2005-2009 Johan Dahlin <johan gnome org>
+ *
+ * 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
+ * USA
+ */
+
+#ifndef __PYGI_INFO_H__
+#define __PYGI_INFO_H__
+
+#include <Python.h>
+
+#include <girepository.h>
+
+G_BEGIN_DECLS
+
+PyObject* pyg_info_new(gpointer info);
+
+GIBaseInfo* pyg_base_info_from_object(PyObject *object);
+
+void pygi_info_register_types(PyObject *m);
+void pygi_info_register_constants(PyObject *m);
+
+G_END_DECLS
+
+#endif /* __PYGI_INFO_H__ */
diff --git a/girepository/bank-repository.c b/gi/pygirepository.c
similarity index 66%
rename from girepository/bank-repository.c
rename to gi/pygirepository.c
index 45a9ee2..3843241 100644
--- a/girepository/bank-repository.c
+++ b/gi/pygirepository.c
@@ -1,7 +1,9 @@
 /* -*- Mode: C; c-basic-offset: 4 -*-
- * vim: set ts=8 sts=4 sw=4 et ai cindent :
- * 
- * Copyright (C) 2005  Johan Dahlin <johan gnome org>
+ * vim: tabstop=4 shiftwidth=4 expandtab
+ *
+ * Copyright (C) 2005-2009 Johan Dahlin <johan gnome org>
+ *
+ *   pygirepository.c: GIRepository wrapper.
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
@@ -15,58 +17,48 @@
  *
  * 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., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
+ * USA
  */
 
-#include "bank.h"
+#include "pygi-private.h"
 
 static PyMethodDef _PyGIRepository_methods[];
 
 PyTypeObject PyGIRepository_Type = {
     PyObject_HEAD_INIT(NULL)
     0,
-    "bank.IRepository",
-    sizeof(PyGIRepository),
-    0,
-    /* methods */
-    (destructor)0,
-    (printfunc)0,
-    (getattrfunc)0,
-    (setattrfunc)0,
-    (cmpfunc)0,
-    (reprfunc)0,
-    0,
-    0,
-    0,
-    (hashfunc)0,
-    (ternaryfunc)0,
-    (reprfunc)0,
-    (getattrofunc)0,
-    (setattrofunc)0,
-    0,
-    Py_TPFLAGS_DEFAULT,
-    NULL,
-    (traverseproc)0,
-    (inquiry)0,
-    (richcmpfunc)0,
-    0,
-    (getiterfunc)0,
-    (iternextfunc)0,
-    _PyGIRepository_methods,
-    0,
-    0,
-    NULL,
-    NULL,
-    (descrgetfunc)0,
-    (descrsetfunc)0,
-    0,
-    (initproc)0,
+    "gi.Repository",         /* tp_name */
+    sizeof(PyGIRepository),  /* tp_basicsize */
+    0,                       /* tp_itemsize */
+    (destructor)NULL,        /* tp_dealloc */
+    (printfunc)NULL,         /* tp_print */
+    (getattrfunc)NULL,       /* tp_getattr */
+    (setattrfunc)NULL,       /* tp_setattr */
+    (cmpfunc)NULL,           /* tp_compare */
+    (reprfunc)NULL,          /* tp_repr */
+    NULL,                    /* tp_as_number */
+    NULL,                    /* tp_as_sequence */
+    NULL,                    /* tp_as_mapping */
+    (hashfunc)NULL,          /* tp_hash */
+    (ternaryfunc)NULL,       /* tp_call */
+    (reprfunc)NULL,          /* tp_str */
+    (getattrofunc)NULL,      /* tp_getattro */
+    (setattrofunc)NULL,      /* tp_setattro */
+    NULL,                    /* tp_as_buffer */
+    Py_TPFLAGS_DEFAULT,      /* tp_flags */
+    NULL,                    /* tp_doc */
+    (traverseproc)NULL,      /* tp_traverse */
+    (inquiry)NULL,           /* tp_clear */
+    (richcmpfunc)NULL,       /* tp_richcompare */
+    0,                       /* tp_weaklistoffset */
+    (getiterfunc)NULL,       /* tp_iter */
+    (iternextfunc)NULL,      /* tp_iternext */
+    _PyGIRepository_methods, /* tp_methods */
 };
 
 static PyObject *
-_wrap_g_irepository_require(PyGIRepository *self,
-			    PyObject *args,
-			    PyObject *kwargs)
+_wrap_g_irepository_require(PyGIRepository *self, PyObject *args, PyObject *kwargs)
 {
     static char *kwlist[] = { "namespace", "lazy", NULL };
     gchar *namespace;
@@ -87,7 +79,7 @@ _wrap_g_irepository_require(PyGIRepository *self,
     /* TODO - handle versioning in some way, need to figure out what
      * this looks like Python side.
      */
-    ret = g_irepository_require(self->repo, namespace, NULL, flags, &error);
+    ret = g_irepository_require(self->repository, namespace, NULL, flags, &error);
 
     if (ret == NULL) {
 #if 0
@@ -117,7 +109,7 @@ _wrap_g_irepository_find_by_name(PyGIRepository *self,
 				     kwlist, &namespace, &name))
         return NULL;
 
-    info = g_irepository_find_by_name (self->repo, namespace, name);
+    info = g_irepository_find_by_name (self->repository, namespace, name);
     if (!info) {
 	Py_INCREF(Py_None);
 	return Py_None;
@@ -133,7 +125,7 @@ _wrap_g_irepository_get_namespaces(PyGIRepository *self)
     int i, length;
     PyObject *retval;
 
-    namespaces = g_irepository_get_loaded_namespaces(self->repo);
+    namespaces = g_irepository_get_loaded_namespaces(self->repository);
 
     length = g_strv_length(namespaces);
     retval = PyTuple_New(length);
@@ -161,12 +153,12 @@ _wrap_g_irepository_get_infos(PyGIRepository *self,
 				     kwlist, &namespace))
         return NULL;
 
-    length = g_irepository_get_n_infos(self->repo, namespace);
+    length = g_irepository_get_n_infos(self->repository, namespace);
 
     retval = PyTuple_New(length);
 
     for (i = 0; i < length; i++) {
-	GIBaseInfo *info = g_irepository_get_info(self->repo, namespace, i);
+	GIBaseInfo *info = g_irepository_get_info(self->repository, namespace, i);
 	PyTuple_SetItem(retval, i, pyg_info_new(info));
     }
 
@@ -180,13 +172,13 @@ _wrap_g_irepository_is_registered(PyGIRepository *self,
 {
     static char *kwlist[] = { "namespace", NULL };
     char *namespace;
- 
+
     if (!PyArg_ParseTupleAndKeywords(args, kwargs,
 				     "s:GIRepository.isRegistered",
 				     kwlist, &namespace))
         return NULL;
 
-    return PyBool_FromLong(g_irepository_is_registered(self->repo, namespace, NULL));
+    return PyBool_FromLong(g_irepository_is_registered(self->repository, namespace, NULL));
 }
 
 static PyObject *
@@ -203,7 +195,7 @@ _wrap_g_irepository_get_c_prefix(PyGIRepository *self,
 				     kwlist, &namespace))
         return NULL;
 
-    return PyString_FromString(g_irepository_get_c_prefix(self->repo, namespace));
+    return PyString_FromString(g_irepository_get_c_prefix(self->repository, namespace));
 }
 
 static PyObject *
@@ -217,7 +209,7 @@ _wrap_g_irepository_get_default(PyObject *_)
 	if (self == NULL)
 	    return NULL;
 
-	self->repo = g_irepository_get_default();
+	self->repository = g_irepository_get_default();
     }
 
     return (PyObject*)self;
@@ -234,3 +226,18 @@ static PyMethodDef _PyGIRepository_methods[] = {
     { NULL, NULL, 0 }
 };
 
+void
+pygi_repository_register_types(PyObject *m)
+{
+    PyGIRepository_Type.ob_type = &PyType_Type;
+    PyGIRepository_Type.tp_alloc = PyType_GenericAlloc;
+    PyGIRepository_Type.tp_new = PyType_GenericNew;
+    if (PyType_Ready(&PyGIRepository_Type)) {
+        return;
+    }
+    if (PyModule_AddObject(m, "Repository", (PyObject *)&PyGIRepository_Type)) {
+        return;
+    }
+    Py_INCREF(&PyGIRepository_Type);
+}
+
diff --git a/gi/pygirepository.h b/gi/pygirepository.h
new file mode 100644
index 0000000..573ecf3
--- /dev/null
+++ b/gi/pygirepository.h
@@ -0,0 +1,33 @@
+/* -*- Mode: C; c-basic-offset: 4 -*-
+ * vim: tabstop=4 shiftwidth=4 expandtab
+ *
+ * Copyright (C) 2005-2009 Johan Dahlin <johan gnome org>
+ *
+ * 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
+ * USA
+ */
+
+#ifndef __PYGI_REPOSITORY_H__
+#define __PYGI_REPOSITORY_H__
+
+#include <Python.h>
+
+G_BEGIN_DECLS
+
+void pygi_repository_register_types(PyObject *m);
+
+G_END_DECLS
+
+#endif /* __PYGI_REPOSITORY_H__ */
diff --git a/girepository/repository.py b/gi/repository.py
similarity index 89%
rename from girepository/repository.py
rename to gi/repository.py
index a72c6a9..f15ad31 100644
--- a/girepository/repository.py
+++ b/gi/repository.py
@@ -1,6 +1,9 @@
 # -*- Mode: Python; py-indent-offset: 4 -*-
+# vim: tabstop=4 shiftwidth=4 expandtab
 #
-# Copyright (C) 2007 Johan Dahlin <johan gnome org>
+# Copyright (C) 2007-2009 Johan Dahlin <johan gnome org>
+#
+#   repository.py: Repository wrapper.
 #
 # This library is free software; you can redistribute it and/or
 # modify it under the terms of the GNU Lesser General Public
@@ -14,12 +17,12 @@
 #
 # 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., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
-#
+# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301
+# USA
 
 import gobject
 
-from .repo import Repository
+from ._gi import Repository
 
 class _Repository(object):
     def __init__(self):
diff --git a/girepository/btypes.py b/gi/types.py
similarity index 93%
rename from girepository/btypes.py
rename to gi/types.py
index f4673bd..b00bc62 100644
--- a/girepository/btypes.py
+++ b/gi/types.py
@@ -1,6 +1,9 @@
 # -*- Mode: Python; py-indent-offset: 4 -*-
+# vim: tabstop=4 shiftwidth=4 expandtab
 #
-# Copyright (C) 2005, 2007  Johan Dahlin <johan gnome org>
+# Copyright (C) 2005-2009 Johan Dahlin <johan gnome org>
+#
+#   types.py: base types for introspected items.
 #
 # This library is free software; you can redistribute it and/or
 # modify it under the terms of the GNU Lesser General Public
@@ -14,15 +17,19 @@
 #
 # 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., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
-#
-
-import gobject
+# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301
+# USA
 
 from new import instancemethod
 
-from . import repo
-from .repo import InterfaceInfo, ObjectInfo, StructInfo, EnumInfo
+import gobject
+
+from ._gi import \
+	setObjectHasNewConstructor, \
+	InterfaceInfo, \
+	ObjectInfo, \
+	StructInfo, \
+	EnumInfo
 from .repository import repository
 
 
@@ -55,7 +62,7 @@ class GObjectIntrospectionMeta(gobject.GObjectMeta):
         super(GObjectIntrospectionMeta, cls).__init__(name, bases, dict_)
 
         if hasattr(cls, '__gtype__'):
-            repo.setObjectHasNewConstructor(cls.__gtype__)
+            setObjectHasNewConstructor(cls.__gtype__)
 
         # Only set up the wrapper methods and fields in their base classes.
         if cls.__name__ == cls.__info__.getName():
diff --git a/tests/test_girepository.py b/tests/test_girepository.py
index a9cbdb0..7ddf488 100644
--- a/tests/test_girepository.py
+++ b/tests/test_girepository.py
@@ -6,8 +6,7 @@ import time
 import gobject
 from gobject import constants
 
-import girepository
-import GLib
+import gi
 import Everything
 
 INT8_MIN = -128



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