zorba-coders team mailing list archive
-
zorba-coders team
-
Mailing list archive
-
Message #10321
[Merge] lp:~zorba-coders/zorba/bug-1006166 into lp:zorba
Markos Zaharioudakis has proposed merging lp:~zorba-coders/zorba/bug-1006166 into lp:zorba.
Requested reviews:
Markos Zaharioudakis (markos-za)
For more details, see:
https://code.launchpad.net/~zorba-coders/zorba/bug-1006166/+merge/107988
fixed bug #1006166
--
https://code.launchpad.net/~zorba-coders/zorba/bug-1006166/+merge/107988
Your team Zorba Coders is subscribed to branch lp:zorba.
=== modified file 'ChangeLog'
--- ChangeLog 2012-05-30 00:37:00 +0000
+++ ChangeLog 2012-05-30 15:00:25 +0000
@@ -1,5 +1,9 @@
Zorba - The XQuery Processor
+version 2.x
+
+ * Fixed bug #1006166 (disabling 2 functions with the same qname)
+
version 2.5
New Features:
=== modified file 'src/compiler/translator/translator.cpp'
--- src/compiler/translator/translator.cpp 2012-05-09 23:06:41 +0000
+++ src/compiler/translator/translator.cpp 2012-05-30 15:00:25 +0000
@@ -3280,7 +3280,7 @@
if (func_decl->is_external())
{
// 1. lookup if the function is a built-in function
- f = theSctx->lookup_fn(qnameItem, numParams);
+ f = theSctx->lookup_fn(qnameItem, numParams, false);
if (f.getp() != 0)
{
@@ -3409,7 +3409,9 @@
// Get function obj out of function qname (will raise error if prefix in qname
// is not bound to a namespace).
- function* f = lookup_fn(v.get_name(), v.get_param_count(), loc);
+ store::Item_t qnameItem;
+ expand_function_qname(qnameItem, v.get_name(), v.get_name()->get_location());
+ function* f = theSctx->lookup_fn(qnameItem, v.get_param_count(), false);
assert(f);
=== modified file 'src/context/static_context.cpp'
--- src/context/static_context.cpp 2012-05-18 22:01:56 +0000
+++ src/context/static_context.cpp 2012-05-30 15:00:25 +0000
@@ -2408,8 +2408,8 @@
if (theFunctionArityMap->get(qname2, fv))
{
- ulong numFunctions = (ulong)fv->size();
- for (ulong i = 0; i < numFunctions; ++i)
+ csize numFunctions = fv->size();
+ for (csize i = 0; i < numFunctions; ++i)
{
if ((*fv)[i].theFunction.getp() == f)
{
@@ -2421,6 +2421,7 @@
fv = new std::vector<FunctionInfo>(1);
fi.theIsDisabled = true;
+ fi.theFunction = f;
(*fv)[0] = fi;
theFunctionArityMap->insert(qname2, fv);
}
@@ -2440,7 +2441,8 @@
********************************************************************************/
function* static_context::lookup_fn(
const store::Item* qname,
- ulong arity)
+ ulong arity,
+ bool skipDisabled)
{
FunctionInfo fi;
store::Item* qname2 = const_cast<store::Item*>(qname);
@@ -2455,7 +2457,10 @@
if (f->getArity() == arity || f->isVariadic())
{
- return (fi.theIsDisabled ? NULL : f);
+ if (fi.theIsDisabled && skipDisabled)
+ return NULL;
+
+ return f;
}
std::vector<FunctionInfo>* fv = NULL;
@@ -2463,11 +2468,16 @@
if (sctx->theFunctionArityMap != NULL &&
sctx->theFunctionArityMap->get(qname2, fv))
{
- ulong numFunctions = (ulong)fv->size();
- for (ulong i = 0; i < numFunctions; ++i)
+ csize numFunctions = fv->size();
+ for (csize i = 0; i < numFunctions; ++i)
{
if ((*fv)[i].theFunction->getArity() == arity)
- return ((*fv)[i].theIsDisabled ? NULL : (*fv)[i].theFunction.getp());
+ {
+ if ((*fv)[i].theIsDisabled && skipDisabled)
+ return NULL;
+
+ return (*fv)[i].theFunction.getp();
+ }
}
}
}
@@ -2486,7 +2496,8 @@
********************************************************************************/
function* static_context::lookup_local_fn(
const store::Item* qname,
- ulong arity)
+ ulong arity,
+ bool skipDisabled)
{
FunctionInfo fi;
store::Item* qname2 = const_cast<store::Item*>(qname);
@@ -2497,18 +2508,26 @@
if (f->getArity() == arity || f->isVariadic())
{
- return (fi.theIsDisabled ? NULL : f);
+ if (fi.theIsDisabled && skipDisabled)
+ return NULL;
+
+ return f;
}
std::vector<FunctionInfo>* fv = NULL;
if (theFunctionArityMap != NULL && theFunctionArityMap->get(qname2, fv))
{
- ulong numFunctions = (ulong)fv->size();
- for (ulong i = 0; i < numFunctions; ++i)
+ csize numFunctions = fv->size();
+ for (csize i = 0; i < numFunctions; ++i)
{
if ((*fv)[i].theFunction->getArity() == arity)
- return ((*fv)[i].theIsDisabled ? NULL : (*fv)[i].theFunction.getp());
+ {
+ if ((*fv)[i].theIsDisabled && skipDisabled)
+ return NULL;
+
+ return (*fv)[i].theFunction.getp();
+ }
}
}
}
=== modified file 'src/context/static_context.h'
--- src/context/static_context.h 2012-05-07 17:42:55 +0000
+++ src/context/static_context.h 2012-05-30 15:00:25 +0000
@@ -826,9 +826,15 @@
void unbind_fn(const store::Item* qname, ulong arity);
- function* lookup_fn(const store::Item* qname, ulong arity);
+ function* lookup_fn(
+ const store::Item* qname,
+ ulong arity,
+ bool skipDisabled = true);
- function* lookup_local_fn(const store::Item* qname, ulong arity);
+ function* lookup_local_fn(
+ const store::Item* qname,
+ ulong arity,
+ bool skipDisabled = true);
void get_functions(std::vector<function*>& functions) const;
=== modified file 'test/unit/static_context.cpp'
--- test/unit/static_context.cpp 2012-05-18 02:52:21 +0000
+++ test/unit/static_context.cpp 2012-05-30 15:00:25 +0000
@@ -23,6 +23,7 @@
#include <zorba/store_manager.h>
#include <zorba/zorba.h>
#include <zorba/zorba_exception.h>
+#include <zorba/diagnostic_list.h>
using namespace std;
using namespace zorba;
@@ -139,10 +140,170 @@
}
+bool
+sctx_test_5(Zorba* zorba)
+{
+ std::stringstream queryString1;
+ std::stringstream queryString2;
+
+ queryString1
+ << "import module namespace ddl = "
+ << "\"http://www.zorba-xquery.com/modules/store/dynamic/collections/ddl\";";
+ << std::endl
+ << "ddl:create(xs:QName(\"ddl:coll1\"));"
+ << std::endl;
+
+ queryString2
+ << "import module namespace ddl = "
+ << "\"http://www.zorba-xquery.com/modules/store/dynamic/collections/ddl\";";
+ << std::endl
+ << "ddl:create(xs:QName(\"ddl:coll1\"), <a/>);"
+ << std::endl;
+
+ ItemFactory* factory = zorba->getItemFactory();
+
+ Item fname = factory->
+ createQName("http://www.zorba-xquery.com/modules/store/dynamic/collections/ddl";,
+ "create");
+
+ try
+ {
+ StaticContext_t sctx = zorba->createStaticContext();
+ sctx->disableFunction(fname, 1);
+ sctx->disableFunction(fname, 2);
+
+ XQuery_t query = zorba->compileQuery(queryString1, sctx);
+ }
+ catch (ZorbaException& e)
+ {
+ std::cerr << e << std::endl;
+
+ if (e.diagnostic() != err::XPST0017)
+ return false;
+ }
+ catch (...)
+ {
+ return false;
+ }
+
+ try
+ {
+ StaticContext_t sctx = zorba->createStaticContext();
+ sctx->disableFunction(fname, 1);
+ sctx->disableFunction(fname, 2);
+
+ queryString2.seekg(0, std::ios::beg);
+
+ XQuery_t query = zorba->compileQuery(queryString2, sctx);
+ }
+ catch (ZorbaException& e)
+ {
+ std::cerr << e << std::endl;
+
+ if (e.diagnostic() != err::XPST0017)
+ return false;
+ }
+ catch (...)
+ {
+ return false;
+ }
+
+ try
+ {
+ StaticContext_t sctx = zorba->createStaticContext();
+ sctx->disableFunction(fname, 1);
+
+ queryString1.clear();
+ queryString1.seekg(0, std::ios::beg);
+
+ XQuery_t query = zorba->compileQuery(queryString1, sctx);
+ }
+ catch (ZorbaException& e)
+ {
+ std::cerr << e << std::endl;
+
+ if (e.diagnostic() != err::XPST0017)
+ return false;
+ }
+ catch (...)
+ {
+ return false;
+ }
+
+ try
+ {
+ StaticContext_t sctx = zorba->createStaticContext();
+ sctx->disableFunction(fname, 1);
+
+ queryString2.clear();
+ queryString2.seekg(0, std::ios::beg);
+
+ XQuery_t query = zorba->compileQuery(queryString2, sctx);
+ }
+ catch (ZorbaException& e)
+ {
+ std::cerr << e << std::endl;
+
+ return false;
+ }
+ catch (...)
+ {
+ return false;
+ }
+
+
+ try
+ {
+ StaticContext_t sctx = zorba->createStaticContext();
+ sctx->disableFunction(fname, 2);
+
+ queryString1.clear();
+ queryString1.seekg(0, std::ios::beg);
+
+ XQuery_t query = zorba->compileQuery(queryString1, sctx);
+ }
+ catch (ZorbaException& e)
+ {
+ std::cerr << e << std::endl;
+
+ return false;
+ }
+ catch (...)
+ {
+ return false;
+ }
+
+ try
+ {
+ StaticContext_t sctx = zorba->createStaticContext();
+ sctx->disableFunction(fname, 2);
+
+ queryString2.clear();
+ queryString2.seekg(0, std::ios::beg);
+
+ XQuery_t query = zorba->compileQuery(queryString2, sctx);
+ }
+ catch (ZorbaException& e)
+ {
+ std::cerr << e << std::endl;
+
+ if (e.diagnostic() != err::XPST0017)
+ return false;
+ }
+ catch (...)
+ {
+ return false;
+ }
+
+ return true;
+}
+
+
+
int static_context( int argc, char *argv[] )
{
- void* const zstore = StoreManager::getStore();
- Zorba* const zorba = Zorba::getInstance( zstore );
+ void* zstore = StoreManager::getStore();
+ Zorba* zorba = Zorba::getInstance(zstore);
if (!sctx_test_1(zorba))
return 1;
@@ -156,6 +317,9 @@
if (!sctx_test_4(zorba))
return 4;
+ if (!sctx_test_5(zorba))
+ return 5;
+
zorba->shutdown();
StoreManager::shutdownStore( zstore );
return 0;
Follow ups