From 026897e53b436f33758a6119f169cfdb1c60283e Mon Sep 17 00:00:00 2001 From: Michael Trinkala Date: Thu, 4 Feb 2016 16:52:27 -0800 Subject: [PATCH] Correct compilation errors on Windows --- CMakeLists.txt | 4 +++- include/luasandbox.h | 8 ++++---- include/luasandbox/error.h | 4 ++-- include/luasandbox/heka/sandbox.h | 4 ++-- include/luasandbox/util/util.h | 8 ++++---- src/CMakeLists.txt | 2 -- src/heka/CMakeLists.txt | 2 +- src/heka/message.c | 2 +- src/heka/sandbox.c | 5 ++++- src/luasandbox.c | 7 +++---- src/util/CMakeLists.txt | 2 +- src/util/output_buffer.c | 8 ++++++-- src/util/util.c | 4 ++-- 13 files changed, 33 insertions(+), 27 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index fe56424..f127c4f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -42,7 +42,6 @@ set(LIB_INSTALL_DIR lib/) set(INCLUDE_INSTALL_DIR include/) include_directories("${EP_BASE}/include") -include_directories("${CMAKE_SOURCE_DIR}/include") install(DIRECTORY "${CMAKE_SOURCE_DIR}/modules/" DESTINATION ${LIB_INSTALL_DIR}${PROJECT_NAME}/modules COMPONENT core) install(FILES "${CMAKE_SOURCE_DIR}/README.md" DESTINATION share/doc/${PROJECT_NAME} COMPONENT core) @@ -63,3 +62,6 @@ install(FILES ${CMAKE_CURRENT_BINARY_DIR}/luasandboxConfig.cmake ${CMAKE_CURRENT DESTINATION ${INSTALL_CMAKE_DIR} COMPONENT core) add_subdirectory(src) +add_custom_target(copy_includes +COMMAND ${CMAKE_COMMAND} -E copy_directory ${CMAKE_SOURCE_DIR}/include ${EP_BASE}/include) +add_dependencies(luasandboxutil copy_includes) diff --git a/include/luasandbox.h b/include/luasandbox.h index 94cfe80..fe14687 100644 --- a/include/luasandbox.h +++ b/include/luasandbox.h @@ -60,15 +60,15 @@ typedef enum { typedef struct lsb_lua_sandbox lsb_lua_sandbox; -LSB_EXPORT extern lsb_err_id LSB_ERR_INIT; -LSB_EXPORT extern lsb_err_id LSB_ERR_LUA; -LSB_EXPORT extern lsb_err_id LSB_ERR_TERMINATED; - #ifdef __cplusplus extern "C" { #endif +LSB_EXPORT extern lsb_err_id LSB_ERR_INIT; +LSB_EXPORT extern lsb_err_id LSB_ERR_LUA; +LSB_EXPORT extern lsb_err_id LSB_ERR_TERMINATED; + /** * Allocates and initializes the structure around the Lua sandbox allowing * full specification of the sandbox configuration using a Lua configuration diff --git a/include/luasandbox/error.h b/include/luasandbox/error.h index fc4501b..39b1a60 100644 --- a/include/luasandbox/error.h +++ b/include/luasandbox/error.h @@ -11,8 +11,8 @@ // See Identify your Errors better with char[] // http://accu.org/index.php/journals/2184 -typedef char const lsb_err_id[]; -typedef char const *lsb_err_value; +typedef const char lsb_err_id[]; +typedef const char *lsb_err_value; #define lsb_err_string(s) s ? s : "" typedef void (*lsb_logger)(const char *component, diff --git a/include/luasandbox/heka/sandbox.h b/include/luasandbox/heka/sandbox.h index c90205e..b287dca 100644 --- a/include/luasandbox/heka/sandbox.h +++ b/include/luasandbox/heka/sandbox.h @@ -33,8 +33,6 @@ #define LSB_HEKA_MAX_MESSAGE_SIZE "max_message_size" -LSB_HEKA_EXPORT extern lsb_err_id LSB_ERR_HEKA_INPUT; - enum lsb_heka_pm_rv { LSB_HEKA_PM_SENT = 0, LSB_HEKA_PM_FAIL = -1, @@ -66,6 +64,8 @@ extern "C" { #endif +LSB_HEKA_EXPORT extern lsb_err_id LSB_ERR_HEKA_INPUT; + /** * inject_message callback function provided by the host. Only one (or neither) * of the checkpoint values will be set in a call. Numeric checkpoints can have diff --git a/include/luasandbox/util/util.h b/include/luasandbox/util/util.h index d040570..e17b62e 100644 --- a/include/luasandbox/util/util.h +++ b/include/luasandbox/util/util.h @@ -27,15 +27,15 @@ #endif #endif +#ifdef __cplusplus +extern "C" { +#endif + LSB_UTIL_EXPORT extern lsb_err_id LSB_ERR_UTIL_NULL; LSB_UTIL_EXPORT extern lsb_err_id LSB_ERR_UTIL_OOM; LSB_UTIL_EXPORT extern lsb_err_id LSB_ERR_UTIL_FULL; LSB_UTIL_EXPORT extern lsb_err_id LSB_ERR_UTIL_PRANGE; -#ifdef __cplusplus -extern "C" { -#endif - /** * Hacker's Delight - Henry S. Warren, Jr. page 48 * diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index bcaf288..f81ef80 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -11,9 +11,7 @@ luasandbox_serialize.c set ( CMAKE_SKIP_BUILD_RPATH FALSE CACHE STRING "" FORCE ) set ( CMAKE_BUILD_WITH_INSTALL_RPATH FALSE CACHE STRING "" FORCE ) -add_custom_target(copy_includes COMMAND ${CMAKE_COMMAND} -E copy_directory ${CMAKE_SOURCE_DIR}/include ${EP_BASE}/include) add_library(luasandbox SHARED ${LUA_SANDBOX_SRC}) -add_dependencies(luasandbox copy_includes) add_dependencies(lua_bloom_filter luasandbox) add_dependencies(lua_circular_buffer luasandbox) diff --git a/src/heka/CMakeLists.txt b/src/heka/CMakeLists.txt index 983d8a5..522cea8 100644 --- a/src/heka/CMakeLists.txt +++ b/src/heka/CMakeLists.txt @@ -11,7 +11,7 @@ stream_reader.c add_library(luasandboxheka SHARED ${HEKA_SRC}) set_target_properties(luasandboxheka PROPERTIES VERSION ${CPACK_PACKAGE_VERSION_MAJOR}.${CPACK_PACKAGE_VERSION_MINOR}.${CPACK_PACKAGE_VERSION_PATCH} SOVERSION 0) -target_compile_definitions(luasandboxheka PUBLIC -Dluasandboxheka_EXPORTS) +target_compile_definitions(luasandboxheka PRIVATE -Dluasandboxheka_EXPORTS) target_link_libraries(luasandboxheka luasandbox) if(WIN32) target_link_libraries(luasandboxheka ws2_32) diff --git a/src/heka/message.c b/src/heka/message.c index 7f769f5..dd743a2 100644 --- a/src/heka/message.c +++ b/src/heka/message.c @@ -330,7 +330,7 @@ static lsb_err_value encode_field_array(lsb_lua_sandbox *lsb, lsb_output_buffer *ob, int t, const char *representation, int value_type) { - lsb_err_value ret; + lsb_err_value ret = NULL; int first = (int)lua_objlen(lsb->lua, -1); int multiple = first > 1 ? first : 0; size_t len_pos = 0; diff --git a/src/heka/sandbox.c b/src/heka/sandbox.c index c2629c0..6aec594 100644 --- a/src/heka/sandbox.c +++ b/src/heka/sandbox.c @@ -23,6 +23,7 @@ #ifdef _WIN32 #include +#define snprintf _snprintf #else #include #endif @@ -499,7 +500,9 @@ int lsb_heka_pm_input(lsb_heka_sandbox *hsb, const char *cp_string, bool profile) { - if (!hsb || hsb->type != 'i') return 1; + if (!hsb || hsb->type != 'i') { + return 1; + } lsb_err_value ret = lsb_pcall_setup(hsb->lsb, pm_func_name); if (ret) { diff --git a/src/luasandbox.c b/src/luasandbox.c index 8fad3df..1abe7b5 100644 --- a/src/luasandbox.c +++ b/src/luasandbox.c @@ -23,10 +23,9 @@ #include "luasandbox_impl.h" #include "luasandbox_serialize.h" - -lsb_err_id LSB_ERR_INIT = "already initialized"; -lsb_err_id LSB_ERR_LUA = "lua error"; // use lsb_get_error for more detail -lsb_err_id LSB_ERR_TERMINATED = "sandbox already terminated"; +lsb_err_id LSB_ERR_INIT = "already initialized"; +lsb_err_id LSB_ERR_LUA = "lua error"; // use lsb_get_error for details +lsb_err_id LSB_ERR_TERMINATED = "sandbox already terminated"; static jmp_buf g_jbuf; diff --git a/src/util/CMakeLists.txt b/src/util/CMakeLists.txt index 518f63b..c04b7a1 100644 --- a/src/util/CMakeLists.txt +++ b/src/util/CMakeLists.txt @@ -15,7 +15,7 @@ util.c add_library(luasandboxutil SHARED ${UTIL_SRC}) set_target_properties(luasandboxutil PROPERTIES VERSION ${CPACK_PACKAGE_VERSION_MAJOR}.${CPACK_PACKAGE_VERSION_MINOR}.${CPACK_PACKAGE_VERSION_PATCH} SOVERSION 0) -target_compile_definitions(luasandboxutil PUBLIC -Dluasandboxutil_EXPORTS) +target_compile_definitions(luasandboxutil PRIVATE -Dluasandboxutil_EXPORTS) if(LIBM_LIBRARY) target_link_libraries(luasandboxutil ${LIBM_LIBRARY}) diff --git a/src/util/output_buffer.c b/src/util/output_buffer.c index bfd6e66..54f56a8 100644 --- a/src/util/output_buffer.c +++ b/src/util/output_buffer.c @@ -77,7 +77,9 @@ lsb_err_value lsb_expand_output_buffer(lsb_output_buffer *b, size_t needed) lsb_err_value lsb_outputc(lsb_output_buffer *b, char ch) { - if (!b) return LSB_ERR_UTIL_NULL; + if (!b) { + return LSB_ERR_UTIL_NULL; + } lsb_err_value ret = lsb_expand_output_buffer(b, 2); if (ret) return ret; @@ -143,7 +145,9 @@ lsb_err_value lsb_outputf(lsb_output_buffer *b, const char *fmt, ...) lsb_err_value lsb_outputs(lsb_output_buffer *b, const char *str, size_t len) { - if (!b) return LSB_ERR_UTIL_NULL; + if (!b) { + return LSB_ERR_UTIL_NULL; + } lsb_err_value ret = lsb_expand_output_buffer(b, len + 1); if (ret) return ret; diff --git a/src/util/util.c b/src/util/util.c index 7e26b75..c97cc30 100644 --- a/src/util/util.c +++ b/src/util/util.c @@ -6,6 +6,8 @@ /** General purpose utility functions @file */ +#include "luasandbox/util/util.h" + #include #include #include @@ -23,8 +25,6 @@ #include #endif -#include "luasandbox/util/util.h" - lsb_err_id LSB_ERR_UTIL_NULL = "pointer is NULL"; lsb_err_id LSB_ERR_UTIL_OOM = "memory allocation failed"; lsb_err_id LSB_ERR_UTIL_FULL = "buffer full";