zorba-coders team mailing list archive
-
zorba-coders team
-
Mailing list archive
-
Message #00137
[Merge] lp:~markos-za/zorba/markos-bugs into lp:zorba
Markos Zaharioudakis has proposed merging lp:~markos-za/zorba/markos-bugs into lp:zorba.
Requested reviews:
Federico Cavalieri (fcavalieri)
For more details, see:
https://code.launchpad.net/~markos-za/zorba/markos-bugs/+merge/76750
Fixed wrong assumption about the content of an element node with simple content
--
https://code.launchpad.net/~markos-za/zorba/markos-bugs/+merge/76750
Your team Zorba Coders is subscribed to branch lp:zorba.
=== modified file 'src/store/api/shared_types.h'
--- src/store/api/shared_types.h 2011-09-19 15:01:21 +0000
+++ src/store/api/shared_types.h 2011-09-23 14:33:26 +0000
@@ -29,6 +29,9 @@
namespace zorba
{
+typedef std::vector<char>::size_type csize;
+
+
namespace store
{
=== modified file 'src/store/naive/node_items.cpp'
--- src/store/naive/node_items.cpp 2011-09-15 07:18:45 +0000
+++ src/store/naive/node_items.cpp 2011-09-23 14:33:26 +0000
@@ -2076,16 +2076,74 @@
/*******************************************************************************
********************************************************************************/
-bool ElementNode::haveTypedTypedValue() const
+bool ElementNode::haveTypedTypedValue(TextNode*& textChild) const
{
+ textChild = NULL;
+
if (numChildren() == 1 &&
getChild(0)->getNodeKind() == store::StoreConsts::textNode)
{
- if (reinterpret_cast<TextNode*>(getChild(0))->isTyped())
- return true;
- }
-
- return false;
+ textChild = static_cast<TextNode*>(getChild(0));
+
+ return textChild->isTyped();
+ }
+ else
+ {
+ InternalNode::const_iterator ite = childrenBegin();
+ InternalNode::const_iterator end = childrenEnd();
+
+ for (; ite != end; ++ite)
+ {
+ store::StoreConsts::NodeKind kind = (*ite)->getNodeKind();
+
+ if (kind == store::StoreConsts::elementNode)
+ return false;
+
+ if (kind == store::StoreConsts::commentNode ||
+ kind == store::StoreConsts::piNode)
+ continue;
+
+ assert(kind == store::StoreConsts::textNode);
+
+ if (textChild != NULL)
+ return false;
+
+ textChild = static_cast<TextNode*>(*ite);
+ }
+
+ return (textChild && textChild->isTyped());
+ }
+}
+
+
+/*******************************************************************************
+
+********************************************************************************/
+TextNode* ElementNode::getUniqueTextChild() const
+{
+ TextNode* textChild = NULL;
+
+ InternalNode::const_iterator ite = childrenBegin();
+ InternalNode::const_iterator end = childrenEnd();
+
+ for (; ite != end; ++ite)
+ {
+ store::StoreConsts::NodeKind kind = (*ite)->getNodeKind();
+
+ ZORBA_ASSERT(kind != store::StoreConsts::elementNode);
+
+ if (kind == store::StoreConsts::textNode)
+ {
+ if (textChild != NULL)
+ ZORBA_ASSERT(false);
+
+ textChild = static_cast<TextNode*>(*ite);
+ }
+ }
+
+ ZORBA_ASSERT(textChild);
+
+ return textChild;
}
@@ -2094,10 +2152,10 @@
********************************************************************************/
bool ElementNode::isId() const
{
- if (numChildren() == 1 &&
- getChild(0)->getNodeKind() == store::StoreConsts::textNode)
+ TextNode* textChild;
+ if (haveTypedTypedValue(textChild))
{
- if (reinterpret_cast<TextNode*>(getChild(0))->isIdInternal())
+ if (textChild->isIdInternal())
return true;
}
@@ -2110,10 +2168,10 @@
********************************************************************************/
bool ElementNode::isIdRefs() const
{
- if (numChildren() == 1 &&
- getChild(0)->getNodeKind() == store::StoreConsts::textNode)
+ TextNode* textChild;
+ if (haveTypedTypedValue(textChild))
{
- if (reinterpret_cast<TextNode*>(getChild(0))->isIdRefsInternal())
+ if (textChild->isIdRefsInternal())
return true;
}
@@ -2128,24 +2186,24 @@
{
if (haveValue())
{
+ TextNode* textChild;
+
if (haveEmptyValue())
{
val = NULL;
iter = NULL;
}
- else if (haveTypedTypedValue())
+ else if (haveTypedTypedValue(textChild))
{
- const TextNode* child = reinterpret_cast<const TextNode*>(getChild(0));
-
- if (child->haveListValue())
+ if (textChild->haveListValue())
{
- ItemVector* vec = reinterpret_cast<ItemVector*>(child->getValue());
+ ItemVector* vec = reinterpret_cast<ItemVector*>(textChild->getValue());
iter = new ItemIterator(vec->getItems(), true);
val = NULL;
}
else
{
- val = child->getValue();
+ val = textChild->getValue();
iter = NULL;
}
}
@@ -2158,10 +2216,8 @@
}
else
{
- throw XQUERY_EXCEPTION(
- err::FOTY0012,
- ERROR_PARAMS( theName->getStringValue(), getType()->getStringValue() )
- );
+ throw XQUERY_EXCEPTION(err::FOTY0012,
+ ERROR_PARAMS(theName->getStringValue(), getType()->getStringValue()));
}
}
@@ -2814,7 +2870,7 @@
store::NsBindings nsBindings;
getNamespaceBindings(nsBindings);
- for (ulong i = 0; i < nsBindings.size(); i++)
+ for (csize i = 0; i < nsBindings.size(); i++)
{
str << " xmlns:" << nsBindings[i].first << "=\""
<< nsBindings[i].second << "\"";
@@ -3345,12 +3401,10 @@
if (parent)
{
#ifndef NDEBUG
- if (parent->getNodeKind() == store::StoreConsts::elementNode &&
- parent->numChildren() == 1 &&
- parent->getChild(0)->getNodeKind() == store::StoreConsts::textNode)
+ if (parent->getNodeKind() == store::StoreConsts::elementNode)
{
- TextNode* textChild = reinterpret_cast<TextNode*>(parent->getChild(0));
- ZORBA_ASSERT(!textChild->isTyped());
+ TextNode* textChild;
+ ZORBA_ASSERT(!static_cast<ElementNode*>(parent)->haveTypedTypedValue(textChild));
}
#endif
@@ -3379,12 +3433,12 @@
********************************************************************************/
TextNode::TextNode(
- InternalNode* parent,
+ InternalNode* parent,
store::Item_t& content,
- bool isListValue)
+ bool isListValue)
:
#ifdef TEXT_ORDPATH
- OrdPathNode(NULL, parent, true, 0, store::StoreConsts::textNode)
+ OrdPathNode(NULL, parent, append, pos, store::StoreConsts::textNode)
#else
XmlNode(NULL, parent, store::StoreConsts::textNode)
#endif
@@ -3395,14 +3449,31 @@
ElementNode* p = reinterpret_cast<ElementNode*>(parent);
- ZORBA_ASSERT(p->numChildren() == 0);
+ // Make sure that the parent node has only comment and pi nodes as children.
+ if (p->numChildren() > 0)
+ {
+ InternalNode::const_iterator ite = p->childrenBegin();
+ InternalNode::const_iterator end = p->childrenEnd();
+
+ for (; ite != end; ++ite)
+ {
+ XmlNode* child = (*ite);
+
+ if (child->getNodeKind() != store::StoreConsts::commentNode &&
+ child->getNodeKind() != store::StoreConsts::piNode)
+ {
+ ZORBA_ASSERT(false);
+ }
+ }
+ }
+
ZORBA_ASSERT(p->haveValue() && !p->haveEmptyValue());
setTypedValue(content);
if (isListValue)
setHaveListValue();
- p->insertChild(this, 0);
+ p->insertChild(this, p->numChildren());
#ifdef TEXT_ORDPATH
NODE_TRACE1("Constructed text node " << this << " parent = "
@@ -3453,7 +3524,7 @@
// always be untyped.
// Merge adjacent text nodes.
- ulong numChildren = parent->numChildren();
+ csize numChildren = parent->numChildren();
XmlNode* lsib = (pos > 0 ? parent->getChild(pos-1) : NULL);
XmlNode* rsib = (pos < numChildren ? parent->getChild(pos) : NULL);
@@ -3615,8 +3686,8 @@
bool TextNode::isIdInternal() const
{
if (isTyped() &&
- (static_cast<AtomicItem*>(getValue()))->isAtomic() &&
- (static_cast<AtomicItem*>(getValue()))->getTypeCode() == XS_ID)
+ getValue()->isAtomic() &&
+ static_cast<AtomicItem*>(getValue())->getTypeCode() == XS_ID)
return true;
return false;
@@ -3635,9 +3706,9 @@
if (haveListValue())
{
const ItemVector& values = *reinterpret_cast<ItemVector*>(value);
- ulong numValues = values.size();
+ csize numValues = values.size();
- for (ulong i = 0; i < numValues; ++i)
+ for (csize i = 0; i < numValues; ++i)
{
if (dynamic_cast<IDREFItem*>(values.getItem(i)) != NULL)
{
@@ -4285,7 +4356,7 @@
void InternalNode::tokenize( XmlNodeTokenizerCallback& cb )
{
XmlNodeTokenizerCallback::begin_type const begin = cb.beginTokenization();
- for ( ulong i = 0; i < numChildren(); ++i )
+ for ( csize i = 0; i < numChildren(); ++i )
getChild( i )->tokenize( cb );
cb.endTokenization( this, begin );
}
=== modified file 'src/store/naive/node_items.h'
--- src/store/naive/node_items.h 2011-09-13 13:33:51 +0000
+++ src/store/naive/node_items.h 2011-09-23 14:33:26 +0000
@@ -899,18 +899,24 @@
void resetHaveEmptyValue() { theFlags &= ~HaveEmptyValue; }
bool haveEmptyValue() const { return (theFlags & HaveEmptyValue) != 0; }
- bool haveTypedTypedValue() const;
+ bool haveTypedTypedValue(TextNode*&) const;
+
+ TextNode* getUniqueTextChild() const;
void setInSubstGroup() { theFlags |= IsInSubstGroup; }
+
void resetInSubstGroup() { theFlags &= ~IsInSubstGroup; }
#ifndef EMBEDED_TYPE
bool haveType() const { return (theFlags & HaveType) != 0; }
+
void setHaveType() { theFlags |= HaveType; }
+
void resetHaveType() { theFlags &= ~HaveType; }
#endif
bool isRecursive() const { return (theFlags & IsRecursive) != 0; }
+
void resetRecursive() { theFlags &= ~IsRecursive; }
void setRecursive()
=== modified file 'src/store/naive/node_updates.cpp'
--- src/store/naive/node_updates.cpp 2011-09-15 07:18:45 +0000
+++ src/store/naive/node_updates.cpp 2011-09-23 14:33:26 +0000
@@ -605,12 +605,12 @@
void XmlNode::removeType(UpdatePrimitive& upd)
{
TypeUndoList& undoList = upd.theTypeUndoList;
- ulong undoSize = (ulong)undoList.size();
+ csize undoSize = undoList.size();
zorba::store::Item* revalidationNode = NULL;
XmlNode* currNode = this;
- while(currNode != NULL)
+ while (currNode != NULL)
{
NodeTypeInfo tinfo;
tinfo.theNode = currNode;
@@ -643,10 +643,10 @@
#endif
tinfo.theFlags = n->theFlags;
- if (n->haveTypedTypedValue())
+ TextNode* textChild;
+
+ if (n->haveTypedTypedValue(textChild))
{
- TextNode* textChild = reinterpret_cast<TextNode*>(n->getChild(0));
-
zstring textValue;
textChild->getStringValue2(textValue);
@@ -744,12 +744,9 @@
n->setType(tinfo.theTypeName);
n->theFlags = tinfo.theFlags;
- if (tinfo.theChildFlags & IsTyped)
+ if (tinfo.theChildFlags & XmlNode::IsTyped)
{
- ZORBA_ASSERT(n->numChildren() == 1 &&
- n->getChild(0)->getNodeKind() == store::StoreConsts::textNode);
-
- TextNode* textChild = reinterpret_cast<TextNode*>(n->getChild(0));
+ TextNode* textChild = n->getUniqueTextChild();
if (!textChild->isTyped())
{
=== modified file 'src/store/naive/pul_primitives.cpp'
--- src/store/naive/pul_primitives.cpp 2011-09-21 10:10:35 +0000
+++ src/store/naive/pul_primitives.cpp 2011-09-23 14:33:26 +0000
@@ -467,10 +467,10 @@
target->setType(theTypeName);
- if (target->haveTypedTypedValue())
+ TextNode* textChild;
+
+ if (target->haveTypedTypedValue(textChild))
{
- TextNode* textChild = reinterpret_cast<TextNode*>(target->getChild(0));
-
zstring textValue;
textChild->getStringValue2(textValue);
@@ -489,10 +489,7 @@
if (theHaveTypedValue)
{
- ZORBA_FATAL(target->numChildren() == 1, "");
- ZORBA_FATAL(target->getChild(0)->getNodeKind() == store::StoreConsts::textNode, "");
-
- TextNode* textChild = reinterpret_cast<TextNode*>(target->getChild(0));
+ TextNode* textChild = target->getUniqueTextChild();
textChild->setTypedValue(theTypedValue);
if (theHaveListValue)
=== modified file 'src/store/naive/shared_types.h'
--- src/store/naive/shared_types.h 2011-06-14 17:26:33 +0000
+++ src/store/naive/shared_types.h 2011-09-23 14:33:26 +0000
@@ -30,9 +30,6 @@
namespace simplestore
{
-typedef std::vector<char>::size_type csize;
-
-
class CollectionSet;
class CollectionIterator;
typedef rchandle<CollectionIterator> CollectionIterator_t;
=== modified file 'src/types/schema/validate.cpp'
--- src/types/schema/validate.cpp 2011-07-01 17:58:59 +0000
+++ src/types/schema/validate.cpp 2011-09-23 14:33:26 +0000
@@ -525,8 +525,8 @@
<< "\n"; cout.flush();
#endif
- if ( xqType!=NULL &&
- xqType->content_kind()==XQType::SIMPLE_CONTENT_KIND )
+ if ( xqType != NULL &&
+ xqType->content_kind() == XQType::SIMPLE_CONTENT_KIND )
{
store::NsBindings nsBindings;
parent->getNamespaceBindings(nsBindings);
@@ -540,7 +540,7 @@
typedValues,
loc);
- if ( typedValues.size()==1 ) // hack around serialization bug
+ if ( typedValues.size() == 1 ) // hack around serialization bug
GENV_ITEMFACTORY->createTextNode(validatedTextNode, parent,
typedValues[0]);
else
=== added file 'test/rbkt/ExpQueryResults/zorba/misc/validate1.xml.res'
--- test/rbkt/ExpQueryResults/zorba/misc/validate1.xml.res 1970-01-01 00:00:00 +0000
+++ test/rbkt/ExpQueryResults/zorba/misc/validate1.xml.res 2011-09-23 14:33:26 +0000
@@ -0,0 +1,9 @@
+<xqdoc xmlns="http://www.xqdoc.org/1.0">
+ <control>
+ <date><?processinginstruction aaa?>TS4J5UJ</date>
+ <version>N/A</version>
+ </control>
+ <module type="library">
+ <uri>DGQEb8Q</uri>
+ </module>
+</xqdoc>
=== added file 'test/rbkt/Queries/zorba/misc/validate1.xq'
--- test/rbkt/Queries/zorba/misc/validate1.xq 1970-01-01 00:00:00 +0000
+++ test/rbkt/Queries/zorba/misc/validate1.xq 2011-09-23 14:33:26 +0000
@@ -0,0 +1,15 @@
+
+import schema namespace s = "http://www.xqdoc.org/1.0";
+
+let $hostInfo :=<xqdoc xmlns="http://www.xqdoc.org/1.0">
+ <control>
+ <date><?processinginstruction aaa?>TS4J5UJ</date>
+ <version>N/A</version>
+ </control>
+ <module type="library">
+ <uri>DGQEb8Q</uri>
+ </module>
+</xqdoc>
+
+return
+ validate { $hostInfo }
Follow ups