Re: [patch] Do not open Python scripts twice #2 [Re: [RFC] Crash sourcing Python script on Windows]

Doug Evans
2012-01-23T22:00:14Z

On Mon, Jan 23, 2012 at 1:08 PM, Jan Kratochvil
<jan.kratochvil@redhat.com> wrote:
> On Mon, 23 Jan 2012 19:38:34 +0100, Pedro Alves wrote:
>> > +# MS-Windows platform may have Python compiled with different libc
>> > +# having the FILE structure layout incompatible between libraries.
>>
>> It is not just about the layout.  The layout of both libc's could be the
>> same, but you'd still (maybe) crash.  It's more about the private global
>> state maintained by each of the libc's.  E.g., file descriptor N of
>> gdb's libc has no meaning the python's libc -- each libc has its own
>> file descriptor table.
>
> I have updated the text.
>
>
>> This is undefined behavior in the supposedly crashing case.  Hopefully this
>> doesn't happen to succeed by running some other random program.  :-)
>
> Yes, my fear is that if for example the only problem is fd assignments it may
> try to read from a closed descriptor possibly behaving as empty file and it
> would falsely pass.  Better test would be it did really read some test Python
> code but a minimal such testcase looks pretty complicated to me for configure.
> But when Joel was talking about "crash" this simple test may be enough.
>
>
>> The patch looks good to me.
>
> These are the reasons why I would prefer a real MS-Windows test of it.
>
>
> Thanks,
> Jan
>
>
> gdb/
> 2012-01-23  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.
>        * config.in: Regenerate.
>        * configure: Regenerate.
>        * configure.ac (HAVE_PYTHON_FILEP_COMPAT): New test.
>        * 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 HAVE_PYTHON_FILEP_COMPAT.
>        (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.

Hi.
Do you have any data that shows there is a problem with the double opening?
[I'm kinda uncomfortable with this patch, as is.]