From: Yann Collet Date: Wed, 6 Nov 2019 01:25:20 +0000 (-0800) Subject: updated zwrapbench to use FileNamesTable* abstraction X-Git-Tag: v1.4.5^2~141^2~18 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=7977899538409b62a4d132e767d8bf4ad0dbaff8;p=thirdparty%2Fzstd.git updated zwrapbench to use FileNamesTable* abstraction --- diff --git a/zlibWrapper/examples/zwrapbench.c b/zlibWrapper/examples/zwrapbench.c index 35893a4b4..38d19ed1f 100644 --- a/zlibWrapper/examples/zwrapbench.c +++ b/zlibWrapper/examples/zwrapbench.c @@ -74,7 +74,7 @@ static U32 g_compressibilityDefault = 50; #define DEFAULT_DISPLAY_LEVEL 2 #define DISPLAY(...) fprintf(displayOut, __VA_ARGS__) #define DISPLAYLEVEL(l, ...) if (g_displayLevel>=l) { DISPLAY(__VA_ARGS__); } -static int g_displayLevel = DEFAULT_DISPLAY_LEVEL; /* 0 : no display; 1: errors; 2 : + result + interaction + warnings; 3 : + progression; 4 : + information */ +static unsigned g_displayLevel = DEFAULT_DISPLAY_LEVEL; /* 0 : no display; 1: errors; 2 : + result + interaction + warnings; 3 : + progression; 4 : + information */ static FILE* displayOut; #define DISPLAYUPDATE(l, ...) if (g_displayLevel>=l) { \ @@ -848,7 +848,7 @@ static unsigned readU32FromChar(const char** stringPtr) { unsigned result = 0; while ((**stringPtr >='0') && (**stringPtr <='9')) - result *= 10, result += **stringPtr - '0', (*stringPtr)++ ; + result *= 10, result += (unsigned)(**stringPtr - '0'), (*stringPtr)++ ; return result; } @@ -865,24 +865,18 @@ int main(int argCount, char** argv) int cLevel = ZSTDCLI_CLEVEL_DEFAULT; int cLevelLast = 1; unsigned recursive = 0; - const char** filenameTable = (const char**)malloc(argCount * sizeof(const char*)); /* argCount >= 1 */ - unsigned filenameIdx = 0; + FileNamesTable* filenames = UTIL_allocateFileNamesTable((size_t)argCount); const char* programName = argv[0]; const char* dictFileName = NULL; char* dynNameSpace = NULL; -#ifdef UTIL_HAS_CREATEFILELIST - const char** fileNamesTable = NULL; - char* fileNamesBuf = NULL; - unsigned fileNamesNb; -#endif /* init */ - if (filenameTable==NULL) { DISPLAY("zstd: %s \n", strerror(errno)); exit(1); } + if (filenames==NULL) { DISPLAY("zstd: %s \n", strerror(errno)); exit(1); } displayOut = stderr; /* Pick out program name from path. Don't rely on stdlib because of conflicting behavior */ { size_t pos; - for (pos = (int)strlen(programName); pos > 0; pos--) { if (programName[pos] == '/') { pos++; break; } } + for (pos = strlen(programName); pos > 0; pos--) { if (programName[pos] == '/') { pos++; break; } } programName += pos; } @@ -930,14 +924,14 @@ int main(int argCount, char** argv) case 'b': /* first compression Level */ argument++; - cLevel = readU32FromChar(&argument); + cLevel = (int)readU32FromChar(&argument); break; /* range bench (benchmark only) */ case 'e': /* last compression Level */ argument++; - cLevelLast = readU32FromChar(&argument); + cLevelLast = (int)readU32FromChar(&argument); break; /* Modify Nb Iterations (benchmark only) */ @@ -964,7 +958,7 @@ int main(int argCount, char** argv) /* Pause at the end (-p) or set an additional param (-p#) (hidden option) */ case 'p': argument++; if ((*argument>='0') && (*argument<='9')) { - BMK_setAdditionalParam(readU32FromChar(&argument)); + BMK_setAdditionalParam((int)readU32FromChar(&argument)); } else main_pause=1; break; @@ -984,7 +978,7 @@ int main(int argCount, char** argv) } /* add filename to list */ - filenameTable[filenameIdx++] = argument; + UTIL_refFilename(filenames, argument); } /* Welcome message (if verbose) */ @@ -992,28 +986,16 @@ int main(int argCount, char** argv) #ifdef UTIL_HAS_CREATEFILELIST if (recursive) { - fileNamesTable = UTIL_createFileList(filenameTable, filenameIdx, &fileNamesBuf, &fileNamesNb, 1); - if (fileNamesTable) { - unsigned u; - for (u=0; ufileNames, (unsigned)filenames->tableSize, dictFileName, cLevel, cLevelLast); _end: if (main_pause) waitEnter(); free(dynNameSpace); -#ifdef UTIL_HAS_CREATEFILELIST - if (fileNamesTable) - UTIL_freeFileList(fileNamesTable, fileNamesBuf); - else -#endif - free((void*)filenameTable); + UTIL_freeFileNamesTable(filenames); return operationResult; }