[ros-diffs] [tkreuzer] 48432: [CRT] Implement a proper version of _assert. It nows shows a message box with the details and let's the user choose to either abort, debug or ignore the assertion. See bug 5486, bug 5507, bug 5511

tkreuzer at svn.reactos.org tkreuzer at svn.reactos.org
Tue Aug 3 16:09:34 UTC 2010


Author: tkreuzer
Date: Tue Aug  3 16:09:33 2010
New Revision: 48432

URL: http://svn.reactos.org/svn/reactos?rev=48432&view=rev
Log:
[CRT]
Implement a proper version of _assert. It nows shows a message box with the details and let's the user choose to either abort, debug or ignore the assertion.
See bug 5486, bug 5507, bug 5511

Modified:
    trunk/reactos/lib/sdk/crt/misc/assert.c

Modified: trunk/reactos/lib/sdk/crt/misc/assert.c
URL: http://svn.reactos.org/svn/reactos/trunk/reactos/lib/sdk/crt/misc/assert.c?rev=48432&r1=48431&r2=48432&view=diff
==============================================================================
--- trunk/reactos/lib/sdk/crt/misc/assert.c [iso-8859-1] (original)
+++ trunk/reactos/lib/sdk/crt/misc/assert.c [iso-8859-1] Tue Aug  3 16:09:33 2010
@@ -5,15 +5,68 @@
 #include <stdlib.h>
 #include <signal.h>
 
+static const char formatstr[] = 
+    "Assertion failed!\n\n"
+    "Program: %s\n"
+    "File: %s\n"
+    "Line: %ld\n\n"
+    "Expression: %s\n"
+    "Press Retry to debug the application\n";
+
 
 /*
  * @implemented
  */
-void _assert(const char *msg, const char *file, unsigned line)
+void _assert(const char *exp, const char *file, unsigned line)
 {
-  /* Assertion failed at foo.c line 45: x<y */
-  fprintf(stderr, "Assertion failed at %s line %d: %s\n", file, line, msg);
-  FIXME("Assertion failed at %s line %d: %s\n", file, line, msg);
-  raise(SIGABRT);
-  for(;;); /* eliminate warning by mingw */
+    int (WINAPI *pMessageBoxA)(HWND, LPCTSTR, LPCTSTR, UINT);
+    HMODULE hmodUser32;
+    char achProgram[40];
+    char *pszBuffer;
+    int len;
+    int iResult;
+
+    /* Assertion failed at foo.c line 45: x<y */
+    fprintf(stderr, "Assertion failed at %s line %d: %s\n", file, line, exp);
+    FIXME("Assertion failed at %s line %d: %s\n", file, line, exp);
+
+    /* Get MessageBoxA function pointer */
+    hmodUser32 = LoadLibrary("user32.dll");
+    pMessageBoxA = GetProcAddress(hmodUser32, "MessageBoxA");
+    if (!pMessageBoxA)
+    {
+        abort();
+    }
+
+    /* Get the file name of the module */
+    len = GetModuleFileNameA(NULL, achProgram, 40);
+    
+    /* Calculate full length of the message */
+    len += sizeof(formatstr) + len + strlen(exp) + strlen(file);
+
+    /* Allocate a buffer */
+    pszBuffer = malloc(len + 1);
+
+    /* Format a message */
+    _snprintf(pszBuffer, len, formatstr, achProgram, file, line, exp);
+
+    /* Display a message box */
+    iResult = pMessageBoxA(NULL, 
+                          pszBuffer, 
+                          "ReactOS C Runtime Library",
+                          MB_ABORTRETRYIGNORE | MB_ICONERROR);
+
+    free(pszBuffer);
+
+    /* Does the user want to abort? */
+    if (iResult == IDABORT)
+    {
+        abort();
+    }
+
+    /* Does the user want to debug? */
+    if (iResult == IDRETRY)
+    {
+        __debugbreak();
+    }
 }




More information about the Ros-diffs mailing list