[pywin32-checkins] pywin32/com/win32com/src oleargs.cpp,1.22,1.23
OLD project page for the Python extensions for Windows
Brought to you by:
mhammond
From: <mha...@us...> - 2003-10-24 23:26:37
|
Update of /cvsroot/pywin32/pywin32/com/win32com/src In directory sc8-pr-cvs1:/tmp/cvs-serv21753 Modified Files: oleargs.cpp Log Message: If __len__ failed when filling a SafeArray, this exception was left pending, and Python would complain with "XXX - undetected error" Index: oleargs.cpp =================================================================== RCS file: /cvsroot/pywin32/pywin32/com/win32com/src/oleargs.cpp,v retrieving revision 1.22 retrieving revision 1.23 diff -C2 -d -r1.22 -r1.23 *** oleargs.cpp 20 Oct 2003 04:48:26 -0000 1.22 --- oleargs.cpp 24 Oct 2003 04:26:21 -0000 1.23 *************** *** 473,486 **** // Allow arbitary sequences, but not strings or Unicode objects. while (obItemCheck && PySequence_Check(obItemCheck) && !PyString_Check(obItemCheck) && !PyUnicode_Check(obItemCheck)) { ! if (!PyBuffer_Check(obItemCheck) && PySequence_Length(obItemCheck)) { ! PyObject *obSave = obItemCheck; ! obItemCheck = PySequence_GetItem(obItemCheck,0); ! Py_DECREF(obSave); ! if (obItemCheck==NULL) { ! // Says it is a sequence, but getting the item failed. ! // (eg, may be a COM instance that has __getitem__, but fails when attempting) ! // Ignore the error, and pretend it is not a sequence. PyErr_Clear(); break; } } else { --- 473,498 ---- // Allow arbitary sequences, but not strings or Unicode objects. while (obItemCheck && PySequence_Check(obItemCheck) && !PyString_Check(obItemCheck) && !PyUnicode_Check(obItemCheck)) { ! if (!PyBuffer_Check(obItemCheck) ) { ! // We *think* it is a sequence, but may not be. (eg, maybe ! // a COM instance with __len__/__getitem__, but they will fail. ! // In these cases, ignore the error and pretend it is not a sequence. ! int sub_len = PySequence_Length(obItemCheck); ! if (sub_len<0) { // __len__ failed. PyErr_Clear(); break; + } + if (sub_len) { + // The reckon we have at least one item - fetch it. + // XXX - is this really necessary? Isn't __len__ failure + // good enough? + PyObject *obSave = obItemCheck; + obItemCheck = PySequence_GetItem(obItemCheck,0); + + Py_DECREF(obSave); + if (obItemCheck==NULL) { + // getting the item failed. + PyErr_Clear(); + break; + } } } else { |