[vala/staging] codegen: Use given dup_function for structs



commit 3ee698c6e35ee3b05fdcd1aa846cb8cb4a39c0a6
Author: Rico Tzschichholz <ricotz ubuntu com>
Date:   Tue Aug 22 15:31:54 2017 +0200

    codegen: Use given dup_function for structs

 codegen/valaccodeattribute.vala  |   17 +++++++++++++++++
 codegen/valaccodebasemodule.vala |    6 +-----
 2 files changed, 18 insertions(+), 5 deletions(-)
---
diff --git a/codegen/valaccodeattribute.vala b/codegen/valaccodeattribute.vala
index d3a97d5..815ec11 100644
--- a/codegen/valaccodeattribute.vala
+++ b/codegen/valaccodeattribute.vala
@@ -222,6 +222,21 @@ public class Vala.CCodeAttribute : AttributeCache {
                }
        }
 
+       public string dup_function {
+               get {
+                       if (!dup_function_set) {
+                               if (ccode != null) {
+                                       _dup_function = ccode.get_string ("dup_function");
+                               }
+                               if (_dup_function == null && !sym.external_package && sym is Struct) {
+                                       _dup_function = "%sdup".printf (lower_case_prefix);
+                               }
+                               dup_function_set = true;
+                       }
+                       return _dup_function;
+               }
+       }
+
        public string free_function {
                get {
                        if (!free_function_set) {
@@ -541,6 +556,8 @@ public class Vala.CCodeAttribute : AttributeCache {
        private bool copy_function_set;
        private string? _destroy_function;
        private bool destroy_function_set;
+       private string? _dup_function;
+       private bool dup_function_set;
        private string? _free_function;
        private bool free_function_set;
        private bool? _free_function_address_of;
diff --git a/codegen/valaccodebasemodule.vala b/codegen/valaccodebasemodule.vala
index 1d0610c..cd5ae3d 100644
--- a/codegen/valaccodebasemodule.vala
+++ b/codegen/valaccodebasemodule.vala
@@ -6240,11 +6240,7 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator {
 
        public static string? get_ccode_dup_function (TypeSymbol sym) {
                if (sym is Struct) {
-                       if (sym.external_package) {
-                               return null;
-                       } else {
-                               return get_ccode_lower_case_prefix (sym) + "dup";
-                       }
+                       return get_ccode_attribute (sym).dup_function;
                }
                return get_ccode_copy_function (sym);
        }


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