[template-glib] gi: handle transfer for some return values



commit 01918ae798e12e91c43dc27a5517813c897fbd7f
Author: Christian Hergert <chergert redhat com>
Date:   Tue Oct 24 23:54:35 2017 -0700

    gi: handle transfer for some return values

 src/tmpl-expr-eval.c  |    4 +++-
 src/tmpl-gi-private.h |    1 +
 src/tmpl-gi.c         |   11 +++++++++--
 3 files changed, 13 insertions(+), 3 deletions(-)
---
diff --git a/src/tmpl-expr-eval.c b/src/tmpl-expr-eval.c
index 3355f26..815a698 100644
--- a/src/tmpl-expr-eval.c
+++ b/src/tmpl-expr-eval.c
@@ -669,6 +669,7 @@ tmpl_expr_gi_call_eval (TmplExprGiCall  *node,
   GIArgument return_value_arg = { 0 };
   GITypeInfo return_value_type;
   GIArgument *dispatch_args = NULL;
+  GITransfer xfer = 0;
   TmplExpr *args;
   GObject *object;
   gboolean ret = FALSE;
@@ -981,8 +982,9 @@ apply_args:
     goto cleanup;
 
   g_callable_info_load_return_type ((GICallableInfo *)function, &return_value_type);
+  xfer = g_callable_info_get_caller_owns ((GICallableInfo *)function);
 
-  if (!tmpl_gi_argument_to_g_value (return_value, &return_value_type, &return_value_arg, error))
+  if (!tmpl_gi_argument_to_g_value (return_value, &return_value_type, &return_value_arg, xfer, error))
     goto cleanup;
 
   ret = TRUE;
diff --git a/src/tmpl-gi-private.h b/src/tmpl-gi-private.h
index 7dbc311..02c95ee 100644
--- a/src/tmpl-gi-private.h
+++ b/src/tmpl-gi-private.h
@@ -33,6 +33,7 @@ gboolean tmpl_gi_argument_from_g_value (const GValue  *value,
 gboolean tmpl_gi_argument_to_g_value   (GValue        *value,
                                         GITypeInfo    *type_info,
                                         GIArgument    *arg,
+                                        GITransfer     xfer,
                                         GError       **error);
 
 G_END_DECLS
diff --git a/src/tmpl-gi.c b/src/tmpl-gi.c
index 4a5c95a..2a94f05 100644
--- a/src/tmpl-gi.c
+++ b/src/tmpl-gi.c
@@ -316,6 +316,7 @@ gboolean
 tmpl_gi_argument_to_g_value (GValue      *value,
                              GITypeInfo  *type_info,
                              GIArgument  *arg,
+                             GITransfer   xfer,
                              GError     **error)
 {
   GITypeTag tag;
@@ -395,7 +396,10 @@ tmpl_gi_argument_to_g_value (GValue      *value,
     case GI_TYPE_TAG_UTF8:
     case GI_TYPE_TAG_FILENAME:
       g_value_init (value, G_TYPE_STRING);
-      g_value_set_string (value, arg->v_string);
+      if (xfer == GI_TRANSFER_NOTHING)
+        g_value_set_string (value, arg->v_string);
+      else
+        g_value_take_string (value, arg->v_string);
       return TRUE;
 
     case GI_TYPE_TAG_INTERFACE:
@@ -408,7 +412,10 @@ tmpl_gi_argument_to_g_value (GValue      *value,
           case GI_INFO_TYPE_INTERFACE:
           case GI_INFO_TYPE_OBJECT:
             g_value_init (value, G_TYPE_OBJECT);
-            g_value_set_object (value, arg->v_pointer);
+            if (xfer == GI_TRANSFER_NOTHING)
+              g_value_set_object (value, arg->v_pointer);
+            else
+              g_value_take_object (value, arg->v_pointer);
             return TRUE;
 
           case GI_INFO_TYPE_FLAGS:


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]