[pygobject] Remove pygi-external.h



commit a6a90551311bc64f037cbd442e13f70c30060871
Author: Tomeu Vizoso <tomeu vizoso collabora co uk>
Date:   Mon Jun 28 14:20:43 2010 +0200

    Remove pygi-external.h
    
    https://bugzilla.gnome.org/show_bug.cgi?id=623021

 gi/gimodule.c           |    8 +++---
 gi/pygi-type.c          |    4 +-
 gi/pygi-type.h          |    2 +-
 gi/pygi.h               |   54 +++++++++++++++----------------------
 gobject/Makefile.am     |    6 ++++
 gobject/pygboxed.c      |    2 +-
 gobject/pygenum.c       |    2 +-
 gobject/pygflags.c      |    2 +-
 gobject/pygi-external.h |   67 -----------------------------------------------
 gobject/pygobject.c     |    2 +-
 gobject/pygpointer.c    |    2 +-
 11 files changed, 40 insertions(+), 111 deletions(-)
---
diff --git a/gi/gimodule.c b/gi/gimodule.c
index 0375825..1a81abc 100644
--- a/gi/gimodule.c
+++ b/gi/gimodule.c
@@ -22,6 +22,7 @@
  */
 
 #include "pygi-private.h"
+#include "pygi.h"
 
 #include <pygobject.h>
 
@@ -241,11 +242,10 @@ static PyMethodDef _pygi_functions[] = {
     { NULL, NULL, 0 }
 };
 
