2012-02-03 19:42:56 +01:00
|
|
|
/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*-
|
|
|
|
* GObject introspection: Helper functions for ffi integration
|
2008-11-11 01:04:45 +01:00
|
|
|
*
|
|
|
|
* Copyright (C) 2008 Red Hat, Inc
|
|
|
|
* Copyright (C) 2005 Matthias Clasen
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the
|
|
|
|
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
|
|
|
* Boston, MA 02111-1307, USA.
|
|
|
|
*/
|
2009-12-02 13:38:58 +01:00
|
|
|
|
2011-09-03 18:02:54 +02:00
|
|
|
#include "config.h"
|
|
|
|
|
2009-12-02 13:38:58 +01:00
|
|
|
#include <sys/types.h>
|
|
|
|
|
2009-02-05 01:40:14 +01:00
|
|
|
#include <errno.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <unistd.h>
|
2008-11-11 01:04:45 +01:00
|
|
|
#include "girffi.h"
|
2009-02-05 01:40:14 +01:00
|
|
|
#include "girepository.h"
|
2010-06-07 04:22:57 +02:00
|
|
|
#include "girepository-private.h"
|
2008-11-11 01:04:45 +01:00
|
|
|
|
2011-12-21 21:55:18 +01:00
|
|
|
static ffi_type *
|
|
|
|
gi_type_tag_get_ffi_type_internal (GITypeTag tag,
|
|
|
|
gboolean is_pointer,
|
|
|
|
gboolean is_enum)
|
2008-11-11 01:04:45 +01:00
|
|
|
{
|
|
|
|
switch (tag)
|
|
|
|
{
|
|
|
|
case GI_TYPE_TAG_BOOLEAN:
|
|
|
|
return &ffi_type_uint;
|
|
|
|
case GI_TYPE_TAG_INT8:
|
|
|
|
return &ffi_type_sint8;
|
|
|
|
case GI_TYPE_TAG_UINT8:
|
|
|
|
return &ffi_type_uint8;
|
|
|
|
case GI_TYPE_TAG_INT16:
|
|
|
|
return &ffi_type_sint16;
|
|
|
|
case GI_TYPE_TAG_UINT16:
|
|
|
|
return &ffi_type_uint16;
|
|
|
|
case GI_TYPE_TAG_INT32:
|
|
|
|
return &ffi_type_sint32;
|
|
|
|
case GI_TYPE_TAG_UINT32:
|
2010-10-26 17:12:26 +02:00
|
|
|
case GI_TYPE_TAG_UNICHAR:
|
2008-11-11 01:04:45 +01:00
|
|
|
return &ffi_type_uint32;
|
|
|
|
case GI_TYPE_TAG_INT64:
|
|
|
|
return &ffi_type_sint64;
|
|
|
|
case GI_TYPE_TAG_UINT64:
|
|
|
|
return &ffi_type_uint64;
|
|
|
|
case GI_TYPE_TAG_GTYPE:
|
|
|
|
#if GLIB_SIZEOF_SIZE_T == 4
|
|
|
|
return &ffi_type_uint32;
|
|
|
|
#elif GLIB_SIZEOF_SIZE_T == 8
|
|
|
|
return &ffi_type_uint64;
|
|
|
|
#else
|
|
|
|
# error "Unexpected size for size_t: not 4 or 8"
|
|
|
|
#endif
|
|
|
|
case GI_TYPE_TAG_FLOAT:
|
|
|
|
return &ffi_type_float;
|
|
|
|
case GI_TYPE_TAG_DOUBLE:
|
|
|
|
return &ffi_type_double;
|
|
|
|
case GI_TYPE_TAG_UTF8:
|
|
|
|
case GI_TYPE_TAG_FILENAME:
|
|
|
|
case GI_TYPE_TAG_ARRAY:
|
|
|
|
case GI_TYPE_TAG_GLIST:
|
|
|
|
case GI_TYPE_TAG_GSLIST:
|
|
|
|
case GI_TYPE_TAG_GHASH:
|
|
|
|
case GI_TYPE_TAG_ERROR:
|
|
|
|
return &ffi_type_pointer;
|
2011-12-21 21:55:18 +01:00
|
|
|
case GI_TYPE_TAG_INTERFACE:
|
|
|
|
{
|
|
|
|
/* We need to handle enums specially:
|
|
|
|
* https://bugzilla.gnome.org/show_bug.cgi?id=665150
|
|
|
|
*/
|
|
|
|
if (!is_enum)
|
|
|
|
return &ffi_type_pointer;
|
|
|
|
else
|
|
|
|
return &ffi_type_sint32;
|
|
|
|
}
|
2009-12-07 17:54:18 +01:00
|
|
|
case GI_TYPE_TAG_VOID:
|
|
|
|
if (is_pointer)
|
|
|
|
return &ffi_type_pointer;
|
|
|
|
else
|
|
|
|
return &ffi_type_void;
|
2008-11-11 01:04:45 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
g_assert_not_reached ();
|
|
|
|
|
|
|
|
return NULL;
|
2010-03-24 19:00:06 +01:00
|
|
|
}
|
2009-02-05 01:40:14 +01:00
|
|
|
|
2011-12-21 21:55:18 +01:00
|
|
|
/**
|
|
|
|
* gi_type_tag_get_ffi_type:
|
|
|
|
* @tag: A #GITypeTag
|
|
|
|
* @is_pointer: Whether or not this is a pointer type
|
|
|
|
*
|
|
|
|
* Returns: A #ffi_type corresponding to the platform default C ABI for @tag and @is_pointer.
|
|
|
|
*/
|
|
|
|
ffi_type *
|
|
|
|
gi_type_tag_get_ffi_type (GITypeTag tag,
|
|
|
|
gboolean is_pointer)
|
|
|
|
{
|
|
|
|
return gi_type_tag_get_ffi_type_internal (tag, is_pointer, FALSE);
|
|
|
|
}
|
|
|
|
|
2009-12-07 17:54:18 +01:00
|
|
|
/**
|
|
|
|
* g_type_info_get_ffi_type:
|
|
|
|
* @info: A #GITypeInfo
|
|
|
|
*
|
|
|
|
* Returns: A #ffi_type corresponding to the platform default C ABI for @info.
|
|
|
|
*/
|
|
|
|
ffi_type *
|
|
|
|
g_type_info_get_ffi_type (GITypeInfo *info)
|
2009-10-20 21:33:33 +02:00
|
|
|
{
|
2012-01-06 20:55:45 +01:00
|
|
|
gboolean is_enum = FALSE;
|
2011-12-21 21:55:18 +01:00
|
|
|
GIBaseInfo *iinfo;
|
|
|
|
|
|
|
|
if (g_type_info_get_tag (info) == GI_TYPE_TAG_INTERFACE)
|
|
|
|
{
|
|
|
|
iinfo = g_type_info_get_interface (info);
|
|
|
|
switch (g_base_info_get_type (iinfo))
|
2012-01-06 20:55:45 +01:00
|
|
|
{
|
|
|
|
case GI_INFO_TYPE_ENUM:
|
|
|
|
case GI_INFO_TYPE_FLAGS:
|
|
|
|
is_enum = TRUE;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2011-12-21 21:55:18 +01:00
|
|
|
g_base_info_unref (iinfo);
|
|
|
|
}
|
|
|
|
|
|
|
|
return gi_type_tag_get_ffi_type_internal (g_type_info_get_tag (info), g_type_info_is_pointer (info), is_enum);
|
2009-10-20 21:33:33 +02:00
|
|
|
}
|
|
|
|
|
2009-02-05 01:40:14 +01:00
|
|
|
/**
|
|
|
|
* g_callable_info_get_ffi_arg_types:
|
|
|
|
* @callable_info: a callable info from a typelib
|
|
|
|
*
|
|
|
|
* Return value: an array of ffi_type*. The array itself
|
|
|
|
* should be freed using g_free() after use.
|
|
|
|
*/
|
2009-12-07 17:54:18 +01:00
|
|
|
static ffi_type **
|
2009-02-05 01:40:14 +01:00
|
|
|
g_callable_info_get_ffi_arg_types (GICallableInfo *callable_info)
|
|
|
|
{
|
|
|
|
ffi_type **arg_types;
|
|
|
|
gint n_args, i;
|
2010-03-24 19:00:06 +01:00
|
|
|
|
2009-02-05 01:40:14 +01:00
|
|
|
g_return_val_if_fail (callable_info != NULL, NULL);
|
|
|
|
|
|
|
|
n_args = g_callable_info_get_n_args (callable_info);
|
2010-03-24 19:00:06 +01:00
|
|
|
|
2009-02-05 01:40:14 +01:00
|
|
|
arg_types = (ffi_type **) g_new0 (ffi_type *, n_args + 1);
|
2010-03-24 19:00:06 +01:00
|
|
|
|
2009-02-05 01:40:14 +01:00
|
|
|
for (i = 0; i < n_args; ++i)
|
|
|
|
{
|
|
|
|
GIArgInfo *arg_info = g_callable_info_get_arg (callable_info, i);
|
|
|
|
GITypeInfo *arg_type = g_arg_info_get_type (arg_info);
|
2011-02-06 05:48:58 +01:00
|
|
|
switch (g_arg_info_get_direction (arg_info))
|
|
|
|
{
|
|
|
|
case GI_DIRECTION_IN:
|
|
|
|
arg_types[i] = g_type_info_get_ffi_type (arg_type);
|
|
|
|
break;
|
|
|
|
case GI_DIRECTION_OUT:
|
|
|
|
case GI_DIRECTION_INOUT:
|
|
|
|
arg_types[i] = &ffi_type_pointer;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
g_assert_not_reached ();
|
|
|
|
}
|
2009-02-05 01:40:14 +01:00
|
|
|
g_base_info_unref ((GIBaseInfo *)arg_info);
|
|
|
|
g_base_info_unref ((GIBaseInfo *)arg_type);
|
|
|
|
}
|
|
|
|
arg_types[n_args] = NULL;
|
|
|
|
|
|
|
|
return arg_types;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* g_callable_info_get_ffi_return_type:
|
|
|
|
* @callable_info: a callable info from a typelib
|
|
|
|
*
|
|
|
|
* Fetches the ffi_type for a corresponding return value of
|
|
|
|
* a #GICallableInfo
|
|
|
|
* Return value: the ffi_type for the return value
|
|
|
|
*/
|
2009-12-07 17:54:18 +01:00
|
|
|
static ffi_type *
|
2009-02-05 01:40:14 +01:00
|
|
|
g_callable_info_get_ffi_return_type (GICallableInfo *callable_info)
|
|
|
|
{
|
|
|
|
GITypeInfo *return_type;
|
2009-12-07 17:54:18 +01:00
|
|
|
ffi_type *return_ffi_type;
|
2009-02-05 01:40:14 +01:00
|
|
|
|
|
|
|
g_return_val_if_fail (callable_info != NULL, NULL);
|
|
|
|
|
|
|
|
return_type = g_callable_info_get_return_type (callable_info);
|
2009-12-07 17:54:18 +01:00
|
|
|
return_ffi_type = g_type_info_get_ffi_type (return_type);
|
2009-12-02 13:18:24 +01:00
|
|
|
g_base_info_unref((GIBaseInfo*)return_type);
|
2010-03-24 19:00:06 +01:00
|
|
|
|
2009-12-07 17:54:18 +01:00
|
|
|
return return_ffi_type;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* g_function_info_prep_invoker:
|
|
|
|
* @info: A #GIFunctionInfo
|
|
|
|
* @invoker: Output invoker structure
|
|
|
|
* @error: A #GError
|
|
|
|
*
|
|
|
|
* Initialize the caller-allocated @invoker structure with a cache
|
|
|
|
* of information needed to invoke the C function corresponding to
|
|
|
|
* @info with the platform's default ABI.
|
|
|
|
*
|
|
|
|
* A primary intent of this function is that a dynamic structure allocated
|
|
|
|
* by a language binding could contain a #GIFunctionInvoker structure
|
|
|
|
* inside the binding's function mapping.
|
2010-05-18 23:10:51 +02:00
|
|
|
*
|
|
|
|
* Returns: %TRUE on success, %FALSE otherwise with @error set.
|
2009-12-07 17:54:18 +01:00
|
|
|
*/
|
|
|
|
gboolean
|
|
|
|
g_function_info_prep_invoker (GIFunctionInfo *info,
|
|
|
|
GIFunctionInvoker *invoker,
|
|
|
|
GError **error)
|
|
|
|
{
|
|
|
|
const char *symbol;
|
2011-11-28 20:51:04 +01:00
|
|
|
gpointer addr;
|
2010-03-24 19:00:06 +01:00
|
|
|
|
2009-12-07 17:54:18 +01:00
|
|
|
g_return_val_if_fail (info != NULL, FALSE);
|
|
|
|
g_return_val_if_fail (invoker != NULL, FALSE);
|
2010-03-24 19:00:06 +01:00
|
|
|
|
2009-12-07 17:54:18 +01:00
|
|
|
symbol = g_function_info_get_symbol ((GIFunctionInfo*) info);
|
2010-03-24 19:00:06 +01:00
|
|
|
|
2009-12-07 17:54:18 +01:00
|
|
|
if (!g_typelib_symbol (g_base_info_get_typelib((GIBaseInfo *) info),
|
2011-11-28 20:51:04 +01:00
|
|
|
symbol, &addr))
|
2009-12-07 17:54:18 +01:00
|
|
|
{
|
|
|
|
g_set_error (error,
|
|
|
|
G_INVOKE_ERROR,
|
|
|
|
G_INVOKE_ERROR_SYMBOL_NOT_FOUND,
|
|
|
|
"Could not locate %s: %s", symbol, g_module_error ());
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2011-11-28 20:51:04 +01:00
|
|
|
return g_function_invoker_new_for_address (addr, info, invoker, error);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* g_function_invoker_new_for_address:
|
|
|
|
* @addr: The address
|
|
|
|
* @info: A #GICallableInfo
|
|
|
|
* @invoker: Output invoker structure
|
|
|
|
* @error: A #GError
|
|
|
|
*
|
|
|
|
* Initialize the caller-allocated @invoker structure with a cache
|
|
|
|
* of information needed to invoke the C function corresponding to
|
|
|
|
* @info with the platform's default ABI.
|
|
|
|
*
|
|
|
|
* A primary intent of this function is that a dynamic structure allocated
|
|
|
|
* by a language binding could contain a #GIFunctionInvoker structure
|
|
|
|
* inside the binding's function mapping.
|
|
|
|
*
|
|
|
|
* Returns: %TRUE on success, %FALSE otherwise with @error set.
|
|
|
|
*/
|
|
|
|
gboolean
|
|
|
|
g_function_invoker_new_for_address (gpointer addr,
|
|
|
|
GICallableInfo *info,
|
|
|
|
GIFunctionInvoker *invoker,
|
|
|
|
GError **error)
|
|
|
|
{
|
|
|
|
ffi_type *rtype;
|
|
|
|
ffi_type **atypes;
|
|
|
|
GITypeInfo *tinfo;
|
|
|
|
GIArgInfo *ainfo;
|
|
|
|
GIInfoType info_type;
|
|
|
|
gboolean is_method;
|
|
|
|
gboolean throws;
|
|
|
|
gint n_args, n_invoke_args, i;
|
|
|
|
|
|
|
|
g_return_val_if_fail (info != NULL, FALSE);
|
|
|
|
g_return_val_if_fail (invoker != NULL, FALSE);
|
|
|
|
|
|
|
|
invoker->native_address = addr;
|
|
|
|
|
|
|
|
info_type = g_base_info_get_type ((GIBaseInfo *) info);
|
|
|
|
|
|
|
|
switch (info_type)
|
|
|
|
{
|
|
|
|
case GI_INFO_TYPE_FUNCTION:
|
|
|
|
{
|
|
|
|
GIFunctionInfoFlags flags;
|
|
|
|
flags = g_function_info_get_flags ((GIFunctionInfo *)info);
|
|
|
|
is_method = (flags & GI_FUNCTION_IS_METHOD) != 0;
|
|
|
|
throws = (flags & GI_FUNCTION_THROWS) != 0;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case GI_INFO_TYPE_VFUNC:
|
2012-02-03 19:47:17 +01:00
|
|
|
{
|
|
|
|
GIVFuncInfoFlags flags;
|
|
|
|
flags = g_vfunc_info_get_flags ((GIVFuncInfo *)info);
|
|
|
|
throws = (flags & GI_VFUNC_THROWS) != 0;
|
|
|
|
}
|
|
|
|
is_method = FALSE;
|
|
|
|
break;
|
|
|
|
case GI_INFO_TYPE_CALLBACK:
|
2011-11-28 20:51:04 +01:00
|
|
|
is_method = TRUE;
|
|
|
|
throws = FALSE;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
g_assert_not_reached ();
|
|
|
|
}
|
2009-12-02 13:18:24 +01:00
|
|
|
|
2011-11-28 20:51:04 +01:00
|
|
|
tinfo = g_callable_info_get_return_type (info);
|
2009-12-07 17:54:18 +01:00
|
|
|
rtype = g_type_info_get_ffi_type (tinfo);
|
|
|
|
g_base_info_unref ((GIBaseInfo *)tinfo);
|
|
|
|
|
2011-11-28 20:51:04 +01:00
|
|
|
n_args = g_callable_info_get_n_args (info);
|
2009-12-07 17:54:18 +01:00
|
|
|
if (is_method)
|
|
|
|
n_invoke_args = n_args+1;
|
|
|
|
else
|
|
|
|
n_invoke_args = n_args;
|
|
|
|
|
|
|
|
if (throws)
|
|
|
|
/* Add an argument for the GError */
|
|
|
|
n_invoke_args ++;
|
|
|
|
|
|
|
|
/* TODO: avoid malloc here? */
|
|
|
|
atypes = g_malloc0 (sizeof (ffi_type*) * n_invoke_args);
|
2010-03-24 19:00:06 +01:00
|
|
|
|
2009-12-07 17:54:18 +01:00
|
|
|
if (is_method)
|
|
|
|
{
|
|
|
|
atypes[0] = &ffi_type_pointer;
|
|
|
|
}
|
|
|
|
for (i = 0; i < n_args; i++)
|
|
|
|
{
|
|
|
|
int offset = (is_method ? 1 : 0);
|
2011-11-28 20:51:04 +01:00
|
|
|
ainfo = g_callable_info_get_arg (info, i);
|
2009-12-07 17:54:18 +01:00
|
|
|
switch (g_arg_info_get_direction (ainfo))
|
|
|
|
{
|
|
|
|
case GI_DIRECTION_IN:
|
|
|
|
tinfo = g_arg_info_get_type (ainfo);
|
|
|
|
atypes[i+offset] = g_type_info_get_ffi_type (tinfo);
|
|
|
|
g_base_info_unref ((GIBaseInfo *)tinfo);
|
|
|
|
break;
|
|
|
|
case GI_DIRECTION_OUT:
|
|
|
|
case GI_DIRECTION_INOUT:
|
|
|
|
atypes[i+offset] = &ffi_type_pointer;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
g_assert_not_reached ();
|
|
|
|
}
|
|
|
|
g_base_info_unref ((GIBaseInfo *)ainfo);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (throws)
|
|
|
|
{
|
|
|
|
atypes[n_invoke_args - 1] = &ffi_type_pointer;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ffi_prep_cif (&(invoker->cif), FFI_DEFAULT_ABI, n_invoke_args, rtype, atypes) == FFI_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* g_function_info_invoker_destroy:
|
|
|
|
* @invoker: A #GIFunctionInvoker
|
2010-03-24 19:00:06 +01:00
|
|
|
*
|
2009-12-07 17:54:18 +01:00
|
|
|
* Release all resources allocated for the internals of @invoker; callers
|
|
|
|
* are responsible for freeing any resources allocated for the structure
|
|
|
|
* itself however.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
g_function_invoker_destroy (GIFunctionInvoker *invoker)
|
|
|
|
{
|
|
|
|
g_free (invoker->cif.arg_types);
|
2009-02-05 01:40:14 +01:00
|
|
|
}
|
|
|
|
|
2010-04-07 23:48:52 +02:00
|
|
|
typedef struct {
|
|
|
|
ffi_closure ffi_closure;
|
|
|
|
gpointer writable_self;
|
|
|
|
} GIClosureWrapper;
|
|
|
|
|
2009-02-05 01:40:14 +01:00
|
|
|
/**
|
|
|
|
* g_callable_info_prepare_closure:
|
|
|
|
* @callable_info: a callable info from a typelib
|
|
|
|
* @cif: a ffi_cif structure
|
|
|
|
* @callback: the ffi callback
|
|
|
|
* @user_data: data to be passed into the callback
|
|
|
|
*
|
|
|
|
* Prepares a callback for ffi invocation.
|
|
|
|
*
|
|
|
|
* Return value: the ffi_closure or NULL on error.
|
2010-04-07 23:48:52 +02:00
|
|
|
* The return value should be freed by calling g_callable_info_free_closure().
|
2009-02-05 01:40:14 +01:00
|
|
|
*/
|
|
|
|
ffi_closure *
|
|
|
|
g_callable_info_prepare_closure (GICallableInfo *callable_info,
|
|
|
|
ffi_cif *cif,
|
|
|
|
GIFFIClosureCallback callback,
|
|
|
|
gpointer user_data)
|
|
|
|
{
|
2010-04-07 23:48:52 +02:00
|
|
|
gpointer exec_ptr;
|
|
|
|
GIClosureWrapper *closure;
|
2009-02-05 01:40:14 +01:00
|
|
|
ffi_status status;
|
2010-03-24 19:00:06 +01:00
|
|
|
|
2009-02-05 01:40:14 +01:00
|
|
|
g_return_val_if_fail (callable_info != NULL, FALSE);
|
|
|
|
g_return_val_if_fail (cif != NULL, FALSE);
|
|
|
|
g_return_val_if_fail (callback != NULL, FALSE);
|
2010-03-24 19:00:06 +01:00
|
|
|
|
2010-04-07 23:48:52 +02:00
|
|
|
closure = ffi_closure_alloc (sizeof (GIClosureWrapper), &exec_ptr);
|
2009-02-05 01:40:14 +01:00
|
|
|
if (!closure)
|
|
|
|
{
|
2010-04-07 23:48:52 +02:00
|
|
|
g_warning ("could not allocate closure\n");
|
2009-02-05 01:40:14 +01:00
|
|
|
return NULL;
|
|
|
|
}
|
2010-04-07 23:48:52 +02:00
|
|
|
closure->writable_self = closure;
|
2009-02-05 01:40:14 +01:00
|
|
|
|
|
|
|
status = ffi_prep_cif (cif, FFI_DEFAULT_ABI,
|
|
|
|
g_callable_info_get_n_args (callable_info),
|
|
|
|
g_callable_info_get_ffi_return_type (callable_info),
|
|
|
|
g_callable_info_get_ffi_arg_types (callable_info));
|
|
|
|
if (status != FFI_OK)
|
|
|
|
{
|
2010-04-07 23:48:52 +02:00
|
|
|
g_warning ("ffi_prep_cif failed: %d\n", status);
|
|
|
|
ffi_closure_free (closure);
|
2009-02-05 01:40:14 +01:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2010-04-07 23:48:52 +02:00
|
|
|
status = ffi_prep_closure_loc (&closure->ffi_closure, cif, callback, user_data, exec_ptr);
|
2009-02-05 01:40:14 +01:00
|
|
|
if (status != FFI_OK)
|
|
|
|
{
|
|
|
|
g_warning ("ffi_prep_closure failed: %d\n", status);
|
2010-04-07 23:48:52 +02:00
|
|
|
ffi_closure_free (closure);
|
2009-02-05 01:40:14 +01:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2010-04-07 23:48:52 +02:00
|
|
|
/* Return exec_ptr, which points to the same underlying memory as
|
|
|
|
* closure, but via an executable-non-writable mapping.
|
|
|
|
*/
|
|
|
|
return exec_ptr;
|
2009-02-05 01:40:14 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2009-02-12 04:32:25 +01:00
|
|
|
* g_callable_info_free_closure:
|
2009-02-05 01:40:14 +01:00
|
|
|
* @callable_info: a callable info from a typelib
|
|
|
|
* @closure: ffi closure
|
|
|
|
*
|
|
|
|
* Frees a ffi_closure returned from g_callable_info_prepare_closure()
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
g_callable_info_free_closure (GICallableInfo *callable_info,
|
|
|
|
ffi_closure *closure)
|
|
|
|
{
|
2010-04-07 23:48:52 +02:00
|
|
|
GIClosureWrapper *wrapper = (GIClosureWrapper *)closure;
|
|
|
|
|
2011-06-20 21:17:55 +02:00
|
|
|
g_free (wrapper->ffi_closure.cif->arg_types);
|
2010-04-07 23:48:52 +02:00
|
|
|
ffi_closure_free (wrapper->writable_self);
|
2009-02-05 01:40:14 +01:00
|
|
|
}
|