[pywin32-checkins] /hgroot/pywin32/pywin32: Move SeqToVector into PythonCOM.h
OLD project page for the Python extensions for Windows
Brought to you by:
mhammond
From: <pyw...@li...> - 2012-08-07 08:25:27
|
changeset aa89dec6e110 in /hgroot/pywin32/pywin32 details: http://pywin32.hg.sourceforge.net/hgweb/pywin32/pywin32/hgroot/pywin32/pywin32?cmd=changeset;node=aa89dec6e110 summary: Move SeqToVector into PythonCOM.h diffstat: com/win32com/src/include/PythonCOM.h | 20 ++++++++++++++++++++ com/win32comext/propsys/src/PyPROPVARIANT.cpp | 21 --------------------- com/win32comext/shell/src/PyIShellItem2.cpp | 21 --------------------- 3 files changed, 20 insertions(+), 42 deletions(-) diffs (90 lines): diff -r a7098757376f -r aa89dec6e110 com/win32com/src/include/PythonCOM.h --- a/com/win32com/src/include/PythonCOM.h Tue Aug 07 00:16:07 2012 -0400 +++ b/com/win32com/src/include/PythonCOM.h Tue Aug 07 04:13:56 2012 -0400 @@ -755,4 +755,24 @@ PYCOM_EXPORT void PyCom_LogF(const char *fmt, ...); +// Generic conversion from python sequence to VT_VECTOR array +// Resulting array must be freed with CoTaskMemFree +template <typename arraytype> +BOOL SeqToVector(PyObject *ob, arraytype **pA, ULONG *pcount, BOOL (*converter)(PyObject *, arraytype *)){ + TmpPyObject seq = PyWinSequence_Tuple(ob, pcount); + if (seq == NULL) + return FALSE; + *pA = (arraytype *)CoTaskMemAlloc(*pcount * sizeof(arraytype)); + if (*pA == NULL){ + PyErr_NoMemory(); + return FALSE; + } + for (ULONG i=0; i<*pcount; i++){ + PyObject *item = PyTuple_GET_ITEM((PyObject *)seq, i); + if (!(*converter)(item, &(*pA)[i])) + return FALSE; + } + return TRUE; +} + #endif // __PYTHONCOM_H__ diff -r a7098757376f -r aa89dec6e110 com/win32comext/propsys/src/PyPROPVARIANT.cpp --- a/com/win32comext/propsys/src/PyPROPVARIANT.cpp Tue Aug 07 00:16:07 2012 -0400 +++ b/com/win32comext/propsys/src/PyPROPVARIANT.cpp Tue Aug 07 04:13:56 2012 -0400 @@ -163,27 +163,6 @@ return PyWinObject_FromPROPVARIANT(&pv); } - -// Generic conversion from python sequence to VT_VECTOR array -template <typename arraytype> -BOOL SeqToVector(PyObject *ob, arraytype **pA, ULONG *pcount, BOOL (*converter)(PyObject *, arraytype *)){ - TmpPyObject seq = PyWinSequence_Tuple(ob, pcount); - if (seq == NULL) - return FALSE; - *pA = (arraytype *)CoTaskMemAlloc(*pcount * sizeof(arraytype)); - if (*pA == NULL){ - PyErr_NoMemory(); - return FALSE; - } - for (ULONG i=0; i<*pcount; i++){ - PyObject *item = PyTuple_GET_ITEM((PyObject *)seq, i); - if (!(*converter)(item, &(*pA)[i])) - return FALSE; - } - return TRUE; -} - - // @pymethod object|PyPROPVARIANT|GetValue|Returns an object representing the variant value PyObject* PyPROPVARIANT::GetValue(PyObject *self, PyObject *args) { diff -r a7098757376f -r aa89dec6e110 com/win32comext/shell/src/PyIShellItem2.cpp --- a/com/win32comext/shell/src/PyIShellItem2.cpp Tue Aug 07 00:16:07 2012 -0400 +++ b/com/win32comext/shell/src/PyIShellItem2.cpp Tue Aug 07 04:13:56 2012 -0400 @@ -82,27 +82,6 @@ return PyCom_PyObjectFromIUnknown((IUnknown *)ret, riid); } - -// ??? Also in PyPROPVARIANT.cpp, should move into a header somewhere ??? -// Generic conversion from python sequence to VT_VECTOR array -template <typename arraytype> -BOOL SeqToVector(PyObject *ob, arraytype **pA, ULONG *pcount, BOOL (*converter)(PyObject *, arraytype *)){ - TmpPyObject seq = PyWinSequence_Tuple(ob, pcount); - if (seq == NULL) - return FALSE; - *pA = (arraytype *)CoTaskMemAlloc(*pcount * sizeof(arraytype)); - if (*pA == NULL){ - PyErr_NoMemory(); - return FALSE; - } - for (ULONG i=0; i<*pcount; i++){ - PyObject *item = PyTuple_GET_ITEM((PyObject *)seq, i); - if (!(*converter)(item, &(*pA)[i])) - return FALSE; - } - return TRUE; -} - // @pymethod <o PyIPropertyStore>|PyIShellItem2|GetPropertyStoreForKeys|Creates a property store containing just the specified properties of the item PyObject *PyIShellItem2::GetPropertyStoreForKeys(PyObject *self, PyObject *args) { |