[Distutils] Bug/patch question, WinNT, Borland C linker, spaces in paths

M.-A. Lemburg mal@lemburg.com
Tue Dec 3 05:46:13 2002


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/