[vala] GVariant: Fix critical on unsupported types
- From: Jürg Billeter <juergbi src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [vala] GVariant: Fix critical on unsupported types
- Date: Sun, 10 Oct 2010 17:08:03 +0000 (UTC)
commit edc78b36c5ae54b6512c5a9ca3ffa52c09dae159
Author: Jürg Billeter <j bitron ch>
Date: Sun Oct 10 19:06:16 2010 +0200
GVariant: Fix critical on unsupported types
codegen/valagvariantmodule.vala | 22 ++++++++++++++++++----
1 files changed, 18 insertions(+), 4 deletions(-)
---
diff --git a/codegen/valagvariantmodule.vala b/codegen/valagvariantmodule.vala
index a8a3e9e..c8196e5 100644
--- a/codegen/valagvariantmodule.vala
+++ b/codegen/valagvariantmodule.vala
@@ -379,7 +379,7 @@ public class Vala.GVariantModule : GAsyncModule {
return new CCodeIdentifier (temp_name);
}
- CCodeExpression deserialize_hash_table (ObjectType type, CCodeExpression variant_expr) {
+ CCodeExpression? deserialize_hash_table (ObjectType type, CCodeExpression variant_expr) {
string temp_name = "_tmp%d_".printf (next_temp_var_id++);
string subiter_name = "_tmp%d_".printf (next_temp_var_id++);
string key_name = "_tmp%d_".printf (next_temp_var_id++);
@@ -430,6 +430,9 @@ public class Vala.GVariantModule : GAsyncModule {
var key_expr = deserialize_expression (key_type, new CCodeIdentifier (key_name), null);
var value_expr = deserialize_expression (value_type, new CCodeIdentifier (value_name), null);
+ if (key_expr == null || value_expr == null) {
+ return null;
+ }
var hash_table_insert = new CCodeFunctionCall (new CCodeIdentifier ("g_hash_table_insert"));
hash_table_insert.add_argument (new CCodeIdentifier (temp_name));
@@ -500,6 +503,11 @@ public class Vala.GVariantModule : GAsyncModule {
ccode.add_expression (new CCodeAssignment (variant_expr, iter_call));
var result = deserialize_expression (type, variant_expr, target_expr);
+ if (result == null) {
+ // error already reported
+ return;
+ }
+
ccode.add_expression (new CCodeAssignment (target_expr, result));
var unref = new CCodeFunctionCall (new CCodeIdentifier ("g_variant_unref"));
@@ -641,7 +649,7 @@ public class Vala.GVariantModule : GAsyncModule {
return builder_end;
}
- CCodeExpression serialize_hash_table (ObjectType type, CCodeExpression hash_table_expr) {
+ CCodeExpression? serialize_hash_table (ObjectType type, CCodeExpression hash_table_expr) {
string subiter_name = "_tmp%d_".printf (next_temp_var_id++);
string tableiter_name = "_tmp%d_".printf (next_temp_var_id++);
string key_name = "_tmp%d_".printf (next_temp_var_id++);
@@ -680,11 +688,17 @@ public class Vala.GVariantModule : GAsyncModule {
ccode.add_expression (new CCodeAssignment (new CCodeIdentifier ("_key"), convert_from_generic_pointer (new CCodeIdentifier (key_name), key_type)));
ccode.add_expression (new CCodeAssignment (new CCodeIdentifier ("_value"), convert_from_generic_pointer (new CCodeIdentifier (value_name), value_type)));
+ var serialized_key = serialize_expression (key_type, new CCodeIdentifier ("_key"));
+ var serialized_value = serialize_expression (value_type, new CCodeIdentifier ("_value"));
+ if (serialized_key == null || serialized_value == null) {
+ return null;
+ }
+
iter_call = new CCodeFunctionCall (new CCodeIdentifier ("g_variant_builder_add"));
iter_call.add_argument (new CCodeUnaryExpression (CCodeUnaryOperator.ADDRESS_OF, new CCodeIdentifier (subiter_name)));
iter_call.add_argument (new CCodeConstant ("\"{?*}\""));
- iter_call.add_argument (serialize_expression (key_type, new CCodeIdentifier ("_key")));
- iter_call.add_argument (serialize_expression (value_type, new CCodeIdentifier ("_value")));
+ iter_call.add_argument (serialized_key);
+ iter_call.add_argument (serialized_value);
ccode.add_expression (iter_call);
ccode.close ();
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]