PostgreSQL Source Code  git master
regex.h File Reference
#include "mb/pg_wchar.h"
Include dependency graph for regex.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  regex_t
 
struct  regmatch_t
 
struct  rm_detail_t
 

Macros

#define _REGEX_H_   /* never again */
 
#define REG_UBACKREF   000001 /* has back-reference (\n) */
 
#define REG_ULOOKAROUND   000002 /* has lookahead/lookbehind constraint */
 
#define REG_UBOUNDS   000004 /* has bounded quantifier ({m,n}) */
 
#define REG_UBRACES   000010 /* has { that doesn't begin a quantifier */
 
#define REG_UBSALNUM   000020 /* has backslash-alphanumeric in non-ARE */
 
#define REG_UPBOTCH
 
#define REG_UBBS   000100 /* has backslash within bracket expr */
 
#define REG_UNONPOSIX   000200 /* has any construct that extends POSIX */
 
#define REG_UUNSPEC
 
#define REG_UUNPORT   001000 /* has numeric character code dependency */
 
#define REG_ULOCALE   002000 /* has locale dependency */
 
#define REG_UEMPTYMATCH   004000 /* can match a zero-length string */
 
#define REG_UIMPOSSIBLE   010000 /* provably cannot match anything */
 
#define REG_USHORTEST   020000 /* has non-greedy quantifier */
 
#define REG_BASIC   000000 /* BREs (convenience) */
 
#define REG_EXTENDED   000001 /* EREs */
 
#define REG_ADVF   000002 /* advanced features in EREs */
 
#define REG_ADVANCED   000003 /* AREs (which are also EREs) */
 
#define REG_QUOTE   000004 /* no special characters, none */
 
#define REG_NOSPEC   REG_QUOTE /* historical synonym */
 
#define REG_ICASE   000010 /* ignore case */
 
#define REG_NOSUB   000020 /* don't care about subexpressions */
 
#define REG_EXPANDED   000040 /* expanded format, white space & comments */
 
#define REG_NLSTOP   000100 /* \n doesn't match . or [^ ] */
 
#define REG_NLANCH   000200 /* ^ matches after \n, $ before */
 
#define REG_NEWLINE   000300 /* newlines are line terminators */
 
#define REG_PEND   000400 /* ugh -- backward-compatibility hack */
 
#define REG_EXPECT   001000 /* report details on partial/limited matches */
 
#define REG_BOSONLY   002000 /* temporary kludge for BOS-only matches */
 
#define REG_DUMP   004000 /* none of your business :-) */
 
#define REG_FAKE   010000 /* none of your business :-) */
 
#define REG_PROGRESS   020000 /* none of your business :-) */
 
#define REG_NOTBOL   0001 /* BOS is not BOL */
 
#define REG_NOTEOL   0002 /* EOS is not EOL */
 
#define REG_STARTEND   0004 /* backward compatibility kludge */
 
#define REG_FTRACE   0010 /* none of your business */
 
#define REG_MTRACE   0020 /* none of your business */
 
#define REG_SMALL   0040 /* none of your business */
 
#define REG_OKAY   0 /* no errors detected */
 
#define REG_NOMATCH   1 /* failed to match */
 
#define REG_BADPAT   2 /* invalid regexp */
 
#define REG_ECOLLATE   3 /* invalid collating element */
 
#define REG_ECTYPE   4 /* invalid character class */
 
#define REG_EESCAPE   5 /* invalid escape \ sequence */
 
#define REG_ESUBREG   6 /* invalid backreference number */
 
#define REG_EBRACK   7 /* brackets [] not balanced */
 
#define REG_EPAREN   8 /* parentheses () not balanced */
 
#define REG_EBRACE   9 /* braces {} not balanced */
 
#define REG_BADBR   10 /* invalid repetition count(s) */
 
#define REG_ERANGE   11 /* invalid character range */
 
#define REG_ESPACE   12 /* out of memory */
 
#define REG_BADRPT   13 /* quantifier operand invalid */
 
#define REG_ASSERT   15 /* "can't happen" -- you found a bug */
 
#define REG_INVARG   16 /* invalid argument to regex function */
 
#define REG_MIXED   17 /* character widths of regex and string differ */
 
#define REG_BADOPT   18 /* invalid embedded option */
 
#define REG_ETOOBIG   19 /* regular expression is too complex */
 
#define REG_ECOLORS   20 /* too many colors */
 
#define REG_CANCEL   21 /* operation cancelled */
 
#define REG_ATOI   101 /* convert error-code name to number */
 
#define REG_ITOA   102 /* convert error-code number to name */
 
#define REG_PREFIX   (-1) /* identified a common prefix */
 
#define REG_EXACT   (-2) /* identified an exact match */
 

Typedefs

typedef long regoff_t
 

Functions

int pg_regcomp (regex_t *, const pg_wchar *, size_t, int, Oid)
 
int pg_regexec (regex_t *, const pg_wchar *, size_t, size_t, rm_detail_t *, size_t, regmatch_t[], int)
 
int pg_regprefix (regex_t *, pg_wchar **, size_t *)
 
void pg_regfree (regex_t *)
 
size_t pg_regerror (int, const regex_t *, char *, size_t)
 
regex_tRE_compile_and_cache (text *text_re, int cflags, Oid collation)
 
bool RE_compile_and_execute (text *text_re, char *dat, int dat_len, int cflags, Oid collation, int nmatch, regmatch_t *pmatch)
 

Macro Definition Documentation

◆ _REGEX_H_

#define _REGEX_H_   /* never again */

Definition at line 2 of file regex.h.

◆ REG_ADVANCED

◆ REG_ADVF

#define REG_ADVF   000002 /* advanced features in EREs */

Definition at line 104 of file regex.h.

Referenced by lexescape(), lexstart(), next(), parse_test_flags(), pg_regcomp(), and prefixes().

◆ REG_ASSERT

#define REG_ASSERT   15 /* "can't happen" -- you found a bug */

◆ REG_ATOI

#define REG_ATOI   101 /* convert error-code name to number */

Definition at line 161 of file regex.h.

Referenced by pg_regerror().

◆ REG_BADBR

#define REG_BADBR   10 /* invalid repetition count(s) */

Definition at line 149 of file regex.h.

Referenced by next(), parseqatom(), and scannum().

◆ REG_BADOPT

#define REG_BADOPT   18 /* invalid embedded option */

Definition at line 156 of file regex.h.

Referenced by prefixes().

◆ REG_BADPAT

#define REG_BADPAT   2 /* invalid regexp */

Definition at line 141 of file regex.h.

Referenced by prefixes().

◆ REG_BADRPT

#define REG_BADRPT   13 /* quantifier operand invalid */

Definition at line 152 of file regex.h.

Referenced by next(), parseqatom(), and prefixes().

◆ REG_BASIC

#define REG_BASIC   000000 /* BREs (convenience) */

Definition at line 102 of file regex.h.

