From 795af921ccd69f38b35afa6f770501faa88393b2 Mon Sep 17 00:00:00 2001 From: Sandu Liviu Catalin Date: Wed, 16 Nov 2016 10:47:29 +0200 Subject: [PATCH 1/5] Never assume the format is actually a string. The invoker should at least know that the value he specified is not of the correct type. --- sqstdlib/sqstdstring.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/sqstdlib/sqstdstring.cpp b/sqstdlib/sqstdstring.cpp index bce6043..e624646 100644 --- a/sqstdlib/sqstdstring.cpp +++ b/sqstdlib/sqstdstring.cpp @@ -69,7 +69,10 @@ SQRESULT sqstd_format(HSQUIRRELVM v,SQInteger nformatstringidx,SQInteger *outlen const SQChar *format; SQChar *dest; SQChar fmt[MAX_FORMAT_LEN]; - sq_getstring(v,nformatstringidx,&format); + const SQRESULT res = sq_getstring(v,nformatstringidx,&format); + if (SQ_FAILED(res)) { + return res; // propagate the error + } SQInteger format_size = sq_getsize(v,nformatstringidx); SQInteger allocated = (format_size+2)*sizeof(SQChar); dest = sq_getscratchpad(v,allocated); From d130dc5471e3a247492626423df71efc4544ef9b Mon Sep 17 00:00:00 2001 From: Paul Date: Sat, 25 Feb 2017 14:40:47 +0000 Subject: [PATCH 2/5] Add DISABLE_DYNAMIC to disable building shared libs for the case where you only want static libs. --- sq/CMakeLists.txt | 14 +++++++++----- sqstdlib/CMakeLists.txt | 16 ++++++++++------ squirrel/CMakeLists.txt | 6 +++++- 3 files changed, 24 insertions(+), 12 deletions(-) diff --git a/sq/CMakeLists.txt b/sq/CMakeLists.txt index 3d05006..2b2733f 100644 --- a/sq/CMakeLists.txt +++ b/sq/CMakeLists.txt @@ -1,7 +1,9 @@ -add_executable(sq sq.c) -set_target_properties(sq PROPERTIES LINKER_LANGUAGE C) -target_link_libraries(sq squirrel sqstdlib) -install(TARGETS sq RUNTIME DESTINATION ${INSTALL_BIN_DIR}) +if(NOT DEFINED DISABLE_DYNAMIC) + add_executable(sq sq.c) + set_target_properties(sq PROPERTIES LINKER_LANGUAGE C) + target_link_libraries(sq squirrel sqstdlib) + install(TARGETS sq RUNTIME DESTINATION ${INSTALL_BIN_DIR}) +endif() if(NOT DEFINED DISABLE_STATIC) add_executable(sq_static sq.c) @@ -11,7 +13,9 @@ if(NOT DEFINED DISABLE_STATIC) endif() if(DEFINED LONG_OUTPUT_NAMES) - set_target_properties(sq PROPERTIES OUTPUT_NAME squirrel3) + if(NOT DEFINED DISABLE_DYNAMIC) + set_target_properties(sq PROPERTIES OUTPUT_NAME squirrel3) + endif() if(NOT DEFINED DISABLE_STATIC) set_target_properties(sq_static PROPERTIES OUTPUT_NAME squirrel3_static) diff --git a/sqstdlib/CMakeLists.txt b/sqstdlib/CMakeLists.txt index 493b0a5..d847393 100644 --- a/sqstdlib/CMakeLists.txt +++ b/sqstdlib/CMakeLists.txt @@ -7,11 +7,13 @@ set(SQSTDLIB_SRC sqstdaux.cpp sqstdstring.cpp sqstdsystem.cpp) -add_library(sqstdlib SHARED ${SQSTDLIB_SRC}) -target_link_libraries(sqstdlib squirrel) -install(TARGETS sqstdlib RUNTIME DESTINATION ${INSTALL_BIN_DIR} - LIBRARY DESTINATION ${INSTALL_LIB_DIR} - ARCHIVE DESTINATION ${INSTALL_LIB_DIR}) +if(NOT DEFINED DISABLE_DYNAMIC) + add_library(sqstdlib SHARED ${SQSTDLIB_SRC}) + target_link_libraries(sqstdlib squirrel) + install(TARGETS sqstdlib RUNTIME DESTINATION ${INSTALL_BIN_DIR} + LIBRARY DESTINATION ${INSTALL_LIB_DIR} + ARCHIVE DESTINATION ${INSTALL_LIB_DIR}) +endif() if(NOT DEFINED DISABLE_STATIC) add_library(sqstdlib_static STATIC ${SQSTDLIB_SRC}) @@ -19,7 +21,9 @@ if(NOT DEFINED DISABLE_STATIC) endif() if(DEFINED LONG_OUTPUT_NAMES) - set_target_properties(sqstdlib PROPERTIES OUTPUT_NAME sqstdlib3) + if(NOT DEFINED DISABLE_DYNAMIC) + set_target_properties(sqstdlib PROPERTIES OUTPUT_NAME sqstdlib3) + endif() if(NOT DEFINED DISABLE_STATIC) set_target_properties(sqstdlib_static PROPERTIES OUTPUT_NAME sqstdlib3_static) diff --git a/squirrel/CMakeLists.txt b/squirrel/CMakeLists.txt index 6efef84..ab42054 100644 --- a/squirrel/CMakeLists.txt +++ b/squirrel/CMakeLists.txt @@ -11,10 +11,12 @@ set(SQUIRREL_SRC sqapi.cpp sqtable.cpp sqvm.cpp) +if(NOT DEFINED DISABLE_DYNAMIC) add_library(squirrel SHARED ${SQUIRREL_SRC}) install(TARGETS squirrel RUNTIME DESTINATION ${INSTALL_BIN_DIR} LIBRARY DESTINATION ${INSTALL_LIB_DIR} ARCHIVE DESTINATION ${INSTALL_LIB_DIR}) +endif() if(NOT DEFINED DISABLE_STATIC) add_library(squirrel_static STATIC ${SQUIRREL_SRC}) @@ -22,7 +24,9 @@ if(NOT DEFINED DISABLE_STATIC) endif() if(DEFINED LONG_OUTPUT_NAMES) - set_target_properties(squirrel PROPERTIES OUTPUT_NAME squirrel3) + if(NOT DEFINED DISABLE_DYNAMIC) + set_target_properties(squirrel PROPERTIES OUTPUT_NAME squirrel3) + endif() if(NOT DEFINED DISABLE_STATIC) set_target_properties(squirrel_static PROPERTIES OUTPUT_NAME squirrel3_static) From bdcb7cc12b6c27c0cf008378381c6812a03b3bae Mon Sep 17 00:00:00 2001 From: Jan Solanti Date: Fri, 10 Mar 2017 19:42:10 +0200 Subject: [PATCH 3/5] Fix building as a git submodule. CMAKE_SOURCE_DIR points at the root project's source dir, which is wrong when building squirrel as a git submodule. CMAKE_CURRENT_SOURCE_DIR points at the dir of the current CMakeLists.txt and thus should be used most of the time. --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 42185e1..00bf8f8 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -9,7 +9,7 @@ set(CMAKE_BUILD_TYPE "Release" CACHE STRING "") project(squirrel C CXX) -include_directories(${CMAKE_SOURCE_DIR}/include) +include_directories(${CMAKE_CURRENT_SOURCE_DIR}/include) if(CMAKE_COMPILER_IS_GNUCXX) set(SQ_FLAGS -fno-exceptions -fno-strict-aliasing -Wall -Wextra -pedantic -Wcast-qual) From aa4afc5b145b52c49b54399234dcc701b5e40fc7 Mon Sep 17 00:00:00 2001 From: Paul Date: Mon, 27 Mar 2017 21:08:56 +0100 Subject: [PATCH 4/5] Allow disable of CMake install() sections --- CMakeLists.txt | 14 ++++++++------ sq/CMakeLists.txt | 8 ++++++-- sqstdlib/CMakeLists.txt | 8 ++++++-- squirrel/CMakeLists.txt | 10 +++++++--- 4 files changed, 27 insertions(+), 13 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 00bf8f8..e339ba5 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -39,19 +39,21 @@ if(CMAKE_SIZEOF_VOID_P EQUAL 8) add_definitions(-D_SQ64) endif() -if(NOT DEFINED INSTALL_BIN_DIR) - set(INSTALL_BIN_DIR bin) -endif() +if(NOT DEFINED SQ_DISABLE_INSTALLER) + if(NOT DEFINED INSTALL_BIN_DIR) + set(INSTALL_BIN_DIR bin) + endif() -if(NOT DEFINED INSTALL_LIB_DIR) - set(INSTALL_LIB_DIR lib) + if(NOT DEFINED INSTALL_LIB_DIR) + set(INSTALL_LIB_DIR lib) + endif() endif() add_subdirectory(squirrel) add_subdirectory(sqstdlib) add_subdirectory(sq) -if(NOT WIN32) +if(NOT WIN32 AND NOT DEFINED DISABLE_DYNAMIC) set_target_properties(squirrel sqstdlib PROPERTIES SOVERSION 0 VERSION 0.0.0) endif() diff --git a/sq/CMakeLists.txt b/sq/CMakeLists.txt index 2b2733f..2ce35c3 100644 --- a/sq/CMakeLists.txt +++ b/sq/CMakeLists.txt @@ -2,14 +2,18 @@ if(NOT DEFINED DISABLE_DYNAMIC) add_executable(sq sq.c) set_target_properties(sq PROPERTIES LINKER_LANGUAGE C) target_link_libraries(sq squirrel sqstdlib) - install(TARGETS sq RUNTIME DESTINATION ${INSTALL_BIN_DIR}) + if(NOT DEFINED SQ_DISABLE_INSTALLER) + install(TARGETS sq RUNTIME DESTINATION ${INSTALL_BIN_DIR}) + endif() endif() if(NOT DEFINED DISABLE_STATIC) add_executable(sq_static sq.c) set_target_properties(sq_static PROPERTIES LINKER_LANGUAGE C) target_link_libraries(sq_static squirrel_static sqstdlib_static) - install(TARGETS sq_static RUNTIME DESTINATION ${INSTALL_BIN_DIR}) + if(NOT DEFINED SQ_DISABLE_INSTALLER) + install(TARGETS sq_static RUNTIME DESTINATION ${INSTALL_BIN_DIR}) + endif() endif() if(DEFINED LONG_OUTPUT_NAMES) diff --git a/sqstdlib/CMakeLists.txt b/sqstdlib/CMakeLists.txt index d847393..86ad721 100644 --- a/sqstdlib/CMakeLists.txt +++ b/sqstdlib/CMakeLists.txt @@ -10,14 +10,18 @@ set(SQSTDLIB_SRC sqstdaux.cpp if(NOT DEFINED DISABLE_DYNAMIC) add_library(sqstdlib SHARED ${SQSTDLIB_SRC}) target_link_libraries(sqstdlib squirrel) - install(TARGETS sqstdlib RUNTIME DESTINATION ${INSTALL_BIN_DIR} + if(NOT DEFINED SQ_DISABLE_INSTALLER) + install(TARGETS sqstdlib RUNTIME DESTINATION ${INSTALL_BIN_DIR} LIBRARY DESTINATION ${INSTALL_LIB_DIR} ARCHIVE DESTINATION ${INSTALL_LIB_DIR}) + endif() endif() if(NOT DEFINED DISABLE_STATIC) add_library(sqstdlib_static STATIC ${SQSTDLIB_SRC}) - install(TARGETS sqstdlib_static ARCHIVE DESTINATION ${INSTALL_LIB_DIR}) + if(NOT DEFINED SQ_DISABLE_INSTALLER) + install(TARGETS sqstdlib_static ARCHIVE DESTINATION ${INSTALL_LIB_DIR}) + endif() endif() if(DEFINED LONG_OUTPUT_NAMES) diff --git a/squirrel/CMakeLists.txt b/squirrel/CMakeLists.txt index ab42054..8ba67fb 100644 --- a/squirrel/CMakeLists.txt +++ b/squirrel/CMakeLists.txt @@ -12,15 +12,19 @@ set(SQUIRREL_SRC sqapi.cpp sqvm.cpp) if(NOT DEFINED DISABLE_DYNAMIC) -add_library(squirrel SHARED ${SQUIRREL_SRC}) -install(TARGETS squirrel RUNTIME DESTINATION ${INSTALL_BIN_DIR} + add_library(squirrel SHARED ${SQUIRREL_SRC}) + if(NOT DEFINED SQ_DISABLE_INSTALLER) + install(TARGETS squirrel RUNTIME DESTINATION ${INSTALL_BIN_DIR} LIBRARY DESTINATION ${INSTALL_LIB_DIR} ARCHIVE DESTINATION ${INSTALL_LIB_DIR}) + endif() endif() if(NOT DEFINED DISABLE_STATIC) add_library(squirrel_static STATIC ${SQUIRREL_SRC}) - install(TARGETS squirrel_static ARCHIVE DESTINATION ${INSTALL_LIB_DIR}) + if(NOT DEFINED SQ_DISABLE_INSTALLER) + install(TARGETS squirrel_static ARCHIVE DESTINATION ${INSTALL_LIB_DIR}) + endif() endif() if(DEFINED LONG_OUTPUT_NAMES) From 76c67169ed3d18b57ec22237c60ec5caebad9f06 Mon Sep 17 00:00:00 2001 From: Paul Date: Mon, 27 Mar 2017 21:13:42 +0100 Subject: [PATCH 5/5] Disable noisy MSVC warning that will never be fixed --- CMakeLists.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index 00bf8f8..57d565e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -33,6 +33,7 @@ if(CMAKE_COMPILER_IS_GNUCXX) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-rtti -std=c++0x") elseif(MSVC) set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS ON) + add_definitions(-D_CRT_SECURE_NO_WARNINGS) endif() if(CMAKE_SIZEOF_VOID_P EQUAL 8)