Changeset: 03ee1aad0c98 for MonetDB
URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=03ee1aad0c98
Modified Files:
        monetdb5/modules/atoms/Makefile.ag
        monetdb5/modules/atoms/colxml.c
        monetdb5/modules/atoms/colxml.h
        monetdb5/modules/atoms/colxml.mal
        monetdb5/modules/atoms/colxml.mx
        monetdb5/modules/atoms/mtime.mx
        monetdb5/modules/atoms/str.c
        monetdb5/modules/atoms/str.h
        monetdb5/modules/atoms/str.mal
        monetdb5/modules/atoms/str.mx
        monetdb5/modules/atoms/streams.c
        monetdb5/modules/atoms/streams.h
        monetdb5/modules/atoms/streams.mal
        monetdb5/modules/atoms/streams.mx
        monetdb5/modules/atoms/url.c
        monetdb5/modules/atoms/url.h
        monetdb5/modules/atoms/url.mal
        monetdb5/modules/atoms/url.mx
        monetdb5/modules/atoms/xml.sql
Branch: headless
Log Message:

Atoms de-Mx-ed
One file left over to do: mtime


diffs (truncated from 11397 to 300 lines):

diff --git a/monetdb5/modules/atoms/Makefile.ag 
b/monetdb5/modules/atoms/Makefile.ag
--- a/monetdb5/modules/atoms/Makefile.ag
+++ b/monetdb5/modules/atoms/Makefile.ag
@@ -25,15 +25,15 @@
 lib_atoms = {
        NOINST
        SOURCES = \
-               colxml.mx \
+               colxml.c \
                blob.c \
                color.c \
                identifier.c \
                inet.c \
                mtime.mx \
-               streams.mx \
-               str.mx \
-               url.mx \
+               streams.c \
+               str.c \
+               url.c \
                xml.c
 }
 
@@ -41,15 +41,15 @@
        HEADERS = mal
        DIR = libdir/monetdb5
        SOURCES = \
-               colxml.mx \
+               colxml.mal \
                blob.mal \
                color.mal \
                identifier.mal \
                inet.mal \
                mtime.mx \
-               streams.mx \
-               str.mx \
-               url.mx \
+               streams.mal \
+               str.mal \
+               url.mal \
                xml.mal
 }
 
diff --git a/monetdb5/modules/atoms/colxml.c b/monetdb5/modules/atoms/colxml.c
new file mode 100644
--- /dev/null
+++ b/monetdb5/modules/atoms/colxml.c
@@ -0,0 +1,1356 @@
+/*
+ * The contents of this file are subject to the MonetDB Public License
+ * Version 1.1 (the "License"); you may not use this file except in
+ * compliance with the License. You may obtain a copy of the License at
+ * http://monetdb.cwi.nl/Legal/MonetDBLicense-1.1.html
+ * 
+ * Software distributed under the License is distributed on an "AS IS"
+ * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
+ * License for the specific language governing rights and limitations
+ * under the License.
+ * 
+ * The Original Code is the MonetDB Database System.
+ * 
+ * The Initial Developer of the Original Code is CWI.
+ * Portions created by CWI are Copyright (C) 1997-July 2008 CWI.
+ * Copyright August 2008-2011 MonetDB B.V.
+ * All Rights Reserved.
+*/
+
+/* M.L. Kersten
+ * XML multiplexes
+ * SQL/XML requires a handful of instructions.
+ * The collection of routines provided here are map operations
+ * for the atom xml primitives. 
+ * 
+ * In line with the batcalc module, we assume that
+ * if two bat operands are provided that they are already
+ * aligned on the head. Moreover, the head of the BATs
+ * are limited to :oid.
+ * 
+ * The implementation is focussed on functionality. At a later stage
+ * we may postpone string contstruction until it is really needed.
+*/
+
+#include "monetdb_config.h"
+#include "colxml.h"
+
+#include <libxml/parser.h>
+
+#define prepareOperand(X,Y,Z)                                                  
        \
