[Zorba-coders] [Bug 986075] Re: out of range vector access in plan generator

2012-05-30 Thread Markos Zaharioudakis
** Changed in: zorba
   Status: Fix Committed = Fix Released

-- 
You received this bug notification because you are a member of Zorba
Coders, which is the registrant for Zorba.
https://bugs.launchpad.net/bugs/986075

Title:
  out of range vector access in plan generator

Status in Zorba - The XQuery Processor:
  Fix Released

Bug description:
  Hello Markos

  We discovered an out-of-range vector access during plan generation on
  our windows machine. On Windows only, because windows does an out-of-
  range check in debug mode automatically. To reproduce and detect the
  problem on linux, you need to apply the following patch to zorba:

  === modified file 'src/compiler/expression/flwor_expr.h'
  --- src/compiler/expression/flwor_expr.h  2012-04-19 21:40:27 +
  +++ src/compiler/expression/flwor_expr.h  2012-04-20 08:51:10 +
  @@ -708,7 +708,7 @@
   
 void remove_clause(ulong pos);
   
  -  const flwor_clause* operator[](int i) const { return theClauses[i].getp(); 
}
  +  const flwor_clause* operator[](int i) const { return 
theClauses.at(i).getp(); }
   
 flwor_clause* get_clause(ulong i);

  
  After applying the patch, you need to execute the following query:

  declare %fn:private function local:serialize-request-as-xml()
  {
()  
  };
  declare function local:serialize-request-as-html()
  {
let $request := local:serialize-request-as-xml()
return
  for $section in $request/element()
  return
for $info in $section/element()
return 
  for $value in $info/value
  let $content :=
switch(false())
  case false() return 
()  
  default return $value/text()
return
  switch(string($value/@class))
case error return 
  $content
default return $content
  };

  local:serialize-request-as-html()

  The result on my machine is:
  $ ./bin/zorba  -q ../../sausalito/build/test.xq -f
  Zorba error [zerr:ZXQP0003]: internal error: vector::_M_range_check; raised 
at /home/dagraf/zorba/sandbox/src/api/zorbaimpl.cpp:288

  In sausalito, we bypassing the issue currently by return 0 if the vector is 
empty:
  -  const flwor_clause* operator[](int i) const { return theClauses[i].getp(); 
}
  +  const flwor_clause* operator[](int i) const { return (theClauses.empty() ? 
0 : theClauses[i].getp()); }

  I have no clue if this is a nice bypass. I am pretty sure this bypass
  hides another problem. But maybe, it is save to use it temporarily.
  What do you think?

  By the way: The call stack is:
  #0  0x73af4dc0 in __cxa_throw () from /usr/lib/libstdc++.so.6
  #1  0x73a90647 in std::__throw_out_of_range(char const*) () from 
/usr/lib/libstdc++.so.6
  #2  0x769c332b in std::vectorzorba::rchandlezorba::flwor_clause, 
std::allocatorzorba::rchandlezorba::flwor_clause  ::_M_range_check 
(this=0x99b380, __n=0) at /usr/include/c++/4.4/bits/stl_vector.h:634
  #3  0x769b9db9 in std::vectorzorba::rchandlezorba::flwor_clause, 
std::allocatorzorba::rchandlezorba::flwor_clause  ::at (this=0x99b380, 
__n=0) at /usr/include/c++/4.4/bits/stl_vector.h:670
  #4  0x7693ae2a in zorba::flwor_expr::operator[] (this=0x99b2f0, i=0) 
at /home/dagraf/zorba/sandbox/src/compiler/expression/flwor_expr.h:711
  #5  0x76af6eb9 in zorba::EliminateUnusedLetVars::rewritePre 
(this=0x9983b0, node=0x99b2f0, rCtx=...) at 
/home/dagraf/zorba/sandbox/src/compiler/rewriter/rules/flwor_rules.cpp:175
  #6  0x76aedf2b in zorba::PrePostRewriteRule::apply (this=0x9983b0, 
rCtx=..., curExpr=0x99b2f0, modified=@0x7fffca6d) at 
/home/dagraf/zorba/sandbox/src/compiler/rewriter/rules/rule_base.cpp:39
  #7  0x76aedfda in zorba::PrePostRewriteRule::apply (this=0x9983b0, 
rCtx=..., curExpr=0x99d620, modified=@0x7fffca6d) at 
/home/dagraf/zorba/sandbox/src/compiler/rewriter/rules/rule_base.cpp:51
  #8  0x76aedfda in zorba::PrePostRewriteRule::apply (this=0x9983b0, 
rCtx=..., curExpr=0x99d9c0, modified=@0x7fffca6d) at 
/home/dagraf/zorba/sandbox/src/compiler/rewriter/rules/rule_base.cpp:51
  #9  0x76aedfda in zorba::PrePostRewriteRule::apply (this=0x9983b0, 
rCtx=..., curExpr=0x99da70, modified=@0x7fffca6d) at 
/home/dagraf/zorba/sandbox/src/compiler/rewriter/rules/rule_base.cpp:51
  #10 0x76aedfda in zorba::PrePostRewriteRule::apply (this=0x9983b0, 
rCtx=..., curExpr=0x99bdc0, modified=@0x7fffca6d) at 
/home/dagraf/zorba/sandbox/src/compiler/rewriter/rules/rule_base.cpp:51
  #11 0x76aedfda in zorba::PrePostRewriteRule::apply (this=0x9983b0, 
rCtx=..., curExpr=0x99be80, modified=@0x7fffca6d) at 
/home/dagraf/zorba/sandbox/src/compiler/rewriter/rules/rule_base.cpp:51
  #12 0x76ae7388 in 

[Zorba-coders] [Bug 986075] Re: out of range vector access in plan generator

2012-04-23 Thread Markos Zaharioudakis
** Changed in: zorba
   Status: In Progress = Fix Committed

-- 
You received this bug notification because you are a member of Zorba
Coders, which is the registrant for Zorba.
https://bugs.launchpad.net/bugs/986075

Title:
  out of range vector access in plan generator

Status in Zorba - The XQuery Processor:
  Fix Committed

Bug description:
  Hello Markos

  We discovered an out-of-range vector access during plan generation on
  our windows machine. On Windows only, because windows does an out-of-
  range check in debug mode automatically. To reproduce and detect the
  problem on linux, you need to apply the following patch to zorba:

  === modified file 'src/compiler/expression/flwor_expr.h'
  --- src/compiler/expression/flwor_expr.h  2012-04-19 21:40:27 +
  +++ src/compiler/expression/flwor_expr.h  2012-04-20 08:51:10 +
  @@ -708,7 +708,7 @@
   
 void remove_clause(ulong pos);
   
  -  const flwor_clause* operator[](int i) const { return theClauses[i].getp(); 
}
  +  const flwor_clause* operator[](int i) const { return 
theClauses.at(i).getp(); }
   
 flwor_clause* get_clause(ulong i);

  
  After applying the patch, you need to execute the following query:

  declare %fn:private function local:serialize-request-as-xml()
  {
()  
  };
  declare function local:serialize-request-as-html()
  {
let $request := local:serialize-request-as-xml()
return
  for $section in $request/element()
  return
for $info in $section/element()
return 
  for $value in $info/value
  let $content :=
switch(false())
  case false() return 
()  
  default return $value/text()
return
  switch(string($value/@class))
case error return 
  $content
default return $content
  };

  local:serialize-request-as-html()

  The result on my machine is:
  $ ./bin/zorba  -q ../../sausalito/build/test.xq -f
  Zorba error [zerr:ZXQP0003]: internal error: vector::_M_range_check; raised 
at /home/dagraf/zorba/sandbox/src/api/zorbaimpl.cpp:288

  In sausalito, we bypassing the issue currently by return 0 if the vector is 
empty:
  -  const flwor_clause* operator[](int i) const { return theClauses[i].getp(); 
}
  +  const flwor_clause* operator[](int i) const { return (theClauses.empty() ? 
0 : theClauses[i].getp()); }

  I have no clue if this is a nice bypass. I am pretty sure this bypass
  hides another problem. But maybe, it is save to use it temporarily.
  What do you think?

  By the way: The call stack is:
  #0  0x73af4dc0 in __cxa_throw () from /usr/lib/libstdc++.so.6
  #1  0x73a90647 in std::__throw_out_of_range(char const*) () from 
/usr/lib/libstdc++.so.6
  #2  0x769c332b in std::vectorzorba::rchandlezorba::flwor_clause, 
std::allocatorzorba::rchandlezorba::flwor_clause  ::_M_range_check 
(this=0x99b380, __n=0) at /usr/include/c++/4.4/bits/stl_vector.h:634
  #3  0x769b9db9 in std::vectorzorba::rchandlezorba::flwor_clause, 
std::allocatorzorba::rchandlezorba::flwor_clause  ::at (this=0x99b380, 
__n=0) at /usr/include/c++/4.4/bits/stl_vector.h:670
  #4  0x7693ae2a in zorba::flwor_expr::operator[] (this=0x99b2f0, i=0) 
at /home/dagraf/zorba/sandbox/src/compiler/expression/flwor_expr.h:711
  #5  0x76af6eb9 in zorba::EliminateUnusedLetVars::rewritePre 
(this=0x9983b0, node=0x99b2f0, rCtx=...) at 
/home/dagraf/zorba/sandbox/src/compiler/rewriter/rules/flwor_rules.cpp:175
  #6  0x76aedf2b in zorba::PrePostRewriteRule::apply (this=0x9983b0, 
rCtx=..., curExpr=0x99b2f0, modified=@0x7fffca6d) at 
/home/dagraf/zorba/sandbox/src/compiler/rewriter/rules/rule_base.cpp:39
  #7  0x76aedfda in zorba::PrePostRewriteRule::apply (this=0x9983b0, 
rCtx=..., curExpr=0x99d620, modified=@0x7fffca6d) at 
/home/dagraf/zorba/sandbox/src/compiler/rewriter/rules/rule_base.cpp:51
  #8  0x76aedfda in zorba::PrePostRewriteRule::apply (this=0x9983b0, 
rCtx=..., curExpr=0x99d9c0, modified=@0x7fffca6d) at 
/home/dagraf/zorba/sandbox/src/compiler/rewriter/rules/rule_base.cpp:51
  #9  0x76aedfda in zorba::PrePostRewriteRule::apply (this=0x9983b0, 
rCtx=..., curExpr=0x99da70, modified=@0x7fffca6d) at 
/home/dagraf/zorba/sandbox/src/compiler/rewriter/rules/rule_base.cpp:51
  #10 0x76aedfda in zorba::PrePostRewriteRule::apply (this=0x9983b0, 
rCtx=..., curExpr=0x99bdc0, modified=@0x7fffca6d) at 
/home/dagraf/zorba/sandbox/src/compiler/rewriter/rules/rule_base.cpp:51
  #11 0x76aedfda in zorba::PrePostRewriteRule::apply (this=0x9983b0, 
rCtx=..., curExpr=0x99be80, modified=@0x7fffca6d) at 
/home/dagraf/zorba/sandbox/src/compiler/rewriter/rules/rule_base.cpp:51
  #12 0x76ae7388 in