summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--gobject/gobjectmodule.c13
-rw-r--r--gobject/pygmaincontext.c26
-rw-r--r--gobject/pygmainloop.c12
-rw-r--r--gobject/pygobject-private.h1
-rw-r--r--gobject/pygsource.c9
5 files changed, 29 insertions, 32 deletions
diff --git a/gobject/gobjectmodule.c b/gobject/gobjectmodule.c
index 0aa7dbd..3eff89c 100644
--- a/gobject/gobjectmodule.c
+++ b/gobject/gobjectmodule.c
@@ -1892,18 +1892,9 @@ pyg_source_remove(PyObject *self, PyObject *args)
}
static PyObject *
-pyg_main_context_default (PyObject *unused)
+pyg_main_context_default(PyObject *unused)
{
- PyGMainContext *self;
-
- self = (PyGMainContext *)PyObject_NEW(PyGMainContext,
- &PyGMainContext_Type);
- if (self == NULL)
- return NULL;
-
- self->context = g_main_context_default();
- return (PyObject *)self;
-
+ return pyg_main_context_new(g_main_context_default());
}
static int pyg_thread_state_tls_key = -1;
diff --git a/gobject/pygmaincontext.c b/gobject/pygmaincontext.c
index 7286a86..b320eea 100644
--- a/gobject/pygmaincontext.c
+++ b/gobject/pygmaincontext.c
@@ -27,7 +27,7 @@
#include "pygobject-private.h"
static int
-pyg_main_context_new(PyGMainContext *self)
+pyg_main_context_init(PyGMainContext *self)
{
self->context = g_main_context_new();
return 0;
@@ -118,5 +118,27 @@ PyTypeObject PyGMainContext_Type = {
(descrgetfunc)0,
(descrsetfunc)0,
0,
- (initproc)pyg_main_context_new,
+ (initproc)pyg_main_context_init,
};
+
+/**
+ * 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;
+}
diff --git a/gobject/pygmainloop.c b/gobject/pygmainloop.c
index 90357f2..5453240 100644
--- a/gobject/pygmainloop.c
+++ b/gobject/pygmainloop.c
@@ -228,17 +228,7 @@ pyg_main_loop_compare(PyGMainLoop *self, PyGMainLoop *v)
static PyObject *
_wrap_g_main_loop_get_context (PyGMainLoop *loop)
{
- PyGMainContext *self;
-
- self = (PyGMainContext *)PyObject_NEW(PyGMainContext,
- &PyGMainContext_Type);
-
- self->context = g_main_loop_get_context(loop->loop);
-
- if (self->context == NULL)
- return NULL;
-
- return (PyObject *)self;
+ return pyg_main_context_new(g_main_loop_get_context(loop->loop));
}
static PyObject *
diff --git a/gobject/pygobject-private.h b/gobject/pygobject-private.h
index c09903e..1055011 100644
--- a/gobject/pygobject-private.h
+++ b/gobject/pygobject-private.h
@@ -189,6 +189,7 @@ typedef struct {
} PyGMainContext;
extern PyTypeObject PyGMainContext_Type;
+PyObject * pyg_main_context_new (GMainContext *context);
/* pygparamspec */
diff --git a/gobject/pygsource.c b/gobject/pygsource.c
index 08ca458..900bd4f 100644
--- a/gobject/pygsource.c
+++ b/gobject/pygsource.c
@@ -167,7 +167,6 @@ pyg_source_set_callback(PyGSource *self, PyObject *args)
static PyObject *
pyg_source_get_context(PyGSource *self)
{
- PyGMainContext *py_context;
GMainContext *context;
CHECK_DESTROYED(self, NULL);
@@ -175,13 +174,7 @@ pyg_source_get_context(PyGSource *self)
context = g_source_get_context(self->source);
if (context) {
- py_context = PyObject_NEW(PyGMainContext, &PyGMainContext_Type);
- if (py_context == NULL)
- return NULL;
-
- py_context->context = context;
-
- return (PyObject *)py_context;
+ return pyg_main_context_new(context);
} else {
Py_INCREF(Py_None);
return Py_None;