summaryrefslogtreecommitdiff
path: root/gi/pygi-marshal-to-py.c
diff options
context:
space:
mode:
Diffstat (limited to 'gi/pygi-marshal-to-py.c')
-rw-r--r--gi/pygi-marshal-to-py.c210
1 files changed, 0 insertions, 210 deletions
diff --git a/gi/pygi-marshal-to-py.c b/gi/pygi-marshal-to-py.c
index 5d238a35..645b248d 100644
--- a/gi/pygi-marshal-to-py.c
+++ b/gi/pygi-marshal-to-py.c
@@ -74,216 +74,6 @@ gi_argument_to_c_long (GIArgument *arg_in,
}
}
-static gboolean
-gi_argument_to_gsize (GIArgument *arg_in,
- gsize *gsize_out,
- GITypeTag type_tag)
-{
- switch (type_tag) {
- case GI_TYPE_TAG_INT8:
- *gsize_out = arg_in->v_int8;
- return TRUE;
- case GI_TYPE_TAG_UINT8:
- *gsize_out = arg_in->v_uint8;
- return TRUE;
- case GI_TYPE_TAG_INT16:
- *gsize_out = arg_in->v_int16;
- return TRUE;
- case GI_TYPE_TAG_UINT16:
- *gsize_out = arg_in->v_uint16;
- return TRUE;
- case GI_TYPE_TAG_INT32:
- *gsize_out = arg_in->v_int32;
- return TRUE;
- case GI_TYPE_TAG_UINT32:
- *gsize_out = arg_in->v_uint32;
- return TRUE;
- case GI_TYPE_TAG_INT64:
- *gsize_out = arg_in->v_int64;
- return TRUE;
- case GI_TYPE_TAG_UINT64:
- *gsize_out = arg_in->v_uint64;
- return TRUE;
- default:
- PyErr_Format (PyExc_TypeError,
- "Unable to marshal %s to gsize",
- g_type_tag_to_string (type_tag));
- return FALSE;
- }
-}
-
-PyObject *
-_pygi_marshal_to_py_array (PyGIInvokeState *state,
- PyGICallableCache *callable_cache,
- PyGIArgCache *arg_cache,
- GIArgument *arg)
-{
- GArray *array_;
- PyObject *py_obj = NULL;
- PyGISequenceCache *seq_cache = (PyGISequenceCache *)arg_cache;
- PyGIArgGArray *array_cache = (PyGIArgGArray *)arg_cache;
- gsize processed_items = 0;
-
- /* GArrays make it easier to iterate over arrays
- * with different element sizes but requires that
- * we allocate a GArray if the argument was a C array
- */
- if (array_cache->array_type == GI_ARRAY_TYPE_C) {
- gsize len;
- if (array_cache->fixed_size >= 0) {
- g_assert(arg->v_pointer != NULL);
- len = array_cache->fixed_size;
- } else if (array_cache->is_zero_terminated) {
- if (arg->v_pointer == NULL) {
- len = 0;
- } else if (seq_cache->item_cache->type_tag == GI_TYPE_TAG_UINT8) {
- len = strlen (arg->v_pointer);
- } else {
- len = g_strv_length ((gchar **)arg->v_pointer);
- }
- } else {
- GIArgument *len_arg = state->args[array_cache->len_arg_index];
- PyGIArgCache *arg_cache = _pygi_callable_cache_get_arg (callable_cache,
- array_cache->len_arg_index);
-
- if (!gi_argument_to_gsize (len_arg, &len, arg_cache->type_tag)) {
- return NULL;
- }
- }
-
- array_ = g_array_new (FALSE,
- FALSE,
- array_cache->item_size);
- if (array_ == NULL) {
- PyErr_NoMemory ();
-
- if (arg_cache->transfer == GI_TRANSFER_EVERYTHING && arg->v_pointer != NULL)
- g_free (arg->v_pointer);
-
- return NULL;
- }
-
- if (array_->data != NULL)
- g_free (array_->data);
- array_->data = arg->v_pointer;
- array_->len = len;
- } else {
- array_ = arg->v_pointer;
- }
-
- if (seq_cache->item_cache->type_tag == GI_TYPE_TAG_UINT8) {
- if (arg->v_pointer == NULL) {
- py_obj = PYGLIB_PyBytes_FromString ("");
- } else {
- py_obj = PYGLIB_PyBytes_FromStringAndSize (array_->data, array_->len);
- }
- } else {
- if (arg->v_pointer == NULL) {
- py_obj = PyList_New (0);
- } else {
- int i;
-
- gsize item_size;
- PyGIMarshalToPyFunc item_to_py_marshaller;
- PyGIArgCache *item_arg_cache;
-
- py_obj = PyList_New (array_->len);
- if (py_obj == NULL)
- goto err;
-
-
- item_arg_cache = seq_cache->item_cache;
- item_to_py_marshaller = item_arg_cache->to_py_marshaller;
-
- item_size = g_array_get_element_size (array_);
-
- for (i = 0; i < array_->len; i++) {
- GIArgument item_arg = {0};
- PyObject *py_item;
-
- /* If we are receiving an array of pointers, simply assign the pointer
- * and move on, letting the per-item marshaler deal with the
- * various transfer modes and ref counts (e.g. g_variant_ref_sink).
- */
- if (array_cache->array_type == GI_ARRAY_TYPE_PTR_ARRAY) {
- item_arg.v_pointer = g_ptr_array_index ( ( GPtrArray *)array_, i);
-
- } else if (item_arg_cache->is_pointer) {
- item_arg.v_pointer = g_array_index (array_, gpointer, i);
-
- } else if (item_arg_cache->type_tag == GI_TYPE_TAG_INTERFACE) {
- PyGIInterfaceCache *iface_cache = (PyGIInterfaceCache *) item_arg_cache;
-
- // FIXME: This probably doesn't work with boxed types or gvalues. See fx. _pygi_marshal_from_py_array()
- switch (g_base_info_get_type (iface_cache->interface_info)) {
- case GI_INFO_TYPE_STRUCT:
- if (arg_cache->transfer == GI_TRANSFER_EVERYTHING &&
- !g_type_is_a (iface_cache->g_type, G_TYPE_BOXED)) {
- /* array elements are structs */
- gpointer *_struct = g_malloc (item_size);
- memcpy (_struct, array_->data + i * item_size,
- item_size);
- item_arg.v_pointer = _struct;
- } else {
- item_arg.v_pointer = array_->data + i * item_size;
- }
- break;
- default:
- item_arg.v_pointer = g_array_index (array_, gpointer, i);
- break;
- }
- } else {
- memcpy (&item_arg, array_->data + i * item_size, item_size);
- }
-
- py_item = item_to_py_marshaller ( state,
- callable_cache,
- item_arg_cache,
- &item_arg);
-
- if (py_item == NULL) {
- Py_CLEAR (py_obj);
-
- if (array_cache->array_type == GI_ARRAY_TYPE_C)
- g_array_unref (array_);
-
- goto err;
- }
- PyList_SET_ITEM (py_obj, i, py_item);
- processed_items++;
- }
- }
- }
-
- if (array_cache->array_type == GI_ARRAY_TYPE_C)
- g_array_free (array_, FALSE);
-
- return py_obj;
-
-err:
- if (array_cache->array_type == GI_ARRAY_TYPE_C) {
- g_array_free (array_, arg_cache->transfer == GI_TRANSFER_EVERYTHING);
- } else {
- /* clean up unprocessed items */
- if (seq_cache->item_cache->to_py_cleanup != NULL) {
- int j;
- PyGIMarshalCleanupFunc cleanup_func = seq_cache->item_cache->to_py_cleanup;
- for (j = processed_items; j < array_->len; j++) {
- cleanup_func (state,
- seq_cache->item_cache,
- NULL,
- g_array_index (array_, gpointer, j),
- FALSE);
- }
- }
-
- if (arg_cache->transfer == GI_TRANSFER_EVERYTHING)
- g_array_free (array_, TRUE);
- }
-
- return NULL;
-}
-
PyObject *
_pygi_marshal_to_py_gerror (PyGIInvokeState *state,
PyGICallableCache *callable_cache,