[pygobject/gsoc2009: 116/160] Make PyGI public
- From: Simon van der Linden <svdlinden src gnome org>
- To: svn-commits-list gnome org
- Cc:
- Subject: [pygobject/gsoc2009: 116/160] Make PyGI public
- Date: Fri, 14 Aug 2009 21:33:29 +0000 (UTC)
commit 3eb0baea679113593e66e02748d199bd454e02c3
Author: Simon van der Linden <svdlinden src gnome org>
Date: Wed Aug 5 23:40:27 2009 +0200
Make PyGI public
gi/Makefile.am | 1 +
gi/__init__.py | 2 ++
gi/gimodule.c | 11 +++++++++++
gi/pygi.h | 44 +++++++++++++++++++++++++++++++++++++++++++-
gobject/Makefile.am | 1 +
5 files changed, 58 insertions(+), 1 deletions(-)
---
diff --git a/gi/Makefile.am b/gi/Makefile.am
index 08145e1..a66e10d 100644
--- a/gi/Makefile.am
+++ b/gi/Makefile.am
@@ -10,6 +10,7 @@ INCLUDES = \
$(PYGOBJECT_CFLAGS) \
$(GOBJECT_INTROSPECTION_CFLAGS)
+pkgincludedir = $(includedir)/pygtk-$(PLATFORM_VERSION)
pkginclude_HEADERS = pygi.h
# gi extension modules
diff --git a/gi/__init__.py b/gi/__init__.py
index 1f6a31e..3e2b049 100644
--- a/gi/__init__.py
+++ b/gi/__init__.py
@@ -18,3 +18,5 @@
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301
# USA
+from ._gi import _API
+
diff --git a/gi/gimodule.c b/gi/gimodule.c
index 41dc111..c8a0185 100644
--- a/gi/gimodule.c
+++ b/gi/gimodule.c
@@ -128,10 +128,15 @@ static PyMethodDef _pygi_functions[] = {
{ NULL, NULL, 0 }
};
+struct PyGI_API PyGI_API = {
+ pygi_type_find_by_info
+};
+
PyMODINIT_FUNC
init_gi(void)
{
PyObject *m;
+ PyObject *api;
m = Py_InitModule("_gi", _pygi_functions);
if (m == NULL) {
@@ -145,5 +150,11 @@ init_gi(void)
_pygi_repository_register_types(m);
_pygi_info_register_types(m);
_pygi_argument_init();
+
+ api = PyCObject_FromVoidPtr((void *)&PyGI_API, NULL);
+ if (api == NULL) {
+ return;
+ }
+ PyModule_AddObject(m, "_API", api);
}
diff --git a/gi/pygi.h b/gi/pygi.h
index f7e6931..23f0f0d 100644
--- a/gi/pygi.h
+++ b/gi/pygi.h
@@ -40,9 +40,51 @@ typedef struct {
} PyGIBaseInfo;
+struct PyGI_API {
+ PyObject* (*type_find_by_info) (GIBaseInfo *info);
+};
+
+
#ifndef __PYGI_PRIVATE_H__
-/* TODO: Public API goes here. */
+struct PyGI_API *PyGI_API = NULL;
+
+#define pygi_type_find_by_info (PyGI_API->type_find_by_info)
+
+static int
+pygi_import (void)
+{
+ PyObject *module;
+ PyObject *api;
+
+ if (PyGI_API != NULL) {
+ return 1;
+ }
+
+ module = PyImport_ImportModule("gi");
+ if (module == NULL) {
+ return -1;
+ }
+
+ api = PyObject_GetAttrString(module, "_API");
+ if (api == NULL) {
+ Py_DECREF(module);
+ return -1;
+ }
+ if (!PyCObject_Check(api)) {
+ Py_DECREF(module);
+ Py_DECREF(api);
+ PyErr_Format(PyExc_TypeError, "gi._API must be cobject, not %s",
+ api->ob_type->tp_name);
+ return -1;
+ }
+
+ PyGI_API = (struct PyGI_API *)PyCObject_AsVoidPtr(api);
+
+ Py_DECREF(api);
+
+ return 0;
+}
#endif
diff --git a/gobject/Makefile.am b/gobject/Makefile.am
index c71afa5..f3b776a 100644
--- a/gobject/Makefile.am
+++ b/gobject/Makefile.am
@@ -40,6 +40,7 @@ _gobject_la_CFLAGS = \
-DPY_SSIZE_T_CLEAN
if BUILD_GOBJECT_INTROSPECTION
_gobject_la_CFLAGS += \
+ -I$(top_srcdir)/gi \
$(GOBJECT_INTROSPECTION_CFLAGS)
endif
_gobject_la_LDFLAGS = $(common_ldflags) -export-symbols-regex "_gobject|PyInit__gobject"
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]