From nobody Mon Sep 16 19:21:36 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass(p=reject dis=none) header.from=citrix.com ARC-Seal: i=1; a=rsa-sha256; t=1720047356; cv=none; d=zohomail.com; s=zohoarc; b=JgO1ImTjdUwOCrKEDWZwpsLhxAm7T5unOz+YyywbKQl+yLTbCr6XUF+9zDS623/pw0/ML9211DctANb06tC1JD5ZSJuRYQyw6IaWQqFeS3p9u8pYa+l2Vq59sv1uqXtKseJaGbvJWb79BA2yVVILPnwFwLoZqogViIlu3JWb/7E= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1720047356; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=nc6jPiNiL6yKZZqXuTh5pDooCk6e0PT5O2QbWpQhSHI=; b=BVixRJib2APWovhfY4yJXO6fO2z7XCJF4ZNI3RSoBwIejlMCQJjFF2GWxI9s35FO8DG5o2SbeBpWnd2I+fOVU5Jr22KIM0gTfRQkjp2BqClHAagUFR/2lPFsAQLGRf9RT+stlIX/jvfzmIXvsFbVwKoegnFaJ7bFnkiI9xSo8iQ= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass header.from= (p=reject dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1720047356184228.59050962594108; Wed, 3 Jul 2024 15:55:56 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.753355.1161601 (Exim 4.92) (envelope-from ) id 1sP8sz-0004a4-5C; Wed, 03 Jul 2024 22:55:37 +0000 Received: by outflank-mailman (output) from mailman id 753355.1161601; Wed, 03 Jul 2024 22:55:37 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1sP8sz-0004Zv-11; Wed, 03 Jul 2024 22:55:37 +0000 Received: by outflank-mailman (input) for mailman id 753355; Wed, 03 Jul 2024 22:55:35 +0000 Received: from se1-gles-sth1-in.inumbo.com ([159.253.27.254] helo=se1-gles-sth1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1sP8sx-0004Kt-Ml for xen-devel@lists.xenproject.org; Wed, 03 Jul 2024 22:55:35 +0000 Received: from mail-wr1-x433.google.com (mail-wr1-x433.google.com [2a00:1450:4864:20::433]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 5b515ba4-398f-11ef-bbf9-fd08da9f4363; Thu, 04 Jul 2024 00:55:34 +0200 (CEST) Received: by mail-wr1-x433.google.com with SMTP id ffacd0b85a97d-36799a67d9cso68760f8f.0 for ; Wed, 03 Jul 2024 15:55:34 -0700 (PDT) Received: from andrewcoop.eng.citrite.net ([185.25.67.249]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a72aaf638f3sm549984566b.89.2024.07.03.15.55.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 03 Jul 2024 15:55:30 -0700 (PDT) X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 5b515ba4-398f-11ef-bbf9-fd08da9f4363 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=citrix.com; s=google; t=1720047333; x=1720652133; darn=lists.xenproject.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=nc6jPiNiL6yKZZqXuTh5pDooCk6e0PT5O2QbWpQhSHI=; b=n5xbw8LzwNYaG65SL2RdRRtR8U0mrwTTmLapG0dmPhFQxbhq897S981Xk/G5AzhyFr iX1RPJILXbYW75/NnwHv3iH6tqwcdCIR11O1m4z4L2jTYkYKO7HX/qhQt+EXxr1n8YbY CVayakmKUdwjvO1HIOSDI0uvWQ3wgr3/eQgxk= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1720047333; x=1720652133; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=nc6jPiNiL6yKZZqXuTh5pDooCk6e0PT5O2QbWpQhSHI=; b=G/i0UVABQeRuVKGBHwEv8xuUdxmMEy4TLP3IcO7hxcr80+5qxa20W+Z3dtoNCP4x8L inb7sC171p3FkZYp9csByDYowv6YsSOE0HbJytz8tlghs3m+xGR1Ssczu8aWcsPduBAu iYXfSYjIHuxylxpW1GVjL/sAY8ywBV0BtoKnQBpXbgr+31/Q9hA+jhVT23Lz1u75tnmx 4DBvGg117sTOA/Km4bib2nn/kHnzdXTdyC8qQrvBQ5Hj0uq7BmjaYJHrld1xDYIWibf1 GzmB/f1tKH945R2Y+0XI9p02KHjrwO4NzDDJjxGq3Blm8PJ1Son6Ev4zakuaPWtfkVkO QItA== X-Gm-Message-State: AOJu0Ywllm0pB+BNBalVT2v+39LqKl6DhURFhd2w3WEoAKteN/ITc8m8 27gqLMKDOntVzuMWDMVfn7fN5daFMmkwNc59P1JymM6PnbW58xdk88XTO1ZGicpSVpV78tbixui 2 X-Google-Smtp-Source: AGHT+IHK6dAz6/ClADPFpho9/pZFjPiB4wEg0e0Rt8mllSGYd2/Wv6a8YnlFCR+ELQkPE1R23gSDYw== X-Received: by 2002:a5d:4a45:0:b0:367:9114:4693 with SMTP id ffacd0b85a97d-3679dd31348mr18355f8f.31.1720047333205; Wed, 03 Jul 2024 15:55:33 -0700 (PDT) From: Andrew Cooper To: Xen-devel Cc: Andrew Cooper , Anthony PERARD , Jan Beulich , Stefano Stabellini , Julien Grall , Oleksii Kurochko Subject: [PATCH 1/2] build/mkheader: Remove C-isms from the code Date: Wed, 3 Jul 2024 23:55:24 +0100 Message-Id: <20240703225525.1759907-2-andrew.cooper3@citrix.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240703225525.1759907-1-andrew.cooper3@citrix.com> References: <20240703225525.1759907-1-andrew.cooper3@citrix.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @citrix.com) X-ZM-MESSAGEID: 1720047357501100001 Content-Type: text/plain; charset="utf-8" This was clearly written by a C programmer, rather than a python programmer. Drop all the useless semi-colons. The very final line of the script simply references f.close, rather than calling the function. Switch to using a with: statement, as python does ca= re about unclosed files if you enable enough warnings. No functional change. Signed-off-by: Andrew Cooper Reviewed-by: Anthony PERARD --- CC: Anthony PERARD CC: Jan Beulich CC: Stefano Stabellini CC: Julien Grall CC: Oleksii Kurochko --- tools/include/xen-foreign/mkheader.py | 104 +++++++++++++------------- 1 file changed, 51 insertions(+), 53 deletions(-) diff --git a/tools/include/xen-foreign/mkheader.py b/tools/include/xen-fore= ign/mkheader.py index 081b57f842a2..3a33df4984a2 100644 --- a/tools/include/xen-foreign/mkheader.py +++ b/tools/include/xen-foreign/mkheader.py @@ -2,21 +2,21 @@ =20 from __future__ import print_function =20 -import sys, re; -from structs import unions, structs, defines; +import sys, re +from structs import unions, structs, defines =20 # command line arguments -arch =3D sys.argv[1]; -outfile =3D sys.argv[2]; -infiles =3D sys.argv[3:]; +arch =3D sys.argv[1] +outfile =3D sys.argv[2] +infiles =3D sys.argv[3:] =20 =20 ########################################################################### # configuration #2: architecture information =20 -inttypes =3D {}; -header =3D {}; -footer =3D {}; +inttypes =3D {} +header =3D {} +footer =3D {} =20 #arm inttypes["arm32"] =3D [ @@ -35,7 +35,7 @@ header["arm32"] =3D """ # define __DECL_REG(n64, n32) uint64_t n64 # define __align8__ FIXME #endif -"""; +""" footer["arm32"] =3D """ #undef __DECL_REG """ @@ -56,7 +56,7 @@ header["arm64"] =3D """ # define __DECL_REG(n64, n32) uint64_t n64 # define __align8__ FIXME #endif -"""; +""" footer["arm64"] =3D """ #undef __DECL_REG """ @@ -73,12 +73,12 @@ header["x86_32"] =3D """ #define __DECL_REG_LO16(name) uint32_t e ## name #define __i386___X86_32 1 #pragma pack(4) -"""; +""" footer["x86_32"] =3D """ #undef __DECL_REG_LO8 #undef __DECL_REG_LO16 #pragma pack() -"""; +""" =20 # x86_64 inttypes["x86_64"] =3D [ @@ -100,7 +100,7 @@ header["x86_64"] =3D """ #define __DECL_REG_LO16 __DECL_REG #define __DECL_REG_HI __DECL_REG #define __x86_64___X86_64 1 -"""; +""" footer["x86_64"] =3D """ #undef __DECL_REG #undef __DECL_REG_LOHI @@ -112,12 +112,12 @@ footer["x86_64"] =3D """ ########################################################################### # main =20 -input =3D ""; -output =3D ""; -fileid =3D re.sub("[-.]", "_", "__FOREIGN_%s__" % outfile.upper()); +input =3D "" +output =3D "" +fileid =3D re.sub("[-.]", "_", "__FOREIGN_%s__" % outfile.upper()) =20 for name in infiles: - f =3D open(name, "r"); + f =3D open(name, "r") =20 # Sanity check the licence of the input file(s) line =3D f.readline() @@ -126,8 +126,8 @@ for name in infiles: (sys.argv[0], name, line.strip()), file=3Dsys.stderr) exit(1) =20 - input +=3D f.read(); - f.close(); + input +=3D f.read() + f.close() =20 # replace path in "infiles" by path in '/usr/include' to avoid exposing the # build directory path in the generated headers. @@ -151,83 +151,81 @@ output +=3D """/* SPDX-License-Identifier: MIT */ """ % (arch, headers_name_list, sys.argv[0], fileid, fileid) =20 if arch in header: - output +=3D header[arch]; - output +=3D "\n"; + output +=3D header[arch] + output +=3D "\n" =20 defined =3D {} =20 # add defines to output for line in re.findall("#define[^\n]+", input): for define in defines: - regex =3D "#define\s+%s\\b" % define; - match =3D re.search(regex, line); + regex =3D "#define\s+%s\\b" % define + match =3D re.search(regex, line) if None =3D=3D match: - continue; + continue defined[define] =3D 1 if define.upper()[0] =3D=3D define[0]: - replace =3D define + "_" + arch.upper(); + replace =3D define + "_" + arch.upper() else: - replace =3D define + "_" + arch; - regex =3D "\\b%s\\b" % define; - output +=3D re.sub(regex, replace, line) + "\n"; -output +=3D "\n"; + replace =3D define + "_" + arch + regex =3D "\\b%s\\b" % define + output +=3D re.sub(regex, replace, line) + "\n" +output +=3D "\n" =20 # delete defines, comments, empty lines -input =3D re.sub("#define[^\n]+\n", "", input); +input =3D re.sub("#define[^\n]+\n", "", input) input =3D re.compile("/\*(.*?)\*/", re.S).sub("", input) -input =3D re.compile("\n\s*\n", re.S).sub("\n", input); +input =3D re.compile("\n\s*\n", re.S).sub("\n", input) =20 # add unions to output for union in unions: - regex =3D "union\s+%s\s*\{(.*?)\n\};" % union; + regex =3D "union\s+%s\s*\{(.*?)\n\};" % union match =3D re.search(regex, input, re.S) if None =3D=3D match: - output +=3D "#define %s_has_no_%s 1\n" % (arch, union); + output +=3D "#define %s_has_no_%s 1\n" % (arch, union) else: - output +=3D "union %s_%s {%s\n};\n" % (union, arch, match.group(1)= ); - output +=3D "\n"; + output +=3D "union %s_%s {%s\n};\n" % (union, arch, match.group(1)) + output +=3D "\n" =20 # add structs to output for struct in structs: - regex =3D "(?:#ifdef ([A-Z_]+))?\nstruct\s+%s\s*\{(.*?)\n\};" % struct; + regex =3D "(?:#ifdef ([A-Z_]+))?\nstruct\s+%s\s*\{(.*?)\n\};" % struct match =3D re.search(regex, input, re.S) if None =3D=3D match or \ (match.group(1) is not None and match.group(1) not in defined): - output +=3D "#define %s_has_no_%s 1\n" % (arch, struct); + output +=3D "#define %s_has_no_%s 1\n" % (arch, struct) else: - output +=3D "struct %s_%s {%s\n};\n" % (struct, arch, match.group(= 2)); - output +=3D "typedef struct %s_%s %s_%s_t;\n" % (struct, arch, str= uct, arch); - output +=3D "\n"; + output +=3D "struct %s_%s {%s\n};\n" % (struct, arch, match.group(= 2)) + output +=3D "typedef struct %s_%s %s_%s_t;\n" % (struct, arch, str= uct, arch) + output +=3D "\n" =20 # add footer if arch in footer: - output +=3D footer[arch]; - output +=3D "\n"; -output +=3D "#endif /* %s */\n" % fileid; + output +=3D footer[arch] + output +=3D "\n" +output +=3D "#endif /* %s */\n" % fileid =20 # replace: defines for define in defines: if define.upper()[0] =3D=3D define[0]: - replace =3D define + "_" + arch.upper(); + replace =3D define + "_" + arch.upper() else: - replace =3D define + "_" + arch; - output =3D re.sub("\\b%s\\b" % define, replace, output); + replace =3D define + "_" + arch + output =3D re.sub("\\b%s\\b" % define, replace, output) =20 # replace: unions for union in unions: - output =3D re.sub("\\b(union\s+%s)\\b" % union, "\\1_%s" % arch, outpu= t); + output =3D re.sub("\\b(union\s+%s)\\b" % union, "\\1_%s" % arch, outpu= t) =20 # replace: structs + struct typedefs for struct in structs: - output =3D re.sub("\\b(struct\s+%s)\\b" % struct, "\\1_%s" % arch, out= put); - output =3D re.sub("\\b(%s)_t\\b" % struct, "\\1_%s_t" % arch, output); + output =3D re.sub("\\b(struct\s+%s)\\b" % struct, "\\1_%s" % arch, out= put) + output =3D re.sub("\\b(%s)_t\\b" % struct, "\\1_%s_t" % arch, output) =20 # replace: integer types for old, new in inttypes[arch]: output =3D re.sub("\\b%s\\b" % old, new, output) =20 # print results -f =3D open(outfile, "w"); -f.write(output); -f.close; - +with open(outfile, "w") as f: + f.write(output) --=20 2.39.2 From nobody Mon Sep 16 19:21:36 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass(p=reject dis=none) header.from=citrix.com ARC-Seal: i=1; a=rsa-sha256; t=1720047358; cv=none; d=zohomail.com; s=zohoarc; b=Tg2sBsGhNPRmAZLZjQCdEX9TkTIivKGrnYyqaTjIX2fYeMvYAgIDRsWegy2dGezHnwkNTP4SojbyHK8Uce/RiKwHsnGUkgV89KurqeG3p7cA2uOu8oT5LO8T2nYKkDDk2Lzs9tY5uufRn/IUCiazVr4ovBSu3xDiWGAmZegdiE0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1720047358; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=AFUGiegqbMuC9H9PbqyiLhEoErZkG5s/nrc/O3c/qqA=; b=jGyxfwBcHRheT/UGh/k/EYiJU54lyCKwfx01LTarwGjBBprjx3K/xdpfxKKlQ30e+n5asxJZgkMbXoTUuXaPBAKsok49TRD1zCFOG8Dr5iqMeLWTsQ0KoNgk2eAKWDtEkcZ/rPfBGY+pDGzH9mVPSdM/9sVpxLMPjq79774shm4= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass header.from= (p=reject dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1720047358609118.40147042339981; Wed, 3 Jul 2024 15:55:58 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.753356.1161610 (Exim 4.92) (envelope-from ) id 1sP8t0-0004pf-B8; Wed, 03 Jul 2024 22:55:38 +0000 Received: by outflank-mailman (output) from mailman id 753356.1161610; Wed, 03 Jul 2024 22:55:38 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1sP8t0-0004pW-7d; Wed, 03 Jul 2024 22:55:38 +0000 Received: by outflank-mailman (input) for mailman id 753356; Wed, 03 Jul 2024 22:55:37 +0000 Received: from se1-gles-sth1-in.inumbo.com ([159.253.27.254] helo=se1-gles-sth1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1sP8sz-0004Kt-Mt for xen-devel@lists.xenproject.org; Wed, 03 Jul 2024 22:55:37 +0000 Received: from mail-ej1-x631.google.com (mail-ej1-x631.google.com [2a00:1450:4864:20::631]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 5ca5a0bf-398f-11ef-bbf9-fd08da9f4363; Thu, 04 Jul 2024 00:55:37 +0200 (CEST) Received: by mail-ej1-x631.google.com with SMTP id a640c23a62f3a-a7194ce90afso1946666b.2 for ; Wed, 03 Jul 2024 15:55:37 -0700 (PDT) Received: from andrewcoop.eng.citrite.net ([185.25.67.249]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a72aaf638f3sm549984566b.89.2024.07.03.15.55.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 03 Jul 2024 15:55:33 -0700 (PDT) X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 5ca5a0bf-398f-11ef-bbf9-fd08da9f4363 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=citrix.com; s=google; t=1720047335; x=1720652135; darn=lists.xenproject.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=AFUGiegqbMuC9H9PbqyiLhEoErZkG5s/nrc/O3c/qqA=; b=OxGXtAVJ4Nv5v67J+5JiaUB/8NAldl+flItHWUuPHqRHBjrpVZDA4KGltCfcWd7oNW NJs8AAjQuXDD5BMy5OKoCPheo6W14jKvIeWWQq6g/xl13EYHaIrnliC+7zJ0ulXxQdwc 7+k+S8mlkP5ZkkNZLkWBsuQg12Mqn934cTA+I= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1720047335; x=1720652135; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=AFUGiegqbMuC9H9PbqyiLhEoErZkG5s/nrc/O3c/qqA=; b=AQmDgDnyO7CQc22kjkmO75bn8pdiqn6L/WoXqoDJPl8dRU7+mRxl83PaBsCwBi5k2i J3DE4+KCenjGK+0IS/vHUas7Y5Uu0xPrUoJP++9jdqVa3xDpLwlTvS8jzaDoMncEx7+V ziwQC0Ua7aLKPfpVL9rdcHLNGu4+I1wAYUe6pCe0HjuyJCgW7K0dwd07UdeccdVi+yXL IrQVgRLpmgcHTTI12RaMnToY/0sA5h2Z99YYQCVQQOQF6nBFcnQje2Z/ZuVnTz0oQAb2 NfttDK67NiSmJf9hw2xJM9TmQ/J6/V6xSRe0MYe3HhCA5JodFhIaDMq3vNWHLkExnlvJ S/eg== X-Gm-Message-State: AOJu0Yy+6VUpCzflH4zg9x3KQ2Qr3jNSq/z7PYrxF7rdvi5CcXvNrgDF iOcaXvsUFUD0YSwQUGEwa4SjaMtxlfB97pedlIOgGWW76oQBTL+l5x9CO3EKVCD7ROHwdIxZ0kd w X-Google-Smtp-Source: AGHT+IETyXGsHmaw2eGrnOW4zIkrlxRNxnzOyZgqrp1bog7Onu2fsOpqcWadq5jB2XvIpNO5yxp0ww== X-Received: by 2002:a17:907:31c6:b0:a72:b340:8827 with SMTP id a640c23a62f3a-a75144398c7mr1014444966b.41.1720047335609; Wed, 03 Jul 2024 15:55:35 -0700 (PDT) From: Andrew Cooper To: Xen-devel Cc: Andrew Cooper , Anthony PERARD , Jan Beulich , Stefano Stabellini , Julien Grall , Oleksii Kurochko Subject: [PATCH 2/2] build/mkheader: Fix Syntax/DeprecationWarnings Date: Wed, 3 Jul 2024 23:55:25 +0100 Message-Id: <20240703225525.1759907-3-andrew.cooper3@citrix.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240703225525.1759907-1-andrew.cooper3@citrix.com> References: <20240703225525.1759907-1-andrew.cooper3@citrix.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @citrix.com) X-ZM-MESSAGEID: 1720047359369100003 Content-Type: text/plain; charset="utf-8" With Python 3.11, the following is emitted during a build: tools/include/xen-foreign/mkheader.py:162: DeprecationWarning: invalid es= cape sequence '\s' regex =3D "#define\s+%s\\b" % define; tools/include/xen-foreign/mkheader.py:177: DeprecationWarning: invalid es= cape sequence '\*' input =3D re.compile("/\*(.*?)\*/", re.S).sub("", input) tools/include/xen-foreign/mkheader.py:178: DeprecationWarning: invalid es= cape sequence '\s' input =3D re.compile("\n\s*\n", re.S).sub("\n", input); tools/include/xen-foreign/mkheader.py:182: DeprecationWarning: invalid es= cape sequence '\s' regex =3D "union\s+%s\s*\{(.*?)\n\};" % union; tools/include/xen-foreign/mkheader.py:192: DeprecationWarning: invalid es= cape sequence '\s' regex =3D "(?:#ifdef ([A-Z_]+))?\nstruct\s+%s\s*\{(.*?)\n\};" % struct; tools/include/xen-foreign/mkheader.py:218: DeprecationWarning: invalid es= cape sequence '\s' output =3D re.sub("\\b(union\s+%s)\\b" % union, "\\1_%s" % arch, output= ); tools/include/xen-foreign/mkheader.py:222: DeprecationWarning: invalid es= cape sequence '\s' output =3D re.sub("\\b(struct\s+%s)\\b" % struct, "\\1_%s" % arch, outp= ut); Python regexes should use raw strings. Convert all regexes, and drop escap= ed backslashes. Note that regular escape sequences are interpreted normally w= hen parsing a regex, so \n even in a raw-string regex is a newline. No functional change. Signed-off-by: Andrew Cooper Reviewed-by: Anthony PERARD --- CC: Anthony PERARD CC: Jan Beulich CC: Stefano Stabellini CC: Julien Grall CC: Oleksii Kurochko --- tools/include/xen-foreign/mkheader.py | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/tools/include/xen-foreign/mkheader.py b/tools/include/xen-fore= ign/mkheader.py index 3a33df4984a2..128b0f3014c2 100644 --- a/tools/include/xen-foreign/mkheader.py +++ b/tools/include/xen-foreign/mkheader.py @@ -159,7 +159,7 @@ defined =3D {} # add defines to output for line in re.findall("#define[^\n]+", input): for define in defines: - regex =3D "#define\s+%s\\b" % define + regex =3D r"#define\s+%s\b" % define match =3D re.search(regex, line) if None =3D=3D match: continue @@ -168,18 +168,18 @@ for line in re.findall("#define[^\n]+", input): replace =3D define + "_" + arch.upper() else: replace =3D define + "_" + arch - regex =3D "\\b%s\\b" % define + regex =3D r"\b%s\b" % define output +=3D re.sub(regex, replace, line) + "\n" output +=3D "\n" =20 # delete defines, comments, empty lines input =3D re.sub("#define[^\n]+\n", "", input) -input =3D re.compile("/\*(.*?)\*/", re.S).sub("", input) -input =3D re.compile("\n\s*\n", re.S).sub("\n", input) +input =3D re.compile(r"/\*(.*?)\*/", re.S).sub("", input) +input =3D re.compile(r"\n\s*\n", re.S).sub("\n", input) =20 # add unions to output for union in unions: - regex =3D "union\s+%s\s*\{(.*?)\n\};" % union + regex =3D r"union\s+%s\s*\{(.*?)\n\};" % union match =3D re.search(regex, input, re.S) if None =3D=3D match: output +=3D "#define %s_has_no_%s 1\n" % (arch, union) @@ -189,7 +189,7 @@ for union in unions: =20 # add structs to output for struct in structs: - regex =3D "(?:#ifdef ([A-Z_]+))?\nstruct\s+%s\s*\{(.*?)\n\};" % struct + regex =3D r"(?:#ifdef ([A-Z_]+))?\nstruct\s+%s\s*\{(.*?)\n\};" % struct match =3D re.search(regex, input, re.S) if None =3D=3D match or \ (match.group(1) is not None and match.group(1) not in defined): @@ -211,20 +211,20 @@ for define in defines: replace =3D define + "_" + arch.upper() else: replace =3D define + "_" + arch - output =3D re.sub("\\b%s\\b" % define, replace, output) + output =3D re.sub(r"\b%s\b" % define, replace, output) =20 # replace: unions for union in unions: - output =3D re.sub("\\b(union\s+%s)\\b" % union, "\\1_%s" % arch, outpu= t) + output =3D re.sub(r"\b(union\s+%s)\b" % union, r"\1_%s" % arch, output) =20 # replace: structs + struct typedefs for struct in structs: - output =3D re.sub("\\b(struct\s+%s)\\b" % struct, "\\1_%s" % arch, out= put) - output =3D re.sub("\\b(%s)_t\\b" % struct, "\\1_%s_t" % arch, output) + output =3D re.sub(r"\b(struct\s+%s)\b" % struct, r"\1_%s" % arch, outp= ut) + output =3D re.sub(r"\b(%s)_t\b" % struct, r"\1_%s_t" % arch, output) =20 # replace: integer types for old, new in inttypes[arch]: - output =3D re.sub("\\b%s\\b" % old, new, output) + output =3D re.sub(r"\b%s\b" % old, new, output) =20 # print results with open(outfile, "w") as f: --=20 2.39.2