From patchwork Thu Jan 14 02:16:54 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 362811 Delivered-To: patch@linaro.org Received: by 2002:a02:ccad:0:0:0:0:0 with SMTP id t13csp75457jap; Wed, 13 Jan 2021 18:35:57 -0800 (PST) X-Google-Smtp-Source: ABdhPJwFQEk/afyzcn2LBxVam7JRtsFPAkr+n2BJJFVKldyqYYAMjn/Y4HsZ++E47Vg4OXCzfl2R X-Received: by 2002:a25:c095:: with SMTP id c143mr7388853ybf.119.1610591757665; Wed, 13 Jan 2021 18:35:57 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1610591757; cv=none; d=google.com; s=arc-20160816; b=rzx2Tlhrggow9sToq6Ae7pktG5jbJsqVPpGTvQfIFq+lrfLgkpEYwJLKjw1h7zgH5t YxRrAKr8cjIvep3QyUG9iDibiA8RiQHYHO2d8cZf5outf6KKCD9AlLrXqanX6oj4yrjo NQykZQkufV7aJtgH1ghpggx+P3Ih722xYwUm+XBaSQG26r7WTuzqS30u6c3Fd8f69Zia EV7VuyUn1pOqrqED+9HE9lTZHJkBTIsznLMEeSUwkGRtK9VzVYtc3mHduPJ2kcojzH0r RzZPmQ84J5iNGAzU2gZBfS2LS/2awSBiC+NOdUYJ/wwhXS4O7AJLxHDVWTX9eyaqoNrT mdgg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:to:from :dkim-signature; bh=BFho4U3fob4m3gWpchyMGBLbmRuOR0wIULlt2gnx2gA=; b=GGCn+0LeaoEZGJnT7lTYTmm91kBgdt8qgOo7B1Cthq+UJ/hDYlnP4nkVcUwumL0til sxGgiXKhJfmGHPfppLZPp0isGe2zA8oVR6Tv2coxe8/zwJhiCBtEwRuT97mgjZk2pIGH EVWKjl8VvV3DCrlSxbGUCdpDGweUA+5MLXyNJOdn/yyOEQrhLzKtQ8A8DnX3axIrMZH9 gf50BZvoIcxeL+chx8j6mOy/ppcZGGm0CAxbvl1lGT+1MuL0C4KrUOnBwrQ+yH/WglVZ hg/sElNKvmykaeuY2nlZeH7E6uZ4qPrZiWEc0UsPOJmNzoEEtl6HbY2ifggpq/M9gP8L FFxg== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=P8AsBAjC; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id d14si2556147ybj.19.2021.01.13.18.35.57 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Wed, 13 Jan 2021 18:35:57 -0800 (PST) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=P8AsBAjC; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:58578 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kzsUP-0000Ov-4c for patch@linaro.org; Wed, 13 Jan 2021 21:35:57 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:60520) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kzsCn-0003ve-Sj for qemu-devel@nongnu.org; Wed, 13 Jan 2021 21:17:45 -0500 Received: from mail-pg1-x52a.google.com ([2607:f8b0:4864:20::52a]:36921) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1kzsCh-0003Yu-Sh for qemu-devel@nongnu.org; Wed, 13 Jan 2021 21:17:45 -0500 Received: by mail-pg1-x52a.google.com with SMTP id z21so2748006pgj.4 for ; Wed, 13 Jan 2021 18:17:39 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=BFho4U3fob4m3gWpchyMGBLbmRuOR0wIULlt2gnx2gA=; b=P8AsBAjCe1GbV/I2MyFKU+agoFuPCHOPymRwWQTXv2nvPqpqL9GU5Pcc35iufRjyGH 1Kirl1N2o9muhkqmfR9GPr9e2n1bfx2M8e7vigBCTScsOGs7GdsqQhBAkW8dGlgun8HG 1hygl/1M3Osn9roA64CdeurAdfay9+h2ousHY1Y4dsE7tPdOE2996gQyuJDiUCKjr/NX qabzgdu11LZG4RlWYimXkHS+R155yMGpf8Qq2J6mkfKVTmzQOABoDhKPkDvOVrpQ+gzy RCjScl1lgifWQCbFPOuwjXVpU/pbufYJKtCgbrauIQxUqbujRLjzDNm9iDtteicPxmaO RmoA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=BFho4U3fob4m3gWpchyMGBLbmRuOR0wIULlt2gnx2gA=; b=DeMwNja62hDFRYsZx13SLJgF50e1lq0oiLUsMXZRlDZ4H4aGsFouOBG3JkR6xCca1l qD5r/H4l/fHlo24jyP4gdeID31Asrjmq2SIDTlakRyDuJvxbFOdB2zWPnq/TPEYL+RUz AJ4p8ujmKLtRN6OYJa3ueaNqnjVLu2IcgqAZvVUQjNJvlHj9I4EXuw01zLdbWbY2bI1P Em4GC2Ng9SXcbZDAgqQWidSu7fuswub0qh37b0sRWzDP3pBvLUdpi9EJ+bopsqDjz0q8 6h5tsSov5WCFBTrZjMgn0e2rObck7PaBGxQilSZobFpzMayR0S/vg/u0RjInAFKH4PLf ehiA== X-Gm-Message-State: AOAM530tZ9+4Pea6s5ghiQeSnyOBzxOhD4cgAbD6PA1ssJkvTyiCC1Tv tbOYUeHA+2gxMJ3nPN+gbe2Tdg7IdwPObQ== X-Received: by 2002:a65:4347:: with SMTP id k7mr5024198pgq.186.1610590658332; Wed, 13 Jan 2021 18:17:38 -0800 (PST) Received: from localhost.localdomain (rrcs-173-197-107-21.west.biz.rr.com. [173.197.107.21]) by smtp.gmail.com with ESMTPSA id i7sm3771687pfc.50.2021.01.13.18.17.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 13 Jan 2021 18:17:37 -0800 (PST) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PULL 24/24] decodetree: Open files with encoding='utf-8' Date: Wed, 13 Jan 2021 16:16:54 -1000 Message-Id: <20210114021654.647242-25-richard.henderson@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210114021654.647242-1-richard.henderson@linaro.org> References: <20210114021654.647242-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::52a; envelope-from=richard.henderson@linaro.org; helo=mail-pg1-x52a.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: peter.maydell@linaro.org, Yonggang Luo , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , Eduardo Habkost Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" From: Philippe Mathieu-Daudé When decodetree.py was added in commit 568ae7efae7, QEMU was using Python 2 which happily reads UTF-8 files in text mode. Python 3 requires either UTF-8 locale or an explicit encoding passed to open(). Now that Python 3 is required, explicit UTF-8 encoding for decodetree source files. To avoid further problems with the user locale, also explicit UTF-8 encoding for the generated C files. Explicit both input/output are plain text by using the 't' mode. This fixes: $ /usr/bin/python3 scripts/decodetree.py test.decode Traceback (most recent call last): File "scripts/decodetree.py", line 1397, in main() File "scripts/decodetree.py", line 1308, in main parse_file(f, toppat) File "scripts/decodetree.py", line 994, in parse_file for line in f: File "/usr/lib/python3.6/encodings/ascii.py", line 26, in decode return codecs.ascii_decode(input, self.errors)[0] UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position 80: ordinal not in range(128) Reported-by: Peter Maydell Suggested-by: Yonggang Luo Reviewed-by: Eduardo Habkost Signed-off-by: Philippe Mathieu-Daudé Message-Id: <20210110000240.761122-1-f4bug@amsat.org> Signed-off-by: Richard Henderson --- scripts/decodetree.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) -- 2.25.1 diff --git a/scripts/decodetree.py b/scripts/decodetree.py index 47aa9caf6d..4637b633e7 100644 --- a/scripts/decodetree.py +++ b/scripts/decodetree.py @@ -20,6 +20,7 @@ # See the syntax and semantics in docs/devel/decodetree.rst. # +import io import os import re import sys @@ -1304,7 +1305,7 @@ def main(): for filename in args: input_file = filename - f = open(filename, 'r') + f = open(filename, 'rt', encoding='utf-8') parse_file(f, toppat) f.close() @@ -1324,9 +1325,11 @@ def main(): prop_size(stree) if output_file: - output_fd = open(output_file, 'w') + output_fd = open(output_file, 'wt', encoding='utf-8') else: - output_fd = sys.stdout + output_fd = io.TextIOWrapper(sys.stdout.buffer, + encoding=sys.stdout.encoding, + errors="ignore") output_autogen() for n in sorted(arguments.keys()):