Changeset: 6fbe5ffbce5e for MonetDB
URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=6fbe5ffbce5e
Modified Files:
        configure.ag
        monetdb5/modules/mal/pcre.c
        tools/mserver/monet_version.c.in
Branch: default
Log Message:

PCRE library now optional on POSIX systems with GNU regex.


diffs (truncated from 586 to 300 lines):

diff --git a/configure.ag b/configure.ag
--- a/configure.ag
+++ b/configure.ag
@@ -1687,7 +1687,7 @@ AS_CASE([$host],
 
 
 # PCRE library
-# required for MonetDB5 (and SQL), optional otherwise
+# required on Windows, optional on POSIX systems with GNU regex
 req_pcre_ver='4.5'
 PKG_CHECK_MODULES([pcre], [libpcre >= $req_pcre_ver],
        [have_pcre=yes], [have_pcre=no; why_have_pcre="(libpcre >= 
$req_pcre_ver not found)"])
@@ -1705,16 +1705,28 @@ AS_VAR_IF([have_pcre], [yes], [
                [AC_MSG_RESULT([assuming yes])])
        LIBS="$save_LIBS"
        CFLAGS="$save_CFLAGS"])
+
 AS_VAR_IF([have_pcre], [yes], [
        AC_DEFINE([HAVE_LIBPCRE], 1, [Define if you have the pcre library])])
 AM_CONDITIONAL([HAVE_PCRE], [test x"$have_pcre" != xno])
-AS_CASE([$enable_monetdb5-$have_pcre],
-[yes-no], [
-       AC_MSG_ERROR([PCRE library not found but required for MonetDB5])],
-[auto-no], [
+
+have_gnuregex=yes
+AS_VAR_IF([have_pcre], [yes], [], [
+       AC_RUN_IFELSE([AC_LANG_PROGRAM(
+               [[@%:@include <regex.h>]],
+               [[regex_t re; regcomp(&re, "hello", 
REG_EXTENDED|REG_NOSUB);]])],
+               [AC_MSG_RESULT([yes])],
+               [have_gnuregex=no],
+               [have_gnuregex=no])
+])
+
+AS_CASE([$enable_monetdb5-$have_pcre-$have_gnuregex],
+[yes-no-no], [
+       AC_MSG_ERROR([PCRE library or GNU regex library not found but required 
for MonetDB5])],
+[auto-no-no], [
        enable_monetdb5=no
        AS_VAR_IF([disable_monetdb5], [], [
-               disable_monetdb5="(PCRE library not found but required for 
MonetDB5)"])])
+               disable_monetdb5="(PCRE library or GNU regex library not found 
but required for MonetDB5)"])])
 
 org_have_libxml2=yes
 have_libxml2=$org_have_libxml2
diff --git a/monetdb5/modules/mal/pcre.c b/monetdb5/modules/mal/pcre.c
--- a/monetdb5/modules/mal/pcre.c
+++ b/monetdb5/modules/mal/pcre.c
@@ -24,12 +24,16 @@
 #include "mal.h"
 #include "mal_exception.h"
 
-
+#ifdef HAVE_LIBPCRE
 #include <pcre.h>
-
+#else
 #if PCRE_MAJOR < 8 || (PCRE_MAJOR == 8 && PCRE_MINOR < 13)
 #define pcre_free_study my_pcre_free
 #endif
+#include <regex.h>
+
+typedef regex_t pcre;
+#endif
 
 mal_export str pcre_init(void *ret);
 
@@ -221,6 +225,7 @@ re_destroy( RE *p)
 #define m2p(p) (pcre*)(((size_t*)p)+1)
 #define p2m(p) (pcre*)(((size_t*)p)-1)
 
+#ifdef HAVE_LIBPCRE
 static void *
 my_pcre_malloc(size_t s)
 {
@@ -243,10 +248,12 @@ my_pcre_free(void *blk)
        sz -= 1;
        GDKfree(sz);
 }
+#endif
 
 static str
 pcre_compile_wrap(pcre **res, const char *pattern, bit insensitive)
 {
+#ifdef HAVE_LIBPCRE
        pcre *r;
        const char err[BUFSIZ], *err_p = err;
        int errpos = 0;
@@ -261,6 +268,12 @@ pcre_compile_wrap(pcre **res, const char
        }
        *(pcre **) res = p2m(r);
        return MAL_SUCCEED;
+#else
+       (void) res;
+       (void) pattern;
+       (void) insensitive;
+       throw(MAL,"pcre.compile", "Database was compiled without PCRE 
support.");
+#endif
 }
 
 /* these two defines are copies from gdk_select.c */
@@ -302,23 +315,35 @@ pcre_compile_wrap(pcre **res, const char
 static str
 pcre_likesubselect(BAT **bnp, BAT *b, BAT *s, const char *pat, int caseignore, 
int anti)
 {
+#ifdef HAVE_LIBPCRE
        int options = PCRE_UTF8 | PCRE_MULTILINE;
        pcre *re;
        pcre_extra *pe;
        const char *error;
        int errpos;
+       int ovector[10];
+#else
+       int options = REG_NEWLINE | REG_NOSUB;
+       pcre re;
+       int errcode;
+#endif
        BATiter bi = bat_iterator(b);
        BAT *bn;
        BUN p, q;
        oid o, off;
        const char *v;
-       int ovector[10];
 
        assert(ATOMstorage(b->ttype) == TYPE_str);
        assert(anti == 0 || anti == 1);
 
-       if (caseignore)
+       if (caseignore) {
+#ifdef HAVE_LIBPCRE
                options |= PCRE_CASELESS;
+#else
+               options |= REG_ICASE;
+#endif
+       }
+#ifdef HAVE_LIBPCRE
        if ((re = pcre_compile(pat, options, &error, &errpos, NULL)) == NULL)
                throw(MAL, "pcre.likesubselect",
                          OPERATION_FAILED ": compilation of pattern \"%s\" 
failed\n", pat);
@@ -329,10 +354,20 @@ pcre_likesubselect(BAT **bnp, BAT *b, BA
                throw(MAL, "pcre.likesubselect",
                          OPERATION_FAILED ": studying pattern \"%s\" 
failed\n", pat);
        }
+#else
+       if ((errcode = regcomp(&re, pat, options)) != 0) {
+               throw(MAL, "pcre.likesubselect",
+                         OPERATION_FAILED ": compilation of pattern \"%s\" 
failed\n", pat);
+       }
+#endif
        bn = COLnew(0, TYPE_oid, s ? BATcount(s) : BATcount(b), TRANSIENT);
        if (bn == NULL) {
+#ifdef HAVE_LIBPCRE
                my_pcre_free(re);
                pcre_free_study(pe);
+#else
+               regfree(&re);
+#endif
                throw(MAL, "pcre.likesubselect", MAL_MALLOC_FAIL);
        }
        off = b->hseqbase;
@@ -352,10 +387,18 @@ pcre_likesubselect(BAT **bnp, BAT *b, BA
                candlist = (const oid *) Tloc(s, p);
                if (anti)
                        candscanloop(v && *v != '\200' &&
+#ifdef HAVE_LIBPCRE
                                pcre_exec(re, pe, v, (int) strlen(v), 0, 0, 
ovector, 10) == -1);
+#else
+                               regexec(&re, v, (size_t) 0, NULL, 0) == 
REG_NOMATCH);
+#endif
                else
                        candscanloop(v && *v != '\200' &&
+#ifdef HAVE_LIBPCRE
                                pcre_exec(re, pe, v, (int) strlen(v), 0, 0, 
ovector, 10) >= 0);
+#else
+                               regexec(&re, v, (size_t) 0, NULL, 0) != 
REG_NOMATCH);
+#endif
        } else {
                if (s) {
                        assert(BATtdense(s));
@@ -371,13 +414,25 @@ pcre_likesubselect(BAT **bnp, BAT *b, BA
                }
                if (anti)
                        scanloop(v && *v != '\200' &&
+#ifdef HAVE_LIBPCRE
                                pcre_exec(re, pe, v, (int) strlen(v), 0, 0, 
ovector, 10) == -1);
+#else
+                               regexec(&re, v, (size_t) 0, NULL, 0) == 
REG_NOMATCH);
+#endif
                else
                        scanloop(v && *v != '\200' &&
+#ifdef HAVE_LIBPCRE
                                pcre_exec(re, pe, v, (int) strlen(v), 0, 0, 
ovector, 10) >= 0);
+#else
+                               regexec(&re, v, (size_t) 0, NULL, 0) != 
REG_NOMATCH);
+#endif
        }
+#ifdef HAVE_LIBPCRE
        my_pcre_free(re);
        pcre_free_study(pe);
+#else
+       regfree(&re);
+#endif
        BATsetcount(bn, BATcount(bn)); /* set some properties */
        bn->tsorted = 1;
        bn->trevsorted = bn->batCount <= 1;
@@ -390,8 +445,12 @@ pcre_likesubselect(BAT **bnp, BAT *b, BA
 
   bunins_failed:
        BBPreclaim(bn);
+#ifdef HAVE_LIBPCRE
        my_pcre_free(re);
        pcre_free_study(pe);
+#else
+       regfree(&re);
+#endif
        *bnp = NULL;
        throw(MAL, "pcre.likesubselect", OPERATION_FAILED);
 }
@@ -537,6 +596,7 @@ re_likesubselect(BAT **bnp, BAT *b, BAT 
 static str
 pcre_replace(str *res, const char *origin_str, const char *pattern, const char 
*replacement, const char *flags)
 {
+#ifdef HAVE_LIBPCRE
        const char err[BUFSIZ], *err_p = err, *err_p2 = err;
        pcre *pcre_code = NULL;
        pcre_extra *extra;
@@ -640,11 +700,20 @@ pcre_replace(str *res, const char *origi
        GDKfree(ovector);
        *res = tmpres;
        return MAL_SUCCEED;
+#else
+       (void) res;
+       (void) origin_str;
+       (void) pattern;
+       (void) replacement;
+       (void) flags;
+       throw(MAL,"pcre.replace", "Database was compiled without PCRE 
support.");
+#endif
 }
 
 static str
 pcre_replace_bat(BAT **res, BAT *origin_strs, const char *pattern, const char 
*replacement, const char *flags)
 {
+#ifdef HAVE_LIBPCRE
        BATiter origin_strsi = bat_iterator(origin_strs);
        const char err[BUFSIZ], *err_p = err, *err_p2 = err;
        int i, j, k, len, errpos = 0, offset = 0;
@@ -684,7 +753,7 @@ pcre_replace_bat(BAT **res, BAT *origin_
        /* Since the compiled pattern is ging to be used several times, it is 
worth spending
         * more time analyzing it in order to speed up the time taken for 
matching.
         */
-       extra = pcre_study(pcre_code, 0, &err_p2);
+       extra = (pcre_code, 0, &err_p2);
        pcre_fullinfo(pcre_code, extra, PCRE_INFO_CAPTURECOUNT, &i);
        ovecsize = (i + 1) * 3;
        if ((ovector = (int *) GDKzalloc(sizeof(int) * ovecsize)) == NULL) {
@@ -762,39 +831,72 @@ pcre_replace_bat(BAT **res, BAT *origin_
        GDKfree(ovector);
        *res = tmpbat;
        return MAL_SUCCEED;
+#else
+       (void) res;
+       (void) origin_strs;
+       (void) pattern;
+       (void) replacement;
+       (void) flags;
+       throw(MAL,"pcre.replace_bat", "Database was compiled without PCRE 
support.");
+#endif
 }
 
 str
 pcre_init(void *ret)
 {
        (void) ret;
+#ifdef HAVE_LIBPCRE
 #if defined(HAVE_EMBEDDED) && defined(WIN32)
        // TODO: what should we do here?
 #else
        pcre_malloc = my_pcre_malloc;
        pcre_free = my_pcre_free;
 #endif
+#else
+#endif
        return NULL;
 }
 
 static str
 pcre_match_with_flags(bit *ret, const char *val, const char *pat, const char 
*flags)
 {
+       int i;
+       int pos;
+#ifdef HAVE_LIBPCRE
        const char err[BUFSIZ], *err_p = err;
        int errpos = 0;
-       int options = PCRE_UTF8, i;
-       int pos;
+       int options = PCRE_UTF8;
        pcre *re;
+#else
_______________________________________________
checkin-list mailing list
[email protected]
https://www.monetdb.org/mailman/listinfo/checkin-list

Reply via email to