From: Rico Tzschichholz Date: Wed, 21 Nov 2018 16:14:03 +0000 (+0100) Subject: codegen: Add required headers for ctor/dtor of compact classes and structs X-Git-Tag: 0.43.1~59 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=d7da53a0b32fbb83a959ae09a7c8f505265a05f7;p=thirdparty%2Fvala.git codegen: Add required headers for ctor/dtor of compact classes and structs --- diff --git a/codegen/valaccodemethodmodule.vala b/codegen/valaccodemethodmodule.vala index 6bf75b3a9..19d03dce0 100644 --- a/codegen/valaccodemethodmodule.vala +++ b/codegen/valaccodemethodmodule.vala @@ -651,6 +651,8 @@ public abstract class Vala.CCodeMethodModule : CCodeStructModule { if (!((CreationMethod) m).chain_up) { // TODO implicitly chain up to base class as in add_object_creation + // g_slice_new0 needs glib.h + cfile.add_include ("glib.h"); var ccall = new CCodeFunctionCall (new CCodeIdentifier ("g_slice_new0")); ccall.add_argument (new CCodeIdentifier (get_ccode_name (cl))); ccode.add_assignment (get_this_cexpression (), ccall); diff --git a/codegen/valaccodestructmodule.vala b/codegen/valaccodestructmodule.vala index cfa9ef906..0e155f74d 100644 --- a/codegen/valaccodestructmodule.vala +++ b/codegen/valaccodestructmodule.vala @@ -215,11 +215,15 @@ public abstract class Vala.CCodeStructModule : CCodeBaseModule { ccode.add_declaration (get_ccode_name (st) + "*", new CCodeVariableDeclarator ("dup")); if (context.profile == Profile.GOBJECT) { + // g_new0 needs glib.h + cfile.add_include ("glib.h"); var creation_call = new CCodeFunctionCall (new CCodeIdentifier ("g_new0")); creation_call.add_argument (new CCodeConstant (get_ccode_name (st))); creation_call.add_argument (new CCodeConstant ("1")); ccode.add_assignment (new CCodeIdentifier ("dup"), creation_call); } else if (context.profile == Profile.POSIX) { + // calloc needs stdlib.h + cfile.add_include ("stdlib.h"); var creation_call = new CCodeFunctionCall (new CCodeIdentifier ("calloc")); creation_call.add_argument (new CCodeConstant ("1")); creation_call.add_argument (new CCodeIdentifier ("sizeof (%s*)".printf (get_ccode_name (st)))); @@ -270,10 +274,14 @@ public abstract class Vala.CCodeStructModule : CCodeBaseModule { } if (context.profile == Profile.GOBJECT) { + // g_free needs glib.h + cfile.add_include ("glib.h"); var free_call = new CCodeFunctionCall (new CCodeIdentifier ("g_free")); free_call.add_argument (new CCodeIdentifier ("self")); ccode.add_expression (free_call); } else if (context.profile == Profile.POSIX) { + // free needs stdlib.h + cfile.add_include ("stdlib.h"); var free_call = new CCodeFunctionCall (new CCodeIdentifier ("free")); free_call.add_argument (new CCodeIdentifier ("self")); ccode.add_expression (free_call); diff --git a/codegen/valagtypemodule.vala b/codegen/valagtypemodule.vala index 32e7bf07c..3ce231702 100644 --- a/codegen/valagtypemodule.vala +++ b/codegen/valagtypemodule.vala @@ -1854,6 +1854,8 @@ public class Vala.GTypeModule : GErrorModule { cfile.add_function_declaration (instance_finalize_context.ccode); cfile.add_function (instance_finalize_context.ccode); } else if (cl.base_class == null) { + // g_slice_free needs glib.h + cfile.add_include ("glib.h"); var ccall = new CCodeFunctionCall (new CCodeIdentifier ("g_slice_free")); ccall.add_argument (new CCodeIdentifier (get_ccode_name (cl))); ccall.add_argument (new CCodeIdentifier ("self"));