From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id CCrRAYVU2GJgRhcAWB0awg (envelope-from ) for ; Wed, 20 Jul 2022 15:16:21 -0400 Received: by simark.ca (Postfix, from userid 112) id 0511D1E5EA; Wed, 20 Jul 2022 15:16:21 -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=gNj9dkS2; 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=-2.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RDNS_DYNAMIC,URIBL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.6 Received: from sourceware.org (ip-8-43-85-97.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 949381E21F for ; Wed, 20 Jul 2022 15:16:20 -0400 (EDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 38AD03858C00 for ; Wed, 20 Jul 2022 19:16:18 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 38AD03858C00 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1658344578; bh=ZQHzIc3Fe3kLmCKr5IVP5OQMUZrda56Y0foQ3NKXGaU=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:Cc:From; b=gNj9dkS23eN8dMmEN0nAZr9a3zXmYXzTcPzsscaJVMJJltXrpVLPvCe5LNL/Rya+h RapLFK6W4wPTo365XAp4fbmslVJVOmnufycnx/SdTtjtQTHU5TKllu3fPqOmbbtQq0 oepZiT2hBetsOmxR1H7UpulycXZhH3tMlPvVYmac= 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 676EF3858D28 for ; Wed, 20 Jul 2022 19:15:57 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 676EF3858D28 Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-556-nbFCm6fSMUeiJs9plNBn2w-1; Wed, 20 Jul 2022 15:15:48 -0400 X-MC-Unique: nbFCm6fSMUeiJs9plNBn2w-1 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 04D1C185A794; Wed, 20 Jul 2022 19:15:48 +0000 (UTC) Received: from f36-1.lan (unknown [10.2.16.60]) by smtp.corp.redhat.com (Postfix) with ESMTP id 6C5541121314; Wed, 20 Jul 2022 19:15:47 +0000 (UTC) To: gdb-patches@sourceware.org Subject: [PATCH] set/show python dont-write-bytecode fixes Date: Wed, 20 Jul 2022 12:14:48 -0700 Message-Id: <20220720191447.1014407-1-kevinb@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.78 on 10.11.54.3 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset="US-ASCII"; x-default=true 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 Errors-To: gdb-patches-bounces+public-inbox=simark.ca@sourceware.org Sender: "Gdb-patches" 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 c719e3dc90c..2b85bbb6301 100644 --- a/gdb/python/python.c +++ b/gdb/python/python.c @@ -1865,8 +1865,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; @@ -2341,11 +2348,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\ +intialization."), set_python_dont_write_bytecode, show_python_dont_write_bytecode, &user_set_python_list, -- 2.36.1