◆ REG_BOSONLY

#define REG_BOSONLY   002000 /* temporary kludge for BOS-only matches */

Definition at line 116 of file regex.h.

Referenced by next(), and parse_test_flags().

◆ REG_CANCEL

#define REG_CANCEL   21 /* operation cancelled */

Definition at line 159 of file regex.h.

Referenced by cdissect(), copyins(), copyouts(), mergeins(), miss(), moveins(), moveouts(), newarc(), newstate(), and range().

◆ REG_DUMP

#define REG_DUMP   004000 /* none of your business :-) */

Definition at line 117 of file regex.h.

Referenced by parse_test_flags(), and pg_regcomp().

◆ REG_EBRACE

#define REG_EBRACE   9 /* braces {} not balanced */

Definition at line 148 of file regex.h.

Referenced by next().

◆ REG_EBRACK

#define REG_EBRACK   7 /* brackets [] not balanced */

Definition at line 146 of file regex.h.

Referenced by next().

◆ REG_ECOLLATE

#define REG_ECOLLATE   3 /* invalid collating element */

Definition at line 142 of file regex.h.

Referenced by brackpart(), and element().

◆ REG_ECOLORS

#define REG_ECOLORS   20 /* too many colors */

Definition at line 158 of file regex.h.

Referenced by newcolor().

◆ REG_ECTYPE

#define REG_ECTYPE   4 /* invalid character class */

Definition at line 143 of file regex.h.

Referenced by brackpart(), and lookupcclass().

◆ REG_EESCAPE

#define REG_EESCAPE   5 /* invalid escape \ sequence */

Definition at line 144 of file regex.h.

Referenced by brenext(), lexdigits(), lexescape(), and next().

◆ REG_EPAREN

#define REG_EPAREN   8 /* parentheses () not balanced */

Definition at line 147 of file regex.h.

Referenced by parse(), and parseqatom().

◆ REG_ERANGE

#define REG_ERANGE   11 /* invalid character range */

Definition at line 150 of file regex.h.

Referenced by brackpart(), and range().

◆ REG_ESPACE

◆ REG_ESUBREG

#define REG_ESUBREG   6 /* invalid backreference number */

Definition at line 145 of file regex.h.

Referenced by parseqatom().

◆ REG_ETOOBIG

#define REG_ETOOBIG   19 /* regular expression is too complex */

◆ REG_EXACT

#define REG_EXACT   (-2) /* identified an exact match */

Definition at line 165 of file regex.h.

Referenced by findprefix(), pg_regprefix(), and regexp_fixed_prefix().

◆ REG_EXPANDED

#define REG_EXPANDED   000040 /* expanded format, white space & comments */

Definition at line 110 of file regex.h.

Referenced by brenext(), lexstart(), next(), parse_re_flags(), parse_test_flags(), pg_regcomp(), prefixes(), and skip().

◆ REG_EXPECT

#define REG_EXPECT   001000 /* report details on partial/limited matches */

Definition at line 115 of file regex.h.

Referenced by build_test_match_result(), cfind(), find(), parse_test_flags(), and pg_regexec().

◆ REG_EXTENDED

#define REG_EXTENDED   000001 /* EREs */

Definition at line 103 of file regex.h.

Referenced by lexstart(), next(), parse_re_flags(), parse_test_flags(), parseqatom(), pg_regcomp(), and prefixes().

◆ REG_FAKE

#define REG_FAKE   010000 /* none of your business :-) */

Definition at line 118 of file regex.h.

Referenced by eclass(), and parse_test_flags().

◆ REG_FTRACE

#define REG_FTRACE   0010 /* none of your business */

Definition at line 129 of file regex.h.

Referenced by longest(), matchuntil(), parse_test_flags(), pg_regexec(), and shortest().

◆ REG_ICASE

◆ REG_INVARG

#define REG_INVARG   16 /* invalid argument to regex function */

Definition at line 154 of file regex.h.

Referenced by pg_regcomp(), pg_regexec(), and pg_regprefix().

◆ REG_ITOA

#define REG_ITOA   102 /* convert error-code number to name */

Definition at line 162 of file regex.h.

Referenced by pg_regerror().

◆ REG_MIXED

#define REG_MIXED   17 /* character widths of regex and string differ */

Definition at line 155 of file regex.h.

Referenced by pg_regexec(), and pg_regprefix().

◆ REG_MTRACE

#define REG_MTRACE   0020 /* none of your business */

Definition at line 130 of file regex.h.

Referenced by parse_test_flags(), and pg_regexec().

◆ REG_NEWLINE

#define REG_NEWLINE   000300 /* newlines are line terminators */

Definition at line 113 of file regex.h.

Referenced by lexstart(), parse_re_flags(), parse_test_flags(), pg_regcomp(), and prefixes().

◆ REG_NLANCH

#define REG_NLANCH   000200 /* ^ matches after \n, $ before */

Definition at line 112 of file regex.h.

Referenced by parse_re_flags(), parse_test_flags(), parseqatom(), pg_regcomp(), and prefixes().

◆ REG_NLSTOP

#define REG_NLSTOP   000100 /* \n doesn't match . or [^ ] */

Definition at line 111 of file regex.h.

Referenced by cbracket(), parse_re_flags(), parse_test_flags(), parseqatom(), pg_regcomp(), and prefixes().

◆ REG_NOMATCH

◆ REG_NOSPEC

#define REG_NOSPEC   REG_QUOTE /* historical synonym */

Definition at line 107 of file regex.h.

◆ REG_NOSUB

#define REG_NOSUB   000020 /* don't care about subexpressions */

Definition at line 109 of file regex.h.

Referenced by next(), NIAddAffix(), parse_test_flags(), and pg_regexec().

◆ REG_NOTBOL

#define REG_NOTBOL   0001 /* BOS is not BOL */

Definition at line 126 of file regex.h.

Referenced by longest(), matchuntil(), parse_test_flags(), and shortest().

◆ REG_NOTEOL

#define REG_NOTEOL   0002 /* EOS is not EOL */

Definition at line 127 of file regex.h.

Referenced by longest(), matchuntil(), parse_test_flags(), and shortest().

◆ REG_OKAY

◆ REG_PEND

#define REG_PEND   000400 /* ugh -- backward-compatibility hack */

Definition at line 114 of file regex.h.

◆ REG_PREFIX

#define REG_PREFIX   (-1) /* identified a common prefix */

Definition at line 164 of file regex.h.

Referenced by findprefix(), pg_regprefix(), and regexp_fixed_prefix().

◆ REG_PROGRESS

#define REG_PROGRESS   020000 /* none of your business :-) */

Definition at line 119 of file regex.h.

Referenced by parse_test_flags(), and pg_regcomp().

◆ REG_QUOTE

#define REG_QUOTE   000004 /* no special characters, none */

Definition at line 106 of file regex.h.

