Compiler Options moved to util.h

This commit is contained in:
inikep
2016-05-05 11:53:42 +02:00
parent 3163403855
commit 9c22e57bfb
8 changed files with 67 additions and 97 deletions
+45 -14
View File
@@ -39,6 +39,28 @@
extern "C" { extern "C" {
#endif #endif
/* **************************************
* Compiler Options
****************************************/
#if defined(_MSC_VER)
# define _CRT_SECURE_NO_WARNINGS /* Disable some Visual warning messages for fopen, strncpy */
# define _CRT_SECURE_NO_DEPRECATE /* VS2005 */
# pragma warning(disable : 4127) /* disable: C4127: conditional expression is constant */
# define snprintf sprintf_s /* snprintf unsupported by Visual <= 2012 */
//# define snprintf _snprintf
#endif
/* Unix Large Files support (>4GB) */
#if !defined(__LP64__) /* No point defining Large file for 64 bit */
# define _FILE_OFFSET_BITS 64 /* turn off_t into a 64-bit type for ftello, fseeko */
# if defined(__sun__) /* Sun Solaris 32-bits requires specific definitions */
# define _LARGEFILE_SOURCE /* fseeko, ftello */
# else
# define _LARGEFILE64_SOURCE /* off64_t, fseeko64, ftello64 */
# endif
#endif
/*-**************************************** /*-****************************************
* Dependencies * Dependencies
******************************************/ ******************************************/
@@ -63,7 +85,9 @@ extern "C" {
#endif #endif
/* Sleep functions: Windows - Posix - others */ /*-****************************************
* Sleep functions: Windows - Posix - others
******************************************/
#if defined(_WIN32) #if defined(_WIN32)
# include <windows.h> # include <windows.h>
# define SET_HIGH_PRIORITY SetPriorityClass(GetCurrentProcess(), REALTIME_PRIORITY_CLASS) # define SET_HIGH_PRIORITY SetPriorityClass(GetCurrentProcess(), REALTIME_PRIORITY_CLASS)
@@ -75,11 +99,11 @@ extern "C" {
# include <time.h> /* clock_t, nanosleep, clock, CLOCKS_PER_SEC */ # include <time.h> /* clock_t, nanosleep, clock, CLOCKS_PER_SEC */
# define SET_HIGH_PRIORITY setpriority(PRIO_PROCESS, 0, -20) # define SET_HIGH_PRIORITY setpriority(PRIO_PROCESS, 0, -20)
# define UTIL_sleep(s) sleep(s) # define UTIL_sleep(s) sleep(s)
#if defined(_POSIX_C_SOURCE) && (_POSIX_C_SOURCE >= 199309L) # if defined(_POSIX_C_SOURCE) && (_POSIX_C_SOURCE >= 199309L)
# define UTIL_sleepMilli(milli) { struct timespec t; t.tv_sec=0; t.tv_nsec=milli*1000000ULL; nanosleep(&t, NULL); } # define UTIL_sleepMilli(milli) { struct timespec t; t.tv_sec=0; t.tv_nsec=milli*1000000ULL; nanosleep(&t, NULL); }
#else # else
# define UTIL_sleepMilli(milli) /* disabled */ # define UTIL_sleepMilli(milli) /* disabled */
#endif # endif
#else #else
# define SET_HIGH_PRIORITY /* disabled */ # define SET_HIGH_PRIORITY /* disabled */
# define UTIL_sleep(s) /* disabled */ # define UTIL_sleep(s) /* disabled */
@@ -191,6 +215,7 @@ UTIL_STATIC U32 UTIL_isDirectory(const char* infilename)
#ifdef _WIN32 #ifdef _WIN32
# define UTIL_HAS_CREATEFILELIST
UTIL_STATIC int UTIL_prepareFileList(const char *dirName, char** bufStart, char* bufEnd) UTIL_STATIC int UTIL_prepareFileList(const char *dirName, char** bufStart, char* bufEnd)
{ {
@@ -243,6 +268,7 @@ next:
} }
#elif (defined(__unix__) || defined(__unix) || (defined(__APPLE__) && defined(__MACH__))) && defined(_POSIX_C_SOURCE) && (_POSIX_C_SOURCE >= 200112L) /* snprintf, opendir */ #elif (defined(__unix__) || defined(__unix) || (defined(__APPLE__) && defined(__MACH__))) && defined(_POSIX_C_SOURCE) && (_POSIX_C_SOURCE >= 200112L) /* snprintf, opendir */
# define UTIL_HAS_CREATEFILELIST
# include <dirent.h> /* opendir, readdir */ # include <dirent.h> /* opendir, readdir */
# include <limits.h> /* PATH_MAX */ # include <limits.h> /* PATH_MAX */
# include <errno.h> # include <errno.h>
@@ -291,25 +317,28 @@ UTIL_STATIC int UTIL_prepareFileList(const char *dirName, char** bufStart, char*
UTIL_STATIC int UTIL_prepareFileList(const char *dirName, char** bufStart, char* bufEnd) UTIL_STATIC int UTIL_prepareFileList(const char *dirName, char** bufStart, char* bufEnd)
{ {
(void)bufStart; (void)bufEnd;
fprintf(stderr, "Directory %s ignored (zstd compiled without _POSIX_C_SOURCE)\n", dirName); fprintf(stderr, "Directory %s ignored (zstd compiled without _POSIX_C_SOURCE)\n", dirName);
return 0; return 0;
} }
#endif // WIN32 #endif // #ifdef _WIN32
UTIL_STATIC int UTIL_createFileList(const char **inputNames, unsigned nbNames, unsigned maxListSize, char*** filenameTable) UTIL_STATIC int UTIL_createFileList(const char **inputNames, unsigned nbNames, unsigned maxListSize, const char*** filenameTable, char** allocatedBuffer)
{ {
unsigned i, nbFiles = 0; unsigned i, nbFiles = 0;
char *pbuf, *bufend, *buf; char *pbuf, *bufend, *buf;
buf = (char*)malloc(maxListSize); buf = (char*)malloc(maxListSize);
if (!buf) { *filenameTable = NULL; return 0; }
bufend = buf + maxListSize; bufend = buf + maxListSize;
for (i=0, pbuf = buf; i<nbNames; i++) {
for (i=0, pbuf = buf; i<nbNames; i++) {
if (UTIL_doesFileExists(inputNames[i])) { if (UTIL_doesFileExists(inputNames[i])) {
// printf ("UTIL_doesFileExists=[%s]\n", inputNames[i]); // printf ("UTIL_doesFileExists=[%s]\n", inputNames[i]);
int len = strlen(inputNames[i]); size_t len = strlen(inputNames[i]);
if (bufend - pbuf <= len) break; if (pbuf + len >= bufend) break;
strncpy(pbuf, inputNames[i], bufend - pbuf); strncpy(pbuf, inputNames[i], bufend - pbuf);
pbuf += len + 1; pbuf += len + 1;
nbFiles++; nbFiles++;
@@ -318,7 +347,8 @@ UTIL_STATIC int UTIL_createFileList(const char **inputNames, unsigned nbNames, u
nbFiles += UTIL_prepareFileList(inputNames[i], &pbuf, bufend); nbFiles += UTIL_prepareFileList(inputNames[i], &pbuf, bufend);
} }
{ char** fileTable = (char**)malloc((nbFiles+1) * sizeof(const char*)); { const char** fileTable = (const char**)malloc((nbFiles+1) * sizeof(const char*));
if (!fileTable) { free(buf); *filenameTable = NULL; return 0; }
if (nbFiles == 0) if (nbFiles == 0)
fileTable[0] = buf; fileTable[0] = buf;
@@ -330,15 +360,16 @@ UTIL_STATIC int UTIL_createFileList(const char **inputNames, unsigned nbNames, u
} }
*filenameTable = fileTable; *filenameTable = fileTable;
*allocatedBuffer = buf;
} }
return nbFiles; return nbFiles;
} }
UTIL_STATIC void UTIL_freeFileList(char** filenameTable) UTIL_STATIC void UTIL_freeFileList(const char** filenameTable, char* buf)
{ {
free(filenameTable[0]); /* free buffer */ free(buf);
free(filenameTable); free(filenameTable);
} }
+16 -19
View File
@@ -23,24 +23,6 @@
- zstd source repository : https://github.com/Cyan4973/zstd - zstd source repository : https://github.com/Cyan4973/zstd
*/ */
/* **************************************
* Compiler Options
****************************************/
/* Disable some Visual warning messages */
#ifdef _MSC_VER
# define _CRT_SECURE_NO_WARNINGS /* fopen */
# pragma warning(disable : 4127) /* disable: C4127: conditional expression is constant */
#endif
/* Unix Large Files support (>4GB) */
#define _FILE_OFFSET_BITS 64
#if (defined(__sun__) && (!defined(__LP64__))) /* Sun Solaris 32-bits requires specific definitions */
# define _LARGEFILE_SOURCE
#elif ! defined(__LP64__) /* No point defining Large file for 64 bit */
# define _LARGEFILE64_SOURCE
#endif
/* ************************************* /* *************************************
* Includes * Includes
***************************************/ ***************************************/
@@ -59,7 +41,7 @@
* Compiler specifics * Compiler specifics
***************************************/ ***************************************/
#if defined(_MSC_VER) #if defined(_MSC_VER)
# define snprintf sprintf_s
#elif defined (__cplusplus) || (defined (__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L)) #elif defined (__cplusplus) || (defined (__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L))
/* part of <stdio.h> */ /* part of <stdio.h> */
#else #else
@@ -78,6 +60,7 @@
#define TIMELOOP_MICROSEC 1*1000000ULL /* 1 second */ #define TIMELOOP_MICROSEC 1*1000000ULL /* 1 second */
#define ACTIVEPERIOD_MICROSEC 70*1000000ULL /* 70 seconds */ #define ACTIVEPERIOD_MICROSEC 70*1000000ULL /* 70 seconds */
#define COOLPERIOD_SEC 10 #define COOLPERIOD_SEC 10
#define MAX_LIST_SIZE (64*1024)
#define KB *(1 <<10) #define KB *(1 <<10)
#define MB *(1 <<20) #define MB *(1 <<20)
@@ -535,7 +518,21 @@ int BMK_benchFiles(const char** fileNamesTable, unsigned nbFiles,
if (nbFiles == 0) if (nbFiles == 0)
BMK_syntheticTest(cLevel, cLevelLast, compressibility); BMK_syntheticTest(cLevel, cLevelLast, compressibility);
else else
{
#ifdef UTIL_HAS_CREATEFILELIST
char* buf;
const char** filenameTable;
unsigned i;
nbFiles = UTIL_createFileList(fileNamesTable, nbFiles, MAX_LIST_SIZE, &filenameTable, &buf);
if (filenameTable) {
for (i=0; i<nbFiles; i++) printf ("%d %s\n", i, filenameTable[i]);
BMK_benchFileTable(filenameTable, nbFiles, dictFileName, cLevel, cLevelLast);
UTIL_freeFileList(filenameTable, buf);
}
#else
BMK_benchFileTable(fileNamesTable, nbFiles, dictFileName, cLevel, cLevelLast); BMK_benchFileTable(fileNamesTable, nbFiles, dictFileName, cLevel, cLevelLast);
#endif
}
return 0; return 0;
} }
-18
View File
@@ -22,24 +22,6 @@
- zstd homepage : http://www.zstd.net/ - zstd homepage : http://www.zstd.net/
*/ */
/*-**************************************
* Compiler Options
****************************************/
/* Disable some Visual warning messages */
#ifdef _MSC_VER
# define _CRT_SECURE_NO_WARNINGS /* fopen */
# pragma warning(disable : 4127) /* disable: C4127: conditional expression is constant */
#endif
/* Unix Large Files support (>4GB) */
#define _FILE_OFFSET_BITS 64
#if (defined(__sun__) && (!defined(__LP64__))) /* Sun Solaris 32-bits requires specific definitions */
# define _LARGEFILE_SOURCE
#elif ! defined(__LP64__) /* No point defining Large file for 64 bit */
# define _LARGEFILE64_SOURCE
#endif
/*-************************************* /*-*************************************
* Includes * Includes
***************************************/ ***************************************/
-8
View File
@@ -41,14 +41,6 @@
/* ************************************* /* *************************************
* Compiler Options * Compiler Options
***************************************/ ***************************************/
/* Disable some Visual warning messages */
#ifdef _MSC_VER
# define _CRT_SECURE_NO_WARNINGS
# define _CRT_SECURE_NO_DEPRECATE /* VS2005 */
# pragma warning(disable : 4127) /* disable: C4127: conditional expression is constant */
#endif
#define _FILE_OFFSET_BITS 64 /* Large file support on 32-bits unix */
#define _POSIX_SOURCE 1 /* enable fileno() within <stdio.h> on unix */ #define _POSIX_SOURCE 1 /* enable fileno() within <stdio.h> on unix */
-16
View File
@@ -22,22 +22,6 @@
- zstd homepage : http://www.zstd.net - zstd homepage : http://www.zstd.net
*/ */
/*_************************************
* Compiler Options
**************************************/
/* Disable some Visual warning messages */
#define _CRT_SECURE_NO_WARNINGS
#define _CRT_SECURE_NO_DEPRECATE /* VS2005 */
/* Unix Large Files support (>4GB) */
#if (defined(__sun__) && (!defined(__LP64__))) /* Sun Solaris 32-bits requires specific definitions */
# define _LARGEFILE_SOURCE
# define _FILE_OFFSET_BITS 64
#elif ! defined(__LP64__) /* No point defining Large file for 64 bit */
# define _LARGEFILE64_SOURCE
#endif
/*_************************************ /*_************************************
* Includes * Includes
**************************************/ **************************************/
-16
View File
@@ -25,27 +25,11 @@
/*-************************************ /*-************************************
* Compiler Options * Compiler Options
**************************************/ **************************************/
/* Disable some Visual warning messages */
#define _CRT_SECURE_NO_WARNINGS
#define _CRT_SECURE_NO_DEPRECATE /* VS2005 */
/* Unix Large Files support (>4GB) */
#if (defined(__sun__) && (!defined(__LP64__))) /* Sun Solaris 32-bits requires specific definitions */
# define _LARGEFILE_SOURCE
# define _FILE_OFFSET_BITS 64
#elif ! defined(__LP64__) /* No point defining Large file for 64 bit */
# define _LARGEFILE64_SOURCE
#endif
/* gettimeofday() are not supported by MSVC */ /* gettimeofday() are not supported by MSVC */
#if defined(_MSC_VER) || defined(_WIN32) #if defined(_MSC_VER) || defined(_WIN32)
# define BMK_LEGACY_TIMER 1 # define BMK_LEGACY_TIMER 1
#endif #endif
#if defined(_MSC_VER)
# define snprintf _snprintf /* snprintf unsupported by Visual <= 2012 */
#endif
/*-************************************ /*-************************************
* Dependencies * Dependencies
+3 -3
View File
@@ -1,4 +1,4 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> <Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup Label="ProjectConfigurations"> <ItemGroup Label="ProjectConfigurations">
<ProjectConfiguration Include="Debug|Win32"> <ProjectConfiguration Include="Debug|Win32">
@@ -35,7 +35,7 @@
<ConfigurationType>Application</ConfigurationType> <ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries> <UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v110</PlatformToolset> <PlatformToolset>v110</PlatformToolset>
<CharacterSet>Unicode</CharacterSet> <CharacterSet>MultiByte</CharacterSet>
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration"> <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType> <ConfigurationType>Application</ConfigurationType>
@@ -49,7 +49,7 @@
<UseDebugLibraries>false</UseDebugLibraries> <UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v110</PlatformToolset> <PlatformToolset>v110</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization> <WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet> <CharacterSet>MultiByte</CharacterSet>
</PropertyGroup> </PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" /> <Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings"> <ImportGroup Label="ExtensionSettings">
+3 -3
View File
@@ -1,4 +1,4 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> <Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup Label="ProjectConfigurations"> <ItemGroup Label="ProjectConfigurations">
<ProjectConfiguration Include="Debug|Win32"> <ProjectConfiguration Include="Debug|Win32">
@@ -87,7 +87,7 @@
<ConfigurationType>Application</ConfigurationType> <ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries> <UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v110</PlatformToolset> <PlatformToolset>v110</PlatformToolset>
<CharacterSet>Unicode</CharacterSet> <CharacterSet>MultiByte</CharacterSet>
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration"> <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType> <ConfigurationType>Application</ConfigurationType>
@@ -101,7 +101,7 @@
<UseDebugLibraries>false</UseDebugLibraries> <UseDebugLibraries>false</UseDebugLibraries>
<WholeProgramOptimization>true</WholeProgramOptimization> <WholeProgramOptimization>true</WholeProgramOptimization>
<PlatformToolset>v110</PlatformToolset> <PlatformToolset>v110</PlatformToolset>
<CharacterSet>Unicode</CharacterSet> <CharacterSet>MultiByte</CharacterSet>
</PropertyGroup> </PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" /> <Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings"> <ImportGroup Label="ExtensionSettings">