From 87c29ebc91dc82ab6354549f0a953820b513f111 Mon Sep 17 00:00:00 2001 From: Jason Turner Date: Sat, 26 Mar 2011 09:03:36 -0600 Subject: [PATCH] Ensure that non-shared_ptr, non-boxed_value, non-reference return types are treated as const. --- include/chaiscript/chaiscript_threading.hpp | 1 + .../chaiscript/dispatchkit/handle_return.hpp | 23 ++++++++++++++++++- unittests/assign_const.chai | 2 ++ 3 files changed, 25 insertions(+), 1 deletion(-) create mode 100644 unittests/assign_const.chai diff --git a/include/chaiscript/chaiscript_threading.hpp b/include/chaiscript/chaiscript_threading.hpp index bfc7d6c..85cba1d 100644 --- a/include/chaiscript/chaiscript_threading.hpp +++ b/include/chaiscript/chaiscript_threading.hpp @@ -23,6 +23,7 @@ namespace chaiscript { + /// \internal namespace detail { namespace threading diff --git a/include/chaiscript/dispatchkit/handle_return.hpp b/include/chaiscript/dispatchkit/handle_return.hpp index ba2b381..a79e5b0 100644 --- a/include/chaiscript/dispatchkit/handle_return.hpp +++ b/include/chaiscript/dispatchkit/handle_return.hpp @@ -27,7 +27,7 @@ namespace chaiscript { static Boxed_Value handle(const Ret &r) { - return Boxed_Value(r); + return const_var(r); } }; @@ -40,6 +40,15 @@ namespace chaiscript } }; + template + struct Handle_Return > + { + static Boxed_Value handle(const boost::shared_ptr &r) + { + return Boxed_Value(r); + } + }; + template struct Handle_Return &> { @@ -88,6 +97,18 @@ namespace chaiscript } }; + /** + * Used internally for handling a return value from a Proxy_Function call + */ + template<> + struct Handle_Return + { + static Boxed_Value handle(const Boxed_Value &r) + { + return r; + } + }; + /** * Used internally for handling a return value from a Proxy_Function call */ diff --git a/unittests/assign_const.chai b/unittests/assign_const.chai new file mode 100644 index 0000000..ff6a8c3 --- /dev/null +++ b/unittests/assign_const.chai @@ -0,0 +1,2 @@ +assert_throws("Mismatched types in equation, lhs is const.", fun() { 1 = 2 } ); +assert_throws("Mismatched types in equation, lhs is const.", fun() { 1 + 2 = 2 } );