Referenced by lexstart(), parse_re_flags(), parse_test_flags(), pg_regcomp(), and prefixes().

◆ REG_SMALL

#define REG_SMALL   0040 /* none of your business */

Definition at line 131 of file regex.h.

Referenced by newdfa(), and parse_test_flags().

◆ REG_STARTEND

#define REG_STARTEND   0004 /* backward compatibility kludge */

Definition at line 128 of file regex.h.

◆ REG_UBACKREF

#define REG_UBACKREF   000001 /* has back-reference (\n) */

Definition at line 60 of file regex.h.

Referenced by brenext(), build_test_info_result(), lexescape(), parse_test_flags(), and pg_regexec().

◆ REG_UBBS

#define REG_UBBS   000100 /* has backslash within bracket expr */

Definition at line 67 of file regex.h.

Referenced by build_test_info_result(), next(), and parse_test_flags().

◆ REG_UBOUNDS

#define REG_UBOUNDS   000004 /* has bounded quantifier ({m,n}) */

Definition at line 62 of file regex.h.

Referenced by brenext(), build_test_info_result(), next(), and parse_test_flags().

◆ REG_UBRACES

#define REG_UBRACES   000010 /* has { that doesn't begin a quantifier */

Definition at line 63 of file regex.h.

Referenced by build_test_info_result(), next(), and parse_test_flags().

◆ REG_UBSALNUM

#define REG_UBSALNUM   000020 /* has backslash-alphanumeric in non-ARE */

Definition at line 64 of file regex.h.

Referenced by brenext(), build_test_info_result(), next(), and parse_test_flags().

◆ REG_UEMPTYMATCH

#define REG_UEMPTYMATCH   004000 /* can match a zero-length string */

Definition at line 73 of file regex.h.

Referenced by analyze(), build_test_info_result(), and parse_test_flags().

◆ REG_UIMPOSSIBLE

#define REG_UIMPOSSIBLE   010000 /* provably cannot match anything */

Definition at line 74 of file regex.h.

Referenced by analyze(), build_test_info_result(), parse_test_flags(), pg_regexec(), and pg_regprefix().

◆ REG_ULOCALE

#define REG_ULOCALE   002000 /* has locale dependency */

◆ REG_ULOOKAROUND

#define REG_ULOOKAROUND   000002 /* has lookahead/lookbehind constraint */

Definition at line 61 of file regex.h.

Referenced by build_test_info_result(), next(), and parse_test_flags().

◆ REG_UNONPOSIX

#define REG_UNONPOSIX   000200 /* has any construct that extends POSIX */

Definition at line 68 of file regex.h.

Referenced by brenext(), build_test_info_result(), lexescape(), next(), parse_test_flags(), prefixes(), and skip().

◆ REG_UPBOTCH

#define REG_UPBOTCH
Value:
000040 /* has unmatched right paren in ERE (legal
* per spec, but that was a mistake) */

Definition at line 65 of file regex.h.

Referenced by build_test_info_result(), parse_test_flags(), and parseqatom().

◆ REG_USHORTEST

#define REG_USHORTEST   020000 /* has non-greedy quantifier */

Definition at line 75 of file regex.h.

Referenced by build_test_info_result(), parse_test_flags(), and pg_regcomp().

◆ REG_UUNPORT

#define REG_UUNPORT   001000 /* has numeric character code dependency */

Definition at line 71 of file regex.h.

Referenced by brackpart(), build_test_info_result(), lexescape(), and parse_test_flags().

◆ REG_UUNSPEC

#define REG_UUNSPEC
Value:
000400 /* has any case disallowed by POSIX, e.g.
* an empty branch */

Definition at line 69 of file regex.h.

Referenced by brenext(), build_test_info_result(), next(), parse_test_flags(), and parsebranch().

Typedef Documentation

◆ regoff_t

typedef long regoff_t

Definition at line 48 of file regex.h.

Function Documentation

◆ pg_regcomp()

int pg_regcomp ( regex_t ,
const pg_wchar ,
size_t  ,
int  ,
Oid   
)

Definition at line 329 of file regcomp.c.

References assert, casecmp(), vars::cflags, guts::cflags, cleanst(), vars::cm, guts::cmap, cmp(), CNOERR, COLORLESS, compact(), vars::cv, vars::cv2, debug, DISCARD, dumpnfa(), EOS, vars::err, nfa::final, subre::flags, fprintf, freev(), vars::g, GUTSMAGIC, i, guts::info, nfa::init, initcm(), vars::lacons, guts::lacons, subre::latype, LATYPE_IS_AHEAD, lexstart(), guts::magic, makesearch(), MALLOC, markst(), newcvec(), newline(), newnfa(), vars::nfa, nfanode(), nfatree(), vars::nlacons, guts::nlacons, vars::nlcolor, NOTE, vars::now, guts::nsub, vars::nsubexp, vars::nsubs, vars::ntree, guts::ntree, numst(), okcolors(), optimize(), optst(), parse(), pg_set_regex_collation(), PLAIN, vars::re, regex_t::re_collation, regex_t::re_csize, regex_t::re_fns, regex_t::re_guts, regex_t::re_info, regex_t::re_magic, regex_t::re_nsub, REG_ADVANCED, REG_ADVF, REG_DUMP, REG_ESPACE, REG_EXPANDED, REG_EXTENDED, REG_ICASE, REG_INVARG, REG_NEWLINE, REG_NLANCH, REG_NLSTOP, REG_PROGRESS, REG_QUOTE, REG_USHORTEST, REMAGIC, guts::search, SEE, SHORTER, vars::spaceused, specialcolors(), generate_unaccent_rules::stdout, vars::stop, vars::sub10, subcolor(), vars::subs, vars::tree, guts::tree, vars::treechain, vars::treefree, VS, vars::wordchrs, and ZAPCNFA.

Referenced by NIAddAffix(), parse_ident_line(), RE_compile(), RE_compile_and_cache(), and test_re_compile().

