Update of /cvsroot/pywin32/pywin32/win32/src
In directory sc8-pr-cvs1:/tmp/cvs-serv333
Modified Files:
PyUnicode.cpp
Log Message:
Avoid blindly casting PyUNICODE to wchar_t - use Python's
PyUnicode_AsWideChar to do the right thing if the types aren't
the same (which it does).
Index: PyUnicode.cpp
===================================================================
RCS file: /cvsroot/pywin32/pywin32/win32/src/PyUnicode.cpp,v
retrieving revision 1.17
retrieving revision 1.18
diff -C2 -d -r1.17 -r1.18
*** PyUnicode.cpp 7 Nov 2003 03:58:17 -0000 1.17
--- PyUnicode.cpp 8 Nov 2003 05:53:50 -0000 1.18
***************
*** 921,926 ****
// copy the value, including embedded NULLs
#if defined(PYWIN_USE_PYUNICODE)
! wchar_t *v = (wchar_t *)PyUnicode_AS_UNICODE(stringObject);
! *pResult = SysAllocStringLen(v, PyUnicode_GET_SIZE(stringObject));
#else
BSTR v = ((PyUnicode *)stringObject)->m_bstrValue;
--- 921,935 ----
// copy the value, including embedded NULLs
#if defined(PYWIN_USE_PYUNICODE)
! int nchars = PyUnicode_GET_SIZE(stringObject);
! *pResult = SysAllocStringLen(NULL, nchars);
! if (*pResult) {
! PyUnicode_AsWideChar((PyUnicodeObject *)stringObject, *pResult, nchars);
! // The SysAllocStringLen docs indicate that nchars+1 bytes are allocated,
! // and that normally a \0 is appened by the function. It also states
! // the \0 is not necessary! While it seems to work fine without it,
! // we do copy it, as the previous code, which used SysAllocStringLen
! // with a non-NULL arg is documented clearly as appending the \0.
! (*pResult)[nchars] = 0;
! }
#else
BSTR v = ((PyUnicode *)stringObject)->m_bstrValue;
|