[vala] Fix memory management in generic methods
- From: Jürg Billeter <juergbi src gnome org>
- To: svn-commits-list gnome org
- Cc:
- Subject: [vala] Fix memory management in generic methods
- Date: Thu, 27 Aug 2009 08:29:22 +0000 (UTC)
commit 2aae6b2b3f8acac14e22d9a98d7604c2daa3afe5
Author: Jürg Billeter <j bitron ch>
Date: Thu Aug 27 10:27:50 2009 +0200
Fix memory management in generic methods
Fixes bug 593260.
codegen/valaccodebasemodule.vala | 21 ++++++++++++++-------
1 files changed, 14 insertions(+), 7 deletions(-)
---
diff --git a/codegen/valaccodebasemodule.vala b/codegen/valaccodebasemodule.vala
index 26c5e51..a31b0c7 100644
--- a/codegen/valaccodebasemodule.vala
+++ b/codegen/valaccodebasemodule.vala
@@ -1924,7 +1924,7 @@ internal class Vala.CCodeBaseModule : CCodeModule {
}
return new CCodeIdentifier (dup_function);
- } else if (type.type_parameter != null && current_type_symbol is Class) {
+ } else if (type.type_parameter != null) {
string func_name = "%s_dup_func".printf (type.type_parameter.name.down ());
if (is_in_generic_type (type) && !is_chainup) {
return new CCodeMemberAccess.pointer (new CCodeMemberAccess.pointer (new CCodeIdentifier ("self"), "priv"), func_name);
@@ -2806,6 +2806,17 @@ internal class Vala.CCodeBaseModule : CCodeModule {
return null;
}
+ bool is_limited_generic_type (DataType type) {
+ var cl = type.type_parameter.parent_symbol as Class;
+ var st = type.type_parameter.parent_symbol as Struct;
+ if ((cl != null && cl.is_compact) || st != null) {
+ // compact classes and structs only
+ // have very limited generics support
+ return true;
+ }
+ return false;
+ }
+
public bool requires_copy (DataType type) {
if (!type.is_disposable ()) {
return false;
@@ -2819,7 +2830,7 @@ internal class Vala.CCodeBaseModule : CCodeModule {
}
if (type.type_parameter != null) {
- if (!(current_type_symbol is Class) || current_class.is_compact) {
+ if (is_limited_generic_type (type)) {
return false;
}
}
@@ -2845,7 +2856,7 @@ internal class Vala.CCodeBaseModule : CCodeModule {
}
if (type.type_parameter != null) {
- if (!(current_type_symbol is Class) || current_class.is_compact) {
+ if (is_limited_generic_type (type)) {
return false;
}
}
@@ -2937,10 +2948,6 @@ internal class Vala.CCodeBaseModule : CCodeModule {
var cisnull = new CCodeBinaryExpression (CCodeBinaryOperator.EQUALITY, ctemp, new CCodeConstant ("NULL"));
if (expression_type.type_parameter != null) {
- if (!(current_type_symbol is Class)) {
- return cexpr;
- }
-
// dup functions are optional for type parameters
var cdupisnull = new CCodeBinaryExpression (CCodeBinaryOperator.EQUALITY, get_dup_func_expression (expression_type, node.source_reference), new CCodeConstant ("NULL"));
cisnull = new CCodeBinaryExpression (CCodeBinaryOperator.OR, cisnull, cdupisnull);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]