Changeset: bf4445adb70b for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=bf4445adb70b
Modified Files:
        clients/Tests/MAL-signatures.stable.out
        clients/Tests/MAL-signatures.stable.out.int128
        monetdb5/modules/mal/pcre.c
        monetdb5/modules/mal/pcre.mal
Branch: default
Log Message:

Merge with Jul2017 branch.


diffs (253 lines):

diff --git a/clients/Tests/MAL-signatures.stable.out 
b/clients/Tests/MAL-signatures.stable.out
--- a/clients/Tests/MAL-signatures.stable.out
+++ b/clients/Tests/MAL-signatures.stable.out
@@ -8237,6 +8237,7 @@ Ready.
 [ "batmtime",  "seconds",      "command 
batmtime.seconds(d:bat[:daytime]):bat[:int] ", 
"MTIMEdaytime_extract_seconds_bulk;",   ""      ]
 [ "batmtime",  "sql_seconds",  "command 
batmtime.sql_seconds(d:bat[:daytime]):bat[:int] ",     
"MTIMEdaytime_extract_sql_seconds_bulk;",       ""      ]
 [ "batmtime",  "year", "command batmtime.year(d:bat[:date]):bat[:int] ",       
"MTIMEdate_extract_year_bulk;", ""      ]
+[ "batpcre",   "replace",      "command batpcre.replace(orig:bat[:str], 
pat:str, repl:str, flag:str):bat[:str] ",      "PCREreplace_bat_wrap;",        
""      ]
 [ "batpyapi",  "eval", "pattern batpyapi.eval(fptr:ptr, expr:str, 
arg:any...):any... ",        "PYAPI2PyAPIevalStd;",  "Execute a simple Python 
script value"  ]
 [ "batpyapi",  "eval_aggr",    "pattern batpyapi.eval_aggr(fptr:ptr, expr:str, 
arg:any...):any... ",   "PYAPI2PyAPIevalAggr;", "grouped aggregates through 
Python"     ]
 [ "batpyapi",  "eval_loader",  "pattern batpyapi.eval_loader(fptr:ptr, 
expr:str):any... ",     "PYAPI2PyAPIevalLoader;",       "loader functions 
through Python"       ]
@@ -10702,7 +10703,6 @@ Ready.
 [ "pcre",      "patindex",     "command pcre.patindex(pat:str, s:str):int ",   
"PCREpatindex;",        "Location of the first POSIX pattern matching against a 
string" ]
 [ "pcre",      "pcre_quote",   "command pcre.pcre_quote(s:str):str ",  
"PCREquote;",   "Return a PCRE pattern string that matches the argument 
exactly."       ]
 [ "pcre",      "prelude",      "command pcre.prelude():void ", "pcre_init;",   
"Initialize pcre"       ]
-[ "pcre",      "replace",      "command pcre.replace(orig:bat[:str], pat:str, 
repl:str, flag:str):bat[:str] ", "PCREreplace_bat_wrap;",        ""      ]
 [ "pcre",      "replace",      "command pcre.replace(origin:str, pat:str, 
repl:str, flags:str):str ",  "PCREreplace_wrap;",    "Replace _all_ matches of 
\"pattern\" in \"origin_str\" with \"replacement\".\n\t Parameter \"flags\" 
accept these flags: 'i', 'm', 's', and 'x'.\n\t   'e': if present, an empty 
string is considered to be a valid match\n\t   'i': if present, the match 
operates in case-insensitive mode.\n\t\tOtherwise, in case-sensitive mode.\n\t  
 'm': if present, the match operates in multi-line mode.\n\t   's': if present, 
the match operates in \"dot-all\"\n\t   The specifications of the flags can be 
found in \"man pcreapi\"\n\t   The flag letters may be repeated.\n\t   No other 
letters than 'e', 'i', 'm', 's' and 'x' are allowed in \"flags\".\n\t   Returns 
the replaced string, or if no matches found, the original string."   ]
 [ "pcre",      "sql2pcre",     "command pcre.sql2pcre(pat:str, esc:str):str ", 
"PCREsql2pcre;",        "Convert a SQL like pattern with the given escape 
character into a PCRE pattern."       ]
 [ "profiler",  "cleanup",      "command profiler.cleanup():void ",     
"CMDcleanupTraces;",    "Remove the temporary tables for profiling"     ]
diff --git a/clients/Tests/MAL-signatures.stable.out.int128 
b/clients/Tests/MAL-signatures.stable.out.int128
--- a/clients/Tests/MAL-signatures.stable.out.int128
+++ b/clients/Tests/MAL-signatures.stable.out.int128
@@ -11805,6 +11805,7 @@ Ready.
 [ "batmtime",  "seconds",      "command 
batmtime.seconds(d:bat[:daytime]):bat[:int] ", 
"MTIMEdaytime_extract_seconds_bulk;",   ""      ]
 [ "batmtime",  "sql_seconds",  "command 
batmtime.sql_seconds(d:bat[:daytime]):bat[:int] ",     
"MTIMEdaytime_extract_sql_seconds_bulk;",       ""      ]
 [ "batmtime",  "year", "command batmtime.year(d:bat[:date]):bat[:int] ",       
"MTIMEdate_extract_year_bulk;", ""      ]
+[ "batpcre",   "replace",      "command batpcre.replace(orig:bat[:str], 
pat:str, repl:str, flag:str):bat[:str] ",      "PCREreplace_bat_wrap;",        
""      ]
 [ "batpyapi",  "eval", "pattern batpyapi.eval(fptr:ptr, expr:str, 
arg:any...):any... ",        "PYAPI2PyAPIevalStd;",  "Execute a simple Python 
script value"  ]
 [ "batpyapi",  "eval_aggr",    "pattern batpyapi.eval_aggr(fptr:ptr, expr:str, 
arg:any...):any... ",   "PYAPI2PyAPIevalAggr;", "grouped aggregates through 
Python"     ]
 [ "batpyapi",  "eval_loader",  "pattern batpyapi.eval_loader(fptr:ptr, 
expr:str):any... ",     "PYAPI2PyAPIevalLoader;",       "loader functions 
through Python"       ]
@@ -14913,7 +14914,6 @@ Ready.
 [ "pcre",      "patindex",     "command pcre.patindex(pat:str, s:str):int ",   
"PCREpatindex;",        "Location of the first POSIX pattern matching against a 
string" ]
 [ "pcre",      "pcre_quote",   "command pcre.pcre_quote(s:str):str ",  
"PCREquote;",   "Return a PCRE pattern string that matches the argument 
exactly."       ]
 [ "pcre",      "prelude",      "command pcre.prelude():void ", "pcre_init;",   
"Initialize pcre"       ]
-[ "pcre",      "replace",      "command pcre.replace(orig:bat[:str], pat:str, 
repl:str, flag:str):bat[:str] ", "PCREreplace_bat_wrap;",        ""      ]
 [ "pcre",      "replace",      "command pcre.replace(origin:str, pat:str, 
repl:str, flags:str):str ",  "PCREreplace_wrap;",    "Replace _all_ matches of 
\"pattern\" in \"origin_str\" with \"replacement\".\n\t Parameter \"flags\" 
accept these flags: 'i', 'm', 's', and 'x'.\n\t   'e': if present, an empty 
string is considered to be a valid match\n\t   'i': if present, the match 
operates in case-insensitive mode.\n\t\tOtherwise, in case-sensitive mode.\n\t  
 'm': if present, the match operates in multi-line mode.\n\t   's': if present, 
the match operates in \"dot-all\"\n\t   The specifications of the flags can be 
found in \"man pcreapi\"\n\t   The flag letters may be repeated.\n\t   No other 
letters than 'e', 'i', 'm', 's' and 'x' are allowed in \"flags\".\n\t   Returns 
the replaced string, or if no matches found, the original string."   ]
 [ "pcre",      "sql2pcre",     "command pcre.sql2pcre(pat:str, esc:str):str ", 
"PCREsql2pcre;",        "Convert a SQL like pattern with the given escape 
character into a PCRE pattern."       ]
 [ "profiler",  "cleanup",      "command profiler.cleanup():void ",     
"CMDcleanupTraces;",    "Remove the temporary tables for profiling"     ]
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
@@ -336,8 +336,8 @@ pcre_likeselect(BAT **bnp, BAT *b, BAT *
        bn = COLnew(0, TYPE_oid, s ? BATcount(s) : BATcount(b), TRANSIENT);
        if (bn == NULL) {
 #ifdef HAVE_LIBPCRE
+               pcre_free_study(pe);
                pcre_free(re);
-               pcre_free_study(pe);
 #else
                regfree(&re);
 #endif
@@ -386,8 +386,8 @@ pcre_likeselect(BAT **bnp, BAT *b, BAT *
                        scanloop(v && *v != '\200' && BODY);
        }
 #ifdef HAVE_LIBPCRE
+       pcre_free_study(pe);
        pcre_free(re);
-       pcre_free_study(pe);
 #else
        regfree(&re);
 #endif
@@ -404,8 +404,8 @@ pcre_likeselect(BAT **bnp, BAT *b, BAT *
   bunins_failed:
        BBPreclaim(bn);
 #ifdef HAVE_LIBPCRE
+       pcre_free_study(pe);
        pcre_free(re);
-       pcre_free_study(pe);
 #else
        regfree(&re);
 #endif
@@ -584,13 +584,13 @@ pcre_replace(str *res, const char *origi
                        compile_options |= PCRE_EXTENDED;
                        break;
                default:
-                       throw(MAL, "pcre_replace", ILLEGAL_ARGUMENT ": 
unsupported flag character '%c'\n", *flags);
+                       throw(MAL, "pcre.replace", ILLEGAL_ARGUMENT ": 
unsupported flag character '%c'\n", *flags);
                }
                flags++;
        }
 
        if ((pcre_code = pcre_compile(pattern, compile_options, &err_p, 
&errpos, NULL)) == NULL) {
-               throw(MAL, "pcre_replace", OPERATION_FAILED ": pcre compile of 
pattern (%s) failed at %d with\n'%s'.\n", pattern, errpos, err_p);
+               throw(MAL, "pcre.replace", OPERATION_FAILED ": pcre compile of 
pattern (%s) failed at %d with\n'%s'.\n", pattern, errpos, err_p);
        }
 
        /* Since the compiled pattern is going to be used several times, it is
@@ -600,13 +600,13 @@ pcre_replace(str *res, const char *origi
        extra = pcre_study(pcre_code, 0, &err_p);
        if (err_p != NULL) {
                pcre_free(pcre_code);
-               throw(MAL, "pcre_replace", OPERATION_FAILED ": pcre study of 
pattern (%s) failed with '%s'.\n", pattern, err_p);
+               throw(MAL, "pcre.replace", OPERATION_FAILED ": pcre study of 
pattern (%s) failed with '%s'.\n", pattern, err_p);
        }
        pcre_fullinfo(pcre_code, extra, PCRE_INFO_CAPTURECOUNT, &i);
        ovecsize = (i + 1) * 3;
        if ((ovector = (int *) GDKmalloc(sizeof(int) * ovecsize)) == NULL) {
+               pcre_free_study(extra);
                pcre_free(pcre_code);
-               pcre_free_study(extra);
                throw(MAL, "pcre_replace", SQLSTATE(HY001) MAL_MALLOC_FAIL);
        }
 
@@ -663,7 +663,7 @@ pcre_replace(str *res, const char *origi
        pcre_free(pcre_code);
        GDKfree(ovector);
        if (tmpres == NULL)
-               throw(MAL, "pcre_replace", SQLSTATE(HY001) MAL_MALLOC_FAIL);
+               throw(MAL, "pcre.replace", SQLSTATE(HY001) MAL_MALLOC_FAIL);
        *res = tmpres;
        return MAL_SUCCEED;
 #else
@@ -712,13 +712,13 @@ pcre_replace_bat(BAT **res, BAT *origin_
                        compile_options |= PCRE_EXTENDED;
                        break;
                default:
-                       throw(MAL, "pcre_replace_bat", ILLEGAL_ARGUMENT ": 
unsupported flag character '%c'\n", *flags);
+                       throw(MAL, "batpcre.replace", ILLEGAL_ARGUMENT ": 
unsupported flag character '%c'\n", *flags);
                }
                flags++;
        }
 
        if ((pcre_code = pcre_compile(pattern, compile_options, &err_p, 
&errpos, NULL)) == NULL) {
-               throw(MAL, "pcre_replace_bat", OPERATION_FAILED
+               throw(MAL, "batpcre.replace", OPERATION_FAILED
                          ": pcre compile of pattern (%s) failed at %d 
with\n'%s'.\n",
                          pattern, errpos, err_p);
        }
@@ -730,20 +730,22 @@ pcre_replace_bat(BAT **res, BAT *origin_
        extra = pcre_study(pcre_code, 0, &err_p);
        if (err_p != NULL) {
                pcre_free(pcre_code);
-               throw(MAL, "pcre_replace_bat", OPERATION_FAILED);
+               throw(MAL, "batpcre.replace", OPERATION_FAILED);
        }
        pcre_fullinfo(pcre_code, extra, PCRE_INFO_CAPTURECOUNT, &i);
        ovecsize = (i + 1) * 3;
        if ((ovector = (int *) GDKzalloc(sizeof(int) * ovecsize)) == NULL) {
+               pcre_free_study(extra);
                pcre_free(pcre_code);
-               throw(MAL, "pcre_replace_bat", SQLSTATE(HY001) MAL_MALLOC_FAIL);
+               throw(MAL, "batpcre,replace", SQLSTATE(HY001) MAL_MALLOC_FAIL);
        }
 
        tmpbat = COLnew(origin_strs->hseqbase, TYPE_str, BATcount(origin_strs), 
TRANSIENT);
        if (tmpbat == NULL) {
+               pcre_free_study(extra);
                pcre_free(pcre_code);
                GDKfree(ovector);
-               throw(MAL, "pcre.replace", SQLSTATE(HY001) MAL_MALLOC_FAIL);
+               throw(MAL, "batpcre.replace", SQLSTATE(HY001) MAL_MALLOC_FAIL);
        }
        BATloop(origin_strs, p, q) {
                origin_str = BUNtail(origin_strsi, p);
@@ -765,11 +767,11 @@ pcre_replace_bat(BAT **res, BAT *origin_
                if (ncaptures > 0) {
                        replaced_str = GDKmalloc(len_origin_str - len_del + 
(len_replacement * ncaptures) + 1);
                        if (replaced_str == NULL) {
+                               pcre_free_study(extra);
                                pcre_free(pcre_code);
-                               pcre_free_study(extra);
                                GDKfree(ovector);
                                BBPreclaim(tmpbat);
-                               throw(MAL, "pcre_replace_bat", SQLSTATE(HY001) 
MAL_MALLOC_FAIL);
+                               throw(MAL, "batpcre.replace", SQLSTATE(HY001) 
MAL_MALLOC_FAIL);
                        }
 
                        j = k = 0;
@@ -799,21 +801,22 @@ pcre_replace_bat(BAT **res, BAT *origin_
                        k += len;
                        replaced_str[k] = '\0';
                        if (BUNappend(tmpbat, replaced_str, FALSE) != 
GDK_SUCCEED) {
+                               pcre_free_study(extra);
                                pcre_free(pcre_code);
-                               pcre_free_study(extra);
                                GDKfree(ovector);
                                GDKfree(replaced_str);
                                BBPreclaim(tmpbat);
-                               throw(MAL, "pcre_replace_bat", SQLSTATE(HY001) 
MAL_MALLOC_FAIL);
+                               throw(MAL, "batpcre.replace", SQLSTATE(HY001) 
MAL_MALLOC_FAIL);
                        }
                        GDKfree(replaced_str);
-               } else { /* no captured substrings, copy the original string 
into new bat */
+               } else {
+                       /* no captured substrings, copy the original string 
into new bat */
                        if (BUNappend(tmpbat, origin_str, FALSE) != 
GDK_SUCCEED) {
+                               pcre_free_study(extra);
                                pcre_free(pcre_code);
-                               pcre_free_study(extra);
                                GDKfree(ovector);
                                BBPreclaim(tmpbat);
-                               throw(MAL, "pcre_replace_bat", SQLSTATE(HY001) 
MAL_MALLOC_FAIL);
+                               throw(MAL, "batpcre.replace", SQLSTATE(HY001) 
MAL_MALLOC_FAIL);
                        }
                }
        }
@@ -829,7 +832,7 @@ pcre_replace_bat(BAT **res, BAT *origin_
        (void) pattern;
        (void) replacement;
        (void) flags;
-       throw(MAL, "pcre.replace_bat", "Database was compiled without PCRE 
support.");
+       throw(MAL, "batpcre.replace", "Database was compiled without PCRE 
support.");
 #endif
 }
 
@@ -1788,8 +1791,8 @@ pcrejoin(BAT *r1, BAT *r2, BAT *l, BAT *
                }
                if (pcrere) {
 #ifdef HAVE_LIBPCRE
+                       pcre_free_study(pcreex);
                        pcre_free(pcrere);
-                       pcre_free_study(pcreex);
                        pcrere = NULL;
                        pcreex = NULL;
 #else
@@ -1833,10 +1836,10 @@ pcrejoin(BAT *r1, BAT *r2, BAT *l, BAT *
        if (pcrepat)
                GDKfree(pcrepat);
 #ifdef HAVE_LIBPCRE
+       if (pcreex)
+               pcre_free_study(pcreex);
        if (pcrere)
                pcre_free(pcrere);
-       if (pcreex)
-               pcre_free_study(pcreex);
 #else
        if (pcrere)
                regfree(&regex);
diff --git a/monetdb5/modules/mal/pcre.mal b/monetdb5/modules/mal/pcre.mal
--- a/monetdb5/modules/mal/pcre.mal
+++ b/monetdb5/modules/mal/pcre.mal
@@ -35,9 +35,6 @@ comment "Replace _all_ matches of \"patt
           No other letters than 'e', 'i', 'm', 's' and 'x' are allowed in 
\"flags\".
           Returns the replaced string, or if no matches found, the original 
string.";
 
-command replace(orig:bat[:str],pat:str,repl:str,flag:str):bat[:str]
-address PCREreplace_bat_wrap;
-
 command pcre_quote(s:str):str
 address PCREquote
 comment "Return a PCRE pattern string that matches the argument exactly.";
@@ -64,6 +61,11 @@ command algebra.ilike(s:str, pat:str):bi
 command algebra.not_ilike(s:str, pat:str, esc:str):bit address PCREnotilike3;
 command algebra.not_ilike(s:str, pat:str):bit address PCREnotilike2;
 
+module batpcre;
+
+command batpcre.replace(orig:bat[:str],pat:str,repl:str,flag:str):bat[:str]
+address PCREreplace_bat_wrap;
+
 module batalgebra;
 
 command batalgebra.like(s:bat[:str], pat:str, esc:str):bat[:bit] address 
BATPCRElike;
_______________________________________________
checkin-list mailing list
checkin-list@monetdb.org
https://www.monetdb.org/mailman/listinfo/checkin-list

Reply via email to