fix generation of unresolvable 'memset' for classes without strings.
authorRaffaele Sandrini <rasa@gmx.ch>
Thu, 22 Mar 2007 09:57:14 +0000 (09:57 +0000)
committerRaffaele Sandrini <rasa@src.gnome.org>
Thu, 22 Mar 2007 09:57:14 +0000 (09:57 +0000)
2007-03-22  Raffaele Sandrini  <rasa@gmx.ch>

* vala/valacodegenerator.vala: fix generation of unresolvable 'memset'
  for classes without strings.

svn path=/trunk/; revision=262

vala/ChangeLog
vala/vala/valacodegenerator.vala

index 4ab151d..fbf361d 100644 (file)
@@ -1,3 +1,8 @@
+2007-03-22  Raffaele Sandrini  <rasa@gmx.ch>
+
+       * vala/valacodegenerator.vala: fix generation of unresolvable 'memset'
+         for classes without strings.
+
 2007-03-21  Raffaele Sandrini  <rasa@gmx.ch>
 
        * vapi/pango.vala: add Pango.Cairo and Pango.CairoFontMap
index 3cbdf02..841e377 100644 (file)
@@ -94,6 +94,8 @@ public class Vala.CodeGenerator : CodeVisitor {
 
        private bool in_plugin = false;
        private string module_init_param_name;
+       
+       private bool string_h_needed;
 
        public CodeGenerator (bool manage_memory = true) {
                memory_management = manage_memory;
@@ -225,6 +227,8 @@ public class Vala.CodeGenerator : CodeVisitor {
                
                next_temp_var_id = 0;
                
+               string_h_needed = false;
+               
                header_begin.append (new CCodeIncludeDirective ("glib.h"));
                header_begin.append (new CCodeIncludeDirective ("glib-object.h"));
                source_include_directives.append (new CCodeIncludeDirective (source_file.get_cheader_filename (), true));
@@ -308,6 +312,10 @@ public class Vala.CodeGenerator : CodeVisitor {
        public override void visit_end_source_file (SourceFile! source_file) {
                var header_define = get_define_for_filename (source_file.get_cheader_filename ());
                
+               if (string_h_needed) {
+                       source_include_directives.append (new CCodeIncludeDirective ("string.h"));
+               }
+               
                CCodeComment comment = null;
                if (source_file.comment != null) {
                        comment = new CCodeComment (source_file.comment);
@@ -2030,6 +2038,9 @@ public class Vala.CodeGenerator : CodeVisitor {
                        if (decl.initializer == null && decl.type_reference.data_type is Struct) {
                                var st = (Struct) decl.type_reference.data_type;
                                if (!st.is_reference_type () && st.get_fields ().length () > 0) {
+                                       /* memset needs string.h */
+                                       string_h_needed = true;
+                                       
                                        var czero = new CCodeFunctionCall (new CCodeIdentifier ("memset"));
                                        czero.add_argument (new CCodeUnaryExpression (CCodeUnaryOperator.ADDRESS_OF, new CCodeIdentifier (decl.name)));
                                        czero.add_argument (new CCodeConstant ("0"));