recompile regexp on cache miss after ys copy

This commit is contained in:
Olof hagsand 2019-05-30 00:03:37 +02:00
parent 2e23a8c275
commit 683d570008

View file

@ -811,6 +811,7 @@ ys_cv_validate_union_one(clicon_handle h,
int options = 0; int options = 0;
cvec *cvv = NULL; cvec *cvv = NULL;
cvec *regexps = NULL; cvec *regexps = NULL;
cvec *patterns = NULL;
uint8_t fraction = 0; uint8_t fraction = 0;
char *restype; char *restype;
enum cv_type cvtype; enum cv_type cvtype;
@ -820,9 +821,21 @@ ys_cv_validate_union_one(clicon_handle h,
clicon_err(OE_UNIX, errno, "cvec_new"); clicon_err(OE_UNIX, errno, "cvec_new");
goto done; goto done;
} }
if (yang_type_resolve(ys, ys, yt, &yrt, &options, &cvv, NULL, regexps, if ((patterns = cvec_new(0)) == NULL){
clicon_err(OE_UNIX, errno, "cvec_new");
goto done;
}
if (yang_type_resolve(ys, ys, yt, &yrt, &options, &cvv, patterns, regexps,
&fraction) < 0) &fraction) < 0)
goto done; goto done;
/* The regexp cache may be invalidated, in that case re-compile
* eg due to copying
*/
if (cvec_len(patterns)!=0 && cvec_len(regexps)==0){
if (compile_pattern2regexp(h, patterns, regexps) < 1)
goto done;
/* XXX reset cache? */
}
restype = yrt?yrt->ys_argument:NULL; restype = yrt?yrt->ys_argument:NULL;
if (restype && strcmp(restype, "union") == 0){ /* recursive union */ if (restype && strcmp(restype, "union") == 0){ /* recursive union */
if ((retval = ys_cv_validate_union(h, ys, reason, yrt, type, val)) < 0) if ((retval = ys_cv_validate_union(h, ys, reason, yrt, type, val)) < 0)
@ -847,6 +860,8 @@ ys_cv_validate_union_one(clicon_handle h,
goto done; goto done;
} }
done: done:
if (patterns)
cvec_free(patterns);
if (regexps) if (regexps)
cvec_free(regexps); cvec_free(regexps);
if (cvt) if (cvt)
@ -922,6 +937,7 @@ ys_cv_validate(clicon_handle h,
cg_var *ycv; /* cv of yang-statement */ cg_var *ycv; /* cv of yang-statement */
int options = 0; int options = 0;
cvec *cvv = NULL; cvec *cvv = NULL;
cvec *patterns = NULL;
cvec *regexps = NULL; cvec *regexps = NULL;
enum cv_type cvtype; enum cv_type cvtype;
char *type; /* orig type */ char *type; /* orig type */
@ -943,11 +959,24 @@ ys_cv_validate(clicon_handle h,
clicon_err(OE_UNIX, errno, "cvec_new"); clicon_err(OE_UNIX, errno, "cvec_new");
goto done; goto done;
} }
if ((patterns = cvec_new(0)) == NULL){
clicon_err(OE_UNIX, errno, "cvec_new");
goto done;
}
if (yang_type_get(ys, &type, &yrestype, if (yang_type_get(ys, &type, &yrestype,
&options, &cvv, &options, &cvv,
NULL, regexps, patterns, regexps,
&fraction) < 0) &fraction) < 0)
goto done; goto done;
/* The regexp cache may be invalidated, in that case re-compile
* eg due to copying
*/
if (cvec_len(patterns)!=0 && cvec_len(regexps)==0){
fprintf(stderr, "%s cache miss\n", __FUNCTION__);
if (compile_pattern2regexp(h, patterns, regexps) < 1)
goto done;
/* XXX reset cache? */
}
restype = yrestype?yrestype->ys_argument:NULL; restype = yrestype?yrestype->ys_argument:NULL;
if (clicon_type2cv(type, restype, ys, &cvtype) < 0) if (clicon_type2cv(type, restype, ys, &cvtype) < 0)
goto done; goto done;
@ -977,6 +1006,8 @@ ys_cv_validate(clicon_handle h,
done: done:
if (regexps) if (regexps)
cvec_free(regexps); cvec_free(regexps);
if (regexps)
cvec_free(patterns);
if (cvt) if (cvt)
cv_free(cvt); cv_free(cvt);
return retval; return retval;