Commit 4f5e8b75 authored by Martin Pitt's avatar Martin Pitt
Browse files

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
parent 70118c38
...@@ -368,8 +368,17 @@ _pygi_marshal_cleanup_from_py_array (PyGIInvokeState *state, ...@@ -368,8 +368,17 @@ _pygi_marshal_cleanup_from_py_array (PyGIInvokeState *state,
else if (sequence_cache->item_cache->is_pointer) else if (sequence_cache->item_cache->is_pointer)
item = g_array_index (array_, gpointer, i); item = g_array_index (array_, gpointer, i);
/* case 3: C array or GArray with simple types or structs */ /* case 3: C array or GArray with simple types or structs */
else else {
item = array_->data + i * sequence_cache->item_size; 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); cleanup_func (state, sequence_cache->item_cache, item, TRUE);
} }
......
...@@ -1015,14 +1015,10 @@ _pygi_marshal_from_py_array (PyGIInvokeState *state, ...@@ -1015,14 +1015,10 @@ _pygi_marshal_from_py_array (PyGIInvokeState *state,
g_value_init (dest, G_VALUE_TYPE ((GValue*) item.v_pointer)); g_value_init (dest, G_VALUE_TYPE ((GValue*) item.v_pointer));
g_value_copy ((GValue*) item.v_pointer, dest); g_value_copy ((GValue*) item.v_pointer, dest);
} }
/* we free the original copy already, the new one is a plain struct
if (from_py_cleanup) { * 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); 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) { } else if (!is_boxed) {
/* HACK: Gdk.Atom is merely an integer wrapped in a pointer, /* HACK: Gdk.Atom is merely an integer wrapped in a pointer,
* so we must not dereference it; just copy the pointer * so we must not dereference it; just copy the pointer
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment