From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: 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 From: Kevin Buettner To: Pedro Alves Cc: gdb-patches@sourceware.org, Simon Marchi 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-Spam-Status: No, score=-11.4 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_NONE, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org 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: , X-List-Received-Date: Thu, 21 Jul 2022 23:08:43 -0000 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,