334 {
335  struct vars var;
336  struct vars *v = &var;
337  struct guts *g;
338  int i;
339  size_t j;
340 
341 #ifdef REG_DEBUG
342  FILE *debug = (flags & REG_PROGRESS) ? stdout : (FILE *) NULL;
343 #else
344  FILE *debug = (FILE *) NULL;
345 #endif
346 
347 #define CNOERR() { if (ISERR()) return freev(v, v->err); }
348 
349  /* sanity checks */
350 
351  if (re == NULL || string == NULL)
352  return REG_INVARG;
353  if ((flags & REG_QUOTE) &&
354  (flags & (REG_ADVANCED | REG_EXPANDED | REG_NEWLINE)))
355  return REG_INVARG;
356  if (!(flags & REG_EXTENDED) && (flags & REG_ADVF))
357  return REG_INVARG;
358 
359  /* Initialize locale-dependent support */
360  pg_set_regex_collation(collation);
361 
362  /* initial setup (after which freev() is callable) */
363  v->re = re;
364  v->now = string;
365  v->stop = v->now + len;
366  v->err = 0;
367  v->cflags = flags;
368  v->nsubexp = 0;
369  v->subs = v->sub10;
370  v->nsubs = 10;
371  for (j = 0; j < v->nsubs; j++)
372  v->subs[j] = NULL;
373  v->nfa = NULL;
374  v->cm = NULL;
375  v->nlcolor = COLORLESS;
376  v->wordchrs = NULL;
377  v->tree = NULL;
378  v->treechain = NULL;
379  v->treefree = NULL;
380  v->cv = NULL;
381  v->cv2 = NULL;
382  v->lacons = NULL;
383  v->nlacons = 0;
384  v->spaceused = 0;
385  re->re_magic = REMAGIC;
386  re->re_info = 0; /* bits get set during parse */
387  re->re_csize = sizeof(chr);
388  re->re_collation = collation;
389  re->re_guts = NULL;
390  re->re_fns = VS(&functions);
391 
392  /* more complex setup, malloced things */
393  re->re_guts = VS(MALLOC(sizeof(struct guts)));
394  if (re->re_guts == NULL)
395  return freev(v, REG_ESPACE);
396  g = (struct guts *) re->re_guts;
397  g->tree = NULL;
398  initcm(v, &g->cmap);
399  v->cm = &g->cmap;
400  g->lacons = NULL;
401  g->nlacons = 0;
402  ZAPCNFA(g->search);
403  v->nfa = newnfa(v, v->cm, (struct nfa *) NULL);
404  CNOERR();
405  /* set up a reasonably-sized transient cvec for getcvec usage */
406  v->cv = newcvec(100, 20);
407  if (v->cv == NULL)
408  return freev(v, REG_ESPACE);
409 
410  /* parsing */
411  lexstart(v); /* also handles prefixes */
412  if ((v->cflags & REG_NLSTOP) || (v->cflags & REG_NLANCH))
413  {
414  /* assign newline a unique color */
415  v->nlcolor = subcolor(v->cm, newline());
416  okcolors(v->nfa, v->cm);
417  }
418  CNOERR();
419  v->tree = parse(v, EOS, PLAIN, v->nfa->init, v->nfa->final);
420  assert(SEE(EOS)); /* even if error; ISERR() => SEE(EOS) */
421  CNOERR();
422  assert(v->tree != NULL);
423 
424  /* finish setup of nfa and its subre tree */
425  specialcolors(v->nfa);
426  CNOERR();
427 #ifdef REG_DEBUG
428  if (debug != NULL)
429  {
430  fprintf(debug, "\n\n\n========= RAW ==========\n");
431  dumpnfa(v->nfa, debug);
432  dumpst(v->tree, debug, 1);
433  }
434 #endif
435  optst(v, v->tree);
436  v->ntree = numst(v->tree, 1);
437  markst(v->tree);
438  cleanst(v);
439 #ifdef REG_DEBUG
440  if (debug != NULL)
441  {
442  fprintf(debug, "\n\n\n========= TREE FIXED ==========\n");
443  dumpst(v->tree, debug, 1);
444  }
445 #endif
446 
447  /* build compacted NFAs for tree and lacons */
448  re->re_info |= nfatree(v, v->tree, debug);
449  CNOERR();
450  assert(v->nlacons == 0 || v->lacons != NULL);
451  for (i = 1; i < v->nlacons; i++)
452  {
453  struct subre *lasub = &v->lacons[i];
454 
455 #ifdef REG_DEBUG
456  if (debug != NULL)
457  fprintf(debug, "\n\n\n========= LA%d ==========\n", i);
458 #endif
459 
460  /* Prepend .* to pattern if it's a lookbehind LACON */
461  nfanode(v, lasub, !LATYPE_IS_AHEAD(lasub->latype), debug);
462  }
463  CNOERR();
464  if (v->tree->flags & SHORTER)
466 
467  /* build compacted NFAs for tree, lacons, fast search */
468 #ifdef REG_DEBUG
469  if (debug != NULL)
470  fprintf(debug, "\n\n\n========= SEARCH ==========\n");
471 #endif
472  /* can sacrifice main NFA now, so use it as work area */
473  (DISCARD) optimize(v->nfa, debug);
474  CNOERR();
475  makesearch(v, v->nfa);
476  CNOERR();
477  compact(v->nfa, &g->search);
478  CNOERR();
479 
480  /* looks okay, package it up */
481  re->re_nsub = v->nsubexp;
482  v->re = NULL; /* freev no longer frees re */
483  g->magic = GUTSMAGIC;
484  g->cflags = v->cflags;
485  g->info = re->re_info;
486  g->nsub = re->re_nsub;
487  g->tree = v->tree;
488  v->tree = NULL;
489  g->ntree = v->ntree;
490  g->compare = (v->cflags & REG_ICASE) ? casecmp : cmp;
491  g->lacons = v->lacons;
492  v->lacons = NULL;
493  g->nlacons = v->nlacons;
494 
495 #ifdef REG_DEBUG
496  if (flags & REG_DUMP)
497  {
498  dump(re, stdout);
499  fflush(stdout);
500  }
501 #endif
502 
503  assert(v->err == 0);
504  return freev(v, 0);
505 }
#define REG_USHORTEST
Definition: regex.h:75
static chr newline(void)
struct subre * treefree
Definition: regcomp.c:259
static void optst(struct vars *, struct subre *)
Definition: regcomp.c:2129
#define REG_NLSTOP
Definition: regex.h:111
static void okcolors(struct nfa *, struct colormap *)
static int numst(struct subre *, int)
Definition: regcomp.c:2145
static long optimize(struct nfa *, FILE *)
int ntree
Definition: regcomp.c:260
static bool debug
Definition: initdb.c:140
struct subre * lacons
Definition: regguts.h:538
struct subre * tree
Definition: regguts.h:533
struct state * final
Definition: regguts.h:347
static long nfatree(struct vars *, struct subre *, FILE *)
Definition: regcomp.c:2212
struct subre * treechain
Definition: regcomp.c:258
#define REG_ESPACE
Definition: regex.h:151
static int freev(struct vars *, int)
Definition: regcomp.c:548
static void specialcolors(struct nfa *)
#define REG_QUOTE
Definition: regex.h:106
static struct cvec * newcvec(int, int)
color nlcolor
Definition: regcomp.c:255
int nlacons
Definition: regguts.h:539
#define REMAGIC
Definition: regguts.h:96
static color subcolor(struct colormap *, chr)
Definition: regguts.h:343
char latype
Definition: regguts.h:489
#define fprintf
Definition: port.h:220
#define REG_ICASE
Definition: regex.h:108
static void makesearch(struct vars *, struct nfa *)
Definition: regcomp.c:577
int nsubexp
Definition: regcomp.c:249
#define MALLOC(n)
Definition: regcustom.h:60
#define REG_PROGRESS
Definition: regex.h:119
struct cnfa search
Definition: regguts.h:534
pg_wchar chr
Definition: regcustom.h:66
struct colormap * cm
Definition: regcomp.c:254
#define ZAPCNFA(cnfa)
Definition: regguts.h:429
static void dumpnfa(struct nfa *, FILE *)
regex_t * re
Definition: regcomp.c:240
int nlacons
Definition: regcomp.c:264
int magic
Definition: regguts.h:528
#define REG_INVARG
Definition: regex.h:154
static void markst(struct subre *)
Definition: regcomp.c:2178
char flags
Definition: regguts.h:474
struct subre ** subs
Definition: regcomp.c:250
static struct nfa * newnfa(struct vars *, struct colormap *, struct nfa *)
char string[11]
Definition: preproc-type.c:46
struct colormap cmap
Definition: regguts.h:536
#define assert(TEST)
Definition: imath.c:73
#define LATYPE_IS_AHEAD(la)
Definition: regguts.h:104
#define REG_NEWLINE
Definition: regex.h:113
#define REG_ADVANCED
Definition: regex.h:105
#define SEE(t)
Definition: regcomp.c:271
size_t nsubs
Definition: regcomp.c:251
int err
Definition: regcomp.c:243
static long nfanode(struct vars *, struct subre *, int, FILE *)
Definition: regcomp.c:2232
struct nfa * nfa
Definition: regcomp.c:253
#define REG_EXTENDED
Definition: regex.h:103
struct cvec * cv
Definition: regcomp.c:261
struct cvec * cv2
Definition: regcomp.c:262
#define REG_ADVF
Definition: regex.h:104
#define PLAIN
Definition: regcomp.c:288
struct state * wordchrs
Definition: regcomp.c:256
#define REG_DUMP
Definition: regex.h:117
Definition: regguts.h:526
int ntree
Definition: regguts.h:535
#define EOS
Definition: regcomp.c:287
#define GUTSMAGIC
Definition: regguts.h:529
void pg_set_regex_collation(Oid collation)
const chr * now
Definition: regcomp.c:241
#define REG_NLANCH
Definition: regex.h:112
static const struct fns functions
Definition: regcomp.c:314
#define VS(x)
Definition: regguts.h:61
static int cmp(const chr *, const chr *, size_t)
static void initcm(struct vars *, struct colormap *)
long info
Definition: regguts.h:531
Definition: regguts.h:471
#define NOTE(b)
Definition: regcomp.c:282
#define CNOERR()
const chr * stop
Definition: regcomp.c:242
int cflags
Definition: regguts.h:530
struct state * init
Definition: regguts.h:346
int cflags
Definition: regcomp.c:244
size_t nsub
Definition: regguts.h:532
static void lexstart(struct vars *)
static int casecmp(const chr *, const chr *, size_t)
#define SHORTER
Definition: regguts.h:476
int i
struct subre * sub10[10]
Definition: regcomp.c:252
#define COLORLESS
Definition: regguts.h:153
#define REG_EXPANDED
Definition: regex.h:110
#define DISCARD
Definition: regguts.h:58
struct subre * tree
Definition: regcomp.c:257
static void cleanst(struct vars *)
Definition: regcomp.c:2193
size_t spaceused
Definition: regcomp.c:266
struct subre * lacons
Definition: regcomp.c:263
Definition: regcomp.c:238
static void compact(struct nfa *, struct cnfa *)
static struct subre * parse(struct vars *, int, int, struct state *, struct state *)
Definition: regcomp.c:666

