[vala] D-Bus: Avoid invalid C code when using reserved names as parameters
- From: Jürg Billeter <juergbi src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [vala] D-Bus: Avoid invalid C code when using reserved names as parameters
- Date: Sun, 3 Apr 2011 15:08:50 +0000 (UTC)
commit 5c1be07f25c27d8ad9e9451826ece43460fa3aee
Author: Marco Trevisan (Treviño) <mail 3v1n0 net>
Date: Thu Mar 3 03:39:55 2011 +0100
D-Bus: Avoid invalid C code when using reserved names as parameters
Fixes bug 643744.
codegen/valagdbusclientmodule.vala | 13 +++++++------
codegen/valagdbusservermodule.vala | 22 +++++++++++++---------
2 files changed, 20 insertions(+), 15 deletions(-)
---
diff --git a/codegen/valagdbusclientmodule.vala b/codegen/valagdbusclientmodule.vala
index d33b320..1d6edad 100644
--- a/codegen/valagdbusclientmodule.vala
+++ b/codegen/valagdbusclientmodule.vala
@@ -368,16 +368,17 @@ public class Vala.GDBusClientModule : GDBusModule {
ccall.add_argument (sig.get_canonical_cconstant ());
foreach (Parameter param in sig.get_parameters ()) {
+ var param_name = get_variable_cname (param.name);
var owned_type = param.variable_type.copy ();
owned_type.value_owned = true;
- ccode.add_declaration (owned_type.get_cname (), new CCodeVariableDeclarator.zero (param.name, default_value_for_type (param.variable_type, true)));
+ ccode.add_declaration (owned_type.get_cname (), new CCodeVariableDeclarator.zero (param_name, default_value_for_type (param.variable_type, true)));
var st = param.variable_type.data_type as Struct;
if (st != null && !st.is_simple_type ()) {
- ccall.add_argument (new CCodeUnaryExpression (CCodeUnaryOperator.ADDRESS_OF, new CCodeIdentifier (param.name)));
+ ccall.add_argument (new CCodeUnaryExpression (CCodeUnaryOperator.ADDRESS_OF, new CCodeIdentifier (param_name)));
} else {
- ccall.add_argument (new CCodeIdentifier (param.name));
+ ccall.add_argument (new CCodeIdentifier (param_name));
}
if (param.variable_type is ArrayType) {
@@ -391,7 +392,7 @@ public class Vala.GDBusClientModule : GDBusModule {
}
}
- read_expression (param.variable_type, new CCodeIdentifier ("_arguments_iter"), new CCodeIdentifier (param.name), param);
+ read_expression (param.variable_type, new CCodeIdentifier ("_arguments_iter"), new CCodeIdentifier (param_name), param);
}
ccode.add_expression (ccall);
@@ -527,7 +528,7 @@ public class Vala.GDBusClientModule : GDBusModule {
foreach (Parameter param in m.get_parameters ()) {
if (param.direction == ParameterDirection.IN) {
- CCodeExpression expr = new CCodeIdentifier (param.name);
+ CCodeExpression expr = new CCodeIdentifier (get_variable_cname (param.name));
if (param.variable_type.is_real_struct_type ()) {
expr = new CCodeUnaryExpression (CCodeUnaryOperator.POINTER_INDIRECTION, expr);
}
@@ -694,7 +695,7 @@ public class Vala.GDBusClientModule : GDBusModule {
// TODO check that parameter is not NULL (out parameters are optional)
// free value if parameter is NULL
- ccode.add_assignment (new CCodeUnaryExpression (CCodeUnaryOperator.POINTER_INDIRECTION, new CCodeIdentifier (param.name)), target);
+ ccode.add_assignment (new CCodeUnaryExpression (CCodeUnaryOperator.POINTER_INDIRECTION, new CCodeIdentifier (get_variable_cname (param.name))), target);
if (array_type != null) {
for (int dim = 1; dim <= array_type.rank; dim++) {
diff --git a/codegen/valagdbusservermodule.vala b/codegen/valagdbusservermodule.vala
index a0642ff..75a2dc8 100644
--- a/codegen/valagdbusservermodule.vala
+++ b/codegen/valagdbusservermodule.vala
@@ -119,6 +119,7 @@ public class Vala.GDBusServerModule : GDBusClientModule {
}
foreach (Parameter param in m.get_parameters ()) {
+ string param_name = get_variable_cname (param.name);
if (param.direction != ParameterDirection.IN) {
continue;
}
@@ -135,7 +136,7 @@ public class Vala.GDBusServerModule : GDBusClientModule {
var owned_type = param.variable_type.copy ();
owned_type.value_owned = true;
- ccode.add_declaration (owned_type.get_cname (), new CCodeVariableDeclarator.zero (param.name, default_value_for_type (param.variable_type, true)));
+ ccode.add_declaration (owned_type.get_cname (), new CCodeVariableDeclarator.zero (param_name, default_value_for_type (param.variable_type, true)));
var array_type = param.variable_type as ArrayType;
if (array_type != null) {
@@ -150,7 +151,7 @@ public class Vala.GDBusServerModule : GDBusClientModule {
message_expr.add_argument (new CCodeIdentifier ("invocation"));
bool may_fail;
- receive_dbus_value (param.variable_type, message_expr, new CCodeIdentifier ("_arguments_iter"), new CCodeIdentifier (param.name), param, new CCodeUnaryExpression (CCodeUnaryOperator.ADDRESS_OF, new CCodeIdentifier ("error")), out may_fail);
+ receive_dbus_value (param.variable_type, message_expr, new CCodeIdentifier ("_arguments_iter"), new CCodeIdentifier (param_name), param, new CCodeUnaryExpression (CCodeUnaryOperator.ADDRESS_OF, new CCodeIdentifier ("error")), out may_fail);
if (may_fail) {
if (!uses_error) {
@@ -173,6 +174,7 @@ public class Vala.GDBusServerModule : GDBusClientModule {
}
foreach (Parameter param in m.get_parameters ()) {
+ string param_name = get_variable_cname (param.name);
if (param.direction == ParameterDirection.IN && !ready) {
if (param.variable_type is ObjectType && param.variable_type.data_type.get_full_name () == "GLib.Cancellable") {
ccall.add_argument (new CCodeConstant ("NULL"));
@@ -189,12 +191,12 @@ public class Vala.GDBusServerModule : GDBusClientModule {
var st = param.variable_type.data_type as Struct;
if (st != null && !st.is_simple_type ()) {
- ccall.add_argument (new CCodeUnaryExpression (CCodeUnaryOperator.ADDRESS_OF, new CCodeIdentifier (param.name)));
+ ccall.add_argument (new CCodeUnaryExpression (CCodeUnaryOperator.ADDRESS_OF, new CCodeIdentifier (param_name)));
} else {
- ccall.add_argument (new CCodeIdentifier (param.name));
+ ccall.add_argument (new CCodeIdentifier (param_name));
}
} else if (param.direction == ParameterDirection.OUT && (!m.coroutine || ready)) {
- ccall.add_argument (new CCodeUnaryExpression (CCodeUnaryOperator.ADDRESS_OF, new CCodeIdentifier (param.name)));
+ ccall.add_argument (new CCodeUnaryExpression (CCodeUnaryOperator.ADDRESS_OF, new CCodeIdentifier (param_name)));
}
var array_type = param.variable_type as ArrayType;
@@ -286,10 +288,11 @@ public class Vala.GDBusServerModule : GDBusClientModule {
continue;
}
+ string param_name = get_variable_cname (param.name);
var owned_type = param.variable_type.copy ();
owned_type.value_owned = true;
- ccode.add_declaration (owned_type.get_cname (), new CCodeVariableDeclarator.zero (param.name, default_value_for_type (param.variable_type, true)));
+ ccode.add_declaration (owned_type.get_cname (), new CCodeVariableDeclarator.zero (param_name, default_value_for_type (param.variable_type, true)));
var array_type = param.variable_type as ArrayType;
if (array_type != null) {
@@ -300,7 +303,7 @@ public class Vala.GDBusServerModule : GDBusClientModule {
}
}
- send_dbus_value (param.variable_type, new CCodeIdentifier ("_reply_builder"), new CCodeIdentifier (param.name), param);
+ send_dbus_value (param.variable_type, new CCodeIdentifier ("_reply_builder"), new CCodeIdentifier (param_name), param);
}
if (!(m.return_type is VoidType)) {
@@ -388,7 +391,7 @@ public class Vala.GDBusServerModule : GDBusClientModule {
if (requires_destroy (owned_type)) {
// keep local alive (symbol_reference is weak)
- var local = new LocalVariable (owned_type, param.name);
+ var local = new LocalVariable (owned_type, get_variable_cname (param.name));
ccode.add_expression (destroy_local (local));
}
}
@@ -462,7 +465,8 @@ public class Vala.GDBusServerModule : GDBusClientModule {
ccode.add_expression (builder_init);
foreach (Parameter param in sig.get_parameters ()) {
- CCodeExpression expr = new CCodeIdentifier (param.name);
+ string param_name = get_variable_cname (param.name);
+ CCodeExpression expr = new CCodeIdentifier (param_name);
if (param.variable_type.is_real_struct_type ()) {
expr = new CCodeUnaryExpression (CCodeUnaryOperator.POINTER_INDIRECTION, expr);
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]