3535/* Licensed to PSF under a Contributor Agreement. */
3636/* See http://www.python.org/2.4/license for licensing details. */
3737
38- /* TODO: handle unicode command lines? */
39- /* TODO: handle unicode environment? */
40-
4138#include "Python.h"
4239
4340#define WINDOWS_LEAN_AND_MEAN
@@ -272,7 +269,7 @@ gethandle(PyObject* obj, char* name)
272269 PyErr_Clear (); /* FIXME: propagate error? */
273270 return NULL ;
274271 }
275- if (Py_Type (& value ) != & sp_handle_type )
272+ if (Py_Type (value ) != & sp_handle_type )
276273 ret = NULL ;
277274 else
278275 ret = value -> handle ;
@@ -287,7 +284,7 @@ getenvironment(PyObject* environment)
287284 PyObject * out = NULL ;
288285 PyObject * keys ;
289286 PyObject * values ;
290- char * p ;
287+ Py_UNICODE * p ;
291288
292289 /* convert environment dictionary to windows enviroment string */
293290 if (! PyMapping_Check (environment )) {
@@ -303,42 +300,42 @@ getenvironment(PyObject* environment)
303300 if (!keys || !values )
304301 goto error ;
305302
306- out = PyString_FromStringAndSize (NULL , 2048 );
303+ out = PyUnicode_FromUnicode (NULL , 2048 );
307304 if (! out )
308305 goto error ;
309306
310- p = PyString_AS_STRING (out );
307+ p = PyUnicode_AS_UNICODE (out );
311308
312309 for (i = 0 ; i < envsize ; i ++ ) {
313310 int ksize , vsize , totalsize ;
314311 PyObject * key = PyList_GET_ITEM (keys , i );
315312 PyObject * value = PyList_GET_ITEM (values , i );
316313
317- if (! PyString_Check (key ) || ! PyString_Check (value )) {
314+ if (! PyUnicode_Check (key ) || ! PyUnicode_Check (value )) {
318315 PyErr_SetString (PyExc_TypeError ,
319316 "environment can only contain strings" );
320317 goto error ;
321318 }
322- ksize = PyString_GET_SIZE (key );
323- vsize = PyString_GET_SIZE (value );
324- totalsize = (p - PyString_AS_STRING (out )) + ksize + 1 +
319+ ksize = PyUnicode_GET_SIZE (key );
320+ vsize = PyUnicode_GET_SIZE (value );
321+ totalsize = (p - PyUnicode_AS_UNICODE (out )) + ksize + 1 +
325322 vsize + 1 + 1 ;
326- if (totalsize > PyString_GET_SIZE (out )) {
327- int offset = p - PyString_AS_STRING (out );
328- _PyString_Resize (& out , totalsize + 1024 );
329- p = PyString_AS_STRING (out ) + offset ;
323+ if (totalsize > PyUnicode_GET_SIZE (out )) {
324+ int offset = p - PyUnicode_AS_UNICODE (out );
325+ PyUnicode_Resize (& out , totalsize + 1024 );
326+ p = PyUnicode_AS_UNICODE (out ) + offset ;
330327 }
331- memcpy (p , PyString_AS_STRING (key ), ksize );
328+ Py_UNICODE_COPY (p , PyUnicode_AS_UNICODE (key ), ksize );
332329 p += ksize ;
333330 * p ++ = '=' ;
334- memcpy (p , PyString_AS_STRING (value ), vsize );
331+ Py_UNICODE_COPY (p , PyUnicode_AS_UNICODE (value ), vsize );
335332 p += vsize ;
336333 * p ++ = '\0' ;
337334 }
338335
339336 /* add trailing null byte */
340337 * p ++ = '\0' ;
341- _PyString_Resize (& out , p - PyString_AS_STRING (out ));
338+ PyUnicode_Resize (& out , p - PyUnicode_AS_UNICODE (out ));
342339
343340 /* PyObject_Print(out, stdout, 0); */
344341
@@ -359,20 +356,20 @@ sp_CreateProcess(PyObject* self, PyObject* args)
359356{
360357 BOOL result ;
361358 PROCESS_INFORMATION pi ;
362- STARTUPINFO si ;
359+ STARTUPINFOW si ;
363360 PyObject * environment ;
364361
365- char * application_name ;
366- char * command_line ;
362+ Py_UNICODE * application_name ;
363+ Py_UNICODE * command_line ;
367364 PyObject * process_attributes ; /* ignored */
368365 PyObject * thread_attributes ; /* ignored */
369366 int inherit_handles ;
370367 int creation_flags ;
371368 PyObject * env_mapping ;
372- char * current_directory ;
369+ Py_UNICODE * current_directory ;
373370 PyObject * startup_info ;
374371
375- if (! PyArg_ParseTuple (args , "zzOOiiOzO :CreateProcess" ,
372+ if (! PyArg_ParseTuple (args , "ZZOOiiOZO :CreateProcess" ,
376373 & application_name ,
377374 & command_line ,
378375 & process_attributes ,
@@ -406,13 +403,13 @@ sp_CreateProcess(PyObject* self, PyObject* args)
406403 }
407404
408405 Py_BEGIN_ALLOW_THREADS
409- result = CreateProcess (application_name ,
406+ result = CreateProcessW (application_name ,
410407 command_line ,
411408 NULL ,
412409 NULL ,
413410 inherit_handles ,
414- creation_flags ,
415- environment ? PyString_AS_STRING (environment ) : NULL ,
411+ creation_flags | CREATE_UNICODE_ENVIRONMENT ,
412+ environment ? PyUnicode_AS_UNICODE (environment ) : NULL ,
416413 current_directory ,
417414 & si ,
418415 & pi );
@@ -504,18 +501,18 @@ sp_GetModuleFileName(PyObject* self, PyObject* args)
504501{
505502 BOOL result ;
506503 long module ;
507- TCHAR filename [MAX_PATH ];
504+ WCHAR filename [MAX_PATH ];
508505
509506 if (! PyArg_ParseTuple (args , "l:GetModuleFileName" , & module ))
510507 return NULL ;
511508
512- result = GetModuleFileName ((HMODULE )module , filename , MAX_PATH );
509+ result = GetModuleFileNameW ((HMODULE )module , filename , MAX_PATH );
513510 filename [MAX_PATH - 1 ] = '\0' ;
514511
515512 if (! result )
516513 return PyErr_SetFromWindowsErr (GetLastError ());
517514
518- return PyString_FromString (filename );
515+ return PyUnicode_FromUnicode (filename , Py_UNICODE_strlen ( filename ) );
519516}
520517
521518static PyMethodDef sp_functions [] = {
0 commit comments