[pygobject] Merge static PyGLib module into PyGI



commit ad565e5bbc9d12607c39be9479bc671a8f2de6e3
Author: Simon Feltman <sfeltman src gnome org>
Date:   Wed Jan 8 18:57:58 2014 -0800

    Merge static PyGLib module into PyGI
    
    Remove gi._glib._glib as a separately compiled module. Move all C files into
    pygobject/gi. Remove compilation and use of libpyglib-gi-2.0-python.so as a
    shared dependency since we do not distribute header files for it.
    Remove unused threading macros.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=712197

 gi/Makefile.am                        |   16 +++++-
 gi/_glib/Makefile.am                  |   74 +-----------------------------
 gi/_glib/__init__.py                  |    5 --
 gi/_glib/option.py                    |    2 +-
 gi/gimodule.c                         |    9 ++++
 gi/{_glib => }/glibmodule.c           |   34 ++------------
 gi/gobjectmodule.c                    |    5 +-
 gi/overrides/GLib.py                  |    2 +-
 gi/{_glib => }/pyglib-private.h       |   14 ++----
 gi/{_glib => }/pyglib-python-compat.h |    0
 gi/{_glib => }/pyglib.c               |   81 ++-------------------------------
 gi/{_glib => }/pyglib.h               |   10 ----
 gi/{_glib => }/pygoptioncontext.c     |    0
 gi/{_glib => }/pygoptioncontext.h     |    0
 gi/{_glib => }/pygoptiongroup.c       |    0
 gi/{_glib => }/pygoptiongroup.h       |    0
 gi/{_glib => }/pygspawn.c             |    0
 gi/{_glib => }/pygspawn.h             |    0
 18 files changed, 40 insertions(+), 212 deletions(-)
---
diff --git a/gi/Makefile.am b/gi/Makefile.am
index e4b1819..354f407 100644
--- a/gi/Makefile.am
+++ b/gi/Makefile.am
@@ -50,6 +50,18 @@ _gi_la_SOURCES = \
        pygpointer.h \
        pygtype.c \
        pygtype.h \
+       glibmodule.c \
+       pygoptioncontext.c \
+       pygoptioncontext.h \
+       pygoptiongroup.c \
+       pygoptiongroup.h \
+       pygspawn.c \
+       pygspawn.h \
+       pyglib.c \
+       pyglib.h \
+       pyglib-private.h \
+       pyglib-python-compat.h \
+       gimodule.c \
        pygi-repository.c \
        pygi-repository.h \
        pygi-info.c \
@@ -77,7 +89,6 @@ _gi_la_SOURCES = \
        pygi-signal-closure.c \
        pygi-signal-closure.h \
        pygobject-external.h \
-       gimodule.c \
        pygi-invoke.c \
        pygi-invoke.h \
        pygi-invoke-state-struct.h \
@@ -100,8 +111,7 @@ _gi_la_CPPFLAGS = \
 _gi_la_LIBADD = \
        $(extension_libadd) \
        $(GLIB_LIBS) \
-       $(GI_LIBS) \
-       $(top_builddir)/gi/_glib/libpyglib-gi-2 0- PYTHON_BASENAME@.la
+       $(GI_LIBS)
 _gi_la_LDFLAGS = \
        $(extension_ldflags) \
        -export-symbols-regex "init_gi|PyInit__gi"
diff --git a/gi/_glib/Makefile.am b/gi/_glib/Makefile.am
index 774b7e1..423dda4 100644
--- a/gi/_glib/Makefile.am
+++ b/gi/_glib/Makefile.am
@@ -1,25 +1,5 @@
 AUTOMAKE_OPTIONS = 1.7
 
-extension_cppflags = \
-       $(PYTHON_INCLUDES) \
-       -DPY_SSIZE_T_CLEAN
-
-extension_ldflags = \
-       -module \
-       -avoid-version \
-       -shrext $(PYTHON_SO)
-
-if OS_WIN32
-# Windows requires Python modules to be explicitly linked to libpython.
-# Extension modules are shared libaries (.dll), but need to be
-# called .pyd for Python to load it as an extension module.
-extension_libadd = \
-       $(PYTHON_LIBS)
-
-extension_ldflags += \
-       -no-undefined
-endif
-
 
 pyglibdir = $(pyexecdir)/gi/_glib
 
@@ -27,52 +7,6 @@ pyglib_PYTHON = \
        __init__.py \
        option.py
 
-lib_LTLIBRARIES = libpyglib-gi-2 0- PYTHON_BASENAME@.la
-
-libpyglib_gi_2_0_ PYTHON_BASENAME@_la_SOURCES = \
-       pyglib.c \
-       pyglib.h \
-       pyglib-private.h \
-       pyglib-python-compat.h
-libpyglib_gi_2_0_ PYTHON_BASENAME@_la_CPPFLAGS = \
-       $(extension_cppflags)
-libpyglib_gi_2_0_ PYTHON_BASENAME@_la_CFLAGS = \
-       $(GLIB_CFLAGS)
-libpyglib_gi_2_0_ PYTHON_BASENAME@_la_LIBADD = \
-       $(extension_libadd) \
-       $(FFI_LIBS) \
-       $(GLIB_LIBS)
-
-if OS_WIN32
-libpyglib_gi_2_0_ PYTHON_BASENAME@_la_LDFLAGS = \
-       -no-undefined
-endif
-
-pyglib_LTLIBRARIES = _glib.la
-
-_glib_la_SOURCES = \
-       glibmodule.c \
-       pygoptioncontext.c \
-       pygoptioncontext.h \
-       pygoptiongroup.c \
-       pygoptiongroup.h \
-       pygspawn.c \
-       pygspawn.h
-_glib_la_CFLAGS = \
-       $(GLIB_CFLAGS)
-_glib_la_CPPFLAGS = \
-       $(extension_cppflags)
-_glib_la_LIBADD = \
-       $(extension_libadd) \
-       $(GLIB_LIBS) \
-       libpyglib-gi-2 0- PYTHON_BASENAME@.la
-_glib_la_LDFLAGS = \
-       $(extension_ldflags) \
-       -export-symbols-regex "_glib|PyInit__glib"
-
-if PLATFORM_WIN32
-_glib_la_CFLAGS += -DPLATFORM_WIN32
-endif
 
 # if we build in a separate tree, we need to symlink the *.py files from the
 # source tree; Python does not accept the extensions and modules in different
@@ -83,9 +17,5 @@ build_pylinks:
        done
 
 
-all: $(pyglib_LTLIBRARIES:.la=$(PYTHON_SO)) build_pylinks
-check-local: $(pyglib_LTLIBRARIES:.la=$(PYTHON_SO)) build_pylinks
-clean-local:
-       rm -f $(pyglib_LTLIBRARIES:.la=$(PYTHON_SO))
-%$(PYTHON_SO): %.la
-       $(LN_S) -f .libs/$@ $@
+all: build_pylinks
+check-local: build_pylinks
diff --git a/gi/_glib/__init__.py b/gi/_glib/__init__.py
index 0b9df9a..0ea3f79 100644
--- a/gi/_glib/__init__.py
+++ b/gi/_glib/__init__.py
@@ -18,8 +18,3 @@
 # License along with this library; if not, write to the Free Software
 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
 # USA
-
-from . import _glib
-
-# Internal API
-_PyGLib_API = _glib._PyGLib_API
diff --git a/gi/_glib/option.py b/gi/_glib/option.py
index 54e802f..b4d3050 100644
--- a/gi/_glib/option.py
+++ b/gi/_glib/option.py
@@ -42,7 +42,7 @@ else:
     _basestring = basestring
     _bytes = str
 
-from gi._glib import _glib
+from gi._gi import _glib
 GLib = get_introspection_module('GLib')
 
 OPTION_CONTEXT_ERROR_QUARK = GLib.quark_to_string(GLib.option_error_quark())
diff --git a/gi/gimodule.c b/gi/gimodule.c
index 0ca6d40..e0d9878 100644
--- a/gi/gimodule.c
+++ b/gi/gimodule.c
@@ -21,6 +21,7 @@
  * USA
  */
 
+#include "pyglib-private.h"
 #include "pygobject-private.h"
 #include "pyginterface.h"
 #include "pygi-private.h"
