[pygobject] Fix cleanup of GValue arrays
- From: Martin Pitt <martinpitt src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [pygobject] Fix cleanup of GValue arrays
- Date: Wed, 27 Feb 2013 22:28:18 +0000 (UTC)
commit 4f5e8b7554b6388aa2d0eb4a3b285d99499163be
Author: Martin Pitt <martinpitt gnome org>
Date: Wed Feb 27 23:21:34 2013 +0100
Fix cleanup of GValue arrays
Commit bc1fd8 introduced a thinko: We must not change
item_arg_cache->from_py_cleanup, as it's a global cache. Revert the original
change, and instead put the hack into _pygi_marshal_cleanup_from_py_array(),
which now short-circuits _pygi_marshal_cleanup_from_py_interface_struct_gvalue() to avoid
trying to release a slice which has never been allocated in
_pygi_marshal_from_py_array().
https://bugzilla.gnome.org/show_bug.cgi?id=672224
gi/pygi-marshal-cleanup.c | 11 ++++++++++-
gi/pygi-marshal-from-py.c | 10 +++-------
2 files changed, 13 insertions(+), 8 deletions(-)
---
diff --git a/gi/pygi-marshal-cleanup.c b/gi/pygi-marshal-cleanup.c
index bd9522a..50f593d 100644
--- a/gi/pygi-marshal-cleanup.c
+++ b/gi/pygi-marshal-cleanup.c
@@ -368,8 +368,17 @@ _pygi_marshal_cleanup_from_py_array (PyGIInvokeState *state,
else if (sequence_cache->item_cache->is_pointer)
item = g_array_index (array_, gpointer, i);
/* case 3: C array or GArray with simple types or structs */
- else
+ else {
item = array_->data + i * sequence_cache->item_size;
+ /* special-case hack: GValue array items do not get slice
+ * allocated in _pygi_marshal_from_py_array(), so we must
+ * not try to deallocate it as a slice and thus
+ * short-circuit cleanup_func. */
+ if (cleanup_func == _pygi_marshal_cleanup_from_py_interface_struct_gvalue) {
+ g_value_unset ((GValue*) item);
+ continue;
+ }
+ }
cleanup_func (state, sequence_cache->item_cache, item, TRUE);
}
diff --git a/gi/pygi-marshal-from-py.c b/gi/pygi-marshal-from-py.c
index 15fdcc9..570b464 100644
--- a/gi/pygi-marshal-from-py.c
+++ b/gi/pygi-marshal-from-py.c
@@ -1015,14 +1015,10 @@ _pygi_marshal_from_py_array (PyGIInvokeState *state,
g_value_init (dest, G_VALUE_TYPE ((GValue*) item.v_pointer));
g_value_copy ((GValue*) item.v_pointer, dest);
}
-
- if (from_py_cleanup) {
+ /* we free the original copy already, the new one is a plain struct
+ * in an array. _pygi_marshal_cleanup_from_py_array() does not free it again */
+ if (from_py_cleanup)
from_py_cleanup (state, item_arg_cache, item.v_pointer, TRUE);
- /* we freed the original copy already, the new one is a
- * struct in an array. _pygi_marshal_cleanup_from_py_array()
- * must not free it again */
- item_arg_cache->from_py_cleanup = NULL;
- }
} else if (!is_boxed) {
/* HACK: Gdk.Atom is merely an integer wrapped in a pointer,
* so we must not dereference it; just copy the pointer
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]