[1/2] winetest: Rename xmalloc() & co to heap_xxx() to not imply they are based on malloc(), and add heap_free(). (try2)

Francois Gouget fgouget at free.fr
Sun May 17 06:28:23 CDT 2009


---
 programs/winetest/gui.c      |   30 +++++++++++++++---------------
 programs/winetest/main.c     |   40 ++++++++++++++++++++--------------------
 programs/winetest/send.c     |    6 +++---
 programs/winetest/util.c     |   15 ++++++++++-----
 programs/winetest/winetest.h |    7 ++++---
 5 files changed, 52 insertions(+), 46 deletions(-)

diff --git a/programs/winetest/gui.c b/programs/winetest/gui.c
index 2957dbf..a2b1e7f 100644
--- a/programs/winetest/gui.c
+++ b/programs/winetest/gui.c
@@ -66,7 +66,7 @@ textStatus (va_list ap)
 
     fputs (str, stderr);
     fputc ('\n', stderr);
-    free (str);
+    heap_free (str);
     return 0;
 }
 
@@ -78,7 +78,7 @@ guiStatus (va_list ap)
 
     if (len > 128) str[129] = 0;
     SetDlgItemText (dialog, IDC_SB, str);
-    free (str);
+    heap_free (str);
     return 0;
 }
 
@@ -121,7 +121,7 @@ textStep (va_list ap)
     progressCurr++;
     fputs (str, stderr);
     fprintf (stderr, " (%d of %d)\n", progressCurr, progressMax);
-    free (str);
+    heap_free (str);
     return 0;
 }
 
@@ -135,7 +135,7 @@ guiStep (va_list ap)
     SetDlgItemText (dialog, pgID, str);
     SendDlgItemMessage (dialog, pgID+1, PBM_SETPOS,
                         (WPARAM)(progressScale * progressCurr), 0);
-    free (str);
+    heap_free (str);
     return 0;
 }
 
@@ -149,7 +149,7 @@ textDelta (va_list ap)
     progressCurr += inc;
     fputs (str, stderr);
     fprintf (stderr, " (%d of %d)\n", progressCurr, progressMax);
-    free (str);
+    heap_free (str);
     return 0;
 }
 
@@ -164,7 +164,7 @@ guiDelta (va_list ap)
     SetDlgItemText (dialog, pgID, str);
     SendDlgItemMessage (dialog, pgID+1, PBM_SETPOS,
                         (WPARAM)(progressScale * progressCurr), 0);
-    free (str);
+    heap_free (str);
     return 0;
 }
 
@@ -194,7 +194,7 @@ textDir (va_list ap)
     fputs ("Temporary directory: ", stderr);
     fputs (str, stderr);
     fputc ('\n', stderr);
-    free (str);
+    heap_free (str);
     return 0;
 }
 
@@ -204,7 +204,7 @@ guiDir (va_list ap)
     char *str = vstrmake (NULL, ap);
 
     SetDlgItemText (dialog, IDC_DIR, str);
-    free (str);
+    heap_free (str);
     return 0;
 }
 
@@ -217,7 +217,7 @@ textOut (va_list ap)
     fputs ("Log file: ", stderr);
     fputs (str, stderr);
     fputc ('\n', stderr);
-    free (str);
+    heap_free (str);
     return 0;
 }
 
@@ -227,7 +227,7 @@ guiOut (va_list ap)
     char *str = vstrmake (NULL, ap);
 
     SetDlgItemText (dialog, IDC_OUT, str);
-    free (str);
+    heap_free (str);
     return 0;
 }
 
@@ -246,7 +246,7 @@ guiWarning (va_list ap)
     char *str = vstrmake (NULL, ap);
 
     MessageBox (dialog, str, "Warning", MB_ICONWARNING | MB_OK);
-    free (str);
+    heap_free (str);
     return 0;
 }
 
@@ -265,7 +265,7 @@ guiError (va_list ap)
     char *str = vstrmake (NULL, ap);
 
     MessageBox (dialog, str, "Error", MB_ICONERROR | MB_OK);
-    free (str);
+    heap_free (str);
     return 0;
 }
 
@@ -294,7 +294,7 @@ textAsk (va_list ap)
 
     fprintf (stderr, "Question of type %d: %s\n"
              "Returning default: %d\n", uType, str, ret);
-    free (str);
+    heap_free (str);
     return ret;
 }
 
@@ -306,7 +306,7 @@ guiAsk (va_list ap)
     int ret = MessageBox (dialog, str, "Question",
                           MB_ICONQUESTION | uType);
 
-    free (str);
+    heap_free (str);
     return ret;
 }
 
@@ -341,7 +341,7 @@ AskTagProc (HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
                report (R_WARNING, "You must enter a tag to continue");
                return FALSE;
             }
-            tag = xmalloc (len+1);
+            tag = heap_alloc (len+1);
             GetDlgItemTextA (hwnd, IDC_TAG, tag, len+1);
             EndDialog (hwnd, IDOK);
             return TRUE;
