vala r1399 - in trunk: . gobject vala
- From: juergbi svn gnome org
- To: svn-commits-list gnome org
- Subject: vala r1399 - in trunk: . gobject vala
- Date: Sun, 18 May 2008 18:27:32 +0000 (UTC)
Author: juergbi
Date: Sun May 18 18:27:32 2008
New Revision: 1399
URL: http://svn.gnome.org/viewvc/vala?rev=1399&view=rev
Log:
2008-05-18 Juerg Billeter <j bitron ch>
* vala/valadatatype.vala:
* vala/valapointertype.vala:
* vala/valasemanticanalyzer.vala:
* gobject/valaccodegenerator.vala:
Don't report value ownership errors for non-disposable types
Modified:
trunk/ChangeLog
trunk/gobject/valaccodegenerator.vala
trunk/vala/valadatatype.vala
trunk/vala/valapointertype.vala
trunk/vala/valasemanticanalyzer.vala
Modified: trunk/gobject/valaccodegenerator.vala
==============================================================================
--- trunk/gobject/valaccodegenerator.vala (original)
+++ trunk/gobject/valaccodegenerator.vala Sun May 18 18:27:32 2008
@@ -2811,41 +2811,31 @@
}
public bool requires_copy (DataType type) {
- if (!type.value_owned) {
+ if (!type.is_disposable ()) {
return false;
}
- if (type.is_reference_type_or_type_parameter ()) {
- if (type.type_parameter != null) {
- if (!(current_type_symbol is Class) || !current_class.is_subtype_of (gobject_type)) {
- return false;
- }
+ if (type.type_parameter != null) {
+ if (!(current_type_symbol is Class) || !current_class.is_subtype_of (gobject_type)) {
+ return false;
}
- return true;
- } else if (type is ValueType) {
- // nullable structs are heap allocated
- return type.nullable;
}
- return false;
+
+ return true;
}
public bool requires_destroy (DataType type) {
- if (!type.value_owned) {
+ if (!type.is_disposable ()) {
return false;
}
- if (type.is_reference_type_or_type_parameter ()) {
- if (type.type_parameter != null) {
- if (!(current_type_symbol is Class) || !current_class.is_subtype_of (gobject_type)) {
- return false;
- }
+ if (type.type_parameter != null) {
+ if (!(current_type_symbol is Class) || !current_class.is_subtype_of (gobject_type)) {
+ return false;
}
- return true;
- } else if (type is ValueType) {
- // nullable structs are heap allocated
- return type.nullable;
}
- return false;
+
+ return true;
}
private CCodeExpression? get_ref_expression (Expression expr) {
Modified: trunk/vala/valadatatype.vala
==============================================================================
--- trunk/vala/valadatatype.vala (original)
+++ trunk/vala/valadatatype.vala Sun May 18 18:27:32 2008
@@ -414,4 +414,23 @@
return null;
}
}
+
+ /**
+ * Returns whether the value needs to be disposed, i.e. whether
+ * allocated memory or other resources need to be released when
+ * the value is no longer needed.
+ */
+ public virtual bool is_disposable () {
+ if (!value_owned) {
+ return false;
+ }
+
+ if (is_reference_type_or_type_parameter ()) {
+ return true;
+ } else if (this is ValueType) {
+ // nullable structs are heap allocated
+ return nullable;
+ }
+ return false;
+ }
}
Modified: trunk/vala/valapointertype.vala
==============================================================================
--- trunk/vala/valapointertype.vala (original)
+++ trunk/vala/valapointertype.vala Sun May 18 18:27:32 2008
@@ -107,4 +107,8 @@
base_type = new_type;
}
}
+
+ public override bool is_disposable () {
+ return false;
+ }
}
Modified: trunk/vala/valasemanticanalyzer.vala
==============================================================================
--- trunk/vala/valasemanticanalyzer.vala (original)
+++ trunk/vala/valasemanticanalyzer.vala Sun May 18 18:27:32 2008
@@ -851,7 +851,7 @@
return;
}
- if (local.initializer.value_type.value_owned) {
+ if (local.initializer.value_type.is_disposable ()) {
/* rhs transfers ownership of the expression */
if (!(local.variable_type is PointerType) && !local.variable_type.value_owned) {
/* lhs doesn't own the value */
@@ -1154,7 +1154,7 @@
}
if (stmt.return_expression != null &&
- stmt.return_expression.value_type.value_owned &&
+ stmt.return_expression.value_type.is_disposable () &&
!current_return_type.value_owned) {
stmt.error = true;
Report.error (stmt.source_reference, "Return value transfers ownership but method return type hasn't been declared to transfer ownership");
@@ -1163,7 +1163,7 @@
if (stmt.return_expression != null &&
stmt.return_expression.symbol_reference is LocalVariable &&
- stmt.return_expression.value_type.value_owned &&
+ stmt.return_expression.value_type.is_disposable () &&
!current_return_type.value_owned) {
Report.warning (stmt.source_reference, "Local variable with strong reference used as return value and method return type hasn't been declared to transfer ownership");
}
@@ -2688,7 +2688,7 @@
return;
}
- if (!expr.inner.value_type.value_owned
+ if (!expr.inner.value_type.is_disposable ()
&& !(expr.inner.value_type is PointerType)) {
expr.error = true;
Report.error (expr.source_reference, "No reference to be transferred");
@@ -3170,7 +3170,7 @@
return;
}
- if (a.right.value_type.value_owned) {
+ if (a.right.value_type.is_disposable ()) {
/* rhs transfers ownership of the expression */
if (!(a.left.value_type is PointerType) && !a.left.value_type.value_owned) {
/* lhs doesn't own the value */
@@ -3193,7 +3193,7 @@
return;
}
- if (a.right.value_type.value_owned) {
+ if (a.right.value_type.is_disposable ()) {
/* rhs transfers ownership of the expression */
DataType element_type;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]