Update of /cvsroot/pywin32/pywin32/win32/src
In directory sc8-pr-cvs1:/tmp/cvs-serv8086
Modified Files:
PyWinTypes.h PyUnicode.cpp
Log Message:
PyWinObject_AsTaskAllocatedWCHAR did not NULL terminate the strings.
Abstract this function to take a function pointer to perform the
allocation, so other allocators can be used (which the shell does)
Index: PyWinTypes.h
===================================================================
RCS file: /cvsroot/pywin32/pywin32/win32/src/PyWinTypes.h,v
retrieving revision 1.17
retrieving revision 1.18
diff -C2 -d -r1.17 -r1.18
*** PyWinTypes.h 7 Nov 2003 03:58:17 -0000 1.17
--- PyWinTypes.h 24 Nov 2003 09:13:11 -0000 1.18
***************
*** 171,174 ****
--- 171,181 ----
#ifndef MS_WINCE
+ // String support for buffers allocated via a function of your choice.
+ PYWINTYPES_EXPORT PyWinObject_AsPfnAllocatedWCHAR(PyObject *stringObject,
+ void *(*pfnAllocator)(ULONG),
+ WCHAR **ppResult,
+ BOOL bNoneOK = FALSE,
+ DWORD *pResultLen = NULL);
+
// String support for buffers allocated via CoTaskMemAlloc and CoTaskMemFree
PYWINTYPES_EXPORT BOOL PyWinObject_AsTaskAllocatedWCHAR(PyObject *stringObject, WCHAR **ppResult, BOOL bNoneOK /*= FALSE*/,DWORD *pResultLen /*= NULL*/);
Index: PyUnicode.cpp
===================================================================
RCS file: /cvsroot/pywin32/pywin32/win32/src/PyUnicode.cpp,v
retrieving revision 1.18
retrieving revision 1.19
diff -C2 -d -r1.18 -r1.19
*** PyUnicode.cpp 8 Nov 2003 05:53:50 -0000 1.18
--- PyUnicode.cpp 24 Nov 2003 09:13:11 -0000 1.19
***************
*** 16,20 ****
#ifndef MS_WINCE
! BOOL PyWinObject_AsTaskAllocatedWCHAR(PyObject *stringObject, WCHAR **ppResult, BOOL bNoneOK /*= FALSE*/,DWORD *pResultLen /*= NULL*/)
{
BOOL rc = TRUE;
--- 16,20 ----
#ifndef MS_WINCE
! BOOL PyWinObject_AsPfnAllocatedWCHAR(PyObject *stringObject, void *(*pfnAllocator)(ULONG), WCHAR **ppResult, BOOL bNoneOK /*= FALSE*/,DWORD *pResultLen /*= NULL*/)
{
BOOL rc = TRUE;
***************
*** 29,36 ****
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)) {
--- 29,36 ----
should never need more
*/
! *ppResult = (LPWSTR)(*pfnAllocator)((cch+1)*sizeof(WCHAR));
if (*ppResult)
/* convert and get the final character size */
! cch = MultiByteToWideChar(CP_ACP, 0, buf, cch+1, *ppResult, cch+1);
if (*ppResult && pResultLen) *pResultLen = cch;
} else if (PyUnicode_Check(stringObject)) {
***************
*** 43,49 ****
UINT cch = SysStringLen(v);
#endif
! *ppResult = (WCHAR *)CoTaskMemAlloc(cch * sizeof(WCHAR));
if (*ppResult)
! memcpy(*ppResult, v, cch * sizeof(WCHAR));
if (*ppResult && pResultLen) *pResultLen = cch;
--- 43,49 ----
UINT cch = SysStringLen(v);
#endif
! *ppResult = (WCHAR *)pfnAllocator((cch+1) * sizeof(WCHAR));
if (*ppResult)
! memcpy(*ppResult, v, (cch+1) * sizeof(WCHAR));
if (*ppResult && pResultLen) *pResultLen = cch;
***************
*** 61,68 ****
}
if (rc && !ppResult) {
! PyErr_SetString(PyExc_MemoryError, "Allocating WCHAR via CoTaskMemAlloc");
return FALSE;
}
return rc;
}
--- 61,79 ----
}
if (rc && !ppResult) {
! PyErr_SetString(PyExc_MemoryError, "Allocating WCHAR");
return FALSE;
}
return rc;
+ }
+
+ // Get around calling conversion issues.
+ void *AllocViaCoTaskMemAlloc(ULONG cb)
+ {
+ return CoTaskMemAlloc(cb);
+ }
+
+ BOOL PyWinObject_AsTaskAllocatedWCHAR(PyObject *stringObject, WCHAR **ppResult, BOOL bNoneOK /*= FALSE*/,DWORD *pResultLen /*= NULL*/)
+ {
+ return PyWinObject_AsPfnAllocatedWCHAR(stringObject, AllocViaCoTaskMemAlloc, ppResult, bNoneOK, pResultLen);
}
|