[vala/staging] girwriter: Don't use instance-parameter inside callback (2)
- From: Rico Tzschichholz <ricotz src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [vala/staging] girwriter: Don't use instance-parameter inside callback (2)
- Date: Mon, 5 Apr 2021 17:08:15 +0000 (UTC)
commit 31afbf4bba9c40ec08f1491dd6b950bf4be5042f
Author: Rico Tzschichholz <ricotz ubuntu com>
Date: Mon Apr 5 19:06:40 2021 +0200
girwriter: Don't use instance-parameter inside callback (2)
Fixes https://gitlab.gnome.org/GNOME/vala/issues/1167
codegen/valagirwriter.vala | 25 +++++++++++--------------
tests/girwriter/GirTest-1.0.gir-expected | 24 ++++++++++++------------
2 files changed, 23 insertions(+), 26 deletions(-)
---
diff --git a/codegen/valagirwriter.vala b/codegen/valagirwriter.vala
index 3f5ebcb1b..acb19c8db 100644
--- a/codegen/valagirwriter.vala
+++ b/codegen/valagirwriter.vala
@@ -1135,7 +1135,7 @@ public class Vala.GIRWriter : CodeVisitor {
buffer.append_printf ("</%s>\n", tag_type);
}
- private void write_params_and_return (List<Parameter> params, List<TypeParameter>? type_params,
DataType? return_type, bool return_array_length, string? return_comment = null, bool constructor = false,
Parameter? instance_param = null, bool user_data = false) {
+ private void write_params_and_return (string tag_name, List<Parameter> params, List<TypeParameter>?
type_params, DataType? return_type, bool return_array_length, string? return_comment = null, bool constructor
= false, Parameter? instance_param = null, bool user_data = false) {
int last_index = 0;
bool ret_is_struct = return_type != null && return_type.is_real_non_null_struct_type ();
@@ -1179,7 +1179,12 @@ public class Vala.GIRWriter : CodeVisitor {
type.nullable = true;
}
int skip = 0;
- write_param_or_return (type, "instance-parameter", ref skip, false, "self");
+ if (tag_name == "callback") {
+ write_param_or_return (type, "parameter", ref skip, false, "self");
+ index++;
+ } else {
+ write_param_or_return (type, "instance-parameter", ref skip, false,
"self");
+ }
}
if (type_params != null) {
@@ -1244,7 +1249,7 @@ public class Vala.GIRWriter : CodeVisitor {
write_doc (get_delegate_comment (cb));
- write_params_and_return (cb.get_parameters (), cb.get_type_parameters (), cb.return_type,
get_ccode_array_length (cb), get_delegate_return_comment (cb), false, null, cb.has_target);
+ write_params_and_return ("callback", cb.get_parameters (), cb.get_type_parameters (),
cb.return_type, get_ccode_array_length (cb), get_delegate_return_comment (cb), false, null, cb.has_target);
indent--;
write_indent ();
@@ -1369,15 +1374,7 @@ public class Vala.GIRWriter : CodeVisitor {
write_doc (get_method_comment (m));
}
- if (tag_name == "callback" && m.this_parameter != null) {
- m.this_parameter.set_attribute_string ("CCode", "cname", "self");
- var static_params = new ArrayList<Vala.Parameter> ();
- static_params.add (m.this_parameter);
- static_params.add_all (params);
- write_params_and_return (static_params, m.get_type_parameters (), return_type,
get_ccode_array_length (m), return_comment, false);
- } else {
- write_params_and_return (params, m.get_type_parameters (), return_type,
get_ccode_array_length (m), return_comment, false, m.this_parameter);
- }
+ write_params_and_return (tag_name, params, m.get_type_parameters (), return_type,
get_ccode_array_length (m), return_comment, false, m.this_parameter);
indent--;
write_indent ();
@@ -1425,7 +1422,7 @@ public class Vala.GIRWriter : CodeVisitor {
if (m.parent_symbol is Class) {
type_params = ((Class) m.parent_symbol).get_type_parameters ();
}
- write_params_and_return (m.get_parameters (), type_params, datatype, false,
get_method_return_comment (m), true);
+ write_params_and_return (tag_name, m.get_parameters (), type_params, datatype, false,
get_method_return_comment (m), true);
indent--;
write_indent ();
@@ -1502,7 +1499,7 @@ public class Vala.GIRWriter : CodeVisitor {
write_doc (get_signal_comment (sig));
- write_params_and_return (sig.get_parameters (), null, sig.return_type, false,
get_signal_return_comment (sig));
+ write_params_and_return ("glib:signal", sig.get_parameters (), null, sig.return_type, false,
get_signal_return_comment (sig));
indent--;
write_indent ();
diff --git a/tests/girwriter/GirTest-1.0.gir-expected b/tests/girwriter/GirTest-1.0.gir-expected
index 0a342ea5b..d4bb4291e 100644
--- a/tests/girwriter/GirTest-1.0.gir-expected
+++ b/tests/girwriter/GirTest-1.0.gir-expected
@@ -1086,7 +1086,7 @@
<type name="none" c:type="void"/>
</return-value>
<parameters>
- <parameter name="this" transfer-ownership="none">
+ <parameter name="self" transfer-ownership="none">
<type name="GirTest.ObjectTest" c:type="GirTestObjectTest*"/>
</parameter>
<parameter name="_callback_" transfer-ownership="none" allow-none="1"
closure="2" scope="async">
@@ -1104,7 +1104,7 @@
<type name="none" c:type="void"/>
</return-value>
<parameters>
- <parameter name="this" transfer-ownership="none">
+ <parameter name="self" transfer-ownership="none">
<type name="GirTest.ObjectTest" c:type="GirTestObjectTest*"/>
</parameter>
<parameter name="_res_" transfer-ownership="none">
@@ -1119,7 +1119,7 @@
<type name="none" c:type="void"/>
</return-value>
<parameters>
- <parameter name="this" transfer-ownership="none">
+ <parameter name="self" transfer-ownership="none">
<type name="GirTest.ObjectTest" c:type="GirTestObjectTest*"/>
</parameter>
<parameter name="i1" transfer-ownership="none">
@@ -1140,7 +1140,7 @@
<type name="none" c:type="void"/>
</return-value>
<parameters>
- <parameter name="this" transfer-ownership="none">
+ <parameter name="self" transfer-ownership="none">
<type name="GirTest.ObjectTest" c:type="GirTestObjectTest*"/>
</parameter>
<parameter name="_res_" transfer-ownership="none">
@@ -1182,7 +1182,7 @@
<type name="none" c:type="void"/>
</return-value>
<parameters>
- <parameter name="this" transfer-ownership="none">
+ <parameter name="self" transfer-ownership="none">
<type name="GirTest.ObjectTest" c:type="GirTestObjectTest*"/>
</parameter>
<parameter name="_callback_" transfer-ownership="none" allow-none="1"
closure="2" scope="async">
@@ -1200,7 +1200,7 @@
<type name="none" c:type="void"/>
</return-value>
<parameters>
- <parameter name="this" transfer-ownership="none">
+ <parameter name="self" transfer-ownership="none">
<type name="GirTest.ObjectTest" c:type="GirTestObjectTest*"/>
</parameter>
<parameter name="_res_" transfer-ownership="none">
@@ -2454,7 +2454,7 @@
<type name="none" c:type="void"/>
</return-value>
<parameters>
- <parameter name="this" transfer-ownership="none">
+ <parameter name="self" transfer-ownership="none">
<type name="GirTest.InterfaceTest"
c:type="GirTestInterfaceTest*"/>
</parameter>
<parameter name="_callback_" transfer-ownership="none" allow-none="1"
closure="2" scope="async">
@@ -2472,7 +2472,7 @@
<type name="none" c:type="void"/>
</return-value>
<parameters>
- <parameter name="this" transfer-ownership="none">
+ <parameter name="self" transfer-ownership="none">
<type name="GirTest.InterfaceTest"
c:type="GirTestInterfaceTest*"/>
</parameter>
<parameter name="_res_" transfer-ownership="none">
@@ -2505,7 +2505,7 @@
<type name="none" c:type="void"/>
</return-value>
<parameters>
- <parameter name="this" transfer-ownership="none">
+ <parameter name="self" transfer-ownership="none">
<type name="GirTest.InterfaceTest"
c:type="GirTestInterfaceTest*"/>
</parameter>
<parameter name="param" transfer-ownership="none">
@@ -2526,7 +2526,7 @@
<type name="none" c:type="void"/>
</return-value>
<parameters>
- <parameter name="this" transfer-ownership="none">
+ <parameter name="self" transfer-ownership="none">
<type name="GirTest.InterfaceTest"
c:type="GirTestInterfaceTest*"/>
</parameter>
<parameter name="_res_" transfer-ownership="none">
@@ -2565,7 +2565,7 @@
<type name="none" c:type="void"/>
</return-value>
<parameters>
- <parameter name="this" transfer-ownership="none">
+ <parameter name="self" transfer-ownership="none">
<type name="GirTest.InterfaceTest"
c:type="GirTestInterfaceTest*"/>
</parameter>
<parameter name="_callback_" transfer-ownership="none" allow-none="1"
closure="2" scope="async">
@@ -2583,7 +2583,7 @@
<type name="none" c:type="void"/>
</return-value>
<parameters>
- <parameter name="this" transfer-ownership="none">
+ <parameter name="self" transfer-ownership="none">
<type name="GirTest.InterfaceTest"
c:type="GirTestInterfaceTest*"/>
</parameter>
<parameter name="_res_" transfer-ownership="none">
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]