Commit 557c03ad authored by Allison Karlitskaya's avatar Allison Karlitskaya Committed by Ryan Lortie

Bug 571169 – make floating references generic

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.


svn path=/trunk/; revision=2425
parent f0c175f5
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.
2009-02-09 Jürg Billeter <j@bitron.ch>
* gobject/valaccodedelegatemodule.vala:
......
......@@ -3357,13 +3357,19 @@ internal class Vala.CCodeBaseModule : CCodeModule {
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
......
......@@ -100,6 +100,7 @@ public class Vala.Class : ObjectTypeSymbol {
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 @@ public class Vala.Class : ObjectTypeSymbol {
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 @@ public class Vala.Class : ObjectTypeSymbol {
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;
}
......
......@@ -399,6 +399,16 @@ public class Vala.Interface : ObjectTypeSymbol {
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;
......
......@@ -259,7 +259,7 @@ public class Vala.ObjectCreationExpression : Expression {
}
while (cl != null) {
if (cl == analyzer.initially_unowned_type) {
if (cl.get_ref_sink_function () != null) {
value_type.floating_reference = true;
break;
}
......
......@@ -57,7 +57,6 @@ public class Vala.SemanticAnalyzer : CodeVisitor {
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 @@ public class Vala.SemanticAnalyzer : CodeVisitor {
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"));
......
......@@ -134,7 +134,25 @@ public abstract class Vala.TypeSymbol : Symbol {
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.
......
......@@ -219,6 +219,7 @@ namespace GLib {
public Value value;
}
[CCode (ref_sink_function = "g_object_ref_sink")]
public class InitiallyUnowned : Object {
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment