Alexandre Julliard : include: Make wine_dbg_printf() into an inline function.
Alexandre Julliard
julliard at winehq.org
Wed Apr 3 15:26:18 CDT 2019
Module: wine
Branch: master
Commit: ddf1ff2f6ae39e6962441a5a88439755ff72c525
URL: https://source.winehq.org/git/wine.git/?a=commit;h=ddf1ff2f6ae39e6962441a5a88439755ff72c525
Author: Alexandre Julliard <julliard at winehq.org>
Date: Wed Apr 3 19:24:39 2019 +0200
include: Make wine_dbg_printf() into an inline function.
Signed-off-by: Alexandre Julliard <julliard at winehq.org>
---
dlls/ntdll/debugtools.c | 34 ++++++++++++++++++++++++++++++++++
dlls/ntdll/ntdll.spec | 1 +
include/wine/debug.h | 14 +++++++++++++-
libs/wine/debug.c | 2 ++
4 files changed, 50 insertions(+), 1 deletion(-)
diff --git a/dlls/ntdll/debugtools.c b/dlls/ntdll/debugtools.c
index 42db30a..9c3add4 100644
--- a/dlls/ntdll/debugtools.c
+++ b/dlls/ntdll/debugtools.c
@@ -74,6 +74,20 @@ static void release_temp_buffer( char *ptr, size_t size )
info->str_pos = ptr + size;
}
+/* add a string to the output buffer */
+static int append_output( struct debug_info *info, const char *str, size_t len )
+{
+ if (len >= sizeof(info->output) - (info->out_pos - info->output))
+ {
+ fprintf( stderr, "wine_dbg_output: debugstr buffer overflow (contents: '%s')\n", info->output );
+ info->out_pos = info->output;
+ abort();
+ }
+ memcpy( info->out_pos, str, len );
+ info->out_pos += len;
+ return len;
+}
+
/***********************************************************************
* __wine_dbg_strdup (NTDLL.@)
*/
@@ -89,6 +103,26 @@ const char * __cdecl __wine_dbg_strdup( const char *str )
}
/***********************************************************************
+ * __wine_dbg_output (NTDLL.@)
+ */
+int __cdecl __wine_dbg_output( const char *str )
+{
+ struct debug_info *info = get_info();
+ const char *end = strrchr( str, '\n' );
+ int ret = 0;
+
+ if (end)
+ {
+ ret += append_output( info, str, end + 1 - str );
+ write( 2, info->output, info->out_pos - info->output );
+ info->out_pos = info->output;
+ str = end + 1;
+ }
+ if (*str) ret += append_output( info, str, strlen( str ));
+ return ret;
+}
+
+/***********************************************************************
* NTDLL_dbg_vprintf
*/
static int NTDLL_dbg_vprintf( const char *format, va_list args )
diff --git a/dlls/ntdll/ntdll.spec b/dlls/ntdll/ntdll.spec
index 7622289..98991ad 100644
--- a/dlls/ntdll/ntdll.spec
+++ b/dlls/ntdll/ntdll.spec
@@ -1506,6 +1506,7 @@
@ cdecl __wine_make_process_system()
# Debugging
+@ cdecl -norelay __wine_dbg_output(str)
@ cdecl -norelay __wine_dbg_strdup(str)
# Virtual memory
diff --git a/include/wine/debug.h b/include/wine/debug.h
index fd8e56e..2412c2b 100644
--- a/include/wine/debug.h
+++ b/include/wine/debug.h
@@ -162,6 +162,7 @@ extern int __wine_dbg_set_channel_flags( struct __wine_debug_channel *channel,
extern void __wine_dbg_set_functions( const struct __wine_debug_functions *new_funcs,
struct __wine_debug_functions *old_funcs, size_t size );
extern const char * __cdecl __wine_dbg_strdup( const char *str );
+extern int __cdecl __wine_dbg_output( const char *str );
/*
* Exported definitions and macros
@@ -171,7 +172,6 @@ extern const char * __cdecl __wine_dbg_strdup( const char *str );
quotes. The string will be valid for some time, but not indefinitely
as strings are re-used. */
-extern int wine_dbg_printf( const char *format, ... ) __WINE_PRINTF_ATTR(1,2);
extern int wine_dbg_log( enum __wine_debug_class cls, struct __wine_debug_channel *ch, const char *func,
const char *format, ... ) __WINE_PRINTF_ATTR(4,5);
@@ -199,6 +199,18 @@ static inline const char * __wine_dbg_cdecl wine_dbg_sprintf( const char *format
return __wine_dbg_strdup( buffer );
}
+static int __wine_dbg_cdecl wine_dbg_printf( const char *format, ... ) __WINE_PRINTF_ATTR(1,2);
+static inline int __wine_dbg_cdecl wine_dbg_printf( const char *format, ... )
+{
+ char buffer[1024];
+ __wine_dbg_va_list args;
+
+ __wine_dbg_va_start( args, format );
+ vsnprintf( buffer, sizeof(buffer), format, args );
+ __wine_dbg_va_end( args );
+ return __wine_dbg_output( buffer );
+}
+
static inline const char *wine_dbgstr_an( const char *str, int n )
{
static const char hex[16] = "0123456789abcdef";
diff --git a/libs/wine/debug.c b/libs/wine/debug.c
index 1bf59dd..2d56b01 100644
--- a/libs/wine/debug.c
+++ b/libs/wine/debug.c
@@ -31,6 +31,7 @@
#endif
#define wine_dbg_sprintf wine_dbg_sprintf_inline
+#define wine_dbg_printf wine_dbg_printf_inline
#define wine_dbgstr_an wine_dbgstr_an_inline
#define wine_dbgstr_wn wine_dbgstr_wn_inline
#include "wine/debug.h"
@@ -217,6 +218,7 @@ static void debug_init(void)
}
/* varargs wrapper for funcs.dbg_vprintf */
+#undef wine_dbg_printf
int wine_dbg_printf( const char *format, ... )
{
int ret;
More information about the wine-cvs
mailing list