From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id gIi9Fo7c2WJ2TxgAWB0awg (envelope-from ) for ; Thu, 21 Jul 2022 19:09:02 -0400 Received: by simark.ca (Postfix, from userid 112) id 58B341E5EA; Thu, 21 Jul 2022 19:09:02 -0400 (EDT) Authentication-Results: simark.ca; dkim=pass (1024-bit key; secure) header.d=sourceware.org header.i=@sourceware.org header.a=rsa-sha256 header.s=default header.b=SobhX4Dw; dkim-atps=neutral X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on simark.ca X-Spam-Level: X-Spam-Status: No, score=-3.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,URIBL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.6 Received: from sourceware.org (server2.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by simark.ca (Postfix) with ESMTPS id E609A1E21F for ; Thu, 21 Jul 2022 19:09:01 -0400 (EDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 75D9D38356A0 for ; Thu, 21 Jul 2022 23:09:01 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 75D9D38356A0 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1658444941; bh=JG/PluHDZVpDc9ZGkfwjHY0AjjDShbqXnDQdroO+nv8=; h=Date:To:Subject:In-Reply-To:References:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc: From; b=SobhX4DwjFQWyEypHxUpKcb1LbnfrmIWWIuN+yYI1qbQwuhtoe2D12STuWTopZ6fQ pT/1UTSoPcGY2AvZNna1AqvZRw3Uv1gJJyAztHPdaf7vsQz9wQE0VQveZ/vLQEM9NG 8K8sPxmTnTl2i+jJzYLOv8J7rDLKJKx2qqywA+7M= Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by sourceware.org (Postfix) with ESMTPS id C078C383583A for ; Thu, 21 Jul 2022 23:08:41 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org C078C383583A Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-152-5NE5-MvsPvuLcRM1vdizGg-1; Thu, 21 Jul 2022 19:08:35 -0400 X-MC-Unique: 5NE5-MvsPvuLcRM1vdizGg-1 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.rdu2.redhat.com [10.11.54.7]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 815D429DD992; Thu, 21 Jul 2022 23:08:34 +0000 (UTC) Received: from f35-zws-1 (unknown [10.2.16.60]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 1024C1415118; Thu, 21 Jul 2022 23:08:33 +0000 (UTC) Date: Thu, 21 Jul 2022 16:08:32 -0700 To: Pedro Alves Subject: Re: [PATCH] set/show python dont-write-bytecode fixes Message-ID: <20220721160832.3a1d4b3c@f35-zws-1> In-Reply-To: <96a7e665-5700-349c-dfc5-50e59ab78fa5@palves.net> References: <20220720191447.1014407-1-kevinb@redhat.com> <96a7e665-5700-349c-dfc5-50e59ab78fa5@palves.net> Organization: Red Hat MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.85 on 10.11.54.7 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , From: Kevin Buettner via Gdb-patches Reply-To: Kevin Buettner Cc: Simon Marchi , gdb-patches@sourceware.org Errors-To: gdb-patches-bounces+public-inbox=simark.ca@sourceware.org Sender: "Gdb-patches" On Thu, 21 Jul 2022 18:55:35 +0100 Pedro Alves wrote: > Hi Kevin, > > I just skimmed the patch without paying much attention, but I noticed a typo, below, > in "intialization". > > On 2022-07-20 8:14 p.m., Kevin Buettner via Gdb-patches wrote: > > +In order to take effect, this setting must be enabled before python\n\ > > +intialization."), > Thanks for spotting this! Fixed - see below: GDB uses the environment variable PYTHONDONTWRITEBYTECODE to determine whether or not to write the result of byte-compiling python modules when the "python dont-write-bytecode" setting is "auto". Simon noticed that GDB's implementation doesn't follow the Python documentation. At present, GDB only checks for the existence of this environment variable. That is not sufficient though. Regarding PYTHONDONTWRITEBYTECODE, this document... https://docs.python.org/3/using/cmdline.html ...says: If this is set to a non-empty string, Python won't try to write .pyc files on the import of source modules. This commit fixes GDB's handling of PYTHONDONTWRITEBYTECODE by adding an empty string check. This commit also corrects the set/show command documentation for "python dont-write-bytecode". The current doc was just a copy of that for set/show python ignore-environment. --- gdb/python/python.c | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/gdb/python/python.c b/gdb/python/python.c index c7d4157b70c..eef7946f28d 100644 --- a/gdb/python/python.c +++ b/gdb/python/python.c @@ -1866,8 +1866,15 @@ python_write_bytecode () int wbc = 0; if (python_dont_write_bytecode == AUTO_BOOLEAN_AUTO) - wbc = (!python_ignore_environment - && getenv ("PYTHONDONTWRITEBYTECODE") != nullptr) ? 0 : 1; + { + if (python_ignore_environment) + wbc = 1; + else + { + const char *pdwbc = getenv ("PYTHONDONTWRITEBYTECODE"); + wbc = (pdwbc == nullptr || pdwbc[0] == '\0') ? 1 : 0; + } + } else wbc = python_dont_write_bytecode == AUTO_BOOLEAN_TRUE ? 0 : 1; @@ -2346,11 +2353,11 @@ python executable."), add_setshow_auto_boolean_cmd ("dont-write-bytecode", no_class, &python_dont_write_bytecode, _("\ -Set whether the Python interpreter should ignore environment variables."), _(" \ -Show whether the Python interpreter showlist ignore environment variables."), _(" \ -When enabled GDB's Python interpreter will ignore any Python related\n \ -flags in the environment. This is equivalent to passing `-E' to a\n \ -python executable."), +Set whether the Python interpreter won't byte-compile python modules."), _("\ +Show whether the Python interpreter won't byte-compile python modules."), _("\ +When enabled GDB's Python interpreter won't byte-compile python modules.\n\ +In order to take effect, this setting must be enabled before python\n\ +initialization."), set_python_dont_write_bytecode, show_python_dont_write_bytecode, &user_set_python_list,