[gjs/wip/gobj-kitchen-sink: 9/21] arg: Don't copy boxed types
- From: Jasper St. Pierre <jstpierre src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gjs/wip/gobj-kitchen-sink: 9/21] arg: Don't copy boxed types
- Date: Fri, 27 Jan 2012 20:07:15 +0000 (UTC)
commit e0a2d0d5a72508fadd870974fa30a08775853916
Author: Jasper St. Pierre <jstpierre mecheye net>
Date: Sun Nov 6 17:58:34 2011 -0500
arg: Don't copy boxed types
In some places, an API passes a vfunc a boxed parameter and expects
the vfunc implementation to modify it. We can't copy boxed objects
in this case, as the modifications that the vfunc implementation did
won't apply to the copy.
We still need to not copy variants, as we ref them at the end of
the function.
https://bugzilla.gnome.org/show_bug.cgi?id=663492
gi/arg.c | 6 +++---
gi/function.c | 31 -------------------------------
2 files changed, 3 insertions(+), 34 deletions(-)
---
diff --git a/gi/arg.c b/gi/arg.c
index 223f610..d2612c6 100644
--- a/gi/arg.c
+++ b/gi/arg.c
@@ -2431,8 +2431,9 @@ gjs_value_from_g_argument (JSContext *context,
if (interface_type == GI_INFO_TYPE_STRUCT || interface_type == GI_INFO_TYPE_BOXED) {
JSObject *obj;
+
obj = gjs_boxed_from_c_struct(context, (GIStructInfo *)interface_info, arg->v_pointer,
- GJS_BOXED_CREATION_NONE);
+ g_type_is_a(gtype, G_TYPE_VARIANT) ? GJS_BOXED_CREATION_NONE : GJS_BOXED_CREATION_NO_COPY);
if (obj)
value = OBJECT_TO_JSVAL(obj);
@@ -2708,8 +2709,7 @@ gjs_g_arg_release_internal(JSContext *context,
/* G_TYPE_VALUE is-a G_TYPE_BOXED, but we special case it */
g_boxed_free(gtype, arg->v_pointer);
} else if (g_type_is_a(gtype, G_TYPE_BOXED)) {
- if (transfer != TRANSFER_IN_NOTHING)
- g_boxed_free(gtype, arg->v_pointer);
+ /* We don't free boxed types. */
} else if (g_type_is_a(gtype, G_TYPE_VARIANT)) {
if (transfer != TRANSFER_IN_NOTHING)
g_variant_unref (arg->v_pointer);
diff --git a/gi/function.c b/gi/function.c
index 549ae40..cc44d19 100644
--- a/gi/function.c
+++ b/gi/function.c
@@ -1101,37 +1101,6 @@ release:
if (arg_failed)
postinvoke_release_failed = TRUE;
- /* For caller-allocates, what happens here is we allocate
- * a structure above, then gjs_value_from_g_argument calls
- * g_boxed_copy on it, and takes ownership of that. So
- * here we release the memory allocated above. It would be
- * better to special case this and directly hand JS the boxed
- * object and tell gjs_boxed it owns the memory, but for now
- * this works OK. We could also alloca() the structure instead
- * of slice allocating.
- */
- if (g_arg_info_is_caller_allocates(&arg_info)) {
- GITypeTag type_tag;
- GIBaseInfo* interface_info;
- GIInfoType interface_type;
- gsize size;
-
- type_tag = g_type_info_get_tag(&arg_type_info);
- g_assert(type_tag == GI_TYPE_TAG_INTERFACE);
- interface_info = g_type_info_get_interface(&arg_type_info);
- interface_type = g_base_info_get_type(interface_info);
- if (interface_type == GI_INFO_TYPE_STRUCT) {
- size = g_struct_info_get_size((GIStructInfo*)interface_info);
- } else if (interface_type == GI_INFO_TYPE_UNION) {
- size = g_union_info_get_size((GIUnionInfo*)interface_info);
- } else {
- g_assert_not_reached();
- }
-
- g_slice_free1(size, out_arg_cvalues[c_arg_pos].v_pointer);
- g_base_info_unref((GIBaseInfo*)interface_info);
- }
-
/* Free GArgument, the jsval should have ref'd or copied it */
transfer = g_arg_info_get_ownership_transfer(&arg_info);
if (!arg_failed) {
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]