summaryrefslogtreecommitdiff
path: root/gobject
diff options
context:
space:
mode:
authorJuerg Billeter <j@bitron.ch>2008-03-24 20:14:14 +0000
committerJürg Billeter <juergbi@src.gnome.org>2008-03-24 20:14:14 +0000
commitc406f623c95b9866c8e9ad42b0991f6e8ef94b64 (patch)
tree6239d5bf8350fcd5f49de081bfa55d2fad14755e /gobject
parent93297a48cb7413ff6ca3ee189981e96475208290 (diff)
downloadvala-c406f623c95b9866c8e9ad42b0991f6e8ef94b64.tar.gz
fix generated code for methods returning structs
2008-03-24 Juerg Billeter <j@bitron.ch> * gobject/valaccodegenerator.vala, gobject/valaccodegeneratormethod.vala: fix generated code for methods returning structs svn path=/trunk/; revision=1158
Diffstat (limited to 'gobject')
-rw-r--r--gobject/valaccodegenerator.vala6
-rw-r--r--gobject/valaccodegeneratormethod.vala9
2 files changed, 8 insertions, 7 deletions
diff --git a/gobject/valaccodegenerator.vala b/gobject/valaccodegenerator.vala
index 2fdc4e3ec..f01ff1dd9 100644
--- a/gobject/valaccodegenerator.vala
+++ b/gobject/valaccodegenerator.vala
@@ -518,7 +518,7 @@ public class Vala.CCodeGenerator : CodeGenerator {
header_type_member_declaration.append (cdecl);
var var_decl = new CCodeVariableDeclarator (f.get_cname ());
- var_decl.initializer = default_value_for_type (f.type_reference);
+ var_decl.initializer = default_value_for_type (f.type_reference, true);
if (f.initializer != null) {
var init = (CCodeExpression) f.initializer.ccodenode;
@@ -1055,7 +1055,7 @@ public class Vala.CCodeGenerator : CodeGenerator {
/* try to initialize uninitialized variables */
if (decl.initializer == null) {
- ((CCodeVariableDeclarator) decl.ccodenode).initializer = default_value_for_type (decl.type_reference);
+ ((CCodeVariableDeclarator) decl.ccodenode).initializer = default_value_for_type (decl.type_reference, true);
}
}
@@ -1460,7 +1460,7 @@ public class Vala.CCodeGenerator : CodeGenerator {
if (current_return_type is VoidType) {
cerror_block.add_statement (new CCodeReturnStatement ());
} else {
- cerror_block.add_statement (new CCodeReturnStatement (default_value_for_type (current_return_type)));
+ cerror_block.add_statement (new CCodeReturnStatement (default_value_for_type (current_return_type, false)));
}
var ccond = new CCodeBinaryExpression (CCodeBinaryOperator.INEQUALITY, new CCodeIdentifier ("inner_error"), new CCodeConstant ("NULL"));
diff --git a/gobject/valaccodegeneratormethod.vala b/gobject/valaccodegeneratormethod.vala
index 24e48d080..c5aec68f9 100644
--- a/gobject/valaccodegeneratormethod.vala
+++ b/gobject/valaccodegeneratormethod.vala
@@ -676,7 +676,7 @@ public class Vala.CCodeGenerator {
} else {
ccheck.call = new CCodeIdentifier ("g_return_val_if_fail");
- var cdefault = default_value_for_type (ret_type);
+ var cdefault = default_value_for_type (ret_type, false);
if (cdefault != null) {
ccheck.add_argument (cdefault);
} else {
@@ -699,7 +699,7 @@ public class Vala.CCodeGenerator {
} else {
ccheck.call = new CCodeIdentifier ("g_return_val_if_fail");
- var cdefault = default_value_for_type (ret_type);
+ var cdefault = default_value_for_type (ret_type, false);
if (cdefault != null) {
ccheck.add_argument (cdefault);
} else {
@@ -719,13 +719,14 @@ public class Vala.CCodeGenerator {
return new CCodeExpressionStatement (cassert);
}
- private CCodeExpression default_value_for_type (DataType! type) {
+ private CCodeExpression default_value_for_type (DataType! type, bool initializer_expression) {
if ((type.data_type != null && type.data_type.is_reference_type ()) || type is PointerType || type is ArrayType) {
return new CCodeConstant ("NULL");
} else if (type.data_type != null && type.data_type.get_default_value () != null) {
return new CCodeConstant (type.data_type.get_default_value ());
- } else if (type.data_type is Struct) {
+ } else if (type.data_type is Struct && initializer_expression) {
// 0-initialize struct with struct initializer { 0 }
+ // only allowed as initializer expression in C
var clist = new CCodeInitializerList ();
clist.append (new CCodeConstant ("0"));
return clist;