freetype-commit
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[freetype2] master 0338048: [builds/windows] Improve debugging.


From: Werner Lemberg
Subject: [freetype2] master 0338048: [builds/windows] Improve debugging.
Date: Mon, 29 Nov 2021 20:54:31 -0500 (EST)

branch: master
commit 03380482ce6c89b015b06dd22efced4aba66d418
Author: Alexei Podtelezhnikov <apodtele@gmail.com>
Commit: Alexei Podtelezhnikov <apodtele@gmail.com>

    [builds/windows] Improve debugging.
    
    * builds/windows/ftdebug.c (FT_Message, FT_Panic): Buffer output
    and call `OutputDebugStringA` only if `IsDebuggerPresent`.
    [_WIN32_WCE] (OutputDebugStringA): Implement the missing API.
---
 builds/windows/ftdebug.c | 61 +++++++++++++++++++++++++++++++++++++-----------
 1 file changed, 48 insertions(+), 13 deletions(-)

diff --git a/builds/windows/ftdebug.c b/builds/windows/ftdebug.c
index f7f65f6..94c22da 100644
--- a/builds/windows/ftdebug.c
+++ b/builds/windows/ftdebug.c
@@ -93,28 +93,57 @@
 
 #ifdef FT_DEBUG_LEVEL_ERROR
 
-#include <stdarg.h>
-#include <stdlib.h>
-#include <string.h>
-
+#define WIN32_LEAN_AND_MEAN
 #include <windows.h>
 
 
+#ifdef _WIN32_WCE
+
+  FT_LOACAL_DEF( void )
+  OutputDebugStringA( LPCSTR lpOutputString )
+  {
+    int            len;
+    LPWSTR         lpOutputStringW;
+
+
+    /* allocate memory space for converted string */
+    len = MultiByteToWideChar( CP_ACP, MB_ERR_INVALID_CHARS,
+                               lpOutputString, -1, NULL, 0 );
+
+    lpOutputStringW = (LPWSTR)_alloca( len * sizeof ( WCHAR ) );
+
+    if ( !len || !lpOutputStringW )
+      return;
+
+    /* now it is safe to do the translation */
+    MultiByteToWideChar( CP_ACP, MB_ERR_INVALID_CHARS,
+                         lpOutputString, -1, lpOutputStringW, len );
+
+    OutputDebugStringW( lpOutputStringW );
+  }
+
+#endif /* _WIN32_WCE */
+
+
   /* documentation is in ftdebug.h */
 
   FT_BASE_DEF( void )
   FT_Message( const char*  fmt,
               ... )
   {
-    static char  buf[8192];
-    va_list      ap;
+    va_list  ap;
 
 
     va_start( ap, fmt );
     vfprintf( stderr, fmt, ap );
-    /* send the string to the debugger as well */
-    vsprintf( buf, fmt, ap );
-    OutputDebugStringA( buf );
+    if ( IsDebuggerPresent() )
+    {
+      static char  buf[1024];
+
+
+      vsnprintf( buf, sizeof buf, fmt, ap );
+      OutputDebugStringA( buf );
+    }
     va_end( ap );
   }
 
@@ -125,13 +154,19 @@
   FT_Panic( const char*  fmt,
             ... )
   {
-    static char  buf[8192];
-    va_list      ap;
+    va_list  ap;
 
 
     va_start( ap, fmt );
-    vsprintf( buf, fmt, ap );
-    OutputDebugStringA( buf );
+    vfprintf( stderr, fmt, ap );
+    if ( IsDebuggerPresent() )
+    {
+      static char  buf[1024];
+
+
+      vsnprintf( buf, sizeof buf, fmt, ap );
+      OutputDebugStringA( buf );
+    }
     va_end( ap );
 
     exit( EXIT_FAILURE );



reply via email to

[Prev in Thread] Current Thread [Next in Thread]