Commit 4efa7634 authored by Jürg Billeter's avatar Jürg Billeter

Ensure string.h is included when using memcpy

parent 04ef3b8f
......@@ -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"));
......
......@@ -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"));
......
......@@ -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"));
......
......@@ -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;
......
......@@ -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"));
......
......@@ -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);
......
......@@ -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));
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment