Suppress "Compile called before Add" in re2.Filter #200
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
When compiling an empty set,
FilteredRE2::Compile
logs a warning to stderr which can not be suppressed (google/re2#485).Replace
re2.Filter
by a null object if the corresponding matchers list is empty: not only do we need to skipFilter.Compile
to suppress the warning message, we need to skipFilter.Match
or the program will segfault (google/re2#484). Using a null object seems safer and more reliable than adding conditionals, even if it requires more code and reindenting half the file.Doing this also seems safer than my first instinct of trying to use low-level fd redirection: fd redirection suffers from race
conditions1 and could suffer from other cross-platform compatibility issues (e.g. does every python-supported OS have stderr on fd 2 and correctly supports dup, dup2, and close?)
Footnotes
AFAIK CPython does not provide a python-level GIL-pin feature (even less so with the GILectomy plans), so we have no way to prevent context-switching and any message sent to stderr by sibling threads would be lost ↩