diff options
author | Marvin W <git@larma.de> | 2017-03-14 18:04:07 +0100 |
---|---|---|
committer | Rico Tzschichholz <ricotz@ubuntu.com> | 2017-03-16 12:52:24 +0100 |
commit | c6f6428f10adb0b9ff037342810ccd8b86963690 (patch) | |
tree | 17bcfed7b319e0b8d7ed95ceedc6da7911e47f74 | |
parent | e339a3459562ef02ce20217ab8dd1383dca2670f (diff) | |
download | vala-c6f6428f10adb0b9ff037342810ccd8b86963690.tar.gz |
codegen: Properly null-out source on ownership-transfer of delegates
-rw-r--r-- | codegen/valaccodebasemodule.vala | 5 | ||||
-rw-r--r-- | tests/Makefile.am | 1 | ||||
-rw-r--r-- | tests/delegates/reference_transfer.vala | 14 |
3 files changed, 20 insertions, 0 deletions
diff --git a/codegen/valaccodebasemodule.vala b/codegen/valaccodebasemodule.vala index e7951c498..ae2a8e820 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 769e3373a..3bdfffbd6 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 000000000..6aad6b1f9 --- /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 (() => {}); +} |