winetest: Rename xmalloc() & co to heap_xxx() to not imply they are based on malloc(), and add heap_free().

This commit is contained in:
Francois Gouget 2009-05-17 13:28:23 +02:00 committed by Alexandre Julliard
parent 7422611cc9
commit bf6b95e95c
5 changed files with 52 additions and 46 deletions

View File

@ -66,7 +66,7 @@ textStatus (va_list ap)
fputs (str, stderr); fputs (str, stderr);
fputc ('\n', stderr); fputc ('\n', stderr);
free (str); heap_free (str);
return 0; return 0;
} }
@ -78,7 +78,7 @@ guiStatus (va_list ap)
if (len > 128) str[129] = 0; if (len > 128) str[129] = 0;
SetDlgItemText (dialog, IDC_SB, str); SetDlgItemText (dialog, IDC_SB, str);
free (str); heap_free (str);
return 0; return 0;
} }
@ -121,7 +121,7 @@ textStep (va_list ap)
progressCurr++; progressCurr++;
fputs (str, stderr); fputs (str, stderr);
fprintf (stderr, " (%d of %d)\n", progressCurr, progressMax); fprintf (stderr, " (%d of %d)\n", progressCurr, progressMax);
free (str); heap_free (str);
return 0; return 0;
} }
@ -135,7 +135,7 @@ guiStep (va_list ap)
SetDlgItemText (dialog, pgID, str); SetDlgItemText (dialog, pgID, str);
SendDlgItemMessage (dialog, pgID+1, PBM_SETPOS, SendDlgItemMessage (dialog, pgID+1, PBM_SETPOS,
(WPARAM)(progressScale * progressCurr), 0); (WPARAM)(progressScale * progressCurr), 0);
free (str); heap_free (str);
return 0; return 0;
} }
@ -149,7 +149,7 @@ textDelta (va_list ap)
progressCurr += inc; progressCurr += inc;
fputs (str, stderr); fputs (str, stderr);
fprintf (stderr, " (%d of %d)\n", progressCurr, progressMax); fprintf (stderr, " (%d of %d)\n", progressCurr, progressMax);
free (str); heap_free (str);
return 0; return 0;
} }
@ -164,7 +164,7 @@ guiDelta (va_list ap)
SetDlgItemText (dialog, pgID, str); SetDlgItemText (dialog, pgID, str);
SendDlgItemMessage (dialog, pgID+1, PBM_SETPOS, SendDlgItemMessage (dialog, pgID+1, PBM_SETPOS,
(WPARAM)(progressScale * progressCurr), 0); (WPARAM)(progressScale * progressCurr), 0);
free (str); heap_free (str);
return 0; return 0;
} }
@ -194,7 +194,7 @@ textDir (va_list ap)
fputs ("Temporary directory: ", stderr); fputs ("Temporary directory: ", stderr);
fputs (str, stderr); fputs (str, stderr);
fputc ('\n', stderr); fputc ('\n', stderr);
free (str); heap_free (str);
return 0; return 0;
} }
@ -204,7 +204,7 @@ guiDir (va_list ap)
char *str = vstrmake (NULL, ap); char *str = vstrmake (NULL, ap);
SetDlgItemText (dialog, IDC_DIR, str); SetDlgItemText (dialog, IDC_DIR, str);
free (str); heap_free (str);
return 0; return 0;
} }
@ -217,7 +217,7 @@ textOut (va_list ap)
fputs ("Log file: ", stderr); fputs ("Log file: ", stderr);
fputs (str, stderr); fputs (str, stderr);
fputc ('\n', stderr); fputc ('\n', stderr);
free (str); heap_free (str);
return 0; return 0;
} }
@ -227,7 +227,7 @@ guiOut (va_list ap)
char *str = vstrmake (NULL, ap); char *str = vstrmake (NULL, ap);
SetDlgItemText (dialog, IDC_OUT, str); SetDlgItemText (dialog, IDC_OUT, str);
free (str); heap_free (str);
return 0; return 0;
} }
@ -246,7 +246,7 @@ guiWarning (va_list ap)
char *str = vstrmake (NULL, ap); char *str = vstrmake (NULL, ap);
MessageBox (dialog, str, "Warning", MB_ICONWARNING | MB_OK); MessageBox (dialog, str, "Warning", MB_ICONWARNING | MB_OK);
free (str); heap_free (str);
return 0; return 0;
} }
@ -265,7 +265,7 @@ guiError (va_list ap)
char *str = vstrmake (NULL, ap); char *str = vstrmake (NULL, ap);
MessageBox (dialog, str, "Error", MB_ICONERROR | MB_OK); MessageBox (dialog, str, "Error", MB_ICONERROR | MB_OK);
free (str); heap_free (str);
return 0; return 0;
} }
@ -294,7 +294,7 @@ textAsk (va_list ap)
fprintf (stderr, "Question of type %d: %s\n" fprintf (stderr, "Question of type %d: %s\n"
"Returning default: %d\n", uType, str, ret); "Returning default: %d\n", uType, str, ret);
free (str); heap_free (str);
return ret; return ret;
} }
@ -306,7 +306,7 @@ guiAsk (va_list ap)
int ret = MessageBox (dialog, str, "Question", int ret = MessageBox (dialog, str, "Question",
MB_ICONQUESTION | uType); MB_ICONQUESTION | uType);
free (str); heap_free (str);
return ret; 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"); report (R_WARNING, "You must enter a tag to continue");
return FALSE; return FALSE;
} }
tag = xmalloc (len+1); tag = heap_alloc (len+1);
GetDlgItemTextA (hwnd, IDC_TAG, tag, len+1); GetDlgItemTextA (hwnd, IDC_TAG, tag, len+1);
EndDialog (hwnd, IDOK); EndDialog (hwnd, IDOK);
return TRUE; return TRUE;

