closure_new.add_argument (new CCodeCastExpression (delegate_target_destroy_notify, "GClosureNotify"));
cexpr = new CCodeConditionalExpression (new CCodeBinaryExpression (CCodeBinaryOperator.EQUALITY, cexpr, new CCodeConstant ("NULL")), new CCodeConstant ("NULL"), closure_new);
} else {
- carg_map.set (get_param_pos (get_ccode_delegate_target_pos (param)), delegate_target);
- if (deleg_type.is_disposable ()) {
- assert (delegate_target_destroy_notify != null);
- carg_map.set (get_param_pos (get_ccode_destroy_notify_pos (param)), delegate_target_destroy_notify);
+ // Override previously given target/destroy only if it was NULL
+ // TODO https://gitlab.gnome.org/GNOME/vala/issues/59
+ var node = carg_map.get (get_param_pos (get_ccode_delegate_target_pos (param)));
+ if (node == null || (node is CCodeConstant && ((CCodeConstant) node).name == "NULL")) {
+ carg_map.set (get_param_pos (get_ccode_delegate_target_pos (param)), delegate_target);
+ if (deleg_type.is_disposable ()) {
+ assert (delegate_target_destroy_notify != null);
+ carg_map.set (get_param_pos (get_ccode_destroy_notify_pos (param)), delegate_target_destroy_notify);
+ }
}
}
}
}
}
+void call_shared ([CCode (delegate_target_cname = "user_data", delegate_target_pos = 2.9)] FooFunc a, [CCode (delegate_target_cname = "user_data", delegate_target_pos = 2.9)] FooFunc b) {
+ a ();
+ b ();
+}
+
+void call_shared_owned ([CCode (delegate_target_cname = "user_data", delegate_target_pos = 2.9)] owned FooFunc a, [CCode (delegate_target_cname = "user_data", delegate_target_pos = 2.9)] owned FooFunc b) {
+ a ();
+ b ();
+}
+
+void run_static_1 () {
+ var foo = new Foo ();
+
+ assert (foo.ref_count == 1);
+
+ call_shared (
+ () => {
+ assert (foo != null);
+ },
+ () => {
+ }
+ );
+
+ assert (foo.ref_count == 1);
+}
+
+void run_static_2 () {
+ var foo = new Foo ();
+
+ assert (foo.ref_count == 1);
+
+ call_shared (
+ () => {
+ },
+ () => {
+ assert (foo != null);
+ }
+ );
+
+ assert (foo.ref_count == 1);
+}
+
+void run_static_3 () {
+ var foo = new Foo ();
+
+ assert (foo.ref_count == 1);
+
+ call_shared_owned (
+ () => {
+ assert (foo != null);
+ },
+ () => {
+ }
+ );
+
+ assert (foo.ref_count == 1);
+}
+
+void run_static_4 () {
+ var foo = new Foo ();
+
+ assert (foo.ref_count == 1);
+
+ call_shared_owned (
+ () => {
+ },
+ () => {
+ assert (foo != null);
+ }
+ );
+
+ assert (foo.ref_count == 1);
+}
+
void main () {
var foo = new Foo ();
assert (foo.ref_count == 1);
assert (foo.ref_count == 1);
foo.run_4 ();
assert (foo.ref_count == 1);
+
+ run_static_1 ();
+ run_static_2 ();
+ run_static_3 ();
+ run_static_4 ();
}