Merge lp:~zorba-coders/zorba/threads into lp:zorba

Proposed by Markos Zaharioudakis
Status: Merged
Merged at revision: 11549
Proposed branch: lp:~zorba-coders/zorba/threads
Merge into: lp:zorba
Diff against target: 4779 lines (+1074/-880)
76 files modified
include/zorba/xquery.h (+17/-19)
src/annotations/annotations.cpp (+10/-4)
src/annotations/annotations.h (+6/-11)
src/api/annotationimpl.cpp (+10/-5)
src/api/annotationimpl.h (+1/-2)
src/api/serialization/serializer.cpp (+15/-3)
src/api/staticcontextimpl.cpp (+11/-17)
src/api/xmldatamanagerimpl.cpp (+5/-4)
src/api/xqueryimpl.cpp (+1/-0)
src/api/xqueryimpl.h (+2/-8)
src/api/zorbaimpl.cpp (+6/-0)
src/api/zorbaimpl.h (+5/-3)
src/capi/csequence.cpp (+3/-1)
src/common/shared_types.h (+1/-3)
src/compiler/codegen/plan_visitor.cpp (+1/-1)
src/compiler/expression/expr_put.cpp (+1/-1)
src/compiler/expression/fo_expr.cpp (+1/-1)
src/compiler/expression/function_item_expr.cpp (+18/-16)
src/compiler/expression/function_item_expr.h (+1/-1)
src/compiler/parsetree/parsenode_print_xqdoc_visitor.cpp (+5/-3)
src/compiler/rewriter/rules/type_rules.cpp (+1/-1)
src/compiler/translator/translator.cpp (+89/-88)
src/compiler/xqddf/collection_decl.cpp (+5/-4)
src/compiler/xqddf/collection_decl.h (+6/-6)
src/context/root_static_context.cpp (+7/-2)
src/context/root_static_context.h (+2/-0)
src/context/static_context.cpp (+46/-47)
src/context/static_context.h (+14/-8)
src/functions/external_function.cpp (+1/-2)
src/functions/function.cpp (+35/-31)
src/functions/function.h (+7/-9)
src/functions/function_impl.h (+4/-4)
src/functions/library.cpp (+13/-10)
src/functions/library.h (+13/-7)
src/functions/udf.cpp (+1/-3)
src/runtime/full_text/ft_util.cpp (+5/-2)
src/runtime/hof/fn_hof_functions_impl.cpp (+1/-1)
src/runtime/hof/function_item.cpp (+11/-10)
src/runtime/hof/function_item.h (+1/-1)
src/runtime/nodes/nodes_impl.cpp (+1/-1)
src/runtime/strings/strings_impl.cpp (+3/-3)
src/store/api/annotation.h (+1/-8)
src/store/api/collection.h (+1/-9)
src/store/api/ic.h (+1/-9)
src/store/api/index.h (+1/-9)
src/store/api/item.h (+1/-1)
src/store/naive/atomic_items.cpp (+7/-2)
src/store/naive/atomic_items.h (+6/-0)
src/store/naive/item.cpp (+11/-0)
src/store/naive/loader_dtd.cpp (+10/-6)
src/store/naive/loader_fast.cpp (+8/-5)
src/store/naive/node_items.cpp (+5/-3)
src/store/naive/nsbindings.cpp (+1/-0)
src/store/naive/qname_pool.cpp (+110/-47)
src/store/naive/qname_pool.h (+16/-8)
src/store/naive/simple_item_factory.cpp (+2/-2)
src/store/naive/simple_pul.cpp (+7/-8)
src/store/naive/store.cpp (+63/-63)
src/store/naive/store_defs.h (+1/-0)
src/system/globalenv.cpp (+7/-7)
src/system/globalenv.h (+16/-4)
src/types/root_typemanager.cpp (+2/-2)
src/types/schema/revalidateUtils.cpp (+12/-6)
src/types/schema/schema.cpp (+1/-1)
src/types/typeimpl.cpp (+3/-0)
src/types/typemanagerimpl.cpp (+4/-2)
src/util/http_util.cpp (+19/-6)
src/zorbamisc/ns_consts.h (+0/-3)
src/zorbaserialization/archiver_consts.h (+2/-1)
src/zorbaserialization/serialize_zorba_types.cpp (+1/-1)
src/zorbatypes/rchandle.cpp (+11/-67)
src/zorbatypes/rchandle.h (+75/-47)
test/driver/testdriver_common.cpp (+29/-16)
test/driver/testdriver_common.h (+3/-2)
test/driver/testdriver_mt.cpp (+250/-191)
test/rbkt/Queries/zorba/updates/forms.xsd (+1/-1)
To merge this branch: bzr merge lp:~zorba-coders/zorba/threads
Reviewer Review Type Date Requested Status
Markos Zaharioudakis Approve
Review via email: mp+174198@code.launchpad.net

Commit message

Some work towards multi-threading
1. Fixed a couple of threading bugs in qname pool
2. Redefined free() method for root_static_context and for builtin functions
3. Annotations are not RCObjects anymore
4. Use atomic ints are counters in RCObjects
5. No query cloning in testdriver_mt

Description of the change

Some work towards multi-threading
1. Fixed a couple of threading bugs in qname pool
2. Redefined free() method for root_static_context and for builtin functions
3. Annotations are not RCObjects anymore
4. Use atomic ints are counters in RCObjects
5. No query cloning in testdriver_mt

To post a comment you must log in.
Revision history for this message
Markos Zaharioudakis (markos-za) :
review: Approve
Revision history for this message
Zorba Build Bot (zorba-buildbot) wrote :

Validation queue starting for the following merge proposals:
https://code.launchpad.net/~zorba-coders/zorba/threads/+merge/174198

Progress dashboard at http://jenkins.lambda.nu/view/ValidationQueue

Revision history for this message
Zorba Build Bot (zorba-buildbot) wrote :

