← Back to team overview

zorba-coders team mailing list archive

[Merge] lp:~zorba-coders/zorba/fix-external_func_exceptions into lp:zorba

 

Matthias Brantner has proposed merging lp:~zorba-coders/zorba/fix-external_func_exceptions into lp:zorba.

Commit message:
allow arbitrary exceptions raised by external functions to be caught by try-catch

Requested reviews:
  Matthias Brantner (matthias-brantner)
  Federico Cavalieri (fcavalieri)

For more details, see:
https://code.launchpad.net/~zorba-coders/zorba/fix-external_func_exceptions/+merge/200922
-- 
https://code.launchpad.net/~zorba-coders/zorba/fix-external_func_exceptions/+merge/200922
Your team Zorba Coders is subscribed to branch lp:zorba.
=== modified file 'src/runtime/core/fncall_iterator.cpp'
--- src/runtime/core/fncall_iterator.cpp	2013-09-26 09:38:51 +0000
+++ src/runtime/core/fncall_iterator.cpp	2014-01-08 22:01:01 +0000
@@ -908,9 +908,17 @@
   }
   catch (XQueryException& e)
   {
-		set_source( e, loc );
-		throw;
-  }
+    set_source( e, loc );
+    throw;
+  }
+  catch (std::exception& e)
+  {
+    throw XQUERY_EXCEPTION(
+      zerr::ZXQP0001_DYNAMIC_RUNTIME_ERROR,
+      ERROR_PARAMS(e.what()),
+      ERROR_LOC(loc));
+  }
+  
 
   if(state->theResult.get() != NULL)
   {

=== modified file 'test/unit/CMakeLists.txt'
--- test/unit/CMakeLists.txt	2013-05-31 23:44:41 +0000
+++ test/unit/CMakeLists.txt	2014-01-08 22:01:01 +0000
@@ -34,6 +34,7 @@
 CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/ext_main.xq ${CMAKE_CURRENT_BINARY_DIR}/ext_main.xq)
 CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/ext_main2.xq ${CMAKE_CURRENT_BINARY_DIR}/ext_main2.xq)
 CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/ext_main3.xq ${CMAKE_CURRENT_BINARY_DIR}/ext_main3.xq)
+CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/ext_main4.xq ${CMAKE_CURRENT_BINARY_DIR}/ext_main4.xq)
 
 #belongs to test no_folding.cpp
 CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/fold_mod1.xq ${CMAKE_CURRENT_BINARY_DIR}/fold_mod1.xq)

=== added file 'test/unit/ext_main4.xq'
--- test/unit/ext_main4.xq	1970-01-01 00:00:00 +0000
+++ test/unit/ext_main4.xq	2014-01-08 22:01:01 +0000
@@ -0,0 +1,22 @@
+(:
+ : Copyright 2006-2009 The FLWOR Foundation.
+ :
+ : Licensed under the Apache License, Version 2.0 (the "License");
+ : you may not use this file except in compliance with the License.
+ : You may obtain a copy of the License at
+ :
+ : http://www.apache.org/licenses/LICENSE-2.0
+ :
+ : Unless required by applicable law or agreed to in writing, software
+ : distributed under the License is distributed on an "AS IS" BASIS,
+ : WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ : See the License for the specific language governing permissions and
+ : limitations under the License.
+:)
+
+
+import module namespace ext = "http://www.zorba-xquery.com/m"; at "file:///${CMAKE_CURRENT_BINARY_DIR}/ext_mod2.xq";
+
+
+ext:bar5()
+

=== modified file 'test/unit/ext_mod2.xq'
--- test/unit/ext_mod2.xq	2013-02-07 17:24:36 +0000
+++ test/unit/ext_mod2.xq	2014-01-08 22:01:01 +0000
@@ -17,3 +17,5 @@
 module namespace ext = "http://www.zorba-xquery.com/m";;
 
 declare function ext:bar4($s as item()*) as item()* external;
+
+declare function ext:bar5() external;

=== modified file 'test/unit/external_function.cpp'
--- test/unit/external_function.cpp	2013-05-28 00:58:27 +0000
+++ test/unit/external_function.cpp	2014-01-08 22:01:01 +0000
@@ -138,6 +138,19 @@
   }
 };
 
+class MySimpleExternalFunction5 : public NonContextualExternalFunction
+{
+public:
+  String getURI() const { return "http://www.zorba-xquery.com/m";; }
+
+  String getLocalName() const { return "bar5"; }
+
+  ItemSequence_t evaluate(const ExternalFunction::Arguments_t& args) const
+  {
+    throw std::exception();
+  }
+};
+
 class MyExternalModule : public ExternalModule
 {
 protected:
@@ -145,6 +158,7 @@
   MySimpleExternalFunction2          bar2;
   MySimpleExternalFunction3          bar3;
   MySimpleExternalFunction4          bar4;
+  MySimpleExternalFunction5          bar5;
 
 public:
   String getURI() const { return "http://www.zorba-xquery.com/m";; }
@@ -157,6 +171,8 @@
         return const_cast<MySimpleExternalFunction3*>(&bar3);
     else if (aLocalname == "bar4")
         return const_cast<MySimpleExternalFunction4*>(&bar4);
+    else if (aLocalname == "bar5")
+        return const_cast<MySimpleExternalFunction5*>(&bar5);
     else
         return const_cast<MySimpleExternalFunction2*>(&bar2);
   }
@@ -378,6 +394,42 @@
   return true;
 }
 
+bool
+external_function_test_5(Zorba* aZorba)
+{
+  try 
+  {
+    std::ifstream lIn("ext_main4.xq");
+    assert(lIn.good());
+    std::ostringstream lOut;
+    MyExternalModule lMod;
+
+    StaticContext_t lSctx = aZorba->createStaticContext();
+    lSctx->registerModule(&lMod);
+
+    {
+      XQuery_t lQuery = aZorba->compileQuery(lIn, lSctx);
+
+      std::cout << lQuery << std::endl;
+    }
+  } 
+  catch (XQueryException& qe) 
+  {
+    if (std::string("ZXQP0001") == qe.diagnostic().qname().localname())
+    {
+      std::cerr << qe << std::endl;
+      return true;
+    } else {
+      std::cerr << qe << std::endl;
+      return false;
+    }
+  }
+  catch (...)
+  {
+    return false;
+  }
+  return false;
+}
 
 int
 external_function(int argc, char* argv[]) 
@@ -409,6 +461,12 @@
     return 4;
   }
 
+  std::cout << "executing external_function_test_5" << std::endl;
+  if (!external_function_test_5(lZorba))
+  {
+    return 4;
+  }
+
 
   lZorba->shutdown();
   zorba::StoreManager::shutdownStore(lStore);