Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
* [python] [patch] PR python/13345
@ 2011-10-31 18:11 Phil Muldoon
  2011-11-01 14:07 ` Meador Inge
  2011-11-01 18:55 ` Tom Tromey
  0 siblings, 2 replies; 6+ messages in thread
From: Phil Muldoon @ 2011-10-31 18:11 UTC (permalink / raw)
  To: gdb-patches


This patch fixes a case where the tilde (~) command was being passed to
Python via the "source" command.  Python does not understand what to do
with a tilde, so we have to expand it first.

OK?

Cheers,

Phil

--

2011-10-31  Phil Muldoon  <pmuldoon@redhat.com>

	PR Python/13345

	* python/python.c (python_run_simple_file): Expand tilde in path.

--

Index: python/python.c
===================================================================
RCS file: /cvs/src/src/gdb/python/python.c,v
retrieving revision 1.75
diff -u -r1.75 python.c
--- python/python.c	7 Oct 2011 07:38:30 -0000	1.75
+++ python/python.c	31 Oct 2011 15:42:19 -0000
@@ -30,6 +30,7 @@
 #include "exceptions.h"
 #include "event-loop.h"
 #include "serial.h"
+#include "readline/tilde.h"
 #include "python.h"
 
 #include <ctype.h>
@@ -162,13 +163,22 @@
 static void
 python_run_simple_file (const char *filename)
 {
-  char *filename_copy;
+  char *full_path;
   PyObject *python_file;
   struct cleanup *cleanup;
 
-  filename_copy = xstrdup (filename);
-  cleanup = make_cleanup (xfree, filename_copy);
-  python_file = PyFile_FromString (filename_copy, "r");
+  /* 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)
+    {
+      do_cleanups (cleanup);
+      gdbpy_print_stack ();
+      error (_("Error sourcing Python file"));
+    }
+ 
   make_cleanup_py_decref (python_file);
   PyRun_SimpleFile (PyFile_AsFile (python_file), filename);
   do_cleanups (cleanup);


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

end of thread, other threads:[~2011-11-01 18:55 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-10-31 18:11 [python] [patch] PR python/13345 Phil Muldoon
2011-11-01 14:07 ` Meador Inge
2011-11-01 14:15   ` Phil Muldoon
2011-11-01 18:06     ` Meador Inge
2011-11-01 17:53   ` Tom Tromey
2011-11-01 18:55 ` Tom Tromey

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox