Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Suppress "Compile called before Add" in re2.Filter #200

Merged
merged 1 commit into from
Mar 16, 2024

Conversation

masklinn
Copy link
Contributor

@masklinn masklinn commented Mar 16, 2024

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 skip Filter.Compile to suppress the warning message, we need to skip Filter.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

  1. 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

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 skip `Filter.Compile` to
suppress the warning message, we need to skip `Filter.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
conditions[^thread] 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?)

[^thread]: 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
@masklinn masklinn merged commit 4282003 into ua-parser:master Mar 16, 2024
29 checks passed
@masklinn masklinn deleted the re2-empty-set branch March 16, 2024 19:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant