Commit 2ebb31c9 authored by Jürg Billeter's avatar Jürg Billeter Committed by Jürg Billeter

use GSlice and generate free function for reference-type structs with a

2007-07-26  Juerg Billeter  <j@bitron.ch>

	* vala/valastruct.vala, gobject/valacodegeneratormethod.vala,
	  gobject/valacodegeneratorstruct.vala: use GSlice and generate free
	  function for reference-type structs with a creation method

svn path=/trunk/; revision=389
parent a4633948
2007-07-26 Jürg Billeter <j@bitron.ch>
* vala/valastruct.vala, gobject/valacodegeneratormethod.vala,
gobject/valacodegeneratorstruct.vala: use GSlice and generate free
function for reference-type structs with a creation method
2007-07-25 Jürg Billeter <j@bitron.ch>
* vala/valaarray.vala: remove comments of overridden methods
......
......@@ -294,9 +294,8 @@ public class Vala.CodeGenerator {
} else {
var st = (Struct) m.parent_symbol;
var cdecl = new CCodeDeclaration (st.get_cname () + "*");
var ccall = new CCodeFunctionCall (new CCodeIdentifier ("g_new0"));
ccall.add_argument (new CCodeConstant (st.get_cname ()));
ccall.add_argument (new CCodeConstant ("1"));
var ccall = new CCodeFunctionCall (new CCodeIdentifier ("g_slice_new0"));
ccall.add_argument (new CCodeIdentifier (st.get_cname ()));
cdecl.add_declarator (new CCodeVariableDeclarator.with_initializer ("self", ccall));
cinit.append (cdecl);
}
......
......@@ -30,7 +30,7 @@ public class Vala.CodeGenerator {
var old_instance_dispose_fragment = instance_dispose_fragment;
current_type_symbol = st;
instance_struct = new CCodeStruct ("_%s".printf (st.get_cname ()));
instance_dispose_fragment = null;
instance_dispose_fragment = new CCodeFragment ();
CCodeFragment decl_frag;
CCodeFragment def_frag;
......@@ -53,6 +53,30 @@ public class Vala.CodeGenerator {
st.accept_children (this);
if (st.default_construction_method != null) {
var function = new CCodeFunction (st.get_lower_case_cprefix () + "free", "void");
if (st.access == MemberAccessibility.PRIVATE) {
function.modifiers = CCodeModifiers.STATIC;
}
function.add_parameter (new CCodeFormalParameter ("self", st.get_cname () + "*"));
decl_frag.append (function.copy ());
var cblock = new CCodeBlock ();
cblock.add_statement (instance_dispose_fragment);
var ccall = new CCodeFunctionCall (new CCodeIdentifier ("g_slice_free"));
ccall.add_argument (new CCodeIdentifier (st.get_cname ()));
ccall.add_argument (new CCodeIdentifier ("self"));
cblock.add_statement (new CCodeExpressionStatement (ccall));
function.block = cblock;
def_frag.append (function);
}
current_type_symbol = old_type_symbol;
instance_struct = old_instance_struct;
instance_dispose_fragment = old_instance_dispose_fragment;
......
......@@ -333,7 +333,11 @@ public class Vala.Struct : DataType {
public override string get_free_function () {
if (free_function == null) {
Report.error (source_reference, "The type `%s` doesn't contain a free function".printf (get_full_name ()));
if (default_construction_method != null) {
free_function = get_lower_case_cprefix () + "free";
} else {
Report.error (source_reference, "The type `%s` doesn't contain a free function".printf (get_full_name ()));
}
}
return free_function;
}
......
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