pygobject r843 - in trunk: . glib gobject tests



Author: johan
Date: Sun Jul 20 14:17:04 2008
New Revision: 843
URL: http://svn.gnome.org/viewvc/pygobject?rev=843&view=rev

Log:
2008-07-20  Johan Dahlin  <johan gnome org>

	* glib/Makefile.am:
	* glib/glibmodule.c (pyglib_main_context_default), (init_glib):
	* glib/pyglib.c (pyglib_init), (pyglib_threads_enabled),
	(pyglib_main_context_new):
	* glib/pyglib.h:
	* glib/pygmaincontext.c (_wrap_g_main_context_iteration),
	(pyglib_maincontext_register_types):
	* glib/pygmaincontext.h:
	* glib/pygmainloop.c (pyg_signal_watch_prepare),
	(pyg_signal_watch_check), (pyg_main_loop_new),
	(_wrap_g_main_loop_get_context), (_wrap_g_main_loop_run),
	(pyglib_mainloop_register_types):
	* glib/pygmainloop.h:
	* gobject/Makefile.am:
	* gobject/__init__.py:
	* gobject/gobjectmodule.c (pyg_destroy_notify), (pyobject_free),
	(pyg_object_set_property), (pyg_object_get_property),
	(_pyg_signal_accumulator), (pygobject__g_instance_init),
	(pyg_handler_marshal), (pygobject_gil_state_ensure),
	(pygobject_gil_state_release), (marshal_emission_hook),
	(_log_func), (init_gobject):
	* gobject/pygboxed.c (pyg_boxed_dealloc), (pyg_boxed_new):
	* gobject/pygenum.c (pyg_enum_add):
	* gobject/pygflags.c (pyg_flags_add):
	* gobject/pygiochannel.c (pyg_iowatch_marshal):
	* gobject/pygmaincontext.c:
	* gobject/pygmainloop.c:
	* gobject/pygobject-private.h:
	* gobject/pygobject.c (pygobject_data_free), (pyg_toggle_notify),
	(pygobject_new_with_interfaces), (pygobject_weak_ref_notify):
	* gobject/pygobject.h:
	* gobject/pygoptiongroup.c (destroy_g_group), (arg_func):
	* gobject/pygpointer.c (pyg_pointer_new):
	* gobject/pygsource.c (pyg_source_get_context),
	(pyg_source_prepare), (pyg_source_check), (pyg_source_dispatch),
	(pyg_source_finalize):
	* gobject/pygtype.c (pyg_closure_invalidate),
	(pyg_closure_marshal), (pyg_signal_class_closure_marshal):
	* tests/common.py:

	Move maincontext and mainloop over to glib.
	Update the threadstate api to use the variant in glib.


Added:
   trunk/glib/pygmaincontext.c
      - copied, changed from r839, /trunk/gobject/pygmaincontext.c
   trunk/glib/pygmaincontext.h
   trunk/glib/pygmainloop.c
      - copied, changed from r839, /trunk/gobject/pygmainloop.c
   trunk/glib/pygmainloop.h
Removed:
   trunk/gobject/pygmaincontext.c
   trunk/gobject/pygmainloop.c
Modified:
   trunk/ChangeLog
   trunk/glib/Makefile.am
   trunk/glib/glibmodule.c
   trunk/glib/pyglib.c
   trunk/glib/pyglib.h
   trunk/gobject/Makefile.am
   trunk/gobject/__init__.py
   trunk/gobject/gobjectmodule.c
   trunk/gobject/pygboxed.c
   trunk/gobject/pygenum.c
   trunk/gobject/pygflags.c
   trunk/gobject/pygiochannel.c
   trunk/gobject/pygobject-private.h
   trunk/gobject/pygobject.c
   trunk/gobject/pygobject.h
   trunk/gobject/pygoptiongroup.c
   trunk/gobject/pygpointer.c
   trunk/gobject/pygsource.c
   trunk/gobject/pygtype.c
   trunk/tests/common.py

Modified: trunk/glib/Makefile.am
==============================================================================
--- trunk/glib/Makefile.am	(original)
+++ trunk/glib/Makefile.am	Sun Jul 20 14:17:04 2008
@@ -28,10 +28,12 @@
 _glib_la_CFLAGS = $(GLIB_CFLAGS)
 _glib_la_LDFLAGS = $(common_ldflags) -export-symbols-regex init_glib
 _glib_la_LIBADD = $(GLIB_LIBS) libpyglib-2.0.la
-_glib_la_SOURCES = 	\
-	glibmodule.c	\
-	pygspawn.c	\
-	pygspawn.h
+_glib_la_SOURCES = 	 \
+	glibmodule.c	 \
+	pygspawn.c	 \
+	pygspawn.h	 \
+	pygmaincontext.c \
+	pygmainloop.c
 
 if PLATFORM_WIN32
 _glib_la_CFLAGS += -DPLATFORM_WIN32

Modified: trunk/glib/glibmodule.c
==============================================================================
--- trunk/glib/glibmodule.c	(original)
+++ trunk/glib/glibmodule.c	Sun Jul 20 14:17:04 2008
@@ -29,8 +29,10 @@
 #include <glib.h>
 #include "pyglib.h"
 
-#include "pygspawn.h"
 #include "pyglib-private.h"
+#include "pygmaincontext.h"
+#include "pygmainloop.h"
+#include "pygspawn.h"
 
 #define PYGLIB_MAJOR_VERSION PYGOBJECT_MAJOR_VERSION
 #define PYGLIB_MINOR_VERSION PYGOBJECT_MINOR_VERSION
@@ -343,13 +345,11 @@
     return PyBool_FromLong(g_source_remove(tag));
 }
 
-#ifdef FIXME
 static PyObject *
-pyg_main_context_default(PyObject *unused)
+pyglib_main_context_default(PyObject *unused)
 {
-    return pyg_main_context_new(g_main_context_default());
+    return pyglib_main_context_new(g_main_context_default());
 }