◆ pg_regerror()

size_t pg_regerror ( int  ,
const regex_t ,
char *  ,
size_t   
)

Definition at line 60 of file regerror.c.

References rerr::code, rerr::explain, rerr::name, REG_ATOI, REG_ITOA, rerrs, sprintf, and unk.

Referenced by check_ident_usermap(), NIAddAffix(), parse_ident_line(), RE_compile(), RE_compile_and_cache(), RE_wchar_execute(), regexp_fixed_prefix(), replace_text_regexp(), test_re_compile(), and test_re_execute().

64 {
65  const struct rerr *r;
66  const char *msg;
67  char convbuf[sizeof(unk) + 50]; /* 50 = plenty for int */
68  size_t len;
69  int icode;
70 
71  switch (errcode)
72  {
73  case REG_ATOI: /* convert name to number */
74  for (r = rerrs; r->code >= 0; r++)
75  if (strcmp(r->name, errbuf) == 0)
76  break;
77  sprintf(convbuf, "%d", r->code); /* -1 for unknown */
78  msg = convbuf;
79  break;
80  case REG_ITOA: /* convert number to name */
81  icode = atoi(errbuf); /* not our problem if this fails */
82  for (r = rerrs; r->code >= 0; r++)
83  if (r->code == icode)
84  break;
85  if (r->code >= 0)
86  msg = r->name;
87  else
88  { /* unknown; tell him the number */
89  sprintf(convbuf, "REG_%u", (unsigned) icode);
90  msg = convbuf;
91  }
92  break;
93  default: /* a real, normal error code */
94  for (r = rerrs; r->code >= 0; r++)
95  if (r->code == errcode)
96  break;
97  if (r->code >= 0)
98  msg = r->explain;
99  else
100  { /* unknown; say so */
101  sprintf(convbuf, unk, errcode);
102  msg = convbuf;
103  }
104  break;
105  }
106 
107  len = strlen(msg) + 1; /* space needed, including NUL */
108  if (errbuf_size > 0)
109  {
110  if (errbuf_size > len)
111  strcpy(errbuf, msg);
112  else
113  { /* truncate to fit */
114  memcpy(errbuf, msg, errbuf_size - 1);
115  errbuf[errbuf_size - 1] = '\0';
116  }
117  }
118 
119  return len;
120 }
int code
Definition: regerror.c:42
static const struct rerr rerrs[]
static const char unk[]
Definition: regerror.c:37
int errcode(int sqlerrcode)
Definition: elog.c:694
#define sprintf
Definition: port.h:218
const char * name
Definition: regerror.c:43
#define REG_ATOI
Definition: regex.h:161
#define REG_ITOA
Definition: regex.h:162
const char * explain
Definition: regerror.c:44
Definition: regerror.c:40

◆ pg_regexec()

int pg_regexec ( regex_t ,
const pg_wchar ,
size_t  ,
size_t  ,
rm_detail_t ,
size_t  ,
regmatch_t  [],
int   
)

Definition at line 176 of file regexec.c.

