Skip to content

[BUG] when returning a primitive type from a C callback for a task task::propagate expects a GValue #1730

@Ytsejam76

Description

@Ytsejam76

given a C code callback returning a primitive typed result (such as a boolean) with, e.g., g_task_return_boolean the Gtk-rs bindings fail to propagate the result, since the generic ffi::g_task_propagate_value() (or ffi::g_task_propagate_pointer`, depending on the version) is called under the hood by Task::propagate() and the call fails at the:

  g_return_val_if_fail (task->result_destroy == value_free, FALSE);

The workaround is to use g_task_return_value() even for primitive types:

  void my_task_callback(....) {
            GValue ret_value = { 0 };

/* My callback logic */

            g_value_init(&ret_value, G_TYPE_BOOLEAN);
            g_value_set_boolean(&ret_value, TRUE);
            g_task_return_value(task, &ret_value);
            g_value_unset(&ret_value);
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions