[Distutils] _spawn_posix fails, command line works??

Rene Liebscher R.Liebscher@gmx.de
Thu Jan 24 04:11:39 2002


"John J. Lee" wrote:
> 
> This is so bizarre I think it has to be something I'm doing wrong, but
> here goes:
> 
> Having some trouble linking something on Windows, I tried moving back to
> linux to see if I could get it working in distutils there first. The
> actual compilation was working fine on Windows (mingw32).  So, back on
> linux:
> 
> $ ./setup.py build
> [...usual stuff...]
> gcc -g -O2 -Wall -Wstrict-prototypes -fPIC -DHAVE_CONFIG_H=1 -DLOCALEDIR=\"\" -DGNULOCALEDIR=\"\" -DLOCALE_ALIAS_PATH=\"\" -Iwin -Iwin/src -Iwin/lib -Iwin/intl -I/usr/lib/glib/include -c win/src/argmatch.c -o build/temp.linux-i586-2.1/argmatch.o
> win/src/argmatch.c:0: unterminated string or character constant
> win/src/argmatch.c:0: possible real start of unterminated constant
> win/src/argmatch.c:0: unterminated string or character constant
> win/src/argmatch.c:0: possible real start of unterminated constant
> win/src/argmatch.c:0: unterminated string or character constant
> win/src/argmatch.c:0: possible real start of unterminated constant
> error: command 'gcc' failed with exit status 1
> 
> This file is the first one it attempted to compile.
> 
> OK, I thought, clearly I've messed up the line endings or something.
> However, to cut the longer story short, if you cut and paste the command
> distutils claims to be executing (in distutils.spawn._spawn_posix, I
> guess) onto the command line, it works fine!
> 
> Looking at argmatch.c, of course, reveals nothing amiss.  Line 0 is
> the first line of a multi-line comment.
> 
> Still, I can't really bring myself to believe that there is something
> wrong with _spawn_posix; at least, not enough to try to 'debug' it.
> 
> Is this problem my fault, or distutils'?
> 
> Just to make clear: I'm not doing any poking around in distutils'
> internals in my setup.py: it's just a perfectly standard set of
> Extension() instances, and a couple of static libs, and the only distutils
> function I call is setup itself.
> 
> John

I think the problem is related to the quoting of 
-DLOCALEDIR=\"\" -DGNULOCALEDIR=\"\" -DLOCALE_ALIAS_PATH=\"\"
gcc first processes these defines (preprocessor!), so it is line 0 of
the input file. 
(First line of the file should be get the number 1.)

You can simply show this:

Create a file x.c:
---------------
char x[]=FOO;
---------------

Directly typed at the shell
$ gcc -E -DFOO=\"\" x.c
# 1 "x.c"
char x[]= "" ;

The quoting what distutils seems to use:
$ gcc -E '-DFOO=\"\"' x.c
x.c:0: unterminated string or character constant
x.c:0: possible real start of unterminated constant
# 1 "x.c"
char x[]=FOO;

The problem must be here the different quoting behavior of distutils for
Unix or Windows.
(Distutils uses os.execpv and os.spawn here, parameters without ' ' go
unquoted to these 
commands in both cases [file spawn.py]. So these Python functions should
be checked too.)
(Or there is a difference in the shells or how gcc processes command
line parameters.)

Maybe someone else can investigate this further. (because I have the
next weeks not much
time for it.)


Kind regards
Rene Liebscher