From 4b81a24a0a37da68bf1f55240e676e6ba5887a1f Mon Sep 17 00:00:00 2001 From: Jason Turner Date: Sat, 24 Sep 2016 17:15:17 -0600 Subject: [PATCH 1/2] Fix numeric mixed-convesion operations --- .../dispatchkit/proxy_functions.hpp | 5 ++--- include/chaiscript/dispatchkit/type_info.hpp | 10 ++++++++++ unittests/compiled_tests.cpp | 20 +++++++++++++++++++ 3 files changed, 32 insertions(+), 3 deletions(-) diff --git a/include/chaiscript/dispatchkit/proxy_functions.hpp b/include/chaiscript/dispatchkit/proxy_functions.hpp index 6128b33b..a5c25261 100644 --- a/include/chaiscript/dispatchkit/proxy_functions.hpp +++ b/include/chaiscript/dispatchkit/proxy_functions.hpp @@ -846,7 +846,8 @@ namespace chaiscript plist.begin(), std::back_inserter(newplist), [](const Type_Info &ti, const Boxed_Value ¶m) -> Boxed_Value { - if (ti.is_arithmetic() && param.get_type_info().is_arithmetic()) { + if (ti.is_arithmetic() && param.get_type_info().is_arithmetic() + && param.get_type_info() != ti) { return Boxed_Number(param).get_as(ti).bv; } else { return param; @@ -854,8 +855,6 @@ namespace chaiscript } ); - - try { return (*(matching_func->second))(newplist, t_conversions); } catch (const exception::bad_boxed_cast &) { diff --git a/include/chaiscript/dispatchkit/type_info.hpp b/include/chaiscript/dispatchkit/type_info.hpp index c43767a3..eac984d4 100644 --- a/include/chaiscript/dispatchkit/type_info.hpp +++ b/include/chaiscript/dispatchkit/type_info.hpp @@ -60,6 +60,16 @@ namespace chaiscript return m_type_info < ti.m_type_info; } + CHAISCRIPT_CONSTEXPR bool operator!=(const Type_Info &ti) const CHAISCRIPT_NOEXCEPT + { + return !(operator==(ti)); + } + + CHAISCRIPT_CONSTEXPR bool operator!=(const std::type_info &ti) const CHAISCRIPT_NOEXCEPT + { + return !(operator==(ti)); + } + CHAISCRIPT_CONSTEXPR bool operator==(const Type_Info &ti) const CHAISCRIPT_NOEXCEPT { return ti.m_type_info == m_type_info diff --git a/unittests/compiled_tests.cpp b/unittests/compiled_tests.cpp index edc62e2d..71fc59cb 100644 --- a/unittests/compiled_tests.cpp +++ b/unittests/compiled_tests.cpp @@ -950,4 +950,24 @@ TEST_CASE("Parse floats with non-posix locale") +bool FindBitmap(int &ox, int &oy, long) { + ox = 1; + oy = 2; + return true; +} + +TEST_CASE("Mismatched numeric types only convert necessary params") +{ + chaiscript::ChaiScript chai; + + chai.add(chaiscript::fun(&FindBitmap), "FindBitmap"); + int x = 0; + int y = 0; + chai.add(chaiscript::var(&x), "x"); + chai.add(chaiscript::var(&y), "y"); + chai.eval( "if ( FindBitmap ( x, y, 0) ) { print(\"found at \" + to_string(x) + \", \" + to_string(y))}" ); + CHECK(x == 1); + CHECK(y == 2); + +} From bec1b91b7beacbcaf672d77bfbe10ed57f02bdc0 Mon Sep 17 00:00:00 2001 From: Jason Turner Date: Sat, 24 Sep 2016 17:17:40 -0600 Subject: [PATCH 2/2] Increment to 5.8.4 --- CMakeLists.txt | 2 +- include/chaiscript/chaiscript_defines.hpp | 2 +- releasenotes.md | 5 ++++- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index e3fde8cd..ccab0041 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -103,7 +103,7 @@ set(CPACK_PACKAGE_DESCRIPTION_FILE "${CMAKE_CURRENT_SOURCE_DIR}/description.txt" set(CPACK_PACKAGE_VERSION_MAJOR 5) set(CPACK_PACKAGE_VERSION_MINOR 8) -set(CPACK_PACKAGE_VERSION_PATCH 2) +set(CPACK_PACKAGE_VERSION_PATCH 4) 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 9184f50e..ea8b1db9 100644 --- a/include/chaiscript/chaiscript_defines.hpp +++ b/include/chaiscript/chaiscript_defines.hpp @@ -99,7 +99,7 @@ namespace chaiscript { static const int version_major = 5; static const int version_minor = 8; - static const int version_patch = 2; + static const int version_patch = 4; 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 2ff69476..d2698ae8 100644 --- a/releasenotes.md +++ b/releasenotes.md @@ -1,6 +1,9 @@ Notes: ======= -Current Version: 5.8.3 +Current Version: 5.8.4 + +### Changes since 5.8.3 +* Fix case with some numeric conversions mixed with numerics that do not need conversion ### Changes since 5.8.2 * Add support for reference of pointer return types