From 4be5e876b8a1cd406f96fb9d1ea484837f289583 Mon Sep 17 00:00:00 2001 From: Jason Turner Date: Wed, 15 Aug 2018 11:19:09 -0600 Subject: [PATCH 1/3] Add failing test for returning of & to * --- unittests/compiled_tests.cpp | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/unittests/compiled_tests.cpp b/unittests/compiled_tests.cpp index 8723d23d..614dcb73 100644 --- a/unittests/compiled_tests.cpp +++ b/unittests/compiled_tests.cpp @@ -204,6 +204,31 @@ TEST_CASE("Throw int or double") } } +TEST_CASE("Deduction of pointer return types") +{ + int val = 5; + int *val_ptr = &val; + auto &val_ptr_ref = val_ptr; + const auto &val_ptr_const_ref = val_ptr; + + auto get_val_ptr = [&]() -> int * { return val_ptr; }; + auto get_val_const_ptr = [&]() -> int const * { return val_ptr; }; + auto get_val_ptr_ref = [&]() -> int *& { return val_ptr_ref; }; + auto get_val_const_ptr_ref = [&]() -> int * const & { return val_ptr_const_ref; }; + + chaiscript::ChaiScript_Basic chai(create_chaiscript_stdlib(), create_chaiscript_parser()); + chai.add(chaiscript::fun(get_val_ptr), "get_val_ptr"); + chai.add(chaiscript::fun(get_val_const_ptr), "get_val_const_ptr"); + chai.add(chaiscript::fun(get_val_ptr_ref), "get_val_ptr_ref"); + chai.add(chaiscript::fun(get_val_const_ptr_ref), "get_val_const_ptr_ref"); + + CHECK(chai.eval("get_val_ptr()") == &val); + CHECK(chai.eval("get_val_const_ptr()") == &val); + CHECK(chai.eval("get_val_ptr_ref()") == &val); + CHECK(chai.eval("get_val_const_ptr_ref()") == &val); +} + + TEST_CASE("Throw a runtime_error") { chaiscript::ChaiScript_Basic chai(create_chaiscript_stdlib(),create_chaiscript_parser()); From 44dab4d45c1b9f7753b9480d622a4e3e3067c15d Mon Sep 17 00:00:00 2001 From: Jason Turner Date: Wed, 15 Aug 2018 13:10:23 -0600 Subject: [PATCH 2/3] Deal with returning of & to * types --- .../chaiscript/dispatchkit/handle_return.hpp | 26 +++++++++++++++---- unittests/compiled_tests.cpp | 20 ++++++++++---- 2 files changed, 36 insertions(+), 10 deletions(-) diff --git a/include/chaiscript/dispatchkit/handle_return.hpp b/include/chaiscript/dispatchkit/handle_return.hpp index 8570c8d0..5a98c9a9 100644 --- a/include/chaiscript/dispatchkit/handle_return.hpp +++ b/include/chaiscript/dispatchkit/handle_return.hpp @@ -167,17 +167,33 @@ namespace chaiscript } }; - - - template - struct Handle_Return + template + struct Handle_Return_Ref { - static Boxed_Value handle(const Ret &r) + template + static Boxed_Value handle(T &&r) { return Boxed_Value(std::cref(r), true); } }; + template + struct Handle_Return_Ref + { + template + static Boxed_Value handle(T &&r) + { + return Boxed_Value(typename std::remove_reference::type{r}, true); + } + }; + + template + struct Handle_Return : Handle_Return_Ref::type>::value> + { + + }; + + template struct Handle_Return { diff --git a/unittests/compiled_tests.cpp b/unittests/compiled_tests.cpp index 614dcb73..705d34b3 100644 --- a/unittests/compiled_tests.cpp +++ b/unittests/compiled_tests.cpp @@ -214,18 +214,28 @@ TEST_CASE("Deduction of pointer return types") auto get_val_ptr = [&]() -> int * { return val_ptr; }; auto get_val_const_ptr = [&]() -> int const * { return val_ptr; }; auto get_val_ptr_ref = [&]() -> int *& { return val_ptr_ref; }; - auto get_val_const_ptr_ref = [&]() -> int * const & { return val_ptr_const_ref; }; + auto get_val_ptr_const_ref = [&]() -> int * const & { return val_ptr_const_ref; }; +// auto get_val_const_ptr_const_ref = [ref=std::cref(val_ptr)]() -> int const * const & { return ref.get(); }; chaiscript::ChaiScript_Basic chai(create_chaiscript_stdlib(), create_chaiscript_parser()); chai.add(chaiscript::fun(get_val_ptr), "get_val_ptr"); chai.add(chaiscript::fun(get_val_const_ptr), "get_val_const_ptr"); chai.add(chaiscript::fun(get_val_ptr_ref), "get_val_ptr_ref"); - chai.add(chaiscript::fun(get_val_const_ptr_ref), "get_val_const_ptr_ref"); + chai.add(chaiscript::fun(get_val_ptr_const_ref), "get_val_ptr_const_ref"); +// chai.add(chaiscript::fun(get_val_const_ptr_const_ref), "get_val_const_ptr_const_ref"); CHECK(chai.eval("get_val_ptr()") == &val); - CHECK(chai.eval("get_val_const_ptr()") == &val); - CHECK(chai.eval("get_val_ptr_ref()") == &val); - CHECK(chai.eval("get_val_const_ptr_ref()") == &val); + CHECK(*chai.eval("get_val_ptr()") == val); + CHECK(chai.eval("get_val_const_ptr()") == &val); + CHECK(*chai.eval("get_val_const_ptr()") == val); + + // note that we cannot maintain the references here, + // chaiscript internals cannot handle that, effectively pointer to pointer + CHECK(chai.eval("get_val_ptr_ref()") == &val); + CHECK(*chai.eval("get_val_ptr_ref()") == val); + CHECK(chai.eval("get_val_ptr_const_ref()") == &val); + CHECK(*chai.eval("get_val_ptr_const_ref()") == val); +// CHECK(chai.eval("get_val_const_ptr_const_ref()") == &val); } From 3af55d60f23c6a3ef4e3becc16ade6364ca15f7d Mon Sep 17 00:00:00 2001 From: Jason Turner Date: Wed, 15 Aug 2018 13:12:36 -0600 Subject: [PATCH 3/3] Update version to 6.1.1 --- CMakeLists.txt | 2 +- include/chaiscript/chaiscript_defines.hpp | 2 +- releasenotes.md | 6 +++++- 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 1ab8f3b1..8a66d287 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -100,7 +100,7 @@ set(CPACK_PACKAGE_DESCRIPTION_FILE "${CMAKE_CURRENT_SOURCE_DIR}/description.txt" set(CPACK_PACKAGE_VERSION_MAJOR 6) set(CPACK_PACKAGE_VERSION_MINOR 1) -set(CPACK_PACKAGE_VERSION_PATCH 0) +set(CPACK_PACKAGE_VERSION_PATCH 1) set(CPACK_PACKAGE_EXECUTABLES "chai;ChaiScript Eval") set(CPACK_PACKAGE_VENDOR "ChaiScript.com") diff --git a/include/chaiscript/chaiscript_defines.hpp b/include/chaiscript/chaiscript_defines.hpp index 4508d603..bf9a13d7 100644 --- a/include/chaiscript/chaiscript_defines.hpp +++ b/include/chaiscript/chaiscript_defines.hpp @@ -77,7 +77,7 @@ static_assert(_MSC_FULL_VER >= 190024210, "Visual C++ 2015 Update 3 or later req namespace chaiscript { static const int version_major = 6; static const int version_minor = 1; - static const int version_patch = 0; + static const int version_patch = 1; static const char *compiler_version = CHAISCRIPT_COMPILER_VERSION; static const char *compiler_name = CHAISCRIPT_COMPILER_NAME; diff --git a/releasenotes.md b/releasenotes.md index c4ab63be..cdccd888 100644 --- a/releasenotes.md +++ b/releasenotes.md @@ -1,6 +1,10 @@ Notes: ======= -Current Version: 6.1.0 +Current Version: 6.1.1 + +### Changes since 6.1.0 + + * Handle the returning of `&` to `*` types. This specifically comes up with `std::vector` and similar containers ### Changes since 6.0.0