You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When using whitelists with alternation, it seems that the last alternative is not checked during matching, which can result in some items not getting matched.
# Pick one of the following whitelists:
WHITELIST='^_?em_|^_?emscripten_|^_?EM_|^_?EMSCRIPTEN_'
#WHITELIST='^_?em_|^_?EMSCRIPTEN_|^_?EM_|^_?emscripten_'
bindgen --whitelist-type="$WHITELIST" --whitelist-function="$WHITELIST" --whitelist-var="$WHITELIST" test.h
The problem is in RegexSet::build(). When the regular expressions are given to the inner regex::RegexSet, they are wrapped in anchors using format!("^{}$", item), which isn't completely sanitary.
In my case, my whitelist regex becomes ^^_?em_|^_?emscripten_|^_?EM_|^_?EMSCRIPTEN_$. Since alternation has the lowest precedence, the leading anchor only applies to the first alternative, and the trailing anchor only applies to the last alternative.
A quick fix without modifying the behavior for other uses would be to change the format string to "^({})$", since alternation stays within capture groups.
This makes me wonder why the regular expression is implicitly wrapped in the first place. It might not be a good practice, especially if it is not well-documented. It's possible that the original author of this whitelist regex thought it was a raw regular expression input since they added their own anchors.
When using whitelists with alternation, it seems that the last alternative is not checked during matching, which can result in some items not getting matched.
Input C/C++ Header
test.h:
Bindgen Invocation
Actual Results
With the first whitelist:
With the second whitelist:
Expected Results
All of the definitions from the given header should match under both whitelists, resulting in the following bindings under either whitelist:
Appending a non-matching alternative to the whitelist produces the expected output:
The text was updated successfully, but these errors were encountered: