From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 166B845AA2; Thu, 3 Oct 2024 18:47:11 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id A15C4402B1; Thu, 3 Oct 2024 18:47:10 +0200 (CEST) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by mails.dpdk.org (Postfix) with ESMTP id 5A84040289 for ; Thu, 3 Oct 2024 18:47:08 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1727974027; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=b7AugzRvzHcRWI6hGs+LteJlFKo59ELmOkRFGsgqdR0=; b=HnFCOinENZ4+LIyVThEzoFEdD/5pkaBdDD27MESdIoRrcSJxodxq66m2p6//PF4+LYMmyW KWLZoewsBW1YmxfkjeFMafGynwl7SRVLn/3OOsujGSK9EbWLkSRgJb8zKUFUaNIVmnCw/N 0O07auqRS6b+yiTxw+MEx6+ZsRCrOP0= Received: from mail-wm1-f71.google.com (mail-wm1-f71.google.com [209.85.128.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-649-wNeyLqeRN8apmCNpQHQyWw-1; Thu, 03 Oct 2024 12:47:06 -0400 X-MC-Unique: wNeyLqeRN8apmCNpQHQyWw-1 Received: by mail-wm1-f71.google.com with SMTP id 5b1f17b1804b1-42cb857fc7dso7736115e9.0 for ; Thu, 03 Oct 2024 09:47:06 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1727974025; x=1728578825; h=in-reply-to:references:user-agent:subject:to:from:cc:message-id :date:content-transfer-encoding:mime-version:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=b7AugzRvzHcRWI6hGs+LteJlFKo59ELmOkRFGsgqdR0=; b=DpEjbF8a8e3BOXcD/Z42NQ4izm1OJOiEjhv2pK9yUW8ifjQUABQHTSQR7EUkF95ZTq eZ0GxIidECnQotC2PzX+t0bCVsB947m7MM6mjongSPJtSk42+cnF8h1COU9PyK2tMBbA 72W8LTgekqSFLKxlf3cBUzlGSEXpgNBWzcqwYVXct14uUZT1gnr5RalJSOGQ1r4Nws2J Nd83H//AiuB17fSw4X1OftoSZALhhS8yUrHhpdbGRbEm6jJhOGZNjYEg5tU2beKqq9SW 5xLnBLIzKkxIe6qKSr61jNoxQ+A8GDnTesz/DVYF2fzSERJHhgf8N69NPHTf7wc50w4P ttnA== X-Forwarded-Encrypted: i=1; AJvYcCU2LRmq0wkK5+rFsV7gsYRO1RgQO1+p8v0YmNb5ETfr4ppqcRAXJDuGtZzQWUjJES7qXHo=@dpdk.org X-Gm-Message-State: AOJu0Yx8tpvPypNgBbbTZBnLFsRzyVV8EBtPGBqCld2guKde6oGSH5FR 7XLCzbbxHXMmvNfkKTRGFLfrzy4ruYabztxRS/5Q0dx+BFvVuEhH80rOkzxWFcWRQlb3wl3mqVA t/0HkxtREraB53YIG/SIz7PITHs+Bc7nnZIyxy/0t X-Received: by 2002:a5d:5043:0:b0:37c:c60d:f9b5 with SMTP id ffacd0b85a97d-37d0e6f647dmr28428f8f.2.1727974025436; Thu, 03 Oct 2024 09:47:05 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHr378piwavI5Qq2AU5ezWeu5uCRmv8uMOXNwSqjzv+JrlMF3u9oGvOZzYvAH5TjHYIoRVsug== X-Received: by 2002:a5d:5043:0:b0:37c:c60d:f9b5 with SMTP id ffacd0b85a97d-37d0e6f647dmr28420f8f.2.1727974025020; Thu, 03 Oct 2024 09:47:05 -0700 (PDT) Received: from localhost (2a01cb00025433006239e1f47a0b2371.ipv6.abo.wanadoo.fr. [2a01:cb00:254:3300:6239:e1f4:7a0b:2371]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-37d0822b878sm1642108f8f.44.2024.10.03.09.47.04 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 03 Oct 2024 09:47:04 -0700 (PDT) Mime-Version: 1.0 Date: Thu, 03 Oct 2024 18:47:04 +0200 Message-Id: Cc: , "Heng Wang" , "Stephen Hemminger" , "Tyler Retzlaff" , =?utf-8?q?Morten_Br=C3=B8rup?= , "Jack Bond-Preston" , "David Marchand" , "Chengwen Feng" From: "Robin Jarry" To: =?utf-8?q?Mattias_R=C3=B6nnblom?= , Subject: Re: [PATCH v12 1/7] buildtools/chkincs: relax C linkage requirement User-Agent: aerc/0.18.2-74-g7e4ac1a5f54c References: <20240920062437.738706-2-mattias.ronnblom@ericsson.com> <20240920104754.739033-1-mattias.ronnblom@ericsson.com> <20240920104754.739033-2-mattias.ronnblom@ericsson.com> In-Reply-To: <20240920104754.739033-2-mattias.ronnblom@ericsson.com> X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=UTF-8; format=Flowed X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Mattias R=C3=B6nnblom, 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=C3=B6nnblom > > -- > > 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/chkexte= rn.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 =3D "" > + header =3D header.replace("\\\n", " ") > + > + for line in header.split("\n"): > + if re.match(r'^\s*#.*', line) is None and len(line) > 0: > + no_cpp +=3D "%s\n" % line > + > + return no_cpp > + > + > +def strip_comments(header): > + no_c_comments =3D re.sub(r'/\*.*?\*/', '', header, flags=3Dre.DOTALL= ) > + no_cxx_comments =3D re.sub(r'//.*', '', no_c_comments) > + return no_cxx_comments > + > + > +def strip(header): > + header =3D strip_comments(header) > + header =3D strip_cpp(header) > + return header None of these three strip* functions are used. > + > + > +def has_extern_c(header): > + return header.find('extern "C"') !=3D -1 > + > + > +def has_vars(header): > + return re.search(r'^extern\s+[a-z0-9_]+\s.*;', header, flags=3Dre.MU= LTILINE) is not None > + > + > +FUNCTION_RES =3D [ > + 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 =3D open(filename).read() with open(filename) as f: header =3D f.read() > + if has_symbols(header) and not has_extern_c(header): > + print(filename) > + > + > +def chk_redundant(filename): > + header =3D open(filename).read() with open(filename) as f: header =3D 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?=20 I don't think the abbreviation is needed here. > + > +if len(sys.argv) < 3: > + print("%s missing|redundant ..." % sys.argv[0]) > + sys.exit(1) > + > +op =3D sys.argv[1] > +headers =3D sys.argv[2:] > + > +for header in headers: > + if op =3D=3D 'missing': > + chk_missing(header) > + elif op =3D=3D '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=20 a proper main() function and use argparse to handle errors. E.g.: def main(): parser =3D argparse.ArgumentParser(description=3D__doc__) parser.add_argument("op", choices=3D("missing", "redundant")) parser.add_argument("headers", nargs=3D"+") args =3D parser.parse_args() for h in args.headers: if op =3D=3D "missing": chk_missing(h) elif op =3D=3D "redundant": chk_redundant(h) if __name__ =3D=3D "__main__": main() > diff --git a/buildtools/chkincs/meson.build b/buildtools/chkincs/meson.bu= ild > 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 > =20 > # check for extern C in files, since this is not detected as an error by= the compiler > -grep =3D find_program('grep', required: false) > -if grep.found() > - errlist =3D run_command([grep, '--files-without-match', '^extern "C"= ', dpdk_chkinc_headers], > - check: false, capture: true).stdout().split() > - if errlist !=3D [] > - error('Files missing C++ \'extern "C"\' guards:\n- ' + '\n- '.jo= in(errlist)) > - endif > +chkextern =3D find_program('chkextern.py') > + > +missing_extern_headers =3D run_command(chkextern, 'missing', dpdk_chkinc= _headers, > + capture: true, check: true).stdout().split() > + > +if missing_extern_headers !=3D [] > + error('Files missing C++ \'extern "C"\' guards:\n- ' + '\n- '.join(m= issing_extern_headers)) Instead of just relying on this script output, it would be better if it=20 exited with a non-zero status when something is wrong. That way you=20 would not have to capture stdout at all and you could leave meson do the=20 work. > endif > =20 > gen_cpp_files =3D generator(gen_c_file_for_header, > --=20 > 2.43.0