-
Notifications
You must be signed in to change notification settings - Fork 1.5k
refs #10610 / fixed #13994 - compile --rule-file
pattern only once / extracted regular expressions code to separate file
#6211
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
base: main
Are you sure you want to change the base?
Conversation
This is mainly so the issues are reported on start-up instead on each file. It does not improve performance much. The refactoring and improved testing will also make it easier to add support for PCRE2 since PCRE is EOL since quite a while (see https://trac.cppcheck.net/ticket/10610). |
cli/cmdlineparser.cpp
Outdated
} | ||
|
||
rule.regex = std::make_shared<Regex>(rule.pattern); | ||
const std::string regex_err = rule.regex->compile(); |
This comment was marked as outdated.
This comment was marked as outdated.
Sorry, something went wrong.
@@ -293,6 +299,7 @@ class CPPCHECKLIB WARN_UNUSED Settings { | |||
std::string id = "rule"; // default id | |||
std::string summary; | |||
Severity severity = Severity::style; // default severity | |||
std::shared_ptr<Regex> regex; |
This comment was marked as outdated.
This comment was marked as outdated.
Sorry, something went wrong.
lib/regex.h
Outdated
std::string mPattern; | ||
|
||
class Data; | ||
std::shared_ptr<Data> mData; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This needs to be a shared pointer because the it is used in Settings
are they are being copied (the copies in production code will hopefully go away soon) and we have dynamic memory.
This means that multiple threads will use this but as the used data is const
there should not be any issues. I did not see anything related to thread safety in the PCRE documentation. I will check again though. I hope any potential issues will be caught by the CI.
Thinking about that we a --rule
test which actually has multiple input files. Wil add that.
So it seems the shared pointers do not seem to work with forked processes. But there is something else:
I wonder where the whitespace in the filename is coming from. |
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
--rule-file
pattern only once / extracted regular expressions code to separate file / improved errorhandling of --rule
and --rule-file=
--rule-file
pattern only once / extracted regular expressions code to separate file
1fb855b
to
b300dc5
Compare
e6c61a6
to
2b3ebf5
Compare
1b2c244
to
2ed6ba0
Compare
The problem is that the memory behind the shared pointer is leaked in the forked process:
|
CMake 4.0 removed support for projects targeting versions prior to 3.5.
0818aa8
to
31fbac0
Compare
I think we should just allow the leak for now so we can get this refactoring merged and can proceed with this. |
0937a56
to
085f2f5
Compare
1b28fd1
to
e8d3bc1
Compare
--rule-file
pattern only once / extracted regular expressions code to separate file--rule-file
pattern only once / extracted regular expressions code to separate file
…ns code to separate file
--rule-file
pattern only once / extracted regular expressions code to separate file--rule-file
pattern only once / extracted regular expressions code to separate file
I would really like to drop |
So let's deprecate the rule (build) options without a target in the next version and switch the code to use
We could re-write rules as addons internally and thus no longer need the actual code. But addons are magnitudes slower because of the process invocation and that would be even worse than using
It is only compiled once. It is the matching which is performed one the analysis. |
Also if it is deprecated, this PR should be safe to be merged for the current release. |
That is what this PR is about isn't it? Otherwise the PR title is misleading. How much time does PR save if I have 100 files? Some rough test is fine. |
No description provided.