References assert, cfind(), guts::cflags, cleanup(), guts::cmap, subre::cnfa, vars::details, vars::eflags, vars::err, find(), FREE, freedfa(), vars::g, i, guts::info, vars::ladfas, vars::lblastcp, vars::lblastcss, LOCALDFAS, LOCALMAT, MALLOC, guts::nlacons, vars::nmatch, guts::nsub, guts::ntree, pg_set_regex_collation(), vars::pmatch, vars::re, regex_t::re_collation, regex_t::re_csize, regex_t::re_guts, regex_t::re_magic, REG_ESPACE, REG_EXPECT, REG_FTRACE, REG_INVARG, REG_MIXED, REG_MTRACE, REG_NOMATCH, REG_NOSUB, REG_OKAY, REG_UBACKREF, REG_UIMPOSSIBLE, REMAGIC, vars::search_start, vars::start, generate_unaccent_rules::stdout, vars::stop, vars::subdfas, guts::tree, VS, and zapallsubs().

Referenced by check_ident_usermap(), CheckAffix(), RE_wchar_execute(), replace_text_regexp(), and test_re_execute().

184 {
185  struct vars var;
186  register struct vars *v = &var;
187  int st;
188  size_t n;
189  size_t i;
190  int backref;
191 
192 #define LOCALMAT 20
193  regmatch_t mat[LOCALMAT];
194 
195 #define LOCALDFAS 40
196  struct dfa *subdfas[LOCALDFAS];
197 
198  /* sanity checks */
199  if (re == NULL || string == NULL || re->re_magic != REMAGIC)
200  return REG_INVARG;
201  if (re->re_csize != sizeof(chr))
202  return REG_MIXED;
203 
204  /* Initialize locale-dependent support */
205  pg_set_regex_collation(re->re_collation);
206 
207  /* setup */
208  v->re = re;
209  v->g = (struct guts *) re->re_guts;
210  if ((v->g->cflags & REG_EXPECT) && details == NULL)
211  return REG_INVARG;
212  if (v->g->info & REG_UIMPOSSIBLE)
213  return REG_NOMATCH;
214  backref = (v->g->info & REG_UBACKREF) ? 1 : 0;
215  v->eflags = flags;
216  if (v->g->cflags & REG_NOSUB)
217  nmatch = 0; /* override client */
218  v->nmatch = nmatch;
219  if (backref)
220  {
221  /* need work area */
222  if (v->g->nsub + 1 <= LOCALMAT)
223  v->pmatch = mat;
224  else
225  v->pmatch = (regmatch_t *) MALLOC((v->g->nsub + 1) *
226  sizeof(regmatch_t));
227  if (v->pmatch == NULL)
228  return REG_ESPACE;
229  v->nmatch = v->g->nsub + 1;
230  }
231  else
232  v->pmatch = pmatch;
233  v->details = details;
234  v->start = (chr *) string;
235  v->search_start = (chr *) string + search_start;
236  v->stop = (chr *) string + len;
237  v->err = 0;
238  v->subdfas = NULL;
239  v->ladfas = NULL;
240  v->lblastcss = NULL;
241  v->lblastcp = NULL;
242  /* below this point, "goto cleanup" will behave sanely */
243 
244  assert(v->g->ntree >= 0);
245  n = (size_t) v->g->ntree;
246  if (n <= LOCALDFAS)
247  v->subdfas = subdfas;
248  else
249  {
250  v->subdfas = (struct dfa **) MALLOC(n * sizeof(struct dfa *));
251  if (v->subdfas == NULL)
252  {
253  st = REG_ESPACE;
254  goto cleanup;
255  }
256  }
257  for (i = 0; i < n; i++)
258  v->subdfas[i] = NULL;
259 
260  assert(v->g->nlacons >= 0);
261  n = (size_t) v->g->nlacons;
262  if (n > 0)
263  {
264  v->ladfas = (struct dfa **) MALLOC(n * sizeof(struct dfa *));
265  if (v->ladfas == NULL)
266  {
267  st = REG_ESPACE;
268  goto cleanup;
269  }
270  for (i = 0; i < n; i++)
271  v->ladfas[i] = NULL;
272  v->lblastcss = (struct sset **) MALLOC(n * sizeof(struct sset *));
273  v->lblastcp = (chr **) MALLOC(n * sizeof(chr *));
274  if (v->lblastcss == NULL || v->lblastcp == NULL)
275  {
276  st = REG_ESPACE;
277  goto cleanup;
278  }
279  for (i = 0; i < n; i++)
280  {
281  v->lblastcss[i] = NULL;
282  v->lblastcp[i] = NULL;
283  }
284  }
285 
286  /* do it */
287  assert(v->g->tree != NULL);
288  if (backref)
289  st = cfind(v, &v->g->tree->cnfa, &v->g->cmap);
290  else
291  st = find(v, &v->g->tree->cnfa, &v->g->cmap);
292 
293  /* copy (portion of) match vector over if necessary */
294  if (st == REG_OKAY && v->pmatch != pmatch && nmatch > 0)
295  {
296  zapallsubs(pmatch, nmatch);
297  n = (nmatch < v->nmatch) ? nmatch : v->nmatch;
298  memcpy(VS(pmatch), VS(v->pmatch), n * sizeof(regmatch_t));
299  }
300 
301  /* clean up */
302 cleanup:
303  if (v->pmatch != pmatch && v->pmatch != mat)
304  FREE(v->pmatch);
305  if (v->subdfas != NULL)
306  {
307  n = (size_t) v->g->ntree;
308  for (i = 0; i < n; i++)
309  {
310  if (v->subdfas[i] != NULL)
311  freedfa(v->subdfas[i]);
312  }
313  if (v->subdfas != subdfas)
314  FREE(v->subdfas);
315  }
316  if (v->ladfas != NULL)
317  {
318  n = (size_t) v->g->nlacons;
319  for (i = 0; i < n; i++)
320  {
321  if (v->ladfas[i] != NULL)
322  freedfa(v->ladfas[i]);
323  }
324  FREE(v->ladfas);
325  }
326  if (v->lblastcss != NULL)
327  FREE(v->lblastcss);
328  if (v->lblastcp != NULL)
329  FREE(v->lblastcp);
330 
331 #ifdef REG_DEBUG
332  if (v->eflags & (REG_FTRACE | REG_MTRACE))
333  fflush(stdout);
334 #endif
335 
336  return st;
337 }
#define REG_UIMPOSSIBLE
Definition: regex.h:74
struct dfa ** ladfas
Definition: regexec.c:119
static int find(struct vars *, struct cnfa *, struct colormap *)
Definition: regexec.c:395
#define REG_EXPECT
Definition: regex.h:115
struct subre * tree
Definition: regguts.h:533
#define REG_ESPACE
Definition: regex.h:151
int nlacons
Definition: regguts.h:539
#define REMAGIC
Definition: regguts.h:96
#define REG_FTRACE
Definition: regex.h:129
#define FREE(ptr)
Definition: cryptohash.c:37
rm_detail_t * details
Definition: regexec.c:113
#define REG_MTRACE
Definition: regex.h:130
chr * start
Definition: regexec.c:114
#define MALLOC(n)
Definition: regcustom.h:60
Definition: regexec.c:63
struct sset ** lblastcss
Definition: regexec.c:120
chr * search_start
Definition: regexec.c:115
pg_wchar chr
Definition: regcustom.h:66
#define REG_OKAY
Definition: regex.h:139
regex_t * re
Definition: regcomp.c:240
#define REG_INVARG
Definition: regex.h:154
struct colormap cmap
Definition: regguts.h:536
#define assert(TEST)
Definition: imath.c:73
struct guts * g
Definition: regexec.c:109
int err
Definition: regcomp.c:243
#define LOCALMAT
int eflags
Definition: regexec.c:110
static void cleanup(void)
Definition: bootstrap.c:862
Definition: regguts.h:526
int ntree
Definition: regguts.h:535
#define REG_UBACKREF
Definition: regex.h:60
#define LOCALDFAS
struct dfa ** subdfas
Definition: regexec.c:118
void pg_set_regex_collation(Oid collation)
regmatch_t * pmatch
Definition: regexec.c:112
#define REG_NOSUB
Definition: regex.h:109
static void freedfa(struct dfa *)
#define VS(x)
Definition: regguts.h:61
long info
Definition: regguts.h:531
struct cnfa cnfa
Definition: regguts.h:499
size_t nmatch
Definition: regexec.c:111
static void zapallsubs(regmatch_t *, size_t)
Definition: regexec.c:639
const chr * stop
Definition: regcomp.c:242
int cflags
Definition: regguts.h:530
Definition: regexec.c:45
size_t nsub
Definition: regguts.h:532
int i
#define REG_NOMATCH
Definition: regex.h:140
chr ** lblastcp
Definition: regexec.c:121
#define REG_MIXED
Definition: regex.h:155
Definition: regcomp.c:238
static int cfind(struct vars *, struct cnfa *, struct colormap *)
Definition: regexec.c:486

