[vala] Ensure string.h is included when using memcpy
- From: Jürg Billeter <juergbi src gnome org>
- To: svn-commits-list gnome org
- Subject: [vala] Ensure string.h is included when using memcpy
- Date: Sun, 12 Apr 2009 15:30:29 -0400 (EDT)
commit 4efa763474fce46a7f3b8136a6199bd7a0fb6371
Author: Jürg Billeter <j bitron ch>
Date: Sun Apr 12 21:29:32 2009 +0200
Ensure string.h is included when using memcpy
---
gobject/valaccodearraymodule.vala | 4 +++-
gobject/valaccodeassignmentmodule.vala | 2 ++
gobject/valaccodebasemodule.vala | 12 +++++-------
gobject/valaccodemethodcallmodule.vala | 2 +-
gobject/valaccodemethodmodule.vala | 2 +-
gobject/valaccodestructmodule.vala | 4 ++++
gobject/valadbusclientmodule.vala | 2 ++
7 files changed, 18 insertions(+), 10 deletions(-)
diff --git a/gobject/valaccodearraymodule.vala b/gobject/valaccodearraymodule.vala
index 2143f3f..72499af 100644
--- a/gobject/valaccodearraymodule.vala
+++ b/gobject/valaccodearraymodule.vala
@@ -446,7 +446,7 @@ internal class Vala.CCodeArrayModule : CCodeMethodCallModule {
}
public override void append_vala_array_move () {
- string_h_needed = true;
+ source_declarations.add_include ("string.h");
// assumes that overwritten array elements are null before invocation
// FIXME will leak memory if that's not the case
@@ -702,6 +702,8 @@ internal class Vala.CCodeArrayModule : CCodeMethodCallModule {
block.add_statement (cfrag);
temp_vars = old_temp_vars;
} else {
+ source_declarations.add_include ("string.h");
+
var dup_call = new CCodeFunctionCall (new CCodeIdentifier ("memcpy"));
dup_call.add_argument (new CCodeIdentifier ("dest"));
dup_call.add_argument (new CCodeIdentifier ("self"));
diff --git a/gobject/valaccodeassignmentmodule.vala b/gobject/valaccodeassignmentmodule.vala
index 4470628..a948a94 100644
--- a/gobject/valaccodeassignmentmodule.vala
+++ b/gobject/valaccodeassignmentmodule.vala
@@ -212,6 +212,8 @@ internal class Vala.CCodeAssignmentModule : CCodeMemberAccessModule {
CCodeExpression rhs = (CCodeExpression) assignment.right.ccodenode;
CCodeExpression lhs = (CCodeExpression) get_ccodenode (assignment.left);
+ source_declarations.add_include ("string.h");
+
// it is necessary to use memcpy for fixed-length (stack-allocated) arrays
// simple assignments do not work in C
var sizeof_call = new CCodeFunctionCall (new CCodeIdentifier ("sizeof"));
diff --git a/gobject/valaccodebasemodule.vala b/gobject/valaccodebasemodule.vala
index b5d9c30..d2d0afd 100644
--- a/gobject/valaccodebasemodule.vala
+++ b/gobject/valaccodebasemodule.vala
@@ -120,7 +120,6 @@ internal class Vala.CCodeBaseModule : CCodeModule {
public bool in_plugin = false;
public string module_init_param_name;
- public bool string_h_needed;
public bool gvaluecollector_h_needed;
public bool gio_h_needed;
public bool requires_array_free;
@@ -407,7 +406,6 @@ internal class Vala.CCodeBaseModule : CCodeModule {
next_temp_var_id = 0;
variable_name_map.clear ();
- string_h_needed = false;
gvaluecollector_h_needed = false;
gio_h_needed = false;
dbus_glib_h_needed = false;
@@ -443,10 +441,6 @@ internal class Vala.CCodeBaseModule : CCodeModule {
if (requires_strcmp0) {
append_vala_strcmp0 ();
}
-
- if (string_h_needed) {
- source_declarations.add_include ("string.h");
- }
if (gvaluecollector_h_needed) {
source_declarations.add_include ("gobject/gvaluecollector.h");
@@ -1609,6 +1603,8 @@ internal class Vala.CCodeBaseModule : CCodeModule {
var array_type = (ArrayType) local.variable_type;
if (array_type.fixed_length) {
+ source_declarations.add_include ("string.h");
+
// it is necessary to use memcpy for fixed-length (stack-allocated) arrays
// simple assignments do not work in C
var sizeof_call = new CCodeFunctionCall (new CCodeIdentifier ("sizeof"));
@@ -1787,6 +1783,8 @@ internal class Vala.CCodeBaseModule : CCodeModule {
copy_call.add_argument (new CCodeIdentifier ("dup"));
block.add_statement (new CCodeExpressionStatement (copy_call));
} else {
+ source_declarations.add_include ("string.h");
+
var sizeof_call = new CCodeFunctionCall (new CCodeIdentifier ("sizeof"));
sizeof_call.add_argument (new CCodeConstant (value_type.data_type.get_cname ()));
@@ -2867,7 +2865,7 @@ internal class Vala.CCodeBaseModule : CCodeModule {
creation_call.add_argument (new CCodeConstant ("1"));
} else if (expr.type_reference.data_type is Struct) {
// memset needs string.h
- string_h_needed = true;
+ source_declarations.add_include ("string.h");
creation_call = new CCodeFunctionCall (new CCodeIdentifier ("memset"));
creation_call.add_argument (new CCodeUnaryExpression (CCodeUnaryOperator.ADDRESS_OF, instance));
creation_call.add_argument (new CCodeConstant ("0"));
diff --git a/gobject/valaccodemethodcallmodule.vala b/gobject/valaccodemethodcallmodule.vala
index 4341b1a..adb0106 100644
--- a/gobject/valaccodemethodcallmodule.vala
+++ b/gobject/valaccodemethodcallmodule.vala
@@ -595,7 +595,7 @@ internal class Vala.CCodeMethodCallModule : CCodeAssignmentModule {
temp_vars.insert (0, temp_decl);
/* memset needs string.h */
- string_h_needed = true;
+ source_declarations.add_include ("string.h");
var clen = head.get_array_length_cexpression (ma.inner, 1);
var celems = (CCodeExpression) ma.inner.ccodenode;
diff --git a/gobject/valaccodemethodmodule.vala b/gobject/valaccodemethodmodule.vala
index 8e235a4..67dc2f7 100644
--- a/gobject/valaccodemethodmodule.vala
+++ b/gobject/valaccodemethodmodule.vala
@@ -532,7 +532,7 @@ internal class Vala.CCodeMethodModule : CCodeStructModule {
var st = (Struct) m.parent_symbol;
// memset needs string.h
- string_h_needed = true;
+ source_declarations.add_include ("string.h");
var czero = new CCodeFunctionCall (new CCodeIdentifier ("memset"));
czero.add_argument (new CCodeIdentifier ("self"));
czero.add_argument (new CCodeConstant ("0"));
diff --git a/gobject/valaccodestructmodule.vala b/gobject/valaccodestructmodule.vala
index b45578c..d1cfe5e 100644
--- a/gobject/valaccodestructmodule.vala
+++ b/gobject/valaccodestructmodule.vala
@@ -133,6 +133,8 @@ internal class Vala.CCodeStructModule : CCodeBaseModule {
copy_call.add_argument (new CCodeIdentifier ("dup"));
cblock.add_statement (new CCodeExpressionStatement (copy_call));
} else {
+ source_declarations.add_include ("string.h");
+
var sizeof_call = new CCodeFunctionCall (new CCodeIdentifier ("sizeof"));
sizeof_call.add_argument (new CCodeConstant (st.get_cname ()));
@@ -208,6 +210,8 @@ internal class Vala.CCodeStructModule : CCodeBaseModule {
var array_type = f.field_type as ArrayType;
if (array_type != null && array_type.fixed_length) {
// fixed-length (stack-allocated) arrays
+ source_declarations.add_include ("string.h");
+
var sizeof_call = new CCodeFunctionCall (new CCodeIdentifier ("sizeof"));
sizeof_call.add_argument (new CCodeIdentifier (array_type.element_type.get_cname ()));
var size = new CCodeBinaryExpression (CCodeBinaryOperator.MUL, new CCodeConstant ("%d".printf (array_type.length)), sizeof_call);
diff --git a/gobject/valadbusclientmodule.vala b/gobject/valadbusclientmodule.vala
index 97dd8e3..dc3520b 100644
--- a/gobject/valadbusclientmodule.vala
+++ b/gobject/valadbusclientmodule.vala
@@ -235,6 +235,8 @@ internal class Vala.DBusClientModule : DBusModule {
block.add_statement (cdecl);
if (dbus_use_ptr_array (array_type)) {
+ source_declarations.add_include ("string.h");
+
var memcpy_call = new CCodeFunctionCall (new CCodeIdentifier ("memcpy"));
memcpy_call.add_argument (new CCodeMemberAccess.pointer (new CCodeIdentifier ("dbus_%s".printf (param.name)), "pdata"));
memcpy_call.add_argument (new CCodeIdentifier (param.name));
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]