-#endif
 
 struct _PyGChildData {
     PyObject *func;
@@ -565,6 +565,8 @@
 static PyMethodDef pyglib_functions[] = {
     { "spawn_async",
       (PyCFunction)pyglib_spawn_async, METH_VARARGS|METH_KEYWORDS },
+    { "main_context_default",
+      (PyCFunction)pyglib_main_context_default, METH_NOARGS },
 
     { "idle_add",
       (PyCFunction)pyg_idle_add, METH_VARARGS|METH_KEYWORDS },
@@ -598,10 +600,8 @@
       (PyCFunction)pyg_set_prgname, METH_VARARGS },
     { "main_depth",
       (PyCFunction)pyg_main_depth, METH_NOARGS },
-#if 0
-    { "main_context_default",
-      (PyCFunction)pyg_main_context_default, METH_NOARGS },
-#endif
+
+
     { NULL, NULL, 0 }
 };
 
@@ -675,4 +675,7 @@
     pyg_register_error(d);
     pyg_register_version_tuples(d);
     pyg_spawn_register_types(d);
+
+    pyglib_mainloop_register_types(d);
+    pyglib_maincontext_register_types(d);
 }

Modified: trunk/glib/pyglib.c
==============================================================================
--- trunk/glib/pyglib.c	(original)
+++ trunk/glib/pyglib.c	Sun Jul 20 14:17:04 2008
@@ -27,10 +27,14 @@
 #include <pythread.h>
 #include "pyglib.h"
 #include "pyglib-private.h"
+#include "pygmaincontext.h"
 
 static struct _PyGLib_Functions *_PyGLib_API;
 static int pyglib_thread_state_tls_key;
 
+static PyTypeObject *_PyGMainContext_Type;
+#define PyGMainContext_Type (*_PyGMainContext_Type)
+
 void
 pyglib_init(void)
 {
@@ -63,6 +67,8 @@
 			"could not import glib (could not find _PyGLib_API object)");
 	Py_DECREF(glib);
     }
+
+    _PyGMainContext_Type = (PyTypeObject*)PyObject_GetAttrString(glib, "MainContext");
 }
 
 void
@@ -71,6 +77,12 @@
     _PyGLib_API = (struct _PyGLib_Functions *) PyCObject_AsVoidPtr(api);
 }
 
+gboolean
+pyglib_threads_enabled(void)
+{
+    return _PyGLib_API->threads_enabled;
+}
+
 PyGILState_STATE
 pyglib_gil_state_ensure(void)
 {
@@ -255,3 +267,25 @@
     PyErr_Print();
     return -2;
 }
+
+/**
+ * pyglib_main_context_new:
+ * @context: a GMainContext.
+ *
+ * Creates a wrapper for a GMainContext.
+ *
+ * Returns: the GMainContext wrapper.
+ */
+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;
+}

Modified: trunk/glib/pyglib.h
==============================================================================
--- trunk/glib/pyglib.h	(original)
+++ trunk/glib/pyglib.h	Sun Jul 20 14:17:04 2008
@@ -35,6 +35,19 @@
 gboolean pyglib_enable_threads(void);
 gboolean pyglib_error_check(GError **error);
 gboolean pyglib_gerror_exception_check(GError **error);
+gboolean pyglib_threads_enabled(void);
+PyObject *pyglib_main_context_new(GMainContext *context);
+
+#define pyglib_begin_allow_threads		\
+    G_STMT_START {                              \
+        PyThreadState *_save = NULL;            \
+        if (pyglib_threads_enabled())		\
+            _save = PyEval_SaveThread();
+
+#define pyglib_end_allow_threads                \
+        if (pyglib_threads_enabled())           \
+            PyEval_RestoreThread(_save);        \
+    } G_STMT_END
 
 G_END_DECLS
 

Copied: trunk/glib/pygmaincontext.c (from r839, /trunk/gobject/pygmaincontext.c)
==============================================================================
--- /trunk/gobject/pygmaincontext.c	(original)
+++ trunk/glib/pygmaincontext.c	Sun Jul 20 14:17:04 2008
@@ -24,7 +24,12 @@
 #  include <config.h>
 #endif
 
-#include "pygobject-private.h"
+#include <Python.h>
+#include <pythread.h>
+#include <glib.h>
+#include "pygmaincontext.h"
+#include "pyglib.h"
+#include "pyglib-private.h"
 
 static int
 pyg_main_context_init(PyGMainContext *self)
@@ -61,9 +66,9 @@
 			  &may_block))
 	return NULL;
 
-    pyg_begin_allow_threads;
+    pyglib_begin_allow_threads;
     ret = g_main_context_iteration(self->context, may_block);
-    pyg_end_allow_threads;
+    pyglib_end_allow_threads;
     
     return PyBool_FromLong(ret);
 }
