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

compile --rule-file pattern only once / extracted regular expressions code to separate file #6211

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

firewave
Copy link
Collaborator

No description provided.

@firewave
Copy link
Collaborator Author

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

}

rule.regex = std::make_shared<Regex>(rule.pattern);
const std::string regex_err = rule.regex->compile();
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not too happy about this pattern but I could not come up with some without changing the code quite a bit which I wanted to avoid.

lib/settings.h Outdated
@@ -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;
Copy link
Collaborator Author

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 Settings are being copied (the copies in production code will hopefully go away soon) and we have dynamic memory.

std::string mPattern;

class Data;
std::shared_ptr<Data> mData;
Copy link
Collaborator Author

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.

@firewave
Copy link
Collaborator Author

So it seems the shared pointers do not seem to work with forked processes.

But there is something else:

[processfs_1.cpp :0]: (error) Internal error: Child process exited with 1

I wonder where the whitespace in the filename is coming from.

@firewave
Copy link
Collaborator Author

I will split the changes which are are not related to the compilation into a separate PR.

@firewave
Copy link
Collaborator Author

I will split the changes which are are not related to the compilation into a separate PR.

See #6212.

@firewave firewave changed the title compile --rule-file pattern only once / extracted regular expressions code to separate file / improved errorhandling of --rule and --rule-file= compile --rule-file pattern only once / extracted regular expressions code to separate file Apr 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
1 participant