[pywin32-checkins] /hgroot/pywin32/pywin32: Fix a couple of places where BSTR used ...
OLD project page for the Python extensions for Windows
Brought to you by:
mhammond
From: <pyw...@li...> - 2012-08-20 06:28:21
|
changeset 54ec13f605a5 in /hgroot/pywin32/pywin32 details: http://pywin32.hg.sourceforge.net/hgweb/pywin32/pywin32/hgroot/pywin32/pywin32?cmd=changeset;node=54ec13f605a5 summary: Fix a couple of places where BSTR used for WCHAR, and fix error cleanup logic diffstat: com/win32comext/shell/src/PyIShellFolder.cpp | 97 +++++++++++++-------------- 1 files changed, 47 insertions(+), 50 deletions(-) diffs (169 lines): diff -r 757d893bb5c0 -r 54ec13f605a5 com/win32comext/shell/src/PyIShellFolder.cpp --- a/com/win32comext/shell/src/PyIShellFolder.cpp Sun Aug 19 23:18:55 2012 -0400 +++ b/com/win32comext/shell/src/PyIShellFolder.cpp Mon Aug 20 02:23:41 2012 -0400 @@ -36,36 +36,34 @@ return NULL; // @pyparm <o PyHANDLE>|hwndOwner||Window in which to display any dialogs or message boxes, can be 0 // @pyparm <o PyIBindCtx>|pbc||Bind context that affects how parsing is performed, can be None - // @pyparm <o PyUNICODE>|DisplayName||Display name to parse, format is dependent on the shell folder. + // @pyparm str|DisplayName||Display name to parse, format is dependent on the shell folder. // Desktop folder will accept a file path, as well as guids of the form ::{guid} // Example: '::%s\\::%s' %(shell.CLSID_MyComputer,shell.CLSID_ControlPanel) // @pyparm int|Attributes|0|Combination of shellcon.SFGAO_* constants specifying which attributes should be returned - PyObject *obpbcReserved; - PyObject *oblpszDisplayName; + PyObject *obpbc; + PyObject *obDisplayName; HWND hwndOwner; PyObject *obhwndOwner; - IBindCtx * pbcReserved; - LPOLESTR lpszDisplayName; + IBindCtx * pbc; + TmpWCHAR DisplayName; ULONG pchEaten = (ULONG)-1; ITEMIDLIST *ppidl; - ULONG pdwAttributes = 0; - if ( !PyArg_ParseTuple(args, "OOO|k:ParseDisplayName", &obhwndOwner, &obpbcReserved, - &oblpszDisplayName, &pdwAttributes) ) + ULONG dwAttributes = 0; + if ( !PyArg_ParseTuple(args, "OOO|k:ParseDisplayName", &obhwndOwner, &obpbc, + &obDisplayName, &dwAttributes) ) return NULL; if (!PyWinObject_AsHANDLE(obhwndOwner, (HANDLE *)&hwndOwner)) return NULL; - BOOL bPythonIsHappy = TRUE; - if (bPythonIsHappy && !PyCom_InterfaceFromPyInstanceOrObject(obpbcReserved, IID_IBindCtx, (void **)&pbcReserved, TRUE /* bNoneOK */)) - bPythonIsHappy = FALSE; - if (bPythonIsHappy && !PyWinObject_AsBstr(oblpszDisplayName, &lpszDisplayName)) bPythonIsHappy = FALSE; - if (!bPythonIsHappy) return NULL; + if (!PyWinObject_AsWCHAR(obDisplayName, &DisplayName)) + return NULL; + if (!PyCom_InterfaceFromPyInstanceOrObject(obpbc, IID_IBindCtx, (void **)&pbc, TRUE /* bNoneOK */)) + return NULL; + HRESULT hr; PY_INTERFACE_PRECALL; - hr = pISF->ParseDisplayName(hwndOwner, pbcReserved, lpszDisplayName, &pchEaten, - &ppidl, &pdwAttributes ); - if (pbcReserved) pbcReserved->Release(); - SysFreeString(lpszDisplayName); - + hr = pISF->ParseDisplayName(hwndOwner, pbc, DisplayName, &pchEaten, + &ppidl, &dwAttributes ); + if (pbc) pbc->Release(); PY_INTERFACE_POSTCALL; if ( FAILED(hr) ) @@ -73,7 +71,7 @@ PyObject *obppidl; obppidl = PyObject_FromPIDL(ppidl, TRUE); - PyObject *pyretval = Py_BuildValue("lOl", pchEaten, obppidl, pdwAttributes); + PyObject *pyretval = Py_BuildValue("lOl", pchEaten, obppidl, dwAttributes); Py_XDECREF(obppidl); return pyretval; } @@ -125,12 +123,15 @@ void * out; if ( !PyArg_ParseTuple(args, "OOO:BindToObject", &obpidl, &obpbcReserved, &obriid) ) return NULL; - BOOL bPythonIsHappy = TRUE; - if (bPythonIsHappy && !PyObject_AsPIDL(obpidl, &pidl)) bPythonIsHappy = FALSE; - if (bPythonIsHappy && !PyCom_InterfaceFromPyInstanceOrObject(obpbcReserved, IID_IBindCtx, (void **)&pbcReserved, TRUE /* bNoneOK */)) - bPythonIsHappy = FALSE; - if (!PyWinObject_AsIID(obriid, &riid)) bPythonIsHappy = FALSE; - if (!bPythonIsHappy) return NULL; // this could leak the pidl + if (!PyWinObject_AsIID(obriid, &riid)) + return NULL; + if (!PyObject_AsPIDL(obpidl, &pidl)) + return NULL; + if (!PyCom_InterfaceFromPyInstanceOrObject(obpbcReserved, IID_IBindCtx, (void **)&pbcReserved, TRUE /* bNoneOK */)){ + PyObject_FreePIDL(pidl); + return NULL; + } + HRESULT hr; PY_INTERFACE_PRECALL; hr = pISF->BindToObject( pidl, pbcReserved, riid, &out ); @@ -250,9 +251,8 @@ return NULL; if (!PyWinObject_AsHANDLE(obhwndOwner, (HANDLE *)&hwndOwner)) return NULL; - BOOL bPythonIsHappy = TRUE; - if (!PyWinObject_AsIID(obriid, &riid)) bPythonIsHappy = FALSE; - if (!bPythonIsHappy) return NULL; + if (!PyWinObject_AsIID(obriid, &riid)) + return NULL; HRESULT hr; PY_INTERFACE_PRECALL; hr = pISF->CreateViewObject( hwndOwner, riid, &out ); @@ -280,9 +280,9 @@ ULONG rgfInOut; if ( !PyArg_ParseTuple(args, "Ol:GetAttributesOf", &obpidl, &rgfInOut) ) return NULL; - BOOL bPythonIsHappy = TRUE; - if (bPythonIsHappy && !PyObject_AsPIDLArray(obpidl, &cidl, &pidl)) bPythonIsHappy = FALSE; - if (!bPythonIsHappy) return NULL; + + if (!PyObject_AsPIDLArray(obpidl, &cidl, &pidl)) + return NULL; HRESULT hr; PY_INTERFACE_PRECALL; hr = pISF->GetAttributesOf( cidl, pidl, &rgfInOut ); @@ -383,40 +383,37 @@ return NULL; // @pyparm HWND|hwndOwner||Window in which to display any message boxes or dialogs, can be 0 // @pyparm <o PyIDL>|pidl||PIDL that identifies the item relative to the parent folder - // @pyparm <o unicode>|lpszName||New name for the item + // @pyparm str|Name||New name for the item // @pyparm int|Flags||Combination of shellcon.SHGDM_* values PyObject *obpidl=NULL, *ret=NULL; - PyObject *oblpszName=NULL; + PyObject *obName=NULL; PyObject *obhwndOwner; HWND hwndOwner; ITEMIDLIST *pidl=NULL; ITEMIDLIST *pidlRet = NULL; - LPOLESTR lpszName=NULL; + TmpWCHAR Name; DWORD flags; - if ( !PyArg_ParseTuple(args, "OOOl:SetNameOf", &obhwndOwner, &obpidl, &oblpszName, &flags) ) + if ( !PyArg_ParseTuple(args, "OOOl:SetNameOf", &obhwndOwner, &obpidl, &obName, &flags) ) return NULL; if (!PyWinObject_AsHANDLE(obhwndOwner, (HANDLE *)&hwndOwner)) return NULL; + if (!PyWinObject_AsWCHAR(obName, &Name)) + return NULL; + if (!PyObject_AsPIDL(obpidl, &pidl)) + return NULL; - if (PyObject_AsPIDL(obpidl, &pidl)&& - PyWinObject_AsBstr(oblpszName, &lpszName)){ - HRESULT hr; - PY_INTERFACE_PRECALL; - hr = pISF->SetNameOf( hwndOwner, pidl, lpszName, (SHGDNF)flags, &pidlRet ); - PY_INTERFACE_POSTCALL; - if ( FAILED(hr) ) - PyCom_BuildPyException(hr, pISF, IID_IShellFolder ); - else - ret = PyObject_FromPIDL(pidlRet, TRUE); - } - + HRESULT hr; + PY_INTERFACE_PRECALL; + hr = pISF->SetNameOf( hwndOwner, pidl, Name, (SHGDNF)flags, &pidlRet ); + PY_INTERFACE_POSTCALL; PyObject_FreePIDL(pidl); - SysFreeString(lpszName); - return ret; + if ( FAILED(hr) ) + return PyCom_BuildPyException(hr, pISF, IID_IShellFolder ); + return PyObject_FromPIDL(pidlRet, TRUE); } -// @object PyIShellFolder|Description of the interface +// @object PyIShellFolder|Interface that represents an Explorer folder static struct PyMethodDef PyIShellFolder_methods[] = { { "ParseDisplayName", PyIShellFolder::ParseDisplayName, 1 }, // @pymeth ParseDisplayName|Returns the PIDL of an item in a shell folder |