@@ -83,7 +88,7 @@
 PyTypeObject PyGMainContext_Type = {
     PyObject_HEAD_INIT(NULL)
     0,
-    "gobject.MainContext",
+    "glib.MainContext",
     sizeof(PyGMainContext),
     0,
     /* methods */
@@ -121,24 +126,8 @@
     (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;
+void
+pyglib_maincontext_register_types(PyObject *d)
+{
+    PYGLIB_REGISTER_TYPE(d, PyGMainContext_Type, "MainContext"); 
 }

Added: trunk/glib/pygmaincontext.h
==============================================================================
--- (empty file)
+++ trunk/glib/pygmaincontext.h	Sun Jul 20 14:17:04 2008
@@ -0,0 +1,40 @@
+/* -*- Mode: C; c-basic-offset: 4 -*-
+ * pyglib - Python bindings for GLib toolkit.
+ * Copyright (C) 1998-2003  James Henstridge
+ *               2004-2008  Johan Dahlin
+ *
+ * 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, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
+ * USA
+ */
+
+#ifndef __PYG_MAINCONTEXT_H__
+#define __PYG_MAINCONTEXT_H__
+
+#include <Python.h>
+#include <glib.h>
+
+typedef struct {
+    PyObject_HEAD
+    GMainContext *context;
+} PyGMainContext;
+
+extern PyTypeObject PyGMainContext_Type;
+
+PyObject * pyglib_main_context_new(GMainContext *context);
+
+void pyglib_maincontext_register_types(PyObject *d);
+
+#endif /* __PYG_MAINCONTEXT_H__ */
+

Copied: trunk/glib/pygmainloop.c (from r839, /trunk/gobject/pygmainloop.c)
==============================================================================
--- /trunk/gobject/pygmainloop.c	(original)
+++ trunk/glib/pygmainloop.c	Sun Jul 20 14:17:04 2008
@@ -25,8 +25,21 @@
 #  include <config.h>
 #endif
 
-#include "pygobject-private.h"
-#include "pythread.h"
+#include <Python.h>
+#include <pythread.h>
+#include <glib.h>
+
+#include "pygmainloop.h"
+#include "pygmaincontext.h"
+#include "pyglib.h"
+#include "pyglib-private.h"
+
+
+typedef struct {
+    GSource source;
+    int fds[2];
+    GPollFD fd;
+} PySignalWatchSource;
 
 #ifdef DISABLE_THREADING
 static GMainLoop *pyg_current_main_loop = NULL;;
@@ -102,18 +115,14 @@
 }
 #endif /* DISABLE_THREADING */
 
-typedef struct {
-    GSource source;
-    int fds[2];
-    GPollFD fd;
-} PySignalWatchSource;
-
 static gboolean
 pyg_signal_watch_prepare(GSource *source,
 			 int     *timeout)
 {
+#ifdef HAVE_PYSIGNAL_SETWAKEUPFD
     PySignalWatchSource *real_source = (PySignalWatchSource *)source;
-
+#endif
+    
     /* Python only invokes signal handlers from the main thread,
      * so if a thread other than the main thread receives the signal
      * from the kernel, PyErr_CheckSignals() from that thread will
@@ -125,7 +134,7 @@
      * only one thread.
      */
 #ifndef PLATFORM_WIN32
-    if (!pyg_threads_enabled)
+    if (!pyglib_threads_enabled())
 	return FALSE;
 #endif
 
@@ -166,7 +175,7 @@
     PyGILState_STATE state;
     GMainLoop *main_loop;
 
-    state = pyg_gil_state_ensure();
+    state = pyglib_gil_state_ensure();
 
     main_loop = pyg_get_current_main_loop();
 
@@ -175,7 +184,7 @@
 	g_main_loop_quit(main_loop);
     }
 
-    pyg_gil_state_release(state);
+    pyglib_gil_state_release(state);
 
     return FALSE;
 }
@@ -235,7 +244,7 @@
     if (!PyObject_TypeCheck(py_context, &PyGMainContext_Type) &&
 	py_context != Py_None) {
 	PyErr_SetString(PyExc_TypeError,
-			"context must be a gobject.GMainContext or None");
+			"context must be a glib.GMainContext or None");
 	return -1;
     }
 
@@ -280,7 +289,7 @@
 static PyObject *
 _wrap_g_main_loop_get_context (PyGMainLoop *loop)
 {
-    return pyg_main_context_new(g_main_loop_get_context(loop->loop));
+    return pyglib_main_context_new(g_main_loop_get_context(loop->loop));
 }
 
 static PyObject *
@@ -305,9 +314,9 @@
 
     prev_loop = pyg_save_current_main_loop(self->loop);
 
-    pyg_begin_allow_threads;
+    pyglib_begin_allow_threads;
     g_main_loop_run(self->loop);
-    pyg_end_allow_threads;
+    pyglib_end_allow_threads;
 
     pyg_restore_current_main_loop(prev_loop);
    
@@ -329,7 +338,7 @@
 PyTypeObject PyGMainLoop_Type = {
     PyObject_HEAD_INIT(NULL)
     0,			
-    "gobject.MainLoop",	
+    "glib.MainLoop",	
     sizeof(PyGMainLoop),	
     0,			
     /* methods */
@@ -366,3 +375,9 @@
     0,                 
     (initproc)pyg_main_loop_new,
 };
+
+void
+pyglib_mainloop_register_types(PyObject *d)
+{
+    PYGLIB_REGISTER_TYPE(d, PyGMainLoop_Type, "MainLoop"); 
+}

Added: trunk/glib/pygmainloop.h
==============================================================================
--- (empty file)
+++ trunk/glib/pygmainloop.h	Sun Jul 20 14:17:04 2008
@@ -0,0 +1,36 @@
+/* -*- Mode: C; c-basic-offset: 4 -*-
+ * pyglib - Python bindings for GLib toolkit.
+ * Copyright (C) 1998-2003  James Henstridge
+ *               2004-2008  Johan Dahlin
+ *
+ * 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, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
+ * USA
+ */
+
+#ifndef __PYG_MAINLOOP_H__
+#define __PYG_MAINLOOP_H__
+
+typedef struct {
+    PyObject_HEAD
+    GMainLoop *loop;
+    GSource *signal_source;
+} PyGMainLoop;
+
+extern PyTypeObject PyGMainLoop_Type;
+
+void pyglib_mainloop_register_types(PyObject *d);
+
+#endif /* __PYG_MAINLOOP_H__ */
+

Modified: trunk/gobject/Makefile.am
==============================================================================
--- trunk/gobject/Makefile.am	(original)
+++ trunk/gobject/Makefile.am	Sun Jul 20 14:17:04 2008
@@ -51,8 +51,6 @@
 	pygobject.c \
 	pygobject.h \
 	pygobject-private.h \
-	pygmaincontext.c \
-	pygmainloop.c \
 	pygparamspec.c \
 	pygpointer.c \
 	pygiochannel.c \

