public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
* [PATCH] set/show python dont-write-bytecode fixes
@ 2022-07-20 19:14 Kevin Buettner
  2022-07-21 17:55 ` Pedro Alves
  0 siblings, 1 reply; 8+ messages in thread
From: Kevin Buettner @ 2022-07-20 19:14 UTC (permalink / raw)
  To: gdb-patches; +Cc: Kevin Buettner, Simon Marchi

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


^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2022-07-24  5:41 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-07-20 19:14 [PATCH] set/show python dont-write-bytecode fixes Kevin Buettner
2022-07-21 17:55 ` Pedro Alves
2022-07-21 23:08   ` Kevin Buettner
2022-07-22  6:40     ` Eli Zaretskii
2022-07-23  1:37       ` Kevin Buettner
2022-07-23  6:54         ` Eli Zaretskii
2022-07-23 21:30           ` Kevin Buettner
2022-07-24  5:41             ` Eli Zaretskii

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).