|
From: Bart V. A. <bar...@gm...> - 2008-07-02 12:08:27
|
On Tue, Jul 1, 2008 at 10:02 AM, Dirk Mueller <dm...@gm...> wrote:
> VG_(printf) uses "%t" as a "xml-escaped %s" attribute. This does not if gcc
> format checking is enabled, as %t is a nonstandard extension, which it doesn't
> understand. I've asked you some time ago wether it would be okay to either map
> it to "%s" and use a ToXml function for the argument, or to use a completely
> different (non printf-like) function for xml output. I guess the latter makes
> more sense, as line formatting (printf) doesn't really make sense with xml
> output, the stream output can be abstracted into something else.
How about the code below ? The patch below defines two variants of the
same function, namely VG_(xml_message)() and VG_(message)(). Format
string checking is disabled for the former and enabled for the latter.
This way the %t format specifier does not trigger a warning when
passed to VG_(xml_message)().
Bart.
Index: include/pub_tool_libcprint.h
===================================================================
--- include/pub_tool_libcprint.h (revision 8323)
+++ include/pub_tool_libcprint.h (working copy)
@@ -85,12 +85,11 @@
VgMsgKind;
/* Send a single-part message. Appends a newline. */
+extern UInt VG_(xml_message)( VgMsgKind kind, const HChar* format, ... );
extern UInt VG_(message) ( VgMsgKind kind, const HChar* format,
... ) PRINTF_CHECK(2, 3);
extern UInt VG_(vmessage) ( VgMsgKind kind, const HChar* format,
va_list vargs ) PRINTF_CHECK(2, 0);
-/* Convert a string such that it can be inserted into an XML output stream. */
-extern HChar* VG_(ToXML)(HChar* buf, Int size, const HChar* str);
#endif // __PUB_TOOL_LIBCPRINT_H
Index: coregrind/m_libcprint.c
===================================================================
--- coregrind/m_libcprint.c (revision 8323)
+++ coregrind/m_libcprint.c (working copy)
@@ -285,47 +285,6 @@
/* ---------------------------------------------------------------------
- ToXML()
- ------------------------------------------------------------------ */
-
-struct xml_buf {
- HChar* cur;
- HChar* end;
-};
-
-static void append_to_xml_buf(const HChar ch, void* arg2)
-{
- struct xml_buf* const xml_buf = arg2;
-
- if (xml_buf->cur < xml_buf->end)
- {
- *xml_buf->cur++ = ch;
- }
- else
- {
- /* Make sure that it gets noticed if a buffer is too small. */
- vg_assert(False);
- }
-}
-
-/* Convert a string such that it can be inserted into an XML output stream. */
-
-extern HChar* VG_(ToXML)(HChar* const buf, const Int size,
- const HChar* str)
-{
- static struct xml_buf xml_buf;
-
- if (str == NULL)
- str = "(null)";
- xml_buf.cur = buf;
- xml_buf.end = buf + size - 1;
- myvprintf_str_XML_simplistic(append_to_xml_buf, &xml_buf, str);
- *xml_buf.cur++ = 0;
- return buf;
-}
-
-
-/* ---------------------------------------------------------------------
elapsed_wallclock_time()
------------------------------------------------------------------ */
@@ -407,6 +366,16 @@
}
/* Send a simple single-part message. */
+UInt VG_(xml_message) ( VgMsgKind kind, const HChar* format, ... )
+{
+ UInt count;
+ va_list vargs;
+ va_start(vargs,format);
+ count = VG_(vmessage) ( kind, format, vargs );
+ va_end(vargs);
+ return count;
+}
+
UInt VG_(message) ( VgMsgKind kind, const HChar* format, ... )
{
UInt count;
|