+2012-01-26 Jan Kratochvil <jan.kratochvil@redhat.com>
+
+ Do not open script filenames twice.
+ * cli/cli-cmds.c (source_script_from_stream): Pass to
+ source_python_script also STREAM.
+ * python/py-auto-load.c (source_section_scripts): Pass to
+ source_python_script_for_objfile also STREAM.
+ (auto_load_objfile_script): Pass to source_python_script_for_objfile
+ also INPUT.
+ * python/python-internal.h (source_python_script_for_objfile): New
+ parameter file, rename parameter file to filename.
+ * python/python.c (python_run_simple_file): Call PyRun_SimpleFile
+ instead if !_WIN32. Update the function comment.
+ (source_python_script, source_python_script_for_objfile)
+ (source_python_script): New parameter file, rename parameter file to
+ filename. Pass FILENAME to python_run_simple_file.
+ * python/python.h (source_python_script): New parameter file, rename
+ parameter file to filename.
+
2012-01-26 Pedro Alves <palves@redhat.com>
* corelow.c (core_has_fake_pid): Delete.
return make_cleanup (restore_python_env, env);
}
-/* A wrapper around PyRun_SimpleFile. FILENAME is the name of
- the Python script to run.
-
- One of the parameters of PyRun_SimpleFile is a FILE *.
- The problem is that type FILE is extremely system and compiler
- dependent. So, unless the Python library has been compiled using
- the same build environment as GDB, we run the risk of getting
- a crash due to inconsistencies between the definition used by GDB,
- and the definition used by Python. A mismatch can very likely
- lead to a crash.
-
- There is also the situation where the Python library and GDB
- are using two different versions of the C runtime library.
- This is particularly visible on Windows, where few users would
- build Python themselves (this is no trivial task on this platform),
- and thus use binaries built by someone else instead. Python,
- being built with VC, would use one version of the msvcr DLL
- (Eg. msvcr100.dll), while MinGW uses msvcrt.dll. A FILE *
- from one runtime does not necessarily operate correctly in
+/* A wrapper around PyRun_SimpleFile. FILE is the Python script to run
+ named FILENAME.
+
+ On Windows hosts few users would build Python themselves (this is no
+ trivial task on this platform), and thus use binaries built by
+ someone else instead. There may happen situation where the Python
+ library and GDB are using two different versions of the C runtime
+ library. Python, being built with VC, would use one version of the
+ msvcr DLL (Eg. msvcr100.dll), while MinGW uses msvcrt.dll.
+ A FILE * from one runtime does not necessarily operate correctly in
the other runtime.
- To work around this potential issue, we create the FILE object
- using Python routines, thus making sure that it is compatible
- with the Python library. */
+ To work around this potential issue, we create on Windows hosts the
+ FILE object using Python routines, thus making sure that it is
+ compatible with the Python library. */
static void
-python_run_simple_file (const char *filename)
+python_run_simple_file (FILE *file, const char *filename)
{
+#ifndef _WIN32
+
+ PyRun_SimpleFile (file, filename);
+
+#else /* _WIN32 */
+
char *full_path;
PyObject *python_file;
struct cleanup *cleanup;
make_cleanup_py_decref (python_file);
PyRun_SimpleFile (PyFile_AsFile (python_file), filename);
do_cleanups (cleanup);
+
+#endif /* _WIN32 */
}
/* Given a command_line, return a command string suitable for passing
}
/* Read a file as Python code.
- FILE is the name of the file.
+ FILE is the file to run. FILENAME is name of the file FILE.
This does not throw any errors. If an exception occurs python will print
the traceback and clear the error indicator. */
void
-source_python_script (const char *file)
+source_python_script (FILE *file, const char *filename)
{
struct cleanup *cleanup;
cleanup = ensure_python_env (get_current_arch (), current_language);
- python_run_simple_file (file);
+ python_run_simple_file (file, filename);
do_cleanups (cleanup);
}
source_python_script_for_objfile; it is NULL at other times. */
static struct objfile *gdbpy_current_objfile;
-/* Set the current objfile to OBJFILE and then read FILE as Python code.
- This does not throw any errors. If an exception occurs python will print
- the traceback and clear the error indicator. */
+/* Set the current objfile to OBJFILE and then read FILE named FILENAME
+ as Python code. This does not throw any errors. If an exception
+ occurs python will print the traceback and clear the error indicator. */
void
-source_python_script_for_objfile (struct objfile *objfile, const char *file)
+source_python_script_for_objfile (struct objfile *objfile, FILE *file,
+ const char *filename)
{
struct cleanup *cleanups;
cleanups = ensure_python_env (get_objfile_arch (objfile), current_language);
gdbpy_current_objfile = objfile;
- python_run_simple_file (file);
+ python_run_simple_file (file, filename);
do_cleanups (cleanups);
gdbpy_current_objfile = NULL;
}
void
-source_python_script (const char *file)
+source_python_script (FILE *file, const char *filename)
{
throw_error (UNSUPPORTED_ERROR,
_("Python scripting is not supported in this copy of GDB."));