vala r2425 - in trunk: . gobject vala vapi
- From: ryanl svn gnome org
- To: svn-commits-list gnome org
- Subject: vala r2425 - in trunk: . gobject vala vapi
- Date: Tue, 10 Feb 2009 15:04:39 +0000 (UTC)
Author: ryanl
Date: Tue Feb 10 15:04:39 2009
New Revision: 2425
URL: http://svn.gnome.org/viewvc/vala?rev=2425&view=rev
Log:
2009-02-10 Ryan Lortie <desrt desrt ca>
Bug 571169 â make floating references generic
* gobject/valaccodebasemodule.vala:
* vala/valainterface.vala:
* vala/valaclass.vala:
* vala/valaobjectcreationexpression.vala:
* vala/valasemanticanalyzer.vala:
* vala/valatypesymbol.vala:
Add support for 'ref_sink_function' CCode attribute on classes.
Use this instead of hardcoding g_object_ref_sink() for
GInitiallyUnowned.
* vapi/gobject-2.0.vapi:
Set ref_sink_function on InitiallyUnowned class.
Modified:
trunk/ChangeLog
trunk/gobject/valaccodebasemodule.vala
trunk/vala/valaclass.vala
trunk/vala/valainterface.vala
trunk/vala/valaobjectcreationexpression.vala
trunk/vala/valasemanticanalyzer.vala
trunk/vala/valatypesymbol.vala
trunk/vapi/gobject-2.0.vapi
Modified: trunk/gobject/valaccodebasemodule.vala
==============================================================================
--- trunk/gobject/valaccodebasemodule.vala (original)
+++ trunk/gobject/valaccodebasemodule.vala Tue Feb 10 15:04:39 2009
@@ -3357,13 +3357,19 @@
if (expression_type.value_owned
&& expression_type.floating_reference) {
- /* constructor of GInitiallyUnowned subtype
- * returns floating reference, sink it
+ /* floating reference, sink it.
*/
- var csink = new CCodeFunctionCall (new CCodeIdentifier ("g_object_ref_sink"));
- csink.add_argument (cexpr);
-
- cexpr = csink;
+ var cl = expression_type.data_type as ObjectTypeSymbol;
+ var sink_func = (cl != null) ? cl.get_ref_sink_function () : null;
+
+ if (sink_func != null) {
+ var csink = new CCodeFunctionCall (new CCodeIdentifier (sink_func));
+ csink.add_argument (cexpr);
+
+ cexpr = csink;
+ } else {
+ Report.error (null, "type `%s' does not support floating references".printf (expression_type.data_type.name));
+ }
}
bool boxing = (expression_type is ValueType && !expression_type.nullable
Modified: trunk/vala/valaclass.vala
==============================================================================
--- trunk/vala/valaclass.vala (original)
+++ trunk/vala/valaclass.vala Tue Feb 10 15:04:39 2009
@@ -100,6 +100,7 @@
private string type_id;
private string ref_function;
private string unref_function;
+ private string ref_sink_function;
private string param_spec_function;
private string copy_function;
private string free_function;
@@ -605,6 +606,9 @@
if (a.has_argument ("unref_function")) {
set_unref_function (a.get_string ("unref_function"));
}
+ if (a.has_argument ("ref_sink_function")) {
+ set_ref_sink_function (a.get_string ("ref_sink_function"));
+ }
if (a.has_argument ("copy_function")) {
set_dup_function (a.get_string ("copy_function"));
}
@@ -779,6 +783,18 @@
this.unref_function = name;
}
+ public override string? get_ref_sink_function () {
+ if (ref_sink_function == null && base_class != null) {
+ return base_class.get_ref_sink_function ();
+ } else {
+ return ref_sink_function;
+ }
+ }
+
+ public void set_ref_sink_function (string? name) {
+ this.ref_sink_function = name;
+ }
+
public override string? get_dup_function () {
return copy_function;
}
Modified: trunk/vala/valainterface.vala
==============================================================================
--- trunk/vala/valainterface.vala (original)
+++ trunk/vala/valainterface.vala Tue Feb 10 15:04:39 2009
@@ -399,6 +399,16 @@
return null;
}
+ public override string? get_ref_sink_function () {
+ foreach (DataType prerequisite in prerequisites) {
+ string ref_sink_func = prerequisite.data_type.get_ref_sink_function ();
+ if (ref_sink_func != null) {
+ return ref_sink_func;
+ }
+ }
+ return null;
+ }
+
public override bool is_subtype_of (TypeSymbol t) {
if (this == t) {
return true;
Modified: trunk/vala/valaobjectcreationexpression.vala
==============================================================================
--- trunk/vala/valaobjectcreationexpression.vala (original)
+++ trunk/vala/valaobjectcreationexpression.vala Tue Feb 10 15:04:39 2009
@@ -259,7 +259,7 @@
}
while (cl != null) {
- if (cl == analyzer.initially_unowned_type) {
+ if (cl.get_ref_sink_function () != null) {
value_type.floating_reference = true;
break;
}
Modified: trunk/vala/valasemanticanalyzer.vala
==============================================================================
--- trunk/vala/valasemanticanalyzer.vala (original)
+++ trunk/vala/valasemanticanalyzer.vala Tue Feb 10 15:04:39 2009
@@ -57,7 +57,6 @@
public DataType double_type;
public DataType type_type;
public Class object_type;
- public TypeSymbol initially_unowned_type;
public DataType glist_type;
public DataType gslist_type;
public DataType garray_type;
@@ -103,8 +102,6 @@
var glib_ns = root_symbol.scope.lookup ("GLib");
if (glib_ns != null) {
object_type = (Class) glib_ns.scope.lookup ("Object");
- initially_unowned_type = (TypeSymbol) glib_ns.scope.lookup ("InitiallyUnowned");
-
type_type = new IntegerType ((Struct) glib_ns.scope.lookup ("Type"));
glist_type = new ObjectType ((Class) glib_ns.scope.lookup ("List"));
Modified: trunk/vala/valatypesymbol.vala
==============================================================================
--- trunk/vala/valatypesymbol.vala (original)
+++ trunk/vala/valatypesymbol.vala Tue Feb 10 15:04:39 2009
@@ -134,7 +134,25 @@
public virtual string? get_unref_function () {
return null;
}
-
+
+ /**
+ * Returns the C function name that sinks the reference count of
+ * "floating" instances of this data type. This is only valid for data
+ * types supporting floating references. The specified C function must
+ * accept one argument referencing the instance of this data type and
+ * return a non-floating reference.
+ *
+ * The ref_sink function is called for any constructor of the class and
+ * for other methods that have the class as a return value and are
+ * marked with the 'floating' attribute.
+ *
+ * @return the name of the C function or null if this data type does not
+ * support floating reference counts
+ */
+ public virtual string? get_ref_sink_function () {
+ return null;
+ }
+
/**
* Returns the C symbol representing the runtime type id for this data
* type. The specified symbol must express a registered GType.
Modified: trunk/vapi/gobject-2.0.vapi
==============================================================================
--- trunk/vapi/gobject-2.0.vapi (original)
+++ trunk/vapi/gobject-2.0.vapi Tue Feb 10 15:04:39 2009
@@ -219,6 +219,7 @@
public Value value;
}
+ [CCode (ref_sink_function = "g_object_ref_sink")]
public class InitiallyUnowned : Object {
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]