[gjs] function: Reuse GIArgument for "handy union we can pass to ffi"
- From: Colin Walters <walters src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gjs] function: Reuse GIArgument for "handy union we can pass to ffi"
- Date: Mon, 5 Mar 2012 14:59:33 +0000 (UTC)
commit b3d34ef373e5333d8fa745dbe3c82101c5c4c493
Author: Colin Walters <walters verbum org>
Date: Thu Feb 16 14:55:40 2012 -0500
function: Reuse GIArgument for "handy union we can pass to ffi"
This is a preparatory patch for pushing the code down into
gobject-introspection.
https://bugzilla.gnome.org/show_bug.cgi?id=670249
gi/function.c | 52 +++++++++++++++++++++++-----------------------------
1 files changed, 23 insertions(+), 29 deletions(-)
---
diff --git a/gi/function.c b/gi/function.c
index 4322721..a796185 100644
--- a/gi/function.c
+++ b/gi/function.c
@@ -539,58 +539,52 @@ get_length_from_arg (GArgument *arg, GITypeTag tag)
}
}
+
/* Extract the correct bits from an ffi_arg return value into
* GIArgument: https://bugzilla.gnome.org/show_bug.cgi?id=665152
*
* Also see the ffi_call man page - the storage requirements for return
* values are "special".
*/
-union GjsFFIReturnValue {
- ffi_arg rv_ffi_arg;
- ffi_sarg rv_ffi_sarg;
- guint64 rv_u64;
- gint64 rv_s64;
- float rv_float;
- double rv_double;
-};
+typedef GIArgument GjsFFIReturnValue;
+
static void
set_gargument_from_ffi_return_value (GITypeInfo *return_info,
- GIArgument *return_value,
- union GjsFFIReturnValue *value)
+ GIArgument *arg,
+ GjsFFIReturnValue *ffi_value)
{
switch (g_type_info_get_tag (return_info)) {
case GI_TYPE_TAG_INT8:
- return_value->v_int8 = (gint8) value->rv_ffi_sarg;
+ arg->v_int8 = (gint8) ffi_value->v_long;
break;
case GI_TYPE_TAG_UINT8:
- return_value->v_uint8 = (guint8) value->rv_ffi_arg;
+ arg->v_uint8 = (guint8) ffi_value->v_ulong;
break;
case GI_TYPE_TAG_INT16:
- return_value->v_int16 = (gint16) value->rv_ffi_sarg;
+ arg->v_int16 = (gint16) ffi_value->v_long;
break;
case GI_TYPE_TAG_UINT16:
- return_value->v_uint16 = (guint16) value->rv_ffi_arg;
+ arg->v_uint16 = (guint16) ffi_value->v_ulong;
break;
case GI_TYPE_TAG_INT32:
- return_value->v_int32 = (gint32) value->rv_ffi_sarg;
+ arg->v_int32 = (gint32) ffi_value->v_long;
break;
case GI_TYPE_TAG_UINT32:
case GI_TYPE_TAG_BOOLEAN:
case GI_TYPE_TAG_UNICHAR:
- return_value->v_uint32 = (guint32) value->rv_ffi_arg;
-
+ arg->v_uint32 = (guint32) ffi_value->v_ulong;
break;
case GI_TYPE_TAG_INT64:
- return_value->v_int64 = (gint64) value->rv_s64;
+ arg->v_int64 = (gint64) ffi_value->v_int64;
break;
case GI_TYPE_TAG_UINT64:
- return_value->v_uint64 = (guint64) value->rv_u64;
+ arg->v_uint64 = (guint64) ffi_value->v_uint64;
break;
case GI_TYPE_TAG_FLOAT:
- return_value->v_float = value->rv_float;
+ arg->v_float = ffi_value->v_float;
break;
case GI_TYPE_TAG_DOUBLE:
- return_value->v_double = value->rv_double;
+ arg->v_double = ffi_value->v_double;
break;
case GI_TYPE_TAG_INTERFACE:
{
@@ -603,10 +597,10 @@ set_gargument_from_ffi_return_value (GITypeInfo *return_info,
switch(interface_type) {
case GI_INFO_TYPE_ENUM:
case GI_INFO_TYPE_FLAGS:
- return_value->v_int32 = (gint32) value->rv_ffi_sarg;
+ arg->v_int32 = (gint32) ffi_value->v_long;
break;
default:
- return_value->v_pointer = (gpointer) value->rv_ffi_arg;
+ arg->v_pointer = (gpointer) ffi_value->v_ulong;
break;
}
@@ -614,7 +608,7 @@ set_gargument_from_ffi_return_value (GITypeInfo *return_info,
}
break;
default:
- return_value->v_pointer = (gpointer) value->rv_ffi_arg;
+ arg->v_pointer = (gpointer) ffi_value->v_ulong;
break;
}
}
@@ -643,7 +637,7 @@ gjs_invoke_c_function(JSContext *context,
GArgument *out_arg_cvalues;
GArgument *inout_original_arg_cvalues;
gpointer *ffi_arg_pointers;
- union GjsFFIReturnValue return_value;
+ GjsFFIReturnValue return_value;
gpointer return_value_p; /* Will point inside the union return_value */
GArgument return_gargument;
@@ -996,13 +990,13 @@ gjs_invoke_c_function(JSContext *context,
/* See comment for GjsFFIReturnValue above */
if (return_tag == GI_TYPE_TAG_FLOAT)
- return_value_p = &return_value.rv_float;
+ return_value_p = &return_value.v_float;
else if (return_tag == GI_TYPE_TAG_DOUBLE)
- return_value_p = &return_value.rv_double;
+ return_value_p = &return_value.v_double;
else if (return_tag == GI_TYPE_TAG_INT64 || return_tag == GI_TYPE_TAG_UINT64)
- return_value_p = &return_value.rv_u64;
+ return_value_p = &return_value.v_uint64;
else
- return_value_p = &return_value.rv_ffi_arg;
+ return_value_p = &return_value.v_long;
ffi_call(&(function->invoker.cif), function->invoker.native_address, return_value_p, ffi_arg_pointers);
gjs_runtime_pop_context(JS_GetRuntime(context));
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]