@@ -628,6 +629,7 @@ static struct PyGI_API CAPI = {
 PYGLIB_MODULE_START(_gi, "_gi")
 {
     PyObject *api;
+    PyObject *_glib_module;
     PyObject *_gobject_module;
 
     /* Always enable Python threads since we cannot predict which GI repositories
@@ -637,6 +639,13 @@ PYGLIB_MODULE_START(_gi, "_gi")
      */
     PyEval_InitThreads ();
 
+    _glib_module = pyglib__glib_module_create ();
+    if (_glib_module == NULL) {
+        return PYGLIB_MODULE_ERROR_RETURN;
+    }
+    PyModule_AddObject (module, "_glib", _glib_module);
+    PyModule_AddStringConstant(module, "__package__", "gi._gi");
+
     _gobject_module = pyglib__gobject_module_create ();
     if (_gobject_module == NULL) {
         return PYGLIB_MODULE_ERROR_RETURN;
diff --git a/gi/_glib/glibmodule.c b/gi/glibmodule.c
similarity index 74%
rename from gi/_glib/glibmodule.c
rename to gi/glibmodule.c
index d08d4fb..c11f08b 100644
--- a/gi/_glib/glibmodule.c
+++ b/gi/glibmodule.c
@@ -33,6 +33,8 @@
 #include "pygoptiongroup.h"
 #include "pygspawn.h"
 
+PyObject *PyGError = NULL;
+
 /* ---------------- glib module functions -------------------- */
 
 static PyMethodDef _glib_functions[] = {
@@ -47,54 +49,26 @@ static PyMethodDef _glib_functions[] = {
     { NULL, NULL, 0 }
 };
 
-/* ----------------- glib module initialisation -------------- */
-
-static struct _PyGLib_Functions pyglib_api = {
-    FALSE, /* threads_enabled */
-    NULL,  /* gerror_exception */
-    NULL,  /* block_threads */
-    NULL,  /* unblock_threads */
-    NULL,  /* pyg_main_context_new */
-    pyg_option_context_new,
-    pyg_option_group_new,
-};
-
-static void
-pyglib_register_api(PyObject *d)
-{
-    PyObject *o;
-
-    /* for addon libraries ... */
-    PyDict_SetItemString(d, "_PyGLib_API",
-                        o=PYGLIB_CPointer_WrapPointer(&pyglib_api,"gi._glib._PyGLib_API"));
-    Py_DECREF(o);
-    
-    pyglib_init_internal(o);
-}
-
 static void
 pyglib_register_error(PyObject *d)
 {
     PyObject *dict;
-    PyObject *gerror_class;
     dict = PyDict_New();
     /* This is a hack to work around the deprecation warning of
      * BaseException.message in Python 2.6+.
      * GError has also an "message" attribute.
      */
     PyDict_SetItemString(dict, "message", Py_None);
-    gerror_class = PyErr_NewException("gi._glib.GError", PyExc_RuntimeError, dict);
+    PyGError = PyErr_NewException("gi._glib.GError", PyExc_RuntimeError, dict);
     Py_DECREF(dict);
 
-    PyDict_SetItemString(d, "GError", gerror_class);
-    pyglib_api.gerror_exception = gerror_class;
+    PyDict_SetItemString(d, "GError", PyGError);
 }
 
 PYGLIB_MODULE_START(_glib, "_glib")
 {
     PyObject *d = PyModule_GetDict(module);
 
-    pyglib_register_api(d);
     pyglib_register_error(d);
     pyglib_spawn_register_types(d);
     pyglib_option_context_register_types(d);
diff --git a/gi/gobjectmodule.c b/gi/gobjectmodule.c
index e982107..4c614f7 100644
--- a/gi/gobjectmodule.c
+++ b/gi/gobjectmodule.c
@@ -36,6 +36,7 @@
 #include "pygparamspec.h"
 #include "pygpointer.h"
 #include "pygtype.h"
+#include "pygoptiongroup.h"
 
 static GHashTable *log_handlers = NULL;
 static gboolean log_handlers_disabled = FALSE;
@@ -2099,7 +2100,7 @@ struct _PyGObject_Functions pygobject_api_functions = {
 
   pyg_gerror_exception_check,
 
-  pyglib_option_group_new,
+  pyg_option_group_new,
   pyg_type_from_object_strict,
 
   pygobject_new_full,
@@ -2193,8 +2194,6 @@ PYGLIB_MODULE_START(_gobject, "_gobject")
 {
     PyObject *d;
 
-    pyglib_init();
-
     d = PyModule_GetDict(module);
     pygobject_register_api(d);
     pygobject_register_constants(module);
diff --git a/gi/overrides/GLib.py b/gi/overrides/GLib.py
index df5654a..73a2567 100644
--- a/gi/overrides/GLib.py
+++ b/gi/overrides/GLib.py
@@ -39,7 +39,7 @@ __all__.append('option')
 
 
 # Types and functions still needed from static bindings
-from gi._glib import _glib
+from gi._gi import _glib
 GError = _glib.GError
 OptionContext = _glib.OptionContext
 OptionGroup = _glib.OptionGroup
diff --git a/gi/_glib/pyglib-private.h b/gi/pyglib-private.h
similarity index 77%
rename from gi/_glib/pyglib-private.h
rename to gi/pyglib-private.h
index 183184f..9f05816 100644
--- a/gi/_glib/pyglib-private.h
+++ b/gi/pyglib-private.h
@@ -25,23 +25,17 @@
 #include <Python.h>
 #include <glib.h>
 
+#include <pyglib.h>
 #include <pyglib-python-compat.h>
 
 G_BEGIN_DECLS
 
-struct _PyGLib_Functions {
-    gboolean threads_enabled;
-    PyObject *gerror_exception;
-    PyGLibThreadBlockFunc block_threads;
-    PyGLibThreadBlockFunc unblock_threads;
-    PyObject* (*main_context_new)(GMainContext *context);
-    PyObject* (*option_context_new)(GOptionContext *context);
-    PyObject* (*option_group_new)(GOptionGroup *group);
-};
-
 gboolean _pyglib_handler_marshal(gpointer user_data);
 void _pyglib_destroy_notify(gpointer user_data);
 
+extern PyObject *PyGError;
+extern PyObject *pyglib__glib_module_create (void);
+
 G_END_DECLS
 
 #endif /* __PYGLIB_PRIVATE_H__ */
diff --git a/gi/_glib/pyglib-python-compat.h b/gi/pyglib-python-compat.h
similarity index 100%
rename from gi/_glib/pyglib-python-compat.h
rename to gi/pyglib-python-compat.h
diff --git a/gi/_glib/pyglib.c b/gi/pyglib.c
similarity index 82%
rename from gi/_glib/pyglib.c
rename to gi/pyglib.c
index 9753a52..15109fd 100644
--- a/gi/_glib/pyglib.c
+++ b/gi/pyglib.c
@@ -30,52 +30,8 @@
 #include "pygoptioncontext.h"
 #include "pygoptiongroup.h"
 
-static struct _PyGLib_Functions *_PyGLib_API;
 static PyObject *exception_table = NULL;
 
-void
-pyglib_init(void)
-{
-    PyObject *glib, *cobject;
-    
-    glib = PyImport_ImportModule("gi._glib");
-    if (!glib) {
-       if (PyErr_Occurred()) {
-           PyObject *type, *value, *traceback;
-           PyObject *py_orig_exc;
-           PyErr_Fetch(&type, &value, &traceback);
-           py_orig_exc = PyObject_Repr(value);
-           Py_XDECREF(type);
-           Py_XDECREF(value);
-           Py_XDECREF(traceback);
-           PyErr_Format(PyExc_ImportError,
-                        "could not import gi._glib (error was: %s)",
-                        PYGLIB_PyUnicode_AsString(py_orig_exc));
-           Py_DECREF(py_orig_exc);
-        } else {
-           PyErr_SetString(PyExc_ImportError,
-                           "could not import gi._glib (no error given)");
-       }
-       return;
-    }
-    
-    cobject = PyObject_GetAttrString(glib, "_PyGLib_API");
-    if (cobject && PYGLIB_CPointer_Check(cobject))
-       _PyGLib_API = (struct _PyGLib_Functions *) PYGLIB_CPointer_GetPointer(cobject, 
"gi._glib._PyGLib_API");
-    else {
-       PyErr_SetString(PyExc_ImportError,
-                       "could not import gi._glib (could not find _PyGLib_API object)");
-       Py_DECREF(glib);
-       return;
-    }
-}
-
-void
-pyglib_init_internal(PyObject *api)
-{
-    _PyGLib_API = (struct _PyGLib_Functions *) PYGLIB_CPointer_GetPointer(api, "gi._glib._PyGLib_API");
-}
-
 /**
  * pyglib_error_marshal:
  * @error: a pointer to the GError.
@@ -100,7 +56,7 @@ pyglib_error_marshal (GError **error)
 
     state = pyglib_gil_state_ensure();
 
-    exc_type = _PyGLib_API->gerror_exception;
+    exc_type = PyGError;
     if (exception_table != NULL)
     {
        PyObject *item;
@@ -159,7 +115,7 @@ pyglib_error_check(GError **error)
     state = pyglib_gil_state_ensure();
 
     exc_instance = pyglib_error_marshal (error);
-    PyErr_SetObject(_PyGLib_API->gerror_exception, exc_instance);
+    PyErr_SetObject(PyGError, exc_instance);
     Py_DECREF(exc_instance);
     g_clear_error(error);
     
@@ -197,7 +153,7 @@ pyglib_gerror_exception_check(GError **error)
     }
     if (!value ||
        !PyErr_GivenExceptionMatches(type,
-                                    (PyObject *) _PyGLib_API->gerror_exception)) {
+                                    (PyObject *) PyGError)) {
         PyErr_Restore(type, value, traceback);
         PyErr_Print();
         return -2;
@@ -262,7 +218,7 @@ pyglib_register_exception_for_domain(gchar *name,
 {
     PyObject *exception;
 
-    exception = PyErr_NewException(name, _PyGLib_API->gerror_exception, NULL);
+    exception = PyErr_NewException(name, PyGError, NULL);
 
     if (exception_table == NULL)
        exception_table = PyDict_New();
@@ -309,33 +265,6 @@ pyglib_option_group_transfer_group(PyObject *obj)
     return self->group;
 }
 
-/**
- * pyglib_option_group_new:
- * @group: a GOptionGroup
- *
- * The returned GOptionGroup can't be used to set any hooks, translation domains
- * or add entries. It's only intend is, to use for GOptionContext.add_group().
- *
- * Returns: the GOptionGroup wrapper.
- */
-PyObject * 
-pyglib_option_group_new (GOptionGroup *group)
-{
-    return _PyGLib_API->option_group_new(group);
-}
-
-/**
- * pyglib_option_context_new:
- * @context: a GOptionContext
- *
- * Returns: A new GOptionContext wrapper.
- */
-PyObject * 
-pyglib_option_context_new (GOptionContext *context)
-{
-    return _PyGLib_API->option_context_new(context);
-}
-
 
 /****** Private *****/
 
@@ -352,8 +281,6 @@ _pyglib_destroy_notify(gpointer user_data)
     PyObject *obj = (PyObject *)user_data;
     PyGILState_STATE state;
 
-    g_return_if_fail (_PyGLib_API != NULL);
-
     state = pyglib_gil_state_ensure();
     Py_DECREF(obj);
     pyglib_gil_state_release(state);
diff --git a/gi/_glib/pyglib.h b/gi/pyglib.h
similarity index 87%
rename from gi/_glib/pyglib.h
rename to gi/pyglib.h
index 1c62f1d..9c7b22b 100644
--- a/gi/_glib/pyglib.h
+++ b/gi/pyglib.h
@@ -31,9 +31,6 @@ G_BEGIN_DECLS
 typedef void (*PyGLibThreadsEnabledFunc) (void);
 typedef void (*PyGLibThreadBlockFunc) (void);
 
-void pyglib_init(void);
-void pyglib_init_internal(PyObject *api);
-
 #ifdef DISABLE_THREADING
 #    define pyglib_gil_state_ensure()        PyGILState_LOCKED
 #    define pyglib_gil_state_release(state)  state
@@ -42,18 +39,11 @@ void pyglib_init_internal(PyObject *api);
 #    define pyglib_gil_state_release         PyGILState_Release
 #endif
 
-/* Deprecated, only available for API compatibility. */
-#define pyg_set_thread_block_funcs(a, b)
-#define pyglib_block_threads()
-#define pyglib_unblock_threads()
-
 gboolean pyglib_error_check(GError **error);
 PyObject *pyglib_error_marshal (GError **error);
 gboolean pyglib_gerror_exception_check(GError **error);
 PyObject *pyglib_register_exception_for_domain(gchar *name,
                                               gint error_domain);
-PyObject * pyglib_option_context_new(GOptionContext *context);
-PyObject * pyglib_option_group_new(GOptionGroup *group);
 GOptionGroup * pyglib_option_group_transfer_group(PyObject *self);
 
 /* Private: for gobject <-> glib interaction only. */
diff --git a/gi/_glib/pygoptioncontext.c b/gi/pygoptioncontext.c
similarity index 100%
rename from gi/_glib/pygoptioncontext.c
rename to gi/pygoptioncontext.c
diff --git a/gi/_glib/pygoptioncontext.h b/gi/pygoptioncontext.h
similarity index 100%
rename from gi/_glib/pygoptioncontext.h
rename to gi/pygoptioncontext.h
diff --git a/gi/_glib/pygoptiongroup.c b/gi/pygoptiongroup.c
similarity index 100%
rename from gi/_glib/pygoptiongroup.c
rename to gi/pygoptiongroup.c
diff --git a/gi/_glib/pygoptiongroup.h b/gi/pygoptiongroup.h
similarity index 100%
rename from gi/_glib/pygoptiongroup.h
rename to gi/pygoptiongroup.h
diff --git a/gi/_glib/pygspawn.c b/gi/pygspawn.c
similarity index 100%
rename from gi/_glib/pygspawn.c
rename to gi/pygspawn.c
diff --git a/gi/_glib/pygspawn.h b/gi/pygspawn.h
similarity index 100%
rename from gi/_glib/pygspawn.h
rename to gi/pygspawn.h


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