[Distutils] Possible Distutils shell processing bug
Michael Hudson
mwh@python.net
Mon Jan 14 06:57:01 2002
"Brian Quinlan" <brian@sweetapp.com> writes:
> Hi,
>
> Is it intended that users must escape their own strings, which are
> passed to the shell? As an example, if I wanted to define a string for
> the preprocessor, I would have to do something like this:
>
> defines = [('VERSION',r'\"1.2.3\"')]
>
> If I hadn't escaped the double quotes then the shell would have removed
> them*.
Hang on. Are you sure about this? Consider:
(sorry for the long lines)
[mwh@starship foo]$ cat setup.py
from distutils.core import setup, Extension
setup(ext_modules=[Extension("foo", ["foomodule.c"],
define_macros=[("FOO",'"a"')])])
[mwh@starship foo]$ cat foomodule.c
#include <Python.h>
static PyObject*
foo_func(PyObject* self, PyObject* args)
{
return PyString_FromString(FOO);
}
static PyMethodDef foo_meths[] = {
{ "func", foo_func }
};
void
initfoo()
{
Py_InitModule("foo", foo_meths);
}
[mwh@starship foo]$ python setup.py build_ext
running build_ext
building 'foo' extension
creating build
creating build/temp.linux-i686-2.2
gcc -DNDEBUG -g -O3 -Wall -Wstrict-prototypes -fPIC -DFOO="a" -I/home/crew/mwh/include/python2.2 -c foomodule.c -o build/temp.linux-i686-2.2/foomodule.o
foomodule.c:15: warning: function declaration isn't a prototype
creating build/lib.linux-i686-2.2
gcc -shared build/temp.linux-i686-2.2/foomodule.o -o build/lib.linux-i686-2.2/foo.so
[mwh@starship foo]$ PYTHONPATH=build/lib.linux-i686-2.2 python
Python 2.2c1+ (#1, Dec 26 2001, 21:36:30)
[GCC egcs-2.91.66 19990314/Linux (egcs-1.1.2 release)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import foo
>>> foo.func()
'a'
>>>
What made you think quotes were disappearing?
Cheers,
M.
--
Important data should not be entrusted to Pinstripe, as it may
eat it and make loud belching noises.
-- from the announcement of the beta of "Pinstripe" aka. Redhat 7.0