luabind (0.9+dfsg-3) 04_defer_longjmp.diff

Summary

 luabind/make_function.hpp |    7 ++++++-
 test/test_exceptions.cpp  |    8 +++++++-
 2 files changed, 13 insertions(+), 2 deletions(-)

    
download this patch

Patch contents

diff --git a/luabind/make_function.hpp b/luabind/make_function.hpp
index 0528c2d..145cbd1 100644
--- a/luabind/make_function.hpp
+++ b/luabind/make_function.hpp
@@ -56,6 +56,7 @@ namespace detail
           int results = 0;
 
 # ifndef LUABIND_NO_EXCEPTIONS
+          bool exception_caught = false;
           try
           {
               results = invoke(
@@ -63,9 +64,13 @@ namespace detail
           }
           catch (...)
           {
+              exception_caught = true;
               handle_exception_aux(L);
-              lua_error(L);
           }
+
+          if(exception_caught)
+              lua_error(L);
+
 # else
           results = invoke(L, *impl, ctx, impl->f, Signature(), impl->policies);
 # endif
diff --git a/test/test_exceptions.cpp b/test/test_exceptions.cpp
index 0696192..a5be57d 100644
--- a/test/test_exceptions.cpp
+++ b/test/test_exceptions.cpp
@@ -23,9 +23,10 @@
 #include "test.hpp"
 #include <luabind/luabind.hpp>
 
-struct ex : public std::exception
+struct ex : public std::exception, public counted_type<ex>
 {
     ex(const char* m): msg(m) {}
+    virtual ~ex() throw() {}
     virtual const char* what() const throw() { return msg; }
     const char* msg;
 };
@@ -49,6 +50,8 @@ void test_main(lua_State* L)
 
 #ifndef LUABIND_NO_EXCEPTIONS
 
+    const int start_count = ex::count;
+
     module(L)
     [
         class_<exception_thrower>("throw")
@@ -77,6 +80,9 @@ void test_main(lua_State* L)
         "void __init(luabind::argument const&,int)\n"
         "void __init(luabind::argument const&)");
 
+    const int end_count = ex::count;
+    TEST_CHECK( start_count == end_count );
+
 #endif
 }