aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIan Elliott <ian@LunarG.com>2015-02-04 12:06:46 -0700
committerIan Elliott <ian@lunarg.com>2015-02-05 11:06:32 -0700
commit988c35fb30c2158ce81ef76483a3e5e6e7a9a57d (patch)
tree75521fd719a2d3cdfe5a5e5b696d4f0552650321
parent9f2ae974752208211166a8983f8425be8ac2fffa (diff)
downloadusermoji-988c35fb30c2158ce81ef76483a3e5e6e7a9a57d.tar.xz
Win: Eliminate VS2013 compiler warnings for "loader.c" ...
As part of this, eliminated some similar warnings within/across usage of "loader_platform.h". One of these is #define'ing _CRT_SECURE_NO_WARNINGS, so that VisualStudio won't issue warnings with our use of _snprint() (which they don't consider secure enough; but their desired function doesn't match the signature of snprintf()).
-rw-r--r--layers/CMakeLists.txt13
-rw-r--r--loader/CMakeLists.txt6
-rw-r--r--loader/loader.c44
-rw-r--r--loader/loader_platform.h5
4 files changed, 41 insertions, 27 deletions
diff --git a/layers/CMakeLists.txt b/layers/CMakeLists.txt
index 4693d4e4..8235ff8f 100644
--- a/layers/CMakeLists.txt
+++ b/layers/CMakeLists.txt
@@ -38,9 +38,16 @@ include_directories(
${CMAKE_CURRENT_BINARY_DIR}
)
-set (CMAKE_CXX_FLAGS "-std=c++11")
-set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DXGL_PROTOTYPES")
-set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DXGL_PROTOTYPES")
+if (WIN32)
+ set (CMAKE_CXX_FLAGS "-std=c++11")
+ set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DXGL_PROTOTYPES -D_CRT_SECURE_NO_WARNINGS")
+ set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DXGL_PROTOTYPES -D_CRT_SECURE_NO_WARNINGS")
+endif()
+if (NOT WIN32)
+ set (CMAKE_CXX_FLAGS "-std=c++11")
+ set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DXGL_PROTOTYPES")
+ set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DXGL_PROTOTYPES")
+endif()
add_custom_command(OUTPUT xgl_dispatch_table_helper.h
COMMAND ${PROJECT_SOURCE_DIR}/xgl-generate.py dispatch-table-ops layer > xgl_dispatch_table_helper.h
diff --git a/loader/CMakeLists.txt b/loader/CMakeLists.txt
index 13a4b5b7..46fe8142 100644
--- a/loader/CMakeLists.txt
+++ b/loader/CMakeLists.txt
@@ -11,13 +11,17 @@ include_directories(
${CMAKE_CURRENT_BINARY_DIR}
)
-set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DXGL_PROTOTYPES")
if (WIN32)
+ set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DXGL_PROTOTYPES -D_CRT_SECURE_NO_WARNINGS")
+
add_library(XGL SHARED loader.c dirent_on_windows.c dispatch.c table_ops.h)
endif()
if (NOT WIN32)
+ set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DXGL_PROTOTYPES")
+
add_library(XGL SHARED loader.c dispatch.c table_ops.h)
endif()
+
set_target_properties(XGL PROPERTIES SOVERSION 0)
target_link_libraries(XGL -ldl -lpthread)
diff --git a/loader/loader.c b/loader/loader.c
index eb4956c5..2ea37e71 100644
--- a/loader/loader.c
+++ b/loader/loader.c
@@ -356,7 +356,7 @@ static void loader_icd_scan(void)
struct dirent *dent;
char icd_library[1024];
char path[1024];
- int len;
+ uint32_t len;
libPaths = NULL;
#if !defined(WIN32)
@@ -373,11 +373,11 @@ static void loader_icd_scan(void)
for (p = libPaths; *p; p = next) {
next = strchr(p, PATH_SEPERATOR);
if (next == NULL) {
- len = strlen(p);
+ len = (uint32_t) strlen(p);
next = p + len;
}
else {
- len = next - p;
+ len = (uint32_t) (next - p);
sprintf(path, "%.*s", (len > sizeof(path) - 1) ? (int) sizeof(path) - 1 : len, p);
p = path;
next++;
@@ -395,7 +395,7 @@ static void loader_icd_scan(void)
if (!strncmp(dent->d_name,
XGL_DRIVER_LIBRARY_PREFIX,
XGL_DRIVER_LIBRARY_PREFIX_LEN)) {
- int nlen = strlen(dent->d_name);
+ uint32_t nlen = (uint32_t) strlen(dent->d_name);
const char *suf = dent->d_name + nlen - XGL_LIBRARY_SUFFIX_LEN;
if ((nlen > XGL_LIBRARY_SUFFIX_LEN) &&
!strncmp(suf,
@@ -422,13 +422,13 @@ static void layer_lib_scan_path(const char * libInPaths)
char *libPaths;
DIR *curdir;
struct dirent *dent;
- int len, i;
+ uint32_t len, i;
char temp_str[1024];
len = 0;
loader.layer_dirs = NULL;
if (libInPaths){
- len = strlen(libInPaths);
+ len = (uint32_t) strlen(libInPaths);
p = libInPaths;
}
else {
@@ -437,14 +437,14 @@ static void layer_lib_scan_path(const char * libInPaths)
#endif // WIN32
p = getenv("LIBXGL_LAYERS_PATH");
if (p != NULL)
- len = strlen(p);
+ len = (uint32_t) strlen(p);
#if !defined(WIN32)
}
#endif // WIN32
}
if (len == 0) {
- len = strlen(DEFAULT_XGL_LAYERS_PATH);
+ len = (uint32_t) strlen(DEFAULT_XGL_LAYERS_PATH);
p = DEFAULT_XGL_LAYERS_PATH;
}
@@ -471,11 +471,11 @@ static void layer_lib_scan_path(const char * libInPaths)
for (p = libPaths; *p; p = next) {
next = strchr(p, PATH_SEPERATOR);
if (next == NULL) {
- len = strlen(p);
+ len = (uint32_t) strlen(p);
next = p + len;
}
else {
- len = next - p;
+ len = (uint32_t) (next - p);
*(char *) next = '\0';
next++;
}
@@ -490,7 +490,7 @@ static void layer_lib_scan_path(const char * libInPaths)
if (!strncmp(dent->d_name,
XGL_LAYER_LIBRARY_PREFIX,
XGL_LAYER_LIBRARY_PREFIX_LEN)) {
- int nlen = strlen(dent->d_name);
+ uint32_t nlen = (uint32_t) strlen(dent->d_name);
const char *suf = dent->d_name + nlen - XGL_LIBRARY_SUFFIX_LEN;
if ((nlen > XGL_LIBRARY_SUFFIX_LEN) &&
!strncmp(suf,
@@ -526,7 +526,7 @@ static void layer_lib_scan_path(const char * libInPaths)
loader.layer_scanned = true;
}
-static void layer_lib_scan()
+static void layer_lib_scan(void)
{
layer_lib_scan_path(NULL);
}
@@ -661,11 +661,11 @@ static uint32_t loader_get_layer_env(struct loader_icd *icd, uint32_t gpu_index,
const char *lib_name = NULL;
next = strchr(p, PATH_SEPERATOR);
if (next == NULL) {
- len = strlen(p);
+ len = (uint32_t) strlen(p);
next = p + len;
}
else {
- len = next - p;
+ len = (uint32_t) (next - p);
*(char *) next = '\0';
next++;
}
@@ -675,7 +675,7 @@ static uint32_t loader_get_layer_env(struct loader_icd *icd, uint32_t gpu_index,
continue;
}
- len = strlen(name);
+ len = (uint32_t) strlen(name);
pLayerNames[count].layer_name = malloc(len + 1);
if (!pLayerNames[count].layer_name) {
free(pOrig);
@@ -714,7 +714,7 @@ static uint32_t loader_get_layer_libs(struct loader_icd *icd, uint32_t gpu_index
name = *(pCi->ppActiveLayerNames + i);
if (!find_layer_name(icd, gpu_index, name, &lib_name))
return loader_get_layer_env(icd, gpu_index, layerNames);
- len = strlen(name);
+ len = (uint32_t) strlen(name);
layerNames[i].layer_name = malloc(len + 1);
if (!layerNames[i].layer_name)
return i;
@@ -959,7 +959,7 @@ LOADER_EXPORT XGL_RESULT XGLAPI xglEnumerateGpus(
icd->gpu_count = n;
icd->loader_dispatch = (XGL_LAYER_DISPATCH_TABLE *) malloc(n *
sizeof(XGL_LAYER_DISPATCH_TABLE));
- for (int i = 0; i < n; i++) {
+ for (unsigned int i = 0; i < n; i++) {
(wrapped_gpus + i)->baseObject = gpus[i];
(wrapped_gpus + i)->pGPA = get_proc_addr;
(wrapped_gpus + i)->nextObject = gpus[i];
@@ -1020,7 +1020,7 @@ LOADER_EXPORT void * XGLAPI xglGetProcAddr(XGL_PHYSICAL_GPU gpu, const char * pN
LOADER_EXPORT XGL_RESULT XGLAPI xglEnumerateLayers(XGL_PHYSICAL_GPU gpu, size_t maxLayerCount, size_t maxStringSize, size_t* pOutLayerCount, char* const* pOutLayers, void* pReserved)
{
uint32_t gpu_index;
- uint32_t count = 0;
+ size_t count = 0;
char *lib_name;
struct loader_icd *icd = loader_get_icd((const XGL_BASE_LAYER_OBJECT *) gpu, &gpu_index);
loader_platform_dl_handle handle;
@@ -1049,7 +1049,7 @@ LOADER_EXPORT XGL_RESULT XGLAPI xglEnumerateLayers(XGL_PHYSICAL_GPU gpu, size_t
loader_platform_close_library(handle);
lib_name = basename(lib_name);
pEnd = strrchr(lib_name, '.');
- siz = pEnd - lib_name - strlen(XGL_LAYER_LIBRARY_PREFIX) + 1;
+ siz = (int) (pEnd - lib_name - strlen(XGL_LAYER_LIBRARY_PREFIX) + 1);
if (pEnd == NULL || siz <= 0)
continue;
cpyStr = malloc(siz);
@@ -1060,7 +1060,7 @@ LOADER_EXPORT XGL_RESULT XGLAPI xglEnumerateLayers(XGL_PHYSICAL_GPU gpu, size_t
strncpy(cpyStr, lib_name + strlen(XGL_LAYER_LIBRARY_PREFIX), siz);
cpyStr[siz - 1] = '\0';
if (siz > maxStringSize)
- siz = maxStringSize;
+ siz = (int) maxStringSize;
strncpy((char *) (pOutLayers[count]), cpyStr, siz);
pOutLayers[count][siz - 1] = '\0';
count++;
@@ -1070,14 +1070,14 @@ LOADER_EXPORT XGL_RESULT XGLAPI xglEnumerateLayers(XGL_PHYSICAL_GPU gpu, size_t
size_t cnt;
uint32_t n;
XGL_RESULT res;
- n = (maxStringSize < 256) ? maxStringSize : 256;
+ n = (uint32_t) ((maxStringSize < 256) ? maxStringSize : 256);
res = fpEnumerateLayers(NULL, 16, n, &cnt, layers, (char *) icd->gpus + gpu_index);
loader_platform_close_library(handle);
if (res != XGL_SUCCESS)
continue;
if (cnt + count > maxLayerCount)
cnt = maxLayerCount - count;
- for (unsigned int i = count; i < cnt + count; i++) {
+ for (uint32_t i = (uint32_t) count; i < cnt + count; i++) {
strncpy((char *) (pOutLayers[i]), (char *) layers[i - count], n);
if (n > 0)
pOutLayers[i - count][n - 1] = '\0';
diff --git a/loader/loader_platform.h b/loader/loader_platform.h
index 0ff9671d..e567700b 100644
--- a/loader/loader_platform.h
+++ b/loader/loader_platform.h
@@ -167,7 +167,8 @@ using namespace std;
// C99:
// Microsoft didn't implement C99 in Visual Studio; but started adding it with
// VS2013. However, VS2013 still didn't have snprintf(). The following is a
-// work-around.
+// work-around (Note: The _CRT_SECURE_NO_WARNINGS macro must be set in the
+// "CMakeLists.txt" file).
#define snprintf _snprintf
#define STATIC_INLINE static
// Microsoft also doesn't have basename(). Paths are different on Windows, and
@@ -192,6 +193,8 @@ static char *basename(char *pathname)
next++;
}
}
+ // We shouldn't get to here, but this makes the compiler happy:
+ return current;
}
// Dynamic Loading: