[vala/staging] codegen: Add required includes or generate used symbols (POSIX)



commit b8ca0d9d2fddacda3f60453aa4610dc0b88a0739
Author: Rico Tzschichholz <ricotz ubuntu com>
Date:   Sat Oct 19 15:12:55 2019 +0200

    codegen: Add required includes or generate used symbols (POSIX)

 codegen/valaccodearraymodule.vala      | 6 ++++++
 codegen/valaccodebasemodule.vala       | 6 ++++++
 codegen/valaccodemethodcallmodule.vala | 4 ++++
 3 files changed, 16 insertions(+)
---
diff --git a/codegen/valaccodearraymodule.vala b/codegen/valaccodearraymodule.vala
index f8228b8cd..607deda3c 100644
--- a/codegen/valaccodearraymodule.vala
+++ b/codegen/valaccodearraymodule.vala
@@ -245,6 +245,7 @@ public class Vala.CCodeArrayModule : CCodeMethodCallModule {
 
                CCodeFunctionCall carrfree;
                if (context.profile == Profile.POSIX) {
+                       cfile.add_include ("stdlib.h");
                        carrfree = new CCodeFunctionCall (new CCodeIdentifier ("free"));
                } else {
                        carrfree = new CCodeFunctionCall (new CCodeIdentifier ("g_free"));
@@ -281,6 +282,7 @@ public class Vala.CCodeArrayModule : CCodeMethodCallModule {
 
        public override void append_vala_array_free () {
                // _vala_array_destroy only frees elements but not the array itself
+               generate_type_declaration (delegate_target_destroy_type, cfile);
 
                var fun = new CCodeFunction ("_vala_array_destroy", "void");
                fun.modifiers = CCodeModifiers.STATIC;
@@ -323,6 +325,7 @@ public class Vala.CCodeArrayModule : CCodeMethodCallModule {
 
                CCodeFunctionCall carrfree;
                if (context.profile == Profile.POSIX) {
+                       cfile.add_include ("stdlib.h");
                        carrfree = new CCodeFunctionCall (new CCodeIdentifier ("free"));
                } else {
                        carrfree = new CCodeFunctionCall (new CCodeIdentifier ("g_free"));
@@ -476,6 +479,7 @@ public class Vala.CCodeArrayModule : CCodeMethodCallModule {
                        }
 
                        requires_array_free = true;
+                       generate_type_declaration (delegate_target_destroy_type, cfile);
 
                        var ccall = new CCodeFunctionCall (get_destroy_func_expression (type));
 
@@ -561,6 +565,8 @@ public class Vala.CCodeArrayModule : CCodeMethodCallModule {
 
                        if (context.profile == Profile.POSIX) {
                                cfile.add_include ("stdlib.h");
+                               cfile.add_include ("string.h");
+
                                var alloc = new CCodeFunctionCall (new CCodeIdentifier ("calloc"));
                                alloc.add_argument (length_expr);
                                alloc.add_argument (sizeof_call);
diff --git a/codegen/valaccodebasemodule.vala b/codegen/valaccodebasemodule.vala
index a80dfaf6f..849e3ac2b 100644
--- a/codegen/valaccodebasemodule.vala
+++ b/codegen/valaccodebasemodule.vala
@@ -3212,6 +3212,7 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator {
 
                        CCodeFunctionCall free_call;
                        if (context.profile == Profile.POSIX) {
+                               cfile.add_include ("stdlib.h");
                                free_call = new CCodeFunctionCall (new CCodeIdentifier ("free"));
                        } else {
                                free_call = new CCodeFunctionCall (new CCodeIdentifier ("g_free"));
@@ -3324,6 +3325,7 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator {
                                                        unref_function = generate_free_func_wrapper (type);
                                                } else {
                                                        if (context.profile == Profile.POSIX) {
+                                                               cfile.add_include ("stdlib.h");
                                                                unref_function = "free";
                                                        } else {
                                                                unref_function = "g_free";
@@ -3371,12 +3373,14 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator {
                        }
                } else if (type is ArrayType) {
                        if (context.profile == Profile.POSIX) {
+                               cfile.add_include ("stdlib.h");
                                return new CCodeIdentifier ("free");
                        } else {
                                return new CCodeIdentifier ("g_free");
                        }
                } else if (type is PointerType) {
                        if (context.profile == Profile.POSIX) {
+                               cfile.add_include ("stdlib.h");
                                return new CCodeIdentifier ("free");
                        } else {
                                return new CCodeIdentifier ("g_free");
@@ -3664,6 +3668,8 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator {
                                                ccall.add_argument (csizeexpr);
                                        } else {
                                                requires_array_free = true;
+                                               generate_type_declaration (delegate_target_destroy_type, 
cfile);
+
                                                ccall.call = new CCodeIdentifier ("_vala_array_free");
                                                ccall.add_argument (csizeexpr);
                                                ccall.add_argument (new CCodeCastExpression 
(get_destroy_func_expression (array_type.element_type), get_ccode_name (delegate_target_destroy_type)));
diff --git a/codegen/valaccodemethodcallmodule.vala b/codegen/valaccodemethodcallmodule.vala
index 5d28ee365..1fa3aebb2 100644
--- a/codegen/valaccodemethodcallmodule.vala
+++ b/codegen/valaccodemethodcallmodule.vala
@@ -991,6 +991,10 @@ public class Vala.CCodeMethodCallModule : CCodeAssignmentModule {
 
                ccode.add_expression (va_start);
 
+               if (context.profile == Profile.POSIX) {
+                       cfile.add_include ("stdio.h");
+               }
+
                var vsnprintf = new CCodeFunctionCall (new CCodeIdentifier ("vsnprintf"));
                vsnprintf.add_argument (new CCodeConstant ("NULL"));
                vsnprintf.add_argument (new CCodeConstant ("0"));


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