[pywin32-checkins] pywin32/win32/src PyUnicode.cpp,1.15,1.16
OLD project page for the Python extensions for Windows
Brought to you by:
mhammond
From: <mha...@us...> - 2003-10-31 04:58:21
|
Update of /cvsroot/pywin32/pywin32/win32/src In directory sc8-pr-cvs1:/tmp/cvs-serv3180 Modified Files: PyUnicode.cpp Log Message: Correct almost every use of MultiByteToWideChar - the last param is the number of wide chars, not bytes. Index: PyUnicode.cpp =================================================================== RCS file: /cvsroot/pywin32/pywin32/win32/src/PyUnicode.cpp,v retrieving revision 1.15 retrieving revision 1.16 diff -C2 -d -r1.15 -r1.16 *** PyUnicode.cpp 6 Apr 2003 23:47:05 -0000 1.15 --- PyUnicode.cpp 31 Oct 2003 04:58:18 -0000 1.16 *************** *** 26,36 **** if (buf==NULL) return FALSE; ! /* compute the max possible size ("size" may contain multi-byte chars) */ ! int wideSize = cch*2; ! ! *ppResult = (LPWSTR)CoTaskMemAlloc(wideSize); if (*ppResult) /* convert and get the final character size */ ! cch = MultiByteToWideChar(CP_ACP, 0, buf, cch, *ppResult, wideSize); if (*ppResult && pResultLen) *pResultLen = cch; } else if (PyUnicode_Check(stringObject)) { --- 26,38 ---- if (buf==NULL) return FALSE; ! /* We assume that we dont need more 'wide characters' for the result ! then the number of bytes in the input. Often we ! will need less, as the input may contain multi-byte chars, but we ! should never need more ! */ ! *ppResult = (LPWSTR)CoTaskMemAlloc(cch*sizeof(WCHAR)); if (*ppResult) /* convert and get the final character size */ ! cch = MultiByteToWideChar(CP_ACP, 0, buf, cch, *ppResult, cch); if (*ppResult && pResultLen) *pResultLen = cch; } else if (PyUnicode_Check(stringObject)) { *************** *** 891,898 **** if (buf==NULL) return FALSE; ! /* compute the max possible size ("size" may contain multi-byte chars) */ ! int wideSize = size*2; ! LPWSTR wstr = (LPWSTR)malloc(wideSize); if (wstr==NULL) { PyErr_SetString(PyExc_MemoryError, "No memory for wide string buffer"); --- 893,903 ---- if (buf==NULL) return FALSE; ! /* We assume that we dont need more 'wide characters' for the result ! then the number of bytes in the input. Often we ! will need less, as the input may contain multi-byte chars, but we ! should never need more ! */ ! LPWSTR wstr = (LPWSTR)malloc(size*sizeof(WCHAR)); if (wstr==NULL) { PyErr_SetString(PyExc_MemoryError, "No memory for wide string buffer"); *************** *** 900,904 **** } /* convert and get the final character size */ ! size = MultiByteToWideChar(CP_ACP, 0, buf, size, wstr, wideSize); *pResult = SysAllocStringLen(wstr, size); if (*pResult==NULL) --- 905,909 ---- } /* convert and get the final character size */ ! size = MultiByteToWideChar(CP_ACP, 0, buf, size, wstr, size); *pResult = SysAllocStringLen(wstr, size); if (*pResult==NULL) *************** *** 963,970 **** if (buf==NULL) return FALSE; ! /* compute the max possible size ("size" may contain multi-byte chars) */ ! int wideSize = size*2; ! ! *pResult = (LPWSTR)PyMem_Malloc(wideSize+sizeof(WCHAR)); if (*pResult==NULL) { PyErr_SetString(PyExc_MemoryError, "No memory for wide string buffer"); --- 968,977 ---- if (buf==NULL) return FALSE; ! /* We assume that we dont need more 'wide characters' for the result ! then the number of bytes in the input. Often we ! will need less, as the input may contain multi-byte chars, but we ! should never need more ! */ ! *pResult = (LPWSTR)PyMem_Malloc((size+1)*sizeof(WCHAR)); if (*pResult==NULL) { PyErr_SetString(PyExc_MemoryError, "No memory for wide string buffer"); *************** *** 972,976 **** } /* convert and get the final character size */ ! resultLen = MultiByteToWideChar(CP_ACP, 0, buf, size, *pResult, wideSize); /* terminate the string */ (*pResult)[resultLen] = L'\0'; --- 979,983 ---- } /* convert and get the final character size */ ! resultLen = MultiByteToWideChar(CP_ACP, 0, buf, size, *pResult, size); /* terminate the string */ (*pResult)[resultLen] = L'\0'; |