Message ID | 20240531121838.27643-3-laurent.pinchart@ideasonboard.com |
---|---|
State | Accepted |
Headers | show |
Series |
|
Related | show |
On Fri, May 31, 2024 at 03:18:36PM +0300, Laurent Pinchart wrote: > math.h is an exception to the C compatibility header rule, as we prefer > using cmath. Extend the IncludeCheck to warn about it. > > Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Reviewed-by: Paul Elder <paul.elder@ideasonboard.com> > --- > utils/checkstyle.py | 12 +++++++++--- > 1 file changed, 9 insertions(+), 3 deletions(-) > > diff --git a/utils/checkstyle.py b/utils/checkstyle.py > index 518be0897db5..f3604299de94 100755 > --- a/utils/checkstyle.py > +++ b/utils/checkstyle.py > @@ -568,7 +568,7 @@ class IncludeChecker(StyleChecker): > headers = ('cassert', 'cctype', 'cerrno', 'cfenv', 'cfloat', 'cinttypes', > 'climits', 'clocale', 'csetjmp', 'csignal', 'cstdarg', 'cstddef', > 'cstdint', 'cstdio', 'cstdlib', 'cstring', 'ctime', 'cuchar', > - 'cwchar', 'cwctype') > + 'cwchar', 'cwctype', 'math.h') > include_regex = re.compile(r'^#include <([a-z.]*)>') > > def __init__(self, content): > @@ -588,9 +588,15 @@ class IncludeChecker(StyleChecker): > if header not in IncludeChecker.headers: > continue > > - header = header[1:] + '.h' > + if header.endswith('.h'): > + header_type = 'C++' > + header = 'c' + header[:-2] > + else: > + header_type = 'C compatibility' > + header = header[1:] + '.h' > + > issues.append(StyleIssue(line_number, line, > - 'C compatibility header <%s> is preferred' % header)) > + f'{header_type} header <{header}> is preferred')) > > return issues
Quoting Laurent Pinchart (2024-05-31 13:18:36) > math.h is an exception to the C compatibility header rule, as we prefer > using cmath. Extend the IncludeCheck to warn about it. > Have we documented /why/ we prefer that anywhere? > Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com> > --- > utils/checkstyle.py | 12 +++++++++--- > 1 file changed, 9 insertions(+), 3 deletions(-) > > diff --git a/utils/checkstyle.py b/utils/checkstyle.py > index 518be0897db5..f3604299de94 100755 > --- a/utils/checkstyle.py > +++ b/utils/checkstyle.py > @@ -568,7 +568,7 @@ class IncludeChecker(StyleChecker): > headers = ('cassert', 'cctype', 'cerrno', 'cfenv', 'cfloat', 'cinttypes', > 'climits', 'clocale', 'csetjmp', 'csignal', 'cstdarg', 'cstddef', > 'cstdint', 'cstdio', 'cstdlib', 'cstring', 'ctime', 'cuchar', > - 'cwchar', 'cwctype') > + 'cwchar', 'cwctype', 'math.h') > include_regex = re.compile(r'^#include <([a-z.]*)>') > > def __init__(self, content): > @@ -588,9 +588,15 @@ class IncludeChecker(StyleChecker): > if header not in IncludeChecker.headers: > continue > > - header = header[1:] + '.h' > + if header.endswith('.h'): > + header_type = 'C++' > + header = 'c' + header[:-2] > + else: > + header_type = 'C compatibility' > + header = header[1:] + '.h' > + > issues.append(StyleIssue(line_number, line, > - 'C compatibility header <%s> is preferred' % header)) > + f'{header_type} header <{header}> is preferred')) > > return issues > > -- > Regards, > > Laurent Pinchart >
Kieran Bingham <kieran.bingham@ideasonboard.com> writes: > Quoting Laurent Pinchart (2024-05-31 13:18:36) >> math.h is an exception to the C compatibility header rule, as we prefer >> using cmath. Extend the IncludeCheck to warn about it. >> > > Have we documented /why/ we prefer that anywhere? Yes, in Documentation/coding-style.rst. >> Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> > > > Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com> Tested-by: Milan Zamazal <mzamazal@redhat.com> >> --- >> utils/checkstyle.py | 12 +++++++++--- >> 1 file changed, 9 insertions(+), 3 deletions(-) >> >> diff --git a/utils/checkstyle.py b/utils/checkstyle.py >> index 518be0897db5..f3604299de94 100755 >> --- a/utils/checkstyle.py >> +++ b/utils/checkstyle.py >> @@ -568,7 +568,7 @@ class IncludeChecker(StyleChecker): >> headers = ('cassert', 'cctype', 'cerrno', 'cfenv', 'cfloat', 'cinttypes', >> 'climits', 'clocale', 'csetjmp', 'csignal', 'cstdarg', 'cstddef', >> 'cstdint', 'cstdio', 'cstdlib', 'cstring', 'ctime', 'cuchar', >> - 'cwchar', 'cwctype') >> + 'cwchar', 'cwctype', 'math.h') >> include_regex = re.compile(r'^#include <([a-z.]*)>') >> >> def __init__(self, content): >> @@ -588,9 +588,15 @@ class IncludeChecker(StyleChecker): >> if header not in IncludeChecker.headers: >> continue >> >> - header = header[1:] + '.h' >> + if header.endswith('.h'): >> + header_type = 'C++' >> + header = 'c' + header[:-2] >> + else: >> + header_type = 'C compatibility' >> + header = header[1:] + '.h' >> + >> issues.append(StyleIssue(line_number, line, >> - 'C compatibility header <%s> is preferred' % header)) >> + f'{header_type} header <{header}> is preferred')) >> >> return issues >> >> -- >> Regards, >> >> Laurent Pinchart >>
diff --git a/utils/checkstyle.py b/utils/checkstyle.py index 518be0897db5..f3604299de94 100755 --- a/utils/checkstyle.py +++ b/utils/checkstyle.py @@ -568,7 +568,7 @@ class IncludeChecker(StyleChecker): headers = ('cassert', 'cctype', 'cerrno', 'cfenv', 'cfloat', 'cinttypes', 'climits', 'clocale', 'csetjmp', 'csignal', 'cstdarg', 'cstddef', 'cstdint', 'cstdio', 'cstdlib', 'cstring', 'ctime', 'cuchar', - 'cwchar', 'cwctype') + 'cwchar', 'cwctype', 'math.h') include_regex = re.compile(r'^#include <([a-z.]*)>') def __init__(self, content): @@ -588,9 +588,15 @@ class IncludeChecker(StyleChecker): if header not in IncludeChecker.headers: continue - header = header[1:] + '.h' + if header.endswith('.h'): + header_type = 'C++' + header = 'c' + header[:-2] + else: + header_type = 'C compatibility' + header = header[1:] + '.h' + issues.append(StyleIssue(line_number, line, - 'C compatibility header <%s> is preferred' % header)) + f'{header_type} header <{header}> is preferred')) return issues
math.h is an exception to the C compatibility header rule, as we prefer using cmath. Extend the IncludeCheck to warn about it. Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> --- utils/checkstyle.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-)