From 698dfb06db216630d3fa2f54a85b7c658059c9e5 Mon Sep 17 00:00:00 2001 From: ftk Date: Sun, 5 Mar 2017 20:54:01 +0300 Subject: [PATCH 1/9] Loadable module support can be disabled by defining CHAISCRIPT_NO_DYNLOAD --- include/chaiscript/language/chaiscript_engine.hpp | 7 ++++--- include/chaiscript/language/chaiscript_unknown.hpp | 4 ++++ 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/include/chaiscript/language/chaiscript_engine.hpp b/include/chaiscript/language/chaiscript_engine.hpp index 5d8b6f0..27b4698 100644 --- a/include/chaiscript/language/chaiscript_engine.hpp +++ b/include/chaiscript/language/chaiscript_engine.hpp @@ -36,12 +36,13 @@ #include #endif -#if defined(_POSIX_VERSION) && !defined(__CYGWIN__) +#if !defined(CHAISCRIPT_NO_DYNLOAD) && defined(_POSIX_VERSION) && !defined(__CYGWIN__) #include #endif - -#ifdef CHAISCRIPT_WINDOWS +#if defined(CHAISCRIPT_NO_DYNLOAD) +#include "chaiscript_unknown.hpp" +#elif defined(CHAISCRIPT_WINDOWS) #include "chaiscript_windows.hpp" #elif _POSIX_VERSION #include "chaiscript_posix.hpp" diff --git a/include/chaiscript/language/chaiscript_unknown.hpp b/include/chaiscript/language/chaiscript_unknown.hpp index 9e1d7af..8fc1d49 100644 --- a/include/chaiscript/language/chaiscript_unknown.hpp +++ b/include/chaiscript/language/chaiscript_unknown.hpp @@ -16,7 +16,11 @@ namespace chaiscript { Loadable_Module(const std::string &, const std::string &) { +#ifdef CHAISCRIPT_NO_DYNLOAD + throw chaiscript::exception::load_module_error("Loadable module support was disabled (CHAISCRIPT_NO_DYNLOAD)"); +#else throw chaiscript::exception::load_module_error("Loadable module support not available for your platform"); +#endif } ModulePtr m_moduleptr; From 84f9c44ab628b9445e2bf62c95609f7625ce244b Mon Sep 17 00:00:00 2001 From: ftk Date: Sun, 5 Mar 2017 21:23:05 +0300 Subject: [PATCH 2/9] Do not register load_module by default when dynamic loading is disabled --- include/chaiscript/chaiscript_defines.hpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/include/chaiscript/chaiscript_defines.hpp b/include/chaiscript/chaiscript_defines.hpp index cc349a0..be837c2 100644 --- a/include/chaiscript/chaiscript_defines.hpp +++ b/include/chaiscript/chaiscript_defines.hpp @@ -216,7 +216,11 @@ namespace chaiscript { static inline std::vector default_options() { +#ifdef CHAISCRIPT_NO_DYNLOAD + return {Options::No_Load_Modules, Options::External_Scripts}; +#else return {Options::Load_Modules, Options::External_Scripts}; +#endif } } #endif From 72cb9bd940530dbb56ebb68b5fedb14cfe48c05c Mon Sep 17 00:00:00 2001 From: ftk Date: Sun, 5 Mar 2017 21:26:01 +0300 Subject: [PATCH 3/9] Compile out module path search code when module support is disabled --- include/chaiscript/language/chaiscript_engine.hpp | 2 +- samples/fun_call_performance.cpp | 2 ++ src/main.cpp | 2 ++ 3 files changed, 5 insertions(+), 1 deletion(-) diff --git a/include/chaiscript/language/chaiscript_engine.hpp b/include/chaiscript/language/chaiscript_engine.hpp index 27b4698..16110f0 100644 --- a/include/chaiscript/language/chaiscript_engine.hpp +++ b/include/chaiscript/language/chaiscript_engine.hpp @@ -243,7 +243,7 @@ namespace chaiscript m_parser(std::move(parser)), m_engine(*m_parser) { -#if defined(_POSIX_VERSION) && !defined(__CYGWIN__) +#if !defined(CHAISCRIPT_NO_DYNLOAD) && defined(_POSIX_VERSION) && !defined(__CYGWIN__) // If on Unix, add the path of the current executable to the module search path // as windows would do diff --git a/samples/fun_call_performance.cpp b/samples/fun_call_performance.cpp index a519052..b8bda5a 100644 --- a/samples/fun_call_performance.cpp +++ b/samples/fun_call_performance.cpp @@ -68,6 +68,7 @@ std::vector default_search_paths() { std::vector paths; +#ifndef CHAISCRIPT_NO_DYNLOAD #ifdef CHAISCRIPT_WINDOWS // force no unicode CHAR path[4096]; int size = GetModuleFileNameA(0, path, sizeof(path) - 1); @@ -137,6 +138,7 @@ std::vector default_search_paths() paths.push_back(exepath.substr(0, secondtolastslash) + "/lib/chaiscript/"); } #endif +#endif // ifndef CHAISCRIPT_NO_DYNLOAD return paths; } diff --git a/src/main.cpp b/src/main.cpp index 4179a6b..78044e0 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -71,6 +71,7 @@ std::vector default_search_paths() { std::vector paths; +#ifndef CHAISCRIPT_NO_DYNLOAD #ifdef CHAISCRIPT_WINDOWS // force no unicode CHAR path[4096]; int size = GetModuleFileNameA(nullptr, path, sizeof(path)-1); @@ -140,6 +141,7 @@ std::vector default_search_paths() paths.push_back(exepath.substr(0, secondtolastslash) + "/lib/chaiscript/"); } #endif +#endif // ifndef CHAISCRIPT_NO_DYNLOAD return paths; } From c2f7ca3aa220911eb6dde46560c71c0dec9177e2 Mon Sep 17 00:00:00 2001 From: ftk Date: Sun, 5 Mar 2017 21:48:59 +0300 Subject: [PATCH 4/9] Using runtime stdlib constructor will result in compilation error --- include/chaiscript/language/chaiscript_engine.hpp | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/include/chaiscript/language/chaiscript_engine.hpp b/include/chaiscript/language/chaiscript_engine.hpp index 16110f0..b2df16b 100644 --- a/include/chaiscript/language/chaiscript_engine.hpp +++ b/include/chaiscript/language/chaiscript_engine.hpp @@ -279,6 +279,7 @@ namespace chaiscript build_eval_system(t_lib, t_opts); } +#ifndef CHAISCRIPT_NO_DYNLOAD /// \brief Constructor for ChaiScript. /// /// This version of the ChaiScript constructor attempts to find the stdlib module to load @@ -308,6 +309,12 @@ namespace chaiscript throw; } } +#else // CHAISCRIPT_NO_DYNLOAD +explicit ChaiScript_Basic(std::unique_ptr &&parser, + std::vector t_module_paths = {}, + std::vector t_use_paths = {}, + const std::vector &t_opts = chaiscript::default_options()) = delete; +#endif parser::ChaiScript_Parser_Base &get_parser() { From 60c43233c68ba52dd4363d8bc92262e5a7c385b6 Mon Sep 17 00:00:00 2001 From: ftk Date: Sun, 5 Mar 2017 21:55:01 +0300 Subject: [PATCH 5/9] More clear error message in load_module --- include/chaiscript/language/chaiscript_engine.hpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/include/chaiscript/language/chaiscript_engine.hpp b/include/chaiscript/language/chaiscript_engine.hpp index b2df16b..3713177 100644 --- a/include/chaiscript/language/chaiscript_engine.hpp +++ b/include/chaiscript/language/chaiscript_engine.hpp @@ -556,6 +556,10 @@ explicit ChaiScript_Basic(std::unique_ptr &&pars /// \throw chaiscript::exception::load_module_error In the event that no matching module can be found. std::string load_module(const std::string &t_module_name) { +#ifdef CHAISCRIPT_NO_DYNLOAD + (void)t_module_name; // -Wunused-parameter + throw chaiscript::exception::load_module_error("Loadable module support was disabled (CHAISCRIPT_NO_DYNLOAD)"); +#else std::vector errors; std::string version_stripped_name = t_module_name; size_t version_pos = version_stripped_name.find("-" + Build_Info::version()); @@ -589,6 +593,7 @@ explicit ChaiScript_Basic(std::unique_ptr &&pars } throw chaiscript::exception::load_module_error(t_module_name, errors); +#endif } /// \brief Load a binary module from a dynamic library. Works on platforms that support From d22c27b62791584e6a5f910be98b223e7041414c Mon Sep 17 00:00:00 2001 From: ftk Date: Wed, 8 Mar 2017 12:31:30 +0300 Subject: [PATCH 6/9] Added option to disable dynload in cmakelists.txt --- CMakeLists.txt | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index fbba252..6409ea5 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -14,6 +14,7 @@ ELSE() project(chaiscript) option(MULTITHREAD_SUPPORT_ENABLED "Multithreaded Support Enabled" TRUE) +option(DYNLOAD_ENABLED "Dynamic Loading Support Enabled" TRUE) option(BUILD_MODULES "Build Extra Modules (stl)" TRUE) @@ -221,9 +222,15 @@ if(NOT MULTITHREAD_SUPPORT_ENABLED) add_definitions(-DCHAISCRIPT_NO_THREADS) endif() +if(NOT DYNLOAD_ENABLED) + add_definitions(-DCHAISCRIPT_NO_DYNLOAD) +endif() + if(CMAKE_HOST_UNIX) - if(NOT ${CMAKE_SYSTEM_NAME} MATCHES "FreeBSD" AND NOT ${CMAKE_SYSTEM_NAME} MATCHES "Haiku") - list(APPEND LIBS "dl") + if(DYNLOAD_ENABLED) + if(NOT ${CMAKE_SYSTEM_NAME} MATCHES "FreeBSD" AND NOT ${CMAKE_SYSTEM_NAME} MATCHES "Haiku") + list(APPEND LIBS "dl") + endif() endif() if(MULTITHREAD_SUPPORT_ENABLED) From 12100cce99e9807d553c2764abb58de55dcf1e95 Mon Sep 17 00:00:00 2001 From: ftk Date: Wed, 8 Mar 2017 12:37:04 +0300 Subject: [PATCH 7/9] Updated travis.yml --- .travis.yml | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/.travis.yml b/.travis.yml index c7a33cf..1d6e283 100644 --- a/.travis.yml +++ b/.travis.yml @@ -23,6 +23,10 @@ matrix: sudo: false env: GCC_VER="4.9" compiler: gcc + - os: linux + sudo: false + env: GCC_VER="4.9" CMAKE_OPTIONS="-D DYNLOAD_ENABLED:BOOL=FALSE -D MULTITHREAD_SUPPORT_ENABLED:BOOL=FALSE -D USE_STD_MAKE_SHARED:BOOL=TRUE" BUILD_ONLY=1 + compiler: gcc - os: linux sudo: false env: GCC_VER="5" @@ -30,7 +34,10 @@ matrix: - os: osx compiler: clang osx_image: xcode8 - + - os: osx + compiler: clang + osx_image: xcode8 + env: CMAKE_OPTIONS="-D DYNLOAD_ENABLED:BOOL=FALSE -D MULTITHREAD_SUPPORT_ENABLED:BOOL=FALSE -D USE_STD_MAKE_SHARED:BOOL=TRUE" BUILD_ONLY=1 env: global: @@ -40,14 +47,14 @@ env: before_install: - if [ "${GCC_VER}" != "" ]; then export CXX="g++-$GCC_VER" CC="gcc-$GCC_VER" GCOV="gcov-$GCC_VER" ; fi - - if [ "${GCC_VER}" == "5" ]; then export CPPCHECK=1 COVERAGE=1 FUZZY_CMD="-D RUN_FUZZY_TESTS:BOOL=TRUE" ; fi + - if [ "${GCC_VER}" == "5" && "${BUILD_ONLY}" != "1"]; then export CPPCHECK=1 COVERAGE=1 CMAKE_OPTIONS+=" -D RUN_FUZZY_TESTS:BOOL=TRUE" ; fi - pip install --user cpp-coveralls script: - - cmake -D ENABLE_COVERAGE:BOOL=TRUE -D CMAKE_BUILD_TYPE:STRING=Debug $FUZZY_CMD . + - cmake -D ENABLE_COVERAGE:BOOL=TRUE -D CMAKE_BUILD_TYPE:STRING=Debug $CMAKE_OPTIONS . - cmake --build . -- -j2 - - ctest - - if [ ${COVERAGE} = 1 ]; then bash <(curl -s https://raw.githubusercontent.com/codecov/codecov-bash/master/codecov) -x $GCOV -a "-s `pwd`" ; fi + - if [ "${BUILD_ONLY}" != "1" ]; then ctest; fi + - if [ "${COVERAGE}" = "1" ]; then bash <(curl -s https://raw.githubusercontent.com/codecov/codecov-bash/master/codecov) -x $GCOV -a "-s `pwd`" ; fi #after_script: # - if [ ${CPPCHECK} = 1 ]; then contrib/codeanalysis/runcppcheck.sh ; fi From f53a1ed9513615d15a676062dcd516ae8b5ba7f9 Mon Sep 17 00:00:00 2001 From: ftk Date: Wed, 8 Mar 2017 13:00:34 +0300 Subject: [PATCH 8/9] Fix compilation of multithreaded_test --- unittests/multithreaded_test.cpp | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/unittests/multithreaded_test.cpp b/unittests/multithreaded_test.cpp index ff06620..e2d0240 100644 --- a/unittests/multithreaded_test.cpp +++ b/unittests/multithreaded_test.cpp @@ -2,6 +2,9 @@ #include +#ifdef CHAISCRIPT_NO_DYNLOAD +#include +#endif #include #include @@ -57,18 +60,22 @@ int main() } std::vector modulepaths; + +#ifdef CHAISCRIPT_NO_DYNLOAD + chaiscript::ChaiScript chai(/* unused */modulepaths, usepaths); +#else modulepaths.push_back(""); if (modulepath) { modulepaths.push_back(modulepath); } - // For this test we are going to load the dynamic stdlib // to make sure it continues to work chaiscript::ChaiScript_Basic chai( std::make_unique>(), modulepaths,usepaths); +#endif std::vector > threads; From 12829ee5d24bbbd7a91910ee002819af0b02a0df Mon Sep 17 00:00:00 2001 From: ftk Date: Sat, 11 Mar 2017 15:42:24 +0300 Subject: [PATCH 9/9] Simplified travis.yml --- .travis.yml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index 1d6e283..01ab0ea 100644 --- a/.travis.yml +++ b/.travis.yml @@ -29,7 +29,7 @@ matrix: compiler: gcc - os: linux sudo: false - env: GCC_VER="5" + env: GCC_VER="5" CPPCHECK=1 COVERAGE=1 CMAKE_OPTIONS="-D RUN_FUZZY_TESTS:BOOL=TRUE" compiler: gcc - os: osx compiler: clang @@ -47,7 +47,6 @@ env: before_install: - if [ "${GCC_VER}" != "" ]; then export CXX="g++-$GCC_VER" CC="gcc-$GCC_VER" GCOV="gcov-$GCC_VER" ; fi - - if [ "${GCC_VER}" == "5" && "${BUILD_ONLY}" != "1"]; then export CPPCHECK=1 COVERAGE=1 CMAKE_OPTIONS+=" -D RUN_FUZZY_TESTS:BOOL=TRUE" ; fi - pip install --user cpp-coveralls script: