diff options
author | Aaron Andersen <aaron@fosslib.net> | 2011-12-25 15:29:24 +0100 |
---|---|---|
committer | Jürg Billeter <j@bitron.ch> | 2012-01-31 13:09:18 +0100 |
commit | 1cddf0ba6c950d46d1fcb9786b48b861f6a30238 (patch) | |
tree | faca261017fbe9c25c80d5bcd464b24450c121d3 | |
parent | 8c26945205570eef5bc1dcf88532be1c3b61b305 (diff) | |
download | vala-1cddf0ba6c950d46d1fcb9786b48b861f6a30238.tar.gz |
codegen: Generate _dup() and _free() for structs in the posix profile
Fixes bug 665815.
-rw-r--r-- | codegen/valaccodestructmodule.vala | 31 |
1 files changed, 22 insertions, 9 deletions
diff --git a/codegen/valaccodestructmodule.vala b/codegen/valaccodestructmodule.vala index b21829b54..affb48ea2 100644 --- a/codegen/valaccodestructmodule.vala +++ b/codegen/valaccodestructmodule.vala @@ -155,7 +155,7 @@ public abstract class Vala.CCodeStructModule : CCodeBaseModule { generate_struct_declaration (st, internal_header_file); } - if (context.profile == Profile.GOBJECT && !st.is_boolean_type () && !st.is_integer_type () && !st.is_floating_type ()) { + if (!st.is_boolean_type () && !st.is_integer_type () && !st.is_floating_type ()) { if (st.is_disposable ()) { begin_struct_destroy_function (st); } @@ -163,7 +163,7 @@ public abstract class Vala.CCodeStructModule : CCodeBaseModule { st.accept_children (this); - if (context.profile == Profile.GOBJECT && !st.is_boolean_type () && !st.is_integer_type () && !st.is_floating_type ()) { + if (!st.is_boolean_type () && !st.is_integer_type () && !st.is_floating_type ()) { if (st.is_disposable ()) { add_struct_copy_function (st); add_struct_destroy_function (st); @@ -191,10 +191,17 @@ public abstract class Vala.CCodeStructModule : CCodeBaseModule { ccode.add_declaration (get_ccode_name (st) + "*", new CCodeVariableDeclarator ("dup")); - var creation_call = new CCodeFunctionCall (new CCodeIdentifier ("g_new0")); - creation_call.add_argument (new CCodeConstant (get_ccode_name (st))); - creation_call.add_argument (new CCodeConstant ("1")); - ccode.add_assignment (new CCodeIdentifier ("dup"), creation_call); + if (context.profile == Profile.GOBJECT) { + var creation_call = new CCodeFunctionCall (new CCodeIdentifier ("g_new0")); + creation_call.add_argument (new CCodeConstant (get_ccode_name (st))); + creation_call.add_argument (new CCodeConstant ("1")); + ccode.add_assignment (new CCodeIdentifier ("dup"), creation_call); + } else if (context.profile == Profile.POSIX) { + var creation_call = new CCodeFunctionCall (new CCodeIdentifier ("calloc")); + creation_call.add_argument (new CCodeConstant ("1")); + creation_call.add_argument (new CCodeIdentifier ("sizeof (%s*)".printf (get_ccode_name (st)))); + ccode.add_assignment (new CCodeIdentifier ("dup"), creation_call); + } if (st.is_disposable ()) { var copy_call = new CCodeFunctionCall (new CCodeIdentifier (get_ccode_copy_function (st))); @@ -237,9 +244,15 @@ public abstract class Vala.CCodeStructModule : CCodeBaseModule { ccode.add_expression (destroy_call); } - var free_call = new CCodeFunctionCall (new CCodeIdentifier ("g_free")); - free_call.add_argument (new CCodeIdentifier ("self")); - ccode.add_expression (free_call); + if (context.profile == Profile.GOBJECT) { + var free_call = new CCodeFunctionCall (new CCodeIdentifier ("g_free")); + free_call.add_argument (new CCodeIdentifier ("self")); + ccode.add_expression (free_call); + } else if (context.profile == Profile.POSIX) { + var free_call = new CCodeFunctionCall (new CCodeIdentifier ("free")); + free_call.add_argument (new CCodeIdentifier ("self")); + ccode.add_expression (free_call); + } pop_function (); |