[vala] Fix initialization of nullable structs
- From: Jürg Billeter <juergbi src gnome org>
- To: svn-commits-list gnome org
- Subject: [vala] Fix initialization of nullable structs
- Date: Thu, 7 May 2009 11:01:46 -0400 (EDT)
commit 3ad7e0d8f342b39ca1e470039491d9c281460f74
Author: Levi Bard <taktaktaktaktaktaktaktaktaktak gmail com>
Date: Thu May 7 17:01:14 2009 +0200
Fix initialization of nullable structs
Fixes bug 579758.
---
gobject/valaccodebasemodule.vala | 9 ++++++---
1 files changed, 6 insertions(+), 3 deletions(-)
diff --git a/gobject/valaccodebasemodule.vala b/gobject/valaccodebasemodule.vala
index 625a8aa..2bfc97f 100644
--- a/gobject/valaccodebasemodule.vala
+++ b/gobject/valaccodebasemodule.vala
@@ -2079,7 +2079,8 @@ internal class Vala.CCodeBaseModule : CCodeModule {
// initialization is not needed for these special
// pointer temp variables
// used to avoid side-effects in assignments
- } else if ((st != null && !st.is_simple_type ()) ||
+ } else if (!local.variable_type.nullable &&
+ (st != null && !st.is_simple_type ()) ||
(array_type != null && array_type.fixed_length)) {
// 0-initialize struct with struct initializer { 0 }
// necessary as they will be passed by reference
@@ -2087,7 +2088,8 @@ internal class Vala.CCodeBaseModule : CCodeModule {
clist.append (new CCodeConstant ("0"));
vardecl.initializer = clist;
- } else if (local.variable_type.is_reference_type_or_type_parameter ()) {
+ } else if (local.variable_type.is_reference_type_or_type_parameter () ||
+ local.variable_type.nullable) {
vardecl.initializer = new CCodeConstant ("NULL");
}
@@ -3724,7 +3726,7 @@ internal class Vala.CCodeBaseModule : CCodeModule {
public CCodeExpression? default_value_for_type (DataType type, bool initializer_expression) {
var st = type.data_type as Struct;
var array_type = type as ArrayType;
- if (initializer_expression &&
+ if (initializer_expression && !type.nullable &&
((st != null && !st.is_simple_type ()) ||
(array_type != null && array_type.fixed_length))) {
// 0-initialize struct with struct initializer { 0 }
@@ -3733,6 +3735,7 @@ internal class Vala.CCodeBaseModule : CCodeModule {
clist.append (new CCodeConstant ("0"));
return clist;
} else if ((type.data_type != null && type.data_type.is_reference_type ())
+ || type.nullable
|| type is PointerType || type is DelegateType
|| (array_type != null && !array_type.fixed_length)) {
return new CCodeConstant ("NULL");
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]