◆ pg_regfree()

void pg_regfree ( regex_t )

Definition at line 49 of file regfree.c.

References regex_t::re_fns.

Referenced by createTrgmNFA(), load_ident(), RE_compile_and_cache(), and test_regex().

50 {
51  if (re == NULL)
52  return;
53  (*((struct fns *) re->re_fns)->free) (re);
54 }
Definition: regguts.h:509

◆ pg_regprefix()

int pg_regprefix ( regex_t ,
pg_wchar **  ,
size_t *   
)

Definition at line 46 of file regprefix.c.

References assert, guts::cmap, subre::cnfa, findprefix(), cnfa::flags, FREE, guts::info, MALLOC, MATCHALL, cnfa::nstates, pg_set_regex_collation(), regex_t::re_collation, regex_t::re_csize, regex_t::re_guts, regex_t::re_magic, REG_ESPACE, REG_EXACT, REG_INVARG, REG_MIXED, REG_NOMATCH, REG_PREFIX, REG_UIMPOSSIBLE, REMAGIC, and guts::tree.

Referenced by regexp_fixed_prefix().

49 {
50  struct guts *g;
51  struct cnfa *cnfa;
52  int st;
53 
54  /* sanity checks */
55  if (string == NULL || slength == NULL)
56  return REG_INVARG;
57  *string = NULL; /* initialize for failure cases */
58  *slength = 0;
59  if (re == NULL || re->re_magic != REMAGIC)
60  return REG_INVARG;
61  if (re->re_csize != sizeof(chr))
62  return REG_MIXED;
63 
64  /* Initialize locale-dependent support */
65  pg_set_regex_collation(re->re_collation);
66 
67  /* setup */
68  g = (struct guts *) re->re_guts;
69  if (g->info & REG_UIMPOSSIBLE)
70  return REG_NOMATCH;
71 
72  /*
73  * This implementation considers only the search NFA for the topmost regex
74  * tree node. Therefore, constraints such as backrefs are not fully
75  * applied, which is allowed per the function's API spec.
76  */
77  assert(g->tree != NULL);
78  cnfa = &g->tree->cnfa;
79 
80  /* matchall NFAs never have a fixed prefix */
81  if (cnfa->flags & MATCHALL)
82  return REG_NOMATCH;
83 
84  /*
85  * Since a correct NFA should never contain any exit-free loops, it should
86  * not be possible for our traversal to return to a previously visited NFA
87  * state. Hence we need at most nstates chrs in the output string.
88  */
89  *string = (chr *) MALLOC(cnfa->nstates * sizeof(chr));
90  if (*string == NULL)
91  return REG_ESPACE;
92 
93  /* do it */
94  st = findprefix(cnfa, &g->cmap, *string, slength);
95 
96  assert(*slength <= cnfa->nstates);
97 
98  /* clean up */
99  if (st != REG_PREFIX && st != REG_EXACT)
100  {
101  FREE(*string);
102  *string = NULL;
103  *slength = 0;
104  }
105 
106  return st;
107 }
#define REG_UIMPOSSIBLE
Definition: regex.h:74
struct subre * tree
Definition: regguts.h:533
#define REG_ESPACE
Definition: regex.h:151
Definition: regguts.h:401
#define REMAGIC
Definition: regguts.h:96
#define FREE(ptr)
Definition: cryptohash.c:37
#define REG_PREFIX
Definition: regex.h:164
#define MALLOC(n)
Definition: regcustom.h:60
int nstates
Definition: regguts.h:403
pg_wchar chr
Definition: regcustom.h:66
#define REG_INVARG
Definition: regex.h:154
static int findprefix(struct cnfa *cnfa, struct colormap *cm, chr *string, size_t *slength)
Definition: regprefix.c:116
struct colormap cmap
Definition: regguts.h:536
#define assert(TEST)
Definition: imath.c:73
#define MATCHALL
Definition: regguts.h:407
Definition: regguts.h:526
void pg_set_regex_collation(Oid collation)
int flags
Definition: regguts.h:405
long info
Definition: regguts.h:531
struct cnfa cnfa
Definition: regguts.h:499
#define REG_EXACT
Definition: regex.h:165
#define REG_NOMATCH
Definition: regex.h:140
#define REG_MIXED
Definition: regex.h:155

◆ RE_compile_and_cache()

regex_t* RE_compile_and_cache ( text text_re,
int  cflags,
Oid  collation 
)

Definition at line 137 of file regexp.c.

References Assert, pg_re_flags::cflags, CHECK_FOR_INTERRUPTS, cached_re_str::cre_collation, cached_re_str::cre_flags, cached_re_str::cre_pat, cached_re_str::cre_pat_len, cached_re_str::cre_re, ereport, errcode(), errmsg(), ERROR, free, i, malloc, Max, MAX_CACHED_RES, num_res, palloc(), pfree(), pg_mb2wchar_with_len(), pg_regcomp(), pg_regerror(), pg_regfree(), REG_OKAY, VARDATA_ANY, and VARSIZE_ANY_EXHDR.

Referenced by RE_compile_and_execute(), regexp_fixed_prefix(), setup_regexp_matches(), textregexreplace(), textregexreplace_noopt(), and textregexsubstr().

