Add a test for positional parameters in g_snprintf(). Use g_printf()

* tests/string-test.c: Add a test for positional parameters in
	g_snprintf().
	* glib-genmarshal.c, gobject-query.c: Use g_printf() instead of
	system printf.  (#99319)
This commit is contained in:
Matthias Clasen 2002-12-12 23:52:29 +00:00
parent ab5fe79f8a
commit 37e7e80e5b
11 changed files with 135 additions and 90 deletions

View File

@ -1,3 +1,8 @@
2002-12-13 Matthias Clasen <maclas@gmx.de>
* tests/string-test.c: Add a test for positional parameters in
g_snprintf().
Thu Dec 12 14:58:55 2002 Manish Singh <yosh@gimp.org> Thu Dec 12 14:58:55 2002 Manish Singh <yosh@gimp.org>
* configure.in: pull in trio if host printf doesn't have a known * configure.in: pull in trio if host printf doesn't have a known

View File

@ -1,3 +1,8 @@
2002-12-13 Matthias Clasen <maclas@gmx.de>
* tests/string-test.c: Add a test for positional parameters in
g_snprintf().
Thu Dec 12 14:58:55 2002 Manish Singh <yosh@gimp.org> Thu Dec 12 14:58:55 2002 Manish Singh <yosh@gimp.org>
* configure.in: pull in trio if host printf doesn't have a known * configure.in: pull in trio if host printf doesn't have a known

View File

@ -1,3 +1,8 @@
2002-12-13 Matthias Clasen <maclas@gmx.de>
* tests/string-test.c: Add a test for positional parameters in
g_snprintf().
Thu Dec 12 14:58:55 2002 Manish Singh <yosh@gimp.org> Thu Dec 12 14:58:55 2002 Manish Singh <yosh@gimp.org>
* configure.in: pull in trio if host printf doesn't have a known * configure.in: pull in trio if host printf doesn't have a known

View File

@ -1,3 +1,8 @@
2002-12-13 Matthias Clasen <maclas@gmx.de>
* tests/string-test.c: Add a test for positional parameters in
g_snprintf().
Thu Dec 12 14:58:55 2002 Manish Singh <yosh@gimp.org> Thu Dec 12 14:58:55 2002 Manish Singh <yosh@gimp.org>
* configure.in: pull in trio if host printf doesn't have a known * configure.in: pull in trio if host printf doesn't have a known

View File

@ -1,3 +1,8 @@
2002-12-13 Matthias Clasen <maclas@gmx.de>
* tests/string-test.c: Add a test for positional parameters in
g_snprintf().
Thu Dec 12 14:58:55 2002 Manish Singh <yosh@gimp.org> Thu Dec 12 14:58:55 2002 Manish Singh <yosh@gimp.org>
* configure.in: pull in trio if host printf doesn't have a known * configure.in: pull in trio if host printf doesn't have a known

View File

@ -1,3 +1,8 @@
2002-12-13 Matthias Clasen <maclas@gmx.de>
* tests/string-test.c: Add a test for positional parameters in
g_snprintf().
Thu Dec 12 14:58:55 2002 Manish Singh <yosh@gimp.org> Thu Dec 12 14:58:55 2002 Manish Singh <yosh@gimp.org>
* configure.in: pull in trio if host printf doesn't have a known * configure.in: pull in trio if host printf doesn't have a known

View File

@ -1,3 +1,8 @@
2002-12-13 Matthias Clasen <maclas@gmx.de>
* tests/string-test.c: Add a test for positional parameters in
g_snprintf().
Thu Dec 12 14:58:55 2002 Manish Singh <yosh@gimp.org> Thu Dec 12 14:58:55 2002 Manish Singh <yosh@gimp.org>
* configure.in: pull in trio if host printf doesn't have a known * configure.in: pull in trio if host printf doesn't have a known

View File

@ -1,3 +1,8 @@
2002-12-13 Matthias Clasen <maclas@gmx.de>
* glib-genmarshal.c, gobject-query.c: Use g_printf() instead of
system printf. (#99319)
Thu Dec 12 15:00:10 2002 Manish Singh <yosh@gimp.org> Thu Dec 12 15:00:10 2002 Manish Singh <yosh@gimp.org>
* gvaluetransform.c: use G_G[U]INT64_FORMAT unconditionally, * gvaluetransform.c: use G_G[U]INT64_FORMAT unconditionally,

View File

@ -22,7 +22,7 @@
#define G_LOG_DOMAIN "GLib-Genmarshal" #define G_LOG_DOMAIN "GLib-Genmarshal"
#include <glib.h> #include <glib.h>
#include <stdio.h> #include <glib/gprintf.h>
#include <stdlib.h> #include <stdlib.h>
#include <fcntl.h> #include <fcntl.h>
#include <string.h> #include <string.h>
@ -352,57 +352,57 @@ generate_marshal (const gchar *signame,
if (gen_cheader && have_std_marshaller) if (gen_cheader && have_std_marshaller)
{ {
fprintf (fout, "#define %s_%s\t%s_%s\n", marshaller_prefix, signame, std_marshaller_prefix, signame); g_fprintf (fout, "#define %s_%s\t%s_%s\n", marshaller_prefix, signame, std_marshaller_prefix, signame);
} }
if (gen_cheader && !have_std_marshaller) if (gen_cheader && !have_std_marshaller)
{ {
ind = fprintf (fout, "extern void "); ind = g_fprintf (fout, "extern void ");
ind += fprintf (fout, "%s_%s (", marshaller_prefix, signame); ind += g_fprintf (fout, "%s_%s (", marshaller_prefix, signame);
fprintf (fout, "GClosure *closure,\n"); g_fprintf (fout, "GClosure *closure,\n");
fprintf (fout, "%sGValue *return_value,\n", indent (ind)); g_fprintf (fout, "%sGValue *return_value,\n", indent (ind));
fprintf (fout, "%sguint n_param_values,\n", indent (ind)); g_fprintf (fout, "%sguint n_param_values,\n", indent (ind));
fprintf (fout, "%sconst GValue *param_values,\n", indent (ind)); g_fprintf (fout, "%sconst GValue *param_values,\n", indent (ind));
fprintf (fout, "%sgpointer invocation_hint,\n", indent (ind)); g_fprintf (fout, "%sgpointer invocation_hint,\n", indent (ind));
fprintf (fout, "%sgpointer marshal_data);\n", indent (ind)); g_fprintf (fout, "%sgpointer marshal_data);\n", indent (ind));
} }
if (gen_cbody && !have_std_marshaller) if (gen_cbody && !have_std_marshaller)
{ {
/* cfile marhsal header */ /* cfile marhsal header */
fprintf (fout, "void\n"); g_fprintf (fout, "void\n");
ind = fprintf (fout, "%s_%s (", marshaller_prefix, signame); ind = g_fprintf (fout, "%s_%s (", marshaller_prefix, signame);
fprintf (fout, "GClosure *closure,\n"); g_fprintf (fout, "GClosure *closure,\n");
fprintf (fout, "%sGValue *return_value,\n", indent (ind)); g_fprintf (fout, "%sGValue *return_value,\n", indent (ind));
fprintf (fout, "%sguint n_param_values,\n", indent (ind)); g_fprintf (fout, "%sguint n_param_values,\n", indent (ind));
fprintf (fout, "%sconst GValue *param_values,\n", indent (ind)); g_fprintf (fout, "%sconst GValue *param_values,\n", indent (ind));
fprintf (fout, "%sgpointer invocation_hint,\n", indent (ind)); g_fprintf (fout, "%sgpointer invocation_hint,\n", indent (ind));
fprintf (fout, "%sgpointer marshal_data)\n", indent (ind)); g_fprintf (fout, "%sgpointer marshal_data)\n", indent (ind));
fprintf (fout, "{\n"); g_fprintf (fout, "{\n");
/* cfile GMarshalFunc typedef */ /* cfile GMarshalFunc typedef */
ind = fprintf (fout, " typedef %s (*GMarshalFunc_%s) (", sig->rarg->ctype, signame); ind = g_fprintf (fout, " typedef %s (*GMarshalFunc_%s) (", sig->rarg->ctype, signame);
fprintf (fout, "%s data1,\n", pad ("gpointer")); g_fprintf (fout, "%s data1,\n", pad ("gpointer"));
for (a = 1, node = sig->args; node; node = node->next) for (a = 1, node = sig->args; node; node = node->next)
{ {
InArgument *iarg = node->data; InArgument *iarg = node->data;
if (iarg->getter) if (iarg->getter)
fprintf (fout, "%s%s arg_%d,\n", indent (ind), pad (iarg->ctype), a++); g_fprintf (fout, "%s%s arg_%d,\n", indent (ind), pad (iarg->ctype), a++);
} }
fprintf (fout, "%s%s data2);\n", indent (ind), pad ("gpointer")); g_fprintf (fout, "%s%s data2);\n", indent (ind), pad ("gpointer"));
/* cfile marshal variables */ /* cfile marshal variables */
fprintf (fout, " register GMarshalFunc_%s callback;\n", signame); g_fprintf (fout, " register GMarshalFunc_%s callback;\n", signame);
fprintf (fout, " register GCClosure *cc = (GCClosure*) closure;\n"); g_fprintf (fout, " register GCClosure *cc = (GCClosure*) closure;\n");
fprintf (fout, " register gpointer data1, data2;\n"); g_fprintf (fout, " register gpointer data1, data2;\n");
if (sig->rarg->setter) if (sig->rarg->setter)
fprintf (fout, " %s v_return;\n", sig->rarg->ctype); g_fprintf (fout, " %s v_return;\n", sig->rarg->ctype);
if (sig->args || sig->rarg->setter) if (sig->args || sig->rarg->setter)
{ {
fprintf (fout, "\n"); g_fprintf (fout, "\n");
if (sig->rarg->setter) if (sig->rarg->setter)
fprintf (fout, " g_return_if_fail (return_value != NULL);\n"); g_fprintf (fout, " g_return_if_fail (return_value != NULL);\n");
if (sig->args) if (sig->args)
{ {
for (a = 0, node = sig->args; node; node = node->next) for (a = 0, node = sig->args; node; node = node->next)
@ -412,43 +412,43 @@ generate_marshal (const gchar *signame,
if (iarg->getter) if (iarg->getter)
a++; a++;
} }
fprintf (fout, " g_return_if_fail (n_param_values == %u);\n", 1 + a); g_fprintf (fout, " g_return_if_fail (n_param_values == %u);\n", 1 + a);
} }
} }
/* cfile marshal data1, data2 and callback setup */ /* cfile marshal data1, data2 and callback setup */
fprintf (fout, "\n"); g_fprintf (fout, "\n");
fprintf (fout, " if (G_CCLOSURE_SWAP_DATA (closure))\n {\n"); g_fprintf (fout, " if (G_CCLOSURE_SWAP_DATA (closure))\n {\n");
fprintf (fout, " data1 = closure->data;\n"); g_fprintf (fout, " data1 = closure->data;\n");
fprintf (fout, " data2 = g_value_peek_pointer (param_values + 0);\n"); g_fprintf (fout, " data2 = g_value_peek_pointer (param_values + 0);\n");
fprintf (fout, " }\n else\n {\n"); g_fprintf (fout, " }\n else\n {\n");
fprintf (fout, " data1 = g_value_peek_pointer (param_values + 0);\n"); g_fprintf (fout, " data1 = g_value_peek_pointer (param_values + 0);\n");
fprintf (fout, " data2 = closure->data;\n"); g_fprintf (fout, " data2 = closure->data;\n");
fprintf (fout, " }\n"); g_fprintf (fout, " }\n");
fprintf (fout, " callback = (GMarshalFunc_%s) (marshal_data ? marshal_data : cc->callback);\n", signame); g_fprintf (fout, " callback = (GMarshalFunc_%s) (marshal_data ? marshal_data : cc->callback);\n", signame);
/* cfile marshal callback action */ /* cfile marshal callback action */
fprintf (fout, "\n"); g_fprintf (fout, "\n");
ind = fprintf (fout, " %s callback (", sig->rarg->setter ? " v_return =" : ""); ind = g_fprintf (fout, " %s callback (", sig->rarg->setter ? " v_return =" : "");
fprintf (fout, "data1,\n"); g_fprintf (fout, "data1,\n");
for (a = 1, node = sig->args; node; node = node->next) for (a = 1, node = sig->args; node; node = node->next)
{ {
InArgument *iarg = node->data; InArgument *iarg = node->data;
if (iarg->getter) if (iarg->getter)
fprintf (fout, "%s%s (param_values + %d),\n", indent (ind), iarg->getter, a++); g_fprintf (fout, "%s%s (param_values + %d),\n", indent (ind), iarg->getter, a++);
} }
fprintf (fout, "%sdata2);\n", indent (ind)); g_fprintf (fout, "%sdata2);\n", indent (ind));
/* cfile marshal return value storage */ /* cfile marshal return value storage */
if (sig->rarg->setter) if (sig->rarg->setter)
{ {
fprintf (fout, "\n"); g_fprintf (fout, "\n");
fprintf (fout, " %s (return_value, v_return);\n", sig->rarg->setter); g_fprintf (fout, " %s (return_value, v_return);\n", sig->rarg->setter);
} }
/* cfile marshal footer */ /* cfile marshal footer */
fprintf (fout, "}\n"); g_fprintf (fout, "}\n");
} }
} }
@ -492,16 +492,16 @@ process_signature (Signature *sig)
} }
/* introductionary comment */ /* introductionary comment */
fprintf (fout, "\n/* %s", sig->rarg->keyword); g_fprintf (fout, "\n/* %s", sig->rarg->keyword);
for (node = sig->args; node; node = node->next) for (node = sig->args; node; node = node->next)
{ {
InArgument *iarg = node->data; InArgument *iarg = node->data;
fprintf (fout, "%c%s", node->prev ? ',' : ':', iarg->keyword); g_fprintf (fout, "%c%s", node->prev ? ',' : ':', iarg->keyword);
} }
if (!skip_ploc) if (!skip_ploc)
fprintf (fout, " (%s)", sig->ploc); g_fprintf (fout, " (%s)", sig->ploc);
fprintf (fout, " */\n"); g_fprintf (fout, " */\n");
/* ensure technical marshaller exists (<marshaller_prefix>_<sname>) */ /* ensure technical marshaller exists (<marshaller_prefix>_<sname>) */
generate_marshal (sname, sig); generate_marshal (sname, sig);
@ -510,7 +510,7 @@ process_signature (Signature *sig)
tmp = g_strconcat (marshaller_prefix, "_", pname, NULL); tmp = g_strconcat (marshaller_prefix, "_", pname, NULL);
if (gen_cheader && !g_hash_table_lookup (marshallers, tmp)) if (gen_cheader && !g_hash_table_lookup (marshallers, tmp))
{ {
fprintf (fout, "#define %s_%s\t%s_%s\n", marshaller_prefix, pname, marshaller_prefix, sname); g_fprintf (fout, "#define %s_%s\t%s_%s\n", marshaller_prefix, pname, marshaller_prefix, sname);
g_hash_table_insert (marshallers, tmp, tmp); g_hash_table_insert (marshallers, tmp, tmp);
} }
@ -630,19 +630,19 @@ main (int argc,
} }
/* put out initial heading */ /* put out initial heading */
fprintf (fout, "\n"); g_fprintf (fout, "\n");
if (gen_cheader && std_includes) if (gen_cheader && std_includes)
{ {
fprintf (fout, "#ifndef __%s_MARSHAL_H__\n", marshaller_prefix); g_fprintf (fout, "#ifndef __%s_MARSHAL_H__\n", marshaller_prefix);
fprintf (fout, "#define __%s_MARSHAL_H__\n\n", marshaller_prefix); g_fprintf (fout, "#define __%s_MARSHAL_H__\n\n", marshaller_prefix);
} }
if ((gen_cheader || gen_cbody) && std_includes) if ((gen_cheader || gen_cbody) && std_includes)
fprintf (fout, "#include\t<glib-object.h>\n\n"); g_fprintf (fout, "#include\t<glib-object.h>\n\n");
if (gen_cheader) if (gen_cheader)
fprintf (fout, "G_BEGIN_DECLS\n"); g_fprintf (fout, "G_BEGIN_DECLS\n");
/* generate necessary preprocessor directives */ /* generate necessary preprocessor directives */
if (gen_cbody) if (gen_cbody)
@ -730,12 +730,12 @@ main (int argc,
/* put out trailer */ /* put out trailer */
if (gen_cheader) if (gen_cheader)
{ {
fprintf (fout, "\nG_END_DECLS\n"); g_fprintf (fout, "\nG_END_DECLS\n");
if (std_includes) if (std_includes)
fprintf (fout, "\n#endif /* __%s_MARSHAL_H__ */\n", marshaller_prefix); g_fprintf (fout, "\n#endif /* __%s_MARSHAL_H__ */\n", marshaller_prefix);
} }
fprintf (fout, "\n"); g_fprintf (fout, "\n");
/* clean up */ /* clean up */
g_slist_free (files); g_slist_free (files);
@ -846,25 +846,25 @@ print_blurb (FILE *bout,
{ {
if (!print_help) if (!print_help)
{ {
fprintf (bout, "%s version ", PRG_NAME); g_fprintf (bout, "%s version ", PRG_NAME);
fprintf (bout, "%u.%u.%u", GLIB_MAJOR_VERSION, GLIB_MINOR_VERSION, GLIB_MICRO_VERSION); g_fprintf (bout, "%u.%u.%u", GLIB_MAJOR_VERSION, GLIB_MINOR_VERSION, GLIB_MICRO_VERSION);
fprintf (bout, "\n"); g_fprintf (bout, "\n");
fprintf (bout, "%s comes with ABSOLUTELY NO WARRANTY.\n", PRG_NAME); g_fprintf (bout, "%s comes with ABSOLUTELY NO WARRANTY.\n", PRG_NAME);
fprintf (bout, "You may redistribute copies of %s under the terms of\n", PRG_NAME); g_fprintf (bout, "You may redistribute copies of %s under the terms of\n", PRG_NAME);
fprintf (bout, "the GNU General Public License which can be found in the\n"); g_fprintf (bout, "the GNU General Public License which can be found in the\n");
fprintf (bout, "%s source package. Sources, examples and contact\n", PKG_NAME); g_fprintf (bout, "%s source package. Sources, examples and contact\n", PKG_NAME);
fprintf (bout, "information are available at %s\n", PKG_HTTP_HOME); g_fprintf (bout, "information are available at %s\n", PKG_HTTP_HOME);
} }
else else
{ {
fprintf (bout, "Usage: %s [options] [files...]\n", PRG_NAME); g_fprintf (bout, "Usage: %s [options] [files...]\n", PRG_NAME);
fprintf (bout, " --header generate C headers\n"); g_fprintf (bout, " --header generate C headers\n");
fprintf (bout, " --body generate C code\n"); g_fprintf (bout, " --body generate C code\n");
fprintf (bout, " --prefix=string specify marshaller prefix\n"); g_fprintf (bout, " --prefix=string specify marshaller prefix\n");
fprintf (bout, " --skip-source skip source location comments\n"); g_fprintf (bout, " --skip-source skip source location comments\n");
fprintf (bout, " --stdinc, --nostdinc include/use standard marshallers\n"); g_fprintf (bout, " --stdinc, --nostdinc include/use standard marshallers\n");
fprintf (bout, " -h, --help show this help message\n"); g_fprintf (bout, " -h, --help show this help message\n");
fprintf (bout, " -v, --version print version informations\n"); g_fprintf (bout, " -v, --version print version informations\n");
fprintf (bout, " --g-fatal-warnings make warnings fatal (abort)\n"); g_fprintf (bout, " --g-fatal-warnings make warnings fatal (abort)\n");
} }
} }

View File

@ -20,7 +20,7 @@
#include <glib-object.h> #include <glib-object.h>
#include <stdio.h> #include <glib/gprintf.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#ifdef HAVE_UNISTD_H #ifdef HAVE_UNISTD_H
@ -66,9 +66,9 @@ show_nodes (GType type,
if (type != root) if (type != root)
for (i = 0; i < spacing; i++) for (i = 0; i < spacing; i++)
fprintf (f_out, "%s%s\n", indent, O_VLINE); g_fprintf (f_out, "%s%s\n", indent, O_VLINE);
fprintf (f_out, "%s%s%s%s", g_fprintf (f_out, "%s%s%s%s",
indent, indent,
sibling ? O_BRANCH : (type != root ? O_LLEAF : O_SPACE), sibling ? O_BRANCH : (type != root ? O_LLEAF : O_SPACE),
O_ESPACE, O_ESPACE,
@ -101,16 +101,16 @@ show_nodes (GType type,
static gint static gint
help (gchar *arg) help (gchar *arg)
{ {
fprintf (stderr, "usage: query <qualifier> [-r <type>] [-{i|b} \"\"] [-s #] [-{h|x|y}]\n"); g_fprintf (stderr, "usage: query <qualifier> [-r <type>] [-{i|b} \"\"] [-s #] [-{h|x|y}]\n");
fprintf (stderr, " -r specifiy root type\n"); g_fprintf (stderr, " -r specifiy root type\n");
fprintf (stderr, " -n don't descend type tree\n"); g_fprintf (stderr, " -n don't descend type tree\n");
fprintf (stderr, " -h guess what ;)\n"); g_fprintf (stderr, " -h guess what ;)\n");
fprintf (stderr, " -b specify indent string\n"); g_fprintf (stderr, " -b specify indent string\n");
fprintf (stderr, " -i specify incremental indent string\n"); g_fprintf (stderr, " -i specify incremental indent string\n");
fprintf (stderr, " -s specify line spacing\n"); g_fprintf (stderr, " -s specify line spacing\n");
fprintf (stderr, "qualifiers:\n"); g_fprintf (stderr, "qualifiers:\n");
fprintf (stderr, " froots iterate over fundamental roots\n"); g_fprintf (stderr, " froots iterate over fundamental roots\n");
fprintf (stderr, " tree print type tree\n"); g_fprintf (stderr, " tree print type tree\n");
return arg != NULL; return arg != NULL;
} }

View File

@ -30,6 +30,7 @@
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>
#include "glib.h" #include "glib.h"
#include "glib/gprintf.h"
int array[10000]; int array[10000];
gboolean failed = FALSE; gboolean failed = FALSE;
@ -226,6 +227,10 @@ main (int argc,
g_assert (g_str_has_suffix("", "xyzzy") == FALSE); g_assert (g_str_has_suffix("", "xyzzy") == FALSE);
g_assert (g_str_has_suffix("", "") == TRUE); g_assert (g_str_has_suffix("", "") == TRUE);
tmp_string = (gchar *) g_malloc (10);
g_snprintf (tmp_string, 10, "%2$s %1$s", "a", "b");
g_assert (strcmp (tmp_string, "b a") == 0);
return 0; return 0;
} }