diff --git a/programs/winetest/main.c b/programs/winetest/main.c
index 7bbb0cb..69496bd 100644
--- a/programs/winetest/main.c
+++ b/programs/winetest/main.c
@@ -98,7 +98,7 @@ static char * get_file_version(char * file_name)
 
     size = GetFileVersionInfoSizeA(file_name, &handle);
     if (size) {
-        char * data = xmalloc(size);
+        char * data = heap_alloc(size);
         if (data) {
             if (GetFileVersionInfoA(file_name, handle, size, data)) {
                 static char backslash[] = "\\";
@@ -114,7 +114,7 @@ static char * get_file_version(char * file_name)
                     sprintf(version, "version not available");
             } else
                 sprintf(version, "unknown");
-            free(data);
+            heap_free(data);
         } else
             sprintf(version, "failed");
     } else
@@ -311,12 +311,12 @@ extract_test (struct wine_test *test, const char *dir, LPTSTR res_name)
     code = extract_rcdata (res_name, TESTRES, &size);
     if (!code) report (R_FATAL, "Can't find test resource %s: %d",
                        res_name, GetLastError ());
-    test->name = xstrdup( res_name );
+    test->name = heap_strdup( res_name );
     test->exename = strmake (NULL, "%s\\%s", dir, test->name);
     exepos = strstr (test->name, testexe);
     if (!exepos) report (R_FATAL, "Not an .exe file: %s", test->name);
     *exepos = 0;
-    test->name = xrealloc (test->name, exepos - test->name + 1);
+    test->name = heap_realloc (test->name, exepos - test->name + 1);
     report (R_STEP, "Extracting: %s", test->name);
 
     hfile = CreateFileA(test->exename, GENERIC_READ | GENERIC_WRITE, 0, NULL,
@@ -349,13 +349,13 @@ static void append_path( const char *path)
 {
     char *newpath;
 
-    newpath = xmalloc(strlen(curpath) + 1 + strlen(path) + 1);
+    newpath = heap_alloc(strlen(curpath) + 1 + strlen(path) + 1);
     strcpy(newpath, curpath);
     strcat(newpath, ";");
     strcat(newpath, path);
     SetEnvironmentVariableA("PATH", newpath);
 
-    free(newpath);
+    heap_free(newpath);
 }
 
 /* Run a command for MS milliseconds.  If OUT != NULL, also redirect
@@ -473,7 +473,7 @@ get_subtests (const char *tempdir, struct wine_test *test, LPTSTR res_name)
         /* Restore PATH again */
         SetEnvironmentVariableA("PATH", curpath);
     }
-    free (cmd);
+    heap_free (cmd);
 
     if (status == -2)
     {
@@ -502,20 +502,20 @@ get_subtests (const char *tempdir, struct wine_test *test, LPTSTR res_name)
     index += sizeof header;
 
     allocated = 10;
-    test->subtests = xmalloc (allocated * sizeof(char*));
+    test->subtests = heap_alloc (allocated * sizeof(char*));
     index = strtok (index, whitespace);
     while (index) {
         if (test->subtest_count == allocated) {
             allocated *= 2;
-            test->subtests = xrealloc (test->subtests,
-                                       allocated * sizeof(char*));
+            test->subtests = heap_realloc (test->subtests,
+                                           allocated * sizeof(char*));
         }
         if (!test_filtered_out( test->name, index ))
-            test->subtests[test->subtest_count++] = xstrdup(index);
+            test->subtests[test->subtest_count++] = heap_strdup(index);
         index = strtok (NULL, whitespace);
     }
-    test->subtests = xrealloc (test->subtests,
-                               test->subtest_count * sizeof(char*));
+    test->subtests = heap_realloc (test->subtests,
+                                   test->subtest_count * sizeof(char*));
     err = 0;
 
  quit:
@@ -533,7 +533,7 @@ run_test (struct wine_test* test, const char* subtest, HANDLE out_file, const ch
 
     xprintf ("%s:%s start %s -\n", test->name, subtest, file);
     status = run_ex (cmd, out_file, tempdir, 120000);
-    free (cmd);
+    heap_free (cmd);
     xprintf ("%s:%s done (%d)\n", test->name, subtest, status);
 }
 
@@ -583,7 +583,7 @@ extract_test_proc (HMODULE hModule, LPCTSTR lpszType,
             GetModuleFileNameA(dll, dllpath, MAX_PATH);
             strcpy(filename, dllpath);
             *strrchr(dllpath, '\\') = '\0';
-            wine_tests[nr_of_files].maindllpath = xstrdup( dllpath );
+            wine_tests[nr_of_files].maindllpath = heap_strdup( dllpath );
         }
     }
     if (!dll) {
@@ -623,7 +623,7 @@ run_tests (char *logname)
 
     /* Get the current PATH only once */
     needed = GetEnvironmentVariableA("PATH", NULL, 0);
-    curpath = xmalloc(needed);
+    curpath = heap_alloc(needed);
     GetEnvironmentVariableA("PATH", curpath, needed);
 
     SetErrorMode (SEM_FAILCRITICALERRORS | SEM_NOGPFAULTERRORBOX);
@@ -702,7 +702,7 @@ run_tests (char *logname)
                             EnumTestFileProc, (LPARAM)&nr_of_files))
         report (R_FATAL, "Can't enumerate test files: %d",
                 GetLastError ());
-    wine_tests = xmalloc (nr_of_files * sizeof wine_tests[0]);
+    wine_tests = heap_alloc (nr_of_files * sizeof wine_tests[0]);
 
     /* Do this only once during extraction (and version checking) */
     hmscoree = LoadLibraryA("mscoree.dll");
@@ -753,8 +753,8 @@ run_tests (char *logname)
     CloseHandle( logfile );
     logfile = 0;
     remove_dir (tempdir);
-    free (wine_tests);
-    free (curpath);
+    heap_free(wine_tests);
+    heap_free(curpath);
 
     return logname;
 }
@@ -800,7 +800,7 @@ static void extract_only (const char *target_dir)
     if (!EnumResourceNames (NULL, MAKEINTRESOURCE(TESTRES), EnumTestFileProc, (LPARAM)&nr_of_files))
         report (R_FATAL, "Can't enumerate test files: %d", GetLastError ());
 
-    wine_tests = xmalloc (nr_of_files * sizeof wine_tests[0] );
+    wine_tests = heap_alloc (nr_of_files * sizeof wine_tests[0] );
 
     report (R_STATUS, "Extracting tests");
     report (R_PROGRESS, 0, nr_of_files);
diff --git a/programs/winetest/send.c b/programs/winetest/send.c
index 947f2c1..9eae079 100644
--- a/programs/winetest/send.c
+++ b/programs/winetest/send.c
@@ -97,7 +97,7 @@ send_str (SOCKET s, ...)
     va_end (ap);
     if (!p) return 1;
     ret = send_buf (s, p, len);
-    free (p);
+    heap_free (p);
     return ret;
 }
 
@@ -159,7 +159,7 @@ send_file (const char *name)
     str = strmake (&total, body1, name);
     ret = send_str (s, head, filesize + total + sizeof body2 - 1) ||
         send_buf (s, str, total);
-    free (str);
+    heap_free (str);
     if (ret) {
         report (R_WARNING, "Error sending header: %d, %d",
                 errno, WSAGetLastError ());
@@ -211,7 +211,7 @@ send_file (const char *name)
     str = strmake (&count, "Received %s (%d bytes).\n",
                    name, filesize);
     ret = memcmp (str, buffer + total - count, count);
-    free (str);
+    heap_free (str);
     if (ret) {
         buffer[total] = 0;
         str = strstr (buffer, "\r\n\r\n");
diff --git a/programs/winetest/util.c b/programs/winetest/util.c
index 0253296..66f79f5 100644
--- a/programs/winetest/util.c
+++ b/programs/winetest/util.c
@@ -27,7 +27,7 @@
 
 HANDLE logfile = 0;
 
-void *xmalloc (size_t len)
+void *heap_alloc (size_t len)
 {
     void *p = malloc (len);
 
@@ -35,7 +35,7 @@ void *xmalloc (size_t len)
     return p;
 }
 
-void *xrealloc (void *op, size_t len)
+void *heap_realloc (void *op, size_t len)
 {
     void *p = realloc (op, len);
 
@@ -43,13 +43,18 @@ void *xrealloc (void *op, size_t len)
     return p;
 }
 
-char *xstrdup( const char *str )
+char *heap_strdup( const char *str )
 {
     char *res = strdup( str );
     if (!res) report (R_FATAL, "Out of memory.");
     return res;
 }
 
+void heap_free (void *op)
+{
+    free (op);
+}
+
 static char *vstrfmtmake (size_t *lenp, const char *fmt, va_list ap)
 {
     size_t size = 1000;
@@ -65,7 +70,7 @@ static char *vstrfmtmake (size_t *lenp, const char *fmt, va_list ap)
         else break;
         q = realloc (p, size);
         if (!q) {
-          free (p);
+          heap_free (p);
           return NULL;
        }
        p = q;
@@ -111,7 +116,7 @@ void xprintf (const char *fmt, ...)
         head += written;
         size -= written;
     }
-    free (buffer);
+    heap_free (buffer);
 }
 
 int
diff --git a/programs/winetest/winetest.h b/programs/winetest/winetest.h
index e4844a9..945586c 100644
--- a/programs/winetest/winetest.h
+++ b/programs/winetest/winetest.h
@@ -45,9 +45,10 @@ extern HANDLE logfile;
 #ifndef __WINE_ALLOC_SIZE
 #define __WINE_ALLOC_SIZE(x)
 #endif
-void *xmalloc (size_t len) __WINE_ALLOC_SIZE(1);
-void *xrealloc (void *op, size_t len) __WINE_ALLOC_SIZE(2);
-char *xstrdup( const char *str );
+void *heap_alloc (size_t len) __WINE_ALLOC_SIZE(1);
+void *heap_realloc (void *op, size_t len) __WINE_ALLOC_SIZE(2);
+char *heap_strdup( const char *str );
+void heap_free (void *op);
 
 enum report_type {
     R_STATUS = 0,
-- 
1.6.2.4




More information about the wine-patches mailing list