37
38
#define VRE_MAGIC 0xe83097dc
41
vre_t *VRE_compile(const char *pattern, int options,
42
const char **errptr, int *erroffset) {
43
#ifndef PCRE_STUDY_JIT_COMPILE
44
#define PCRE_STUDY_JIT_COMPILE 0
48
* We don't want to spread or even expose the majority of PCRE options
49
* so we establish our own options and implement hard linkage to PCRE
52
const unsigned VRE_CASELESS = PCRE_CASELESS;
53
const unsigned VRE_NOTEMPTY = PCRE_NOTEMPTY;
56
VRE_compile(const char *pattern, int options,
57
const char **errptr, int *erroffset)
44
60
*errptr = NULL; *erroffset = 0;
46
62
ALLOC_OBJ(v, VRE_MAGIC);
48
65
v->re = pcre_compile(pattern, options, errptr, erroffset, NULL);
49
66
if (v->re == NULL) {
70
v->re_extra = pcre_study(v->re, PCRE_STUDY_JIT_COMPILE, errptr);
71
if (v->re_extra == NULL) {
72
if (*errptr != NULL) {
76
/* allocate our own, pcre_study can return NULL without it
78
v->re_extra = calloc(1, sizeof(pcre_extra));
79
if (v->re_extra == NULL) {
56
int VRE_exec(const vre_t *code, const char *subject, int length,
57
int startoffset, int options, int *ovector, int ovecsize) {
88
VRE_exec(const vre_t *code, const char *subject, int length,
89
int startoffset, int options, int *ovector, int ovecsize,
90
const volatile struct vre_limits *lim)
58
92
CHECK_OBJ_NOTNULL(code, VRE_MAGIC);
60
95
if (ovector == NULL) {
62
97
ovecsize = sizeof(ov)/sizeof(ov[0]);
65
return pcre_exec(code->re, NULL, subject, length,
66
startoffset, options, ovector, ovecsize);
101
code->re_extra->match_limit = lim->match;
102
code->re_extra->flags |= PCRE_EXTRA_MATCH_LIMIT;
103
code->re_extra->match_limit_recursion = lim->match_recursion;
104
code->re_extra->flags |= PCRE_EXTRA_MATCH_LIMIT_RECURSION;
106
code->re_extra->flags &= ~PCRE_EXTRA_MATCH_LIMIT;
107
code->re_extra->flags &= ~PCRE_EXTRA_MATCH_LIMIT_RECURSION;
110
return (pcre_exec(code->re, code->re_extra, subject, length,
111
startoffset, options, ovector, ovecsize));
69
void VRE_free(vre_t **vv) {
74
120
CHECK_OBJ(v, VRE_MAGIC);
121
#ifdef PCRE_CONFIG_JIT
122
pcre_free_study(v->re_extra);