From: "Robin Jarry" <rjarry@redhat.com>
To: "Mattias Rönnblom" <mattias.ronnblom@ericsson.com>, dev@dpdk.org
Cc: hofors@lysator.liu.se, "Heng Wang" <heng.wang@ericsson.com>,
"Stephen Hemminger" <stephen@networkplumber.org>,
"Tyler Retzlaff" <roretzla@linux.microsoft.com>,
"Morten Brørup" <mb@smartsharesystems.com>,
"Jack Bond-Preston" <jack.bond-preston@foss.arm.com>,
"David Marchand" <david.marchand@redhat.com>,
"Chengwen Feng" <fengchengwen@huawei.com>
Subject: Re: [PATCH v12 1/7] buildtools/chkincs: relax C linkage requirement
Date: Thu, 03 Oct 2024 18:47:04 +0200 [thread overview]
Message-ID: <D4MBO3TESLI4.GEJ8YKSLMRQ6@redhat.com> (raw)
In-Reply-To: <20240920104754.739033-2-mattias.ronnblom@ericsson.com>
Mattias Rönnblom, Sep 20, 2024 at 12:47:
> Relax chkincs requirement of all DPDK header files having to contain
> 'extern "C"'.
>
> Instructing a C++ toolchain to use C linkage is only necessarily if the
> header file declares symbols (i.e., functions or global variables).
>
> With this change, chkincs tries to find if any functions or references
> to global variables are declared in the header file, and if not, no C
> linkage is required.
>
> Signed-off-by: Mattias Rönnblom <mattias.ronnblom@ericsson.com>
>
> --
>
> PATCH v11:
> * Detect functions from the Windows POSIX wrappers, to avoid false
> positives for redundant 'extern "C"'.
> ---
Hi Mattias,
I have some remarks on this script. Please see below:
> buildtools/chkincs/chkextern.py | 88 +++++++++++++++++++++++++++++++++
> buildtools/chkincs/meson.build | 14 +++---
> 2 files changed, 95 insertions(+), 7 deletions(-)
> create mode 100755 buildtools/chkincs/chkextern.py
>
> diff --git a/buildtools/chkincs/chkextern.py b/buildtools/chkincs/chkextern.py
> new file mode 100755
> index 0000000000..5374ce1c72
> --- /dev/null
> +++ b/buildtools/chkincs/chkextern.py
> @@ -0,0 +1,88 @@
> +#! /usr/bin/env python3
> +# SPDX-License-Identifier: BSD-3-Clause
> +# Copyright(c) 2024 Ericsson AB
> +
> +import sys
> +import re
> +
> +def strip_cpp(header):
> + no_cpp = ""
> + header = header.replace("\\\n", " ")
> +
> + for line in header.split("\n"):
> + if re.match(r'^\s*#.*', line) is None and len(line) > 0:
> + no_cpp += "%s\n" % line
> +
> + return no_cpp
> +
> +
> +def strip_comments(header):
> + no_c_comments = re.sub(r'/\*.*?\*/', '', header, flags=re.DOTALL)
> + no_cxx_comments = re.sub(r'//.*', '', no_c_comments)
> + return no_cxx_comments
> +
> +
> +def strip(header):
> + header = strip_comments(header)
> + header = strip_cpp(header)
> + return header
None of these three strip* functions are used.
> +
> +
> +def has_extern_c(header):
> + return header.find('extern "C"') != -1
> +
> +
> +def has_vars(header):
> + return re.search(r'^extern\s+[a-z0-9_]+\s.*;', header, flags=re.MULTILINE) is not None
> +
> +
> +FUNCTION_RES = [
> + r'rte_[a-z0-9_]+\(',
> + r'cmdline_[a-z0-9_]+\(',
> + r'vt100_[a-z0-9_]+\(',
> + r'rdline_[a-z0-9_]+\(',
> + r'cirbuf_[a-z0-9_]+\(',
> + # Windows UNIX compatibility
> + r'pthread_[a-z0-9_]+\(',
> + r'regcomp\(',
> + r'count_cpu\('
> +]
> +
> +
> +def has_functions(header):
> + for function_re in FUNCTION_RES:
> + if re.search(function_re, header) is not None:
> + return True
> + return False
> +
> +
> +def has_symbols(header):
> + return has_functions(header) or has_vars(header)
> +
> +
> +def chk_missing(filename):
> + header = open(filename).read()
with open(filename) as f:
header = f.read()
> + if has_symbols(header) and not has_extern_c(header):
> + print(filename)
> +
> +
> +def chk_redundant(filename):
> + header = open(filename).read()
with open(filename) as f:
header = f.read()
> + if not has_symbols(header) and has_extern_c(header):
> + print(filename)
Can we rename these functions to check_missing and check_redundant?
I don't think the abbreviation is needed here.
> +
> +if len(sys.argv) < 3:
> + print("%s missing|redundant <header-file> ..." % sys.argv[0])
> + sys.exit(1)
> +
> +op = sys.argv[1]
> +headers = sys.argv[2:]
> +
> +for header in headers:
> + if op == 'missing':
> + chk_missing(header)
> + elif op == 'redundant':
> + chk_redundant(header)
I don't see the 'redundant' op being used here.
> + else:
> + print("Unknown operation.")
> + sys.exit(1)
I know it is a simple python script but it would be better to add
a proper main() function and use argparse to handle errors. E.g.:
def main():
parser = argparse.ArgumentParser(description=__doc__)
parser.add_argument("op", choices=("missing", "redundant"))
parser.add_argument("headers", nargs="+")
args = parser.parse_args()
for h in args.headers:
if op == "missing":
chk_missing(h)
elif op == "redundant":
chk_redundant(h)
if __name__ == "__main__":
main()
> diff --git a/buildtools/chkincs/meson.build b/buildtools/chkincs/meson.build
> index f2dadcae18..762f85efe5 100644
> --- a/buildtools/chkincs/meson.build
> +++ b/buildtools/chkincs/meson.build
> @@ -38,13 +38,13 @@ if not add_languages('cpp', required: false)
> endif
>
> # check for extern C in files, since this is not detected as an error by the compiler
> -grep = find_program('grep', required: false)
> -if grep.found()
> - errlist = run_command([grep, '--files-without-match', '^extern "C"', dpdk_chkinc_headers],
> - check: false, capture: true).stdout().split()
> - if errlist != []
> - error('Files missing C++ \'extern "C"\' guards:\n- ' + '\n- '.join(errlist))
> - endif
> +chkextern = find_program('chkextern.py')
> +
> +missing_extern_headers = run_command(chkextern, 'missing', dpdk_chkinc_headers,
> + capture: true, check: true).stdout().split()
> +
> +if missing_extern_headers != []
> + error('Files missing C++ \'extern "C"\' guards:\n- ' + '\n- '.join(missing_extern_headers))
Instead of just relying on this script output, it would be better if it
exited with a non-zero status when something is wrong. That way you
would not have to capture stdout at all and you could leave meson do the
work.
> endif
>
> gen_cpp_files = generator(gen_c_file_for_header,
> --
> 2.43.0
next prev parent reply other threads:[~2024-10-03 16:47 UTC|newest]
Thread overview: 85+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-01-31 13:13 [RFC v3] eal: add bitset type Mattias Rönnblom
2024-01-31 16:02 ` Stephen Hemminger
2024-01-31 16:28 ` Mattias Rönnblom
2024-01-31 16:06 ` Stephen Hemminger
2024-01-31 18:45 ` Mattias Rönnblom
2024-02-01 8:04 ` Morten Brørup
2024-02-02 10:19 ` Mattias Rönnblom
2024-02-02 12:42 ` Morten Brørup
2024-02-16 10:23 ` [RFC v4 1/4] " Mattias Rönnblom
2024-02-16 10:23 ` [RFC v4 2/4] eal: add bitset test suite Mattias Rönnblom
2024-02-16 10:23 ` [RFC v4 3/4] service: use multi-word bitset to represent service flags Mattias Rönnblom
2024-02-16 10:23 ` [RFC v4 4/4] event/dsw: optimize serving port logic Mattias Rönnblom
2024-05-05 7:33 ` [RFC v5 1/6] eal: add bitset type Mattias Rönnblom
2024-05-05 7:33 ` [RFC v5 2/6] eal: add bitset test suite Mattias Rönnblom
2024-05-05 7:33 ` [RFC v5 3/6] eal: add atomic bitset functions Mattias Rönnblom
2024-05-05 7:33 ` [RFC v5 4/6] eal: add unit tests for atomic bitset operations Mattias Rönnblom
2024-05-05 7:33 ` [RFC v5 5/6] service: use multi-word bitset to represent service flags Mattias Rönnblom
2024-05-05 7:33 ` [RFC v5 6/6] event/dsw: optimize serving port logic Mattias Rönnblom
2024-08-09 20:14 ` [PATCH 1/6] eal: add bitset type Mattias Rönnblom
2024-08-09 20:14 ` [PATCH 2/6] eal: add bitset test suite Mattias Rönnblom
2024-09-12 4:51 ` Tyler Retzlaff
2024-08-09 20:14 ` [PATCH 3/6] eal: add atomic bitset functions Mattias Rönnblom
2024-09-12 4:51 ` Tyler Retzlaff
2024-08-09 20:14 ` [PATCH 4/6] eal: add unit tests for atomic bitset operations Mattias Rönnblom
2024-09-12 4:52 ` Tyler Retzlaff
2024-08-09 20:14 ` [PATCH 5/6] service: use multi-word bitset to represent service flags Mattias Rönnblom
2024-09-12 4:52 ` Tyler Retzlaff
2024-08-09 20:14 ` [PATCH 6/6] event/dsw: add support for larger port count Mattias Rönnblom
2024-09-12 4:53 ` Tyler Retzlaff
2024-08-20 17:09 ` [PATCH 1/6] eal: add bitset type Mattias Rönnblom
2024-09-02 13:55 ` Morten Brørup
2024-09-02 14:46 ` Mattias Rönnblom
2024-09-02 14:49 ` Mattias Rönnblom
2024-09-12 4:51 ` Tyler Retzlaff
2024-09-17 9:36 ` [PATCH v7 0/6] Improve EAL bit operations API Mattias Rönnblom
2024-09-17 9:36 ` [PATCH v7 1/6] dpdk: do not force C linkage on include file dependencies Mattias Rönnblom
2024-09-17 10:48 ` [PATCH v8 0/6] Improve EAL bit operations API Mattias Rönnblom
2024-09-17 10:48 ` [PATCH v8 1/6] dpdk: do not force C linkage on include file dependencies Mattias Rönnblom
2024-09-18 9:04 ` [PATCH v9 0/6] Improve EAL bit operations API Mattias Rönnblom
2024-09-18 9:04 ` [PATCH v9 1/6] dpdk: do not force C linkage on include file dependencies Mattias Rönnblom
2024-09-19 19:31 ` [PATCH v10 0/7] Improve EAL bit operations API Mattias Rönnblom
2024-09-19 19:31 ` [PATCH v10 1/7] buildtools/chkincs: relax C linkage requirement Mattias Rönnblom
2024-09-20 6:24 ` [PATCH v11 0/7] Improve EAL bit operations API Mattias Rönnblom
2024-09-20 6:24 ` [PATCH v11 1/7] buildtools/chkincs: relax C linkage requirement Mattias Rönnblom
2024-09-20 10:47 ` [PATCH v12 0/7] Improve EAL bit operations API Mattias Rönnblom
2024-09-20 10:47 ` [PATCH v12 1/7] buildtools/chkincs: relax C linkage requirement Mattias Rönnblom
2024-10-03 16:47 ` Robin Jarry [this message]
2024-10-04 7:31 ` Mattias Rönnblom
2024-10-04 8:05 ` Robin Jarry
2024-10-04 8:40 ` Mattias Rönnblom
2024-10-04 11:51 ` Robin Jarry
2024-10-04 12:19 ` Thomas Monjalon
2024-09-20 10:47 ` [PATCH v12 2/7] dpdk: use C linkage only where appropriate Mattias Rönnblom
2024-09-20 10:47 ` [PATCH v12 3/7] eal: extend bit manipulation functionality Mattias Rönnblom
2024-09-20 10:47 ` [PATCH v12 4/7] eal: add unit tests for bit operations Mattias Rönnblom
2024-09-20 10:47 ` [PATCH v12 5/7] eal: add atomic " Mattias Rönnblom
2024-09-20 10:47 ` [PATCH v12 6/7] eal: add unit tests for atomic bit access functions Mattias Rönnblom
2024-09-20 10:47 ` [PATCH v12 7/7] eal: extend bitops to handle volatile pointers Mattias Rönnblom
2024-09-20 6:24 ` [PATCH v11 2/7] dpdk: use C linkage only where appropriate Mattias Rönnblom
2024-09-20 6:24 ` [PATCH v11 3/7] eal: extend bit manipulation functionality Mattias Rönnblom
2024-09-20 6:24 ` [PATCH v11 4/7] eal: add unit tests for bit operations Mattias Rönnblom
2024-09-20 6:24 ` [PATCH v11 5/7] eal: add atomic " Mattias Rönnblom
2024-09-20 6:24 ` [PATCH v11 6/7] eal: add unit tests for atomic bit access functions Mattias Rönnblom
2024-09-20 6:24 ` [PATCH v11 7/7] eal: extend bitops to handle volatile pointers Mattias Rönnblom
2024-09-19 19:31 ` [PATCH v10 2/7] dpdk: use C linkage only where appropriate Mattias Rönnblom
2024-09-19 19:31 ` [PATCH v10 3/7] eal: extend bit manipulation functionality Mattias Rönnblom
2024-09-19 19:31 ` [PATCH v10 4/7] eal: add unit tests for bit operations Mattias Rönnblom
2024-09-19 19:31 ` [PATCH v10 5/7] eal: add atomic " Mattias Rönnblom
2024-09-19 19:31 ` [PATCH v10 6/7] eal: add unit tests for atomic bit access functions Mattias Rönnblom
2024-09-19 19:31 ` [PATCH v10 7/7] eal: extend bitops to handle volatile pointers Mattias Rönnblom
2024-09-18 9:04 ` [PATCH v9 2/6] eal: extend bit manipulation functionality Mattias Rönnblom
2024-09-18 9:04 ` [PATCH v9 3/6] eal: add unit tests for bit operations Mattias Rönnblom
2024-09-18 9:04 ` [PATCH v9 4/6] eal: add atomic " Mattias Rönnblom
2024-09-18 9:04 ` [PATCH v9 5/6] eal: add unit tests for atomic bit access functions Mattias Rönnblom
2024-09-18 9:04 ` [PATCH v9 6/6] eal: extend bitops to handle volatile pointers Mattias Rönnblom
2024-09-17 10:48 ` [PATCH v8 2/6] eal: extend bit manipulation functionality Mattias Rönnblom
2024-09-17 10:48 ` [PATCH v8 3/6] eal: add unit tests for bit operations Mattias Rönnblom
2024-09-17 10:48 ` [PATCH v8 4/6] eal: add atomic " Mattias Rönnblom
2024-09-17 10:48 ` [PATCH v8 5/6] eal: add unit tests for atomic bit access functions Mattias Rönnblom
2024-09-17 10:48 ` [PATCH v8 6/6] eal: extend bitops to handle volatile pointers Mattias Rönnblom
2024-09-17 9:36 ` [PATCH v7 2/6] eal: extend bit manipulation functionality Mattias Rönnblom
2024-09-17 9:36 ` [PATCH v7 3/6] eal: add unit tests for bit operations Mattias Rönnblom
2024-09-17 9:36 ` [PATCH v7 4/6] eal: add atomic " Mattias Rönnblom
2024-09-17 9:36 ` [PATCH v7 5/6] eal: add unit tests for atomic bit access functions Mattias Rönnblom
2024-09-17 9:36 ` [PATCH v7 6/6] eal: extend bitops to handle volatile pointers Mattias Rönnblom
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=D4MBO3TESLI4.GEJ8YKSLMRQ6@redhat.com \
--to=rjarry@redhat.com \
--cc=david.marchand@redhat.com \
--cc=dev@dpdk.org \
--cc=fengchengwen@huawei.com \
--cc=heng.wang@ericsson.com \
--cc=hofors@lysator.liu.se \
--cc=jack.bond-preston@foss.arm.com \
--cc=mattias.ronnblom@ericsson.com \
--cc=mb@smartsharesystems.com \
--cc=roretzla@linux.microsoft.com \
--cc=stephen@networkplumber.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).