Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

marshall: Marshall C-native GType array. #86

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 27 additions & 2 deletions src/gig_argument.c
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ static void scm_to_c_native_boolean_array(S2C_ARG_DECL);
static void scm_to_c_native_immediate_array(S2C_ARG_DECL);
static void scm_to_c_native_string_array(S2C_ARG_DECL);
static void scm_to_c_native_interface_array(S2C_ARG_DECL);
static void scm_to_c_native_gtype_array(S2C_ARG_DECL);
static void scm_to_c_garray(S2C_ARG_DECL);
static void scm_to_c_byte_array(S2C_ARG_DECL);
static void scm_to_c_ptr_array(S2C_ARG_DECL);
Expand Down Expand Up @@ -245,8 +246,10 @@ scm_to_c_interface(S2C_ARG_DECL)
arg->v_pointer = NULL;
return;
}
else
UNHANDLED;
else {
arg->v_pointer = g_type_check_instance_cast((GTypeInstance*) gig_type_peek_object(object), meta->gtype);
return;
}
}

static void
Expand Down Expand Up @@ -546,6 +549,8 @@ scm_to_c_native_array(S2C_ARG_DECL)
|| item_type == G_TYPE_UINT64
|| item_type == G_TYPE_FLOAT || item_type == G_TYPE_DOUBLE)
scm_to_c_native_immediate_array(S2C_ARGS);
else if (item_type == G_TYPE_GTYPE)
scm_to_c_native_gtype_array(S2C_ARGS);
else if (item_type == G_TYPE_STRING)
scm_to_c_native_string_array(S2C_ARGS);
else if (fundamental_item_type == G_TYPE_BOXED || item_type == G_TYPE_VARIANT
Expand Down Expand Up @@ -914,6 +919,26 @@ scm_to_c_ghashtable(S2C_ARG_DECL)
arg->v_pointer = hash;
}

static void
scm_to_c_native_gtype_array(S2C_ARG_DECL)
{
TRACE_S2C();
if (!scm_is_vector(object))
scm_wrong_type_arg_msg(subr, argpos, object, "vector of gtype-ables");
*size = scm_c_vector_length(object);
if (meta->is_zero_terminated) {
arg->v_pointer = malloc(sizeof(GType) * (*size + 1));
((GType *)arg->v_pointer)[*size] = 0;
LATER_FREE(arg->v_pointer);
}
else {
arg->v_pointer = malloc(sizeof(GType) * *size);
LATER_FREE(arg->v_pointer);
}
for (gsize i = 0; i < *size; i++)
((GType *)(arg->v_pointer))[i] = scm_to_gtype(scm_c_vector_ref(object, i));
}

static void
scm_to_c_garray(S2C_ARG_DECL)
{
Expand Down
19 changes: 18 additions & 1 deletion test/gtk.scm
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
(use-modules (gi) (gi repository)
(use-modules (gi) (gi repository) (gi types)
(srfi srfi-1)
(srfi srfi-64))

Expand Down Expand Up @@ -63,4 +63,21 @@
(and (is-a? box <GtkBox>)
(= 2 (spacing box)))))

(test-assert "load TreeView"
(every load-by-name? '("Gtk" "Gtk" "Gtk") '("TreeModel" "TreeStore" "TreeView")))

(test-assert "tree-store:new (lowlevel)"
(let ((tree-store (tree-store:new (vector G_TYPE_LONG G_TYPE_LONG G_TYPE_LONG))))
(and (= 3 (tree-model:get-n-columns tree-store)))))

(test-assert "tree-view:set-model (lowlevel)"
(let ((tree-store (tree-store:new (vector G_TYPE_LONG G_TYPE_LONG G_TYPE_LONG)))
(tree-view (tree-view:new)))
(tree-view:set-model tree-view tree-store)))

; Not possible--because the columns are not properties:
;(test-assert "make tree store (highlevel)"
; (let ((tree-store (make <GtkTreeStore> #:columns (vector G_TYPE_LONG G_TYPE_LONG G_TYPE_LONG))))
; (and (= 3 (get-n-columns tree-store)))))

(test-end "gtk.scm")