[Python-Dev] adding Py{String|Unicode}_{Lower|Upper} and fixing CreateProcess in _subprocess.pyd and PyWin32

Trent Mick trentm at ActiveState.com
Wed Oct 27 04:05:42 CEST 2004

There is a subtlety in CreateProcess in the Win32 API in that if one 
specifies an environment (via the lpEnvironment argument), the 
environment strings (A) must be sorted alphabetically and (B) that sort 
must be case-insensitive. See the Remarks section on:

If this is not done, then surprises can happen with the use of 
{Get|Set}EnvironmentVariable in the created process:

Neither _subprocess.pyd (supporting the new subprocess.py module on 
Windows) nor PyWin32's CreateProcess binding do this. I haven't done so 
yet, but I should be able to put together a test case for subprocess.py 
for this. We came across such a surprise when using my process.py module 
that uses this PyWin32 code (which it looks like _subprocess.c borrowed).

Fixing (A) is easy with a "PyList_Sort(keys)" and some other minor 
changes to _subprocess.c::getenvironment() -- and to 
win32process.i::CreateEnvironmentString() in PyWin32.

However, I'd like some guidance on the best way to case-insensitively 
sort a Python list in C code to fix (B). The best thing I see would be 
to expose PyString_Lower/PyUnicode_Lower and/or 
PyString_Upper/PyUnicode_Upper so they can be used to .lower()/.upper() 
the given environment mapping keys for sorting.

Does that sound reasonable? Is there some problem to this approach that 
anyone can see?


Trent Mick
trentm at activestate.com

More information about the Python-Dev mailing list