Closed Conspio closed 5 months ago
Please give more detail (to save me having to understand your program). When I try that pattern with the same string as the match subject, using pcre2test with or without JIT, it just matches the whole subject.
zyp@LAPTOP-TUSLHN7A:/mnt/c/Users/zying/Downloads$ g++ pcre2nojit.cpp -o pcre2nojit -lpcre2-8 zyp@LAPTOP-TUSLHN7A:/mnt/c/Users/zying/Downloads$ ./pcre2nojit start_offset: 3 count: 1 zyp@LAPTOP-TUSLHN7A:/mnt/c/Users/zying/Downloads$ g++ pcre2jit.cpp -o pcre2jit -lpcre2-8 zyp@LAPTOP-TUSLHN7A:/mnt/c/Users/zying/Downloads$ ./pcre2jit start_offset: 3 start_offset: 21 count: 2 zyp@LAPTOP-TUSLHN7A:/mnt/c/Users/zying/Downloads$
They are tested on WSL2-Ubuntu22.
The results are different for with-jit and without-jit versions. The two cpp files are similar except for the jit part.
I am not a C++ programmer. Nevertheless, I have spent some time and figured out what is going on. It is not a bug. In the non-JIT case, after the first match, the second attempt gives a "match limit exceeded" error - that is, a negative value for rc, and hence the loop stops. You do not test for errors, and hence it looks as if it has found just one match. JIT's use of the match limit counts somewhat differently, and it can apparently find the second match without hitting the limit.
Thank you for your further investigation. I checked and confirmed that if we call pcre2_set_match_limit(match_context, 4294967295)
to set a bigger limit, the non-jit case has the same matching results as the jit case.
To test the program, I used a regular expression to match itself. When the compiled regex is
The number of matches in PCRE2 with jit enabled is 2. Match from 0 ~ 3 and 4 ~ 21. here is the repo: https://github.com/Conspio/poc-repo/blob/main/pcre2jit.cpp
However, the number of matches in PCRE2 without jit enabled is 1. Only match from 0 ~ 3. here is the repo: https://github.com/Conspio/poc-repo/blob/main/pcre2nojit.cpp