[vala/0.34] 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/0.34] codegen: Properly null-out source on ownership-transfer of delegates
- Date: Thu, 16 Mar 2017 11:55:45 +0000 (UTC)
commit c6f6428f10adb0b9ff037342810ccd8b86963690
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 e7951c4..ae2a8e8 100644
--- a/codegen/valaccodebasemodule.vala
+++ b/codegen/valaccodebasemodule.vala
@@ -5196,6 +5196,11 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator {
creation_call.add_argument (new CCodeIdentifier ("sizeof (%s)".printf (get_ccode_name
(expr.inner.value_type))));
ccode.add_expression (creation_call);
} else if (expr.value_type is DelegateType) {
+ ccode.add_assignment (get_cvalue (expr.inner), new CCodeConstant ("NULL"));
+ var target = get_delegate_target_cvalue (expr.inner.target_value);
+ if (target != null) {
+ ccode.add_assignment (target, new CCodeConstant ("NULL"));
+ }
var target_destroy_notify = get_delegate_target_destroy_notify_cvalue
(expr.inner.target_value);
if (target_destroy_notify != null) {
ccode.add_assignment (target_destroy_notify, new CCodeConstant ("NULL"));
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 769e337..3bdfffb 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -124,6 +124,7 @@ TESTS = \
structs/bug749952.vala \
structs/bug775761.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]