[pygobject] Replace usage of pyg_begin_allow_threads with Py_BEGIN_ALLOW_THREADS



commit 87e41db2e060acd689a2ac043bc1ac51007de6f3
Author: Simon Feltman <sfeltman src gnome org>
Date:   Fri May 3 02:00:07 2013 -0700

    Replace usage of pyg_begin_allow_threads with Py_BEGIN_ALLOW_THREADS
    
    Replace all usage of pyg[lib]_begin_allow_threads with direct usage
    of Py_BEGIN_ALLOW_THREADS.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=699440

 gi/_glib/pyglib.h           |    4 ----
 gi/_glib/pygoptioncontext.c |    4 ++--
 gi/_gobject/pygobject.c     |   33 ++++++++++++++++-----------------
 gi/gimodule.c               |    4 ++--
 gi/pygi-invoke.c            |    4 ++--
 5 files changed, 22 insertions(+), 27 deletions(-)
---
diff --git a/gi/_glib/pyglib.h b/gi/_glib/pyglib.h
index 35be4eb..1c62f1d 100644
--- a/gi/_glib/pyglib.h
+++ b/gi/_glib/pyglib.h
@@ -37,13 +37,9 @@ void pyglib_init_internal(PyObject *api);
 #ifdef DISABLE_THREADING
 #    define pyglib_gil_state_ensure()        PyGILState_LOCKED
 #    define pyglib_gil_state_release(state)  state
-#    define pyglib_begin_allow_threads       G_STMT_START {
-#    define pyglib_end_allow_threads         } G_STMT_END
 #else
 #    define pyglib_gil_state_ensure          PyGILState_Ensure
 #    define pyglib_gil_state_release         PyGILState_Release
-#    define pyglib_begin_allow_threads       Py_BEGIN_ALLOW_THREADS
-#    define pyglib_end_allow_threads         Py_END_ALLOW_THREADS
 #endif
 
 /* Deprecated, only available for API compatibility. */
diff --git a/gi/_glib/pygoptioncontext.c b/gi/_glib/pygoptioncontext.c
index b985dbe..8ecbff8 100644
--- a/gi/_glib/pygoptioncontext.c
+++ b/gi/_glib/pygoptioncontext.c
@@ -130,10 +130,10 @@ pyg_option_context_parse(PyGOptionContext *self,
 
     g_assert(argv_length <= G_MAXINT);
     argv_length_int = argv_length;
-    pyglib_begin_allow_threads;
+    Py_BEGIN_ALLOW_THREADS;
     result = g_option_context_parse(self->context, &argv_length_int, &argv_content,
                                     &error);
-    pyglib_end_allow_threads;
+    Py_END_ALLOW_THREADS;
     argv_length = argv_length_int;
 
     if (!result)
diff --git a/gi/_gobject/pygobject.c b/gi/_gobject/pygobject.c
index 4ca360a..875da17 100644
--- a/gi/_gobject/pygobject.c
+++ b/gi/_gobject/pygobject.c
@@ -88,10 +88,9 @@ pygobject_data_free(PyGObjectData *data)
     if (Py_IsInitialized()) {
        state = pyglib_gil_state_ensure();
        Py_DECREF(data->type);
-       /* We cannot use pyg_begin_allow_threads here because this is inside
+       /* We cannot use Py_BEGIN_ALLOW_THREADS here because this is inside
         * a branch. */
-       if (pyg_threads_enabled)
-           _save = PyEval_SaveThread();
+       Py_UNBLOCK_THREADS; /* Modifies _save */
     }
 
     tmp = closures = data->closures;
@@ -114,8 +113,7 @@ pygobject_data_free(PyGObjectData *data)
     g_free(data);
 
     if (Py_IsInitialized()) {
-       if (pyg_threads_enabled)
-           PyEval_RestoreThread(_save);
+       Py_BLOCK_THREADS; /* Restores _save */
        pyglib_gil_state_release(state);
     }
 }
@@ -309,10 +307,11 @@ PyGProps_getattro(PyGProps *self, PyObject *attr)
 
     /* The GType is implemented in Python, or we failed to read it via gi:
      * do a straightforward read. */
+    Py_BEGIN_ALLOW_THREADS;
     g_value_init(&value, G_PARAM_SPEC_VALUE_TYPE(pspec));
-    pyg_begin_allow_threads;
     g_object_get_property(self->pygobject->obj, pspec->name, &value);
-    pyg_end_allow_threads;
+    Py_END_ALLOW_THREADS;
+
     ret = pyg_param_gvalue_as_pyobject(&value, TRUE, pspec);
     g_value_unset(&value);
     
@@ -352,12 +351,11 @@ set_property_from_pspec(GObject *obj,
        return FALSE;
     }
 
-    pyg_begin_allow_threads;
+    Py_BEGIN_ALLOW_THREADS;
     g_object_set_property(obj, pspec->name, &value);
-    pyg_end_allow_threads;
-
     g_value_unset(&value);
-    
+    Py_END_ALLOW_THREADS;
+
     return TRUE;
 }
 
@@ -1183,9 +1181,9 @@ pygobject_clear(PyGObject *self)
             g_object_remove_toggle_ref(self->obj, pyg_toggle_notify, self);
             self->private_flags.flags &= ~PYGOBJECT_USING_TOGGLE_REF;
         } else {
-            pyg_begin_allow_threads;
+            Py_BEGIN_ALLOW_THREADS;
             g_object_unref(self->obj);
-            pyg_end_allow_threads;
+            Py_END_ALLOW_THREADS;
         }
         self->obj = NULL;
     }
@@ -1320,9 +1318,10 @@ pygobject_get_property(PyGObject *self, PyObject *args)
        return NULL;
     }
     g_value_init(&value, G_PARAM_SPEC_VALUE_TYPE(pspec));
-    pyg_begin_allow_threads;
+    Py_BEGIN_ALLOW_THREADS;
     g_object_get_property(self->obj, param_name, &value);
-    pyg_end_allow_threads;
+    Py_END_ALLOW_THREADS;
+
     ret = pyg_param_gvalue_as_pyobject(&value, TRUE, pspec);
     g_value_unset(&value);
     return ret;
@@ -1372,9 +1371,9 @@ pygobject_get_properties(PyGObject *self, PyObject *args)
         }
         g_value_init(&value, G_PARAM_SPEC_VALUE_TYPE(pspec));
 
-        pyg_begin_allow_threads;
+        Py_BEGIN_ALLOW_THREADS;
         g_object_get_property(self->obj, property_name, &value);
-        pyg_end_allow_threads;
+        Py_END_ALLOW_THREADS;
 
         item = pyg_value_as_pyobject(&value, TRUE);
         PyTuple_SetItem(tuple, i, item);
diff --git a/gi/gimodule.c b/gi/gimodule.c
index 3952f91..5b6bc14 100644
--- a/gi/gimodule.c
+++ b/gi/gimodule.c
@@ -575,9 +575,9 @@ pyg_channel_read(PyObject* self, PyObject *args, PyObject *kwargs)
        
         buf = PYGLIB_PyBytes_AsString(ret_obj) + total_read;
 
-        pyglib_begin_allow_threads;
+        Py_BEGIN_ALLOW_THREADS;
         status = g_io_channel_read_chars (iochannel, buf, buf_size, &single_read, &error);
-        pyglib_end_allow_threads;
+        Py_END_ALLOW_THREADS;
 
         if (pyglib_error_check(&error))
            goto failure;
diff --git a/gi/pygi-invoke.c b/gi/pygi-invoke.c
index 0cbb9ca..ec5da91 100644
--- a/gi/pygi-invoke.c
+++ b/gi/pygi-invoke.c
@@ -37,7 +37,7 @@ _invoke_callable (PyGIInvokeState *state,
 
     error = NULL;
 
-    pyg_begin_allow_threads;
+    Py_BEGIN_ALLOW_THREADS;
 
     /* FIXME: use this for now but we can streamline the calls */
     if (cache->function_type == PYGI_FUNCTION_TYPE_VFUNC)
@@ -68,7 +68,7 @@ _invoke_callable (PyGIInvokeState *state,
                                           cache->n_to_py_args,
                                          &state->return_arg,
                                          &error);
-    pyg_end_allow_threads;
+    Py_END_ALLOW_THREADS;
 
     if (!retval) {
         g_assert (error != NULL);


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