-struct PyGI_API PyGI_API = {
-    pygi_type_import_by_g_type
+static struct PyGI_API CAPI = {
+  pygi_type_import_by_g_type_real,
 };
 
-
 PyMODINIT_FUNC
 init_gi (void)
 {
@@ -275,7 +275,7 @@ init_gi (void)
     _pygi_boxed_register_types (m);
     _pygi_argument_init();
 
-    api = PyCObject_FromVoidPtr ( (void *) &PyGI_API, NULL);
+    api = PyCObject_FromVoidPtr ( (void *) &CAPI, NULL);
     if (api == NULL) {
         return;
     }
diff --git a/gi/pygi-type.c b/gi/pygi-type.c
index 410efe1..bd9804e 100644
--- a/gi/pygi-type.c
+++ b/gi/pygi-type.c
@@ -54,7 +54,7 @@ _pygi_type_import_by_gi_info (GIBaseInfo *info)
 }
 
 PyObject *
-pygi_type_import_by_g_type (GType g_type)
+pygi_type_import_by_g_type_real (GType g_type)
 {
     GIRepository *repository;
     GIBaseInfo *info;
@@ -86,7 +86,7 @@ _pygi_type_get_from_g_type (GType g_type)
 
     py_type = PyObject_GetAttrString (py_g_type, "pytype");
     if (py_type == Py_None) {
-        py_type = pygi_type_import_by_g_type (g_type);
+        py_type = pygi_type_import_by_g_type_real (g_type);
     }
 
     Py_DECREF (py_g_type);
diff --git a/gi/pygi-type.h b/gi/pygi-type.h
index 19d07dc..16d5bdc 100644
--- a/gi/pygi-type.h
+++ b/gi/pygi-type.h
@@ -28,7 +28,7 @@ G_BEGIN_DECLS
 
 /* Public */
 
-PyObject *pygi_type_import_by_g_type (GType g_type);
+PyObject *pygi_type_import_by_g_type_real (GType g_type);
 
 
 /* Private */
diff --git a/gi/pygi.h b/gi/pygi.h
index a9c4665..667fa70 100644
--- a/gi/pygi.h
+++ b/gi/pygi.h
@@ -22,11 +22,12 @@
 #ifndef __PYGI_H__
 #define __PYGI_H__
 
+#include <config.h>
 #include <pygobject.h>
 
-#include <girepository.h>
+#if ENABLE_INTROSPECTION
 
-G_BEGIN_DECLS
+#include <girepository.h>
 
 typedef struct {
     PyObject_HEAD
@@ -55,51 +56,40 @@ struct PyGI_API {
     PyObject* (*type_import_by_g_type) (GType g_type);
 };
 
-
-#ifndef __PYGI_PRIVATE_H__
-
 static struct PyGI_API *PyGI_API = NULL;
 
-#define pygi_type_import_by_g_type (PyGI_API->type_import_by_g_type)
-
-
 static int
-pygi_import (void)
+_pygi_import (void)
 {
-    PyObject *module;
-    PyObject *api;
-
     if (PyGI_API != NULL) {
         return 1;
     }
 
-    module = PyImport_ImportModule ("gi");
-    if (module == NULL) {
+    PyGI_API = (struct PyGI_API*) PyCObject_Import("gi", "_API");
+    if (PyGI_API == 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;
-    }
+    return 0;
+}
 
-    PyGI_API = (struct PyGI_API *) PyCObject_AsVoidPtr (api);
+static inline PyObject *
+pygi_type_import_by_g_type (GType g_type)
+{
+   if (_pygi_import() < 0) {
+       return NULL;
+   }
+   return PyGI_API->type_import_by_g_type(g_type);
+}
 
-    Py_DECREF (api);
+#else /* ENABLE_INTROSPECTION */
 
-    return 0;
+static inline PyObject *
+pygi_type_import_by_g_type (GType g_type)
+{
+    return NULL;
 }
 
-#endif /* __PYGI_PRIVATE_H__ */
-
-G_END_DECLS
+#endif /* ENABLE_INTROSPECTION */
 
 #endif /* __PYGI_H__ */
diff --git a/gobject/Makefile.am b/gobject/Makefile.am
index 21523be..baac5bf 100644
--- a/gobject/Makefile.am
+++ b/gobject/Makefile.am
@@ -21,10 +21,16 @@ endif
 
 _gobject_la_CFLAGS = \
 	-I$(top_srcdir)/glib \
+	-I$(top_srcdir)/gi \
 	$(PYTHON_INCLUDES) \
 	$(FFI_CFLAGS) \
 	$(GLIB_CFLAGS) \
 	 -DPY_SSIZE_T_CLEAN
+
+if ENABLE_INTROSPECTION
+_gobject_la_CFLAGS += $(GI_CFLAGS)
+endif
+
 _gobject_la_LDFLAGS = $(common_ldflags) -export-symbols-regex "_gobject|PyInit__gobject"
 _gobject_la_LIBADD = \
 	$(GLIB_LIBS) \
diff --git a/gobject/pygboxed.c b/gobject/pygboxed.c
index 87695eb..7bc8e8e 100644
--- a/gobject/pygboxed.c
+++ b/gobject/pygboxed.c
@@ -28,7 +28,7 @@
 #include "pygobject-private.h"
 #include "pygboxed.h"
 
-#include "pygi-external.h"
+#include "pygi.h"
 
 GQuark pygboxed_type_key;
 GQuark pygboxed_marshal_key;
diff --git a/gobject/pygenum.c b/gobject/pygenum.c
index 027dbd4..a09ab98 100644
--- a/gobject/pygenum.c
+++ b/gobject/pygenum.c
@@ -28,7 +28,7 @@
 #include <pyglib.h>
 #include "pygobject-private.h"
 
-#include "pygi-external.h"
+#include "pygi.h"
 
 GQuark pygenum_class_key;
 
diff --git a/gobject/pygflags.c b/gobject/pygflags.c
index 1865abb..7bcd294 100644
--- a/gobject/pygflags.c
+++ b/gobject/pygflags.c
@@ -29,7 +29,7 @@
 #include "pygobject-private.h"
 #include "pygflags.h"
 
-#include "pygi-external.h"
+#include "pygi.h"
 
 GQuark pygflags_class_key;
 
diff --git a/gobject/pygobject.c b/gobject/pygobject.c
index 2671fa9..c37c8a8 100644
--- a/gobject/pygobject.c
+++ b/gobject/pygobject.c
@@ -29,7 +29,7 @@
 #include "pyginterface.h"
 #include "pygparamspec.h"
 
-#include "pygi-external.h"
+#include "pygi.h"
 
 
 static void pygobject_dealloc(PyGObject *self);
diff --git a/gobject/pygpointer.c b/gobject/pygpointer.c
index 5f6417f..95bfae9 100644
--- a/gobject/pygpointer.c
+++ b/gobject/pygpointer.c
@@ -28,7 +28,7 @@
 #include "pygobject-private.h"
 #include "pygpointer.h"
 
-#include "pygi-external.h"
+#include "pygi.h"
 
 
 GQuark pygpointer_class_key;



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