summaryrefslogtreecommitdiffstats
path: root/runtime
diff options
context:
space:
mode:
Diffstat (limited to 'runtime')
-rw-r--r--runtime/stringbuf.c61
-rw-r--r--runtime/stringbuf.h4
2 files changed, 39 insertions, 26 deletions
diff --git a/runtime/stringbuf.c b/runtime/stringbuf.c
index c0a19ae4..4a7cc4bd 100644
--- a/runtime/stringbuf.c
+++ b/runtime/stringbuf.c
@@ -725,33 +725,46 @@ finalize_it:
}
/* same as above, only not braindead */
-int rsCStrSzStrMatchRegexCache(cstr_t *pCS1, uchar *psz, void **rc)
+int rsCStrSzStrMatchRegexCache(cstr_t *pCS1, uchar *psz, void *rc)
{
- int ret;
-
- BEGINfunc
-
- if(objUse(regexp, LM_REGEXP_FILENAME) == RS_RET_OK) {
- regex_t **cache = rc;
- if (*cache == NULL) {
- *cache = calloc(sizeof(regex_t), 1);
- regexp.regcomp(*cache, (char*) rsCStrGetSzStr(pCS1), 0);
- }
- ret = regexp.regexec(*cache, (char*) psz, 0, NULL, 0);
- } else {
- ret = 1; /* simulate "not found" */
- }
-
- ENDfunc
- return ret;
+ int ret;
+ regex_t **cache = (regex_t**) rc;
+
+ BEGINfunc
+
+ assert(cache != NULL);
+
+ if(objUse(regexp, LM_REGEXP_FILENAME) == RS_RET_OK) {
+ if (*cache == NULL) {
+ *cache = calloc(sizeof(regex_t), 1);
+ regexp.regcomp(*cache, (char*) rsCStrGetSzStr(pCS1), 0);
+ }
+ ret = regexp.regexec(*cache, (char*) psz, 0, NULL, 0);
+ } else {
+ ret = 1; /* simulate "not found" */
+ }
+
+ ENDfunc
+ return ret;
}
-/* free a cached compiled regex */
-void rsRegexDestruct(void **rc) {
- regex_t **cache = rc;
- regexp.regfree(*cache);
- free(*cache);
- *cache = NULL;
+
+/* free a cached compiled regex
+ * Caller must provide a pointer to a buffer that was created by
+ * rsCStrSzStrMatchRegexCache()
+ */
+void rsCStrRegexDestruct(void *rc)
+{
+ regex_t **cache = rc;
+
+ assert(cache != NULL);
+ assert(*cache != NULL);
+
+ if(objUse(regexp, LM_REGEXP_FILENAME) == RS_RET_OK) {
+ regexp.regfree(*cache);
+ free(*cache);
+ *cache = NULL;
+ }
}
diff --git a/runtime/stringbuf.h b/runtime/stringbuf.h
index 4b0fb065..311d7f41 100644
--- a/runtime/stringbuf.h
+++ b/runtime/stringbuf.h
@@ -137,8 +137,8 @@ int rsCStrStartsWithSzStr(cstr_t *pCS1, uchar *psz, size_t iLenSz);
int rsCStrCaseInsensitveStartsWithSzStr(cstr_t *pCS1, uchar *psz, size_t iLenSz);
int rsCStrSzStrStartsWithCStr(cstr_t *pCS1, uchar *psz, size_t iLenSz);
rsRetVal rsCStrSzStrMatchRegex(cstr_t *pCS1, uchar *psz, int iType);
-int rsCStrSzStrMatchRegexCache(cstr_t *pCS1, uchar *psz, void **cache);
-void rsRegexDestruct(void **rc);
+int rsCStrSzStrMatchRegexCache(cstr_t *pCS1, uchar *psz, void *cache);
+void rsCStrRegexDestruct(void *rc);
rsRetVal rsCStrConvertToNumber(cstr_t *pStr, number_t *pNumber);
rsRetVal rsCStrConvertToBool(cstr_t *pStr, number_t *pBool);
rsRetVal rsCStrAppendCStr(cstr_t *pThis, cstr_t *pstrAppend);