From patchwork Wed Jul 3 22:55:24 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Cooper X-Patchwork-Id: 13723028 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 5793DC31D97 for ; Wed, 3 Jul 2024 22:55:48 +0000 (UTC) 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 X-Outflank-Mailman: Message body and most headers restored to incoming version 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-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 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 care 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-foreign/mkheader.py index 081b57f842a2..3a33df4984a2 100644 --- a/tools/include/xen-foreign/mkheader.py +++ b/tools/include/xen-foreign/mkheader.py @@ -2,21 +2,21 @@ from __future__ import print_function -import sys, re; -from structs import unions, structs, defines; +import sys, re +from structs import unions, structs, defines # command line arguments -arch = sys.argv[1]; -outfile = sys.argv[2]; -infiles = sys.argv[3:]; +arch = sys.argv[1] +outfile = sys.argv[2] +infiles = sys.argv[3:] ########################################################################### # configuration #2: architecture information -inttypes = {}; -header = {}; -footer = {}; +inttypes = {} +header = {} +footer = {} #arm inttypes["arm32"] = [ @@ -35,7 +35,7 @@ header["arm32"] = """ # define __DECL_REG(n64, n32) uint64_t n64 # define __align8__ FIXME #endif -"""; +""" footer["arm32"] = """ #undef __DECL_REG """ @@ -56,7 +56,7 @@ header["arm64"] = """ # define __DECL_REG(n64, n32) uint64_t n64 # define __align8__ FIXME #endif -"""; +""" footer["arm64"] = """ #undef __DECL_REG """ @@ -73,12 +73,12 @@ header["x86_32"] = """ #define __DECL_REG_LO16(name) uint32_t e ## name #define __i386___X86_32 1 #pragma pack(4) -"""; +""" footer["x86_32"] = """ #undef __DECL_REG_LO8 #undef __DECL_REG_LO16 #pragma pack() -"""; +""" # x86_64 inttypes["x86_64"] = [ @@ -100,7 +100,7 @@ header["x86_64"] = """ #define __DECL_REG_LO16 __DECL_REG #define __DECL_REG_HI __DECL_REG #define __x86_64___X86_64 1 -"""; +""" footer["x86_64"] = """ #undef __DECL_REG #undef __DECL_REG_LOHI @@ -112,12 +112,12 @@ footer["x86_64"] = """ ########################################################################### # main -input = ""; -output = ""; -fileid = re.sub("[-.]", "_", "__FOREIGN_%s__" % outfile.upper()); +input = "" +output = "" +fileid = re.sub("[-.]", "_", "__FOREIGN_%s__" % outfile.upper()) for name in infiles: - f = open(name, "r"); + f = open(name, "r") # Sanity check the licence of the input file(s) line = f.readline() @@ -126,8 +126,8 @@ for name in infiles: (sys.argv[0], name, line.strip()), file=sys.stderr) exit(1) - input += f.read(); - f.close(); + input += f.read() + f.close() # 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 += """/* SPDX-License-Identifier: MIT */ """ % (arch, headers_name_list, sys.argv[0], fileid, fileid) if arch in header: - output += header[arch]; - output += "\n"; + output += header[arch] + output += "\n" defined = {} # add defines to output for line in re.findall("#define[^\n]+", input): for define in defines: - regex = "#define\s+%s\\b" % define; - match = re.search(regex, line); + regex = "#define\s+%s\\b" % define + match = re.search(regex, line) if None == match: - continue; + continue defined[define] = 1 if define.upper()[0] == define[0]: - replace = define + "_" + arch.upper(); + replace = define + "_" + arch.upper() else: - replace = define + "_" + arch; - regex = "\\b%s\\b" % define; - output += re.sub(regex, replace, line) + "\n"; -output += "\n"; + replace = define + "_" + arch + regex = "\\b%s\\b" % define + output += re.sub(regex, replace, line) + "\n" +output += "\n" # delete defines, comments, empty lines -input = re.sub("#define[^\n]+\n", "", input); +input = re.sub("#define[^\n]+\n", "", input) input = re.compile("/\*(.*?)\*/", re.S).sub("", input) -input = re.compile("\n\s*\n", re.S).sub("\n", input); +input = re.compile("\n\s*\n", re.S).sub("\n", input) # add unions to output for union in unions: - regex = "union\s+%s\s*\{(.*?)\n\};" % union; + regex = "union\s+%s\s*\{(.*?)\n\};" % union match = re.search(regex, input, re.S) if None == match: - output += "#define %s_has_no_%s 1\n" % (arch, union); + output += "#define %s_has_no_%s 1\n" % (arch, union) else: - output += "union %s_%s {%s\n};\n" % (union, arch, match.group(1)); - output += "\n"; + output += "union %s_%s {%s\n};\n" % (union, arch, match.group(1)) + output += "\n" # add structs to output for struct in structs: - regex = "(?:#ifdef ([A-Z_]+))?\nstruct\s+%s\s*\{(.*?)\n\};" % struct; + regex = "(?:#ifdef ([A-Z_]+))?\nstruct\s+%s\s*\{(.*?)\n\};" % struct match = re.search(regex, input, re.S) if None == match or \ (match.group(1) is not None and match.group(1) not in defined): - output += "#define %s_has_no_%s 1\n" % (arch, struct); + output += "#define %s_has_no_%s 1\n" % (arch, struct) else: - output += "struct %s_%s {%s\n};\n" % (struct, arch, match.group(2)); - output += "typedef struct %s_%s %s_%s_t;\n" % (struct, arch, struct, arch); - output += "\n"; + output += "struct %s_%s {%s\n};\n" % (struct, arch, match.group(2)) + output += "typedef struct %s_%s %s_%s_t;\n" % (struct, arch, struct, arch) + output += "\n" # add footer if arch in footer: - output += footer[arch]; - output += "\n"; -output += "#endif /* %s */\n" % fileid; + output += footer[arch] + output += "\n" +output += "#endif /* %s */\n" % fileid # replace: defines for define in defines: if define.upper()[0] == define[0]: - replace = define + "_" + arch.upper(); + replace = define + "_" + arch.upper() else: - replace = define + "_" + arch; - output = re.sub("\\b%s\\b" % define, replace, output); + replace = define + "_" + arch + output = re.sub("\\b%s\\b" % define, replace, output) # replace: unions for union in unions: - output = re.sub("\\b(union\s+%s)\\b" % union, "\\1_%s" % arch, output); + output = re.sub("\\b(union\s+%s)\\b" % union, "\\1_%s" % arch, output) # replace: structs + struct typedefs for struct in structs: - output = re.sub("\\b(struct\s+%s)\\b" % struct, "\\1_%s" % arch, output); - output = re.sub("\\b(%s)_t\\b" % struct, "\\1_%s_t" % arch, output); + output = re.sub("\\b(struct\s+%s)\\b" % struct, "\\1_%s" % arch, output) + output = re.sub("\\b(%s)_t\\b" % struct, "\\1_%s_t" % arch, output) # replace: integer types for old, new in inttypes[arch]: output = re.sub("\\b%s\\b" % old, new, output) # print results -f = open(outfile, "w"); -f.write(output); -f.close; - +with open(outfile, "w") as f: + f.write(output) From patchwork Wed Jul 3 22:55:25 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Cooper X-Patchwork-Id: 13723027 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 4EE68C41513 for ; Wed, 3 Jul 2024 22:55:48 +0000 (UTC) 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 X-Outflank-Mailman: Message body and most headers restored to incoming version 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-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 With Python 3.11, the following is emitted during a build: tools/include/xen-foreign/mkheader.py:162: DeprecationWarning: invalid escape sequence '\s' regex = "#define\s+%s\\b" % define; tools/include/xen-foreign/mkheader.py:177: DeprecationWarning: invalid escape sequence '\*' input = re.compile("/\*(.*?)\*/", re.S).sub("", input) tools/include/xen-foreign/mkheader.py:178: DeprecationWarning: invalid escape sequence '\s' input = re.compile("\n\s*\n", re.S).sub("\n", input); tools/include/xen-foreign/mkheader.py:182: DeprecationWarning: invalid escape sequence '\s' regex = "union\s+%s\s*\{(.*?)\n\};" % union; tools/include/xen-foreign/mkheader.py:192: DeprecationWarning: invalid escape sequence '\s' regex = "(?:#ifdef ([A-Z_]+))?\nstruct\s+%s\s*\{(.*?)\n\};" % struct; tools/include/xen-foreign/mkheader.py:218: DeprecationWarning: invalid escape sequence '\s' output = re.sub("\\b(union\s+%s)\\b" % union, "\\1_%s" % arch, output); tools/include/xen-foreign/mkheader.py:222: DeprecationWarning: invalid escape sequence '\s' output = re.sub("\\b(struct\s+%s)\\b" % struct, "\\1_%s" % arch, output); Python regexes should use raw strings. Convert all regexes, and drop escaped backslashes. Note that regular escape sequences are interpreted normally when 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-foreign/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 = {} # add defines to output for line in re.findall("#define[^\n]+", input): for define in defines: - regex = "#define\s+%s\\b" % define + regex = r"#define\s+%s\b" % define match = re.search(regex, line) if None == match: continue @@ -168,18 +168,18 @@ for line in re.findall("#define[^\n]+", input): replace = define + "_" + arch.upper() else: replace = define + "_" + arch - regex = "\\b%s\\b" % define + regex = r"\b%s\b" % define output += re.sub(regex, replace, line) + "\n" output += "\n" # delete defines, comments, empty lines input = re.sub("#define[^\n]+\n", "", input) -input = re.compile("/\*(.*?)\*/", re.S).sub("", input) -input = re.compile("\n\s*\n", re.S).sub("\n", input) +input = re.compile(r"/\*(.*?)\*/", re.S).sub("", input) +input = re.compile(r"\n\s*\n", re.S).sub("\n", input) # add unions to output for union in unions: - regex = "union\s+%s\s*\{(.*?)\n\};" % union + regex = r"union\s+%s\s*\{(.*?)\n\};" % union match = re.search(regex, input, re.S) if None == match: output += "#define %s_has_no_%s 1\n" % (arch, union) @@ -189,7 +189,7 @@ for union in unions: # add structs to output for struct in structs: - regex = "(?:#ifdef ([A-Z_]+))?\nstruct\s+%s\s*\{(.*?)\n\};" % struct + regex = r"(?:#ifdef ([A-Z_]+))?\nstruct\s+%s\s*\{(.*?)\n\};" % struct match = re.search(regex, input, re.S) if None == match or \ (match.group(1) is not None and match.group(1) not in defined): @@ -211,20 +211,20 @@ for define in defines: replace = define + "_" + arch.upper() else: replace = define + "_" + arch - output = re.sub("\\b%s\\b" % define, replace, output) + output = re.sub(r"\b%s\b" % define, replace, output) # replace: unions for union in unions: - output = re.sub("\\b(union\s+%s)\\b" % union, "\\1_%s" % arch, output) + output = re.sub(r"\b(union\s+%s)\b" % union, r"\1_%s" % arch, output) # replace: structs + struct typedefs for struct in structs: - output = re.sub("\\b(struct\s+%s)\\b" % struct, "\\1_%s" % arch, output) - output = re.sub("\\b(%s)_t\\b" % struct, "\\1_%s_t" % arch, output) + output = re.sub(r"\b(struct\s+%s)\b" % struct, r"\1_%s" % arch, output) + output = re.sub(r"\b(%s)_t\b" % struct, r"\1_%s_t" % arch, output) # replace: integer types for old, new in inttypes[arch]: - output = re.sub("\\b%s\\b" % old, new, output) + output = re.sub(r"\b%s\b" % old, new, output) # print results with open(outfile, "w") as f: