[pygobject] Move pygi foreign API into pygi-foreign-api.h



commit def47144b63a1492ebf47a4eadb535f45253ff3a
Author: Simon Feltman <sfeltman src gnome org>
Date:   Sat Mar 22 14:13:01 2014 -0700

    Move pygi foreign API into pygi-foreign-api.h
    
    Move limited set of APIs necessary for registering foreign marshalers into
    pygi-foreign-api.h. Remove "_real" from internally used APIs and add necessary
    includes to the rest of pygobject for calling directly (instead of going through
    the PyCapsule API within PyGI itself).
    This is needed to avoid compilation errors when including pygobject.h in
    foreign marshaling plugins which conflicts with pygobject-private.h.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=694604

 gi/Makefile.am           |    1 +
 gi/gimodule.c            |    6 +--
 gi/pygboxed.c            |    1 +
 gi/pygenum.c             |    1 +
 gi/pygflags.c            |    1 +
 gi/pygi-foreign-api.h    |   85 ++++++++++++++++++++++++++++++++++++
 gi/pygi-foreign-cairo.c  |    8 ++-
 gi/pygi-foreign.c        |   10 ++--
 gi/pygi-foreign.h        |   14 +++---
 gi/pygi-property.c       |    8 ++--
 gi/pygi-property.h       |   14 +++---
 gi/pygi-signal-closure.c |   12 +++---
 gi/pygi-signal-closure.h |   15 +++---
 gi/pygi-type.c           |    4 +-
 gi/pygi-type.h           |    2 +-
 gi/pygi.h                |  107 ----------------------------------------------
 gi/pygobject.c           |    3 +
 gi/pygpointer.c          |    1 +
 18 files changed, 139 insertions(+), 154 deletions(-)
---
diff --git a/gi/Makefile.am b/gi/Makefile.am
index b00d30a..61e4ee7 100644
--- a/gi/Makefile.am
+++ b/gi/Makefile.am
@@ -71,6 +71,7 @@ _gi_la_SOURCES = \
        pygi-info.h \
        pygi-foreign.c \
        pygi-foreign.h \
+       pygi-foreign-api.h \
        pygi-struct.c \
        pygi-struct.h \
        pygi-source.c \
diff --git a/gi/gimodule.c b/gi/gimodule.c
index 17e8587..1731190 100644
--- a/gi/gimodule.c
+++ b/gi/gimodule.c
@@ -620,11 +620,7 @@ static PyMethodDef _gi_functions[] = {
 };
 
 static struct PyGI_API CAPI = {
-  pygi_type_import_by_g_type_real,
-  pygi_get_property_value_real,
-  pygi_set_property_value_real,
-  pygi_signal_closure_new_real,
-  pygi_register_foreign_struct_real,
+  pygi_register_foreign_struct,
 };
 
 PYGLIB_MODULE_START(_gi, "_gi")
diff --git a/gi/pygboxed.c b/gi/pygboxed.c
index 35716a2..5e579db 100644
--- a/gi/pygboxed.c
+++ b/gi/pygboxed.c
@@ -27,6 +27,7 @@
 #include "pygboxed.h"
 
 #include "pygi.h"
+#include "pygi-type.h"
 
 GQuark pygboxed_type_key;
 GQuark pygboxed_marshal_key;
diff --git a/gi/pygenum.c b/gi/pygenum.c
index 1b9b50e..053518f 100644
--- a/gi/pygenum.c
+++ b/gi/pygenum.c
@@ -26,6 +26,7 @@
 #include <pyglib.h>
 #include "pygobject-private.h"
 #include "pygi.h"
+#include "pygi-type.h"
 
 #include "pygenum.h"
 
diff --git a/gi/pygflags.c b/gi/pygflags.c
index c14bf7d..a7df8ce 100644
--- a/gi/pygflags.c
+++ b/gi/pygflags.c
@@ -28,6 +28,7 @@
 #include "pygflags.h"
 
 #include "pygi.h"
+#include "pygi-type.h"
 
 GQuark pygflags_class_key;
 
diff --git a/gi/pygi-foreign-api.h b/gi/pygi-foreign-api.h
new file mode 100644
index 0000000..9367518
--- /dev/null
+++ b/gi/pygi-foreign-api.h
@@ -0,0 +1,85 @@
+/* -*- 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, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef __PYGI_FOREIGN_API_H__
+#define __PYGI_FOREIGN_API_H__
+
+#include <girepository.h>
+#include <pygobject.h>
+
+typedef PyObject * (*PyGIArgOverrideToGIArgumentFunc)   (PyObject        *value,
+                                                         GIInterfaceInfo *interface_info,
+                                                         GITransfer       transfer,
+                                                         GIArgument      *arg);
+typedef PyObject * (*PyGIArgOverrideFromGIArgumentFunc) (GIInterfaceInfo *interface_info,
+                                                         GITransfer       transfer,
+                                                         gpointer         data);
+typedef PyObject * (*PyGIArgOverrideReleaseFunc)        (GITypeInfo *type_info,
+                                                         gpointer  struct_);
+
+
+struct PyGI_API {
+    void (*register_foreign_struct) (const char* namespace_,
+                                     const char* name,
+                                     PyGIArgOverrideToGIArgumentFunc to_func,
+                                     PyGIArgOverrideFromGIArgumentFunc from_func,
+                                     PyGIArgOverrideReleaseFunc release_func);
+};
+
+
+#ifndef _INSIDE_PYGOBJECT_
+
+static struct PyGI_API *PyGI_API = NULL;
+
+static int
+_pygi_import (void)
+{
+    if (PyGI_API != NULL) {
+        return 1;
+    }
+    PyGI_API = (struct PyGI_API*) PyCapsule_Import("gi._API", FALSE);
+    if (PyGI_API == NULL) {
+        return -1;
+    }
+
+    return 0;
+}
+
+
+static inline PyObject *
+pygi_register_foreign_struct (const char* namespace_,
+                              const char* name,
+                              PyGIArgOverrideToGIArgumentFunc to_func,
+                              PyGIArgOverrideFromGIArgumentFunc from_func,
+                              PyGIArgOverrideReleaseFunc release_func)
+{
+    if (_pygi_import() < 0) {
+        return NULL;
+    }
+    PyGI_API->register_foreign_struct(namespace_,
+                                      name,
+                                      to_func,
+                                      from_func,
+                                      release_func);
+    Py_RETURN_NONE;
+}
+
+#endif /* _INSIDE_PYGOBJECT_ */
+
+#endif /* __PYGI_FOREIGN_API_H__ */
diff --git a/gi/pygi-foreign-cairo.c b/gi/pygi-foreign-cairo.c
index 8261a07..a53ae4f 100644
--- a/gi/pygi-foreign-cairo.c
+++ b/gi/pygi-foreign-cairo.c
@@ -31,9 +31,11 @@ static Pycairo_CAPI_t *Pycairo_CAPI;
 #include <pycairo/py3cairo.h>
 #endif
 
-
-#include "pygi-foreign.h"
-
+/* Limit includes from PyGI to APIs which do not have link dependencies
+ * (pygobject.h and pygi-foreign-api.h) since _gi_cairo is built as a separate
+ * shared library that interacts with PyGI through a PyCapsule API at runtime.
+ */
+#include <pygi-foreign-api.h>
 #include <pyglib-python-compat.h>
 
 static PyObject *
diff --git a/gi/pygi-foreign.c b/gi/pygi-foreign.c
index f3c1a34..6e0bf79 100644
--- a/gi/pygi-foreign.c
+++ b/gi/pygi-foreign.c
@@ -151,11 +151,11 @@ pygi_struct_foreign_release (GIBaseInfo *base_info,
 }
 
 void
-pygi_register_foreign_struct_real (const char* namespace_,
-                                   const char* name,
-                                   PyGIArgOverrideToGIArgumentFunc to_func,
-                                   PyGIArgOverrideFromGIArgumentFunc from_func,
-                                   PyGIArgOverrideReleaseFunc release_func)
+pygi_register_foreign_struct (const char* namespace_,
+                              const char* name,
+                              PyGIArgOverrideToGIArgumentFunc to_func,
+                              PyGIArgOverrideFromGIArgumentFunc from_func,
+                              PyGIArgOverrideReleaseFunc release_func)
 {
     PyGIForeignStruct *new_struct = g_slice_new (PyGIForeignStruct);
     new_struct->namespace = namespace_;
diff --git a/gi/pygi-foreign.h b/gi/pygi-foreign.h
index 478d759..acec069 100644
--- a/gi/pygi-foreign.h
+++ b/gi/pygi-foreign.h
@@ -26,9 +26,7 @@
 #define __PYGI_FOREIGN_H__
 
 #include <Python.h>
-#include <girepository.h>
-
-#include "pygi.h"
+#include "pygi-foreign-api.h"
 
 PyObject *pygi_struct_foreign_convert_to_g_argument (PyObject           *value,
                                                      GIInterfaceInfo    *interface_info,
@@ -40,10 +38,10 @@ PyObject *pygi_struct_foreign_convert_from_g_argument (GIInterfaceInfo *interfac
 PyObject *pygi_struct_foreign_release (GITypeInfo *type_info,
                                        gpointer struct_);
 
-void pygi_register_foreign_struct_real (const char* namespace_,
-                                        const char* name,
-                                        PyGIArgOverrideToGIArgumentFunc to_func,
-                                        PyGIArgOverrideFromGIArgumentFunc from_func,
-                                        PyGIArgOverrideReleaseFunc release_func);
+void pygi_register_foreign_struct (const char* namespace_,
+                                   const char* name,
+                                   PyGIArgOverrideToGIArgumentFunc to_func,
+                                   PyGIArgOverrideFromGIArgumentFunc from_func,
+                                   PyGIArgOverrideReleaseFunc release_func);
 
 #endif /* __PYGI_FOREIGN_H__ */
diff --git a/gi/pygi-property.c b/gi/pygi-property.c
index 6f80506..f7cb032 100644
--- a/gi/pygi-property.c
+++ b/gi/pygi-property.c
@@ -105,7 +105,7 @@ g_value_get_or_dup_boxed (const GValue *value, GITransfer transfer)
 }
 
 PyObject *
-pygi_get_property_value_real (PyGObject *instance, GParamSpec *pspec)
+pygi_get_property_value (PyGObject *instance, GParamSpec *pspec)
 {
     GIPropertyInfo *property_info = NULL;
     GValue value = { 0, };
@@ -271,9 +271,9 @@ out:
 }
 
 gint
-pygi_set_property_value_real (PyGObject *instance,
-                              GParamSpec *pspec,
-                              PyObject *py_value)
+pygi_set_property_value (PyGObject *instance,
+                         GParamSpec *pspec,
+                         PyObject *py_value)
 {
     GIPropertyInfo *property_info = NULL;
     GITypeInfo *type_info = NULL;
diff --git a/gi/pygi-property.h b/gi/pygi-property.h
index 875d21e..5678bc3 100644
--- a/gi/pygi-property.h
+++ b/gi/pygi-property.h
@@ -27,13 +27,15 @@
 #include <Python.h>
 #include <girepository.h>
 
-#include "pygi.h"
+#include "pygobject.h"
 
-PyObject *pygi_get_property_value_real (PyGObject *instance,
-                                        GParamSpec *pspec);
+PyObject *
+pygi_get_property_value (PyGObject *instance,
+                         GParamSpec *pspec);
 
-gint pygi_set_property_value_real (PyGObject *instance,
-                                   GParamSpec *pspec,
-                                   PyObject *py_value);
+gint
+pygi_set_property_value (PyGObject *instance,
+                         GParamSpec *pspec,
+                         PyObject *py_value);
 
 #endif /* __PYGI_PROPERTY_H__ */
diff --git a/gi/pygi-signal-closure.c b/gi/pygi-signal-closure.c
index c5f51af..079669c 100644
--- a/gi/pygi-signal-closure.c
+++ b/gi/pygi-signal-closure.c
@@ -171,12 +171,12 @@ pygi_signal_closure_marshal(GClosure *closure,
 }
 
 GClosure *
-pygi_signal_closure_new_real (PyGObject *instance,
-                              GType g_type,
-                              const gchar *signal_name,
-                              PyObject *callback,
-                              PyObject *extra_args,
-                              PyObject *swap_data)
+pygi_signal_closure_new (PyGObject *instance,
+                         GType g_type,
+                         const gchar *signal_name,
+                         PyObject *callback,
+                         PyObject *extra_args,
+                         PyObject *swap_data)
 {
     GClosure *closure = NULL;
     PyGISignalClosure *pygi_closure = NULL;
diff --git a/gi/pygi-signal-closure.h b/gi/pygi-signal-closure.h
index ffdd29c..5cc191b 100644
--- a/gi/pygi-signal-closure.h
+++ b/gi/pygi-signal-closure.h
@@ -24,7 +24,7 @@
 #ifndef __PYGI_SIGNAL_CLOSURE_H__
 #define __PYGI_SIGNAL_CLOSURE_H__
 
-#include "pygi.h"
+#include "pygobject.h"
 
 G_BEGIN_DECLS
 
@@ -35,12 +35,13 @@ typedef struct _PyGISignalClosure
     GISignalInfo *signal_info;
 } PyGISignalClosure;
 
-GClosure * pygi_signal_closure_new_real (PyGObject *instance,
-                                         GType g_type,
-                                         const gchar *sig_name,
-                                         PyObject *callback,
-                                         PyObject *extra_args,
-                                         PyObject *swap_data);
+GClosure *
+pygi_signal_closure_new (PyGObject *instance,
+                         GType g_type,
+                         const gchar *sig_name,
+                         PyObject *callback,
+                         PyObject *extra_args,
+                         PyObject *swap_data);
 
 G_END_DECLS
 
diff --git a/gi/pygi-type.c b/gi/pygi-type.c
index b8d4c65..924e0b8 100644
--- a/gi/pygi-type.c
+++ b/gi/pygi-type.c
@@ -50,7 +50,7 @@ _pygi_type_import_by_name (const char *namespace_,
 }
 
 PyObject *
-pygi_type_import_by_g_type_real (GType g_type)
+pygi_type_import_by_g_type (GType g_type)
 {
     GIRepository *repository;
     GIBaseInfo *info;
@@ -89,7 +89,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_real (g_type);
+        py_type = pygi_type_import_by_g_type (g_type);
     }
 
     Py_DECREF (py_g_type);
diff --git a/gi/pygi-type.h b/gi/pygi-type.h
index 822a441..fdac5c0 100644
--- a/gi/pygi-type.h
+++ b/gi/pygi-type.h
@@ -26,7 +26,7 @@ G_BEGIN_DECLS
 
 /* Public */
 
-PyObject *pygi_type_import_by_g_type_real (GType g_type);
+PyObject *pygi_type_import_by_g_type (GType g_type);
 
 
 /* Private */
diff --git a/gi/pygi.h b/gi/pygi.h
index a67696e..2a9ee14 100644
--- a/gi/pygi.h
+++ b/gi/pygi.h
@@ -78,112 +78,5 @@ typedef struct {
     PyGICallableCache *cache;
 } PyGICCallback;
 
-typedef PyObject * (*PyGIArgOverrideToGIArgumentFunc) (PyObject        *value,
-                                                       GIInterfaceInfo *interface_info,
-                                                       GITransfer       transfer,
-                                                       GIArgument      *arg);
-typedef PyObject * (*PyGIArgOverrideFromGIArgumentFunc) (GIInterfaceInfo *interface_info,
-                                                         GITransfer       transfer,
-                                                         gpointer         data);
-typedef PyObject * (*PyGIArgOverrideReleaseFunc) (GITypeInfo *type_info,
-                                                  gpointer  struct_);
-
-struct PyGI_API {
-    PyObject* (*type_import_by_g_type) (GType g_type);
-    PyObject* (*get_property_value) (PyGObject *instance,
-                                     GParamSpec *pspec);
-    gint (*set_property_value) (PyGObject *instance,
-                                GParamSpec *pspec,
-                                PyObject *value);
-    GClosure * (*signal_closure_new) (PyGObject *instance,
-                                      GType g_type,
-                                      const gchar *sig_name,
-                                      PyObject *callback,
-                                      PyObject *extra_args,
-                                      PyObject *swap_data);
-    void (*register_foreign_struct) (const char* namespace_,
-                                     const char* name,
-                                     PyGIArgOverrideToGIArgumentFunc to_func,
-                                     PyGIArgOverrideFromGIArgumentFunc from_func,
-                                     PyGIArgOverrideReleaseFunc release_func);
-};
-
-static struct PyGI_API *PyGI_API = NULL;
-
-static int
-_pygi_import (void)
-{
-    if (PyGI_API != NULL) {
-        return 1;
-    }
-    PyGI_API = (struct PyGI_API*) PyCapsule_Import("gi._API", FALSE);
-    if (PyGI_API == NULL) {
-        return -1;
-    }
-
-    return 0;
-}
-
-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);
-}
-
-static inline PyObject *
-pygi_get_property_value (PyGObject *instance,
-                         GParamSpec *pspec)
-{
-    if (_pygi_import() < 0) {
-        return NULL;
-    }
-    return PyGI_API->get_property_value(instance, pspec);
-}
-
-static inline gint
-pygi_set_property_value (PyGObject *instance,
-                         GParamSpec *pspec,
-                         PyObject *value)
-{
-    if (_pygi_import() < 0) {
-        return -1;
-    }
-    return PyGI_API->set_property_value(instance, pspec, value);
-}
-
-static inline GClosure *
-pygi_signal_closure_new (PyGObject *instance,
-                         GType g_type,
-                         const gchar *sig_name,
-                         PyObject *callback,
-                         PyObject *extra_args,
-                         PyObject *swap_data)
-{
-    if (_pygi_import() < 0) {
-        return NULL;
-    }
-    return PyGI_API->signal_closure_new(instance, g_type, sig_name, callback, extra_args, swap_data);
-}
-
-static inline PyObject *
-pygi_register_foreign_struct (const char* namespace_,
-                              const char* name,
-                              PyGIArgOverrideToGIArgumentFunc to_func,
-                              PyGIArgOverrideFromGIArgumentFunc from_func,
-                              PyGIArgOverrideReleaseFunc release_func)
-{
-    if (_pygi_import() < 0) {
-        return NULL;
-    }
-    PyGI_API->register_foreign_struct(namespace_,
-                                      name,
-                                      to_func,
-                                      from_func,
-                                      release_func);
-    Py_RETURN_NONE;
-}
 
 #endif /* __PYGI_H__ */
diff --git a/gi/pygobject.c b/gi/pygobject.c
index 04fd6a5..1a011e1 100644
--- a/gi/pygobject.c
+++ b/gi/pygobject.c
@@ -29,6 +29,9 @@
 
 #include "pygi.h"
 #include "pygi-value.h"
+#include "pygi-type.h"
+#include "pygi-property.h"
+#include "pygi-signal-closure.h"
 
 static void pygobject_dealloc(PyGObject *self);
 static int  pygobject_traverse(PyGObject *self, visitproc visit, void *arg);
diff --git a/gi/pygpointer.c b/gi/pygpointer.c
index 2729695..7e39429 100644
--- a/gi/pygpointer.c
+++ b/gi/pygpointer.c
@@ -27,6 +27,7 @@
 #include "pygpointer.h"
 
 #include "pygi.h"
+#include "pygi-type.h"
 
 
 GQuark pygpointer_class_key;


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