138 {
139  int text_re_len = VARSIZE_ANY_EXHDR(text_re);
140  char *text_re_val = VARDATA_ANY(text_re);
141  pg_wchar *pattern;
142  int pattern_len;
143  int i;
144  int regcomp_result;
145  cached_re_str re_temp;
146  char errMsg[100];
147 
148  /*
149  * Look for a match among previously compiled REs. Since the data
150  * structure is self-organizing with most-used entries at the front, our
151  * search strategy can just be to scan from the front.
152  */
153  for (i = 0; i < num_res; i++)
154  {
155  if (re_array[i].cre_pat_len == text_re_len &&
156  re_array[i].cre_flags == cflags &&
157  re_array[i].cre_collation == collation &&
158  memcmp(re_array[i].cre_pat, text_re_val, text_re_len) == 0)
159  {
160  /*
161  * Found a match; move it to front if not there already.
162  */
163  if (i > 0)
164  {
165  re_temp = re_array[i];
166  memmove(&re_array[1], &re_array[0], i * sizeof(cached_re_str));
167  re_array[0] = re_temp;
168  }
169 
170  return &re_array[0].cre_re;
171  }
172  }
173 
174  /*
175  * Couldn't find it, so try to compile the new RE. To avoid leaking
176  * resources on failure, we build into the re_temp local.
177  */
178 
179  /* Convert pattern string to wide characters */
180  pattern = (pg_wchar *) palloc((text_re_len + 1) * sizeof(pg_wchar));
181  pattern_len = pg_mb2wchar_with_len(text_re_val,
182  pattern,
183  text_re_len);
184 
185  regcomp_result = pg_regcomp(&re_temp.cre_re,
186  pattern,
187  pattern_len,
188  cflags,
189  collation);
190 
191  pfree(pattern);
192 
193  if (regcomp_result != REG_OKAY)
194  {
195  /* re didn't compile (no need for pg_regfree, if so) */
196 
197  /*
198  * Here and in other places in this file, do CHECK_FOR_INTERRUPTS
199  * before reporting a regex error. This is so that if the regex
200  * library aborts and returns REG_CANCEL, we don't print an error
201  * message that implies the regex was invalid.
202  */
204 
205  pg_regerror(regcomp_result, &re_temp.cre_re, errMsg, sizeof(errMsg));
206  ereport(ERROR,
207  (errcode(ERRCODE_INVALID_REGULAR_EXPRESSION),
208  errmsg("invalid regular expression: %s", errMsg)));
209  }
210 
211  /*
212  * We use malloc/free for the cre_pat field because the storage has to
213  * persist across transactions, and because we want to get control back on
214  * out-of-memory. The Max() is because some malloc implementations return
215  * NULL for malloc(0).
216  */
217  re_temp.cre_pat = malloc(Max(text_re_len, 1));
218  if (re_temp.cre_pat == NULL)
219  {
220  pg_regfree(&re_temp.cre_re);
221  ereport(ERROR,
222  (errcode(ERRCODE_OUT_OF_MEMORY),
223  errmsg("out of memory")));
224  }
225  memcpy(re_temp.cre_pat, text_re_val, text_re_len);
226  re_temp.cre_pat_len = text_re_len;
227  re_temp.cre_flags = cflags;
228  re_temp.cre_collation = collation;
229 
230  /*
231  * Okay, we have a valid new item in re_temp; insert it into the storage
232  * array. Discard last entry if needed.
233  */
234  if (num_res >= MAX_CACHED_RES)
235  {
236  --num_res;
237  Assert(num_res < MAX_CACHED_RES);
238  pg_regfree(&re_array[num_res].cre_re);
239  free(re_array[num_res].cre_pat);
240  }
241 
242  if (num_res > 0)
243  memmove(&re_array[1], &re_array[0], num_res * sizeof(cached_re_str));
244 
245  re_array[0] = re_temp;
246  num_res++;
247 
248  return &re_array[0].cre_re;
249 }
static int num_res
Definition: regexp.c:109
#define VARDATA_ANY(PTR)
Definition: postgres.h:348
regex_t cre_re
Definition: regexp.c:106
int cre_flags
Definition: regexp.c:104
int errcode(int sqlerrcode)
Definition: elog.c:694
#define MAX_CACHED_RES
Definition: regexp.c:96
int pg_regcomp(regex_t *re, const chr *string, size_t len, int flags, Oid collation)
Definition: regcomp.c:329
char * cre_pat
Definition: regexp.c:102
#define malloc(a)
Definition: header.h:50
void pfree(void *pointer)
Definition: mcxt.c:1057
#define REG_OKAY
Definition: regex.h:139
static cached_re_str re_array[MAX_CACHED_RES]
Definition: regexp.c:110
#define ERROR
Definition: elog.h:45
size_t pg_regerror(int errcode, const regex_t *preg, char *errbuf, size_t errbuf_size)
Definition: regerror.c:60
unsigned int pg_wchar
Definition: mbprint.c:31
Oid cre_collation
Definition: regexp.c:105
int pg_mb2wchar_with_len(const char *from, pg_wchar *to, int len)
Definition: mbutils.c:870
#define ereport(elevel,...)
Definition: elog.h:155
#define free(a)
Definition: header.h:65
#define Max(x, y)
Definition: c.h:980
#define Assert(condition)
Definition: c.h:804
int cflags
Definition: regguts.h:530
#define VARSIZE_ANY_EXHDR(PTR)
Definition: postgres.h:341
void * palloc(Size size)
Definition: mcxt.c:950
int errmsg(const char *fmt,...)
Definition: elog.c:905
int i
#define CHECK_FOR_INTERRUPTS()
Definition: miscadmin.h:100
void pg_regfree(regex_t *re)
Definition: regfree.c:49
int cre_pat_len
Definition: regexp.c:103

◆ RE_compile_and_execute()

bool RE_compile_and_execute ( text text_re,
char *  dat,
int  dat_len,
int  cflags,
Oid  collation,
int  nmatch,
regmatch_t pmatch 
)

Definition at line 343 of file regexp.c.

References RE_compile_and_cache(), and RE_execute().

Referenced by executeLikeRegex(), nameicregexeq(), nameicregexne(), nameregexeq(), nameregexne(), texticregexeq(), texticregexne(), textregexeq(), and textregexne().

346 {
347  regex_t *re;
348 
349  /* Compile RE */
350  re = RE_compile_and_cache(text_re, cflags, collation);
351 
352  return RE_execute(re, dat, dat_len, nmatch, pmatch);
353 }
static bool RE_execute(regex_t *re, char *dat, int dat_len, int nmatch, regmatch_t *pmatch)
Definition: regexp.c:309
regex_t * RE_compile_and_cache(text *text_re, int cflags, Oid collation)
Definition: regexp.c:137
int cflags
Definition: regguts.h:530
Definition: regex.h:55