[vala/staging: 2/2] codegen: Properly null-out source on ownership-transfer of delegates
- From: Rico Tzschichholz <ricotz src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [vala/staging: 2/2] codegen: Properly null-out source on ownership-transfer of delegates
- Date: Tue, 14 Mar 2017 17:43:46 +0000 (UTC)
commit 084eb5422acca802003f1bf1120d7f6ec4222809
Author: Marvin W <git larma de>
Date: Tue Mar 14 18:04:07 2017 +0100
codegen: Properly null-out source on ownership-transfer of delegates
codegen/valaccodebasemodule.vala | 5 +++++
tests/Makefile.am | 1 +
tests/delegates/reference_transfer.vala | 14 ++++++++++++++
3 files changed, 20 insertions(+), 0 deletions(-)
---
diff --git a/codegen/valaccodebasemodule.vala b/codegen/valaccodebasemodule.vala
index 16b5a01..410837a 100644
--- a/codegen/valaccodebasemodule.vala
+++ b/codegen/valaccodebasemodule.vala
@@ -5266,6 +5266,11 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator {
if (target_destroy_notify != null) {
ccode.add_assignment (target_destroy_notify, new CCodeConstant ("NULL"));
}
+ var target = get_delegate_target_cvalue (expr.inner.target_value);
+ if (target != null) {
+ ccode.add_assignment (target, new CCodeConstant ("NULL"));
+ }
+ ccode.add_assignment (get_cvalue (expr.inner), new CCodeConstant ("NULL"));
} else if (expr.inner.value_type is ArrayType) {
var array_type = (ArrayType) expr.inner.value_type;
var glib_value = (GLibValue) expr.inner.target_value;
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 6a50505..426570c 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -145,6 +145,7 @@ TESTS = \
structs/bug775761.vala \
structs/bug777194.vala \
delegates/delegates.vala \
+ delegates/reference_transfer.vala \
delegates/bug539166.vala \
delegates/bug595610.vala \
delegates/bug595639.vala \
diff --git a/tests/delegates/reference_transfer.vala b/tests/delegates/reference_transfer.vala
new file mode 100644
index 0000000..6aad6b1
--- /dev/null
+++ b/tests/delegates/reference_transfer.vala
@@ -0,0 +1,14 @@
+delegate void FooFunc ();
+
+class Foo {
+ FooFunc f;
+
+ public Foo (owned FooFunc d) {
+ f = (owned) d;
+ assert (d == null);
+ }
+}
+
+void main () {
+ var foo = new Foo (() => {});
+}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]