Modified: trunk/gobject/__init__.py
==============================================================================
--- trunk/gobject/__init__.py	(original)
+++ trunk/gobject/__init__.py	Sun Jul 20 14:17:04 2008
@@ -31,7 +31,8 @@
      io_add_watch, source_remove, child_watch_add, markup_escape_text, \
      get_current_time, filename_display_name, filename_display_basename, \
      filename_from_utf8, get_application_name, set_application_name, \
-     get_prgname, set_prgname, main_depth, Pid, GError, glib_version
+     get_prgname, set_prgname, main_depth, Pid, GError, glib_version, \
+     MainLoop, MainContext, main_context_default
 from gobject.constants import *
 from _gobject import *
 _PyGObject_API = _gobject._PyGObject_API

Modified: trunk/gobject/gobjectmodule.c
==============================================================================
--- trunk/gobject/gobjectmodule.c	(original)
+++ trunk/gobject/gobjectmodule.c	Sun Jul 20 14:17:04 2008
@@ -100,9 +100,9 @@
     PyObject *obj = (PyObject *)user_data;
     PyGILState_STATE state;
 
-    state = pyg_gil_state_ensure();
+    state = pyglib_gil_state_ensure();
     Py_DECREF(obj);
-    pyg_gil_state_release(state);
+    pyglib_gil_state_release(state);
 }
 
 
@@ -125,9 +125,9 @@
     PyObject *object = boxed;
     PyGILState_STATE state;
 
-    state = pyg_gil_state_ensure();
+    state = pyglib_gil_state_ensure();
     Py_DECREF(object);
-    pyg_gil_state_release(state);
+    pyglib_gil_state_release(state);
 }
 
 
@@ -241,9 +241,6 @@
     return g_type_get_qdata(gtype, pyginterface_info_key);
 }
 
-/* -------------- GMainContext objects ---------------------------- */
-
-
 /* ---------------- gobject module functions -------------------- */
 
 static PyObject *
@@ -405,12 +402,12 @@
     PyObject *py_pspec, *py_value;
     PyGILState_STATE state;
 
-    state = pyg_gil_state_ensure();
+    state = pyglib_gil_state_ensure();
 
     object_wrapper = pygobject_new(object);
 
     if (object_wrapper == NULL) {
-	pyg_gil_state_release(state);
+	pyglib_gil_state_release(state);
 	return;
     }
 
@@ -429,7 +426,7 @@
     Py_DECREF(py_pspec);
     Py_DECREF(py_value);
 
-    pyg_gil_state_release(state);
+    pyglib_gil_state_release(state);
 }
 
 static void
@@ -440,12 +437,12 @@
     PyObject *py_pspec;
     PyGILState_STATE state;
 
-    state = pyg_gil_state_ensure();
+    state = pyglib_gil_state_ensure();
 
     object_wrapper = pygobject_new(object);
 
     if (object_wrapper == NULL) {
-	pyg_gil_state_release(state);
+	pyglib_gil_state_release(state);
 	return;
     }
 
@@ -459,7 +456,7 @@
     Py_DECREF(py_pspec);
     Py_XDECREF(retval);
     
-    pyg_gil_state_release(state);
+    pyglib_gil_state_release(state);
 }
 
 static void
@@ -486,7 +483,7 @@
     PyGSignalAccumulatorData *data = _data;
     PyGILState_STATE state;
 
-    state = pyg_gil_state_ensure();
+    state = pyglib_gil_state_ensure();
     if (ihint->detail)
         py_detail = PyString_FromString(g_quark_to_string(ihint->detail));
     else {
@@ -520,7 +517,7 @@
         }
         Py_DECREF(py_retval);
     }
-    pyg_gil_state_release(state);
+    pyglib_gil_state_release(state);
     return retval;
 }
 
@@ -1191,7 +1188,7 @@
            * g_object_new -> we have no python wrapper, so create it
            * now */
         PyGILState_STATE state;
-        state = pyg_gil_state_ensure();
+        state = pyglib_gil_state_ensure();
         wrapper = pygobject_new_full(object, FALSE, g_class);
         args = PyTuple_New(0);
         kwargs = PyDict_New();
@@ -1199,7 +1196,7 @@
             PyErr_Print();
         Py_DECREF(args);
         Py_DECREF(kwargs);
-        pyg_gil_state_release(state);
+        pyglib_gil_state_release(state);
     }
 }
 
@@ -1905,7 +1902,7 @@
 
     g_return_val_if_fail(user_data != NULL, FALSE);
 
-    state = pyg_gil_state_ensure();
+    state = pyglib_gil_state_ensure();
 
     tuple = (PyObject *)user_data;
     ret = PyObject_CallObject(PyTuple_GetItem(tuple, 0),
@@ -1918,27 +1915,21 @@
 	Py_DECREF(ret);
     }
     
-    pyg_gil_state_release(state);
+    pyglib_gil_state_release(state);
 
     return res;
 }
 
-static PyObject *
-pyg_main_context_default(PyObject *unused)
-{
-    return pyg_main_context_new(g_main_context_default());
-}
-
 static int
-pyg_gil_state_ensure_py23 (void)
+pygobject_gil_state_ensure (void)
 {
-    return PyGILState_Ensure();
+    return pyglib_gil_state_ensure ();
 }
 
 static void
-pyg_gil_state_release_py23 (int flag)
+pygobject_gil_state_release (int flag)
 {
-    PyGILState_Release(flag);
+    pyglib_gil_state_release(flag);
 }
 
 static PyObject *
@@ -1973,7 +1964,7 @@
     PyObject *params;
     guint i;
 
-    state = pyg_gil_state_ensure();
+    state = pyglib_gil_state_ensure();
 
     /* construct Python tuple for the parameter values */
     params = PyTuple_New(n_param_values);
@@ -2004,7 +1995,7 @@
     retval = (retobj == Py_True ? TRUE : FALSE);
     Py_XDECREF(retobj);
 out:
-    pyg_gil_state_release(state);
+    pyglib_gil_state_release(state);
     return retval;
 }
 
@@ -2128,8 +2119,6 @@
       pyg_object_class_list_properties, METH_VARARGS },
     { "new",
       (PyCFunction)pyg_object_new, METH_VARARGS|METH_KEYWORDS },
-    { "main_context_default",
-      (PyCFunction)pyg_main_context_default, METH_NOARGS },
     { "threads_init",
       (PyCFunction)pyg_threads_init, METH_VARARGS|METH_KEYWORDS },
     { "signal_accumulator_true_handled",
@@ -2536,9 +2525,9 @@
 	PyGILState_STATE state;
 	PyObject* warning = user_data;
 
-	state = pyg_gil_state_ensure();
+	state = pyglib_gil_state_ensure();
 	PyErr_Warn(warning, (char *) message);
-	pyg_gil_state_release(state);
+	pyglib_gil_state_release(state);
     } else
         g_log_default_handler(log_domain, log_level, message, user_data);
 }
@@ -2649,8 +2638,8 @@
 
   FALSE, /* threads_enabled */
   pyglib_enable_threads,
-  pyg_gil_state_ensure_py23,
-  pyg_gil_state_release_py23,
+  pygobject_gil_state_ensure,
+  pygobject_gil_state_release,
   pyg_register_class_init,
   pyg_register_interface_info,
 
@@ -2691,6 +2680,7 @@
     PyObject *m, *d, *o, *tuple, *features;
     PyObject *descr;
     PyObject *warning;
+    PyObject *glib;
     
     PyGParamSpec_Type.ob_type = &PyType_Type;
     if (PyType_Ready(&PyGParamSpec_Type))
@@ -2702,6 +2692,11 @@
     PyDict_SetItemString(d, "GParamSpec", (PyObject *)&PyGParamSpec_Type);
 
     g_type_init();
+    pyglib_init();
+
+    glib = PyImport_ImportModule("glib");
+    _PyGMainLoop_Type = (PyTypeObject*)PyObject_GetAttrString(glib, "MainLoop");
+    _PyGMainContext_Type = (PyTypeObject*)PyObject_GetAttrString(glib, "MainContext");
 
     pygboxed_type_key        = g_quark_from_static_string("PyGBoxed::class");
     pygboxed_marshal_key     = g_quark_from_static_string("PyGBoxed::marshal");
@@ -2758,9 +2753,6 @@
     PyGFlags_Type.tp_base = &PyInt_Type;
     REGISTER_GTYPE(d, PyGFlags_Type, "GFlags", G_TYPE_FLAGS);
 
-    REGISTER_TYPE(d, PyGMainLoop_Type, "MainLoop"); 
-    REGISTER_TYPE(d, PyGMainContext_Type, "MainContext"); 
-
     REGISTER_TYPE(d, PyGIOChannel_Type, "IOChannel");
 
     REGISTER_TYPE(d, PyGSource_Type, "Source");

Modified: trunk/gobject/pygboxed.c
==============================================================================
--- trunk/gobject/pygboxed.c	(original)
+++ trunk/gobject/pygboxed.c	Sun Jul 20 14:17:04 2008
@@ -24,15 +24,16 @@
 #  include <config.h>
 #endif
 
+#include <pyglib.h>
 #include "pygobject-private.h"
 
 static void
 pyg_boxed_dealloc(PyGBoxed *self)
 {
     if (self->free_on_dealloc && self->boxed) {
-	PyGILState_STATE state = pyg_gil_state_ensure();
+	PyGILState_STATE state = pyglib_gil_state_ensure();
 	g_boxed_free(self->gtype, self->boxed);
-	pyg_gil_state_release(state);
+	pyglib_gil_state_release(state);
     }
 
     self->ob_type->tp_free((PyObject *)self);
@@ -213,11 +214,11 @@
     g_return_val_if_fail(boxed_type != 0, NULL);
     g_return_val_if_fail(!copy_boxed || (copy_boxed && own_ref), NULL);
 
-    state = pyg_gil_state_ensure();
+    state = pyglib_gil_state_ensure();
 
     if (!boxed) {
 	Py_INCREF(Py_None);
-	pyg_gil_state_release(state);
+	pyglib_gil_state_release(state);
 	return Py_None;
     }
 
@@ -227,7 +228,7 @@
     self = PyObject_NEW(PyGBoxed, tp);
 
     if (self == NULL) {
-	pyg_gil_state_release(state);
+	pyglib_gil_state_release(state);
         return NULL;
     }
 
@@ -237,7 +238,7 @@
     self->gtype = boxed_type;
     self->free_on_dealloc = own_ref;
 
-    pyg_gil_state_release(state);
+    pyglib_gil_state_release(state);
     
     return (PyObject *)self;
 }

Modified: trunk/gobject/pygenum.c
==============================================================================
--- trunk/gobject/pygenum.c	(original)
+++ trunk/gobject/pygenum.c	Sun Jul 20 14:17:04 2008
@@ -25,6 +25,7 @@
 #  include <config.h>
 #endif
 
+#include <pyglib.h>
 #include "pygobject-private.h"
 
 static PyObject *
@@ -190,7 +191,7 @@
         return NULL;
     }
     
-    state = pyg_gil_state_ensure();
+    state = pyglib_gil_state_ensure();
 
     instance_dict = PyDict_New();
     stub = PyObject_CallFunction((PyObject *)&PyType_Type, "s(O)O",
@@ -199,7 +200,7 @@
     Py_DECREF(instance_dict);
     if (!stub) {
 	PyErr_SetString(PyExc_RuntimeError, "can't create const");
-	pyg_gil_state_release(state);
+	pyglib_gil_state_release(state);
 	return NULL;
     }
 
@@ -255,7 +256,7 @@
 
     g_type_class_unref(eclass);
     
-    pyg_gil_state_release(state);
+    pyglib_gil_state_release(state);
     return stub;
 }
 

