[pygobject] Move pyglib_{main_context, option_context, option_group}_new into _PyGLib_API
- From: Simon van der Linden <svdlinden src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [pygobject] Move pyglib_{main_context, option_context, option_group}_new into _PyGLib_API
- Date: Mon, 17 Jan 2011 14:09:11 +0000 (UTC)
commit 8ceef79c98a1c2e22ed8ab655ef1169f1763dd23
Author: Simon van der Linden <svdlinden gnome org>
Date: Fri Dec 31 18:38:04 2010 +0100
Move pyglib_{main_context, option_context, option_group}_new into _PyGLib_API
_PyG{MainContext, OptionContext, and OptionGroup_Type} were not be initialized
when used inside the glib module, since pyglib_init is not called.
pyglib.c is compiled as a stand-alone library loaded by the _glib module that
declares the above-mentioned types. Hence, they cannot be accessed by the
former. This patch moves the functions that need those symbols into the
glib._glib module and exports them to the pyglib library through _PyGLib_API.
https://bugzilla.gnome.org/show_bug.cgi?id=636656
glib/glibmodule.c | 5 +++-
glib/pyglib-private.h | 3 ++
glib/pyglib.c | 48 ++--------------------------------------------
glib/pygmaincontext.c | 22 +++++++++++++++++++++
glib/pygmaincontext.h | 2 +-
glib/pygmainloop.c | 2 +-
glib/pygoptioncontext.c | 21 ++++++++++++++++++++
glib/pygoptioncontext.h | 2 +
glib/pygoptiongroup.c | 26 +++++++++++++++++++++++++
glib/pygoptiongroup.h | 2 +
glib/pygsource.c | 2 +-
11 files changed, 86 insertions(+), 49 deletions(-)
---
diff --git a/glib/glibmodule.c b/glib/glibmodule.c
index 29a4713..963e5ea 100644
--- a/glib/glibmodule.c
+++ b/glib/glibmodule.c
@@ -787,7 +787,10 @@ static struct _PyGLib_Functions pyglib_api = {
FALSE, /* threads_enabled */
NULL, /* gerror_exception */
NULL, /* block_threads */
- NULL /* unblock_threads */
+ NULL, /* unblock_threads */
+ pyg_main_context_new,
+ pyg_option_context_new,
+ pyg_option_group_new,
};
static void
diff --git a/glib/pyglib-private.h b/glib/pyglib-private.h
index 8b033e1..183184f 100644
--- a/glib/pyglib-private.h
+++ b/glib/pyglib-private.h
@@ -34,6 +34,9 @@ struct _PyGLib_Functions {
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);
diff --git a/glib/pyglib.c b/glib/pyglib.c
index 03f9e91..8163e88 100644
--- a/glib/pyglib.c
+++ b/glib/pyglib.c
@@ -35,15 +35,6 @@ static struct _PyGLib_Functions *_PyGLib_API;
static int pyglib_thread_state_tls_key;
static PyObject *exception_table = NULL;
-static PyTypeObject *_PyGMainContext_Type;
-#define PyGMainContext_Type (*_PyGMainContext_Type)
-
-static PyTypeObject *_PyGOptionGroup_Type;
-#define PyGOptionGroup_Type (*_PyGOptionGroup_Type)
-
-static PyTypeObject *_PyGOptionContext_Type;
-#define PyGOptionContext_Type (*_PyGOptionContext_Type)
-
void
pyglib_init(void)
{
@@ -79,10 +70,6 @@ pyglib_init(void)
Py_DECREF(glib);
return;
}
-
- _PyGMainContext_Type = (PyTypeObject*)PyObject_GetAttrString(glib, "MainContext");
- _PyGOptionGroup_Type = (PyTypeObject*)PyObject_GetAttrString(glib, "OptionGroup");
- _PyGOptionContext_Type = (PyTypeObject*)PyObject_GetAttrString(glib, "OptionContext");
}
void
@@ -414,15 +401,7 @@ pyglib_register_exception_for_domain(gchar *name,
PyObject *
pyglib_main_context_new(GMainContext *context)
{
- PyGMainContext *self;
-
- self = (PyGMainContext *)PyObject_NEW(PyGMainContext,
- &PyGMainContext_Type);
- if (self == NULL)
- return NULL;
-
- self->context = g_main_context_ref(context);
- return (PyObject *)self;
+ return _PyGLib_API->main_context_new(context);
}
/**
@@ -472,18 +451,7 @@ pyglib_option_group_transfer_group(PyObject *obj)
PyObject *
pyglib_option_group_new (GOptionGroup *group)
{
- PyGOptionGroup *self;
-
- self = (PyGOptionGroup *)PyObject_NEW(PyGOptionGroup,
- &PyGOptionGroup_Type);
- if (self == NULL)
- return NULL;
-
- self->group = group;
- self->other_owner = TRUE;
- self->is_in_context = FALSE;
-
- return (PyObject *)self;
+ return _PyGLib_API->option_group_new(group);
}
/**
@@ -495,17 +463,7 @@ pyglib_option_group_new (GOptionGroup *group)
PyObject *
pyglib_option_context_new (GOptionContext *context)
{
- PyGOptionContext *self;
-
- self = (PyGOptionContext *)PyObject_NEW(PyGOptionContext,
- &PyGOptionContext_Type);
- if (self == NULL)
- return NULL;
-
- self->context = context;
- self->main_group = NULL;
-
- return (PyObject *)self;
+ return _PyGLib_API->option_context_new(context);
}
/**
diff --git a/glib/pygmaincontext.c b/glib/pygmaincontext.c
index 43ca84e..cfb7ddd 100644
--- a/glib/pygmaincontext.c
+++ b/glib/pygmaincontext.c
@@ -33,6 +33,28 @@
PYGLIB_DEFINE_TYPE("glib.MainContext", PyGMainContext_Type, PyGMainContext)
+/**
+ * pyg_main_context_new:
+ * @context: a GMainContext.
+ *
+ * Creates a wrapper for a GMainContext.
+ *
+ * Returns: the GMainContext wrapper.
+ */
+PyObject *
+pyg_main_context_new(GMainContext *context)
+{
+ PyGMainContext *self;
+
+ self = (PyGMainContext *)PyObject_NEW(PyGMainContext, &PyGMainContext_Type);
+ if (self == NULL)
+ return NULL;
+
+ self->context = g_main_context_ref(context);
+
+ return (PyObject *)self;
+}
+
static int
pyg_main_context_init(PyGMainContext *self)
{
diff --git a/glib/pygmaincontext.h b/glib/pygmaincontext.h
index 038cb37..4ffa3c9 100644
--- a/glib/pygmaincontext.h
+++ b/glib/pygmaincontext.h
@@ -32,7 +32,7 @@ typedef struct {
extern PyTypeObject PyGMainContext_Type;
-PyObject * pyglib_main_context_new(GMainContext *context);
+PyObject* pyg_main_context_new(GMainContext *context);
void pyglib_maincontext_register_types(PyObject *d);
diff --git a/glib/pygmainloop.c b/glib/pygmainloop.c
index cdb94ae..219b6a3 100644
--- a/glib/pygmainloop.c
+++ b/glib/pygmainloop.c
@@ -302,7 +302,7 @@ pyg_main_loop_richcompare(PyObject *self, PyObject *other, int op)
static PyObject *
_wrap_g_main_loop_get_context (PyGMainLoop *loop)
{
- return pyglib_main_context_new(g_main_loop_get_context(loop->loop));
+ return pyg_main_context_new(g_main_loop_get_context(loop->loop));
}
static PyObject *
diff --git a/glib/pygoptioncontext.c b/glib/pygoptioncontext.c
index 93d9b24..444625c 100644
--- a/glib/pygoptioncontext.c
+++ b/glib/pygoptioncontext.c
@@ -30,6 +30,27 @@
PYGLIB_DEFINE_TYPE("glib.OptionContext", PyGOptionContext_Type, PyGOptionContext)
+/**
+ * pyg_option_context_new:
+ * @context: a GOptionContext
+ *
+ * Returns: A new GOptionContext wrapper.
+ */
+PyObject *
+pyg_option_context_new (GOptionContext *context)
+{
+ PyGOptionContext *self;
+
+ self = (PyGOptionContext *)PyObject_NEW(PyGOptionContext, &PyGOptionContext_Type);
+ if (self == NULL)
+ return NULL;
+
+ self->context = context;
+ self->main_group = NULL;
+
+ return (PyObject *)self;
+}
+
static int
pyg_option_context_init(PyGOptionContext *self,
PyObject *args,
diff --git a/glib/pygoptioncontext.h b/glib/pygoptioncontext.h
index 85d0a47..efe5ffa 100644
--- a/glib/pygoptioncontext.h
+++ b/glib/pygoptioncontext.h
@@ -32,6 +32,8 @@ typedef struct {
GOptionContext *context;
} PyGOptionContext;
+PyObject* pyg_option_context_new(GOptionContext *context);
+
void pyglib_option_context_register_types(PyObject *d);
#endif /* __PYG_OPTIONCONTEXT_H__ */
diff --git a/glib/pygoptiongroup.c b/glib/pygoptiongroup.c
index 9345869..2a69354 100644
--- a/glib/pygoptiongroup.c
+++ b/glib/pygoptiongroup.c
@@ -30,6 +30,32 @@
PYGLIB_DEFINE_TYPE("glib.OptionGroup", PyGOptionGroup_Type, PyGOptionGroup)
+/**
+ * pyg_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 *
+pyg_option_group_new (GOptionGroup *group)
+{
+ PyGOptionGroup *self;
+
+ self = (PyGOptionGroup *)PyObject_NEW(PyGOptionGroup,
+ &PyGOptionGroup_Type);
+ if (self == NULL)
+ return NULL;
+
+ self->group = group;
+ self->other_owner = TRUE;
+ self->is_in_context = FALSE;
+
+ return (PyObject *)self;
+}
+
static gboolean
check_if_owned(PyGOptionGroup *self)
{
diff --git a/glib/pygoptiongroup.h b/glib/pygoptiongroup.h
index cba6a79..872b9c6 100644
--- a/glib/pygoptiongroup.h
+++ b/glib/pygoptiongroup.h
@@ -33,6 +33,8 @@ typedef struct {
GOptionGroup.destroy() */
} PyGOptionGroup;
+PyObject* pyg_option_group_new(GOptionGroup *group);
+
void pyglib_option_group_register_types(PyObject *d);
#endif /* __PYG_OPTIONGROUP_H__ */
diff --git a/glib/pygsource.c b/glib/pygsource.c
index 3587c38..684711e 100644
--- a/glib/pygsource.c
+++ b/glib/pygsource.c
@@ -182,7 +182,7 @@ pyg_source_get_context(PyGSource *self)
context = g_source_get_context(self->source);
if (context) {
- return pyglib_main_context_new(context);
+ return pyg_main_context_new(context);
} else {
Py_INCREF(Py_None);
return Py_None;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]