[vala/staging] Allow specify destroy_function and copy_function in Vala.
- From: Luca Bruno <lucabru src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [vala/staging] Allow specify destroy_function and copy_function in Vala.
- Date: Sun, 13 Jul 2014 09:43:20 +0000 (UTC)
commit f86204ae2fa107eec337646f663696bb9afe6123
Author: Maciej Piechotka <uzytkownik2 gmail com>
Date: Sun Jul 13 01:04:38 2014 +0200
Allow specify destroy_function and copy_function in Vala.
https://bugzilla.gnome.org/show_bug.cgi?id=733110
codegen/valaccodemethodmodule.vala | 4 +++-
codegen/valaccodestructmodule.vala | 13 +++++++++++++
tests/Makefile.am | 1 +
tests/structs/bug733110.vala | 32 ++++++++++++++++++++++++++++++++
4 files changed, 49 insertions(+), 1 deletions(-)
---
diff --git a/codegen/valaccodemethodmodule.vala b/codegen/valaccodemethodmodule.vala
index 0a933ac..bff5e62 100644
--- a/codegen/valaccodemethodmodule.vala
+++ b/codegen/valaccodemethodmodule.vala
@@ -870,7 +870,9 @@ public abstract class Vala.CCodeMethodModule : CCodeStructModule {
public virtual CCodeParameter generate_parameter (Parameter param, CCodeFile decl_space,
Map<int,CCodeParameter> cparam_map, Map<int,CCodeExpression>? carg_map) {
CCodeParameter cparam;
- if (!param.ellipsis) {
+ if (param.get_attribute_string ("CCode", "ctype") != null) {
+ cparam = new CCodeParameter (get_variable_cname (param.name),
param.get_attribute_string ("CCode", "ctype"));
+ } else if (!param.ellipsis) {
string ctypename = get_ccode_name (param.variable_type);
generate_type_declaration (param.variable_type, decl_space);
diff --git a/codegen/valaccodestructmodule.vala b/codegen/valaccodestructmodule.vala
index fe2a7c2..59822d5 100644
--- a/codegen/valaccodestructmodule.vala
+++ b/codegen/valaccodestructmodule.vala
@@ -207,6 +207,8 @@ public abstract class Vala.CCodeStructModule : CCodeBaseModule {
var function = new CCodeFunction (get_ccode_dup_function (st), get_ccode_name (st) + "*");
if (st.access == SymbolAccessibility.PRIVATE) {
function.modifiers = CCodeModifiers.STATIC;
+ } else if (context.hide_internal && st.is_internal_symbol ()) {
+ function.modifiers = CCodeModifiers.INTERNAL;
}
function.add_parameter (new CCodeParameter ("self", "const " + get_ccode_name (st) + "*"));
@@ -273,6 +275,10 @@ public abstract class Vala.CCodeStructModule : CCodeBaseModule {
}
void add_struct_copy_function (Struct st) {
+ if (st.get_attribute_string ("CCode", "copy_function") != null) {
+ return;
+ }
+
var function = new CCodeFunction (get_ccode_copy_function (st), "void");
if (st.is_private_symbol ()) {
function.modifiers = CCodeModifiers.STATIC;
@@ -306,6 +312,10 @@ public abstract class Vala.CCodeStructModule : CCodeBaseModule {
}
void begin_struct_destroy_function (Struct st) {
+ if (st.get_attribute_string ("CCode", "destroy_function") != null) {
+ return;
+ }
+
push_context (instance_finalize_context);
var function = new CCodeFunction (get_ccode_destroy_function (st), "void");
@@ -323,6 +333,9 @@ public abstract class Vala.CCodeStructModule : CCodeBaseModule {
}
void add_struct_destroy_function (Struct st) {
+ if (st.get_attribute_string ("CCode", "destroy_function") != null) {
+ return;
+ }
cfile.add_function (instance_finalize_context.ccode);
}
}
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 07c9877..0a8c1f1 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -105,6 +105,7 @@ TESTS = \
structs/bug685177.vala \
structs/bug686190.vala \
structs/bug690380.vala \
+ structs/bug733110.vala \
delegates/delegates.vala \
delegates/bug539166.vala \
delegates/bug595610.vala \
diff --git a/tests/structs/bug733110.vala b/tests/structs/bug733110.vala
new file mode 100644
index 0000000..6553eb3
--- /dev/null
+++ b/tests/structs/bug733110.vala
@@ -0,0 +1,32 @@
+internal int count = 0;
+
+[CCode (destroy_function = "structs_bug733110_foo_destroy", copy_function = "structs_bug733110_foo_copy")]
+internal struct Foo {
+ Foo() {
+ count++;
+ i = 0;
+ }
+ public static void copy ([CCode(ctype = "const structsbug733110Foo*")] Foo orig, out Foo dest) {
+ count++;
+ dest.i = orig.i + 1;
+ }
+ public void destroy () {
+ count--;
+ }
+ int i;
+}
+
+void main() {
+ assert (count == 0);
+ Foo f = Foo ();
+ assert (count == 1);
+ assert (f.i == 0);
+ {
+ Foo g = f;
+ assert (count == 2);
+ assert (f.i == 0);
+ assert (g.i == 1);
+ }
+ assert (count == 1);
+}
+
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]