Modified: trunk/gobject/pygflags.c
==============================================================================
--- trunk/gobject/pygflags.c	(original)
+++ trunk/gobject/pygflags.c	Sun Jul 20 14:17:04 2008
@@ -25,6 +25,7 @@
 #  include <config.h>
 #endif
 
+#include <pyglib.h>
 #include "pygobject-private.h"
 
 #define GET_INT_VALUE(x) (((PyIntObject*)x)->ob_ival)
@@ -212,7 +213,7 @@
         return NULL;
     }
     
-    state = pyg_gil_state_ensure();
+    state = pyglib_gil_state_ensure();
 
     instance_dict = PyDict_New();
     stub = PyObject_CallFunction((PyObject *)&PyType_Type, "s(O)O",
@@ -221,7 +222,7 @@
     Py_DECREF(instance_dict);
     if (!stub) {
 	PyErr_SetString(PyExc_RuntimeError, "can't create const");
-	pyg_gil_state_release(state);
+	pyglib_gil_state_release(state);
         return NULL;
     }
     
@@ -275,7 +276,7 @@
 
     g_type_class_unref(eclass);
 
-    pyg_gil_state_release(state);
+    pyglib_gil_state_release(state);
 
     return stub;
 }

Modified: trunk/gobject/pygiochannel.c
==============================================================================
--- trunk/gobject/pygiochannel.c	(original)
+++ trunk/gobject/pygiochannel.c	Sun Jul 20 14:17:04 2008
@@ -4,6 +4,7 @@
 #  include <config.h>
 #endif
 
+#include <pyglib.h>
 #include "pygobject-private.h"
 #include "pythread.h"
 #include <structmember.h> /* for PyMemberDef */
@@ -441,7 +442,7 @@
     g_return_val_if_fail(((PyGIOChannel *) data->iochannel)->channel == source,
                          FALSE);
 
-    state = pyg_gil_state_ensure();
+    state = pyglib_gil_state_ensure();
 
     if (data->user_data)
         ret = PyObject_CallFunction(data->callback, "OiO", data->iochannel,
@@ -457,7 +458,7 @@
 	res = PyObject_IsTrue(ret);
 	Py_DECREF(ret);
     }
-    pyg_gil_state_release(state);
+    pyglib_gil_state_release(state);
 
     return res;
 }

Modified: trunk/gobject/pygobject-private.h
==============================================================================
--- trunk/gobject/pygobject-private.h	(original)
+++ trunk/gobject/pygobject-private.h	Sun Jul 20 14:17:04 2008
@@ -218,7 +218,8 @@
     GSource *signal_source;
 } PyGMainLoop;
 
-extern PyTypeObject PyGMainLoop_Type;
+PyTypeObject *_PyGMainLoop_Type;
+#define PyGMainLoop_Type (*_PyGMainLoop_Type)
 
 /* pygmaincontext */
 
@@ -227,8 +228,8 @@
     GMainContext *context;
 } PyGMainContext;
 
-extern PyTypeObject PyGMainContext_Type;
-PyObject * pyg_main_context_new (GMainContext *context);
+PyTypeObject *_PyGMainContext_Type;
+#define PyGMainContext_Type (*_PyGMainContext_Type)
 
 /* pygparamspec */
 

Modified: trunk/gobject/pygobject.c
==============================================================================
--- trunk/gobject/pygobject.c	(original)
+++ trunk/gobject/pygobject.c	Sun Jul 20 14:17:04 2008
@@ -19,6 +19,8 @@
  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
  * USA
  */
+
+#include <pyglib.h>
 #include "pygobject-private.h"
 
 static void pygobject_dealloc(PyGObject *self);
@@ -35,7 +37,7 @@
 void
 pygobject_data_free(PyGObjectData *data)
 {
-    PyGILState_STATE state = pyg_gil_state_ensure();
+    PyGILState_STATE state = pyglib_gil_state_ensure();
     GSList *closures, *tmp;
     Py_DECREF(data->type);
     tmp = closures = data->closures;
@@ -58,7 +60,7 @@
  	g_warning("invalidated all closures, but data->closures != NULL !");
 
     g_free(data);
-    pyg_gil_state_release(state);
+    pyglib_gil_state_release(state);
 }
 
 static inline PyGObjectData *
@@ -629,14 +631,14 @@
     PyGObject *self = (PyGObject*) data;
     PyGILState_STATE state;
 
-    state = pyg_gil_state_ensure();
+    state = pyglib_gil_state_ensure();
 
     if (is_last_ref)
 	Py_DECREF(self);
     else
         Py_INCREF(self);
 
-    pyg_gil_state_release(state);
+    pyglib_gil_state_release(state);
 }
 
   /* Called when the inst_dict is first created; switches the 
@@ -744,7 +746,7 @@
     PyObject *modules, *module;
     gchar *type_name, *mod_name, *gtype_name;
 
-    state = pyg_gil_state_ensure();
+    state = pyglib_gil_state_ensure();
 
     bases = pyg_type_get_bases(gtype);
     py_parent_type = (PyTypeObject *) PyTuple_GetItem(bases, 0);
@@ -787,7 +789,7 @@
 
     if (type == NULL) {
 	PyErr_Print();
-        pyg_gil_state_release(state);
+        pyglib_gil_state_release(state);
 	return NULL;
     }
 
@@ -810,7 +812,7 @@
 
     if (PyType_Ready(type) < 0) {
 	g_warning ("couldn't make the type `%s' ready", type->tp_name);
-        pyg_gil_state_release(state);
+        pyglib_gil_state_release(state);
 	return NULL;
     }
     /* insert type name in module dict */
@@ -824,7 +826,7 @@
     Py_INCREF(type);
     g_type_set_qdata(gtype, pygobject_class_key, type);
 
-    pyg_gil_state_release(state);
+    pyglib_gil_state_release(state);
 
     return type;
 }
@@ -2131,7 +2133,7 @@
     self->obj = NULL;
     if (self->callback) {
         PyObject *retval;
-        PyGILState_STATE state = pyg_gil_state_ensure();
+        PyGILState_STATE state = pyglib_gil_state_ensure();
         retval = PyObject_Call(self->callback, self->user_data, NULL);
         if (retval) {
             if (retval != Py_None)
@@ -2149,7 +2151,7 @@
             self->have_floating_ref = FALSE;
             Py_DECREF((PyObject *) self);
         }
-        pyg_gil_state_release(state);
+        pyglib_gil_state_release(state);
     }
 }
 

Modified: trunk/gobject/pygobject.h
==============================================================================
--- trunk/gobject/pygobject.h	(original)
+++ trunk/gobject/pygobject.h	Sun Jul 20 14:17:04 2008
@@ -176,7 +176,6 @@
     gboolean threads_enabled;
     int       (*enable_threads) (void);
 
-    /* These 2 are deprecated */
     int       (*gil_state_ensure) (void);
     void      (*gil_state_release) (int flag);
     
@@ -254,6 +253,8 @@
 #define pyg_flags_add               (_PyGObject_API->flags_add)
 #define pyg_flags_from_gtype        (_PyGObject_API->flags_from_gtype)
 #define pyg_enable_threads          (_PyGObject_API->enable_threads)
+#define pyg_gil_state_ensure        (_PyGObject_API->gil_state_ensure)
+#define pyg_gil_state_release       (_PyGObject_API->gil_state_release)
 #define pyg_register_class_init     (_PyGObject_API->register_class_init)
 #define pyg_register_interface_info (_PyGObject_API->register_interface_info)
 #define pygobject_construct         (_PyGObject_API->pygobject_construct)
@@ -265,7 +266,6 @@
 #define pyg_gerror_exception_check (_PyGObject_API->gerror_exception_check)
 #define pyg_option_group_new       (_PyGObject_API->option_group_new)
 
-
 #define pyg_block_threads()   G_STMT_START {   \
     if (_PyGObject_API->block_threads != NULL) \
       (* _PyGObject_API->block_threads)();     \
@@ -277,14 +277,6 @@
 
 #define pyg_threads_enabled (_PyGObject_API->threads_enabled)
 
-#define pyg_gil_state_ensure() \
-    (_PyGObject_API->threads_enabled ? \
-      (PyGILState_Ensure()) : 0)
-#define pyg_gil_state_release(state) G_STMT_START {     \
-    if (_PyGObject_API->threads_enabled)                \
-        PyGILState_Release(state);                      \
-    } G_STMT_END
-
 #define pyg_begin_allow_threads                 \
     G_STMT_START {                              \
         PyThreadState *_save = NULL;            \

Modified: trunk/gobject/pygoptiongroup.c
==============================================================================
--- trunk/gobject/pygoptiongroup.c	(original)
+++ trunk/gobject/pygoptiongroup.c	Sun Jul 20 14:17:04 2008
@@ -24,6 +24,7 @@
 #  include <config.h>
 #endif
 
+#include <pyglib.h>
 #include "pygobject-private.h"
 #include "pygobject.h"
 
@@ -43,7 +44,7 @@
 destroy_g_group(PyGOptionGroup *self)
 {
     PyGILState_STATE state;
-    state = pyg_gil_state_ensure();
+    state = pyglib_gil_state_ensure();
 
     self->group = NULL;
     Py_CLEAR(self->callback);
@@ -56,7 +57,7 @@
         Py_DECREF(self);
     }
         
-    pyg_gil_state_release(state);
+    pyglib_gil_state_release(state);
 }
 
 static int
@@ -107,7 +108,7 @@
     PyGILState_STATE state;
     gboolean no_error;
         
-    state = pyg_gil_state_ensure();
+    state = pyglib_gil_state_ensure();
   
     if (value == NULL)
     {
@@ -123,13 +124,13 @@
     if (ret != NULL)
     {
         Py_DECREF(ret);
-        pyg_gil_state_release(state);
+        pyglib_gil_state_release(state);
         return TRUE;
     }
     else
     {
         no_error = pyg_gerror_exception_check(error) != -1;
-        pyg_gil_state_release(state);
+        pyglib_gil_state_release(state);
         return no_error;
     }
 }

Modified: trunk/gobject/pygpointer.c
==============================================================================
--- trunk/gobject/pygpointer.c	(original)
+++ trunk/gobject/pygpointer.c	Sun Jul 20 14:17:04 2008
@@ -24,6 +24,7 @@
 #  include <config.h>
 #endif
 
+#include <pyglib.h>
 #include "pygobject-private.h"
 
 static void
@@ -185,11 +186,11 @@
     PyTypeObject *tp;
     g_return_val_if_fail(pointer_type != 0, NULL);
 
-    state = pyg_gil_state_ensure();
+    state = pyglib_gil_state_ensure();
 
     if (!pointer) {
 	Py_INCREF(Py_None);
-	pyg_gil_state_release(state);
+	pyglib_gil_state_release(state);
 	return Py_None;
     }
 
@@ -198,7 +199,7 @@
 	tp = (PyTypeObject *)&PyGPointer_Type; /* fallback */
     self = PyObject_NEW(PyGPointer, tp);
 
-    pyg_gil_state_release(state);
+    pyglib_gil_state_release(state);
 
     if (self == NULL)
 	return NULL;

Modified: trunk/gobject/pygsource.c
==============================================================================
--- trunk/gobject/pygsource.c	(original)
+++ trunk/gobject/pygsource.c	Sun Jul 20 14:17:04 2008
@@ -30,6 +30,7 @@
 #include "pygobject-private.h"
 #include "pythread.h"
 #include <structmember.h>
+#include <pyglib.h>
 
 
 #define CHECK_DESTROYED(self, ret)			G_STMT_START {	\
@@ -174,7 +175,7 @@
     context = g_source_get_context(self->source);
 
     if (context) {
-	return pyg_main_context_new(context);
+	return pyglib_main_context_new(context);
     } else {
 	Py_INCREF(Py_None);
 	return Py_None;
@@ -397,7 +398,7 @@
     gboolean got_err = TRUE;
     PyGILState_STATE state;
 
-    state = pyg_gil_state_ensure();
+    state = pyglib_gil_state_ensure();
 
     t = PyObject_CallMethod(pysource->obj, "prepare", NULL);
 
@@ -433,7 +434,7 @@
 
     Py_XDECREF(t);
 
-    pyg_gil_state_release(state);
+    pyglib_gil_state_release(state);
 
     return ret;
 }
@@ -446,7 +447,7 @@
     gboolean ret;
     PyGILState_STATE state;
 
-    state = pyg_gil_state_ensure();
+    state = pyglib_gil_state_ensure();
 
     t = PyObject_CallMethod(pysource->obj, "check", NULL);
 
@@ -458,7 +459,7 @@
 	Py_DECREF(t);
     }
 
-    pyg_gil_state_release(state);
+    pyglib_gil_state_release(state);
 
     return ret;
 }
@@ -471,7 +472,7 @@
     gboolean ret;
     PyGILState_STATE state;
 
-    state = pyg_gil_state_ensure();
+    state = pyglib_gil_state_ensure();
 
     if (callback) {
 	tuple = user_data;
@@ -493,7 +494,7 @@
 	Py_DECREF(t);
     }
 
-    pyg_gil_state_release(state);
+    pyglib_gil_state_release(state);
 
     return ret;
 }
@@ -505,7 +506,7 @@
     PyObject *func, *t;
     PyGILState_STATE state;
 
-    state = pyg_gil_state_ensure();
+    state = pyglib_gil_state_ensure();
 
     func = PyObject_GetAttrString(pysource->obj, "finalize");
     if (func) {
@@ -519,7 +520,7 @@
 	}
     }
 
-    pyg_gil_state_release(state);
+    pyglib_gil_state_release(state);
 }
 
 static GSourceFuncs pyg_source_funcs =

Modified: trunk/gobject/pygtype.c
==============================================================================
--- trunk/gobject/pygtype.c	(original)
+++ trunk/gobject/pygtype.c	Sun Jul 20 14:17:04 2008
@@ -20,6 +20,8 @@
  * USA
  */
 
+#include <pyglib.h>
+
 #include "pygobject-private.h"
 
 /* -------------- __gtype__ objects ---------------------------- */
@@ -1076,11 +1078,11 @@
     PyGClosure *pc = (PyGClosure *)closure;
     PyGILState_STATE state;
 
-    state = pyg_gil_state_ensure();
+    state = pyglib_gil_state_ensure();
     Py_XDECREF(pc->callback);
     Py_XDECREF(pc->extra_args);
     Py_XDECREF(pc->swap_data);
-    pyg_gil_state_release(state);
+    pyglib_gil_state_release(state);
 
     pc->callback = NULL;
     pc->extra_args = NULL;
@@ -1100,7 +1102,7 @@
     PyObject *params, *ret;
     guint i;
 
-    state = pyg_gil_state_ensure();
+    state = pyglib_gil_state_ensure();
 
     /* construct Python tuple for the parameter values */
     params = PyTuple_New(n_param_values);
@@ -1148,7 +1150,7 @@
     
  out:
     Py_DECREF(params);
-    pyg_gil_state_release(state);
+    pyglib_gil_state_release(state);
 }
 
 /**
@@ -1241,7 +1243,7 @@
     PyObject *params, *ret;
     guint i, len;
 
-    state = pyg_gil_state_ensure();
+    state = pyglib_gil_state_ensure();
     
     g_return_if_fail(invocation_hint != NULL);
     /* get the object passed as the first argument to the closure */
@@ -1267,7 +1269,7 @@
     if (!method) {
 	PyErr_Clear();
 	Py_DECREF(object_wrapper);
-	pyg_gil_state_release(state);
+	pyglib_gil_state_release(state);
 	return;
     }
     Py_DECREF(object_wrapper);
@@ -1281,7 +1283,7 @@
 	/* error condition */
 	if (!item) {
 	    Py_DECREF(params);
-	    pyg_gil_state_release(state);
+	    pyglib_gil_state_release(state);
 	    return;
 	}
 	PyTuple_SetItem(params, i - 1, item);
@@ -1308,7 +1310,7 @@
 	PyErr_Print();
 	Py_DECREF(method);
 	Py_DECREF(params);
-	pyg_gil_state_release(state);
+	pyglib_gil_state_release(state);
 	return;
     }
     Py_DECREF(method);
@@ -1316,7 +1318,7 @@
     if (return_value)
 	pyg_value_from_pyobject(return_value, ret);
     Py_DECREF(ret);
-    pyg_gil_state_release(state);
+    pyglib_gil_state_release(state);
 }
 
 /**

Modified: trunk/tests/common.py
==============================================================================
--- trunk/tests/common.py	(original)
+++ trunk/tests/common.py	Sun Jul 20 14:17:04 2008
@@ -8,6 +8,7 @@
     # ltihooks
     sys.path.insert(0, srcDir)
     sys.path.insert(0, buildDir)
+    sys.path.insert(0, os.path.join(buildDir, 'glib'))
     sys.path.insert(0, os.path.join(buildDir, 'gobject'))
     sys.path.insert(0, os.path.join(buildDir, 'gio'))
     import ltihooks
@@ -17,6 +18,7 @@
     sys.argv.append('--g-fatal-warnings')
 
     testhelper = importModule('testhelper', '.')
+    glib = importModule('glib', buildDir, 'glib')
     gobject = importModule('gobject', buildDir, 'gobject')
     gio = importModule('gio', buildDir, 'gio')
 



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