Skip to content

Conversation

@moonchen
Copy link
Contributor

This is part of the effort to remove pcre dependency.

This is part of the effort to remove pcre dependency.
@moonchen moonchen changed the title Do Not Merge - prefetch pcre test prefetch: use Regex instead of pcre Oct 17, 2025
@moonchen moonchen self-assigned this Oct 20, 2025
@moonchen moonchen added the pcre label Oct 20, 2025
@bryancall bryancall self-requested a review October 20, 2025 21:57
@bryancall bryancall added this to the 10.2.0 milestone Oct 20, 2025
@moonchen moonchen added the prefetch prefetch plugin label Oct 20, 2025
Copy link
Contributor

@bryancall bryancall left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The migration looks good overall, but there's a functional regression: the original code used PCRE_NOTEMPTY flag in all three pcre_exec() calls, but the new code doesn't pass RE_NOTEMPTY to Regex::exec().

Issue: PCRE_NOTEMPTY prevents matching empty strings, which is important for patterns like .* that could otherwise match at the beginning of an empty string.

Required changes:

  1. Line 185 in match():
return _regex.exec(subject, RE_NOTEMPTY);
  1. Line 203 in capture():
int matchCount = _regex.exec(subject, matches, RE_NOTEMPTY);
  1. Line 234 in replace():
int matchCount = _regex.exec(subject, matches, RE_NOTEMPTY);

This maintains the original PCRE behavior and prevents subtle matching bugs.

- add missing flag to exec()
@moonchen
Copy link
Contributor Author

Added the flag back to exec().

@moonchen moonchen requested review from bneradt and bryancall October 21, 2025 19:06
bryancall
bryancall previously approved these changes Oct 21, 2025
@moonchen
Copy link
Contributor Author

[approve ci autest]

Copy link
Contributor

@bneradt bneradt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good. Just an observation on logging.

Comment on lines 210 to 222
if (!_re) {
return false;
}

matchCount = pcre_exec(_re, _extra, subject.c_str(), subject.length(), 0, PCRE_NOTEMPTY, nullptr, 0);
if (matchCount < 0) {
if (matchCount != PCRE_ERROR_NOMATCH) {
PrefetchError("matching error %d", matchCount);
}
if (_regex.empty()) {
return false;
}

return true;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's a few of these PrefetchError's that are lost in the shuffle. I think we should be able to preserve these using a different Regex interface.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pcre prefetch prefetch plugin

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants