コード例 #1
0
static void
rb_gi_function_info_invoke_raw_call(InvokeData *data)
{
    data->succeeded =
        g_function_info_invoke(data->info,
                               (GIArgument *)((void *)(data->in_args->data)),
                               data->in_args->len,
                               (GIArgument *)((void *)(data->out_args->data)),
                               data->out_args->len,
                               &(data->return_value),
                               data->error);
}
コード例 #2
0
gboolean
peas_gi_method_call (GObject        *instance,
                     GICallableInfo *func_info,
                     GType           iface_type,
                     const gchar    *method_name,
                     GIArgument     *args,
                     GIArgument     *return_value)
{
  gint n_args;
  guint n_in_args, n_out_args;
  GIArgument *in_args, *out_args;
  gboolean ret = TRUE;
  GError *error = NULL;

  g_return_val_if_fail (G_IS_OBJECT (instance), FALSE);
  g_return_val_if_fail (func_info != NULL, FALSE);
  g_return_val_if_fail (G_TYPE_IS_INTERFACE (iface_type), FALSE);
  g_return_val_if_fail (G_TYPE_CHECK_INSTANCE_TYPE (instance, iface_type),
                        FALSE);
  g_return_val_if_fail (method_name != NULL, FALSE);

  n_args = g_callable_info_get_n_args (func_info);
  g_return_val_if_fail (n_args >= 0, FALSE);
  n_in_args = 0;
  n_out_args = 0;

  in_args = g_newa (GIArgument, n_args + 1);
  out_args = g_newa (GIArgument, n_args);

  peas_gi_split_in_and_out_arguments (func_info, args,
                                      in_args+1, &n_in_args,
                                      out_args, &n_out_args);

  /* Set the object as the first argument for the method. */
  in_args[0].v_pointer = instance;
  n_in_args++;

  g_debug ("Calling '%s.%s' on '%p'",
           g_type_name (iface_type), method_name, instance);

  ret = g_function_info_invoke (func_info, in_args, n_in_args, out_args,
                                n_out_args, return_value, &error);
  if (!ret)
    {
      g_warning ("Error while calling '%s.%s': %s",
                 g_type_name (iface_type), method_name, error->message);
      g_error_free (error);
    }

  return ret;
}
コード例 #3
0
int main(void)
{
    GIRepository *repository;
    GError *error = NULL;
    GIBaseInfo *base_info;
    GIArgument in_args[5];
    GIArgument retval;

    g_type_init();

    repository = g_irepository_get_default();
    g_irepository_require(repository, "GLib", "2.0", 0, &error);
    if (error) {
      g_error("ERROR: %s\n", error->message);
      return 1;
    }

    base_info = g_irepository_find_by_name(repository, "GLib", "assertion_message");
    if (!base_info) {
      g_error("ERROR: %s\n", "Could not find GLib.warn_message");
      return 1;
    }

    in_args[0].v_pointer = "domain";
    in_args[1].v_pointer = "glib-print.c";
    in_args[2].v_pointer = "30";
    in_args[3].v_pointer = "main";
    in_args[4].v_pointer = "hello world";

    if (!g_function_info_invoke ((GIFunctionInfo *)base_info,
                                 (const GIArgument*)&in_args,
                                 5,
                                 NULL,
                                 0,
                                 &retval,
                                 &error)) {
      g_error("ERROR: %s\n", error->message);
      return 1;
    }

    g_base_info_unref (base_info);

    return 0;
}
コード例 #4
0
ファイル: plgi.c プロジェクト: keriharris/plgi
gboolean
plgi_main_loop_service_task(gpointer data)
{
  PLGITask *task = data;
  gboolean ret;

  PLGI_debug("  servicing function: %s()",
             g_function_info_get_symbol(task->callable_info->info));

  ret = g_function_info_invoke(task->callable_info->info,
                               task->in_args, task->callable_info->n_in_args,
                               task->out_args, task->callable_info->n_out_args,
                               task->return_arg, &task->error);

  task->ret = ret;
  PLGI_debug("    function retval: %d", ret);
  task->completed = TRUE;

  return G_SOURCE_REMOVE;
}
コード例 #5
0
int
main(int argc, char **argv)
{
  GIRepository *repo;
  GITypelib *ret;
  GIBaseInfo *info;
  GIArgument in_arg[1];
  GIArgument ret_arg;
  GError *error;
  gboolean invoke_return;

  repo = g_irepository_get_default ();

  error = NULL;
  ret = g_irepository_require (repo, "GLib", NULL, 0, &error);
  g_assert (ret != NULL);
  g_assert (error == NULL);

  info = g_irepository_find_by_name (repo, "GLib", "file_read_link");
  g_assert (info != NULL);
  g_assert (g_base_info_get_type (info) == GI_INFO_TYPE_FUNCTION);
  g_assert (g_function_info_get_flags ((GIFunctionInfo *)info) & GI_FUNCTION_THROWS);

  in_arg[0].v_string = g_strdup ("non-existent-file/hope");
  error = NULL;
  invoke_return = g_function_info_invoke ((GIFunctionInfo *)info,
                                          in_arg,
                                          1,
                                          NULL,
                                          0,
                                          &ret_arg,
                                          &error);
  g_free(in_arg[0].v_string);

  g_assert (invoke_return == FALSE);
  g_assert (error != NULL);
  g_assert (error->domain == G_FILE_ERROR);
  g_assert (error->code == G_FILE_ERROR_NOENT);

  exit(0);
}
コード例 #6
0
ファイル: boxed.c プロジェクト: Katyunechka/gjs
static JSBool
boxed_new(JSContext   *context,
          JSObject    *obj, /* "this" for constructor */
          Boxed       *priv,
          unsigned     argc,
          jsval       *argv,
          jsval       *rval)
{
    if (priv->gtype == G_TYPE_VARIANT) {
        /* Short-circuit construction for GVariants by calling into the JS packing
           function */
        return boxed_invoke_constructor (context, obj, "_new_internal", argc, argv, rval);
    }

    /* If the structure is registered as a boxed, we can create a new instance by
     * looking for a zero-args constructor and calling it.
     * Constructors don't really make sense for non-boxed types, since there is no
     * memory management for the return value, and zero_args_constructor and
     * default_constructor are always -1 for them.
     *
     * For backward compatibility, we choose the zero args constructor if one
     * exists, otherwise we choose the internal slice allocator if possible;
     * finally, we fallback on the default constructor */
    if (priv->zero_args_constructor >= 0) {
        GIFunctionInfo *func_info = g_struct_info_get_method (priv->info, priv->zero_args_constructor);

        GIArgument rval;
        GError *error = NULL;

        if (!g_function_info_invoke(func_info, NULL, 0, NULL, 0, &rval, &error)) {
            gjs_throw(context, "Failed to invoke boxed constructor: %s", error->message);
            g_clear_error(&error);
            g_base_info_unref((GIBaseInfo*) func_info);
            return JS_FALSE;
        }

        g_base_info_unref((GIBaseInfo*) func_info);

        priv->gboxed = rval.v_pointer;

        gjs_debug_lifecycle(GJS_DEBUG_GBOXED,
                            "JSObject created with boxed instance %p type %s",
                            priv->gboxed, g_type_name(gtype));

    } else if (priv->can_allocate_directly) {
        boxed_new_direct(priv);
    } else if (priv->default_constructor >= 0) {
        GIFunctionInfo *constructor;
        const gchar *constructor_name;
        JSBool retval;

        /* for simplicity, we simply delegate all the work to the actual JS constructor
           function (which we retrieve from the JS constructor, that is, Namespace.BoxedType,
           or object.constructor, given that object was created with the right prototype */

        constructor = g_struct_info_get_method(priv->info, priv->default_constructor);
        constructor_name = g_base_info_get_name((GIBaseInfo*)constructor);

        retval = boxed_invoke_constructor(context, obj, constructor_name, argc, argv, rval);

        g_base_info_unref((GIBaseInfo*)constructor);

        return retval;
    } else {
        gjs_throw(context, "Unable to construct struct type %s since it has no default constructor and cannot be allocated directly",
                  g_base_info_get_name((GIBaseInfo*) priv->info));
        return JS_FALSE;
    }

    /* If we reach this code, we need to init from a map of fields */

    if (argc == 0)
        return JS_TRUE;

    if (argc > 1) {
        gjs_throw(context, "Constructor with multiple arguments not supported for %s",
                  g_base_info_get_name((GIBaseInfo *)priv->info));
        return JS_FALSE;
    }

    return boxed_init_from_props (context, obj, priv, argv[0]);
}