[gobject-introspection] scanner: Only mark structures and unions as out-caller-allocates



commit 1113955bb6a5276c21771685dd30c51f9ef1661f
Author: Colin Walters <walters verbum org>
Date:   Fri Nov 19 16:59:02 2010 -0500

    scanner: Only mark structures and unions as out-caller-allocates
    
    These are the only things for which we expect native values to be
    preserved; for e.g. flags and integers, we expect bindings to convert.
    
    The particular rationale for this patch is to avoid flagging flags (sic)
    as (out caller-allocates).

 giscanner/maintransformer.py           |    5 ++++-
 tests/scanner/Regress-1.0-expected.gir |   15 +++++++++++++++
 tests/scanner/regress.c                |   11 +++++++++++
 tests/scanner/regress.h                |    2 ++
 4 files changed, 32 insertions(+), 1 deletions(-)
---
diff --git a/giscanner/maintransformer.py b/giscanner/maintransformer.py
index 517ddb2..4ae5516 100644
--- a/giscanner/maintransformer.py
+++ b/giscanner/maintransformer.py
@@ -510,7 +510,10 @@ usage is void (*_gtk_reserved1)(void);"""
             annotated_direction = ast.PARAM_DIRECTION_OUT
             if subtype in (None, ''):
                 if node.type.target_giname and node.type.ctype:
-                    caller_allocates = '**' not in node.type.ctype
+                    target = self._transformer.lookup_giname(node.type.target_giname)
+                    has_double_indirection = '**' in node.type.ctype
+                    is_structure_or_union = isinstance(target, (ast.Record, ast.Union))
+                    caller_allocates = (not has_double_indirection and is_structure_or_union)
                 else:
                     caller_allocates = False
             elif subtype == OPT_OUT_CALLER_ALLOCATES:
diff --git a/tests/scanner/Regress-1.0-expected.gir b/tests/scanner/Regress-1.0-expected.gir
index 515853b..15fba0d 100644
--- a/tests/scanner/Regress-1.0-expected.gir
+++ b/tests/scanner/Regress-1.0-expected.gir
@@ -962,6 +962,21 @@ TpAccount::status-changed</doc>
         </parameter>
       </parameters>
     </function>
+    <function name="global_get_flags_out"
+              c:identifier="regress_global_get_flags_out">
+      <return-value transfer-ownership="none">
+        <type name="none" c:type="void"/>
+      </return-value>
+      <parameters>
+        <parameter name="v"
+                   direction="out"
+                   caller-allocates="0"
+                   transfer-ownership="full">
+          <doc xml:whitespace="preserve">A flags value</doc>
+          <type name="TestFlags" c:type="RegressTestFlags*"/>
+        </parameter>
+      </parameters>
+    </function>
     <function name="random_function_with_skipped_structure"
               c:identifier="regress_random_function_with_skipped_structure"
               introspectable="0">
diff --git a/tests/scanner/regress.c b/tests/scanner/regress.c
index 9f22596..cd7e91c 100644
--- a/tests/scanner/regress.c
+++ b/tests/scanner/regress.c
@@ -1301,6 +1301,17 @@ regress_test_unsigned_enum_param(RegressTestEnumUnsigned e)
   return ev->value_nick;
 }
 
+/**
+ * regress_global_get_flags_out:
+ * @v: (out): A flags value
+ *
+ */
+void
+regress_global_get_flags_out (RegressTestFlags *v)
+{
+  *v = REGRESS_TEST_FLAG1 | REGRESS_TEST_FLAG3;
+}
+
 /* structures */
 
 /**
diff --git a/tests/scanner/regress.h b/tests/scanner/regress.h
index 9b39bd3..9daf179 100644
--- a/tests/scanner/regress.h
+++ b/tests/scanner/regress.h
@@ -163,6 +163,8 @@ GType regress_test_flags_get_type (void) G_GNUC_CONST;
 const gchar * regress_test_enum_param(RegressTestEnum e);
 const gchar * regress_test_unsigned_enum_param(RegressTestEnumUnsigned e);
 
+void regress_global_get_flags_out (RegressTestFlags *v);
+
 /* constants */
 
 #define REGRESS_INT_CONSTANT 4422



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