This is the mail archive of the
gdb-patches@sourceware.org
mailing list for the GDB project.
[python] [patch] PR python/13345
- From: Phil Muldoon <pmuldoon at redhat dot com>
- To: gdb-patches at sourceware dot org
- Date: Mon, 31 Oct 2011 15:51:57 +0000
- Subject: [python] [patch] PR python/13345
- Reply-to: pmuldoon at redhat dot com
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);