This is the mail archive of the gdb-patches@sourceware.org mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [RFA 11/11] Change python_run_simple_file to use gdbpy_ref


>>>>> "Pedro" == Pedro Alves <palves@redhat.com> writes:

Pedro> Curious, that means that nobody is building mingw gdb against
Pedro> Python 3 then.

Yeah.

Pedro> I did git blame on that function now, and that point at git commit
Pedro> 4c63965b8, which shows that we used to do the longer path everywhere,
Pedro> and from the git log it sounds like we don't want to go back.

Yes, definitely.  There's an FAQ in the Python documentation about this
exact scenario.

Pedro> So looks like we're back to the original suggestion of hacking the
Pedro> WIN32 condition locally and test against Python 2.  If that works,
Pedro> push it in.

Ok.  Here is the updated patch that worked for me after temporarily
removing the WIN32 condition.

Tom

commit 1f6ef3298d54963cd6c0f84a901f29d91cdd1263
Author: Tom Tromey <tom@tromey.com>
Date:   Sat Nov 12 12:08:17 2016 -0700

    Change python_run_simple_file to use gdbpy_ref
    
    This changes python_run_simple_file to use gdbpy_ref and
    unique_xmalloc_ptr.  Thi fixes a latent bug in this function, where
    the error path previously ran the cleanups and then referred to one of
    the objects just freed.
    
    2016-11-12  Tom Tromey  <tom@tromey.com>
    
    	* python/python.c (python_run_simple_file): Use
    	unique_xmalloc_ptr, gdbpy_ref.

diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index 2525ac7..49c226b 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,5 +1,10 @@
 2016-11-12  Tom Tromey  <tom@tromey.com>
 
+	* python/python.c (python_run_simple_file): Use
+	unique_xmalloc_ptr, gdbpy_ref.
+
+2016-11-12  Tom Tromey  <tom@tromey.com>
+
 	* python/py-prettyprint.c (print_stack_unless_memory_error)
 	(print_string_repr, print_children): Use gdbpy_ref.
 	(dummy_python_frame): New class.
diff --git a/gdb/python/python.c b/gdb/python/python.c
index b1d086c..7a38ca2 100644
--- a/gdb/python/python.c
+++ b/gdb/python/python.c
@@ -349,25 +349,17 @@ python_run_simple_file (FILE *file, const char *filename)
 
 #else /* _WIN32 */
 
-  char *full_path;
-  PyObject *python_file;
-  struct cleanup *cleanup;
-
   /* Because we have a string for a filename, and are using Python to
      open the file, we need to expand any tilde in the path first.  */
-  full_path = tilde_expand (filename);
-  cleanup = make_cleanup (xfree, full_path);
-  python_file = PyFile_FromString (full_path, "r");
-  if (! python_file)
+  gdb::unique_xmalloc_ptr<char> full_path (tilde_expand (filename));
+  gdbpy_ref python_file (PyFile_FromString (full_path.get (), "r"));
+  if (python_file == NULL)
     {
-      do_cleanups (cleanup);
       gdbpy_print_stack ();
-      error (_("Error while opening file: %s"), full_path);
+      error (_("Error while opening file: %s"), full_path.get ());
     }
 
-  make_cleanup_py_decref (python_file);
-  PyRun_SimpleFile (PyFile_AsFile (python_file), filename);
-  do_cleanups (cleanup);
+  PyRun_SimpleFile (PyFile_AsFile (python_file.get ()), filename);
 
 #endif /* _WIN32 */
 }


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]