[vala/0.36: 50/212] codegen: Adjust format-index for printf/scanf-methods which throw errors
- From: Rico Tzschichholz <ricotz src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [vala/0.36: 50/212] codegen: Adjust format-index for printf/scanf-methods which throw errors
- Date: Sat, 14 Apr 2018 07:47:33 +0000 (UTC)
commit 85b8b81c3e9b86d04ff83a899b6c4a36442e23fa
Author: Rico Tzschichholz <ricotz ubuntu com>
Date: Sun Aug 27 09:11:48 2017 +0200
codegen: Adjust format-index for printf/scanf-methods which throw errors
If there is no explicit FormatArg annotation while this method throws an
error, it is required to mark the parameter located right before ellipsis
as format-arg to account for the parameter shifting caused by the inserted
GError parameter.
https://bugzilla.gnome.org/show_bug.cgi?id=781061
codegen/valaccodemethodmodule.vala | 15 ++++++++++++++-
tests/Makefile.am | 1 +
tests/methods/bug781061.vala | 30 ++++++++++++++++++++++++++++++
3 files changed, 45 insertions(+), 1 deletions(-)
---
diff --git a/codegen/valaccodemethodmodule.vala b/codegen/valaccodemethodmodule.vala
index 4d0d5fb..a4fcb12 100644
--- a/codegen/valaccodemethodmodule.vala
+++ b/codegen/valaccodemethodmodule.vala
@@ -1031,6 +1031,9 @@ public abstract class Vala.CCodeMethodModule : CCodeStructModule {
}
}
+ var needs_format_arg = m.get_format_arg_index () < 0 && (m.printf_format || m.scanf_format);
+
+ CCodeParameter? prev_cparam = null;
foreach (Parameter param in m.get_parameters ()) {
if (param.direction != ParameterDirection.OUT) {
if ((direction & 1) == 0) {
@@ -1044,7 +1047,17 @@ public abstract class Vala.CCodeMethodModule : CCodeStructModule {
}
}
- generate_parameter (param, decl_space, cparam_map, carg_map);
+ var cparam = generate_parameter (param, decl_space, cparam_map, carg_map);
+
+ // if there is no explicit FormatArg annotation while this method throws an error
+ // it is required to mark the parameter located right before ellipsis as format-arg
+ // to account for the parameter shifting caused by the inserted GError parameter
+ if (needs_format_arg) {
+ if (prev_cparam != null && cparam.ellipsis) {
+ prev_cparam.modifiers |= CCodeModifiers.FORMAT_ARG;
+ }
+ prev_cparam = cparam;
+ }
}
if ((direction & 2) != 0) {
diff --git a/tests/Makefile.am b/tests/Makefile.am
index c5cc723..16724e3 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -92,6 +92,7 @@ TESTS = \
methods/bug771964.vala \
methods/bug774060.vala \
methods/bug775466.test \
+ methods/bug781061.vala \
methods/generics.vala \
methods/printf-invalid.test \
methods/printf-constructor.vala \
diff --git a/tests/methods/bug781061.vala b/tests/methods/bug781061.vala
new file mode 100644
index 0000000..0969935
--- /dev/null
+++ b/tests/methods/bug781061.vala
@@ -0,0 +1,30 @@
+errordomain FooError {
+ FAILED;
+}
+
+[PrintfFormat]
+void print_something_throws (bool ok, string format, ...) throws FooError {
+ var vargs = va_list ();
+ print_something_vargs_throws (ok, format, vargs);
+}
+
+[PrintfFormat]
+void print_something_vargs_throws (bool ok, string format, va_list vargs) throws FooError {
+}
+
+[ScanfFormat]
+void scan_something_throws (bool ok, string format, ...) throws FooError {
+}
+
+[ScanfFormat]
+void scan_something_vargs_throws (bool ok, string format, va_list vargs) throws FooError {
+}
+
+void main () {
+ try {
+ print_something_throws (true, "%s", "foo");
+ int i;
+ scan_something_throws (false, "%d", out i);
+ } catch (FooError e) {
+ }
+}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]