[pywin32-checkins] pywin32/win32/src PyUnicode.cpp, 1.21, 1.22 PyWinTypes.h, 1.35, 1.36
OLD project page for the Python extensions for Windows
Brought to you by:
mhammond
From: Roger U. <ru...@us...> - 2007-03-14 04:29:36
|
Update of /cvsroot/pywin32/pywin32/win32/src In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv5944/win32/src Modified Files: PyUnicode.cpp PyWinTypes.h Log Message: Move function to convert consecutive strings into pywintypes Index: PyUnicode.cpp =================================================================== RCS file: /cvsroot/pywin32/pywin32/win32/src/PyUnicode.cpp,v retrieving revision 1.21 retrieving revision 1.22 diff -C2 -d -r1.21 -r1.22 *** PyUnicode.cpp 4 Jul 2005 05:39:03 -0000 1.21 --- PyUnicode.cpp 14 Mar 2007 04:29:35 -0000 1.22 *************** *** 1030,1031 **** --- 1030,1088 ---- PyMem_Free(str); } + + // Converts a series of consecutive null terminated strings into a list + // Note that a read overflow can result if the input is not properly terminated with an extra NULL. + // Should probably also add a counted version, as win32api uses for REG_MULTI_SZ + PyObject *PyWinObject_FromMultipleString(WCHAR *multistring) + { + PyObject *obelement, *ret=NULL; + int elementlen; + if (multistring==NULL){ + Py_INCREF(Py_None); + return Py_None; + } + ret=PyList_New(0); + if (ret==NULL) + return NULL; + elementlen=wcslen(multistring); + do{ + obelement=PyWinObject_FromWCHAR(multistring, elementlen); + if ((obelement==NULL)||(PyList_Append(ret,obelement)==-1)){ + Py_XDECREF(obelement); + Py_DECREF(ret); + return NULL; + } + Py_DECREF(obelement); + multistring+=elementlen+1; + elementlen=wcslen(multistring); + } + while (elementlen>0); + return ret; + } + + PyObject *PyWinObject_FromMultipleString(char *multistring) + { + PyObject *obelement, *ret=NULL; + int elementlen; + if (multistring==NULL){ + Py_INCREF(Py_None); + return Py_None; + } + ret=PyList_New(0); + if (ret==NULL) + return NULL; + elementlen=strlen(multistring); + do{ + obelement=PyString_FromStringAndSize(multistring, elementlen); + if ((obelement==NULL)||(PyList_Append(ret,obelement)==-1)){ + Py_XDECREF(obelement); + Py_DECREF(ret); + return NULL; + } + Py_DECREF(obelement); + multistring+=elementlen+1; + elementlen=strlen(multistring); + } + while (elementlen>0); + return ret; + } Index: PyWinTypes.h =================================================================== RCS file: /cvsroot/pywin32/pywin32/win32/src/PyWinTypes.h,v retrieving revision 1.35 retrieving revision 1.36 diff -C2 -d -r1.35 -r1.36 *** PyWinTypes.h 1 Mar 2007 00:21:16 -0000 1.35 --- PyWinTypes.h 14 Mar 2007 04:29:35 -0000 1.36 *************** *** 174,177 **** --- 174,181 ---- #define PyWinObject_FromWCHAR PyWinObject_FromOLECHAR + // Converts a series of consecutive null terminated strings into a list + PYWINTYPES_EXPORT PyObject *PyWinObject_FromMultipleString(WCHAR *multistring); + PYWINTYPES_EXPORT PyObject *PyWinObject_FromMultipleString(char *multistring); + PYWINTYPES_EXPORT PyObject *PyString_FromUnicode( const OLECHAR *str ); PYWINTYPES_EXPORT PyObject *PyUnicodeObject_FromString(const char *string); |