[vala] codegen: Support null elements in GenericArray
- From: Jürg Billeter <juergbi src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [vala] codegen: Support null elements in GenericArray
- Date: Sat, 23 Oct 2010 19:22:20 +0000 (UTC)
commit f06c7c67cc1c2f626b06a676583f3716d3c155ae
Author: Jürg Billeter <j bitron ch>
Date: Fri Oct 22 13:26:54 2010 +0200
codegen: Support null elements in GenericArray
codegen/valaccodebasemodule.vala | 56 +++++++++++++++++++++-----------------
1 files changed, 31 insertions(+), 25 deletions(-)
---
diff --git a/codegen/valaccodebasemodule.vala b/codegen/valaccodebasemodule.vala
index e37416f..e921ac3 100644
--- a/codegen/valaccodebasemodule.vala
+++ b/codegen/valaccodebasemodule.vala
@@ -2675,40 +2675,46 @@ public class Vala.CCodeBaseModule : CodeGenerator {
return destroy_func;
}
- public CCodeExpression? get_destroy_func_expression (DataType type, bool is_chainup = false) {
- if (context.profile == Profile.GOBJECT && (type.data_type == glist_type || type.data_type == gslist_type || type.data_type == gnode_type)) {
- // create wrapper function to free list elements if necessary
+ public CCodeExpression? get_destroy0_func_expression (DataType type, bool is_chainup = false) {
+ var element_destroy_func_expression = get_destroy_func_expression (type, is_chainup);
- bool elements_require_free = false;
- CCodeExpression element_destroy_func_expression = null;
+ if (element_destroy_func_expression is CCodeIdentifier) {
+ var freeid = (CCodeIdentifier) element_destroy_func_expression;
+ string free0_func = "_%s0_".printf (freeid.name);
- foreach (DataType type_arg in type.get_type_arguments ()) {
- elements_require_free = requires_destroy (type_arg);
- if (elements_require_free) {
- element_destroy_func_expression = get_destroy_func_expression (type_arg);
+ if (add_wrapper (free0_func)) {
+ var function = new CCodeFunction (free0_func, "void");
+ function.modifiers = CCodeModifiers.STATIC;
- if (element_destroy_func_expression is CCodeIdentifier) {
- var freeid = (CCodeIdentifier) element_destroy_func_expression;
- string free0_func = "_%s0_".printf (freeid.name);
+ function.add_parameter (new CCodeFormalParameter ("var", "gpointer"));
- if (add_wrapper (free0_func)) {
- var function = new CCodeFunction (free0_func, "void");
- function.modifiers = CCodeModifiers.STATIC;
+ push_function (function);
- function.add_parameter (new CCodeFormalParameter ("var", "gpointer"));
+ ccode.add_expression (get_unref_expression (new CCodeIdentifier ("var"), type, null, true));
- push_function (function);
+ pop_function ();
- ccode.add_expression (get_unref_expression (new CCodeIdentifier ("var"), type_arg, null, true));
+ cfile.add_function_declaration (function);
+ cfile.add_function (function);
+ }
- pop_function ();
+ element_destroy_func_expression = new CCodeIdentifier (free0_func);
+ }
- cfile.add_function_declaration (function);
- cfile.add_function (function);
- }
+ return element_destroy_func_expression;
+ }
- element_destroy_func_expression = new CCodeIdentifier (free0_func);
- }
+ public CCodeExpression? get_destroy_func_expression (DataType type, bool is_chainup = false) {
+ if (context.profile == Profile.GOBJECT && (type.data_type == glist_type || type.data_type == gslist_type || type.data_type == gnode_type)) {
+ // create wrapper function to free list elements if necessary
+
+ bool elements_require_free = false;
+ CCodeExpression element_destroy_func_expression = null;
+
+ foreach (DataType type_arg in type.get_type_arguments ()) {
+ elements_require_free = requires_destroy (type_arg);
+ if (elements_require_free) {
+ element_destroy_func_expression = get_destroy0_func_expression (type_arg);
}
}
@@ -4154,7 +4160,7 @@ public class Vala.CCodeBaseModule : CodeGenerator {
int type_param_index = 0;
foreach (var type_arg in expr.type_reference.get_type_arguments ()) {
if (requires_copy (type_arg)) {
- carg_map.set (get_param_pos (-1 + 0.1 * type_param_index + 0.03), get_destroy_func_expression (type_arg));
+ carg_map.set (get_param_pos (-1 + 0.1 * type_param_index + 0.03), get_destroy0_func_expression (type_arg));
} else {
carg_map.set (get_param_pos (-1 + 0.1 * type_param_index + 0.03), new CCodeConstant ("NULL"));
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]