Bug/patch question, WinNT, Borland C linker, spaces in paths
Hello, There is a bug in distutils that breaks Borland C linker. Distutils tries to pass search paths to the linker as "/LD:/Program Files/samplepath" This causes the linker to bail out with an error message suggesting that the path argument is mistreated as an object file. It seems that the linker expects a different quoting scheme that the one used by distutils. I have done some experimenting and it turns out that: /L"D:/Program Files/samplepath" /LD:/Program" "Files/samplepath are both OK. Unfortunately: /L "D:/Program Files/samplepath" does not work - there should be no whitespace between '/L' and the path, so passing '/L' and the path as separate arguments does not work. The piece of code responsible for the quoting is _nt_quote_args function in spawn.py. The following patch 'fixes' the quoting scheme. This is the output from 'cvs diff spawn.py': Index: spawn.py =================================================================== RCS file: /cvsroot/python/distutils/distutils/spawn.py,v retrieving revision 1.16 diff -r1.16 spawn.py 62,63c62 < if string.find(args[i], ' ') != -1: < args[i] = '"%s"' % args[i] ---
args[i] = args[i].replace(' ','" "')
Instead of putting the whole space-containing argument into quotes, it only quotes spaces. Unfortunately there is no reason for this not to break other compilers. Due to infelicities in WinApi (child process gets the whole command line, not split into arguments) it's up to the compiler/linker to parse the command line and as far as I know there is no standard way of encoding arguments that contain spaces. Now, the questions: 1. Can anyone test the above patch with other compilers? I only have Borland. 2. I think that one 'standard' argument quoting function might not be sufficient. Perhaps _nt_quote_args should be moved into CCompiler class hierarchy? This way every compiler could override the standard quoting function without the risk of breaking other compilers. 3. I have just started looking at the distutils source code and I am not a Python guru, so perhaps there is another simple way to fix this bug? Regards, Rafal Dowgird
Rafal Dowgird wrote:
Hello,
There is a bug in distutils that breaks Borland C linker. Distutils tries to pass search paths to the linker as "/LD:/Program Files/samplepath"
Are you sure that it's worth adding quoting support for paths with embedded spaces to distutils is worth the effort ? I know that spaces in paths of executables and DLLs cause endless problems on Windows and most of these can easily be avoided by installing program files to a non-space-containing path location on the disk.
This causes the linker to bail out with an error message suggesting that the path argument is mistreated as an object file. It seems that the linker expects a different quoting scheme that the one used by distutils. I have done some experimenting and it turns out that:
/L"D:/Program Files/samplepath" /LD:/Program" "Files/samplepath
are both OK. Unfortunately:
/L "D:/Program Files/samplepath"
does not work - there should be no whitespace between '/L' and the path, so passing '/L' and the path as separate arguments does not work.
I think that the first variant is what is accepted as standard on most OSes, however, the second variant seems to be accepted by the Windows command shell as well, so maybe you're right in that this is the way to go. The space between the option and the argument looks like an application level quirk to me.
The piece of code responsible for the quoting is _nt_quote_args function in spawn.py. The following patch 'fixes' the quoting scheme. This is the output from 'cvs diff spawn.py':
Index: spawn.py =================================================================== RCS file: /cvsroot/python/distutils/distutils/spawn.py,v retrieving revision 1.16 diff -r1.16 spawn.py 62,63c62 < if string.find(args[i], ' ') != -1: < args[i] = '"%s"' % args[i] ---
args[i] = args[i].replace(' ','" "')
Please no string methods until after we have released Python 2.3. String methods are not available in Python 1.5.2 which we still support.
Instead of putting the whole space-containing argument into quotes, it only quotes spaces.
Unfortunately there is no reason for this not to break other compilers.
I think that this is a shell related problem, not so much a per program Due to infelicities in WinApi (child process gets the whole
command line, not split into arguments) it's up to the compiler/linker to parse the command line and as far as I know there is no standard way of encoding arguments that contain spaces.
Now, the questions:
1. Can anyone test the above patch with other compilers? I only have Borland.
2. I think that one 'standard' argument quoting function might not be sufficient. Perhaps _nt_quote_args should be moved into CCompiler class hierarchy? This way every compiler could override the standard quoting function without the risk of breaking other compilers.
3. I have just started looking at the distutils source code and I am not a Python guru, so perhaps there is another simple way to fix this bug?
Regards,
Rafal Dowgird
_______________________________________________ Distutils-SIG maillist - Distutils-SIG@python.org http://mail.python.org/mailman/listinfo/distutils-sig
-- Marc-Andre Lemburg CEO eGenix.com Software GmbH _______________________________________________________________________ eGenix.com -- Makers of the Python mx Extensions: mxDateTime,mxODBC,... Python Consulting: http://www.egenix.com/ Python Software: http://www.egenix.com/files/python/
Thanks for the reply.
Are you sure that it's worth adding quoting support for paths with embedded spaces to distutils is worth the effort ?
I know that spaces in paths of executables and DLLs cause endless problems on Windows and most of these can easily be avoided by installing program files to a non-space-containing path location on the disk.
I am far from insisting that this patch should be applied. There are some simpler options that could improve the situation: - documenting it as a known bug with workaround - making distutils print a warning upon encountering a space in an argument What do you think? Of course, ignoring this is also possible.
Please no string methods until after we have released Python 2.3. String methods are not available in Python 1.5.2 which we still support.
Sorry. As I have said, I have little knowledge of Python/distutils. Here is the patch without string methods: Index: spawn.py =================================================================== RCS file: /cvsroot/python/distutils/distutils/spawn.py,v retrieving revision 1.16 diff -r1.16 spawn.py 62,63c62 < if string.find(args[i], ' ') != -1: < args[i] = '"%s"' % args[i] ---
args[i] = string.replace(args[i],' ','" "')
Regards, Rafal Dowgird
Rafal Dowgird schrieb:
Thanks for the reply.
Are you sure that it's worth adding quoting support for paths with embedded spaces to distutils is worth the effort ?
I know that spaces in paths of executables and DLLs cause endless problems on Windows and most of these can easily be avoided by installing program files to a non-space-containing path location on the disk.
I am far from insisting that this patch should be applied. There are some simpler options that could improve the situation:
- documenting it as a known bug with workaround - making distutils print a warning upon encountering a space in an argument
I would suppose the following solution for _nt_quote_args: IF the given string doesn't contain any '"' THEN quote the whole string as usual ELSE leave it as it is. (Reason is: you would split then arguments. eg. a" "b would become "a" "b" ) With this solution all existing code should work as usual. And it is possible for any code using spawn/_nt_quote_args using its own quoting schema. (Which means for bcppcompiler.py fixing the link method.) Kind regards Rene Liebscher
On Tue, 3 Dec 2002, M.-A. Lemburg wrote:
Rafal Dowgird wrote:
Hello,
There is a bug in distutils that breaks Borland C linker. Distutils tries to pass search paths to the linker as "/LD:/Program Files/samplepath"
Are you sure that it's worth adding quoting support for paths with embedded spaces to distutils is worth the effort ?
I know that spaces in paths of executables and DLLs cause endless problems on Windows and most of these can easily be avoided by installing program files to a non-space-containing path location on the disk.
Having battled spaces in user filenames constantly. I have concedeed that no matter how much I despise them, it's better to code assuming that there will _always_ be a space some where in the path. IMHO, it needs to be treated like a user input problem. Whether you want it to happen or not, it will, so code for it. mwa
participants (4)
-
M.-A. Lemburg
-
Mark W. Alexander
-
Rafal Dowgird
-
René Liebscher