+    if (((X) = BATdescriptor(*(Y))) == NULL )                          \
+        throw(MAL, "xml." Z, INTERNAL_BAT_ACCESS);
+
+#define prepareResult(X,Y,tpe,Z)                                       \
+    (X) = BATnew((Y)->htype, (tpe), BATcount(Y));      \
+    if ((X) == NULL) {                                                         
\
+        BBPreleaseref((Y)->batCacheid);                                \
+        throw(MAL, "xml." Z, MAL_MALLOC_FAIL); \
+    }                                                                          
                \
+    if ((Y)->htype == TYPE_void)                                       \
+        BATseqbase((X), (Y)->hseqbase);                                \
+    (X)->hsorted = (Y)->hsorted;                                       \
+    (X)->tsorted =  0;                                                         
\
+    (X)->H->nonil = (Y)->H->nonil;                                     \
+       (X)->T->nonil = 1;
+
+#define finalizeResult(X,Y,Z)                                  \
+    if (!((Y)->batDirty & 2))                                  \
+               (Y) = BATsetaccess((Y), BAT_READ);              \
+    *(X) = (Y)->batCacheid;                                            \
+    BBPkeepref(*(X));                                                  \
+    BBPreleaseref((Z)->batCacheid);
+
+str
+BATXMLxml2str(int *ret, int *bid)
+{
+       BAT *b, *bn;
+       BUN p, q;
+       BATiter bi;
+
+       prepareOperand(b, bid, "str");
+       prepareResult(bn, b, TYPE_str, "str");
+       bi = bat_iterator(b);
+       BATaccessBegin(b,USE_HEAD|USE_TAIL,MMAP_SEQUENTIAL);
+       BATloop(b, p, q) {
+               ptr h = BUNhead(bi, p);
+               str t = (str) BUNtail(bi, p);
+
+               if (strNil(t)) {
+                       bunfastins(bn, h, t);
+                       bn->T->nonil = 0;
+               } else {
+                       assert(*t == 'A' || *t == 'C' || *t == 'D');
+                       bunfastins(bn, h, t + 1);
+               }
+       }
+       BATaccessEnd(b,USE_HEAD|USE_TAIL,MMAP_SEQUENTIAL);
+       finalizeResult(ret, bn, b);
+       return MAL_SUCCEED;
+  bunins_failed:
+       BATaccessEnd(b,USE_HEAD|USE_TAIL,MMAP_SEQUENTIAL);
+       BBPreleaseref(b->batCacheid);
+       BBPunfix(bn->batCacheid);
+       throw(MAL, "xml.str", OPERATION_FAILED " During bulk coercion");
+}
+
+str
+BATXMLxmltext(int *ret, int *bid)
+{
+       BAT *b, *bn;
+       BUN p, q;
+       BATiter bi;
+       size_t size = 0;
+       str buf = NULL;
+       xmlDocPtr doc = NULL;
+       xmlNodePtr elem;
+       str content = NULL, err = OPERATION_FAILED;
+
+       prepareOperand(b, bid, "text");
+       prepareResult(bn, b, TYPE_str, "text");
+       bi = bat_iterator(b);
+       BATaccessBegin(b,USE_HEAD|USE_TAIL,MMAP_SEQUENTIAL);
+       BATloop(b, p, q) {
+               ptr h = BUNhead(bi, p);
+               str t = (str) BUNtail(bi, p);
+               size_t len;
+
+               if (strNil(t)) {
+                       bunfastins(bn, h, t);
+                       bn->T->nonil = 0;
+                       continue;
+               }
+               assert(*t == 'A' || *t == 'C' || *t == 'D');
+               len = strlen(t);
+               if (*t == 'D') {
+                       xmlDocPtr d = xmlParseMemory(t + 1, (int) (len - 1));
+                       elem = xmlDocGetRootElement(d);
+                       content = (str) xmlNodeGetContent(elem);
+                       xmlFreeDoc(d);
+                       if (content == NULL) {
+                               err= MAL_MALLOC_FAIL;
+                               goto bunins_failed;
+                       }
+               } else if (*t == 'C') {
+                       if (doc == NULL)
+                               doc = xmlParseMemory("<doc/>", 6);
+                       xmlParseInNodeContext(xmlDocGetRootElement(doc), t + 1, 
(int) (len - 1), 0, &elem);
+                       content = (str) xmlNodeGetContent(elem);
+                       xmlFreeNodeList(elem);
+                       if (content == NULL) {
+                               err= MAL_MALLOC_FAIL;
+                               goto bunins_failed;
+                       }
+               } else {
+                       str s;
+
+                       if (buf == 0 || size < len) {
+                               size = len + 128;
+                               if (buf != NULL)
+                                       GDKfree(buf);
+                               buf = GDKmalloc(size);
+                               if ( buf == 0) {
+                                       err= MAL_MALLOC_FAIL;
+                                       goto bunins_failed;
+                               }
+                       }
+                       s = buf;
+                       t++;
+                       while (*t) {
+                               if (*t == '"' || *t == '\'') {
+                                       char q = *t++;
+
+                                       s += XMLunquotestring(&t, q, s);
+                               }
+                               t++;
+                       }
+                       *s = 0;
+               }
+               assert(content != NULL || buf != NULL);
+               bunfastins(bn, h, content != NULL ? content : buf);
+               if (content != NULL)
+                       GDKfree(content);
+               content = NULL;
+       }
+       BATaccessEnd(b,USE_HEAD|USE_TAIL,MMAP_SEQUENTIAL);
+       finalizeResult(ret, bn, b);
+       if (buf != NULL)
+               GDKfree(buf);
+       if (doc != NULL)
+               xmlFreeDoc(doc);
+       return MAL_SUCCEED;
+  bunins_failed:
+       BATaccessEnd(b,USE_HEAD|USE_TAIL,MMAP_SEQUENTIAL);
+       BBPreleaseref(b->batCacheid);
+       BBPunfix(bn->batCacheid);
+       if (buf != NULL)
+               GDKfree(buf);
+       if (doc != NULL)
+               xmlFreeDoc(doc);
+       if (content != NULL)
+               GDKfree(content);
+       throw(MAL, "xml.text", err );
+}
+
+/*
+ * The core of the activity is str2xml, where the actual strings
+ * are constructed.
+ * To avoid repetitive copying we make sure that the garbage
+ * collector does not remove the xml intermediates. 
+ * This way, we know that as long as the xml-variables are not
+ * reused, the complete structure of the xml document(s) are available.
+ * We merely have to collect the pieces.
+ * [FOR LATER, FIRST GO FOR THE EASY IMPLEMENTATION]
+ * XML values are represented by strings already.
+*/
+
+str
+BATXMLstr2xml(int *ret, int *bid)
+{
+       BAT *b, *bn;
+       BUN p, q;
+       size_t size = BUFSIZ;
+       str buf, err= OPERATION_FAILED;
+       BATiter bi;
+
+       buf = GDKmalloc(size);
+       if ( buf == NULL)
+               throw(MAL,"xml.str2xml",MAL_MALLOC_FAIL);
+       prepareOperand(b, bid, "xml");
+       prepareResult(bn, b, TYPE_xml, "xml");
+       bi = bat_iterator(b);
+       BATloop(b, p, q) {
+               ptr h = BUNhead(bi, p);
+               str t = (str) BUNtail(bi, p);
+               size_t len;
+
+               if (strNil(t)) {
+                       bunfastins(bn, h, str_nil);
+                       bn->T->nonil = 0;
+                       continue;
+               }
+
+               len = strlen(t) * 6 + 1;
+               if (size < len) {
+                       size = len + 128;
+                       GDKfree(buf);
+                       buf = GDKmalloc(size);
+                       if ( buf == NULL){
+                               err= MAL_MALLOC_FAIL;
+                               goto bunins_failed;
+                       }
+               }
+               buf[0] = 'C';
+               XMLquotestring(t, buf + 1, size - 1);
+               bunfastins(bn, h, buf);
+       }
+       GDKfree(buf);
+       finalizeResult(ret, bn, b);
+       return MAL_SUCCEED;
+  bunins_failed:
+       BBPreleaseref(b->batCacheid);
+       BBPunfix(bn->batCacheid);
_______________________________________________
Checkin-list mailing list
[email protected]
http://mail.monetdb.org/mailman/listinfo/checkin-list

Reply via email to