Update of /cvsroot/monetdb/pathfinder/compiler/algebra
In directory sc8-pr-cvs16.sourceforge.net:/tmp/cvs-serv23588/algebra

Modified Files:
      Tag: XQuery_0-24
        core2alg.brg 
Log Message:
-- Fix bug in casting:
   Up til now we did not check if the input to a cast contained the correct
   number of items.


U core2alg.brg
Index: core2alg.brg
===================================================================
RCS file: /cvsroot/monetdb/pathfinder/compiler/algebra/core2alg.brg,v
retrieving revision 1.71.2.2
retrieving revision 1.71.2.3
diff -u -d -r1.71.2.2 -r1.71.2.3
--- core2alg.brg        3 Jun 2008 11:53:37 -0000       1.71.2.2
+++ core2alg.brg        17 Jun 2008 07:44:32 -0000      1.71.2.3
@@ -51,6 +51,7 @@
 #include "variable.h"
 
 #include "algebra.h"
+#include "builtins.h"
 
 /* Easily access subtree-parts */
 #include "child_mnemonic.h"
@@ -1752,6 +1753,7 @@
         /* CoreExpr:           cast (seqtype, CoreExpr) */
         case 21:
         {
+            struct  PFla_pair_t pair = A(R(p));
             PFty_t              t;
             PFalg_simple_type_t algty;
 
@@ -1779,12 +1781,23 @@
                         "don't know the algebra equivalent of type %s",
                         PFty_str (L(p)->sem.type));
 
+            /* in case we require a single item and the input
+               may be less or more than a single item add a runtime check */
+            if (PFty_subtype (L(p)->sem.type, PFty_item ()) &&
+                !PFty_subtype (R(p)->type, PFty_item ()))
+                pair = PFbui_fn_exactly_one (LOOP, ORDERING, &pair);
+            /* in case we require zero or one items and the input
+               may be more than a single item add a runtime check */
+            else if (PFty_subtype (L(p)->sem.type, PFty_opt (PFty_item ())) &&
+                     !PFty_subtype (R(p)->type, PFty_opt (PFty_item ())))
+                pair = PFbui_fn_zero_or_one (LOOP, ORDERING, &pair);
+                    
             A(p) = (struct PFla_pair_t) {
-                .rel  = project (cast (A(R(p)).rel, att_cast, att_item, algty),
+                .rel  = project (cast (pair.rel, att_cast, att_item, algty),
                                  proj (att_iter, att_iter),
                                  proj (att_pos, att_pos),
                                  proj (att_item, att_cast)),
-                .frag = A(R(p)).frag };
+                .frag = pair.frag };
 
         } break;
 


-------------------------------------------------------------------------
Check out the new SourceForge.net Marketplace.
It's the best place to buy or sell services for
just about anything Open Source.
http://sourceforge.net/services/buy/index.php
_______________________________________________
Monetdb-pf-checkins mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/monetdb-pf-checkins

Reply via email to