View File

@ -98,7 +98,7 @@ static char * get_file_version(char * file_name)
size = GetFileVersionInfoSizeA(file_name, &handle); size = GetFileVersionInfoSizeA(file_name, &handle);
if (size) { if (size) {
char * data = xmalloc(size); char * data = heap_alloc(size);
if (data) { if (data) {
if (GetFileVersionInfoA(file_name, handle, size, data)) { if (GetFileVersionInfoA(file_name, handle, size, data)) {
static char backslash[] = "\\"; static char backslash[] = "\\";
@ -114,7 +114,7 @@ static char * get_file_version(char * file_name)
sprintf(version, "version not available"); sprintf(version, "version not available");
} else } else
sprintf(version, "unknown"); sprintf(version, "unknown");
free(data); heap_free(data);
} else } else
sprintf(version, "failed"); sprintf(version, "failed");
} else } else
@ -311,12 +311,12 @@ extract_test (struct wine_test *test, const char *dir, LPTSTR res_name)
code = extract_rcdata (res_name, TESTRES, &size); code = extract_rcdata (res_name, TESTRES, &size);
if (!code) report (R_FATAL, "Can't find test resource %s: %d", if (!code) report (R_FATAL, "Can't find test resource %s: %d",
res_name, GetLastError ()); res_name, GetLastError ());
test->name = xstrdup( res_name ); test->name = heap_strdup( res_name );
test->exename = strmake (NULL, "%s\\%s", dir, test->name); test->exename = strmake (NULL, "%s\\%s", dir, test->name);
exepos = strstr (test->name, testexe); exepos = strstr (test->name, testexe);
if (!exepos) report (R_FATAL, "Not an .exe file: %s", test->name); if (!exepos) report (R_FATAL, "Not an .exe file: %s", test->name);
*exepos = 0; *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); report (R_STEP, "Extracting: %s", test->name);
hfile = CreateFileA(test->exename, GENERIC_READ | GENERIC_WRITE, 0, NULL, hfile = CreateFileA(test->exename, GENERIC_READ | GENERIC_WRITE, 0, NULL,
@ -349,13 +349,13 @@ static void append_path( const char *path)
{ {
char *newpath; char *newpath;
newpath = xmalloc(strlen(curpath) + 1 + strlen(path) + 1); newpath = heap_alloc(strlen(curpath) + 1 + strlen(path) + 1);
strcpy(newpath, curpath); strcpy(newpath, curpath);
strcat(newpath, ";"); strcat(newpath, ";");
strcat(newpath, path); strcat(newpath, path);
SetEnvironmentVariableA("PATH", newpath); SetEnvironmentVariableA("PATH", newpath);
free(newpath); heap_free(newpath);
} }
/* Run a command for MS milliseconds. If OUT != NULL, also redirect /* 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 */ /* Restore PATH again */
SetEnvironmentVariableA("PATH", curpath); SetEnvironmentVariableA("PATH", curpath);
} }
free (cmd); heap_free (cmd);
if (status == -2) if (status == -2)
{ {
@ -502,19 +502,19 @@ get_subtests (const char *tempdir, struct wine_test *test, LPTSTR res_name)
index += sizeof header; index += sizeof header;
allocated = 10; allocated = 10;
test->subtests = xmalloc (allocated * sizeof(char*)); test->subtests = heap_alloc (allocated * sizeof(char*));
index = strtok (index, whitespace); index = strtok (index, whitespace);
while (index) { while (index) {
if (test->subtest_count == allocated) { if (test->subtest_count == allocated) {
allocated *= 2; allocated *= 2;
test->subtests = xrealloc (test->subtests, test->subtests = heap_realloc (test->subtests,
allocated * sizeof(char*)); allocated * sizeof(char*));
} }
if (!test_filtered_out( test->name, index )) 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); index = strtok (NULL, whitespace);
} }
test->subtests = xrealloc (test->subtests, test->subtests = heap_realloc (test->subtests,
test->subtest_count * sizeof(char*)); test->subtest_count * sizeof(char*));
err = 0; err = 0;
@ -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); xprintf ("%s:%s start %s -\n", test->name, subtest, file);
status = run_ex (cmd, out_file, tempdir, 120000); status = run_ex (cmd, out_file, tempdir, 120000);
free (cmd); heap_free (cmd);
xprintf ("%s:%s done (%d)\n", test->name, subtest, status); 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); GetModuleFileNameA(dll, dllpath, MAX_PATH);
strcpy(filename, dllpath); strcpy(filename, dllpath);
*strrchr(dllpath, '\\') = '\0'; *strrchr(dllpath, '\\') = '\0';
wine_tests[nr_of_files].maindllpath = xstrdup( dllpath ); wine_tests[nr_of_files].maindllpath = heap_strdup( dllpath );
} }
} }
if (!dll) { if (!dll) {
@ -623,7 +623,7 @@ run_tests (char *logname)
/* Get the current PATH only once */ /* Get the current PATH only once */
needed = GetEnvironmentVariableA("PATH", NULL, 0); needed = GetEnvironmentVariableA("PATH", NULL, 0);
curpath = xmalloc(needed); curpath = heap_alloc(needed);
GetEnvironmentVariableA("PATH", curpath, needed); GetEnvironmentVariableA("PATH", curpath, needed);
SetErrorMode (SEM_FAILCRITICALERRORS | SEM_NOGPFAULTERRORBOX); SetErrorMode (SEM_FAILCRITICALERRORS | SEM_NOGPFAULTERRORBOX);
@ -702,7 +702,7 @@ run_tests (char *logname)
EnumTestFileProc, (LPARAM)&nr_of_files)) EnumTestFileProc, (LPARAM)&nr_of_files))
report (R_FATAL, "Can't enumerate test files: %d", report (R_FATAL, "Can't enumerate test files: %d",
GetLastError ()); 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) */ /* Do this only once during extraction (and version checking) */
hmscoree = LoadLibraryA("mscoree.dll"); hmscoree = LoadLibraryA("mscoree.dll");
@ -753,8 +753,8 @@ run_tests (char *logname)
CloseHandle( logfile ); CloseHandle( logfile );
logfile = 0; logfile = 0;
remove_dir (tempdir); remove_dir (tempdir);
free (wine_tests); heap_free(wine_tests);
free (curpath); heap_free(curpath);
return logname; return logname;
} }
@ -800,7 +800,7 @@ static void extract_only (const char *target_dir)
if (!EnumResourceNames (NULL, MAKEINTRESOURCE(TESTRES), EnumTestFileProc, (LPARAM)&nr_of_files)) if (!EnumResourceNames (NULL, MAKEINTRESOURCE(TESTRES), EnumTestFileProc, (LPARAM)&nr_of_files))
report (R_FATAL, "Can't enumerate test files: %d", GetLastError ()); 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_STATUS, "Extracting tests");
report (R_PROGRESS, 0, nr_of_files); report (R_PROGRESS, 0, nr_of_files);

View File

@ -97,7 +97,7 @@ send_str (SOCKET s, ...)
va_end (ap); va_end (ap);
if (!p) return 1; if (!p) return 1;
ret = send_buf (s, p, len); ret = send_buf (s, p, len);
free (p); heap_free (p);
return ret; return ret;
} }
@ -159,7 +159,7 @@ send_file (const char *name)
str = strmake (&total, body1, name); str = strmake (&total, body1, name);
ret = send_str (s, head, filesize + total + sizeof body2 - 1) || ret = send_str (s, head, filesize + total + sizeof body2 - 1) ||
send_buf (s, str, total); send_buf (s, str, total);
free (str); heap_free (str);
if (ret) { if (ret) {
report (R_WARNING, "Error sending header: %d, %d", report (R_WARNING, "Error sending header: %d, %d",
errno, WSAGetLastError ()); errno, WSAGetLastError ());
@ -211,7 +211,7 @@ send_file (const char *name)
str = strmake (&count, "Received %s (%d bytes).\n", str = strmake (&count, "Received %s (%d bytes).\n",
name, filesize); name, filesize);
ret = memcmp (str, buffer + total - count, count); ret = memcmp (str, buffer + total - count, count);
free (str); heap_free (str);
if (ret) { if (ret) {
buffer[total] = 0; buffer[total] = 0;
str = strstr (buffer, "\r\n\r\n"); str = strstr (buffer, "\r\n\r\n");

View File

@ -27,7 +27,7 @@
HANDLE logfile = 0; HANDLE logfile = 0;
void *xmalloc (size_t len) void *heap_alloc (size_t len)
{ {
void *p = malloc (len); void *p = malloc (len);
@ -35,7 +35,7 @@ void *xmalloc (size_t len)
return p; return p;
} }
void *xrealloc (void *op, size_t len) void *heap_realloc (void *op, size_t len)
{ {
void *p = realloc (op, len); void *p = realloc (op, len);
@ -43,13 +43,18 @@ void *xrealloc (void *op, size_t len)
return p; return p;
} }
char *xstrdup( const char *str ) char *heap_strdup( const char *str )
{ {
char *res = strdup( str ); char *res = strdup( str );
if (!res) report (R_FATAL, "Out of memory."); if (!res) report (R_FATAL, "Out of memory.");
return res; return res;
} }
void heap_free (void *op)
{
free (op);
}
static char *vstrfmtmake (size_t *lenp, const char *fmt, va_list ap) static char *vstrfmtmake (size_t *lenp, const char *fmt, va_list ap)
{ {
size_t size = 1000; size_t size = 1000;
@ -65,7 +70,7 @@ static char *vstrfmtmake (size_t *lenp, const char *fmt, va_list ap)
else break; else break;
q = realloc (p, size); q = realloc (p, size);
if (!q) { if (!q) {
free (p); heap_free (p);
return NULL; return NULL;
} }
p = q; p = q;
@ -111,7 +116,7 @@ void xprintf (const char *fmt, ...)
head += written; head += written;
size -= written; size -= written;
} }
free (buffer); heap_free (buffer);
} }
int int

View File

@ -45,9 +45,10 @@ extern HANDLE logfile;
#ifndef __WINE_ALLOC_SIZE #ifndef __WINE_ALLOC_SIZE
#define __WINE_ALLOC_SIZE(x) #define __WINE_ALLOC_SIZE(x)
#endif #endif
void *xmalloc (size_t len) __WINE_ALLOC_SIZE(1); void *heap_alloc (size_t len) __WINE_ALLOC_SIZE(1);
void *xrealloc (void *op, size_t len) __WINE_ALLOC_SIZE(2); void *heap_realloc (void *op, size_t len) __WINE_ALLOC_SIZE(2);
char *xstrdup( const char *str ); char *heap_strdup( const char *str );
void heap_free (void *op);
enum report_type { enum report_type {
R_STATUS = 0, R_STATUS = 0,