Commit 7d5a61e3 authored by Jürg Billeter's avatar Jürg Billeter

Support [ScanfFormat] attribute

Fixes bug 589930.
parent bef8df5b
......@@ -3228,7 +3228,7 @@ internal class Vala.CCodeBaseModule : CCodeModule {
if (ellipsis) {
/* ensure variable argument list ends with NULL
* except when using printf-style arguments */
if (!m.printf_format && m.sentinel != "") {
if (!m.printf_format && !m.scanf_format && m.sentinel != "") {
creation_call.add_argument (new CCodeConstant (m.sentinel));
}
}
......
......@@ -556,7 +556,7 @@ internal class Vala.CCodeMethodCallModule : CCodeAssignmentModule {
if (ellipsis) {
/* ensure variable argument list ends with NULL
* except when using printf-style arguments */
if (!m.printf_format && m.sentinel != "") {
if (!m.printf_format && !m.scanf_format && m.sentinel != "") {
in_arg_map.set (get_param_pos (-1, true), new CCodeConstant (m.sentinel));
}
} else if (itype is DelegateType) {
......
......@@ -826,6 +826,10 @@ public class Vala.CodeWriter : CodeVisitor {
write_indent ();
write_string ("[PrintfFormat]");
}
if (m.scanf_format) {
write_indent ();
write_string ("[ScanfFormat]");
}
var ccode_params = new StringBuilder ();
var separator = "";
......
......@@ -194,6 +194,11 @@ public class Vala.Method : Member {
*/
public bool printf_format { get; set; }
/**
* Specifies whether this method expects scanf-style format arguments.
*/
public bool scanf_format { get; set; }
/**
* Specifies whether a construct function with a GType parameter is
* available. This is only applicable to creation methods.
......@@ -401,6 +406,8 @@ public class Vala.Method : Member {
return_type.floating_reference = true;
} else if (a.name == "PrintfFormat") {
printf_format = true;
} else if (a.name == "ScanfFormat") {
scanf_format = true;
}
}
}
......
......@@ -818,7 +818,7 @@ public class string {
public bool has_suffix (string suffix);
[CCode (cname = "g_strdup_printf"), PrintfFormat]
public string printf (...);
[CCode (cname = "sscanf", cheader_filename = "stdio.h")]
[CCode (cname = "sscanf", cheader_filename = "stdio.h"), ScanfFormat]
public int scanf (...);
[CCode (cname = "g_strconcat")]
public string concat (string string2, ...);
......@@ -2402,7 +2402,7 @@ namespace GLib {
public weak string gets (char[] s);
[CCode (cname = "feof")]
public bool eof ();
[CCode (cname = "fscanf")]
[CCode (cname = "fscanf"), ScanfFormat]
public int scanf (string format, ...);
[CCode (cname = "fflush")]
public int flush ();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment