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

Commits on Mar 16, 2024

  1. Suppress "Compile called before Add" in re2.Filter

    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 committed Mar 16, 2024
    Configuration menu
    Copy the full SHA
    f6c786e View commit details
    Browse the repository at this point in the history