Validation queue succeeded - proposal merged!

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'include/zorba/xquery.h'
--- include/zorba/xquery.h 2013-05-28 00:58:27 +0000
+++ include/zorba/xquery.h 2013-07-11 13:41:52 +0000
@@ -29,16 +29,14 @@
29typedef Zorba_SerializerOptions_t* (*itemHandler)(void* aUserData);29typedef Zorba_SerializerOptions_t* (*itemHandler)(void* aUserData);
3030
31/** 31/**
32 * \brief This class is the representation of an %XQuery in the %Zorba engine.32 * \brief This class is the representation of an %XQuery program in the %Zorba engine.
33 *33 *
34 * To compile and execute an XQuery, an instance of this class must be created. 34 * To compile and execute an XQuery program, an instance of this class must be
35 * This is done by using either the createQuery or compileQuery methods of the35 * created. This is done by using either the createQuery or compileQuery methods
36 * Zorba class. These methods return an instance of XQuery_t, which is a 36 * of the Zorba class. These methods return an instance of XQuery_t, which is a
37 * reference counted smart pointer to a dynamically allocated XQuery object.37 * reference counted smart pointer to a dynamically allocated XQuery object.
38 * After receiving an XQuery_t, an application can make multiple copies of it.38 * The XQuery object is deleted when all XQuery_t objects that point to it are
39 * Hence, an XQuery object can have multiple users, potentially in different39 * destroyed.
40 * threads. The XQuery object is deleted when all XQuery_t objects that point
41 * to it are destroyed.
42 *40 *
43 * The file \link simple.cpp \endlink contains some basic examples the demonstrate41 * The file \link simple.cpp \endlink contains some basic examples the demonstrate
44 * the use of this class.42 * the use of this class.
@@ -51,7 +49,7 @@
51{49{
52 public:50 public:
53 /** 51 /**
54 * \brief Destructor that destroys this XQuery object. 52 * \brief Destructor.
55 * 53 *
56 * The destructor is called automatically when there are no more XQuery_t54 * The destructor is called automatically when there are no more XQuery_t
57 * smart pointers pointing to this XQuery instance.55 * smart pointers pointing to this XQuery instance.
@@ -61,11 +59,13 @@
61 /** 59 /**
62 * \brief Set the filename of a query.60 * \brief Set the filename of a query.
63 *61 *
64 * This (after URI-encoding) becomes the encapsulating entity's62 * This (after URI-encoding) becomes the encapsulating entity's retrieval URI
65 * retrieval URI (in RFC 3986 terms).63 * (in RFC 3986 terms), and may be used in the computation of the program's
64 * static base URI property, as described at
65 * http://www.w3.org/TR/xquery-30/#dt-base-uri-decl
66 */66 */
67 virtual void67 virtual void
68 setFileName(const String&) = 0;68 setFileName(const String& flename) = 0;
69 69
70 /** 70 /**
71 * \brief Register an DiagnosticHandler to which errors during compilation or71 * \brief Register an DiagnosticHandler to which errors during compilation or
@@ -74,14 +74,14 @@
74 * If no DiagnosticHandler has been set via this function, the default error74 * If no DiagnosticHandler has been set via this function, the default error
75 * handling mechanism is to throw instances of the ZorbaException class.75 * handling mechanism is to throw instances of the ZorbaException class.
76 *76 *
77 * @param aDiagnosticHandler DiagnosticHandler to which errors are reported. The77 * @param handler DiagnosticHandler to which errors are reported. The
78 * caller retains ownership over the DiagnosticHandler passed as78 * caller retains ownership over the DiagnosticHandler passed as
79 * parameter.79 * parameter.
80 * @throw SystemException if the query has been closed.80 * @throw SystemException if the query has been closed.
81 * @see close()81 * @see close()
82 */82 */
83 virtual void83 virtual void
84 registerDiagnosticHandler(DiagnosticHandler* aDiagnosticHandler) = 0;84 registerDiagnosticHandler(DiagnosticHandler* handler) = 0;
85 85
86 /** 86 /**
87 * \brief Reset the error handling mechanism back to the default,87 * \brief Reset the error handling mechanism back to the default,
@@ -443,7 +443,7 @@
443 * This file will contain the output of Zorba profiler.443 * This file will contain the output of Zorba profiler.
444 */444 */
445 virtual void445 virtual void
446 setProfileName( std::string aProfileName ) = 0;446 setProfileName(std::string aProfileName) = 0;
447 447
448 /**448 /**
449 * \brief Get the filename of the profile449 * \brief Get the filename of the profile
@@ -468,9 +468,7 @@
468 * not been compiled, the server cannot connect to the client, etc.)468 * not been compiled, the server cannot connect to the client, etc.)
469 */469 */
470 virtual void470 virtual void
471 debug(471 debug(const std::string& host, unsigned short port) = 0;
472 const std::string& host,
473 unsigned short port) = 0;
474472
475 /**473 /**
476 * \brief Start a debugger server.474 * \brief Start a debugger server.
@@ -556,7 +554,7 @@
556};554};
557 555
558556
559// xml serialization of the query (equiv to calling serialize(os) 557// XML serialization of the query result (equiv to calling serialize(os)
560ZORBA_DLL_PUBLIC558ZORBA_DLL_PUBLIC
561std::ostream& operator<< (std::ostream& os, const XQuery_t& aQuery); 559std::ostream& operator<< (std::ostream& os, const XQuery_t& aQuery);
562560
563561
=== modified file 'src/annotations/annotations.cpp'
--- src/annotations/annotations.cpp 2013-04-29 01:51:11 +0000
+++ src/annotations/annotations.cpp 2013-07-11 13:41:52 +0000
@@ -325,6 +325,12 @@
325********************************************************************************/325********************************************************************************/
326AnnotationList::~AnnotationList()326AnnotationList::~AnnotationList()
327{327{
328 for (Annotations::iterator ite = theAnnotationList.begin();
329 ite != theAnnotationList.end();
330 ++ite)
331 {
332 delete *ite;
333 }
328}334}
329335
330336
@@ -343,7 +349,7 @@
343AnnotationInternal* AnnotationList::get(csize index) const349AnnotationInternal* AnnotationList::get(csize index) const
344{350{
345 if (index < theAnnotationList.size())351 if (index < theAnnotationList.size())
346 return theAnnotationList[index].getp();352 return theAnnotationList[index];
347 else353 else
348 return NULL;354 return NULL;
349}355}
@@ -354,12 +360,12 @@
354********************************************************************************/360********************************************************************************/
355AnnotationInternal* AnnotationList::get(AnnotationInternal::AnnotationId id) const361AnnotationInternal* AnnotationList::get(AnnotationInternal::AnnotationId id) const
356{362{
357 for (ListConstIter_t ite = theAnnotationList.begin();363 for (Annotations::const_iterator ite = theAnnotationList.begin();
358 ite != theAnnotationList.end();364 ite != theAnnotationList.end();
359 ++ite)365 ++ite)
360 {366 {
361 if ((*ite)->getId() == id)367 if ((*ite)->getId() == id)
362 return (*ite).getp();368 return (*ite);
363 }369 }
364370
365 return NULL;371 return NULL;
@@ -408,7 +414,7 @@
408 RuleBitSet lCurrAnn;414 RuleBitSet lCurrAnn;
409415
410 // mark and detect duplicates416 // mark and detect duplicates
411 for (ListConstIter_t ite = theAnnotationList.begin();417 for (Annotations::const_iterator ite = theAnnotationList.begin();
412 ite != theAnnotationList.end();418 ite != theAnnotationList.end();
413 ++ite)419 ++ite)
414 {420 {
415421
=== modified file 'src/annotations/annotations.h'
--- src/annotations/annotations.h 2013-04-29 00:41:13 +0000
+++ src/annotations/annotations.h 2013-07-11 13:41:52 +0000
@@ -32,9 +32,6 @@
32class AnnotationInternal;32class AnnotationInternal;
33class AnnotationList;33class AnnotationList;
3434
35typedef rchandle<AnnotationInternal> AnnotationInternal_t;
36typedef rchandle<AnnotationList> AnnotationList_t;
37
38class const_expr;35class const_expr;
3936
40/*******************************************************************************37/*******************************************************************************
@@ -53,7 +50,7 @@
53 together in a declaration, then a conflict exists. Each set of annotations50 together in a declaration, then a conflict exists. Each set of annotations
54 is implemented as a bitset indexed by annotation id.51 is implemented as a bitset indexed by annotation id.
55********************************************************************************/52********************************************************************************/
56class AnnotationInternal : public SimpleRCObject53class AnnotationInternal : public ::zorba::serialization::SerializeBaseClass
57{54{
58 friend class AnnotationList;55 friend class AnnotationList;
5956
@@ -128,7 +125,7 @@
128125
129public:126public:
130 SERIALIZABLE_CLASS(AnnotationInternal);127 SERIALIZABLE_CLASS(AnnotationInternal);
131 SERIALIZABLE_CLASS_CONSTRUCTOR2(AnnotationInternal, SimpleRCObject)128 SERIALIZABLE_CLASS_CONSTRUCTOR(AnnotationInternal)
132 void serialize(::zorba::serialization::Archiver& ar);129 void serialize(::zorba::serialization::Archiver& ar);
133130
134public:131public:
@@ -149,7 +146,7 @@
149146
150 Annotation ::= "%" EQName ("(" Literal ("," Literal)* ")")?147 Annotation ::= "%" EQName ("(" Literal ("," Literal)* ")")?
151********************************************************************************/148********************************************************************************/
152class AnnotationList : public SimpleRCObject149class AnnotationList : public ::zorba::serialization::SerializeBaseClass
153{150{
154public:151public:
155 enum DeclarationKind152 enum DeclarationKind
@@ -165,16 +162,14 @@
165162
166 typedef AnnotationInternal::AnnotationId AnnotationId;163 typedef AnnotationInternal::AnnotationId AnnotationId;
167164
168 typedef std::vector<AnnotationInternal_t> List_t;165 typedef std::vector<AnnotationInternal*> Annotations;
169
170 typedef List_t::const_iterator ListConstIter_t;
171166
172protected:167protected:
173 List_t theAnnotationList;168 Annotations theAnnotationList;
174169
175public:170public:
176 SERIALIZABLE_CLASS(AnnotationList);171 SERIALIZABLE_CLASS(AnnotationList);
177 SERIALIZABLE_CLASS_CONSTRUCTOR2(AnnotationList, SimpleRCObject)172 SERIALIZABLE_CLASS_CONSTRUCTOR(AnnotationList)
178 void serialize(::zorba::serialization::Archiver& ar);173 void serialize(::zorba::serialization::Archiver& ar);
179174
180public:175public:
181176
=== modified file 'src/api/annotationimpl.cpp'
--- src/api/annotationimpl.cpp 2013-02-07 17:24:36 +0000
+++ src/api/annotationimpl.cpp 2013-07-11 13:41:52 +0000
@@ -27,11 +27,16 @@
2727
28********************************************************************************/28********************************************************************************/
29AnnotationImpl::AnnotationImpl(AnnotationInternal* ann) 29AnnotationImpl::AnnotationImpl(AnnotationInternal* ann)
30 : theAnnotation(ann)30{
31{31 theAnnotation = new AnnotationInternal(*ann);
32}32}
3333
34AnnotationImpl::~AnnotationImpl() {};34
35AnnotationImpl::~AnnotationImpl()
36{
37 delete theAnnotation;
38}
39
3540
36Item AnnotationImpl::getQName() const41Item AnnotationImpl::getQName() const
37{42{
3843
=== modified file 'src/api/annotationimpl.h'
--- src/api/annotationimpl.h 2013-02-07 17:24:36 +0000
+++ src/api/annotationimpl.h 2013-07-11 13:41:52 +0000
@@ -26,7 +26,6 @@
26{26{
2727
28class AnnotationInternal;28class AnnotationInternal;
29typedef rchandle<AnnotationInternal> AnnotationInternal_t;
3029
3130
32/*******************************************************************************31/*******************************************************************************
@@ -38,7 +37,7 @@
38{37{
39protected:38protected:
40 39
41 AnnotationInternal_t theAnnotation;40 AnnotationInternal * theAnnotation;
4241
43public:42public:
44 AnnotationImpl(AnnotationInternal* ann);43 AnnotationImpl(AnnotationInternal* ann);
4544
=== modified file 'src/api/serialization/serializer.cpp'
--- src/api/serialization/serializer.cpp 2013-06-29 08:38:53 +0000
+++ src/api/serialization/serializer.cpp 2013-07-11 13:41:52 +0000
@@ -38,10 +38,14 @@
38#include "util/xml_util.h"38#include "util/xml_util.h"
3939
40#include "system/globalenv.h"40#include "system/globalenv.h"
41
41#include "zorbamisc/ns_consts.h"42#include "zorbamisc/ns_consts.h"
43
42#include "zorbatypes/integer.h"44#include "zorbatypes/integer.h"
43#include "zorbatypes/numconversions.h"45#include "zorbatypes/numconversions.h"
4446
47#include "context/static_context.h"
48
45#include "store/api/iterator.h"49#include "store/api/iterator.h"
46#include "store/api/iterator_factory.h"50#include "store/api/iterator_factory.h"
47#include "store/api/item.h"51#include "store/api/item.h"
@@ -192,10 +196,12 @@
192196
193 // the input string is UTF-8197 // the input string is UTF-8
194 int char_length;198 int char_length;
195 try {199 try
200 {
196 char_length = utf8::char_length(*chars);201 char_length = utf8::char_length(*chars);
197 }202 }
198 catch ( utf8::invalid_byte const& ) {203 catch ( utf8::invalid_byte const& )
204 {
199 char_length = 1;205 char_length = 1;
200 }206 }
201207
@@ -445,9 +451,15 @@
445 tr << " ";451 tr << " ";
446452
447 if (item->isStreamable())453 if (item->isStreamable())
454 {
448 emit_streamable_item(item);455 emit_streamable_item(item);
456 }
449 else457 else
450 emit_expanded_string(item->getStringValue().c_str(), item->getStringValue().size());458 {
459 zstring strval;
460 item->getStringValue2(strval);
461 emit_expanded_string(strval.c_str(), strval.size());
462 }
451463
452 thePreviousItemKind = PREVIOUS_ITEM_WAS_TEXT;464 thePreviousItemKind = PREVIOUS_ITEM_WAS_TEXT;
453 }465 }
454466
=== modified file 'src/api/staticcontextimpl.cpp'
--- src/api/staticcontextimpl.cpp 2013-05-31 03:38:45 +0000
+++ src/api/staticcontextimpl.cpp 2013-07-11 13:41:52 +0000
@@ -1497,26 +1497,24 @@
1497Function_t1497Function_t
1498StaticContextImpl::checkInvokable(const Item& aQName, size_t aNumArgs) const1498StaticContextImpl::checkInvokable(const Item& aQName, size_t aNumArgs) const
1499{1499{
1500 Item lType = aQName.getType();1500 store::Item* qname = Unmarshaller::getInternalItem(aQName);
1501 if (lType.getStringValue() != "xs:QName")1501
1502 if (qname->getTypeCode() != store::XS_QNAME)
1502 {1503 {
1503 throw XQUERY_EXCEPTION(1504 throw XQUERY_EXCEPTION(err::XPTY0004,
1504 err::XPTY0004, ERROR_PARAMS( ZED( BadType_23o ), "xs:QName" )1505 ERROR_PARAMS(ZED(BadType_23o), "xs:QName" ));
1505 );
1506 }1506 }
15071507
1508 // test if function with given #args exists1508 // test if function with given #args exists
1509 Function_t lFunc;1509 Function_t lFunc;
1510
1510 std::vector<Function_t> lFunctions;1511 std::vector<Function_t> lFunctions;
1511 findFunctions(aQName, lFunctions);1512 findFunctions(aQName, lFunctions);
1513
1512 if (lFunctions.empty())1514 if (lFunctions.empty())
1513 {1515 {
1514 throw XQUERY_EXCEPTION(1516 throw XQUERY_EXCEPTION(err::XPST0017,
1515 err::XPST0017,1517 ERROR_PARAMS(aQName.getStringValue(), ZED(FunctionUndeclared_3), aNumArgs));
1516 ERROR_PARAMS(
1517 aQName.getStringValue(), ZED( FunctionUndeclared_3 ), aNumArgs
1518 )
1519 );
1520 }1518 }
15211519
1522 for (std::vector<Function_t>::const_iterator lIter = lFunctions.begin();1520 for (std::vector<Function_t>::const_iterator lIter = lFunctions.begin();
@@ -1531,12 +1529,8 @@
15311529
1532 if (!lFunc)1530 if (!lFunc)
1533 {1531 {
1534 throw XQUERY_EXCEPTION(1532 throw XQUERY_EXCEPTION(err::XPST0017,
1535 err::XPST0017,1533 ERROR_PARAMS(aQName.getStringValue(), ZED(FunctionUndeclared_3), aNumArgs));
1536 ERROR_PARAMS(
1537 aQName.getStringValue(), ZED( FunctionUndeclared_3 ), aNumArgs
1538 )
1539 );
1540 }1534 }
15411535
1542 return lFunc;1536 return lFunc;
15431537
=== modified file 'src/api/xmldatamanagerimpl.cpp'
--- src/api/xmldatamanagerimpl.cpp 2013-02-07 17:24:36 +0000
+++ src/api/xmldatamanagerimpl.cpp 2013-07-11 13:41:52 +0000
@@ -278,8 +278,7 @@
278{278{
279 ZORBA_DM_TRY279 ZORBA_DM_TRY
280 {280 {
281 Item lQName = theFactory->createQName(static_context::ZORBA_XML_FN_NS,281 Item lQName = theFactory->createQName(static_context::ZORBA_XML_FN_NS, "parse");
282 "parse");
283282
284 // create a streamable string item283 // create a streamable string item
285 std::vector<ItemSequence_t> lArgs;284 std::vector<ItemSequence_t> lArgs;
@@ -289,7 +288,9 @@
289 Item empty_item;288 Item empty_item;
290 Item validated_options;289 Item validated_options;
291 NsBindings nsPairs;290 NsBindings nsPairs;
292 Item untyped_type = theFactory->createQName(XML_SCHEMA_NS, XML_SCHEMA_PREFIX, "untyped");291 Item untyped_type = theFactory->createQName(static_context::W3C_XML_SCHEMA_NS,
292 "",
293 "untyped");
293 Item options_node = theFactory->createElementNode(empty_item,294 Item options_node = theFactory->createElementNode(empty_item,
294 theFactory->createQName(static_context::ZORBA_XML_FN_OPTIONS_NS, "options"),295 theFactory->createQName(static_context::ZORBA_XML_FN_OPTIONS_NS, "options"),
295 untyped_type, false, false, nsPairs);296 untyped_type, false, false, nsPairs);
@@ -337,7 +338,7 @@
337 Item empty_item;338 Item empty_item;
338 Item validated_options;339 Item validated_options;
339 NsBindings nsPairs;340 NsBindings nsPairs;
340 Item untyped_type = theFactory->createQName(XML_SCHEMA_NS, XML_SCHEMA_PREFIX, "untyped");341 Item untyped_type = theFactory->createQName(static_context::W3C_XML_SCHEMA_NS, "", "untyped");
341 Item options_node = theFactory->createElementNode(empty_item,342 Item options_node = theFactory->createElementNode(empty_item,
342 theFactory->createQName(static_context::ZORBA_XML_FN_OPTIONS_NS, "options"),343 theFactory->createQName(static_context::ZORBA_XML_FN_OPTIONS_NS, "options"),
343 untyped_type, false, false, nsPairs);344 untyped_type, false, false, nsPairs);
344345
=== modified file 'src/api/xqueryimpl.cpp'
--- src/api/xqueryimpl.cpp 2013-05-28 00:01:01 +0000
+++ src/api/xqueryimpl.cpp 2013-07-11 13:41:52 +0000
@@ -178,6 +178,7 @@
178 close();178 close();
179}179}
180180
181
181/*******************************************************************************182/*******************************************************************************
182 Always called while holding theMutex183 Always called while holding theMutex
183********************************************************************************/184********************************************************************************/
184185
=== modified file 'src/api/xqueryimpl.h'
--- src/api/xqueryimpl.h 2013-05-28 00:01:01 +0000
+++ src/api/xqueryimpl.h 2013-07-11 13:41:52 +0000
@@ -152,23 +152,17 @@
152152
153 protected:153 protected:
154154
155 class PlanProxy : public RCObject155 class PlanProxy : public SyncedRCObject
156 {156 {
157 public:157 public:
158 SYNC_CODE(mutable RCLock theRCLock;)
159
160 rchandle<SimpleRCObject> theRootIter;158 rchandle<SimpleRCObject> theRootIter;
161159
162 public:160 public:
163 SERIALIZABLE_CLASS(PlanProxy)161 SERIALIZABLE_CLASS(PlanProxy)
164 SERIALIZABLE_CLASS_CONSTRUCTOR2(PlanProxy, RCObject)162 SERIALIZABLE_CLASS_CONSTRUCTOR2(PlanProxy, SyncedRCObject)
165 void serialize(::zorba::serialization::Archiver& ar);163 void serialize(::zorba::serialization::Archiver& ar);
166164
167 public:165 public:
168 long* getSharedRefCounter() const { return NULL; }
169
170 SYNC_CODE(virtual RCLock* getRCLock() const { return &theRCLock; })
171
172 PlanProxy(PlanIter_t& root);166 PlanProxy(PlanIter_t& root);
173 };167 };
174168
175169
=== modified file 'src/api/zorbaimpl.cpp'
--- src/api/zorbaimpl.cpp 2013-02-07 17:24:36 +0000
+++ src/api/zorbaimpl.cpp 2013-07-11 13:41:52 +0000
@@ -73,6 +73,7 @@
73}73}
74#endif74#endif
7575
76
76ZorbaImpl::ZorbaImpl() : theNumUsers(0)77ZorbaImpl::ZorbaImpl() : theNumUsers(0)
77{78{
78#ifdef WIN3279#ifdef WIN32
@@ -138,8 +139,10 @@
138XQuery_t ZorbaImpl::createQuery(DiagnosticHandler* aDiagnosticHandler)139XQuery_t ZorbaImpl::createQuery(DiagnosticHandler* aDiagnosticHandler)
139{140{
140 XQuery_t lXQuery(new XQueryImpl());141 XQuery_t lXQuery(new XQueryImpl());
142
141 if (aDiagnosticHandler != 0)143 if (aDiagnosticHandler != 0)
142 lXQuery->registerDiagnosticHandler(aDiagnosticHandler);144 lXQuery->registerDiagnosticHandler(aDiagnosticHandler);
145
143 return lXQuery;146 return lXQuery;
144}147}
145148
@@ -169,9 +172,12 @@
169 DiagnosticHandler* aDiagnosticHandler)172 DiagnosticHandler* aDiagnosticHandler)
170{173{
171 XQuery_t lXQuery(new XQueryImpl());174 XQuery_t lXQuery(new XQueryImpl());
175
172 if (aDiagnosticHandler != 0)176 if (aDiagnosticHandler != 0)
173 lXQuery->registerDiagnosticHandler(aDiagnosticHandler);177 lXQuery->registerDiagnosticHandler(aDiagnosticHandler);
178
174 lXQuery->compile(aQuery, aHints);179 lXQuery->compile(aQuery, aHints);
180
175 return lXQuery;181 return lXQuery;
176}182}
177183
178184
=== modified file 'src/api/zorbaimpl.h'
--- src/api/zorbaimpl.h 2013-02-07 17:24:36 +0000
+++ src/api/zorbaimpl.h 2013-07-11 13:41:52 +0000
@@ -53,16 +53,18 @@
53 */53 */
54class ZorbaImpl : public Zorba54class ZorbaImpl : public Zorba
55{55{
56 protected:56protected:
57 friend class Zorba;57 friend class Zorba;
5858
59 SYNC_CODE(Mutex theUsersMutex);59 SYNC_CODE(Mutex theUsersMutex);
60 ulong theNumUsers;60 ulong theNumUsers;
61
61public:62public:
62#ifdef WIN3263#ifdef WIN32
63 static bool ctrl_c_signaled;64 static bool ctrl_c_signaled;
64#endif65#endif
65 public:66
67public:
6668
67 static void notifyError(DiagnosticHandler*, ZorbaException const&);69 static void notifyError(DiagnosticHandler*, ZorbaException const&);
6870
@@ -75,7 +77,7 @@
7577
76 static void checkItem(const store::Item_t& aItem);78 static void checkItem(const store::Item_t& aItem);
7779
78 public:80public:
7981
80 virtual ~ZorbaImpl();82 virtual ~ZorbaImpl();
8183
8284
=== modified file 'src/capi/csequence.cpp'
--- src/capi/csequence.cpp 2013-06-18 23:53:59 +0000
+++ src/capi/csequence.cpp 2013-07-11 13:41:52 +0000
@@ -30,6 +30,8 @@
30#include "zorbatypes/float.h"30#include "zorbatypes/float.h"
31#include "zorbatypes/numconversions.h"31#include "zorbatypes/numconversions.h"
3232
33#include "context/static_context.h"
34
33#include "error.h"35#include "error.h"
3436
35using namespace zorba;37using namespace zorba;
@@ -240,7 +242,7 @@
240 else /* not isNode() */ {242 else /* not isNode() */ {
241 Item lType = lItem.getType();243 Item lType = lItem.getType();
242 zorba::String lUri = lType.getNamespace();244 zorba::String lUri = lType.getNamespace();
243 if (lUri != XML_SCHEMA_NS) {245 if (lUri != static_context::W3C_XML_SCHEMA_NS) {
244 // We can only identify non-derived atomic types246 // We can only identify non-derived atomic types
245 return XQC_INTERNAL_ERROR;247 return XQC_INTERNAL_ERROR;
246 }248 }
247249
=== modified file 'src/common/shared_types.h'
--- src/common/shared_types.h 2013-06-26 13:56:00 +0000
+++ src/common/shared_types.h 2013-07-11 13:41:52 +0000
@@ -44,9 +44,8 @@
44class QueryLoc;44class QueryLoc;
4545
46class function;46class function;
47class user_function;
47typedef rchandle<function> function_t;48typedef rchandle<function> function_t;
48
49class user_function;
50typedef rchandle<user_function> user_function_t;49typedef rchandle<user_function> user_function_t;
5150
52class ItemIterator;51class ItemIterator;
@@ -88,7 +87,6 @@
8887
89// Annotations88// Annotations
90class AnnotationList;89class AnnotationList;
91typedef rchandle<AnnotationList> AnnotationList_t;
9290
93// Expression nodes91// Expression nodes
94class expr;92class expr;
9593
=== modified file 'src/compiler/codegen/plan_visitor.cpp'
--- src/compiler/codegen/plan_visitor.cpp 2013-06-15 02:57:08 +0000
+++ src/compiler/codegen/plan_visitor.cpp 2013-07-11 13:41:52 +0000
@@ -468,7 +468,7 @@
468{468{
469 CODEGEN_TRACE_OUT("");469 CODEGEN_TRACE_OUT("");
470470
471 FunctionItemInfo* fnInfo = v.get_dynamic_fn_info();471 FunctionItemInfo* fnInfo = v.get_fi_info();
472 fnInfo->theCCB = theCCB;472 fnInfo->theCCB = theCCB;
473 fnInfo->theLoc = qloc;473 fnInfo->theLoc = qloc;
474474
475475
=== modified file 'src/compiler/expression/expr_put.cpp'
--- src/compiler/expression/expr_put.cpp 2013-06-15 02:57:08 +0000
+++ src/compiler/expression/expr_put.cpp 2013-07-11 13:41:52 +0000
@@ -553,7 +553,7 @@
553 }553 }
554554
555 user_function* udf = 555 user_function* udf =
556 static_cast<user_function*>(theFunctionItemInfo->theFunction.getp());556 static_cast<user_function*>(theFunctionItemInfo->theFunction);
557557
558 if (udf != NULL && udf->getBody() != NULL)558 if (udf != NULL && udf->getBody() != NULL)
559 udf->getBody()->put(os);559 udf->getBody()->put(os);
560560
=== modified file 'src/compiler/expression/fo_expr.cpp'
--- src/compiler/expression/fo_expr.cpp 2013-02-07 17:24:36 +0000
+++ src/compiler/expression/fo_expr.cpp 2013-07-11 13:41:52 +0000
@@ -62,7 +62,7 @@
62 user_function* udf,62 user_function* udf,
63 const QueryLoc& loc)63 const QueryLoc& loc)
64{64{
65 function* f = BuiltinFunctionLibrary::getFunction(FunctionConsts::OP_CONCATENATE_N);65 function* f = GENV_FUNC_LIB->getFunction(FunctionConsts::OP_CONCATENATE_N);
6666
67 std::auto_ptr<fo_expr> fo(ccb->theEM->create_fo_expr(sctx, udf, loc, f));67 std::auto_ptr<fo_expr> fo(ccb->theEM->create_fo_expr(sctx, udf, loc, f));
6868
6969
=== modified file 'src/compiler/expression/function_item_expr.cpp'
--- src/compiler/expression/function_item_expr.cpp 2013-04-24 01:35:58 +0000
+++ src/compiler/expression/function_item_expr.cpp 2013-07-11 13:41:52 +0000
@@ -92,15 +92,16 @@
92 bool isInline,92 bool isInline,
93 bool isCoercion)93 bool isCoercion)
94 :94 :
95 expr(ccb, sctx, udf, loc, function_item_expr_kind),95 expr(ccb, sctx, udf, loc, function_item_expr_kind)
96 theFunctionItemInfo(new FunctionItemInfo(sctx,
97 loc,
98 f,
99 f->getName(),
100 arity,
101 isInline,
102 isCoercion))
103{96{
97 theFunctionItemInfo = new FunctionItemInfo(sctx,
98 loc,
99 f,
100 f->getName(),
101 arity,
102 isInline,
103 isCoercion);
104
104 assert(f != NULL);105 assert(f != NULL);
105 compute_scripting_kind();106 compute_scripting_kind();
106}107}
@@ -114,15 +115,16 @@
114 bool isInline,115 bool isInline,
115 bool isCoercion)116 bool isCoercion)
116 :117 :
117 expr(ccb, sctx, udf, loc, function_item_expr_kind),118 expr(ccb, sctx, udf, loc, function_item_expr_kind)
118 theFunctionItemInfo(new FunctionItemInfo(sctx,
119 loc,
120 NULL,
121 NULL,
122 0,
123 isInline,
124 isCoercion))
125{119{
120 theFunctionItemInfo = new FunctionItemInfo(sctx,
121 loc,
122 NULL,
123 NULL,
124 0,
125 isInline,
126 isCoercion);
127
126 compute_scripting_kind();128 compute_scripting_kind();
127}129}
128130
129131
=== modified file 'src/compiler/expression/function_item_expr.h'
--- src/compiler/expression/function_item_expr.h 2013-04-27 16:36:36 +0000
+++ src/compiler/expression/function_item_expr.h 2013-07-11 13:41:52 +0000
@@ -151,7 +151,7 @@
151 virtual ~function_item_expr();151 virtual ~function_item_expr();
152 152
153public:153public:
154 FunctionItemInfo* get_dynamic_fn_info() { return theFunctionItemInfo; }154 FunctionItemInfo* get_fi_info() { return theFunctionItemInfo; }
155155
156 void add_variable(expr* var, var_expr* substVar);156 void add_variable(expr* var, var_expr* substVar);
157157
158158
=== modified file 'src/compiler/parsetree/parsenode_print_xqdoc_visitor.cpp'
--- src/compiler/parsetree/parsenode_print_xqdoc_visitor.cpp 2013-06-18 23:53:59 +0000
+++ src/compiler/parsetree/parsenode_print_xqdoc_visitor.cpp 2013-07-11 13:41:52 +0000
@@ -38,6 +38,8 @@
38#include "store/api/copymode.h"38#include "store/api/copymode.h"
39#include "store/api/iterator.h"39#include "store/api/iterator.h"
4040
41#include "context/static_context.h"
42
41#include "system/globalenv.h"43#include "system/globalenv.h"
42#include "zorbamisc/ns_consts.h"44#include "zorbamisc/ns_consts.h"
4345
@@ -517,9 +519,9 @@
517 theIsIndexDecl(false),519 theIsIndexDecl(false),
518 theWaitForIndexSourceLiteral(false)520 theWaitForIndexSourceLiteral(false)
519{521{
520 theNamespaceMap["fn"] = XQUERY_XPATH_FN_NS;522 theNamespaceMap["fn"] = static_context::W3C_FN_NS;
521 theNamespaceMap[""] = XQUERY_XPATH_FN_NS;523 theNamespaceMap[""] = static_context::W3C_FN_NS;
522 theNamespaceMap[XML_SCHEMA_PREFIX] = XML_SCHEMA_NS;524 theNamespaceMap[XML_SCHEMA_PREFIX] = static_context::W3C_XML_SCHEMA_NS;
523 theNamespaceMap["local"] = XQUERY_LOCAL_FN_NS;525 theNamespaceMap["local"] = XQUERY_LOCAL_FN_NS;
524}526}
525527
526528
=== modified file 'src/compiler/rewriter/rules/type_rules.cpp'
--- src/compiler/rewriter/rules/type_rules.cpp 2013-06-15 02:57:08 +0000
+++ src/compiler/rewriter/rules/type_rules.cpp 2013-07-11 13:41:52 +0000
@@ -605,7 +605,7 @@
605 ZORBA_ASSERT(false);605 ZORBA_ASSERT(false);
606 }606 }
607607
608 return BuiltinFunctionLibrary::getFunction(newKind);608 return GENV_FUNC_LIB->getFunction(newKind);
609}609}
610610
611611
612612
=== modified file 'src/compiler/translator/translator.cpp'
--- src/compiler/translator/translator.cpp 2013-06-27 00:05:25 +0000
+++ src/compiler/translator/translator.cpp 2013-07-11 13:41:52 +0000
@@ -684,7 +684,7 @@
684684
685 std::stack<bool> theInWhileStack;685 std::stack<bool> theInWhileStack;
686686
687 rchandle<AnnotationList> theAnnotations;687 std::auto_ptr<AnnotationList> theAnnotations;
688688
689 IndexDecl_t theIndexDecl;689 IndexDecl_t theIndexDecl;
690 bool theIsInIndexDomain;690 bool theIsInIndexDomain;
@@ -1123,7 +1123,7 @@
1123 }1123 }
1124 else if (local == "atomic")1124 else if (local == "atomic")
1125 {1125 {
1126 ns = XML_SCHEMA_NS;1126 ns = static_context::W3C_XML_SCHEMA_NS;
1127 local = "anyAtomicType";1127 local = "anyAtomicType";
1128 }1128 }
1129 else1129 else
@@ -1136,7 +1136,7 @@
1136 WARN_LOC(loc)));1136 WARN_LOC(loc)));
1137 }1137 }
1138 1138
1139 ns = XML_SCHEMA_NS;1139 ns = static_context::W3C_XML_SCHEMA_NS;
1140 }1140 }
11411141
1142 GENV_ITEMFACTORY->createQName(qnameItem, ns, "", local);1142 GENV_ITEMFACTORY->createQName(qnameItem, ns, "", local);
@@ -1428,18 +1428,18 @@
1428 such a binding exists already in any of these sctxs.1428 such a binding exists already in any of these sctxs.
1429********************************************************************************/1429********************************************************************************/
1430void bind_fn(1430void bind_fn(
1431 function_t& f,1431 const function_t& f,
1432 csize nargs,1432 csize nargs,
1433 const QueryLoc& loc)1433 const QueryLoc& loc)
1434{1434{
1435 theSctx->bind_fn(f, nargs, loc);
1436
1437 theModulesInfo->theGlobalSctx->bind_fn(f, nargs, loc);1435 theModulesInfo->theGlobalSctx->bind_fn(f, nargs, loc);
14381436
1439 if (theExportSctx != NULL)1437 if (theExportSctx != NULL)
1440 {1438 {
1441 theExportSctx->bind_fn(f, nargs, loc);1439 theExportSctx->bind_fn(f, nargs, loc);
1442 }1440 }
1441
1442 theSctx->bind_fn(f, nargs, loc);
1443}1443}
14441444
14451445
@@ -1647,14 +1647,14 @@
1647 inlineFuncExpr->add_variable(fiVar, fiSubstVar);1647 inlineFuncExpr->add_variable(fiVar, fiSubstVar);
16481648
1649 // Create the inline udf obj.1649 // Create the inline udf obj.
1650 user_function_t inlineUDF = 1650 std::auto_ptr<user_function> inlineUDF(
1651 new user_function(loc,1651 new user_function(loc,
1652 signature(function_item_expr::create_inline_fname(loc),1652 signature(function_item_expr::create_inline_fname(loc),
1653 funcType->get_param_types(),1653 funcType->get_param_types(),
1654 returnType),1654 returnType),
1655 NULL,1655 NULL,
1656 SIMPLE_EXPR,1656 SIMPLE_EXPR,
1657 theCCB);1657 theCCB));
16581658
1659 std::vector<var_expr*> argVars;1659 std::vector<var_expr*> argVars;
1660 std::vector<expr*> arguments; // Arguments to the dynamic function call1660 std::vector<expr*> arguments; // Arguments to the dynamic function call
@@ -1669,7 +1669,7 @@
1669 argVars.push_back(argVar);1669 argVars.push_back(argVar);
16701670
1671 expr* arg = CREATE(wrapper)(theRootSctx, theUDF, loc, argVar);1671 expr* arg = CREATE(wrapper)(theRootSctx, theUDF, loc, argVar);
1672 arg = normalize_fo_arg(i, arg, inlineUDF, loc);1672 arg = normalize_fo_arg(i, arg, inlineUDF.get(), loc);
1673 arguments.push_back(arg);1673 arguments.push_back(arg);
1674 }1674 }
16751675
@@ -1696,7 +1696,7 @@
1696 inlineUDF->setArgVars(argVars);1696 inlineUDF->setArgVars(argVars);
1697 inlineUDF->setOptimized(true);1697 inlineUDF->setOptimized(true);
16981698
1699 inlineFuncExpr->set_function(inlineUDF, inlineUDF->numArgs());1699 inlineFuncExpr->set_function(inlineUDF.release(), inlineUDF->numArgs());
17001700
1701 // pop the scope.1701 // pop the scope.
1702 pop_scope();1702 pop_scope();
@@ -1813,12 +1813,9 @@
1813 fkind = FunctionConsts::OP_SORT_DISTINCT_NODES_ASC_1;1813 fkind = FunctionConsts::OP_SORT_DISTINCT_NODES_ASC_1;
1814 }1814 }
18151815
1816 fo_expr* dos = theExprManager->1816 fo_expr* dos = CREATE(fo)(theRootSctx, theUDF, expr->get_loc(),
1817 create_fo_expr(theRootSctx,1817 GENV_FUNC_LIB->getFunction(fkind),
1818 theUDF,1818 expr);
1819 expr->get_loc(),
1820 BuiltinFunctionLibrary::getFunction(fkind),
1821 expr);
18221819
1823 normalize_fo(dos);1820 normalize_fo(dos);
18241821
@@ -2209,7 +2206,7 @@
2209 theSctx->bind_ns(pfx, targetNS, loc);2206 theSctx->bind_ns(pfx, targetNS, loc);
2210 }2207 }
22112208
2212 if (targetNS == XML_SCHEMA_NS)2209 if (targetNS == static_context::W3C_XML_SCHEMA_NS)
2213 {2210 {
2214 // Xerces doesn't like importing XMLSchema.xsd schema4schema, so we skip it2211 // Xerces doesn't like importing XMLSchema.xsd schema4schema, so we skip it
2215 // see Xerces-C++ bug: https://issues.apache.org/jira/browse/XERCESC-19802212 // see Xerces-C++ bug: https://issues.apache.org/jira/browse/XERCESC-1980
@@ -3216,7 +3213,7 @@
3216 RAISE_ERROR(err::XQST0070, loc,3213 RAISE_ERROR(err::XQST0070, loc,
3217 ERROR_PARAMS(ZED(XQST0070_ReservedPrefixInDecl_2), pre));3214 ERROR_PARAMS(ZED(XQST0070_ReservedPrefixInDecl_2), pre));
3218 }3215 }
3219 else if (uri == XML_NS || uri == XMLNS_NS)3216 else if (uri == static_context::W3C_XML_NS || uri == XMLNS_NS)
3220 {3217 {
3221 RAISE_ERROR(err::XQST0070, loc,3218 RAISE_ERROR(err::XQST0070, loc,
3222 ERROR_PARAMS(ZED(XQST0070_ReservedURI_23), pre, uri));3219 ERROR_PARAMS(ZED(XQST0070_ReservedURI_23), pre, uri));
@@ -3243,7 +3240,7 @@
32433240
3244 zstring uri = v.get_default_namespace();3241 zstring uri = v.get_default_namespace();
32453242
3246 if (uri == XML_NS || uri == XMLNS_NS)3243 if (uri == static_context::W3C_XML_NS || uri == XMLNS_NS)
3247 {3244 {
3248 RAISE_ERROR(err::XQST0070, loc,3245 RAISE_ERROR(err::XQST0070, loc,
3249 ERROR_PARAMS(ZED(XQST0070_ReservedURI_23), "", uri));3246 ERROR_PARAMS(ZED(XQST0070_ReservedURI_23), "", uri));
@@ -3515,7 +3512,7 @@
35153512
3516 // Get the parent of the query root sctx. This is the user-specified sctx3513 // Get the parent of the query root sctx. This is the user-specified sctx
3517 // (if any) or the zorba root sctx (if no user-specified sctx).3514 // (if any) or the zorba root sctx (if no user-specified sctx).
3518 static_context_t independentSctx =3515 static_context* independentSctx =
3519 static_cast<static_context *>(theCCB->theRootSctx->get_parent());3516 static_cast<static_context *>(theCCB->theRootSctx->get_parent());
35203517
3521 // Create the root sctx for the imported module as a child of the3518 // Create the root sctx for the imported module as a child of the
@@ -3841,7 +3838,7 @@
3841 {3838 {
3842 annotations->accept(*this);3839 annotations->accept(*this);
38433840
3844 if (theAnnotations)3841 if (theAnnotations.get())
3845 {3842 {
3846 theAnnotations->3843 theAnnotations->
3847 checkConflictingDeclarations(AnnotationList::var_decl, loc);3844 checkConflictingDeclarations(AnnotationList::var_decl, loc);
@@ -3874,7 +3871,7 @@
3874 ve->set_mutable(theSctx->is_feature_set(feature::scripting));3871 ve->set_mutable(theSctx->is_feature_set(feature::scripting));
3875 }3872 }
38763873
3877 theAnnotations = NULL;3874 theAnnotations.reset(NULL);
38783875
3879 // Put a mapping between the var name and the var_expr in the local sctx.3876 // Put a mapping between the var name and the var_expr in the local sctx.
3880 // Raise error if var name exists already in local sctx obj.3877 // Raise error if var name exists already in local sctx obj.
@@ -3927,8 +3924,8 @@
3927 RAISE_ERROR(err::XQST0060, loc, ERROR_PARAMS(qnameItem->getStringValue()));3924 RAISE_ERROR(err::XQST0060, loc, ERROR_PARAMS(qnameItem->getStringValue()));
39283925
3929 if (ns == static_context::W3C_FN_NS ||3926 if (ns == static_context::W3C_FN_NS ||
3930 ns == XML_NS ||3927 ns == static_context::W3C_XML_NS ||
3931 ns == XML_SCHEMA_NS ||3928 ns == static_context::W3C_XML_SCHEMA_NS ||
3932 ns == XSI_NS ||3929 ns == XSI_NS ||
3933 ns == static_context::XQUERY_MATH_FN_NS)3930 ns == static_context::XQUERY_MATH_FN_NS)
3934 {3931 {
@@ -3984,12 +3981,12 @@
3984 }3981 }
39853982
3986 // Create the function signature.3983 // Create the function signature.
3987 bool isVariadic = (theAnnotations ? ZANN_CONTAINS(zann_variadic): false);3984 bool isVariadic = (theAnnotations.get() ? ZANN_CONTAINS(zann_variadic): false);
39883985
3989 signature sig(qnameItem, paramTypes, returnType, isVariadic);3986 signature sig(qnameItem, paramTypes, returnType, isVariadic);
39903987
3991 // Get the scripting kind of the function3988 // Get the scripting kind of the function
3992 bool isSequential = (theAnnotations ?3989 bool isSequential = (theAnnotations.get() ?
3993 ZANN_CONTAINS(zann_sequential) :3990 ZANN_CONTAINS(zann_sequential) :
3994 false);3991 false);
39953992
@@ -4001,12 +3998,12 @@
4001 scriptKind = SEQUENTIAL_FUNC_EXPR;3998 scriptKind = SEQUENTIAL_FUNC_EXPR;
40023999
4003 // create the function object4000 // create the function object
4004 function_t f;4001 function_t func;
40054002
4006 if (func_decl->is_external())4003 if (func_decl->is_external())
4007 {4004 {
4008 // 1. lookup if the function is a built-in function4005 // 1. lookup if the function is a built-in function
4009 f = theSctx->lookup_fn(qnameItem, numParams, false);4006 function* f = theSctx->lookup_fn(qnameItem, numParams, false);
40104007
4011 if (f != 0)4008 if (f != 0)
4012 {4009 {
@@ -4036,8 +4033,8 @@
4036 qnameItem->getLocalName())));4033 qnameItem->getLocalName())));
4037 }4034 }
40384035
4039 f->setAnnotations(theAnnotations);4036 f->setAnnotations(theAnnotations.get());
4040 theAnnotations = NULL; // important to reset4037 theAnnotations.release(); // important to reset
40414038
4042 // continue with the next declaration, because we don't add already4039 // continue with the next declaration, because we don't add already
4043 // built-in functions to the static context4040 // built-in functions to the static context
@@ -4080,25 +4077,27 @@
40804077
4081 ZORBA_ASSERT(ef != NULL);4078 ZORBA_ASSERT(ef != NULL);
40824079
4083 f = new external_function(loc,4080 func = new external_function(loc,
4084 theRootSctx,4081 theRootSctx,
4085 qnameItem->getNamespace(),4082 qnameItem->getNamespace(),
4086 sig,4083 sig,
4087 scriptKind,4084 scriptKind,
4088 ef);4085 ef);
4089 }4086 }
4090 else // Process UDF (non-external) function declaration4087 else
4091 {4088 {
4092 f = new user_function(loc, sig, NULL, scriptKind, theCCB); // no body for now4089 // It's a UDF (non-external) function declaration. Create a user_function
4090 // obj with no body for now.
4091 func = new user_function(loc, sig, NULL, scriptKind, theCCB);
4093 }4092 }
40944093
4095 f->setAnnotations(theAnnotations);4094 func->setAnnotations(theAnnotations.get());
4096 theAnnotations = NULL; // important to reset4095 theAnnotations.release(); // important to reset
40974096
4098 // Create bindings between (function qname item, arity) and function obj4097 // Create bindings between (function qname item, arity) and function obj
4099 // in the current sctx of this module and, if this is a lib module, in its4098 // in the current sctx of this module and, if this is a lib module, in its
4100 // export sctx as well.4099 // export sctx as well.
4101 bind_fn(f, numParams, loc);4100 bind_fn(func, numParams, loc);
4102 }4101 }
41034102
4104 if (haveXQueryOptions)4103 if (haveXQueryOptions)
@@ -4753,7 +4752,7 @@
47534752
4754 ve->set_mutable(false);4753 ve->set_mutable(false);
47554754
4756 theAnnotations = NULL;4755 theAnnotations.reset(NULL);
47574756
4758 // Put a mapping between the var name and the var_expr in the local sctx.4757 // Put a mapping between the var name and the var_expr in the local sctx.
4759 // Raise error if var name exists already in local sctx obj.4758 // Raise error if var name exists already in local sctx obj.
@@ -4819,9 +4818,9 @@
4819{4818{
4820 TRACE_VISIT();4819 TRACE_VISIT();
48214820
4822 assert(theAnnotations == NULL);4821 assert(theAnnotations.get() == NULL);
48234822
4824 theAnnotations = new AnnotationList();4823 theAnnotations.reset(new AnnotationList());
48254824
4826 return no_state;4825 return no_state;
4827}4826}
@@ -4861,7 +4860,7 @@
48614860
4862 if (annotNS == static_context::XQUERY_NS ||4861 if (annotNS == static_context::XQUERY_NS ||
4863 annotNS == static_context::W3C_XML_NS ||4862 annotNS == static_context::W3C_XML_NS ||
4864 annotNS == XML_SCHEMA_NS ||4863 annotNS == static_context::W3C_XML_SCHEMA_NS ||
4865 annotNS == XSI_NS ||4864 annotNS == XSI_NS ||
4866 annotNS == static_context::W3C_FN_NS ||4865 annotNS == static_context::W3C_FN_NS ||
4867 annotNS == static_context::XQUERY_MATH_FN_NS ||4866 annotNS == static_context::XQUERY_MATH_FN_NS ||
@@ -4977,9 +4976,9 @@
4977 lAnns->accept(*this);4976 lAnns->accept(*this);
4978 }4977 }
49794978
4980 if ( !theAnnotations )4979 if (theAnnotations.get() == NULL)
4981 {4980 {
4982 theAnnotations = new AnnotationList();4981 theAnnotations.reset(new AnnotationList());
4983 }4982 }
49844983
4985 theAnnotations->4984 theAnnotations->
@@ -5058,14 +5057,14 @@
5058 // Create the collection object and register it in the static context5057 // Create the collection object and register it in the static context
5059 StaticallyKnownCollection_t lColl = new StaticallyKnownCollection(5058 StaticallyKnownCollection_t lColl = new StaticallyKnownCollection(
5060 lExpandedQName,5059 lExpandedQName,
5061 theAnnotations,5060 theAnnotations.get(),
5062 lNodeType,5061 lNodeType,
5063 lCollectionType,5062 lCollectionType,
5064 lUpdateMode,5063 lUpdateMode,
5065 lOrderMode,5064 lOrderMode,
5066 lNodeModifier);5065 lNodeModifier);
50675066
5068 theAnnotations = NULL; // important to reset5067 theAnnotations.release(); // important to reset
50695068
5070 theSctx->bind_collection(lColl, loc);5069 theSctx->bind_collection(lColl, loc);
50715070
@@ -5136,7 +5135,7 @@
5136 lAnns->accept(*this);5135 lAnns->accept(*this);
5137 }5136 }
51385137
5139 if (theAnnotations)5138 if (theAnnotations.get())
5140 {5139 {
5141 theAnnotations->5140 theAnnotations->
5142 checkConflictingDeclarations(AnnotationList::index_decl, loc);5141 checkConflictingDeclarations(AnnotationList::index_decl, loc);
@@ -5161,7 +5160,7 @@
5161 }5160 }
5162 }5161 }
51635162
5164 theAnnotations = NULL;5163 theAnnotations.reset(NULL);
51655164
5166 theIndexDecl = index;5165 theIndexDecl = index;
5167 theIsInIndexDomain = true;5166 theIsInIndexDomain = true;
@@ -6502,7 +6501,7 @@
65026501
6503 var_expr* ve = dynamic_cast<var_expr*>(pop_nodestack());6502 var_expr* ve = dynamic_cast<var_expr*>(pop_nodestack());
65046503
6505 if (theAnnotations)6504 if (theAnnotations.get())
6506 {6505 {
6507 theAnnotations->6506 theAnnotations->
6508 checkConflictingDeclarations(AnnotationList::var_decl, loc);6507 checkConflictingDeclarations(AnnotationList::var_decl, loc);
@@ -6546,7 +6545,7 @@
65466545
6547 push_nodestack(initExpr);6546 push_nodestack(initExpr);
65486547
6549 theAnnotations = NULL;6548 theAnnotations.reset(NULL);
6550}6549}
65516550
65526551
@@ -12595,17 +12594,17 @@
12595 const QueryLoc& loc)12594 const QueryLoc& loc)
12596{12595{
12597 xqtref_t type;12596 xqtref_t type;
12598 rchandle<user_function> udf;12597 std::auto_ptr<user_function> udf;
12599 expr* body;12598 expr* body;
12600 12599
12601 function_item_expr* fiExpr =12600 function_item_expr* fiExpr =
12602 CREATE(function_item)(theRootSctx, theUDF, loc, false, false);12601 CREATE(function_item)(theRootSctx, theUDF, loc, false, false);
1260312602
12604 function* f = theSctx->lookup_fn(qnameItem, arity, loc);12603 function* func = theSctx->lookup_fn(qnameItem, arity, loc);
1260512604
12606 // Raise XPST0017 if function could not be found, unless it is a type constructor12605 // Raise XPST0017 if function could not be found, unless it is a type constructor
12607 // function12606 // function
12608 if (f == NULL)12607 if (func == NULL)
12609 {12608 {
12610 type = CTX_TM->12609 type = CTX_TM->
12611 create_named_type(qnameItem, TypeConstants::QUANT_QUESTION, loc);12610 create_named_type(qnameItem, TypeConstants::QUANT_QUESTION, loc);
@@ -12623,16 +12622,16 @@
12623 var_expr* argVar = create_temp_var(loc, var_expr::arg_var);12622 var_expr* argVar = create_temp_var(loc, var_expr::arg_var);
12624 argVar->set_param_pos(0);12623 argVar->set_param_pos(0);
12625 udfArgs[0] = argVar;12624 udfArgs[0] = argVar;
12626 expr* body = CREATE(cast)(theRootSctx, udf, loc, argVar, type, false);12625 expr* body = CREATE(cast)(theRootSctx, theUDF, loc, argVar, type, false);
1262712626
12628 udf = new user_function(loc,12627 udf.reset(new user_function(loc,
12629 signature(qnameItem, theRTM.ITEM_TYPE_QUESTION, type),12628 signature(qnameItem, theRTM.ITEM_TYPE_QUESTION, type),
12630 body,12629 body,
12631 SIMPLE_EXPR,12630 SIMPLE_EXPR,
12632 theCCB);12631 theCCB));
1263312632
12634 udf->setArgVars(udfArgs);12633 udf->setArgVars(udfArgs);
12635 f = udf;12634 func = udf.get();
12636 }12635 }
12637 else12636 else
12638 {12637 {
@@ -12640,7 +12639,7 @@
12640 // the module it belongs to has been imported.12639 // the module it belongs to has been imported.
12641 const zstring& fn_ns = qnameItem->getNamespace();12640 const zstring& fn_ns = qnameItem->getNamespace();
1264212641
12643 if (f->isBuiltin() &&12642 if (func->isBuiltin() &&
12644 fn_ns != static_context::W3C_FN_NS &&12643 fn_ns != static_context::W3C_FN_NS &&
12645 fn_ns != static_context::JSONIQ_FN_NS &&12644 fn_ns != static_context::JSONIQ_FN_NS &&
12646 fn_ns != static_context::XQUERY_MATH_FN_NS &&12645 fn_ns != static_context::XQUERY_MATH_FN_NS &&
@@ -12655,15 +12654,15 @@
1265512654
12656 // If it is a builtin function F with signature (R, T1, ..., TN) , wrap it12655 // If it is a builtin function F with signature (R, T1, ..., TN) , wrap it
12657 // in a udf UF: function UF(x1 as T1, ..., xN as TN) as R { F(x1, ... xN) }12656 // in a udf UF: function UF(x1 as T1, ..., xN as TN) as R { F(x1, ... xN) }
12658 if (!f->isUdf())12657 if (!func->isUdf())
12659 {12658 {
12660 FunctionConsts::FunctionKind fkind = f->getKind();12659 FunctionConsts::FunctionKind fkind = func->getKind();
1266112660
12662 udf = new user_function(loc,12661 udf.reset(new user_function(loc,
12663 f->getSignature(),12662 func->getSignature(),
12664 NULL, // no body for now12663 NULL, // no body for now
12665 f->getScriptingKind(),12664 func->getScriptingKind(),
12666 theCCB);12665 theCCB));
1266712666
12668 std::vector<expr*> foArgs(arity);12667 std::vector<expr*> foArgs(arity);
12669 std::vector<var_expr*> udfArgs(arity);12668 std::vector<var_expr*> udfArgs(arity);
@@ -12696,13 +12695,13 @@
1269612695
12697 fiExpr->add_variable(posVarRef, substVar);12696 fiExpr->add_variable(posVarRef, substVar);
1269812697
12699 body = generate_fn_body(f, foArgs, loc);12698 body = generate_fn_body(func, foArgs, loc);
1270012699
12701 pop_scope();12700 pop_scope();
12702 }12701 }
12703 else12702 else
12704 {12703 {
12705 body = generate_fn_body(f, foArgs, loc);12704 body = generate_fn_body(func, foArgs, loc);
12706 }12705 }
1270712706
12708 break;12707 break;
@@ -12725,13 +12724,13 @@
1272512724
12726 fiExpr->add_variable(sizeVarRef, substVar);12725 fiExpr->add_variable(sizeVarRef, substVar);
1272712726
12728 body = generate_fn_body(f, foArgs, loc);12727 body = generate_fn_body(func, foArgs, loc);
1272912728
12730 pop_scope();12729 pop_scope();
12731 }12730 }
12732 else12731 else
12733 {12732 {
12734 body = generate_fn_body(f, foArgs, loc);12733 body = generate_fn_body(func, foArgs, loc);
12735 }12734 }
1273612735
12737 break;12736 break;
@@ -12773,13 +12772,13 @@
1277312772
12774 fiExpr->add_variable(dotVarRef, substVar);12773 fiExpr->add_variable(dotVarRef, substVar);
1277512774
12776 body = generate_fn_body(f, foArgs, loc);12775 body = generate_fn_body(func, foArgs, loc);
1277712776
12778 pop_scope();12777 pop_scope();
12779 }12778 }
12780 else12779 else
12781 {12780 {
12782 body = generate_fn_body(f, foArgs, loc);12781 body = generate_fn_body(func, foArgs, loc);
12783 }12782 }
1278412783
12785 break;12784 break;
@@ -12793,7 +12792,7 @@
12793 flworBody->add_clause(lc);12792 flworBody->add_clause(lc);
12794 foArgs[1] = CREATE(wrapper)(theRootSctx, theUDF, loc, lc->get_var());12793 foArgs[1] = CREATE(wrapper)(theRootSctx, theUDF, loc, lc->get_var());
1279512794
12796 flworBody->set_return_expr(generate_fn_body(f, foArgs, loc));12795 flworBody->set_return_expr(generate_fn_body(func, foArgs, loc));
12797 body = flworBody;12796 body = flworBody;
12798 break;12797 break;
12799 }12798 }
@@ -12853,7 +12852,7 @@
12853 fiExpr->add_variable(ctxVRef, substVar);12852 fiExpr->add_variable(ctxVRef, substVar);
12854 }12853 }
1285512854
12856 body = generate_fn_body(f, foArgs, loc);12855 body = generate_fn_body(func, foArgs, loc);
1285712856
12858 if (varAdded)12857 if (varAdded)
12859 pop_scope();12858 pop_scope();
@@ -12862,7 +12861,7 @@
12862 }12861 }
12863 default:12862 default:
12864 {12863 {
12865 body = generate_fn_body(f, foArgs, loc);12864 body = generate_fn_body(func, foArgs, loc);
12866 break;12865 break;
12867 }12866 }
12868 } // switch 12867 } // switch
@@ -12873,7 +12872,7 @@
12873 } // if builtin function12872 } // if builtin function
12874 else12873 else
12875 {12874 {
12876 udf = static_cast<user_function*>(f);12875 udf.reset(static_cast<user_function*>(func));
12877 }12876 }
12878 }12877 }
1287912878
@@ -12882,7 +12881,7 @@
12882 // because the function item expression may be a forward refereence to a real12881 // because the function item expression may be a forward refereence to a real
12883 // UDF, in which case udf->numArgs() returns 0 since the UDF declaration has12882 // UDF, in which case udf->numArgs() returns 0 since the UDF declaration has
12884 // not been fully processed yet. 12883 // not been fully processed yet.
12885 fiExpr->set_function(udf, arity);12884 fiExpr->set_function(udf.release(), arity);
1288612885
12887 return fiExpr;12886 return fiExpr;
12888}12887}
@@ -13035,14 +13034,14 @@
13035 }13034 }
1303613035
13037 // Create the udf obj.13036 // Create the udf obj.
13038 user_function_t udf = 13037 std::auto_ptr<user_function> udf(
13039 new user_function(loc,13038 new user_function(loc,
13040 signature(function_item_expr::create_inline_fname(loc),13039 signature(function_item_expr::create_inline_fname(loc),
13041 paramTypes,13040 paramTypes,
13042 returnType),13041 returnType),
13043 NULL,13042 NULL,
13044 SIMPLE_EXPR,13043 SIMPLE_EXPR,
13045 theCCB);13044 theCCB));
1304613045
13047 // Parameters, if any, have been translated into LET vars in a flwor expr.13046 // Parameters, if any, have been translated into LET vars in a flwor expr.
13048 // The UDF body, which in genral references these LET vars, must become the13047 // The UDF body, which in genral references these LET vars, must become the
@@ -13064,7 +13063,7 @@
13064 // for arg-value type checking must be placed in the body of the udf itself,13063 // for arg-value type checking must be placed in the body of the udf itself,
13065 // instead of the caller.13064 // instead of the caller.
13066 argVar->set_type(theRTM.ITEM_TYPE_STAR);13065 argVar->set_type(theRTM.ITEM_TYPE_STAR);
13067 lc->set_expr(normalize_fo_arg(i, lc->get_expr(), udf.getp(), loc));13066 lc->set_expr(normalize_fo_arg(i, lc->get_expr(), udf.get(), loc));
1306813067
13069 argVars.push_back(argVar);13068 argVars.push_back(argVar);
13070 }13069 }
@@ -13078,11 +13077,13 @@
13078 // Get the function_item_expr and set its function to the udf created above.13077 // Get the function_item_expr and set its function to the udf created above.
13079 function_item_expr* fiExpr = dynamic_cast<function_item_expr*>(theNodeStack.top());13078 function_item_expr* fiExpr = dynamic_cast<function_item_expr*>(theNodeStack.top());
13080 assert(fiExpr != NULL);13079 assert(fiExpr != NULL);
13081 fiExpr->set_function(udf, udf->numArgs());13080 fiExpr->set_function(udf.get(), udf->numArgs());
1308213081
13083 if (theCCB->theConfig.translate_cb != NULL)13082 if (theCCB->theConfig.translate_cb != NULL)
13084 theCCB->theConfig.translate_cb(udf->getBody(),13083 theCCB->theConfig.translate_cb(udf->getBody(),
13085 udf->getName()->getStringValue().c_str());13084 udf->getName()->getStringValue().c_str());
13085
13086 udf.release();
13086}13087}
1308713088
1308813089
@@ -13510,13 +13511,13 @@
1351013511
13511 if (have_uri)13512 if (have_uri)
13512 {13513 {
13513 if ((ZSTREQ(prefix, "xml") && !ZSTREQ(uri, XML_NS)))13514 if ((ZSTREQ(prefix, "xml") && uri != static_context::W3C_XML_NS))
13514 {13515 {
13515 RAISE_ERROR(err::XQST0070, loc,13516 RAISE_ERROR(err::XQST0070, loc,
13516 ERROR_PARAMS(ZED(XQST0070_ReservedPrefix_23), prefix, uri));13517 ERROR_PARAMS(ZED(XQST0070_ReservedPrefix_23), prefix, uri));
13517 }13518 }
1351813519
13519 if ((ZSTREQ(uri, XML_NS) && !ZSTREQ(prefix, "xml")) ||13520 if ((uri == static_context::W3C_XML_NS && !ZSTREQ(prefix, "xml")) ||
13520 ZSTREQ(uri, XMLNS_NS))13521 ZSTREQ(uri, XMLNS_NS))
13521 {13522 {
13522 RAISE_ERROR(err::XQST0070, loc,13523 RAISE_ERROR(err::XQST0070, loc,
1352313524
=== modified file 'src/compiler/xqddf/collection_decl.cpp'
--- src/compiler/xqddf/collection_decl.cpp 2013-02-07 17:24:36 +0000
+++ src/compiler/xqddf/collection_decl.cpp 2013-07-11 13:41:52 +0000
@@ -34,10 +34,10 @@
3434
35********************************************************************************/35********************************************************************************/
36StaticallyKnownCollection::StaticallyKnownCollection(36StaticallyKnownCollection::StaticallyKnownCollection(
37 store::Item_t& aName,37 store::Item_t& aName,
38 const AnnotationList_t& aAnnotations,38 AnnotationList* aAnnotations,
39 xqtref_t& aNodeType,39 xqtref_t& aNodeType,
40 xqtref_t& aCollectionType,40 xqtref_t& aCollectionType,
41 StaticContextConsts::declaration_property_t aUpdateProperty,41 StaticContextConsts::declaration_property_t aUpdateProperty,
42 StaticContextConsts::declaration_property_t aOrderProperty,42 StaticContextConsts::declaration_property_t aOrderProperty,
43 StaticContextConsts::node_modifier_t aNodeModifier43 StaticContextConsts::node_modifier_t aNodeModifier
@@ -59,6 +59,7 @@
59********************************************************************************/59********************************************************************************/
60StaticallyKnownCollection::~StaticallyKnownCollection() 60StaticallyKnownCollection::~StaticallyKnownCollection()
61{61{
62 delete theAnnotations;
62}63}
6364
6465
6566
=== modified file 'src/compiler/xqddf/collection_decl.h'
--- src/compiler/xqddf/collection_decl.h 2013-02-07 17:24:36 +0000
+++ src/compiler/xqddf/collection_decl.h 2013-07-11 13:41:52 +0000
@@ -33,7 +33,7 @@
33{33{
34private:34private:
35 store::Item_t theName;35 store::Item_t theName;
36 AnnotationList_t theAnnotations;36 AnnotationList * theAnnotations;
37 xqtref_t theNodeType; 37 xqtref_t theNodeType;
38 xqtref_t theCollectionType;38 xqtref_t theCollectionType;
3939
@@ -53,10 +53,10 @@
5353
54public:54public:
55 StaticallyKnownCollection(55 StaticallyKnownCollection(
56 store::Item_t& name,56 store::Item_t& name,
57 const AnnotationList_t& nannotationList,57 AnnotationList* annotationList,
58 xqtref_t& nodeType,58 xqtref_t& nodeType,
59 xqtref_t& collectionType,59 xqtref_t& collectionType,
60 StaticContextConsts::declaration_property_t updateProperty,60 StaticContextConsts::declaration_property_t updateProperty,
61 StaticContextConsts::declaration_property_t orderProperty,61 StaticContextConsts::declaration_property_t orderProperty,
62 StaticContextConsts::node_modifier_t nodeModifier);62 StaticContextConsts::node_modifier_t nodeModifier);
@@ -65,7 +65,7 @@
6565
66 const store::Item* getName() const { return theName.getp(); }66 const store::Item* getName() const { return theName.getp(); }
6767
68 AnnotationList* getAnnotations() const { return theAnnotations.getp(); };68 AnnotationList* getAnnotations() const { return theAnnotations; }
6969
70 StaticContextConsts::declaration_property_t getUpdateProperty() const70 StaticContextConsts::declaration_property_t getUpdateProperty() const
71 {71 {
7272
=== modified file 'src/context/root_static_context.cpp'
--- src/context/root_static_context.cpp 2013-06-09 08:09:40 +0000
+++ src/context/root_static_context.cpp 2013-07-11 13:41:52 +0000
@@ -141,8 +141,8 @@
141 "jn", static_context::JSONIQ_FN_NS,141 "jn", static_context::JSONIQ_FN_NS,
142 "js", static_context::JSONIQ_DM_NS,142 "js", static_context::JSONIQ_DM_NS,
143 "local", XQUERY_LOCAL_FN_NS,143 "local", XQUERY_LOCAL_FN_NS,
144 "xml", XML_NS,144 "xml", static_context::W3C_XML_NS,
145 "xs", XML_SCHEMA_NS,145 "xs", static_context::W3C_XML_SCHEMA_NS,
146 "xsi", XSI_NS,146 "xsi", XSI_NS,
147 NULL, NULL147 NULL, NULL
148 };148 };
@@ -275,5 +275,10 @@
275{275{
276}276}
277277
278
279void root_static_context::free()
280{
281}
282
278}283}
279/* vim:set et sw=2 ts=2: */284/* vim:set et sw=2 ts=2: */
280285
=== modified file 'src/context/root_static_context.h'
--- src/context/root_static_context.h 2013-02-07 17:24:36 +0000
+++ src/context/root_static_context.h 2013-07-11 13:41:52 +0000
@@ -40,6 +40,8 @@
4040
41 void init();41 void init();
4242
43 virtual void free();
44
43 const char** get_builtin_uri_path() const { return theBuiltinURIPath; }45 const char** get_builtin_uri_path() const { return theBuiltinURIPath; }
44 const char** get_builtin_lib_path() const { return theBuiltinLibPath; }46 const char** get_builtin_lib_path() const { return theBuiltinLibPath; }
45};47};
4648
=== modified file 'src/context/static_context.cpp'
--- src/context/static_context.cpp 2013-07-04 22:17:19 +0000
+++ src/context/static_context.cpp 2013-07-11 13:41:52 +0000
@@ -131,12 +131,13 @@
131*******************************************************************************/131*******************************************************************************/
132FunctionInfo::FunctionInfo()132FunctionInfo::FunctionInfo()
133 :133 :
134 theFunction(NULL),
134 theIsDisabled(false)135 theIsDisabled(false)
135{136{
136}137}
137138
138139
139FunctionInfo::FunctionInfo(const function_t& f, bool disabled)140FunctionInfo::FunctionInfo(function* f, bool disabled)
140 :141 :
141 theFunction(f),142 theFunction(f),
142 theIsDisabled(disabled)143 theIsDisabled(disabled)
@@ -324,14 +325,15 @@
324const zstring325const zstring
325static_context::DOT_SIZE_VAR_NAME = "$$context-size";326static_context::DOT_SIZE_VAR_NAME = "$$context-size";
326327
328
327const char*329const char*
328static_context::W3C_NS_PREFIX = "http://www.w3.org/";330static_context::W3C_NS_PREFIX = "http://www.w3.org/";
329331
330const char*332const char*
331static_context::ZORBA_NS_PREFIX = "http://www.zorba-xquery.com/";333static_context::W3C_XML_NS = "http://www.w3.org/XML/1998/namespace";
332334
333const char*335const char*
334static_context::ZORBA_IO_NS_PREFIX = "http://zorba.io/";336static_context::W3C_XML_SCHEMA_NS = "http://www.w3.org/2001/XMLSchema";
335337
336const char*338const char*
337static_context::W3C_FN_NS = "http://www.w3.org/2005/xpath-functions";339static_context::W3C_FN_NS = "http://www.w3.org/2005/xpath-functions";
@@ -340,11 +342,15 @@
340static_context::W3C_ERR_NS = "http://www.w3.org/2005/xqt-errors";342static_context::W3C_ERR_NS = "http://www.w3.org/2005/xqt-errors";
341343
342const char*344const char*
343static_context::W3C_XML_NS = "http://www.w3.org/XML/1998/namespace";
344
345const char*
346static_context::XQUERY_MATH_FN_NS = "http://www.w3.org/2005/xpath-functions/math";345static_context::XQUERY_MATH_FN_NS = "http://www.w3.org/2005/xpath-functions/math";
347346
347
348const char*
349static_context::ZORBA_NS_PREFIX = "http://www.zorba-xquery.com/";
350
351const char*
352static_context::ZORBA_IO_NS_PREFIX = "http://zorba.io/";
353
348const char*354const char*
349static_context::ZORBA_MATH_FN_NS =355static_context::ZORBA_MATH_FN_NS =
350"http://www.zorba-xquery.com/modules/math";356"http://www.zorba-xquery.com/modules/math";
@@ -779,7 +785,7 @@
779 << parent << std::endl;785 << parent << std::endl;
780#endif786#endif
781787
782 if (theParent != NULL)788 if (theParent != NULL && !theParent->is_global_root_sctx())
783 RCHelper::addReference(theParent);789 RCHelper::addReference(theParent);
784}790}
785791
@@ -789,7 +795,7 @@
789********************************************************************************/795********************************************************************************/
790static_context::static_context(::zorba::serialization::Archiver& ar)796static_context::static_context(::zorba::serialization::Archiver& ar)
791 :797 :
792 SimpleRCObject(ar),798 SyncedRCObject(ar),
793 theParent(NULL),799 theParent(NULL),
794 theTraceStream(NULL),800 theTraceStream(NULL),
795 theQueryExpr(NULL),801 theQueryExpr(NULL),
@@ -871,7 +877,9 @@
871 delete theICMap;877 delete theICMap;
872878
873 if (theFunctionMap)879 if (theFunctionMap)
880 {
874 delete theFunctionMap;881 delete theFunctionMap;
882 }
875883
876 if (theFunctionArityMap)884 if (theFunctionArityMap)
877 {885 {
@@ -879,7 +887,8 @@
879 FunctionArityMap::iterator end = theFunctionArityMap->end();887 FunctionArityMap::iterator end = theFunctionArityMap->end();
880 for (; ite != end; ++ite)888 for (; ite != end; ++ite)
881 {889 {
882 delete (*ite).second;890 std::vector<FunctionInfo>* fv = ite.getValue();
891 delete fv;
883 }892 }
884893
885 delete theFunctionArityMap;894 delete theFunctionArityMap;
@@ -926,7 +935,7 @@
926 if (theBaseUriInfo)935 if (theBaseUriInfo)
927 delete theBaseUriInfo;936 delete theBaseUriInfo;
928937
929 if (theParent)938 if (theParent && !theParent->is_global_root_sctx())
930 RCHelper::removeReference(theParent);939 RCHelper::removeReference(theParent);
931}940}
932941
@@ -1062,7 +1071,7 @@
1062 ar & parent_is_root;1071 ar & parent_is_root;
1063 ar.set_is_temp_field(false);1072 ar.set_is_temp_field(false);
10641073
1065 if(!parent_is_root)1074 if (!parent_is_root)
1066 {1075 {
1067 ar.dont_allow_delay();1076 ar.dont_allow_delay();
1068 ar & theParent;1077 ar & theParent;
@@ -1081,15 +1090,16 @@
1081 ar & parent_is_root;1090 ar & parent_is_root;
1082 ar.set_is_temp_field(false);1091 ar.set_is_temp_field(false);
10831092
1084 if(parent_is_root)1093 if (parent_is_root)
1085 {1094 {
1086 set_parent_as_root();1095 theParent = &GENV_ROOT_STATIC_CONTEXT;
1087 }1096 }
1088 else1097 else
1098 {
1089 ar & theParent;1099 ar & theParent;
10901100 ZORBA_ASSERT(theParent);
1091 if (theParent)1101 theParent->addReference();
1092 theParent->addReference(SYNC_CODE(theParent->getRCLock()));1102 }
1093 }1103 }
10941104
1095 ar & theModuleNamespace;1105 ar & theModuleNamespace;
@@ -1198,15 +1208,6 @@
1198/***************************************************************************//**1208/***************************************************************************//**
11991209
1200********************************************************************************/1210********************************************************************************/
1201void static_context::set_parent_as_root()
1202{
1203 theParent = &GENV_ROOT_STATIC_CONTEXT;
1204}
1205
1206
1207/***************************************************************************//**
1208
1209********************************************************************************/
1210expr* static_context::get_query_expr() const1211expr* static_context::get_query_expr() const
1211{1212{
1212 return theQueryExpr;1213 return theQueryExpr;
@@ -1891,7 +1892,7 @@
1891 store::Item_t& validatedResult,1892 store::Item_t& validatedResult,
1892 StaticContextConsts::validation_mode_t validationMode) const1893 StaticContextConsts::validation_mode_t validationMode) const
1893{1894{
1894 zstring xsTns(XML_SCHEMA_NS);1895 zstring xsTns(static_context::W3C_XML_SCHEMA_NS);
1895 return validate(rootElement, validatedResult, xsTns, validationMode);1896 return validate(rootElement, validatedResult, xsTns, validationMode);
1896}1897}
18971898
@@ -2456,7 +2457,7 @@
24562457
2457********************************************************************************/2458********************************************************************************/
2458void static_context::bind_fn(2459void static_context::bind_fn(
2459 function_t& f,2460 const function_t& f,
2460 csize arity,2461 csize arity,
2461 const QueryLoc& loc)2462 const QueryLoc& loc)
2462{2463{
@@ -2473,17 +2474,18 @@
2473 theFunctionMap = new FunctionMap(HashMapItemPointerCmp(0, NULL), size, false);2474 theFunctionMap = new FunctionMap(HashMapItemPointerCmp(0, NULL), size, false);
2474 }2475 }
24752476
2476 FunctionInfo fi(f);2477 FunctionInfo fi(f.getp());
24772478
2478 if (!theFunctionMap->insert(qname, fi))2479 if (!theFunctionMap->insert(qname, fi))
2479 {2480 {
2480 // There is already a function F with the given qname in theFunctionMap.2481 // There is already a function F with the given qname in theFunctionMap.
2481 // First, check if F is the same as f, which implies that f is disabled.2482 // First, check if F is the same as f, which implies that f is disabled.
2482 // In this case, re-enable f. Otherwise, we have to use theFunctionArityMap.2483 // In this case, re-enable f. Otherwise, we have to use theFunctionArityMap.
2483 if (fi.theFunction == f)2484 if (fi.theFunction.getp() == f)
2484 {2485 {
2485 ZORBA_ASSERT(fi.theIsDisabled);2486 ZORBA_ASSERT(fi.theIsDisabled);
2486 fi.theIsDisabled = false;2487 fi.theIsDisabled = false;
2488 theFunctionMap->update(qname, fi);
2487 return;2489 return;
2488 }2490 }
24892491
@@ -2505,7 +2507,7 @@
2505 csize numFunctions = fv->size();2507 csize numFunctions = fv->size();
2506 for (csize i = 0; i < numFunctions; ++i)2508 for (csize i = 0; i < numFunctions; ++i)
2507 {2509 {
2508 if ((*fv)[i].theFunction == f)2510 if ((*fv)[i].theFunction.getp() == f)
2509 {2511 {
2510 ZORBA_ASSERT((*fv)[i].theIsDisabled);2512 ZORBA_ASSERT((*fv)[i].theIsDisabled);
2511 (*fv)[i].theIsDisabled = false;2513 (*fv)[i].theIsDisabled = false;
@@ -2671,7 +2673,7 @@
2671 {2673 {
2672 if (sctx->theFunctionMap != NULL && sctx->theFunctionMap->get(qname2, fi))2674 if (sctx->theFunctionMap != NULL && sctx->theFunctionMap->get(qname2, fi))
2673 {2675 {
2674 function* f = fi.theFunction.getp();2676 function* f = fi.theFunction;
26752677
2676 if (f->getArity() == arity || f->isVariadic())2678 if (f->getArity() == arity || f->isVariadic())
2677 {2679 {
@@ -2694,7 +2696,7 @@
2694 if ((*fv)[i].theIsDisabled && skipDisabled)2696 if ((*fv)[i].theIsDisabled && skipDisabled)
2695 return NULL;2697 return NULL;
26962698
2697 return (*fv)[i].theFunction.getp();2699 return (*fv)[i].theFunction;
2698 }2700 }
2699 }2701 }
2700 }2702 }
@@ -2722,7 +2724,7 @@
27222724
2723 if (theFunctionMap != NULL && theFunctionMap->get(qname2, fi))2725 if (theFunctionMap != NULL && theFunctionMap->get(qname2, fi))
2724 {2726 {
2725 function* f = fi.theFunction.getp();2727 function* f = fi.theFunction;
27262728
2727 if (f->getArity() == arity || f->isVariadic())2729 if (f->getArity() == arity || f->isVariadic())
2728 {2730 {
@@ -2744,7 +2746,7 @@
2744 if ((*fv)[i].theIsDisabled && skipDisabled)2746 if ((*fv)[i].theIsDisabled && skipDisabled)
2745 return NULL;2747 return NULL;
27462748
2747 return (*fv)[i].theFunction.getp();2749 return (*fv)[i].theFunction;
2748 }2750 }
2749 }2751 }
2750 }2752 }
@@ -2784,7 +2786,7 @@
27842786
2785 for (; ite != end; ++ite)2787 for (; ite != end; ++ite)
2786 {2788 {
2787 function* f = (*ite).second.theFunction.getp();2789 function* f = (*ite).second.theFunction;
27882790
2789 if (!(*ite).second.theIsDisabled)2791 if (!(*ite).second.theIsDisabled)
2790 {2792 {
@@ -2842,10 +2844,10 @@
2842 {2844 {
2843 std::vector<FunctionInfo>* fv = (*ite).second;2845 std::vector<FunctionInfo>* fv = (*ite).second;
28442846
2845 ulong numFunctions = (ulong)fv->size();2847 csize numFunctions = fv->size();
2846 for (ulong i = 0; i < numFunctions; ++i)2848 for (csize i = 0; i < numFunctions; ++i)
2847 {2849 {
2848 function* f = (*fv)[i].theFunction.getp();2850 function* f = (*fv)[i].theFunction;
28492851
2850 if (!(*fv)[i].theIsDisabled)2852 if (!(*fv)[i].theIsDisabled)
2851 {2853 {
@@ -2909,7 +2911,7 @@
2909 if (theFunctionMap != NULL && theFunctionMap->get(qname2, fi))2911 if (theFunctionMap != NULL && theFunctionMap->get(qname2, fi))
2910 {2912 {
2911 if (!fi.theIsDisabled)2913 if (!fi.theIsDisabled)
2912 functions.push_back(fi.theFunction.getp());2914 functions.push_back(fi.theFunction);
2913 }2915 }
29142916
2915 std::vector<FunctionInfo>* fv = NULL;2917 std::vector<FunctionInfo>* fv = NULL;
@@ -2920,7 +2922,7 @@
2920 for (ulong i = 0; i < numFunctions; ++i)2922 for (ulong i = 0; i < numFunctions; ++i)
2921 {2923 {
2922 if (!(*fv)[i].theIsDisabled)2924 if (!(*fv)[i].theIsDisabled)
2923 functions.push_back((*fv)[i].theFunction.getp());2925 functions.push_back((*fv)[i].theFunction);
2924 }2926 }
2925 }2927 }
29262928
@@ -3217,11 +3219,8 @@
32173219
3218 if (lookup_index(qname) != NULL)3220 if (lookup_index(qname) != NULL)
3219 {3221 {
3220 throw XQUERY_EXCEPTION(3222 RAISE_ERROR(zerr::ZDST0021_INDEX_ALREADY_DECLARED, loc,
3221 zerr::ZDST0021_INDEX_ALREADY_DECLARED,3223 ERROR_PARAMS(qname->getStringValue()));
3222 ERROR_PARAMS( qname->getStringValue() ),
3223 ERROR_LOC( loc )
3224 );
3225 }3224 }
32263225
3227 if (theIndexMap == NULL)3226 if (theIndexMap == NULL)
@@ -4354,7 +4353,7 @@
4354 FunctionMap::iterator end = module->theFunctionMap->end();4353 FunctionMap::iterator end = module->theFunctionMap->end();
4355 for (; ite != end; ++ite)4354 for (; ite != end; ++ite)
4356 {4355 {
4357 function_t f = (*ite).second.theFunction;4356 function* f = (*ite).second.theFunction;
4358 if (!f->isPrivate())4357 if (!f->isPrivate())
4359 bind_fn(f, f->getArity(), loc);4358 bind_fn(f, f->getArity(), loc);
4360 }4359 }
@@ -4378,7 +4377,7 @@
4378 csize num = fv->size();4377 csize num = fv->size();
4379 for (csize i = 0; i < num; ++i)4378 for (csize i = 0; i < num; ++i)
4380 {4379 {
4381 function_t f = (*fv)[i].theFunction;4380 function* f = (*fv)[i].theFunction;
4382 bind_fn(f, f->getArity(), loc);4381 bind_fn(f, f->getArity(), loc);
4383 }4382 }
4384 }4383 }
43854384
=== modified file 'src/context/static_context.h'
--- src/context/static_context.h 2013-06-26 00:26:58 +0000
+++ src/context/static_context.h 2013-07-11 13:41:52 +0000
@@ -145,7 +145,7 @@
145public:145public:
146 FunctionInfo();146 FunctionInfo();
147147
148 FunctionInfo(const function_t& f, bool disabled = false);148 FunctionInfo(function* f, bool disabled = false);
149149
150 ~FunctionInfo();150 ~FunctionInfo();
151};151};
@@ -287,7 +287,8 @@
287287
288 theParent :288 theParent :
289 -----------289 -----------
290 Pointer to the parent sctx object in the sctx hierarchy.290 Pointer to the parent sctx object in the sctx hierarchy. Manual ref counting
291 is done via this pointer on the parent, unless the parent is the root sctx.
291292
292 theTraceStream :293 theTraceStream :
293 ----------------294 ----------------
@@ -442,7 +443,7 @@
442 context/featueres.h.443 context/featueres.h.
443********************************************************************************/444********************************************************************************/
444445
445class static_context : public SimpleRCObject446class static_context : public SyncedRCObject
446{447{
447 ITEM_PTR_HASH_MAP(StaticallyKnownCollection_t, CollectionMap);448 ITEM_PTR_HASH_MAP(StaticallyKnownCollection_t, CollectionMap);
448449
@@ -499,6 +500,8 @@
499500
500 static const char* W3C_XML_NS; // http://www.w3.org/XML/1998/namespace501 static const char* W3C_XML_NS; // http://www.w3.org/XML/1998/namespace
501502
503 static const char* W3C_XML_SCHEMA_NS; // // http://www.w3.org/2001/XMLSchema
504
502 static const char* W3C_FN_NS; // http://www.w3.org/2005/xpath-functions505 static const char* W3C_FN_NS; // http://www.w3.org/2005/xpath-functions
503 506
504 static const char* W3C_ERR_NS; // http://www.w3.org/2005/xqt-errors507 static const char* W3C_ERR_NS; // http://www.w3.org/2005/xqt-errors
@@ -569,11 +572,14 @@
569 static const char* ZORBA_OPTION_WARN_NS;572 static const char* ZORBA_OPTION_WARN_NS;
570 static const char* ZORBA_OPTION_FEATURE_NS;573 static const char* ZORBA_OPTION_FEATURE_NS;
571 static const char* ZORBA_OPTION_OPTIM_NS;574 static const char* ZORBA_OPTION_OPTIM_NS;
575
572 static const char* XQUERY_NS; // http://www.w3.org/2012/xquery576 static const char* XQUERY_NS; // http://www.w3.org/2012/xquery
573 static const char* XQUERY_OPTION_NS; // http://www.w3.org/2011/xquery-options577 static const char* XQUERY_OPTION_NS; // http://www.w3.org/2011/xquery-options
574 static const char* ZORBA_VERSIONING_NS;578 static const char* ZORBA_VERSIONING_NS;
575579
576protected:580protected:
581 SYNC_CODE(mutable RCLock theRCLock;)
582
577 static_context * theParent;583 static_context * theParent;
578584
579 std::ostream * theTraceStream;585 std::ostream * theTraceStream;
@@ -696,6 +702,8 @@
696702
697 ~static_context();703 ~static_context();
698704
705 SYNC_CODE(RCLock* getRCLock() const { return &theRCLock; })
706
699 static_context* get_parent() const { return theParent; }707 static_context* get_parent() const { return theParent; }
700708
701 static_context* create_child_context();709 static_context* create_child_context();
@@ -901,7 +909,7 @@
901 //909 //
902 // Functions910 // Functions
903 //911 //
904 void bind_fn(function_t& f, csize arity, const QueryLoc& loc);912 void bind_fn(const function_t& f, csize arity, const QueryLoc& loc);
905913
906 void unbind_fn(const store::Item* qname, csize arity);914 void unbind_fn(const store::Item* qname, csize arity);
907915
@@ -929,8 +937,8 @@
929 std::vector<function*>& functions) const;937 std::vector<function*>& functions) const;
930938
931 void bind_external_module(939 void bind_external_module(
932 ExternalModule* aModule,940 ExternalModule* module,
933 bool aDynamicallyLoaded = false);941 bool dynamicallyLoaded = false);
934942
935 ExternalFunction* lookup_external_function(943 ExternalFunction* lookup_external_function(
936 const zstring& prefix,944 const zstring& prefix,
@@ -1152,8 +1160,6 @@
1152 //serialization helpers1160 //serialization helpers
1153 bool check_parent_is_root();1161 bool check_parent_is_root();
11541162
1155 void set_parent_as_root();
1156
1157private:1163private:
11581164
1159 void apply_uri_mappers(1165 void apply_uri_mappers(
11601166
=== modified file 'src/functions/external_function.cpp'
--- src/functions/external_function.cpp 2013-02-07 17:24:36 +0000
+++ src/functions/external_function.cpp 2013-07-11 13:41:52 +0000
@@ -43,13 +43,12 @@
43 unsigned short scriptingType,43 unsigned short scriptingType,
44 ExternalFunction* impl) 44 ExternalFunction* impl)
45 :45 :
46 function(sig, FunctionConsts::FN_UNKNOWN),46 function(sig, FunctionConsts::FN_UNKNOWN, false),
47 theLoc(loc),47 theLoc(loc),
48 theNamespace(ns),48 theNamespace(ns),
49 theScriptingKind(scriptingType),49 theScriptingKind(scriptingType),
50 theImpl(impl)50 theImpl(impl)
51{51{
52 resetFlag(FunctionConsts::isBuiltin);
53 theModuleSctx = modSctx;52 theModuleSctx = modSctx;
54}53}
5554
5655
=== modified file 'src/functions/function.cpp'
--- src/functions/function.cpp 2013-04-15 13:52:08 +0000
+++ src/functions/function.cpp 2013-07-11 13:41:52 +0000
@@ -34,39 +34,42 @@
34namespace zorba {34namespace zorba {
3535
3636
37#ifdef PRE_SERIALIZE_BUILTIN_FUNCTIONS
38SERIALIZE_INTERNAL_METHOD(function)
39#else
40SERIALIZABLE_CLASS_VERSIONS(function);37SERIALIZABLE_CLASS_VERSIONS(function);
41#endif
4238
4339
44/*******************************************************************************40/*******************************************************************************
4541
46********************************************************************************/42********************************************************************************/
47function::function(const signature& sig, FunctionConsts::FunctionKind kind)43function::function(
44 const signature& sig,
45 FunctionConsts::FunctionKind kind,
46 bool isBuiltin)
48 :47 :
49 theSignature(sig),48 theSignature(sig),
50 theKind(kind),49 theKind(kind),
51 theFlags(0),50 theFlags(0),
51 theAnnotationList(NULL),
52 theModuleSctx(NULL),52 theModuleSctx(NULL),
53 theXQueryVersion(StaticContextConsts::xquery_version_1_0)53 theXQueryVersion(StaticContextConsts::xquery_version_1_0)
54{54{
55 setFlag(FunctionConsts::isBuiltin);55 if (isBuiltin)
56 {
57 setFlag(FunctionConsts::isBuiltin);
58#ifndef NDEBUG
59 theRefCount = 1000000;
60#endif
61 }
62
56 setFlag(FunctionConsts::isDeterministic);63 setFlag(FunctionConsts::isDeterministic);
5764}
58#ifdef PRE_SERIALIZE_BUILTIN_FUNCTIONS65
59 zorba::serialization::Archiver& ar =66
60 *::zorba::serialization::ClassSerializer::getInstance()->67/*******************************************************************************
61 getArchiverForHardcodedObjects();68
6269********************************************************************************/
63 if (ar.is_loading_hardcoded_objects())70function::~function()
64 {71{
65 // register this hardcoded object to help plan serialization72 delete theAnnotationList;
66 function* this_ptr = this;
67 ar & this_ptr;
68 }
69#endif
70}73}
7174
7275
@@ -75,11 +78,6 @@
75********************************************************************************/78********************************************************************************/
76void function::serialize(::zorba::serialization::Archiver& ar)79void function::serialize(::zorba::serialization::Archiver& ar)
77{80{
78#ifdef PRE_SERIALIZE_BUILTIN_FUNCTIONS
79 if (ar.is_loading_hardcoded_objects())
80 return;
81#endif
82
83 ar & theSignature;81 ar & theSignature;
84 SERIALIZE_ENUM(FunctionConsts::FunctionKind, theKind);82 SERIALIZE_ENUM(FunctionConsts::FunctionKind, theKind);
85 ar & theFlags;83 ar & theFlags;
@@ -87,13 +85,19 @@
87 ar & theModuleSctx;85 ar & theModuleSctx;
88 SERIALIZE_ENUM(StaticContextConsts::xquery_version_t, theXQueryVersion);86 SERIALIZE_ENUM(StaticContextConsts::xquery_version_t, theXQueryVersion);
8987
90 // If we don't pre-serialize builtin function, it is possible that a builtin88 // It is possible that a builtin function needs to be serialized. This happens
91 // functions needs to be serialized. This happens for builtin functions that89 // for builtin functions that are disabled, and as a result, have been
92 // are disabled, and as a result, have been registered in a non-root static90 // registered in a non-root static context.
93 // context.91}
94#ifdef PRE_SERIALIZE_BUILTIN_FUNCTIONS92
95 ZORBA_ASSERT(!isBuiltin());93
96#endif94/*******************************************************************************
95
96********************************************************************************/
97void function::free()
98{
99 if (!isBuiltin())
100 delete this;
97}101}
98102
99103
100104
=== modified file 'src/functions/function.h'
--- src/functions/function.h 2013-04-15 13:52:08 +0000
+++ src/functions/function.h 2013-07-11 13:41:52 +0000
@@ -54,25 +54,23 @@
54 signature theSignature;54 signature theSignature;
55 FunctionConsts::FunctionKind theKind;55 FunctionConsts::FunctionKind theKind;
56 uint32_t theFlags;56 uint32_t theFlags;
57 AnnotationList_t theAnnotationList;57 AnnotationList * theAnnotationList;
58 static_context * theModuleSctx;58 static_context * theModuleSctx;
5959
60 StaticContextConsts::xquery_version_t theXQueryVersion;60 StaticContextConsts::xquery_version_t theXQueryVersion;
6161
6262
63public:63public:
64#ifdef PRE_SERIALIZE_BUILTIN_FUNCTIONS
65 SERIALIZABLE_ABSTRACT_CLASS(function);
66#else
67 SERIALIZABLE_CLASS(function);64 SERIALIZABLE_CLASS(function);
68#endif
69 SERIALIZABLE_CLASS_CONSTRUCTOR3(function, SimpleRCObject, theSignature);65 SERIALIZABLE_CLASS_CONSTRUCTOR3(function, SimpleRCObject, theSignature);
70 void serialize(::zorba::serialization::Archiver& ar);66 void serialize(::zorba::serialization::Archiver& ar);
7167
72public:68public:
73 function(const signature& sig, FunctionConsts::FunctionKind kind);69 function(const signature& sig, FunctionConsts::FunctionKind k, bool isBuiltin = true);
7470
75 virtual ~function() {}71 virtual ~function();
72
73 void free();
7674
77 StaticContextConsts::xquery_version_t getXQueryVersion() const75 StaticContextConsts::xquery_version_t getXQueryVersion() const
78 {76 {
@@ -164,7 +162,7 @@
164162
165 void setAnnotations(AnnotationList* annotations);163 void setAnnotations(AnnotationList* annotations);
166164
167 const AnnotationList* getAnnotationList() const { return theAnnotationList.getp(); }165 const AnnotationList* getAnnotationList() const { return theAnnotationList; }
168166
169 bool validate_args(std::vector<PlanIter_t>& argv) const;167 bool validate_args(std::vector<PlanIter_t>& argv) const;
170168
171169
=== modified file 'src/functions/function_impl.h'
--- src/functions/function_impl.h 2013-02-07 17:24:36 +0000
+++ src/functions/function_impl.h 2013-07-11 13:41:52 +0000
@@ -44,23 +44,23 @@
44#define DECL_WITH_KIND(sctx, type, sig, kind) \44#define DECL_WITH_KIND(sctx, type, sig, kind) \
45 do \45 do \
46 { \46 { \
47 function_t type##_ptr(new type(signature sig, kind)); \47 function* type##_ptr = new type(signature sig, kind); \
48 const store::Item* fname = type##_ptr->getName(); \48 const store::Item* fname = type##_ptr->getName(); \
49 ulong cnt = type##_ptr->getSignature().paramCount(); \49 ulong cnt = type##_ptr->getSignature().paramCount(); \
50 DEBUG_FN_DECL(fname, cnt); \50 DEBUG_FN_DECL(fname, cnt); \
51 sctx->bind_fn(type##_ptr, cnt, QueryLoc::null); \51 sctx->bind_fn(type##_ptr, cnt, QueryLoc::null); \
52 BuiltinFunctionLibrary::theFunctions[type##_ptr->getKind()] = type##_ptr.getp(); \52 GENV_FUNC_LIB->addFunction(type##_ptr->getKind(), type##_ptr); \
53 } while(0)53 } while(0)
5454
55#define DECL(sctx, type, sig) \55#define DECL(sctx, type, sig) \
56 do \56 do \
57 { \57 { \
58 function_t type##_ptr(new type(signature sig)); \58 function* type##_ptr = new type(signature sig); \
59 const store::Item* fname = type##_ptr->getName(); \59 const store::Item* fname = type##_ptr->getName(); \
60 ulong cnt = type##_ptr->getSignature().paramCount(); \60 ulong cnt = type##_ptr->getSignature().paramCount(); \
61 DEBUG_FN_DECL(fname, cnt); \61 DEBUG_FN_DECL(fname, cnt); \
62 sctx->bind_fn(type##_ptr, cnt, QueryLoc::null); \62 sctx->bind_fn(type##_ptr, cnt, QueryLoc::null); \
63 BuiltinFunctionLibrary::theFunctions[type##_ptr->getKind()] = type##_ptr.getp(); \63 GENV_FUNC_LIB->addFunction(type##_ptr->getKind(), type##_ptr); \
64 } while(0)64 } while(0)
6565
6666
6767
=== modified file 'src/functions/library.cpp'
--- src/functions/library.cpp 2013-06-27 00:05:25 +0000
+++ src/functions/library.cpp 2013-07-11 13:41:52 +0000
@@ -91,8 +91,6 @@
91namespace zorba91namespace zorba
92{92{
9393
94function** BuiltinFunctionLibrary::theFunctions = NULL;
95
96// clear static initializer state94// clear static initializer state
9795
98// dummy function to tell the windows linker to keep the library.obj96// dummy function to tell the windows linker to keep the library.obj
@@ -103,16 +101,16 @@
103}101}
104102
105103
106void BuiltinFunctionLibrary::create(static_context* sctx)104BuiltinFunctionLibrary::BuiltinFunctionLibrary()
107{105{
108#ifdef PRE_SERIALIZE_BUILTIN_FUNCTIONS
109 zorba::serialization::Archiver& ar = *::zorba::serialization::ClassSerializer::getInstance()->getArchiverForHardcodedObjects();
110
111 ar.set_loading_hardcoded_objects(true);
112#endif
113
114 theFunctions = new function*[FunctionConsts::FN_MAX_FUNC];106 theFunctions = new function*[FunctionConsts::FN_MAX_FUNC];
115107
108 memset(&theFunctions[0], 0, FunctionConsts::FN_MAX_FUNC * sizeof(function*));
109}
110
111
112void BuiltinFunctionLibrary::populate(static_context* sctx)
113{
116 populate_context_accessors(sctx);114 populate_context_accessors(sctx);
117 populate_context_any_uri(sctx);115 populate_context_any_uri(sctx);
118 populate_context_accessors_impl(sctx);116 populate_context_accessors_impl(sctx);
@@ -180,8 +178,13 @@
180}178}
181179
182180
183void BuiltinFunctionLibrary::destroy()181BuiltinFunctionLibrary::~BuiltinFunctionLibrary()
184{182{
183 for (csize i = 0; i < FunctionConsts::FN_MAX_FUNC; ++i)
184 {
185 delete theFunctions[i];
186 }
187
185 delete [] theFunctions;188 delete [] theFunctions;
186}189}
187190
188191
=== modified file 'src/functions/library.h'
--- src/functions/library.h 2013-02-07 17:24:36 +0000
+++ src/functions/library.h 2013-07-11 13:41:52 +0000
@@ -32,24 +32,30 @@
32 friend class GlobalEnvironment;32 friend class GlobalEnvironment;
3333
34public:34public:
35 static function ** theFunctions;35 function ** theFunctions;
3636
37public:37public:
38 static function* getFunction(FunctionConsts::FunctionKind kind)38 BuiltinFunctionLibrary();
39
40 ~BuiltinFunctionLibrary();
41
42 void populate(static_context* sctx);
43
44 function* getFunction(FunctionConsts::FunctionKind kind)
39 {45 {
40 return theFunctions[kind];46 return theFunctions[kind];
41 }47 }
4248
43private:49 void addFunction(FunctionConsts::FunctionKind kind, function* f)
44 static void create(static_context* sctx);50 {
4551 theFunctions[kind] = f;
46 static void destroy();52 }
47};53};
4854
4955
5056
51#define BUILTIN_FUNC(func_code) \57#define BUILTIN_FUNC(func_code) \
52BuiltinFunctionLibrary::getFunction(FunctionConsts::func_code)58GENV_FUNC_LIB->getFunction(FunctionConsts::func_code)
5359
5460
55}61}
5662
=== modified file 'src/functions/udf.cpp'
--- src/functions/udf.cpp 2013-06-15 21:18:01 +0000
+++ src/functions/udf.cpp 2013-07-11 13:41:52 +0000
@@ -62,7 +62,7 @@
62 unsigned short scriptingKind,62 unsigned short scriptingKind,
63 CompilerCB* ccb)63 CompilerCB* ccb)
64 :64 :
65 function(sig, FunctionConsts::FN_UNKNOWN),65function(sig, FunctionConsts::FN_UNKNOWN, false),
66 theCCB(ccb),66 theCCB(ccb),
67 theLoc(loc),67 theLoc(loc),
68 theScriptingKind(scriptingKind),68 theScriptingKind(scriptingKind),
@@ -76,8 +76,6 @@
76 theCacheComputed(false)76 theCacheComputed(false)
77{77{
78 setFlag(FunctionConsts::isUDF);78 setFlag(FunctionConsts::isUDF);
79 resetFlag(FunctionConsts::isBuiltin);
80 setDeterministic(true);
81 setPrivate(false);79 setPrivate(false);
82}80}
8381
8482
=== modified file 'src/runtime/full_text/ft_util.cpp'
--- src/runtime/full_text/ft_util.cpp 2013-06-11 23:38:49 +0000
+++ src/runtime/full_text/ft_util.cpp 2013-07-11 13:41:52 +0000
@@ -19,13 +19,16 @@
19#include <stdexcept>19#include <stdexcept>
2020
21#include "diagnostics/xquery_diagnostics.h"21#include "diagnostics/xquery_diagnostics.h"
22
22#include "util/locale.h"23#include "util/locale.h"
23#include "zorbamisc/ns_consts.h"24
24#include "zorbatypes/integer.h"25#include "zorbatypes/integer.h"
25#include "zorbatypes/numconversions.h"26#include "zorbatypes/numconversions.h"
2627
27#include "ft_util.h"28#include "ft_util.h"
2829
30#include "context/static_context.h"
31
29using namespace zorba::locale;32using namespace zorba::locale;
3033
31namespace zorba {34namespace zorba {
@@ -41,7 +44,7 @@
41 store::Item const *const qname = attr->getNodeName();44 store::Item const *const qname = attr->getNodeName();
42 if ( qname &&45 if ( qname &&
43 qname->getLocalName() == "lang" &&46 qname->getLocalName() == "lang" &&
44 qname->getNamespace() == XML_NS ) {47 qname->getNamespace() == static_context::W3C_XML_NS ) {
45 *lang = locale::find_lang( attr->getStringValue() );48 *lang = locale::find_lang( attr->getStringValue() );
46 found_lang = true;49 found_lang = true;
47 break;50 break;
4851
=== modified file 'src/runtime/hof/fn_hof_functions_impl.cpp'
--- src/runtime/hof/fn_hof_functions_impl.cpp 2013-06-04 21:47:40 +0000
+++ src/runtime/hof/fn_hof_functions_impl.cpp 2013-07-11 13:41:52 +0000
@@ -163,7 +163,7 @@
163 Translator::translate_literal_function(qname, arity, ccb, impSctx, loc);163 Translator::translate_literal_function(qname, arity, ccb, impSctx, loc);
164 164
165 FunctionItemInfo_t fiInfo =165 FunctionItemInfo_t fiInfo =
166 static_cast<function_item_expr*>(fiExpr)->get_dynamic_fn_info();166 static_cast<function_item_expr*>(fiExpr)->get_fi_info();
167167
168 fiInfo->theCCB = ccb;168 fiInfo->theCCB = ccb;
169169
170170
=== modified file 'src/runtime/hof/function_item.cpp'
--- src/runtime/hof/function_item.cpp 2013-04-24 01:35:58 +0000
+++ src/runtime/hof/function_item.cpp 2013-07-11 13:41:52 +0000
@@ -141,7 +141,7 @@
141 if (ar.is_serializing_out())141 if (ar.is_serializing_out())
142 {142 {
143 uint32_t planStateSize;143 uint32_t planStateSize;
144 (void)static_cast<user_function*>(theFunction.getp())->getPlan(planStateSize, 1);144 (void)static_cast<user_function*>(theFunction)->getPlan(planStateSize, 1);
145 }145 }
146}146}
147147
@@ -158,15 +158,6 @@
158}158}
159159
160160
161/*******************************************************************************
162
163********************************************************************************/
164FunctionItem::FunctionItem(::zorba::serialization::Archiver& ar)
165 :
166 store::Item(store::Item::FUNCTION)
167{
168}
169
170////////////////////////////////////////////////////////////////////////////////161////////////////////////////////////////////////////////////////////////////////
171// //162// //
172// FunctionItem //163// FunctionItem //
@@ -202,6 +193,16 @@
202/*******************************************************************************193/*******************************************************************************
203194
204********************************************************************************/195********************************************************************************/
196FunctionItem::FunctionItem(::zorba::serialization::Archiver& ar)
197 :
198 store::Item(store::Item::FUNCTION)
199{
200}
201
202
203/*******************************************************************************
204
205********************************************************************************/
205FunctionItem::~FunctionItem()206FunctionItem::~FunctionItem()
206{207{
207#if 0208#if 0
208209
=== modified file 'src/runtime/hof/function_item.h'
--- src/runtime/hof/function_item.h 2013-04-24 01:35:58 +0000
+++ src/runtime/hof/function_item.h 2013-07-11 13:41:52 +0000
@@ -112,7 +112,7 @@
112112
113 static_context * theClosureSctx;113 static_context * theClosureSctx;
114114
115 function_t theFunction;115 function * theFunction;
116116
117 store::Item_t theQName;117 store::Item_t theQName;
118118
119119
=== modified file 'src/runtime/nodes/nodes_impl.cpp'
--- src/runtime/nodes/nodes_impl.cpp 2013-05-06 22:57:08 +0000
+++ src/runtime/nodes/nodes_impl.cpp 2013-07-11 13:41:52 +0000
@@ -236,7 +236,7 @@
236 store::Item* lAttrName = aAttr->getNodeName();236 store::Item* lAttrName = aAttr->getNodeName();
237237
238 return (ZSTREQ(lAttrName->getLocalName(), "lang") &&238 return (ZSTREQ(lAttrName->getLocalName(), "lang") &&
239 ZSTREQ(lAttrName->getNamespace(), XML_NS));239 lAttrName->getNamespace() == static_context::W3C_XML_NS);
240}240}
241241
242242
243243
=== modified file 'src/runtime/strings/strings_impl.cpp'
--- src/runtime/strings/strings_impl.cpp 2013-06-10 22:49:36 +0000
+++ src/runtime/strings/strings_impl.cpp 2013-07-11 13:41:52 +0000
@@ -1839,7 +1839,7 @@
1839 store::NsBindings ns_binding;1839 store::NsBindings ns_binding;
1840 zstring baseURI;1840 zstring baseURI;
1841 GENV_ITEMFACTORY->createQName(untyped_type_name,1841 GENV_ITEMFACTORY->createQName(untyped_type_name,
1842 XML_SCHEMA_NS, XML_SCHEMA_PREFIX, "untyped");1842 static_context::W3C_XML_SCHEMA_NS, "", "untyped");
1843 GENV_ITEMFACTORY->createQName(non_match_element_name,1843 GENV_ITEMFACTORY->createQName(non_match_element_name,
1844 static_context::W3C_FN_NS, "fn", "non-match");1844 static_context::W3C_FN_NS, "fn", "non-match");
1845 GENV_ITEMFACTORY->createElementNode(non_match_elem, parent, non_match_element_name, untyped_type_name, false, false, ns_binding, baseURI);1845 GENV_ITEMFACTORY->createElementNode(non_match_elem, parent, non_match_element_name, untyped_type_name, false, false, ns_binding, baseURI);
@@ -1968,7 +1968,7 @@
1968 store::NsBindings ns_binding;1968 store::NsBindings ns_binding;
1969 zstring baseURI;1969 zstring baseURI;
1970 GENV_ITEMFACTORY->createQName(untyped_type_name,1970 GENV_ITEMFACTORY->createQName(untyped_type_name,
1971 XML_SCHEMA_NS, XML_SCHEMA_PREFIX, "untyped");1971 static_context::W3C_XML_SCHEMA_NS, "", "untyped");
1972 GENV_ITEMFACTORY->createQName(match_element_name,1972 GENV_ITEMFACTORY->createQName(match_element_name,
1973 static_context::W3C_FN_NS, "fn", "match");1973 static_context::W3C_FN_NS, "fn", "match");
1974 store::Item_t match_elem;1974 store::Item_t match_elem;
@@ -2125,7 +2125,7 @@
2125 store::NsBindings ns_binding;2125 store::NsBindings ns_binding;
2126 zstring baseURI;2126 zstring baseURI;
2127 GENV_ITEMFACTORY->createQName(untyped_type_name,2127 GENV_ITEMFACTORY->createQName(untyped_type_name,
2128 XML_SCHEMA_NS, XML_SCHEMA_PREFIX, "untyped");2128 static_context::W3C_XML_SCHEMA_NS, "", "untyped");
2129 GENV_ITEMFACTORY->createQName(result_element_name,2129 GENV_ITEMFACTORY->createQName(result_element_name,
2130 static_context::W3C_FN_NS, "fn", "analyze-string-result");2130 static_context::W3C_FN_NS, "fn", "analyze-string-result");
2131 GENV_ITEMFACTORY->createElementNode(result, NULL, result_element_name, untyped_type_name, false, false, ns_binding, baseURI);2131 GENV_ITEMFACTORY->createElementNode(result, NULL, result_element_name, untyped_type_name, false, false, ns_binding, baseURI);
21322132
=== modified file 'src/store/api/annotation.h'
--- src/store/api/annotation.h 2013-02-07 17:24:36 +0000
+++ src/store/api/annotation.h 2013-07-11 13:41:52 +0000
@@ -24,20 +24,13 @@
24namespace zorba { namespace store {24namespace zorba { namespace store {
2525
2626
27class Annotation : public RCObject27class Annotation : public SyncedRCObject
28{28{
29protected:
30 SYNC_CODE(mutable RCLock theRCLock;)
31
32public:29public:
33 Item_t theName;30 Item_t theName;
34 std::vector<Item_t> theLiterals;31 std::vector<Item_t> theLiterals;
3532
36public:33public:
37 SYNC_CODE(RCLock* getRCLock() const { return &theRCLock; })
38
39 long* getSharedRefCounter() const { return NULL; }
40
41 virtual ~Annotation() {}34 virtual ~Annotation() {}
42};35};
4336
4437
=== modified file 'src/store/api/collection.h'
--- src/store/api/collection.h 2013-04-29 14:39:04 +0000
+++ src/store/api/collection.h 2013-07-11 13:41:52 +0000
@@ -23,16 +23,8 @@
23namespace zorba { namespace store {23namespace zorba { namespace store {
2424
2525
26class Collection : public RCObject26class Collection : public SyncedRCObject
27{27{
28protected:
29 SYNC_CODE(mutable RCLock theRCLock;)
30
31public:
32 SYNC_CODE(RCLock* getRCLock() const { return &theRCLock; })
33
34 long* getSharedRefCounter() const { return NULL; }
35
36public:28public:
37 virtual ~Collection() {}29 virtual ~Collection() {}
3830
3931
=== modified file 'src/store/api/ic.h'
--- src/store/api/ic.h 2013-02-07 17:24:36 +0000
+++ src/store/api/ic.h 2013-07-11 13:41:52 +0000
@@ -31,7 +31,7 @@
31 * Integrity Constraints class. Contains the name of the IC and the31 * Integrity Constraints class. Contains the name of the IC and the
32 * collection name.32 * collection name.
33 */33 */
34class IC : public RCObject34class IC : public SyncedRCObject
35{35{
36public:36public:
37 enum ICKind37 enum ICKind
@@ -40,14 +40,6 @@
40 ic_foreignkey 40 ic_foreignkey
41 };41 };
4242
43protected:
44 SYNC_CODE(mutable RCLock theRCLock;)
45
46public:
47 SYNC_CODE(RCLock* getRCLock() const { return &theRCLock; })
48
49 long* getSharedRefCounter() const { return NULL; }
50
51public:43public:
52 virtual ~IC() {}44 virtual ~IC() {}
5345
5446
=== modified file 'src/store/api/index.h'
--- src/store/api/index.h 2013-02-07 17:24:36 +0000
+++ src/store/api/index.h 2013-07-11 13:41:52 +0000
@@ -369,11 +369,8 @@
369 IndexCondition below).369 IndexCondition below).
370370
371*******************************************************************************/371*******************************************************************************/
372class Index : public RCObject372class Index : public SyncedRCObject
373{373{
374protected:
375 SYNC_CODE(mutable RCLock theRCLock;)
376
377public:374public:
378 class KeyIterator : virtual public SimpleRCObject375 class KeyIterator : virtual public SimpleRCObject
379 {376 {
@@ -391,11 +388,6 @@
391388
392389
393public:390public:
394 SYNC_CODE(RCLock* getRCLock() const { return &theRCLock; })
395
396 long* getSharedRefCounter() const { return NULL; }
397
398public:
399391
400 virtual ~Index() {}392 virtual ~Index() {}
401393
402394
=== modified file 'src/store/api/item.h'
--- src/store/api/item.h 2013-06-29 08:38:53 +0000
+++ src/store/api/item.h 2013-07-11 13:41:52 +0000
@@ -101,7 +101,7 @@
101101
102 virtual ~Item() {}102 virtual ~Item() {}
103103
104 virtual void free() { delete this; }104 virtual void free();
105105
106 long getRefCount() const { return theRefCount; }106 long getRefCount() const { return theRefCount; }
107107
108108
=== modified file 'src/store/naive/atomic_items.cpp'
--- src/store/naive/atomic_items.cpp 2013-06-21 01:06:29 +0000
+++ src/store/naive/atomic_items.cpp 2013-07-11 13:41:52 +0000
@@ -686,8 +686,8 @@
686{686{
687 assert(!isValid());687 assert(!isValid());
688688
689 store::Item_t lPoolQName =689 store::Item_t lPoolQName;
690 GET_STORE().getQNamePool().insert(aNamespace, zstring(), aLocalName);690 GET_STORE().getQNamePool().insert(lPoolQName, aNamespace, zstring(), aLocalName);
691691
692 QNameItem* lNormalized = static_cast<QNameItem*>(lPoolQName.getp());692 QNameItem* lNormalized = static_cast<QNameItem*>(lPoolQName.getp());
693 assert(lNormalized->isNormalized());693 assert(lNormalized->isNormalized());
@@ -705,12 +705,17 @@
705 if (theIsInPool)705 if (theIsInPool)
706 {706 {
707 thePool.remove(this);707 thePool.remove(this);
708
709 SYNC_CODE(getRCLock()->release());
710
708 return;711 return;
709 }712 }
710 713
711 assert(!isNormalized());714 assert(!isNormalized());
712715
713 invalidate(false, NULL);716 invalidate(false, NULL);
717 SYNC_CODE(getRCLock()->release());
718
714 delete this;719 delete this;
715}720}
716721
717722
=== modified file 'src/store/naive/atomic_items.h'
--- src/store/naive/atomic_items.h 2013-05-24 22:52:47 +0000
+++ src/store/naive/atomic_items.h 2013-07-11 13:41:52 +0000
@@ -424,6 +424,12 @@
424424
425 const QNameItem* getNormalized() const { return theNormalizedQName; }425 const QNameItem* getNormalized() const { return theNormalizedQName; }
426 426
427 const zstring& getLocalName2() const { return theLocal; }
428
429 const zstring& getNamespace2() const { return theNamespace; }
430
431 const zstring& getPrefix2() const { return thePrefix; }
432
427 bool isBaseUri() const;433 bool isBaseUri() const;
428 434
429 bool isIdQName() const;435 bool isIdQName() const;
430436
=== modified file 'src/store/naive/item.cpp'
--- src/store/naive/item.cpp 2013-06-15 02:57:08 +0000
+++ src/store/naive/item.cpp 2013-07-11 13:41:52 +0000
@@ -40,6 +40,12 @@
40{40{
4141
4242
43void Item::free()
44{
45 delete this;
46}
47
48
43void Item::addReference() const49void Item::addReference() const
44{50{
45#if defined WIN32 && !defined CYGWIN && !defined ZORBA_FOR_ONE_THREAD_ONLY51#if defined WIN32 && !defined CYGWIN && !defined ZORBA_FOR_ONE_THREAD_ONLY
@@ -135,6 +141,8 @@
135 {141 {
136 SYNC_CODE(static_cast<const simplestore::XmlNode*>(this)->getRCLock()->acquire());142 SYNC_CODE(static_cast<const simplestore::XmlNode*>(this)->getRCLock()->acquire());
137143
144 assert(theRefCount > 0);
145
138 --theRefCount;146 --theRefCount;
139 if (--(*theUnion.treeRCPtr) == 0)147 if (--(*theUnion.treeRCPtr) == 0)
140 {148 {
@@ -150,6 +158,7 @@
150 case ARRAY:158 case ARRAY:
151 {159 {
152 SYNC_CODE(static_cast<const simplestore::json::JSONItem*>(this)->getRCLock()->acquire());160 SYNC_CODE(static_cast<const simplestore::json::JSONItem*>(this)->getRCLock()->acquire());
161 assert(theRefCount > 0);
153162
154 if (--theRefCount == 0)163 if (--theRefCount == 0)
155 {164 {
@@ -166,6 +175,8 @@
166 {175 {
167 SYNC_CODE(static_cast<const simplestore::AtomicItem*>(this)->getRCLock()->acquire());176 SYNC_CODE(static_cast<const simplestore::AtomicItem*>(this)->getRCLock()->acquire());
168177
178 assert(theRefCount > 0);
179
169 if (--theRefCount == 0)180 if (--theRefCount == 0)
170 {181 {
171 SYNC_CODE(static_cast<const simplestore::AtomicItem*>(this)->getRCLock()->release());182 SYNC_CODE(static_cast<const simplestore::AtomicItem*>(this)->getRCLock()->release());
172183
=== modified file 'src/store/naive/loader_dtd.cpp'
--- src/store/naive/loader_dtd.cpp 2013-04-16 21:12:12 +0000
+++ src/store/naive/loader_dtd.cpp 2013-07-11 13:41:52 +0000
@@ -1212,9 +1212,11 @@
1212 csize numBindings = static_cast<csize>(numNamespaces);1212 csize numBindings = static_cast<csize>(numNamespaces);
12131213
1214 // Construct node name1214 // Construct node name
1215 store::Item_t nodeName = qnpool.insert(reinterpret_cast<const char*>(uri),1215 store::Item_t nodeName;
1216 reinterpret_cast<const char*>(prefix),1216 qnpool.insert(nodeName,
1217 reinterpret_cast<const char*>(lname));1217 reinterpret_cast<const char*>(uri),
1218 reinterpret_cast<const char*>(prefix),
1219 reinterpret_cast<const char*>(lname));
12181220
1219 // Create the element node and push it to the node stack1221 // Create the element node and push it to the node stack
1220 ElementNode* elemNode = nfactory.createElementNode(nodeName,1222 ElementNode* elemNode = nfactory.createElementNode(nodeName,
@@ -1335,9 +1337,11 @@
1335 //std::cout << " att: " << attr->name << std::endl; std::cout.flush();1337 //std::cout << " att: " << attr->name << std::endl; std::cout.flush();
13361338
1337 const char* lname = reinterpret_cast<const char*>(attr->name);1339 const char* lname = reinterpret_cast<const char*>(attr->name);
1338 const char* prefix = reinterpret_cast<const char*>( attr->ns != NULL ? attr->ns->prefix : NULL);1340 const char* prefix = reinterpret_cast<const char*>(attr->ns != NULL ? attr->ns->prefix : NULL);
1339 const char* uri = reinterpret_cast<const char*>( attr->ns != NULL ? attr->ns->href : NULL);1341 const char* uri = reinterpret_cast<const char*>(attr->ns != NULL ? attr->ns->href : NULL);
1340 store::Item_t qname = qnpool.insert(uri, prefix, lname);1342 store::Item_t qname;
1343 qnpool.insert(qname, uri, prefix, lname);
1344
1341 AttributeNode* attrNode = nfactory.createAttributeNode(qname);1345 AttributeNode* attrNode = nfactory.createAttributeNode(qname);
13421346
1343 xmlChar* val = xmlGetProp(node, attr->name);1347 xmlChar* val = xmlGetProp(node, attr->name);
13441348
=== modified file 'src/store/naive/loader_fast.cpp'
--- src/store/naive/loader_fast.cpp 2013-06-19 09:54:46 +0000
+++ src/store/naive/loader_fast.cpp 2013-07-11 13:41:52 +0000
@@ -676,10 +676,12 @@
676 csize numBindings = static_cast<csize>(numNamespaces);676 csize numBindings = static_cast<csize>(numNamespaces);
677677
678 // Construct node name678 // Construct node name
679 store::Item_t nodeName = qnpool.insert(reinterpret_cast<const char*>(uri),679 store::Item_t nodeName;
680 reinterpret_cast<const char*>(prefix),680 qnpool.insert(nodeName,
681 reinterpret_cast<const char*>(lname));681 reinterpret_cast<const char*>(uri),
682682 reinterpret_cast<const char*>(prefix),
683 reinterpret_cast<const char*>(lname));
684
683 // Create the element node and push it to the node stack685 // Create the element node and push it to the node stack
684 ElementNode* elemNode = nfactory.createElementNode(nodeName,686 ElementNode* elemNode = nfactory.createElementNode(nodeName,
685 numBindings,687 numBindings,
@@ -803,7 +805,8 @@
803 const char* valueBegin = reinterpret_cast<const char*>(attributes[index+3]);805 const char* valueBegin = reinterpret_cast<const char*>(attributes[index+3]);
804 const char* valueEnd = reinterpret_cast<const char*>(attributes[index+4]);806 const char* valueEnd = reinterpret_cast<const char*>(attributes[index+4]);
805807
806 store::Item_t qname = qnpool.insert(uri, prefix, lname);808 store::Item_t qname;
809 qnpool.insert(qname, uri, prefix, lname);
807810
808 zstring value(valueBegin, valueEnd);811 zstring value(valueBegin, valueEnd);
809 store::Item_t typedValue;812 store::Item_t typedValue;
810813
=== modified file 'src/store/naive/node_items.cpp'
--- src/store/naive/node_items.cpp 2013-06-29 08:38:53 +0000
+++ src/store/naive/node_items.cpp 2013-07-11 13:41:52 +0000
@@ -3645,7 +3645,9 @@
36453645
3646 const Store& store = GET_STORE();3646 const Store& store = GET_STORE();
36473647
3648 store::Item_t qname = store.getQNamePool().insert(store.XML_URI, "xml", "base");3648 store::Item_t qname;
3649 store.getQNamePool().insert(qname, store.XML_URI, "xml", "base");
3650
3649 store::Item_t typeName = store.theSchemaTypeNames[store::XS_ANY_URI];3651 store::Item_t typeName = store.theSchemaTypeNames[store::XS_ANY_URI];
36503652
3651 store::Item_t typedValue;3653 store::Item_t typedValue;
@@ -5133,7 +5135,7 @@
5133 theTarget.take(target);5135 theTarget.take(target);
5134 theContent.take(content);5136 theContent.take(content);
51355137
5136 theName = qnpool.insert(zstring(), zstring(), theTarget);5138 qnpool.insert(theName, zstring(), zstring(), theTarget);
51375139
5138 STORE_TRACE1("Loaded pi node " << this << " target = " << theTarget5140 STORE_TRACE1("Loaded pi node " << this << " target = " << theTarget
5139 << std::endl);5141 << std::endl);
@@ -5158,7 +5160,7 @@
5158 theTarget.take(target);5160 theTarget.take(target);
5159 theContent.take(content);5161 theContent.take(content);
51605162
5161 theName = qnpool.insert(zstring(), zstring(), theTarget);5163 qnpool.insert(theName, zstring(), zstring(), theTarget);
51625164
5163 if (parent)5165 if (parent)
5164 {5166 {
51655167
=== modified file 'src/store/naive/nsbindings.cpp'
--- src/store/naive/nsbindings.cpp 2013-06-20 09:52:25 +0000
+++ src/store/naive/nsbindings.cpp 2013-07-11 13:41:52 +0000
@@ -16,6 +16,7 @@
16#include "stdafx.h"16#include "stdafx.h"
1717
18#include "nsbindings.h"18#include "nsbindings.h"
19#include "store_defs.h"
1920
20#include "zorbautils/fatal.h"21#include "zorbautils/fatal.h"
2122
2223
=== modified file 'src/store/naive/qname_pool.cpp'
--- src/store/naive/qname_pool.cpp 2013-02-07 17:24:36 +0000
+++ src/store/naive/qname_pool.cpp 2013-07-11 13:41:52 +0000
@@ -48,13 +48,16 @@
48 QNameItem* qn = &theCache[1];48 QNameItem* qn = &theCache[1];
49 QNameItem* last = qn + size - 1;49 QNameItem* last = qn + size - 1;
5050
51 for (csize i = 1; qn < last; qn++, i++)51 for (csize i = 1; qn < last; ++qn, ++i)
52 {52 {
53 qn->theNextFree = i + 1;53 qn->theNextFree = i + 1;
54 qn->thePrevFree = i - 1;54 qn->thePrevFree = i - 1;
55 qn->thePosition = i;55 qn->thePosition = i;
56 }56 }
57 (--qn)->theNextFree = 0;57 (--qn)->theNextFree = 0;
58
59 qn = &theCache[0];
60 qn->theNextFree = qn->thePrevFree = qn->thePosition = 0;
58}61}
5962
6063
@@ -64,6 +67,27 @@
64QNamePool::~QNamePool() 67QNamePool::~QNamePool()
65{68{
66 csize n = theHashSet.capacity();69 csize n = theHashSet.capacity();
70
71#if 0
72#ifndef NDEBUG
73 csize numInPool = 0;
74 for (csize i = 0; i < theCacheSize; ++i)
75 {
76 QNameItem* qn = &theCache[i];
77
78 if (qn->getRefCount() != 0)
79 {
80 ++numInPool;
81 std::cerr << "QName in pool: RC = " << qn->getRefCount() << " : "
82 << qn->getStringValue() << " at pos : " << qn->thePosition
83 << std::endl;
84 }
85 }
86
87 std::cerr << std::endl << numInPool << "qnames in pool" << std::endl;
88#endif
89#endif
90
67 for (csize i = 0; i < n; ++i)91 for (csize i = 0; i < n; ++i)
68 {92 {
69 if (!theHashSet.theHashTab[i].isFree() &&93 if (!theHashSet.theHashTab[i].isFree() &&
@@ -84,19 +108,42 @@
84********************************************************************************/108********************************************************************************/
85void QNamePool::addInFreeList(QNameItem* qn)109void QNamePool::addInFreeList(QNameItem* qn)
86{110{
87 assert(qn->thePrevFree == 0);
88 assert(qn->theNextFree == 0);
89 assert(qn->getRefCount() == 0);111 assert(qn->getRefCount() == 0);
90 assert(theCache[theFirstFree].thePrevFree == 0);112 assert(theCache[theFirstFree].thePrevFree == 0);
91113
114 // Nothing to do if qn is already in the free list
115
116 if (qn->thePrevFree != 0 || qn->theNextFree != 0)
117 {
118#ifndef NDEBUG
119 QNameItem* curr = &theCache[theFirstFree];
120 while (curr != NULL && curr != qn)
121 curr = &theCache[curr->theNextFree];
122
123 assert(curr != NULL);
124#endif
125 return;
126 }
127
128 if (theFirstFree == qn->thePosition)
129 return;
130
131 // add it in the list
132
92 qn->theNextFree = (uint16_t)theFirstFree;133 qn->theNextFree = (uint16_t)theFirstFree;
93134
94 if (theFirstFree != 0)135 if (theFirstFree != 0)
136 {
137 assert(theCache[theFirstFree].thePosition == theFirstFree);
138
95 theCache[theFirstFree].thePrevFree = qn->thePosition;139 theCache[theFirstFree].thePrevFree = qn->thePosition;
140 }
96141
97 theFirstFree = qn->thePosition;142 theFirstFree = qn->thePosition;
98143
99 theNumFree++;144 assert(theFirstFree > 0 && theFirstFree < theCacheSize);
145
146 ++theNumFree;
100}147}
101148
102149
@@ -107,19 +154,10 @@
107{154{
108 assert(qn->isInCache());155 assert(qn->isInCache());
109156
110 if (qn->theNextFree == 0 && qn->thePrevFree == 0)
111 {
112 // Either qn does not belong to the free list, or is the only one in the
113 // free list
114
115 if (theFirstFree != qn->thePosition)
116 return;
117 }
118
119 assert(qn->getRefCount() == 0);
120
121 if (qn->theNextFree != 0)157 if (qn->theNextFree != 0)
122 {158 {
159 assert(qn->getRefCount() == 0);
160 assert(theFirstFree > 0 && theFirstFree < theCacheSize);
123 assert(theCache[qn->theNextFree].thePrevFree = qn->thePosition);161 assert(theCache[qn->theNextFree].thePrevFree = qn->thePosition);
124162
125 theCache[qn->theNextFree].thePrevFree = qn->thePrevFree;163 theCache[qn->theNextFree].thePrevFree = qn->thePrevFree;
@@ -127,12 +165,29 @@
127165
128 if (qn->thePrevFree != 0)166 if (qn->thePrevFree != 0)
129 {167 {
168 assert(qn->getRefCount() == 0);
169 assert(theFirstFree > 0 && theFirstFree < theCacheSize);
130 assert(theCache[qn->thePrevFree].theNextFree = qn->thePosition);170 assert(theCache[qn->thePrevFree].theNextFree = qn->thePosition);
131 171
132 theCache[qn->thePrevFree].theNextFree = qn->theNextFree;172 theCache[qn->thePrevFree].theNextFree = qn->theNextFree;
133 }173 }
174 else if (qn->theNextFree == 0)
175 {
176 // Either qn does not belong to the free list, or is the only one in the
177 // free list
178 if (theFirstFree != qn->thePosition)
179 return;
180
181 assert(qn->getRefCount() == 0);
182 assert(theFirstFree == qn->thePosition);
183 assert(theNumFree == 1);
184
185 theFirstFree = qn->theNextFree;
186 }
134 else187 else
135 {188 {
189 // qn is the 1st slot in the free list
190 assert(qn->getRefCount() == 0);
136 assert(theFirstFree == qn->thePosition);191 assert(theFirstFree == qn->thePosition);
137192
138 theFirstFree = qn->theNextFree;193 theFirstFree = qn->theNextFree;
@@ -140,7 +195,7 @@
140195
141 qn->theNextFree = qn->thePrevFree = 0;196 qn->theNextFree = qn->thePrevFree = 0;
142197
143 theNumFree--;198 --theNumFree;
144}199}
145200
146201
@@ -159,15 +214,14 @@
159214
160 theFirstFree = qn->theNextFree;215 theFirstFree = qn->theNextFree;
161216
162 if (theFirstFree != 0)217 assert(theFirstFree == 0 ||
163 {218 theCache[theFirstFree].thePrevFree == qn->thePosition);
164 assert(theCache[theFirstFree].thePrevFree == qn->thePosition);219
165 theCache[theFirstFree].thePrevFree = 0;220 theCache[theFirstFree].thePrevFree = 0;
166 }
167221
168 qn->theNextFree = qn->thePrevFree = 0;222 qn->theNextFree = qn->thePrevFree = 0;
169223
170 theNumFree--;224 --theNumFree;
171225
172 return qn;226 return qn;
173 }227 }
@@ -186,13 +240,15 @@
186{240{
187 QNameItem* normVictim = NULL;241 QNameItem* normVictim = NULL;
188242
189 SYNC_CODE(theHashSet.theMutex.lock(); \243 SYNC_CODE(theHashSet.theMutex.lock();)
190 bool haveLock = true;)
191244
192 try 245 try
193 {246 {
194 if (qn->getRefCount() > 0)247 if (qn->getRefCount() > 0)
248 {
249 SYNC_CODE(theHashSet.theMutex.unlock();)
195 return;250 return;
251 }
196252
197 if (qn->isInCache())253 if (qn->isInCache())
198 {254 {
@@ -211,22 +267,20 @@
211267
212 // Releasing the lock here to avoid deadlock, because decrementing the 268 // Releasing the lock here to avoid deadlock, because decrementing the
213 // normVictim counter might reenter QNamePool::remove.269 // normVictim counter might reenter QNamePool::remove.
214 SYNC_CODE(theHashSet.theMutex.unlock(); \270 SYNC_CODE(theHashSet.theMutex.unlock();)
215 haveLock = false;)
216
217 if (normVictim)
218 {
219 normVictim->removeReference();
220 }
221
222 }271 }
223 catch(...)272 catch(...)
224 {273 {
225 SYNC_CODE(if (haveLock) \274 SYNC_CODE(theHashSet.theMutex.unlock();)
226 theHashSet.theMutex.unlock();)
227 275
228 ZORBA_FATAL(0, "Unexpected exception");276 ZORBA_FATAL(0, "Unexpected exception");
229 }277 }
278
279 if (normVictim)
280 {
281 assert(normVictim->getRefCount() > 0 && normVictim->getRefCount() < 10000);
282 normVictim->removeReference();
283 }
230}284}
231285
232286
@@ -240,7 +294,8 @@
240 copied internally into zstring objects. So, it's always the caller who is294 copied internally into zstring objects. So, it's always the caller who is
241 resposnible for freeing the given strings.295 resposnible for freeing the given strings.
242********************************************************************************/296********************************************************************************/
243store::Item_t QNamePool::insert(297void QNamePool::insert(
298 store::Item_t& res,
244 const char* ns,299 const char* ns,
245 const char* pre,300 const char* pre,
246 const char* ln)301 const char* ln)
@@ -251,6 +306,8 @@
251 store::Item_t normItem;306 store::Item_t normItem;
252 QNameItem* normQName = NULL;307 QNameItem* normQName = NULL;
253308
309 res = NULL;
310
254 bool normalized = (pre == NULL || *pre == '\0');311 bool normalized = (pre == NULL || *pre == '\0');
255312
256 if (ns == NULL) ns = "";313 if (ns == NULL) ns = "";
@@ -286,7 +343,7 @@
286 SYNC_CODE(theHashSet.theMutex.unlock();\343 SYNC_CODE(theHashSet.theMutex.unlock();\
287 haveLock = false;)344 haveLock = false;)
288345
289 normItem = insert(ns, NULL, ln);346 insert(normItem, ns, NULL, ln);
290 normQName = static_cast<QNameItem*>(normItem.getp());347 normQName = static_cast<QNameItem*>(normItem.getp());
291 goto retry;348 goto retry;
292 }349 }
@@ -306,6 +363,9 @@
306 cachePin(qn);363 cachePin(qn);
307 }364 }
308365
366 assert(qn->theNextFree == 0);
367 res = qn;
368
309 SYNC_CODE(theHashSet.theMutex.unlock();\369 SYNC_CODE(theHashSet.theMutex.unlock();\
310 haveLock = false;)370 haveLock = false;)
311 }371 }
@@ -319,10 +379,9 @@
319379
320 if (normVictim != NULL)380 if (normVictim != NULL)
321 {381 {
382 assert(normVictim->getRefCount() > 0 && normVictim->getRefCount() < 10000);
322 normVictim->removeReference();383 normVictim->removeReference();
323 }384 }
324
325 return qn;
326}385}
327386
328387
@@ -331,7 +390,8 @@
331 and local name, then create such a qname, insert it in the pool and return an390 and local name, then create such a qname, insert it in the pool and return an
332 rchandle to it. Otherwise, return an rchandle to the existing qname. 391 rchandle to it. Otherwise, return an rchandle to the existing qname.
333********************************************************************************/392********************************************************************************/
334store::Item_t QNamePool::insert(393void QNamePool::insert(
394 store::Item_t& res,
335 const zstring& ns,395 const zstring& ns,
336 const zstring& pre,396 const zstring& pre,
337 const zstring& ln)397 const zstring& ln)
@@ -342,6 +402,8 @@
342 store::Item_t normItem;402 store::Item_t normItem;
343 QNameItem* normQName = NULL;403 QNameItem* normQName = NULL;
344404
405 res = NULL;
406
345 bool normalized = pre.empty();407 bool normalized = pre.empty();
346408
347 zstring pooledNs;409 zstring pooledNs;
@@ -377,7 +439,7 @@
377 haveLock = false;)439 haveLock = false;)
378440
379 // This call will need the lock.441 // This call will need the lock.
380 normItem = insert(pooledNs, zstring(), ln);442 insert(normItem, pooledNs, zstring(), ln);
381 normQName = static_cast<QNameItem*>(normItem.getp());443 normQName = static_cast<QNameItem*>(normItem.getp());
382444
383 goto retry;445 goto retry;
@@ -398,23 +460,24 @@
398 cachePin(qn);460 cachePin(qn);
399 }461 }
400462
463 assert(qn->theNextFree == 0);
464 res = qn;
465
401 SYNC_CODE(theHashSet.theMutex.unlock();\466 SYNC_CODE(theHashSet.theMutex.unlock();\
402 haveLock = false;)467 haveLock = false;)
403 }468 }
404 catch (...)469 catch (...)
405 {470 {
406 SYNC_CODE(if (haveLock) \471 SYNC_CODE(if (haveLock) theHashSet.theMutex.unlock();)
407 theHashSet.theMutex.unlock();)
408472
409 ZORBA_FATAL(0, "Unexpected exception");473 ZORBA_FATAL(0, "Unexpected exception");
410 }474 }
411475
412 if (normVictim != NULL)476 if (normVictim != NULL)
413 {477 {
478 assert(normVictim->getRefCount() > 0 && normVictim->getRefCount() < 10000);
414 normVictim->removeReference();479 normVictim->removeReference();
415 }480 }
416
417 return qn;
418}481}
419482
420483
@@ -480,9 +543,9 @@
480 {543 {
481 QNameItem* qn = entry->key();544 QNameItem* qn = entry->key();
482545
483 if (ztd::equals(qn->getLocalName(), ln, lnlen) &&546 if (ztd::equals(qn->getLocalName2(), ln, lnlen) &&
484 ztd::equals(qn->getNamespace(), ns, nslen) &&547 ztd::equals(qn->getNamespace2(), ns, nslen) &&
485 ztd::equals(qn->getPrefix(), pre, prelen))548 ztd::equals(qn->getPrefix2(), pre, prelen))
486 return entry;549 return entry;
487550
488 entry = entry->getNext();551 entry = entry->getNext();
489552
=== modified file 'src/store/naive/qname_pool.h'
--- src/store/naive/qname_pool.h 2013-02-07 17:24:36 +0000
+++ src/store/naive/qname_pool.h 2013-07-11 13:41:52 +0000
@@ -68,16 +68,16 @@
68 public:68 public:
69 static bool equal(const QNameItem* t1, const QNameItem* t2)69 static bool equal(const QNameItem* t1, const QNameItem* t2)
70 {70 {
71 return (t1->getLocalName() == t2->getLocalName() &&71 return (t1->getLocalName2() == t2->getLocalName2() &&
72 t1->getNamespace() == t2->getNamespace() &&72 t1->getNamespace2() == t2->getNamespace2() &&
73 t1->getPrefix() == t2->getPrefix());73 t1->getPrefix2() == t2->getPrefix2());
74 }74 }
7575
76 static uint32_t hash(const QNameItem* t)76 static uint32_t hash(const QNameItem* t)
77 {77 {
78 return hashfun::h32(t->getPrefix().c_str(),78 return hashfun::h32(t->getPrefix2().c_str(),
79 hashfun::h32(t->getLocalName().c_str(),79 hashfun::h32(t->getLocalName2().c_str(),
80 hashfun::h32(t->getNamespace().c_str())));80 hashfun::h32(t->getNamespace2().c_str())));
81 }81 }
82 };82 };
8383
@@ -115,9 +115,17 @@
115115
116 ~QNamePool();116 ~QNamePool();
117117
118 store::Item_t insert(const char* ns, const char* pre, const char* ln);118 void insert(
119 store::Item_t& res,
120 const char* ns,
121 const char* pre,
122 const char* ln);
119 123
120 store::Item_t insert(const zstring& ns, const zstring& pre, const zstring& ln);124 void insert(
125 store::Item_t& res,
126 const zstring& ns,
127 const zstring& pre,
128 const zstring& ln);
121 129
122 void remove(QNameItem* qn);130 void remove(QNameItem* qn);
123131
124132
=== modified file 'src/store/naive/simple_item_factory.cpp'
--- src/store/naive/simple_item_factory.cpp 2013-06-21 01:06:29 +0000
+++ src/store/naive/simple_item_factory.cpp 2013-07-11 13:41:52 +0000
@@ -81,7 +81,7 @@
81 const zstring& pre,81 const zstring& pre,
82 const zstring& local)82 const zstring& local)
83{83{
84 result = theQNamePool->insert(ns, pre, local);84 theQNamePool->insert(result, ns, pre, local);
85 return true;85 return true;
86}86}
8787
@@ -92,7 +92,7 @@
92 const char* pre,92 const char* pre,
93 const char* ln)93 const char* ln)
94{94{
95 result = theQNamePool->insert(ns, pre, ln);95 theQNamePool->insert(result, ns, pre, ln);
96 return true;96 return true;
97}97}
9898
9999
=== modified file 'src/store/naive/simple_pul.cpp'
--- src/store/naive/simple_pul.cpp 2013-06-15 02:57:08 +0000
+++ src/store/naive/simple_pul.cpp 2013-07-11 13:41:52 +0000
@@ -166,20 +166,19 @@
166{166{
167 const QNameItem* collName;167 const QNameItem* collName;
168168
169 assert(target->isNode()169 assert(target->isNode() || target->isJSONItem());
170 || target->isJSONItem());
171170
172 assert(dynamic_cast<const StructuredItem*>(target));171 assert(dynamic_cast<const StructuredItem*>(target));
173 const StructuredItem* lStructuredItem =172
174 static_cast<const StructuredItem*>(target);173 const StructuredItem* structuredItem = static_cast<const StructuredItem*>(target);
175 const store::Collection* lCollection = lStructuredItem->getCollection();174
175 const store::Collection* lCollection = structuredItem->getCollection();
176176
177 if (lCollection != NULL)177 if (lCollection != NULL)
178 {178 {
179 collName = static_cast<const QNameItem*>(179 collName = static_cast<const QNameItem*>(lCollection->getName());
180 lCollection->getName())->getNormalized();
181180
182 if (collName == theLastCollection)181 if (theLastCollection != NULL && collName->equals(theLastCollection))
183 return theLastPul;182 return theLastPul;
184183
185 return getCollectionPulByName(collName, lCollection->isDynamic());184 return getCollectionPulByName(collName, lCollection->isDynamic());
186185
=== modified file 'src/store/naive/store.cpp'
--- src/store/naive/store.cpp 2013-06-15 02:57:08 +0000
+++ src/store/naive/store.cpp 2013-07-11 13:41:52 +0000
@@ -185,69 +185,69 @@
185185
186 theSchemaTypeNames.resize(store::XS_LAST);186 theSchemaTypeNames.resize(store::XS_LAST);
187187
188 JS_NULL_QNAME = theQNamePool->insert(JS_URI, "js", "null");188 theQNamePool->insert(JS_NULL_QNAME, JS_URI, "js", "null");
189 JS_OBJECT_QNAME = theQNamePool->insert(JS_URI, "js", "object");189 theQNamePool->insert(JS_OBJECT_QNAME, JS_URI, "js", "object");
190 JS_ARRAY_QNAME = theQNamePool->insert(JS_URI, "js", "array");190 theQNamePool->insert(JS_ARRAY_QNAME, JS_URI, "js", "array");
191191
192 XS_UNTYPED_QNAME = theQNamePool->insert(ns, "xs", "untyped");192 theQNamePool->insert(XS_UNTYPED_QNAME, ns, "xs", "untyped");
193193
194 XS_ANY_QNAME = theQNamePool->insert(ns, "xs", "anyType");194 theQNamePool->insert(XS_ANY_QNAME, ns, "xs", "anyType");
195195
196 theSchemaTypeNames[store::XS_ANY_ATOMIC] =196 theQNamePool->insert(theSchemaTypeNames[store::XS_ANY_ATOMIC],
197 theQNamePool->insert(ns, "xs", "anyAtomicType");197 ns, "xs", "anyAtomicType");
198198
199 theSchemaTypeNames[store::XS_UNTYPED_ATOMIC] =199 theQNamePool->insert(theSchemaTypeNames[store::XS_UNTYPED_ATOMIC],
200 theQNamePool->insert(ns, "xs", "untypedAtomic");200 ns, "xs", "untypedAtomic");
201201
202 theSchemaTypeNames[store::XS_ANY_URI] = theQNamePool->insert(ns, "xs", "anyURI");202 theQNamePool->insert(theSchemaTypeNames[store::XS_ANY_URI], ns, "xs", "anyURI");
203 theSchemaTypeNames[store::XS_QNAME] = theQNamePool->insert(ns, "xs", "QName");203 theQNamePool->insert(theSchemaTypeNames[store::XS_QNAME], ns, "xs", "QName");
204 theSchemaTypeNames[store::XS_NOTATION] = theQNamePool->insert(ns, "xs", "NOTATION");204 theQNamePool->insert(theSchemaTypeNames[store::XS_NOTATION], ns, "xs", "NOTATION");
205 theSchemaTypeNames[store::XS_STRING] = theQNamePool->insert(ns, "xs", "string");205 theQNamePool->insert(theSchemaTypeNames[store::XS_STRING], ns, "xs", "string");
206 theSchemaTypeNames[store::XS_NORMALIZED_STRING] = theQNamePool->insert(ns, "xs", "normalizedString");206 theQNamePool->insert(theSchemaTypeNames[store::XS_NORMALIZED_STRING], ns, "xs", "normalizedString");
207 theSchemaTypeNames[store::XS_TOKEN] = theQNamePool->insert(ns, "xs", "token");207 theQNamePool->insert(theSchemaTypeNames[store::XS_TOKEN], ns, "xs", "token");
208 theSchemaTypeNames[store::XS_NMTOKEN] = theQNamePool->insert(ns, "xs", "NMTOKEN");208 theQNamePool->insert(theSchemaTypeNames[store::XS_NMTOKEN], ns, "xs", "NMTOKEN");
209 theSchemaTypeNames[store::XS_LANGUAGE] = theQNamePool->insert(ns, "xs", "language");209 theQNamePool->insert(theSchemaTypeNames[store::XS_LANGUAGE], ns, "xs", "language");
210 theSchemaTypeNames[store::XS_NAME] = theQNamePool->insert(ns, "xs", "Name");210 theQNamePool->insert(theSchemaTypeNames[store::XS_NAME], ns, "xs", "Name");
211 theSchemaTypeNames[store::XS_NCNAME] = theQNamePool->insert(ns, "xs", "NCName");211 theQNamePool->insert(theSchemaTypeNames[store::XS_NCNAME], ns, "xs", "NCName");
212 theSchemaTypeNames[store::XS_ID] = theQNamePool->insert(ns, "xs", "ID");212 theQNamePool->insert(theSchemaTypeNames[store::XS_ID], ns, "xs", "ID");
213 theSchemaTypeNames[store::XS_IDREF] = theQNamePool->insert(ns, "xs", "IDREF");213 theQNamePool->insert(theSchemaTypeNames[store::XS_IDREF], ns, "xs", "IDREF");
214 theSchemaTypeNames[store::XS_ENTITY] = theQNamePool->insert(ns, "xs", "ENTITY");214 theQNamePool->insert(theSchemaTypeNames[store::XS_ENTITY], ns, "xs", "ENTITY");
215215
216 theSchemaTypeNames[store::XS_DATETIME] = theQNamePool->insert(ns, "xs", "dateTime");216 theQNamePool->insert(theSchemaTypeNames[store::XS_DATETIME], ns, "xs", "dateTime");
217 theSchemaTypeNames[store::XS_DATETIME_STAMP] = theQNamePool->insert(ns, "xs", "dateTimeStamp");217 theQNamePool->insert(theSchemaTypeNames[store::XS_DATETIME_STAMP], ns, "xs", "dateTimeStamp");
218 theSchemaTypeNames[store::XS_DATE] = theQNamePool->insert(ns, "xs", "date");218 theQNamePool->insert(theSchemaTypeNames[store::XS_DATE], ns, "xs", "date");
219 theSchemaTypeNames[store::XS_TIME] = theQNamePool->insert(ns, "xs", "time");219 theQNamePool->insert(theSchemaTypeNames[store::XS_TIME], ns, "xs", "time");
220 theSchemaTypeNames[store::XS_GYEAR_MONTH] = theQNamePool->insert(ns, "xs", "gYearMonth");220 theQNamePool->insert(theSchemaTypeNames[store::XS_GYEAR_MONTH], ns, "xs", "gYearMonth");
221 theSchemaTypeNames[store::XS_GYEAR] = theQNamePool->insert(ns, "xs", "gYear");221 theQNamePool->insert(theSchemaTypeNames[store::XS_GYEAR], ns, "xs", "gYear");
222 theSchemaTypeNames[store::XS_GMONTH_DAY] = theQNamePool->insert(ns, "xs", "gMonthDay");222 theQNamePool->insert(theSchemaTypeNames[store::XS_GMONTH_DAY], ns, "xs", "gMonthDay");
223 theSchemaTypeNames[store::XS_GDAY] = theQNamePool->insert(ns, "xs", "gDay");223 theQNamePool->insert(theSchemaTypeNames[store::XS_GDAY], ns, "xs", "gDay");
224 theSchemaTypeNames[store::XS_GMONTH] = theQNamePool->insert(ns, "xs", "gMonth");224 theQNamePool->insert(theSchemaTypeNames[store::XS_GMONTH], ns, "xs", "gMonth");
225225
226 theSchemaTypeNames[store::XS_DURATION] = theQNamePool->insert(ns, "xs", "duration");226 theQNamePool->insert(theSchemaTypeNames[store::XS_DURATION], ns, "xs", "duration");
227 theSchemaTypeNames[store::XS_DT_DURATION] = theQNamePool->insert(ns, "xs", "dayTimeDuration");227 theQNamePool->insert(theSchemaTypeNames[store::XS_DT_DURATION], ns, "xs", "dayTimeDuration");
228 theSchemaTypeNames[store::XS_YM_DURATION] = theQNamePool->insert(ns, "xs", "yearMonthDuration");228 theQNamePool->insert(theSchemaTypeNames[store::XS_YM_DURATION], ns, "xs", "yearMonthDuration");
229229
230 theSchemaTypeNames[store::XS_FLOAT] = theQNamePool->insert(ns, "xs", "float");230 theQNamePool->insert(theSchemaTypeNames[store::XS_FLOAT], ns, "xs", "float");
231 theSchemaTypeNames[store::XS_DOUBLE] = theQNamePool->insert(ns, "xs", "double");231 theQNamePool->insert(theSchemaTypeNames[store::XS_DOUBLE], ns, "xs", "double");
232 theSchemaTypeNames[store::XS_DECIMAL] = theQNamePool->insert(ns, "xs", "decimal");232 theQNamePool->insert(theSchemaTypeNames[store::XS_DECIMAL], ns, "xs", "decimal");
233 theSchemaTypeNames[store::XS_INTEGER] = theQNamePool->insert(ns, "xs", "integer");233 theQNamePool->insert(theSchemaTypeNames[store::XS_INTEGER], ns, "xs", "integer");
234 theSchemaTypeNames[store::XS_NON_POSITIVE_INTEGER] = theQNamePool->insert(ns, "xs", "nonPositiveInteger");234 theQNamePool->insert(theSchemaTypeNames[store::XS_NON_POSITIVE_INTEGER], ns, "xs", "nonPositiveInteger");
235 theSchemaTypeNames[store::XS_NON_NEGATIVE_INTEGER] = theQNamePool->insert(ns, "xs", "nonNegativeInteger");235 theQNamePool->insert(theSchemaTypeNames[store::XS_NON_NEGATIVE_INTEGER], ns, "xs", "nonNegativeInteger");
236 theSchemaTypeNames[store::XS_NEGATIVE_INTEGER] = theQNamePool->insert(ns, "xs", "negativeInteger");236 theQNamePool->insert(theSchemaTypeNames[store::XS_NEGATIVE_INTEGER], ns, "xs", "negativeInteger");
237 theSchemaTypeNames[store::XS_POSITIVE_INTEGER] = theQNamePool->insert(ns, "xs", "positiveInteger");237 theQNamePool->insert(theSchemaTypeNames[store::XS_POSITIVE_INTEGER], ns, "xs", "positiveInteger");
238238
239 theSchemaTypeNames[store::XS_LONG] = theQNamePool->insert(ns, "xs", "long");239 theQNamePool->insert(theSchemaTypeNames[store::XS_LONG], ns, "xs", "long");
240 theSchemaTypeNames[store::XS_INT] = theQNamePool->insert(ns, "xs", "int");240 theQNamePool->insert(theSchemaTypeNames[store::XS_INT], ns, "xs", "int");
241 theSchemaTypeNames[store::XS_SHORT] = theQNamePool->insert(ns, "xs", "short");241 theQNamePool->insert(theSchemaTypeNames[store::XS_SHORT], ns, "xs", "short");
242 theSchemaTypeNames[store::XS_BYTE] = theQNamePool->insert(ns, "xs", "byte");242 theQNamePool->insert(theSchemaTypeNames[store::XS_BYTE], ns, "xs", "byte");
243 theSchemaTypeNames[store::XS_UNSIGNED_LONG] = theQNamePool->insert(ns, "xs", "unsignedLong");243 theQNamePool->insert(theSchemaTypeNames[store::XS_UNSIGNED_LONG], ns, "xs", "unsignedLong");
244 theSchemaTypeNames[store::XS_UNSIGNED_INT] = theQNamePool->insert(ns, "xs", "unsignedInt");244 theQNamePool->insert(theSchemaTypeNames[store::XS_UNSIGNED_INT], ns, "xs", "unsignedInt");
245 theSchemaTypeNames[store::XS_UNSIGNED_SHORT] = theQNamePool->insert(ns, "xs", "unsignedShort");245 theQNamePool->insert(theSchemaTypeNames[store::XS_UNSIGNED_SHORT], ns, "xs", "unsignedShort");
246 theSchemaTypeNames[store::XS_UNSIGNED_BYTE] = theQNamePool->insert(ns, "xs", "unsignedByte");246 theQNamePool->insert(theSchemaTypeNames[store::XS_UNSIGNED_BYTE], ns, "xs", "unsignedByte");
247247
248 theSchemaTypeNames[store::XS_BASE64BINARY] = theQNamePool->insert(ns, "xs", "base64Binary");248 theQNamePool->insert(theSchemaTypeNames[store::XS_BASE64BINARY], ns, "xs", "base64Binary");
249 theSchemaTypeNames[store::XS_HEXBINARY] = theQNamePool->insert(ns, "xs", "hexBinary");249 theQNamePool->insert(theSchemaTypeNames[store::XS_HEXBINARY], ns, "xs", "hexBinary");
250 theSchemaTypeNames[store::XS_BOOLEAN] = theQNamePool->insert(ns, "xs", "boolean");250 theQNamePool->insert(theSchemaTypeNames[store::XS_BOOLEAN], ns, "xs", "boolean");
251251
252 for (csize i = 0; i < store::XS_LAST; ++i)252 for (csize i = 0; i < store::XS_LAST; ++i)
253 {253 {
254254
=== modified file 'src/store/naive/store_defs.h'
--- src/store/naive/store_defs.h 2013-02-26 04:12:43 +0000
+++ src/store/naive/store_defs.h 2013-07-11 13:41:52 +0000
@@ -26,6 +26,7 @@
26//#define EMBEDED_TYPE26//#define EMBEDED_TYPE
27//#define TEXT_ORDPATH27//#define TEXT_ORDPATH
2828
29#define XML_NS "http://www.w3.org/XML/1998/namespace"
2930
30#define GET_STORE() \31#define GET_STORE() \
31 (*zorba::simplestore::StoreManagerImpl::getStoreInternal())32 (*zorba::simplestore::StoreManagerImpl::getStoreInternal())
3233
=== modified file 'src/system/globalenv.cpp'
--- src/system/globalenv.cpp 2013-05-13 08:45:43 +0000
+++ src/system/globalenv.cpp 2013-07-11 13:41:52 +0000
@@ -86,10 +86,11 @@
86 RCHelper::addReference(m_globalEnv->theRootTypeManager);86 RCHelper::addReference(m_globalEnv->theRootTypeManager);
8787
88 m_globalEnv->theRootStaticContext = new root_static_context();88 m_globalEnv->theRootStaticContext = new root_static_context();
89 RCHelper::addReference(m_globalEnv->theRootStaticContext);
90 m_globalEnv->theRootStaticContext->init();89 m_globalEnv->theRootStaticContext->init();
9190
92 BuiltinFunctionLibrary::create(m_globalEnv->theRootStaticContext);91 m_globalEnv->theFunctionLib = new BuiltinFunctionLibrary();
92
93 m_globalEnv->theFunctionLib->populate(m_globalEnv->theRootStaticContext);
9394
94 AnnotationInternal::createBuiltIn();95 AnnotationInternal::createBuiltIn();
9596
@@ -105,7 +106,7 @@
105#endif106#endif
106107
107 std::auto_ptr<XQueryCompilerSubsystem> lSubSystem = 108 std::auto_ptr<XQueryCompilerSubsystem> lSubSystem =
108 XQueryCompilerSubsystem::create();109 XQueryCompilerSubsystem::create();
109110
110 m_globalEnv->m_compilerSubSys = lSubSystem.release();111 m_globalEnv->m_compilerSubSys = lSubSystem.release();
111112
@@ -139,8 +140,9 @@
139 delete m_globalEnv->xqueryx_convertor;140 delete m_globalEnv->xqueryx_convertor;
140#endif141#endif
141142
142 RCHelper::removeReference(m_globalEnv->theRootStaticContext);143 delete m_globalEnv->theRootStaticContext;
143 m_globalEnv->theRootStaticContext = 0;144
145 delete m_globalEnv->theFunctionLib;
144146
145 RCHelper::removeReference(m_globalEnv->theRootTypeManager);147 RCHelper::removeReference(m_globalEnv->theRootTypeManager);
146 m_globalEnv->theRootTypeManager = 0;148 m_globalEnv->theRootTypeManager = 0;
@@ -157,8 +159,6 @@
157 // see http://www.icu-project.org/apiref/icu4c/uclean_8h.html#93f27d0ddc7c196a1da864763f2d8920159 // see http://www.icu-project.org/apiref/icu4c/uclean_8h.html#93f27d0ddc7c196a1da864763f2d8920
158 m_globalEnv->cleanup_icu();160 m_globalEnv->cleanup_icu();
159161
160 BuiltinFunctionLibrary::destroy();
161
162 delete m_globalEnv;162 delete m_globalEnv;
163 m_globalEnv = NULL;163 m_globalEnv = NULL;
164164
165165
=== modified file 'src/system/globalenv.h'
--- src/system/globalenv.h 2013-02-07 17:24:36 +0000
+++ src/system/globalenv.h 2013-07-11 13:41:52 +0000
@@ -22,14 +22,17 @@
22#include "common/common.h"22#include "common/common.h"
23#include "common/shared_types.h"23#include "common/shared_types.h"
2424
25namespace zorba {25namespace zorba
26{
2627
27class RootTypeManager;28class RootTypeManager;
28class root_static_context;29class root_static_context;
29class XQueryXConvertor;30class XQueryXConvertor;
30class DynamicLoader;31class DynamicLoader;
32class BuiltinFunctionLibrary;
3133
32namespace internal {34namespace internal
35{
33class HTTPURLResolver;36class HTTPURLResolver;
34class FileURLResolver;37class FileURLResolver;
35class AutoFSURIMapper;38class AutoFSURIMapper;
@@ -38,12 +41,15 @@
38#endif /* ZORBA_NO_FULL_TEXT */41#endif /* ZORBA_NO_FULL_TEXT */
39}42}
4043
41namespace store {44namespace store
45{
42class Store;46class Store;
43}47}
4448
4549
46// exported for unit testing only50/*******************************************************************************
51
52********************************************************************************/
47class ZORBA_DLL_PUBLIC GlobalEnvironment 53class ZORBA_DLL_PUBLIC GlobalEnvironment
48{54{
49private:55private:
@@ -57,6 +63,8 @@
5763
58 root_static_context * theRootStaticContext;64 root_static_context * theRootStaticContext;
5965
66 BuiltinFunctionLibrary * theFunctionLib;
67
60 XQueryCompilerSubsystem * m_compilerSubSys;68 XQueryCompilerSubsystem * m_compilerSubSys;
6169
62#ifdef ZORBA_XQUERYX70#ifdef ZORBA_XQUERYX
@@ -95,6 +103,8 @@
95103
96 bool isRootStaticContextInitialized() const;104 bool isRootStaticContextInitialized() const;
97105
106 BuiltinFunctionLibrary* getFuncLib() const { return theFunctionLib; }
107
98 XQueryCompilerSubsystem& getCompilerSubsystem();108 XQueryCompilerSubsystem& getCompilerSubsystem();
99109
100 store::Store& getStore();110 store::Store& getStore();
@@ -142,6 +152,8 @@
142152
143#define GENV_ROOT_STATIC_CONTEXT GlobalEnvironment::getInstance().getRootStaticContext()153#define GENV_ROOT_STATIC_CONTEXT GlobalEnvironment::getInstance().getRootStaticContext()
144154
155#define GENV_FUNC_LIB GlobalEnvironment::getInstance().getFuncLib()
156
145#define GENV_DYNAMIC_LOADER GlobalEnvironment::getInstance().getDynamicLoader()157#define GENV_DYNAMIC_LOADER GlobalEnvironment::getInstance().getDynamicLoader()
146158
147}159}
148160
=== modified file 'src/types/root_typemanager.cpp'
--- src/types/root_typemanager.cpp 2013-06-15 02:57:08 +0000
+++ src/types/root_typemanager.cpp 2013-07-11 13:41:52 +0000
@@ -231,7 +231,7 @@
231231
232#define XSQNDECL(var, local) \232#define XSQNDECL(var, local) \
233 GENV.getStore().getItemFactory()-> \233 GENV.getStore().getItemFactory()-> \
234 createQName(var, XML_SCHEMA_NS, XML_SCHEMA_PREFIX, local)234 createQName(var, static_context::W3C_XML_SCHEMA_NS, "xs", local)
235235
236 XSQNDECL(XS_ANY_ATOMIC_QNAME, "anyAtomicType");236 XSQNDECL(XS_ANY_ATOMIC_QNAME, "anyAtomicType");
237 XSQNDECL(XS_STRING_QNAME, "string");237 XSQNDECL(XS_STRING_QNAME, "string");
@@ -288,7 +288,7 @@
288288
289 GENV_STORE.getItemFactory()->createQName(JS_NULL_QNAME,289 GENV_STORE.getItemFactory()->createQName(JS_NULL_QNAME,
290 static_context::JSONIQ_DM_NS,290 static_context::JSONIQ_DM_NS,
291 "js",291 "",
292 "null");292 "null");
293293
294 store::Item* tempQN = NULL;294 store::Item* tempQN = NULL;
295295
=== modified file 'src/types/schema/revalidateUtils.cpp'
--- src/types/schema/revalidateUtils.cpp 2013-06-29 08:38:53 +0000
+++ src/types/schema/revalidateUtils.cpp 2013-07-11 13:41:52 +0000
@@ -495,10 +495,8 @@
495 std::vector<store::Item_t>& resultList,495 std::vector<store::Item_t>& resultList,
496 const QueryLoc& loc)496 const QueryLoc& loc)
497{497{
498 xqtref_t type = typeManager->create_named_atomic_type(typeQName,498 xqtref_t type = typeManager->create_named_simple_type(typeQName);
499 TypeConstants::QUANT_ONE,499
500 loc,
501 false);
502 //cout << " vup - processTextValue: '" << textValue->c_str() << "'\n";500 //cout << " vup - processTextValue: '" << textValue->c_str() << "'\n";
503 //cout << " vup - processTextValue: " << typeQName->getPrefix()->str()501 //cout << " vup - processTextValue: " << typeQName->getPrefix()->str()
504 // << ":" << typeQName->getLocalName()->str() << "@"502 // << ":" << typeQName->getLocalName()->str() << "@"
@@ -509,7 +507,15 @@
509 store::Item_t result;507 store::Item_t result;
510 if (type != NULL)508 if (type != NULL)
511 {509 {
512 if ( type->type_kind() == XQType::USER_DEFINED_KIND )510 if (type->type_kind() == XQType::ANY_SIMPLE_TYPE_KIND)
511 {
512 if (GENV_ITEMFACTORY->createUntypedAtomic(result, textValue))
513 resultList.push_back(result);
514
515 return;
516 }
517
518 if (type->type_kind() == XQType::USER_DEFINED_KIND)
513 {519 {
514 const UserDefinedXQType udXQType = static_cast<const UserDefinedXQType&>(*type);520 const UserDefinedXQType udXQType = static_cast<const UserDefinedXQType&>(*type);
515 521
@@ -552,7 +558,7 @@
552 }558 }
553 else559 else
554 {560 {
555 if ( GENV_ITEMFACTORY->createUntypedAtomic( result, textValue) )561 if (GENV_ITEMFACTORY->createUntypedAtomic(result, textValue))
556 resultList.push_back(result);562 resultList.push_back(result);
557 }563 }
558}564}
559565
=== modified file 'src/types/schema/schema.cpp'
--- src/types/schema/schema.cpp 2013-06-21 12:07:22 +0000
+++ src/types/schema/schema.cpp 2013-07-11 13:41:52 +0000
@@ -79,7 +79,7 @@
79#endif79#endif
8080
8181
82const char* Schema::XSD_NAMESPACE = XML_SCHEMA_NS;82const char* Schema::XSD_NAMESPACE = static_context::W3C_XML_SCHEMA_NS;
8383
84bool Schema::theIsInitialized = false;84bool Schema::theIsInitialized = false;
8585
8686
=== modified file 'src/types/typeimpl.cpp'
--- src/types/typeimpl.cpp 2013-06-15 02:57:08 +0000
+++ src/types/typeimpl.cpp 2013-07-11 13:41:52 +0000
@@ -181,6 +181,9 @@
181{181{
182 if (theIsBuiltin)182 if (theIsBuiltin)
183 {183 {
184#ifndef NDEBUG
185 theRefCount = 1000000;
186#endif
184 // register this hardcoded object to help plan serialization187 // register this hardcoded object to help plan serialization
185 XQType* this_ptr = this;188 XQType* this_ptr = this;
186 *::zorba::serialization::ClassSerializer::getInstance()->189 *::zorba::serialization::ClassSerializer::getInstance()->
187190
=== modified file 'src/types/typemanagerimpl.cpp'
--- src/types/typemanagerimpl.cpp 2013-06-15 02:57:08 +0000
+++ src/types/typemanagerimpl.cpp 2013-07-11 13:41:52 +0000
@@ -46,6 +46,8 @@
46#include "zorbaserialization/serialize_template_types.h"46#include "zorbaserialization/serialize_template_types.h"
47#include "zorbaserialization/serialize_zorba_types.h"47#include "zorbaserialization/serialize_zorba_types.h"
4848
49#include "context/static_context.h"
50
49#ifdef ZORBA_XBROWSER51#ifdef ZORBA_XBROWSER
50#include "DOMQName.h"52#include "DOMQName.h"
51#endif53#endif
@@ -259,7 +261,7 @@
259261
260 // If the type name is an XML Schema builtin type, then it cannot be an atomic262 // If the type name is an XML Schema builtin type, then it cannot be an atomic
261 // type (because, otherwise it would have been found above). So we return NULL.263 // type (because, otherwise it would have been found above). So we return NULL.
262 if (ZSTREQ(qname->getNamespace(), XML_SCHEMA_NS))264 if (qname->getNamespace() == static_context::W3C_XML_SCHEMA_NS)
263 {265 {
264 if (raiseError)266 if (raiseError)
265 {267 {
@@ -333,7 +335,7 @@
333335
334 // If the type name is an XML Schema builtin type, then it can only be one of336 // If the type name is an XML Schema builtin type, then it can only be one of
335 // xs:NMTOKES, xs:IDREFS, or xs:ENTITIES.337 // xs:NMTOKES, xs:IDREFS, or xs:ENTITIES.
336 if (ZSTREQ(qname->getNamespace(), XML_SCHEMA_NS))338 if (qname->getNamespace() == static_context::W3C_XML_SCHEMA_NS)
337 {339 {
338 RootTypeManager& rtm = GENV_TYPESYSTEM;340 RootTypeManager& rtm = GENV_TYPESYSTEM;
339341
340342
=== modified file 'src/util/http_util.cpp'
--- src/util/http_util.cpp 2013-05-31 03:38:45 +0000
+++ src/util/http_util.cpp 2013-07-11 13:41:52 +0000
@@ -24,6 +24,7 @@
2424
25#include "api/unmarshaller.h"25#include "api/unmarshaller.h"
26#include "zorbamisc/ns_consts.h"26#include "zorbamisc/ns_consts.h"
27#include "context/static_context.h"
2728
28#include "http_util.h"29#include "http_util.h"
2930
@@ -53,16 +54,28 @@
53 ItemFactory* lFactory = lInstance->getItemFactory();54 ItemFactory* lFactory = lInstance->getItemFactory();
54 Item lNodeName = lFactory->createQName("http://expath.org/ns/http-client", "http", "request");55 Item lNodeName = lFactory->createQName("http://expath.org/ns/http-client", "http", "request");
55 Item lEmptyItem;56 Item lEmptyItem;
57
56 NsBindings nsPairs;58 NsBindings nsPairs;
57 nsPairs.push_back(std::make_pair(String(XML_SCHEMA_PREFIX), String(XML_SCHEMA_NS)));59 nsPairs.push_back(std::make_pair(String(XML_SCHEMA_PREFIX),
58 Item lRequestElement = lFactory->createElementNode(lEmptyItem, lNodeName,60 String(static_context::W3C_XML_SCHEMA_NS)));
59 lFactory->createQName(XML_SCHEMA_NS,61
60 XML_SCHEMA_PREFIX, "untyped"),62 Item lRequestElement =
61 true, false, nsPairs);63 lFactory->createElementNode(lEmptyItem, lNodeName,
62 lFactory->createAttributeNode(lRequestElement, lFactory->createQName("", "method"), Item(), lFactory->createString("GET"));64 lFactory->createQName(static_context::W3C_XML_SCHEMA_NS,
65 "", "untyped"),
66 true, false, nsPairs);
67
68 lFactory->createAttributeNode(lRequestElement,
69 lFactory->createQName("", "method"),
70 Item(),
71 lFactory->createString("GET"));
72
63 lFactory->createAttributeNode(lRequestElement, lFactory->createQName("", "href"), Item(), lFactory->createString(theUri.c_str()));73 lFactory->createAttributeNode(lRequestElement, lFactory->createQName("", "href"), Item(), lFactory->createString(theUri.c_str()));
74
64 lFactory->createAttributeNode(lRequestElement, lFactory->createQName("", "override-media-type"), Item(), lFactory->createString("text/plain"));75 lFactory->createAttributeNode(lRequestElement, lFactory->createQName("", "override-media-type"), Item(), lFactory->createString("text/plain"));
76
65 lFactory->createAttributeNode(lRequestElement, lFactory->createQName("", "follow-redirect"), Item(), lFactory->createString("true"));77 lFactory->createAttributeNode(lRequestElement, lFactory->createQName("", "follow-redirect"), Item(), lFactory->createString("true"));
78
66 Zorba_CompilerHints_t lHints;79 Zorba_CompilerHints_t lHints;
67 lHints.opt_level = ZORBA_OPT_LEVEL_O1;80 lHints.opt_level = ZORBA_OPT_LEVEL_O1;
68 theStaticContext->loadProlog("import module namespace httpc = \"http://www.zorba-xquery.com/modules/http-client\";",81 theStaticContext->loadProlog("import module namespace httpc = \"http://www.zorba-xquery.com/modules/http-client\";",
6982
=== modified file 'src/zorbamisc/ns_consts.h'
--- src/zorbamisc/ns_consts.h 2013-06-25 04:47:15 +0000
+++ src/zorbamisc/ns_consts.h 2013-07-11 13:41:52 +0000
@@ -29,13 +29,10 @@
2929
30#define XMLNS_NS W3C_NS "2000/xmlns/"30#define XMLNS_NS W3C_NS "2000/xmlns/"
3131
32#define XML_NS W3C_NS "XML/1998/namespace"
33#define XML_SCHEMA_NS W3C_NS "2001/XMLSchema"
34#define XML_SCHEMA_PREFIX "xs"32#define XML_SCHEMA_PREFIX "xs"
3533
36#define XQUERY_ERR_NS W3C_NS "2005/xqt-errors" //not predeclared in XQuery 3.034#define XQUERY_ERR_NS W3C_NS "2005/xqt-errors" //not predeclared in XQuery 3.0
37#define XQUERY_LOCAL_FN_NS W3C_NS "2005/xquery-local-functions"35#define XQUERY_LOCAL_FN_NS W3C_NS "2005/xquery-local-functions"
38#define XQUERY_XPATH_FN_NS W3C_NS "2005/xpath-functions"
3936
40#define XSI_NS W3C_NS "2001/XMLSchema-instance"37#define XSI_NS W3C_NS "2001/XMLSchema-instance"
4138
4239
=== modified file 'src/zorbaserialization/archiver_consts.h'
--- src/zorbaserialization/archiver_consts.h 2013-06-15 02:57:08 +0000
+++ src/zorbaserialization/archiver_consts.h 2013-07-11 13:41:52 +0000
@@ -378,7 +378,8 @@
378 TYPE_DebuggerSingletonIterator,378 TYPE_DebuggerSingletonIterator,
379 TYPE_DebuggerCommons,379 TYPE_DebuggerCommons,
380380
381 TYPE_RCObject,381 TYPE_SyncedRCObject,
382 TYPE_SimpleRCObject,
382383
383 TYPE_INT64,384 TYPE_INT64,
384 TYPE_UINT64,385 TYPE_UINT64,
385386
=== modified file 'src/zorbaserialization/serialize_zorba_types.cpp'
--- src/zorbaserialization/serialize_zorba_types.cpp 2013-06-30 10:20:25 +0000
+++ src/zorbaserialization/serialize_zorba_types.cpp 2013-07-11 13:41:52 +0000
@@ -1203,7 +1203,7 @@
1203 // store::simplestore::ElementNode *elem_node = dynamic_cast<store::simplestore::ElementNode*>(obj);1203 // store::simplestore::ElementNode *elem_node = dynamic_cast<store::simplestore::ElementNode*>(obj);
1204 // haveTypedValue = elem_node->haveTypedValue();1204 // haveTypedValue = elem_node->haveTypedValue();
1205 // haveEmptyValue = elem_node->haveEmptyValue();1205 // haveEmptyValue = elem_node->haveEmptyValue();
1206 if (!ZSTREQ(name_of_type->getNamespace(), XML_SCHEMA_NS) ||1206 if (name_of_type->getNamespace() != static_context::W3C_XML_SCHEMA_NS ||
1207 !ZSTREQ(name_of_type->getLocalName(), "untyped"))1207 !ZSTREQ(name_of_type->getLocalName(), "untyped"))
1208 haveTypedValue = true;1208 haveTypedValue = true;
1209 }1209 }
12101210
=== modified file 'src/zorbatypes/rchandle.cpp'
--- src/zorbatypes/rchandle.cpp 2013-02-26 04:12:43 +0000
+++ src/zorbatypes/rchandle.cpp 2013-07-11 13:41:52 +0000
@@ -39,12 +39,15 @@
3939
40********************************************************************************/40********************************************************************************/
4141
42SERIALIZABLE_CLASS_VERSIONS(RCObject)42SERIALIZABLE_CLASS_VERSIONS(SyncedRCObject)
4343
44SERIALIZABLE_CLASS_VERSIONS_2(SimpleRCObject, TYPE_RCObject)44SERIALIZABLE_CLASS_VERSIONS_2(SimpleRCObject, TYPE_SimpleRCObject)
4545
4646
47void RCObject::serialize(::zorba::serialization::Archiver& ar)47/*******************************************************************************
48
49********************************************************************************/
50void SyncedRCObject::serialize(::zorba::serialization::Archiver& ar)
48{51{
49 ZORBA_ASSERT(false);52 ZORBA_ASSERT(false);
5053
@@ -53,67 +56,6 @@
53}56}
5457
5558
56void RCObject::addReference(SYNC_CODE(RCLock* lock)) const
57{
58#if defined WIN32 && !defined CYGWIN &&!defined ZORBA_FOR_ONE_THREAD_ONLY
59 if(lock)
60 {
61 InterlockedIncrement(&theRefCount);
62 }
63 else
64 {
65 ++theRefCount;
66 }
67
68#else
69
70 SYNC_CODE(if (lock) lock->acquire());
71
72 ++theRefCount;
73
74 SYNC_CODE(if (lock) lock->release());
75
76#endif
77}
78
79
80void RCObject::removeReference(SYNC_CODE(RCLock* lock))
81{
82#if defined WIN32 && !defined CYGWIN &&!defined ZORBA_FOR_ONE_THREAD_ONLY
83 if (lock)
84 {
85 if (!InterlockedDecrement(&theRefCount))
86 {
87 free();
88 return;
89 }
90 }
91 else
92 {
93 if (--theRefCount == 0)
94 {
95 free();
96 return;
97 }
98 }
99
100#else
101
102 SYNC_CODE(if (lock) lock->acquire());
103
104 if (--theRefCount == 0)
105 {
106 SYNC_CODE(if (lock) lock->release());
107 free();
108 return;
109 }
110
111 SYNC_CODE(if (lock) lock->release());
112
113#endif
114}
115
116
117/*******************************************************************************59/*******************************************************************************
11860
119********************************************************************************/61********************************************************************************/
@@ -125,11 +67,13 @@
125 theRefCount = 0;67 theRefCount = 0;
126}68}
12769
70
128size_t SimpleRCObject::alloc_size() const71size_t SimpleRCObject::alloc_size() const
129{72{
130 return 0;73 return 0;
131}74}
13275
76
133size_t SimpleRCObject::dynamic_size() const77size_t SimpleRCObject::dynamic_size() const
134{78{
135 return sizeof( *this );79 return sizeof( *this );
13680
=== modified file 'src/zorbatypes/rchandle.h'
--- src/zorbatypes/rchandle.h 2013-02-26 04:12:43 +0000
+++ src/zorbatypes/rchandle.h 2013-07-11 13:41:52 +0000
@@ -26,7 +26,7 @@
2626
27#include "zorbautils/fatal.h"27#include "zorbautils/fatal.h"
2828
29#include "zorbatypes/rclock.h"29#include "util/atomic_int.h"
3030
31#include "zorbaserialization/class_serializer.h"31#include "zorbaserialization/class_serializer.h"
3232
@@ -53,15 +53,19 @@
53 reference count becomes 0.53 reference count becomes 0.
5454
55********************************************************************************/55********************************************************************************/
56class ZORBA_DLL_PUBLIC RCObject : public serialization::SerializeBaseClass56class SyncedRCObject : public serialization::SerializeBaseClass
57{57{
58protected:58protected:
59 mutable long theRefCount;59#ifdef ZORBA_FOR_ONE_THREAD_ONLY
60 mutable long theRefCount;
61#else
62 mutable atomic_int theRefCount;
63#endif
6064
61public:65public:
62 SERIALIZABLE_CLASS(RCObject);66 SERIALIZABLE_CLASS(SyncedRCObject);
6367
64 RCObject(::zorba::serialization::Archiver& ar) 68 SyncedRCObject(::zorba::serialization::Archiver& ar)
65 :69 :
66 ::zorba::serialization::SerializeBaseClass(),70 ::zorba::serialization::SerializeBaseClass(),
67 theRefCount(0)71 theRefCount(0)
@@ -71,38 +75,48 @@
71 void serialize(::zorba::serialization::Archiver& ar);75 void serialize(::zorba::serialization::Archiver& ar);
7276
73public:77public:
74 RCObject()78 SyncedRCObject()
75 :79 :
76 ::zorba::serialization::SerializeBaseClass(),80 ::zorba::serialization::SerializeBaseClass(),
77 theRefCount(0)81 theRefCount(0)
78 {82 {
79 }83 }
8084
81 RCObject(const RCObject&) 85 SyncedRCObject(const SyncedRCObject&)
82 :86 :
83 ::zorba::serialization::SerializeBaseClass(),87 ::zorba::serialization::SerializeBaseClass(),
84 theRefCount(0) 88 theRefCount(0)
85 {89 {
86 }90 }
8791
88 virtual ~RCObject() { }92 virtual ~SyncedRCObject() { }
8993
90 RCObject& operator=(const RCObject&) { return *this; }94 SyncedRCObject& operator=(const SyncedRCObject&) { return *this; }
9195
92 virtual void free() { delete this; }96 virtual void free() { delete this; }
9397
98#ifdef ZORBA_FOR_ONE_THREAD_ONLY
94 long getRefCount() const { return theRefCount; }99 long getRefCount() const { return theRefCount; }
95100#else
96 void addReference(SYNC_CODE(RCLock* lock)) const;101 long getRefCount() const { return theRefCount.load(); }
97102#endif
98 void removeReference(SYNC_CODE(RCLock* lock));103
104 void addReference() const { ++theRefCount; }
105
106 void removeReference()
107 {
108 assert(getRefCount() > 0);
109
110 if (--theRefCount == 0)
111 free();
112 }
99};113};
100114
101115
102/*******************************************************************************116/*******************************************************************************
103117
104********************************************************************************/118********************************************************************************/
105class ZORBA_DLL_PUBLIC SimpleRCObject : public serialization::SerializeBaseClass119class SimpleRCObject : public serialization::SerializeBaseClass
106{120{
107protected:121protected:
108 mutable long theRefCount;122 mutable long theRefCount;
@@ -145,17 +159,15 @@
145159
146 long getRefCount() const { return theRefCount; }160 long getRefCount() const { return theRefCount; }
147161
148 void addReference(SYNC_CODE(RCLock* lock)) const { ++theRefCount; }162 void addReference() const { ++theRefCount; }
149163
150 void removeReference(SYNC_CODE(RCLock* lock))164 void removeReference()
151 {165 {
166 assert(getRefCount() > 0);
167
152 if (--theRefCount == 0)168 if (--theRefCount == 0)
153 {
154 free();169 free();
155 }
156 }170 }
157
158 SYNC_CODE(RCLock* getRCLock() const { return NULL; })
159};171};
160172
161173
@@ -200,7 +212,7 @@
200 ~rchandle()212 ~rchandle()
201 {213 {
202 if (p)214 if (p)
203 p->removeReference(SYNC_CODE(p->getRCLock()));215 p->removeReference();
204 p = 0;216 p = 0;
205 }217 }
206218
@@ -255,8 +267,11 @@
255 {267 {
256 if (p != rhs)268 if (p != rhs)
257 {269 {
258 if (p) p->removeReference(SYNC_CODE(p->getRCLock()));270 if (p)
271 p->removeReference();
272
259 p = const_cast<T*>(rhs);273 p = const_cast<T*>(rhs);
274
260 init();275 init();
261 }276 }
262 return *this;277 return *this;
@@ -266,8 +281,11 @@
266 {281 {
267 if (p != rhs)282 if (p != rhs)
268 {283 {
269 if (p) p->removeReference(SYNC_CODE(p->getRCLock()));284 if (p)
285 p->removeReference();
286
270 p = static_cast<T*>(const_cast<otherT*>(rhs));287 p = static_cast<T*>(const_cast<otherT*>(rhs));
288
271 init();289 init();
272 }290 }
273 return *this;291 return *this;
@@ -287,8 +305,11 @@
287 {305 {
288 if (p != rhs.getp())306 if (p != rhs.getp())
289 {307 {
290 if (p) p->removeReference(SYNC_CODE(p->getRCLock()));308 if (p)
309 p->removeReference();
310
291 p = static_cast<T*>(rhs.getp());311 p = static_cast<T*>(rhs.getp());
312
292 rhs.setNull();313 rhs.setNull();
293 }314 }
294 return *this;315 return *this;
@@ -298,7 +319,9 @@
298 {319 {
299 if (p != rhs.p)320 if (p != rhs.p)
300 {321 {
301 if (p) p->removeReference(SYNC_CODE(p->getRCLock()));322 if (p)
323 p->removeReference();
324
302 p = rhs.p;325 p = rhs.p;
303 rhs.p = NULL;326 rhs.p = NULL;
304 }327 }
@@ -323,8 +346,8 @@
323protected:346protected:
324 void init()347 void init()
325 {348 {
326 if (p == 0) return;349 if (p)
327 p->addReference(SYNC_CODE(p->getRCLock()));350 p->addReference();
328 }351 }
329352
330353
@@ -332,8 +355,11 @@
332 {355 {
333 if (p != rhs.getp())356 if (p != rhs.getp())
334 {357 {
335 if (p) p->removeReference(SYNC_CODE(p->getRCLock()));358 if (p)
359 p->removeReference();
360
336 p = static_cast<T*>(rhs.getp());361 p = static_cast<T*>(rhs.getp());
362
337 init();363 init();
338 }364 }
339 return *this;365 return *this;
@@ -363,22 +389,24 @@
363389
364} // namespace ztd390} // namespace ztd
365391
392
366/*******************************************************************************393/*******************************************************************************
367394
368********************************************************************************/395********************************************************************************/
369template<class T> class const_rchandle : protected rchandle<T> 396template<class T> class const_rchandle : protected rchandle<T>
370{397{
371public:398public:
372 const_rchandle (const T *_p = 0) : rchandle<T> (const_cast<T *> (_p)) {}399 const_rchandle(const T* _p = 0) : rchandle<T>(const_cast<T *>(_p)) {}
373400
374 const_rchandle (const const_rchandle &rhs) : rchandle<T> (rhs) {}401 const_rchandle(const const_rchandle& rhs) : rchandle<T>(rhs) {}
375402
376 const_rchandle (rchandle<T> &rhs) : rchandle<T> (rhs) {}403 const_rchandle(rchandle<T>& rhs) : rchandle<T>(rhs) {}
377404
378 const_rchandle(::zorba::serialization::Archiver &ar) {}405 const_rchandle(::zorba::serialization::Archiver& ar) {}
379406
380 const_rchandle& operator= (const const_rchandle &rhs) {407 const_rchandle& operator= (const const_rchandle& rhs)
381 this->assign (rhs);408 {
409 this->assign(rhs);
382 return *this;410 return *this;
383 }411 }
384412
@@ -387,20 +415,20 @@
387415
388 void setNull() { rchandle<T>::setNull();}416 void setNull() { rchandle<T>::setNull();}
389417
390 const T* getp () const { return rchandle<T>::getp (); }418 const T* getp() const { return rchandle<T>::getp (); }
391419
392 typename rchandle<T>::union_T getp_ref() { return rchandle<T>::getp_ref(); }420 typename rchandle<T>::union_T getp_ref() { return rchandle<T>::getp_ref(); }
393421
394 operator const T * () const { return rchandle<T>::getp (); }422 operator const T* () const { return rchandle<T>::getp(); }
395423
396 const T* operator->() const { return getp(); } 424 const T* operator->() const { return getp(); }
397 const T& operator*() const { return *getp(); }425 const T& operator*() const { return *getp(); }
398426
399 bool operator== (const_rchandle h) const { return rchandle<T>::operator== (h); }427 bool operator== (const_rchandle h) const { return rchandle<T>::operator==(h); }
400 bool operator!= (const_rchandle h) const { return rchandle<T>::operator!= (h); }428 bool operator!= (const_rchandle h) const { return rchandle<T>::operator!=(h); }
401 bool operator== (const T * pp) const { return rchandle<T>::operator== (pp); } 429 bool operator== (const T* pp) const { return rchandle<T>::operator==(pp); }
402 bool operator!= (const T * pp) const { return rchandle<T>::operator!= (pp); } 430 bool operator!= (const T* pp) const { return rchandle<T>::operator!=(pp); }
403 bool operator< (const_rchandle h) const { return rchandle<T>::operator< (h); }431 bool operator< (const_rchandle h) const { return rchandle<T>::operator<(h); }
404};432};
405433
406434
@@ -413,13 +441,13 @@
413 template<class T> 441 template<class T>
414 static void addReference(T *t)442 static void addReference(T *t)
415 {443 {
416 t->addReference(SYNC_CODE(t->getRCLock()));444 t->addReference();
417 }445 }
418446
419 template<class T> 447 template<class T>
420 static void removeReference(T *t)448 static void removeReference(T *t)
421 {449 {
422 t->removeReference(SYNC_CODE(t->getRCLock()));450 t->removeReference();
423 }451 }
424452
425 template<class T> 453 template<class T>
426454
=== modified file 'test/driver/testdriver_common.cpp'
--- test/driver/testdriver_common.cpp 2013-05-16 08:22:46 +0000
+++ test/driver/testdriver_common.cpp 2013-07-11 13:41:52 +0000
@@ -280,7 +280,8 @@
280 bool enableDtd,280 bool enableDtd,
281 zorba::DiagnosticHandler& errHandler)281 zorba::DiagnosticHandler& errHandler)
282{282{
283 try {283 try
284 {
284 zorba::Zorba* engine = driverCtx.theEngine;285 zorba::Zorba* engine = driverCtx.theEngine;
285 Specification& spec = *driverCtx.theSpec;286 Specification& spec = *driverCtx.theSpec;
286 zorba::ItemFactory& factory = *engine->getItemFactory();287 zorba::ItemFactory& factory = *engine->getItemFactory();
@@ -336,7 +337,8 @@
336 dctx->setVariable(zorba::String("x"), riter);337 dctx->setVariable(zorba::String("x"), riter);
337 }338 }
338 }339 }
339 catch (zorba::ZorbaException const& e) {340 catch (zorba::ZorbaException const& e)
341 {
340 errHandler.error(e);342 errHandler.error(e);
341 }343 }
342}344}
@@ -457,6 +459,7 @@
457 }459 }
458}460}
459461
462
460/**463/**
461 * Set all options on the provided static context.464 * Set all options on the provided static context.
462 */465 */
@@ -467,7 +470,8 @@
467 for (lIter = spec.optionsBegin(); lIter != spec.optionsEnd(); ++lIter)470 for (lIter = spec.optionsBegin(); lIter != spec.optionsEnd(); ++lIter)
468 {471 {
469 zorba::Item lQName = driverCtx.theEngine->getItemFactory()->472 zorba::Item lQName = driverCtx.theEngine->getItemFactory()->
470 createQName(lIter->theOptName);473 createQName(lIter->theOptName);
474
471 std::string lValue = lIter->theOptValue;475 std::string lValue = lIter->theOptValue;
472 sctx->declareOption(lQName, lValue);476 sctx->declareOption(lQName, lValue);
473 }477 }
@@ -475,41 +479,47 @@
475 if ( spec.getEnableDtd() )479 if ( spec.getEnableDtd() )
476 {480 {
477 zorba::Item lQName = driverCtx.theEngine->getItemFactory()->481 zorba::Item lQName = driverCtx.theEngine->getItemFactory()->
478 createQName(482 createQName("http://www.zorba-xquery.com/options/features", "", "enable");
479 "http://www.zorba-xquery.com/options/features", "", "enable");483
480 sctx->declareOption(lQName, "dtd");484 sctx->declareOption(lQName, "dtd");
481 }485 }
482}486}
483487
488
484/**489/**
485 * Register a URIMapper on the provided static context, and save it490 * Register a URIMapper on the provided static context, and save it
486 * in the DriverContext for later reference.491 * in the DriverContext for later reference.
487 */492 */
488void addURIMapper493void addURIMapper(
489(DriverContext& driverCtx, const zorba::StaticContext_t& sctx,494 DriverContext& driverCtx,
490 zorba::URIMapper* mapper)495 const zorba::StaticContext_t& sctx,
496 zorba::URIMapper* mapper)
491{497{
492 sctx->registerURIMapper(mapper);498 sctx->registerURIMapper(mapper);
493 driverCtx.theURIMappers.push_back(mapper);499 driverCtx.theURIMappers.push_back(mapper);
494}500}
495501
502
496/**503/**
497 * Register a URLResolver on the provided static context, and save it504 * Register a URLResolver on the provided static context, and save it
498 * in the DriverContext for later reference.505 * in the DriverContext for later reference.
499 */506 */
500void addURLResolver507void addURLResolver(
501(DriverContext& driverCtx, const zorba::StaticContext_t& sctx,508 DriverContext& driverCtx,
502 zorba::URLResolver* resolver)509 const zorba::StaticContext_t& sctx,
510 zorba::URLResolver* resolver)
503{511{
504 sctx->registerURLResolver(resolver);512 sctx->registerURLResolver(resolver);
505 driverCtx.theURLResolvers.push_back(resolver);513 driverCtx.theURLResolvers.push_back(resolver);
506}514}
507515
516
508/**517/**
509 * Set all full-text URI mappers on the provided static context.518 * Set all full-text URI mappers on the provided static context.
510 */519 */
511void setFullTextURIMappers520void setFullTextURIMappers(
512(DriverContext& driverCtx, const zorba::StaticContext_t& sctx)521 DriverContext& driverCtx,
522 const zorba::StaticContext_t& sctx)
513{523{
514#ifndef ZORBA_NO_FULL_TEXT524#ifndef ZORBA_NO_FULL_TEXT
515 Specification& spec = * (driverCtx.theSpec);525 Specification& spec = * (driverCtx.theSpec);
@@ -522,8 +532,7 @@
522/**532/**
523 * Set the module paths based on a :- or ;-separated list of paths.533 * Set the module paths based on a :- or ;-separated list of paths.
524 */534 */
525void setModulePaths535void setModulePaths(std::string paths, zorba::StaticContext_t& sctx)
526(std::string paths, zorba::StaticContext_t& sctx)
527{536{
528 std::vector<zorba::String> lModulePaths;537 std::vector<zorba::String> lModulePaths;
529 std::string lPath;538 std::string lPath;
@@ -533,15 +542,19 @@
533 char lDelim = ':';542 char lDelim = ':';
534#endif543#endif
535544
536 while (zorba::ztd::split(paths, lDelim, &lPath, &paths)) {545 while (zorba::ztd::split(paths, lDelim, &lPath, &paths))
546 {
537 lModulePaths.push_back(lPath);547 lModulePaths.push_back(lPath);
538 }548 }
549
539 lModulePaths.push_back(paths);550 lModulePaths.push_back(paths);
540551
541 // Add the default paths for test modules.552 // Add the default paths for test modules.
542 zorba::String lDefPath = zorba::CMAKE_BINARY_DIR + "/TEST_URI_PATH";553 zorba::String lDefPath = zorba::CMAKE_BINARY_DIR + "/TEST_URI_PATH";
543 lModulePaths.push_back(lDefPath);554 lModulePaths.push_back(lDefPath);
555
544 lDefPath = zorba::CMAKE_BINARY_DIR + "/TEST_LIB_PATH";556 lDefPath = zorba::CMAKE_BINARY_DIR + "/TEST_LIB_PATH";
545 lModulePaths.push_back(lDefPath);557 lModulePaths.push_back(lDefPath);
558
546 sctx->setModulePaths(lModulePaths);559 sctx->setModulePaths(lModulePaths);
547}560}
548561
=== modified file 'test/driver/testdriver_common.h'
--- test/driver/testdriver_common.h 2013-05-16 08:22:46 +0000
+++ test/driver/testdriver_common.h 2013-07-11 13:41:52 +0000
@@ -93,10 +93,11 @@
93 << "[line " << xe->source_line() << "]"93 << "[line " << xe->source_line() << "]"
94 << "[column " << xe->source_column() << "]"94 << "[column " << xe->source_column() << "]"
95 << "[file " << xe->source_uri() << "]";95 << "[file " << xe->source_uri() << "]";
96 if(zorba::UserException const *ue = dynamic_cast<zorba::UserException const*>(&e))96
97 if (zorba::UserException const *ue = dynamic_cast<zorba::UserException const*>(&e))
97 {98 {
98 zorba::UserException::error_object_type const & err_objs = ue->error_object();99 zorba::UserException::error_object_type const & err_objs = ue->error_object();
99 if(!err_objs.empty())100 if (!err_objs.empty())
100 {101 {
101 strdescr << " and ..." << std::endl << "User parameters:";102 strdescr << " and ..." << std::endl << "User parameters:";
102 for(size_t i=0;i<err_objs.size();i++)103 for(size_t i=0;i<err_objs.size();i++)
103104
=== modified file 'test/driver/testdriver_mt.cpp'
--- test/driver/testdriver_mt.cpp 2013-06-25 07:47:47 +0000
+++ test/driver/testdriver_mt.cpp 2013-07-11 13:41:52 +0000
@@ -58,70 +58,112 @@
58std::string module_path;58std::string module_path;
5959
60/*******************************************************************************60/*******************************************************************************
61 theQueriesDir : The full pathname of the dir that contains the queries61
62 to run. It is created by appending the user-provided62 theQueriesDir
63 bucket name to RBKT_SRC_DIR/Queries (for example,63 -------------
64 RBKT_SRC_DIR/Queries/w3c_testsuite/Expressions).64 The full pathname of the dir that contains the queries to run. It is a path
65 theRefsDir : The full pathname of the dir that contains the expected65 of the form <bucket-path>/Queries/<bucket-name>, where <bucket-path> is either
66 results of the queries. It is created by appending the66 a user-provided absolute dir path, or RBKT_BINARY_DIR and <bucket-name> is a
67 user-provided bucket name to RBKT_SRC_DIR/ExpQueryResults.67 user-provided bucket name (actually a relative dir path, which may also be
68 theResultsDir : The full pathname of the directory under which the result68 empty).
69 and error files of the queries will be placed. It is69
70 created by appending the user-provided bucket name to70 theRefsDir
71 RBKT_BINARY_DIR/QueryResults.71 ----------
7272 The full pathname of the dir that contains the expected results of the queries.
73 theQueryFilenames : The relative pathnames of the queries found under73 It is a path of the form <bucket-path>/ExpQueryResults/<bucket-name>, where
74 theQueriesDir. The pathname are relative to theQueriesDir.74 <bucket-path> is either a user-provided absolute dir path, or RBKT_BINARY_DIR
7575 and <bucket-name> is a user-provided bucket name (actually a relative dir path,
76 theNumQueries : The number of queries found under theQueriesDir.76 which may also be empty).
7777
78 theNumRunsPerQuery : The number of times to run each query.78 theResultsDir
7979 -------------
80 theNumQueryRuns : How many times has each query being run so far.80 The full pathname of the directory under which the result and error files of
8181 the queries will be placed. It is a path of the form
82 theQueryObjects : Pointers to the compiled query object for each query.82 RBKT_BINARY_DIR/QueryResults/<bucket-name>.
8383
84 theQueryStates : For each query, whether the query was run successfuly or not.84 theIsW3Cbucket
8585 --------------
86 theQueryLocks :86 Whether the user-provided bucket is inside W3C XQTS.
87 theGlobalLock :87
88 theQueryFilenames
89 -----------------
90 The relative pathnames of the queries found under theQueriesDir. The pathnames
91 are relative to theQueriesDir.
92
93 theNumQueries
94 -------------
95 The number of queries found under theQueriesDir.
96
97 theNumRunsPerQuery
98 ------------------
99 The number of times to run each query.
100
101 theNumThreads
102 -------------
103 The number of threads to use.
104
105 theOutput
106 ---------
107 The stream where the output should go to.
108
109
110 theNumQueryRuns
111 ---------------
112 How many times has each query being run so far.
113
114 theQueryStates
115 --------------
116 For each query, whether the query was run successfuly or not.
117
118 theQueryLocks :
119 ---------------
120 One lock per query. It is needed to protect theQueryObjects[queryNo] position.
121
122 theGlobalLock :
123 ---------------
124 Acquired while the next query to be run is selected and locked by each thread.
88125
89********************************************************************************/126********************************************************************************/
90class Queries127class Queries
91{128{
92public:129public:
93 std::string theQueriesDir;130 std::string theQueriesDir;
131
94 std::string theRefsDir;132 std::string theRefsDir;
133
95 std::string theResultsDir;134 std::string theResultsDir;
96135
136 bool theIsW3Cbucket;
137
97 std::vector<std::string> theQueryFilenames;138 std::vector<std::string> theQueryFilenames;
98139
99 bool theIsW3Cbucket;
100
101 long theNumQueries;140 long theNumQueries;
102141
103 long theNumRunsPerQuery;142 long theNumRunsPerQuery;
104143
144 long theNumThreads;
145
146 std::ostream& theOutput;
147
148
105 std::vector<long> theNumQueryRuns;149 std::vector<long> theNumQueryRuns;
106150
107 std::vector<zorba::XQuery_t> theQueryObjects;
108
109 std::vector<bool> theQueryStates;151 std::vector<bool> theQueryStates;
110152
111 long theNumThreads;
112
113 std::ostream& theOutput;
114
115 std::vector<zorba::Mutex*> theQueryLocks;153 std::vector<zorba::Mutex*> theQueryLocks;
154
116 zorba::Mutex theGlobalLock;155 zorba::Mutex theGlobalLock;
117156
118public:157public:
119 Queries(std::ostream& lOutput)158 Queries(std::ostream& output)
120 :159 :
160 theIsW3Cbucket(false),
161 theNumQueries(0),
121 theNumRunsPerQuery(1),162 theNumRunsPerQuery(1),
122 theNumThreads(1),163 theNumThreads(1),
123 theOutput(lOutput)164 theOutput(output)
124 {}165 {
166 }
125167
126 ~Queries();168 ~Queries();
127169
@@ -131,47 +173,55 @@
131};173};
132174
133175
176/*******************************************************************************
177
178********************************************************************************/
134Queries::~Queries()179Queries::~Queries()
135{180{
136 clear();181 clear();
137}182}
138183
139184
185/*******************************************************************************
186
187********************************************************************************/
140void Queries::clear()188void Queries::clear()
141{189{
142 for (long i = 0; i < theNumQueries; i++)190 for (long i = 0; i < theNumQueries; i++)
143 {191 {
144 theQueryObjects[i] = NULL;
145 delete theQueryLocks[i];192 delete theQueryLocks[i];
146 }193 }
147194
148 theQueryFilenames.clear();195 theQueryFilenames.clear();
149 theNumQueryRuns.clear();196 theNumQueryRuns.clear();
150 theQueryObjects.clear();197 theQueryStates.clear();
151198
152 theNumQueries = 0;199 theNumQueries = 0;
153}200}
154201
155202
203/*******************************************************************************
204 Invoked under the protection of theGlobalLock.
205********************************************************************************/
156long Queries::getQuery()206long Queries::getQuery()
157{207{
158 static long nextQuery = 0;208 static long currQuery = 0;
159209
160 if (theNumThreads == 1)210 if (theNumThreads == 1)
161 {211 {
162 if (nextQuery == theNumQueries)212 if (currQuery == theNumQueries)
163 return -1;213 return -1;
164214
165 if (theNumQueryRuns[nextQuery] == theNumRunsPerQuery)215 if (theNumQueryRuns[currQuery] == theNumRunsPerQuery)
166 {216 {
167 ++nextQuery;217 ++currQuery;
168218
169 if (nextQuery == theNumQueries)219 if (currQuery == theNumQueries)
170 return -1;220 return -1;
171 }221 }
172222
173 theNumQueryRuns[nextQuery]++;223 theNumQueryRuns[currQuery]++;
174 return nextQuery;224 return currQuery;
175 }225 }
176226
177 long randomNum = rand();227 long randomNum = rand();
@@ -236,48 +286,60 @@
236void createPath(const fs::path& filePath, std::ofstream& fileStream)286void createPath(const fs::path& filePath, std::ofstream& fileStream)
237{287{
238#if !defined(BOOST_FILESYSTEM_VERSION) || BOOST_FILESYSTEM_VERSION == 2288#if !defined(BOOST_FILESYSTEM_VERSION) || BOOST_FILESYSTEM_VERSION == 2
289
239 fileStream.open(filePath.file_string().c_str());290 fileStream.open(filePath.file_string().c_str());
291
292 if (!fileStream.good())
293 {
294 fs::path dirPath = filePath;
295 dirPath = dirPath.remove_leaf();
296
297 if (!fs::exists(dirPath.file_string()))
298 {
299 fs::create_directories(dirPath.file_string());
300
301 // clear the bad flag on windows, which for some unknown reason doesn't
302 // reset when opening a file again
303 fileStream.clear();
304
305 fileStream.open(filePath.file_string().c_str());
306 }
307
308 if (!fileStream.good())
309 {
310 std::cerr << "Could not open file: "
311 << filePath.file_string() << std::endl;
312 abort();
313 }
314 }
315
240#else316#else
317
241 fileStream.open(filePath.generic_string().c_str());318 fileStream.open(filePath.generic_string().c_str());
242#endif319
243 if (!fileStream.good())320 if (!fileStream.good())
244 {321 {
245 fs::path dirPath = filePath;322 fs::path dirPath = filePath;
246 dirPath = dirPath.remove_leaf();323 dirPath = dirPath.remove_leaf();
247 324
248#if !defined(BOOST_FILESYSTEM_VERSION) || BOOST_FILESYSTEM_VERSION == 2
249 if (!fs::exists(dirPath.file_string()))
250#else
251 if (!fs::exists(dirPath.generic_string()))325 if (!fs::exists(dirPath.generic_string()))
252#endif
253 {326 {
254#if !defined(BOOST_FILESYSTEM_VERSION) || BOOST_FILESYSTEM_VERSION == 2
255 fs::create_directories(dirPath.file_string());
256#else
257 fs::create_directories(dirPath.generic_string());327 fs::create_directories(dirPath.generic_string());
258#endif
259328
260 // clear the bad flag on windows, which for some unknown reason doesn't329 // clear the bad flag on windows, which for some unknown reason doesn't
261 // reset when opening a file again330 // reset when opening a file again
262 fileStream.clear(); 331 fileStream.clear();
263#if !defined(BOOST_FILESYSTEM_VERSION) || BOOST_FILESYSTEM_VERSION == 2
264 fileStream.open(filePath.file_string().c_str());
265#else
266 fileStream.open(filePath.generic_string().c_str());332 fileStream.open(filePath.generic_string().c_str());
267#endif
268 }333 }
269334
270 if (!fileStream.good())335 if (!fileStream.good())
271 {336 {
272 std::cerr << "Could not open file: " 337 std::cerr << "Could not open file: "
273#if !defined(BOOST_FILESYSTEM_VERSION) || BOOST_FILESYSTEM_VERSION == 2
274 << filePath.file_string() << std::endl;
275#else
276 << filePath.generic_string() << std::endl;338 << filePath.generic_string() << std::endl;
277#endif
278 abort();339 abort();
279 }340 }
280 }341 }
342#endif
281}343}
282344
283345
@@ -338,18 +400,16 @@
338400
339 ulong numCanon = 0;401 ulong numCanon = 0;
340402
341 long queryNo;
342
343 std::string w3cDataDir = "/Queries/w3c_testsuite/TestSources/";403 std::string w3cDataDir = "/Queries/w3c_testsuite/TestSources/";
344 std::string uri_map_file = rbkt_src_dir + w3cDataDir + "uri.txt";404 std::string uri_map_file = rbkt_src_dir + w3cDataDir + "uri.txt";
345 std::string mod_map_file = rbkt_src_dir + w3cDataDir + "module.txt";405 std::string mod_map_file = rbkt_src_dir + w3cDataDir + "module.txt";
346 std::string col_map_file = rbkt_src_dir + w3cDataDir + "collection.txt";406 std::string col_map_file = rbkt_src_dir + w3cDataDir + "collection.txt";
347407
348 std::auto_ptr<zorba::TestSchemaURIMapper> smapper408 std::auto_ptr<zorba::TestSchemaURIMapper> smapper;
349 (new zorba::TestSchemaURIMapper(uri_map_file.c_str(), false));
350 std::auto_ptr<zorba::TestModuleURIMapper> mmapper;409 std::auto_ptr<zorba::TestModuleURIMapper> mmapper;
351 std::auto_ptr<zorba::TestCollectionURIMapper> cmapper;410 std::auto_ptr<zorba::TestCollectionURIMapper> cmapper;
352 std::auto_ptr<zorba::TestSchemeURIMapper> dmapper;411
412 std::auto_ptr<zorba::TestSchemeURIMapper> dmapper;
353 std::auto_ptr<zorba::TestURLResolver> tresolver;413 std::auto_ptr<zorba::TestURLResolver> tresolver;
354414
355 while (1)415 while (1)
@@ -374,34 +434,23 @@
374 driverContext.theRbktBinaryDir = rbkt_bin_dir;434 driverContext.theRbktBinaryDir = rbkt_bin_dir;
375 driverContext.theSpec = &querySpec;435 driverContext.theSpec = &querySpec;
376436
377 zorba::XQuery_t query;
378
379 // Choose a query to run. If no query is available, the thread finishes. 437 // Choose a query to run. If no query is available, the thread finishes.
380 // To choose the next query, the whole query container must be locked.438 // To choose the next query, the whole query container must be locked.
381 // After the query is chosen, we release the global container lock and439 // After the query is chosen, we release the global container lock and
382 // acquire the query-specific lock for the chosen query. The query lock440 // acquire the query-specific lock for the chosen query.
383 // is needed to protect the queries->theQueryObjects[queryNo] position and
384 // to make sure that the query will be compiled only once.
385 queries->theGlobalLock.lock();441 queries->theGlobalLock.lock();
386442
387 queryNo = queries->getQuery();443 long queryNo = queries->getQuery();
388444
389 if (queryNo < 0)445 if (queryNo < 0)
390 {446 {
391 queries->theOutput << "Thread " << tno << " finished " << std::endl;447 queries->theOutput << "Thread " << tno << " finished " << std::endl
392 queries->theOutput << std::endl << "Number of canonicaliations = " << numCanon << std::endl;448 << std::endl << "Number of canonicaliations = "
449 << numCanon << std::endl;
393 queries->theGlobalLock.unlock();450 queries->theGlobalLock.unlock();
394 return 0;451 return 0;
395 }452 }
396453
397 queries->theQueryLocks[queryNo]->lock();
398 queries->theGlobalLock.unlock();
399#ifndef WIN32
400 sched_yield();
401#else
402 // SwitchToThread();
403#endif
404
405 // Form the full pathname for the file containing the query.454 // Form the full pathname for the file containing the query.
406 relativeQueryFile = queries->theQueryFilenames[queryNo];455 relativeQueryFile = queries->theQueryFilenames[queryNo];
407 queryPath = fs::path(queries->theQueriesDir) / (relativeQueryFile);456 queryPath = fs::path(queries->theQueriesDir) / (relativeQueryFile);
@@ -411,11 +460,23 @@
411#else460#else
412 std::string testName = fs::change_extension(queryPath, "").generic_string();461 std::string testName = fs::change_extension(queryPath, "").generic_string();
413#endif462#endif
463
414 ulong pos = testName.find("Queries");464 ulong pos = testName.find("Queries");
415 testName = testName.substr(pos + 8);465 testName = testName.substr(pos + 8);
416466
417 queries->theOutput << "*** " << queryNo << " : " << testName467 queries->theOutput << "*** " << queryNo << " : " << testName
418 << " by thread " << tno << std::endl << std::endl;468 << " by thread " << tno << " runNo : "
469 << queries->theNumQueryRuns[queryNo]
470 << std::endl << std::endl;
471
472 queries->theQueryLocks[queryNo]->lock();
473 queries->theGlobalLock.unlock();
474
475#ifndef WIN32
476 sched_yield();
477#else
478 // SwitchToThread();
479#endif
419480
420 // Form the full pathname for the .spec file that may be associated481 // Form the full pathname for the .spec file that may be associated
421 // with this query. If the .spec file exists, read its contents to482 // with this query. If the .spec file exists, read its contents to
@@ -423,11 +484,13 @@
423 // exprected errors, or the pathnames of reference-result files.484 // exprected errors, or the pathnames of reference-result files.
424 specPath = fs::change_extension(queryPath, ".spec");485 specPath = fs::change_extension(queryPath, ".spec");
425 if (fs::exists(specPath))486 if (fs::exists(specPath))
487 {
426#if !defined(BOOST_FILESYSTEM_VERSION) || BOOST_FILESYSTEM_VERSION == 2488#if !defined(BOOST_FILESYSTEM_VERSION) || BOOST_FILESYSTEM_VERSION == 2
427 querySpec.parseFile(specPath.file_string(), rbkt_src_dir, rbkt_bin_dir); 489 querySpec.parseFile(specPath.file_string(), rbkt_src_dir, rbkt_bin_dir);
428#else490#else
429 querySpec.parseFile(specPath.generic_string(), rbkt_src_dir, rbkt_bin_dir);491 querySpec.parseFile(specPath.generic_string(), rbkt_src_dir, rbkt_bin_dir);
430#endif492#endif
493 }
431494
432 // Get the pathnames of the ref-result files found in the .spec file (if any).495 // Get the pathnames of the ref-result files found in the .spec file (if any).
433 // If no ref-results file was specified in the .spec file, create a default496 // If no ref-results file was specified in the .spec file, create a default
@@ -446,6 +509,7 @@
446 if (refFilePaths.size() == 0) 509 if (refFilePaths.size() == 0)
447 {510 {
448 std::string relativeRefFile = relativeQueryFile;511 std::string relativeRefFile = relativeQueryFile;
512
449 if (queries->theIsW3Cbucket)513 if (queries->theIsW3Cbucket)
450 {514 {
451 ulong pos;515 ulong pos;
@@ -481,28 +545,32 @@
481 createPath(resultFilePath, resFileStream);545 createPath(resultFilePath, resFileStream);
482 createPath(errorFilePath, errFileStream);546 createPath(errorFilePath, errFileStream);
483547
548 queries->theQueryLocks[queryNo]->unlock();
549
484 // Create the static context. If this is a w3c query, install special uri550 // Create the static context. If this is a w3c query, install special uri
485 // resolvers in the static context.551 // resolvers in the static context.
486 zorba::StaticContext_t sctx = zorba->createStaticContext();552 zorba::StaticContext_t sctx = zorba->createStaticContext();
487553
488 if (queries->theIsW3Cbucket) 554 if (queries->theIsW3Cbucket)
489 {555 {
490 mmapper.reset556 smapper.reset(
491 (new zorba::TestModuleURIMapper(mod_map_file.c_str(),557 new zorba::TestSchemaURIMapper(uri_map_file.c_str(), false));
492 testName, false));558
493 cmapper.reset(new zorba::TestCollectionURIMapper(559 mmapper.reset(
494 col_map_file.c_str(), rbkt_src_dir));560 new zorba::TestModuleURIMapper(mod_map_file.c_str(), testName, false));
561
562 cmapper.reset(
563 new zorba::TestCollectionURIMapper(col_map_file.c_str(), rbkt_src_dir));
564
495 addURIMapper(driverContext, sctx, smapper.get());565 addURIMapper(driverContext, sctx, smapper.get());
496 addURIMapper(driverContext, sctx, mmapper.get());566 addURIMapper(driverContext, sctx, mmapper.get());
497 addURIMapper(driverContext, sctx, cmapper.get());567 addURIMapper(driverContext, sctx, cmapper.get());
498568
499 sctx->setXQueryVersion(zorba::xquery_version_1_0);569 sctx->setXQueryVersion(zorba::xquery_version_1_0);
500 zorba::Item lEnable570
501 = zorba->getItemFactory()->createQName(571 zorba::Item lDisable = zorba->getItemFactory()->
502 "http://www.zorba-xquery.com/options/features", "", "enable");572 createQName("http://www.zorba-xquery.com/options/features", "", "disable");
503 zorba::Item lDisable573
504 = zorba->getItemFactory()->createQName(
505 "http://www.zorba-xquery.com/options/features", "", "disable");
506 sctx->declareOption(lDisable, "scripting");574 sctx->declareOption(lDisable, "scripting");
507 sctx->setTraceStream(queries->theOutput);575 sctx->setTraceStream(queries->theOutput);
508 }576 }
@@ -513,6 +581,7 @@
513 {581 {
514 dmapper.reset(new zorba::TestSchemeURIMapper(rbkt_src_dir));582 dmapper.reset(new zorba::TestSchemeURIMapper(rbkt_src_dir));
515 addURIMapper(driverContext, sctx, dmapper.get());583 addURIMapper(driverContext, sctx, dmapper.get());
584
516 tresolver.reset(new zorba::TestURLResolver());585 tresolver.reset(new zorba::TestURLResolver());
517 addURLResolver(driverContext, sctx, tresolver.get());586 addURLResolver(driverContext, sctx, tresolver.get());
518 }587 }
@@ -535,82 +604,63 @@
535#endif604#endif
536605
537 //606 //
538 // Compile the query, if it has not been compiled already. 607 // Create the query and register the error handler with it.
539 //608 //
540 if (queries->theQueryObjects[queryNo] == 0)609 zorba::XQuery_t query = zorba->createQuery(&errHandler);
541 {
542#if !defined(BOOST_FILESYSTEM_VERSION) || BOOST_FILESYSTEM_VERSION == 2
543 slurp_file(queryPath.file_string().c_str(),
544 queryString,
545 rbkt_src_dir,
546 rbkt_bin_dir);
547#else
548 slurp_file(queryPath.generic_string().c_str(),
549 queryString,
550 rbkt_src_dir,
551 rbkt_bin_dir);
552#endif
553
554
555 try
556 {
557 query = zorba->createQuery(&errHandler);
558
559#if !defined(BOOST_FILESYSTEM_VERSION) || BOOST_FILESYSTEM_VERSION == 2
560 query->setFileName(queryPath.file_string());
561#else
562 query->setFileName(queryPath.generic_string());
563#endif
564 query->compile(queryString.c_str(), sctx, getCompilerHints());
565 }
566 catch(...)
567 {
568 queries->theOutput << "FAILURE : thread " << tno << " query " << queryNo
569 << " : " << queries->theQueryFilenames[queryNo]
570 << std::endl
571 << "Reason: received an unexpected exception during compilation"
572 << std::endl << std::endl;
573
574 queries->theQueryLocks[queryNo]->unlock();
575 failure = true;
576 goto done;
577 }
578
579 if (errHandler.errors())
580 {
581 if (checkErrors(querySpec, errHandler, queries->theOutput))
582 {
583 queries->theQueryLocks[queryNo]->unlock();
584 goto done;
585 }
586 else
587 {
588 queries->theOutput << "FAILURE : thread " << tno << " query " << queryNo
589 << " : " << queries->theQueryFilenames[queryNo]
590 << std::endl
591 << "Reason: received the following unexpected compilation errors : ";
592 printErrors(errHandler, NULL, false, queries->theOutput);
593 queries->theOutput << std::endl << std::endl;
594
595 queries->theQueryLocks[queryNo]->unlock();
596 failure = true;
597 goto done;
598 }
599 }
600
601 queries->theQueryObjects[queryNo] = query;
602 }
603
604 queries->theQueryLocks[queryNo]->unlock();
605
606 //
607 // Clone the compiled query and register with it the error handler of the
608 // current thread.
609 //
610 query = queries->theQueryObjects[queryNo]->clone();
611610
612 query->registerDiagnosticHandler(&errHandler);611 query->registerDiagnosticHandler(&errHandler);
613612
613 //
614 // Compile the query
615 //
616#if !defined(BOOST_FILESYSTEM_VERSION) || BOOST_FILESYSTEM_VERSION == 2
617 slurp_file(queryPath.file_string().c_str(),
618 queryString, rbkt_src_dir, rbkt_bin_dir);
619#else
620 slurp_file(queryPath.generic_string().c_str(),
621 queryString, rbkt_src_dir, rbkt_bin_dir);
622#endif
623
624 try
625 {
626#if !defined(BOOST_FILESYSTEM_VERSION) || BOOST_FILESYSTEM_VERSION == 2
627 query->setFileName(queryPath.file_string());
628#else
629 query->setFileName(queryPath.generic_string());
630#endif
631
632 query->compile(queryString.c_str(), sctx, getCompilerHints());
633 }
634 catch(...)
635 {
636 queries->theOutput << "FAILURE : thread " << tno << " query " << queryNo
637 << " : " << queries->theQueryFilenames[queryNo]
638 << std::endl
639 << "Reason: received an unexpected exception during compilation"
640 << std::endl << std::endl;
641 failure = true;
642 goto done;
643 }
644
645 if (errHandler.errors())
646 {
647 if (checkErrors(querySpec, errHandler, queries->theOutput))
648 {
649 goto done;
650 }
651 else
652 {
653 queries->theOutput << "FAILURE : thread " << tno << " query " << queryNo
654 << " : " << queries->theQueryFilenames[queryNo]
655 << std::endl
656 << "Reason: received the following unexpected compilation errors : ";
657 printErrors(errHandler, NULL, false, queries->theOutput);
658 queries->theOutput << std::endl << std::endl;
659
660 failure = true;
661 goto done;
662 }
663 }
614664
615 //665 //
616 // Execute the query666 // Execute the query
@@ -628,6 +678,7 @@
628 lSerOptions.indent = ZORBA_INDENT_NO;678 lSerOptions.indent = ZORBA_INDENT_NO;
629679
630 query->execute(resFileStream, &lSerOptions);680 query->execute(resFileStream, &lSerOptions);
681
631 resFileStream.close();682 resFileStream.close();
632 }683 }
633 }684 }
@@ -661,7 +712,8 @@
661 }712 }
662 }713 }
663 else if (querySpec.getComparisonMethod() != "Ignore" 714 else if (querySpec.getComparisonMethod() != "Ignore"
664 && querySpec.errorsSize() > 0 && !refFileSpecified)715 && querySpec.errorsSize() > 0 &&
716 !refFileSpecified)
665 {717 {
666 queries->theOutput << "FAILURE : thread " << tno << " query " << queryNo718 queries->theOutput << "FAILURE : thread " << tno << " query " << queryNo
667 << " : " << queries->theQueryFilenames[queryNo]719 << " : " << queries->theQueryFilenames[queryNo]
@@ -756,6 +808,9 @@
756}808}
757809
758810
811/*******************************************************************************
812
813********************************************************************************/
759void usage()814void usage()
760{815{
761 std::cerr << "\nusage: testdriver_mt -b <bucket> [options] OR" << std::endl816 std::cerr << "\nusage: testdriver_mt -b <bucket> [options] OR" << std::endl
@@ -769,6 +824,9 @@
769}824}
770825
771826
827/*******************************************************************************
828
829********************************************************************************/
772int830int
773#ifdef _WIN32_WCE831#ifdef _WIN32_WCE
774_tmain(int argc, _TCHAR* argv[])832_tmain(int argc, _TCHAR* argv[])
@@ -878,16 +936,20 @@
878 // This is a cheap and easy way to make a "null" ostream:936 // This is a cheap and easy way to make a "null" ostream:
879 std::ostringstream nullstream;937 std::ostringstream nullstream;
880 nullstream.clear(std::ios::badbit);938 nullstream.clear(std::ios::badbit);
939
940 //
941 // Create the query manager
942 //
881 Queries queries(quiet ? nullstream : std::cout);943 Queries queries(quiet ? nullstream : std::cout);
944
882 queries.theNumRunsPerQuery = numRunsPerQuery;945 queries.theNumRunsPerQuery = numRunsPerQuery;
883 queries.theNumThreads = numThreads;946 queries.theNumThreads = numThreads;
884947
885 // Unfortunately there are still places SOMEwhere (in zorba? in a948 // Unfortunately there are still places SOMEwhere (in zorba? in a dependent
886 // dependent library?) that output to stderr. It's important for the949 // library?) that output to stderr. It's important for the remote queue in
887 // remote queue in particular that -q actually work, so we attempt950 // particular that -q actually work, so we attempt to shut them up here.
888 // to shut them up here. QQQ if we can figure out where those951 // QQQ if we can figure out where those messages are coming from it would be
889 // messages are coming from it would be better to fix those than952 // better to fix those than take this heavy-handed approach.
890 // take this heavy-handed approach.
891 if (quiet) 953 if (quiet)
892 {954 {
893#ifndef WIN32955#ifndef WIN32
@@ -904,8 +966,6 @@
904 if (bucketPath == "") 966 if (bucketPath == "")
905 {967 {
906 bucketPath = zorba::RBKT_SRC_DIR;968 bucketPath = zorba::RBKT_SRC_DIR;
907 // QQQ Probably should have an option for specifying alternative
908 // resultsDir too
909 }969 }
910 else 970 else
911 {971 {
@@ -927,7 +987,9 @@
927 testExtension = ".xqx";987 testExtension = ".xqx";
928 }988 }
929 else if ((pos = refsDir.find("XQuery")) != std::string::npos)989 else if ((pos = refsDir.find("XQuery")) != std::string::npos)
990 {
930 refsDir = refsDir.erase(pos, 7);991 refsDir = refsDir.erase(pos, 7);
992 }
931 }993 }
932994
933 reportFilepath = zorba::RBKT_BINARY_DIR + "/../../Testing/" + reportFilename;995 reportFilepath = zorba::RBKT_BINARY_DIR + "/../../Testing/" + reportFilename;
@@ -945,38 +1007,35 @@
945#else1007#else
946 path = fs::system_complete(fs::path(queriesDir));1008 path = fs::system_complete(fs::path(queriesDir));
947#endif1009#endif
1010
948 if (!fs::is_directory(path))1011 if (!fs::is_directory(path))
949 {1012 {
950 std::cerr << "The directory " << queriesDir << " could not be found" << std::endl;1013 std::cerr << "The directory " << queriesDir << " could not be found" << std::endl;
951 exit(2);1014 exit(2);
952 }1015 }
1016
953#if !defined(BOOST_FILESYSTEM_VERSION) || BOOST_FILESYSTEM_VERSION == 21017#if !defined(BOOST_FILESYSTEM_VERSION) || BOOST_FILESYSTEM_VERSION == 2
954 queries.theQueriesDir = path.file_string();1018 queries.theQueriesDir = path.file_string();
1019 path = fs::system_complete(fs::path(refsDir, fs::native));
955#else1020#else
956 queries.theQueriesDir = path.generic_string();1021 queries.theQueriesDir = path.generic_string();
957#endif
958
959#if !defined(BOOST_FILESYSTEM_VERSION) || BOOST_FILESYSTEM_VERSION == 2
960 path = fs::system_complete(fs::path(refsDir, fs::native));
961#else
962 path = fs::system_complete(fs::path(refsDir));1022 path = fs::system_complete(fs::path(refsDir));
963#endif1023#endif
1024
964 if (!fs::is_directory(path))1025 if (!fs::is_directory(path))
965 {1026 {
966 std::cerr << "The directory " << refsDir << " could not be found" << std::endl;1027 std::cerr << "The directory " << refsDir << " could not be found" << std::endl;
967 exit(2);1028 exit(2);
968 }1029 }
1030
969#if !defined(BOOST_FILESYSTEM_VERSION) || BOOST_FILESYSTEM_VERSION == 21031#if !defined(BOOST_FILESYSTEM_VERSION) || BOOST_FILESYSTEM_VERSION == 2
970 queries.theRefsDir = path.native_directory_string();1032 queries.theRefsDir = path.native_directory_string();
1033 path = fs::system_complete(fs::path(resultsDir, fs::native));
971#else1034#else
972 queries.theRefsDir = path.parent_path().generic_string();1035 queries.theRefsDir = path.parent_path().generic_string();
973#endif
974
975#if !defined(BOOST_FILESYSTEM_VERSION) || BOOST_FILESYSTEM_VERSION == 2
976 path = fs::system_complete(fs::path(resultsDir, fs::native));
977#else
978 path = fs::system_complete(fs::path(resultsDir));1036 path = fs::system_complete(fs::path(resultsDir));
979#endif1037#endif
1038
980 if (!fs::exists(path))1039 if (!fs::exists(path))
981 {1040 {
982 fs::create_directories(path);1041 fs::create_directories(path);
@@ -986,6 +1045,7 @@
986 std::cerr << "The pathname " << resultsDir << " is not a directory" << std::endl;1045 std::cerr << "The pathname " << resultsDir << " is not a directory" << std::endl;
987 exit(2);1046 exit(2);
988 }1047 }
1048
989#if !defined(BOOST_FILESYSTEM_VERSION) || BOOST_FILESYSTEM_VERSION == 21049#if !defined(BOOST_FILESYSTEM_VERSION) || BOOST_FILESYSTEM_VERSION == 2
990 queries.theResultsDir = path.native_directory_string();1050 queries.theResultsDir = path.native_directory_string();
991#else1051#else
@@ -1045,7 +1105,6 @@
1045 // Prepare the Queries container1105 // Prepare the Queries container
1046 //1106 //
1047 queries.theNumQueryRuns.resize(queries.theNumQueries);1107 queries.theNumQueryRuns.resize(queries.theNumQueries);
1048 queries.theQueryObjects.resize(queries.theNumQueries);
1049 queries.theQueryLocks.resize(queries.theNumQueries);1108 queries.theQueryLocks.resize(queries.theNumQueries);
1050 queries.theQueryStates.resize(queries.theNumQueries);1109 queries.theQueryStates.resize(queries.theNumQueries);
10511110
10521111
=== modified file 'test/rbkt/Queries/zorba/updates/forms.xsd'
--- test/rbkt/Queries/zorba/updates/forms.xsd 2012-06-01 08:35:24 +0000
+++ test/rbkt/Queries/zorba/updates/forms.xsd 2013-07-11 13:41:52 +0000
@@ -11,7 +11,7 @@
11 </xs:sequence>11 </xs:sequence>
12 </xs:complexType>12 </xs:complexType>
1313
14 <xs:element name="form" type="Form"></xs:element>14 <xs:element name="form" type="Form"></xs:element>
1515
16 <xs:complexType name="Hidden">16 <xs:complexType name="Hidden">
17 <xs:attribute name="name" type="xs:string" use="required"></xs:attribute>17 <xs:attribute name="name" type="xs:string" use="required"></xs:attribute>

Subscribers

People subscribed via source and target branches