diff options
Diffstat (limited to 'gi/pygi-marshal-cleanup.c')
-rw-r--r-- | gi/pygi-marshal-cleanup.c | 150 |
1 files changed, 0 insertions, 150 deletions
diff --git a/gi/pygi-marshal-cleanup.c b/gi/pygi-marshal-cleanup.c index d402f1ea..a8fa3f67 100644 --- a/gi/pygi-marshal-cleanup.c +++ b/gi/pygi-marshal-cleanup.c @@ -294,153 +294,3 @@ _pygi_marshal_cleanup_to_py_interface_struct_foreign (PyGIInvokeState *state, ( (PyGIInterfaceCache *)arg_cache)->interface_info, data); } - -static GArray* -_wrap_c_array (PyGIInvokeState *state, - PyGIArgGArray *array_cache, - gpointer data) -{ - GArray *array_; - gsize len = 0; - - if (array_cache->fixed_size >= 0) { - len = array_cache->fixed_size; - } else if (array_cache->is_zero_terminated) { - len = g_strv_length ((gchar **)data); - } else if (array_cache->len_arg_index >= 0) { - GIArgument *len_arg = state->args[array_cache->len_arg_index]; - len = len_arg->v_long; - } - - array_ = g_array_new (FALSE, - FALSE, - array_cache->item_size); - - if (array_ == NULL) - return NULL; - - g_free (array_->data); - array_->data = data; - array_->len = len; - - return array_; -} - -void -_pygi_marshal_cleanup_from_py_array (PyGIInvokeState *state, - PyGIArgCache *arg_cache, - PyObject *py_arg, - gpointer data, - gboolean was_processed) -{ - if (was_processed) { - GArray *array_ = NULL; - GPtrArray *ptr_array_ = NULL; - PyGISequenceCache *sequence_cache = (PyGISequenceCache *)arg_cache; - PyGIArgGArray *array_cache = (PyGIArgGArray *)arg_cache; - - if (array_cache->array_type == GI_ARRAY_TYPE_PTR_ARRAY) { - ptr_array_ = (GPtrArray *) data; - } else { - array_ = (GArray *) data; - } - - /* clean up items first */ - if (sequence_cache->item_cache->from_py_cleanup != NULL) { - gsize i; - guint len = (array_ != NULL) ? array_->len : ptr_array_->len; - PyGIMarshalCleanupFunc cleanup_func = - sequence_cache->item_cache->from_py_cleanup; - - for (i = 0; i < len; i++) { - gpointer item; - PyObject *py_item = NULL; - - /* case 1: GPtrArray */ - if (ptr_array_ != NULL) - item = g_ptr_array_index (ptr_array_, i); - /* case 2: C array or GArray with object pointers */ - 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 { - item = array_->data + i * array_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; - } - } - - py_item = PySequence_GetItem (py_arg, i); - cleanup_func (state, sequence_cache->item_cache, py_item, item, TRUE); - Py_XDECREF (py_item); - } - } - - /* Only free the array when we didn't transfer ownership */ - if (array_cache->array_type == GI_ARRAY_TYPE_C) { - /* always free the GArray wrapper created in from_py marshaling and - * passed back as cleanup_data - */ - g_array_free (array_, arg_cache->transfer == GI_TRANSFER_NOTHING); - } else { - if (array_ != NULL) - g_array_unref (array_); - else - g_ptr_array_unref (ptr_array_); - } - } -} - -void -_pygi_marshal_cleanup_to_py_array (PyGIInvokeState *state, - PyGIArgCache *arg_cache, - PyObject *dummy, - gpointer data, - gboolean was_processed) -{ - if (arg_cache->transfer == GI_TRANSFER_EVERYTHING || - arg_cache->transfer == GI_TRANSFER_CONTAINER) { - GArray *array_ = NULL; - GPtrArray *ptr_array_ = NULL; - PyGISequenceCache *sequence_cache = (PyGISequenceCache *)arg_cache; - PyGIArgGArray *array_cache = (PyGIArgGArray *)arg_cache; - - /* If this isn't a garray create one to help process variable sized - array elements */ - if (array_cache->array_type == GI_ARRAY_TYPE_C) { - array_ = _wrap_c_array (state, array_cache, data); - - if (array_ == NULL) - return; - - } else if (array_cache->array_type == GI_ARRAY_TYPE_PTR_ARRAY) { - ptr_array_ = (GPtrArray *) data; - } else { - array_ = (GArray *) data; - } - - if (sequence_cache->item_cache->to_py_cleanup != NULL) { - gsize i; - guint len = (array_ != NULL) ? array_->len : ptr_array_->len; - - PyGIMarshalCleanupFunc cleanup_func = sequence_cache->item_cache->to_py_cleanup; - for (i = 0; i < len; i++) { - cleanup_func (state, - sequence_cache->item_cache, - NULL, - (array_ != NULL) ? g_array_index (array_, gpointer, i) : g_ptr_array_index (ptr_array_, i), - was_processed); - } - } - - if (array_ != NULL) - g_array_free (array_, TRUE); - else - g_ptr_array_free (ptr_array_, TRUE); - } -} |