[pywin32-checkins] /hgroot/pywin32/pywin32: When calling PyObject_FromSTRRET, make ...
OLD project page for the Python extensions for Windows
Brought to you by:
mhammond
From: <pyw...@li...> - 2012-08-24 14:51:50
|
changeset e7d21102da8d in /hgroot/pywin32/pywin32 details: http://pywin32.hg.sourceforge.net/hgweb/pywin32/pywin32/hgroot/pywin32/pywin32?cmd=changeset;node=e7d21102da8d summary: When calling PyObject_FromSTRRET, make sure pidls are freed *after* they're used diffstat: com/win32comext/shell/src/PyIShellFolder.cpp | 6 ++-- com/win32comext/shell/src/PyIShellFolder2.cpp | 5 ++- com/win32comext/shell/src/shell.cpp | 37 ++++++-------------------- com/win32comext/shell/src/shell_pch.h | 1 - 4 files changed, 15 insertions(+), 34 deletions(-) diffs (139 lines): diff -r e647878b4ccc -r e7d21102da8d com/win32comext/shell/src/PyIShellFolder.cpp --- a/com/win32comext/shell/src/PyIShellFolder.cpp Thu Aug 23 18:07:43 2012 -0400 +++ b/com/win32comext/shell/src/PyIShellFolder.cpp Fri Aug 24 10:50:19 2012 -0400 @@ -365,13 +365,13 @@ STRRET out; PY_INTERFACE_PRECALL; hr = pISF->GetDisplayNameOf( pidl, uFlags, &out ); - PyObject_FreePIDL(pidl); - PY_INTERFACE_POSTCALL; if ( FAILED(hr) ) return PyCom_BuildPyException(hr, pISF, IID_IShellFolder ); - return PyObject_FromSTRRET(&out, pidl, TRUE); + PyObject *ret = PyObject_FromSTRRET(&out, pidl, TRUE); + PyObject_FreePIDL(pidl); + return ret; } // @pymethod <o PyIDL>|PyIShellFolder|SetNameOf|Sets the display name of an item and changes its PIDL diff -r e647878b4ccc -r e7d21102da8d com/win32comext/shell/src/PyIShellFolder2.cpp --- a/com/win32comext/shell/src/PyIShellFolder2.cpp Thu Aug 23 18:07:43 2012 -0400 +++ b/com/win32comext/shell/src/PyIShellFolder2.cpp Fri Aug 24 10:50:19 2012 -0400 @@ -157,11 +157,12 @@ HRESULT hr; PY_INTERFACE_PRECALL; hr = pISF2->GetDetailsOf( pidl, iColumn, &sd ); - PyObject_FreePIDL(pidl); PY_INTERFACE_POSTCALL; if ( FAILED(hr) ) return PyCom_BuildPyException(hr, pISF2, IID_IShellFolder2 ); - return Py_BuildValue("(iiN)", sd.fmt, sd.cxChar, PyObject_FromSTRRET(&sd.str, pidl, TRUE)); + PyObject *ret = Py_BuildValue("(iiN)", sd.fmt, sd.cxChar, PyObject_FromSTRRET(&sd.str, pidl, TRUE)); + PyObject_FreePIDL(pidl); + return ret; } // @pymethod <o SHCOLUMNID>|PyIShellFolder2|MapColumnToSCID|Returns the unique identifier (FMTID, pid) of a column diff -r e647878b4ccc -r e7d21102da8d com/win32comext/shell/src/shell.cpp --- a/com/win32comext/shell/src/shell.cpp Thu Aug 23 18:07:43 2012 -0400 +++ b/com/win32comext/shell/src/shell.cpp Fri Aug 24 10:50:19 2012 -0400 @@ -611,22 +611,6 @@ pci->nShow, pci->dwHotKey, PyWinLong_FromHANDLE(pci->hIcon)); } -BOOL PyObject_AsSTRRET( PyObject *ob, STRRET &out ) -{ - if (PyInt_Check(ob)) { - out.uType = STRRET_OFFSET; - out.uOffset = PyInt_AsLong(ob); - return TRUE; - } - if (PyString_Check(ob)) { - out.uType = STRRET_CSTR; - strncpy(out.cStr, PyString_AsString(ob), MAX_PATH); - return TRUE; - } - PyErr_Format(PyExc_TypeError, "Can't convert objects of type '%s' to STRRET", ob->ob_type->tp_name); - return FALSE; -} - void PyObject_FreeSTRRET(STRRET &s) { if (s.uType==STRRET_WSTR) { @@ -638,8 +622,6 @@ PyObject *PyObject_FromSTRRET(STRRET *ps, ITEMIDLIST *pidl, BOOL bFree) { if (ps==NULL) { - if (bFree) - PyObject_FreeSTRRET(*ps); Py_INCREF(Py_None); return Py_None; } @@ -2682,31 +2664,30 @@ PyObject *ret = NULL; PyObject *obpidl; SIGDN flags; - WCHAR *strret = NULL; + WCHAR *name = NULL; PIDLIST_ABSOLUTE pidl = NULL; if(!PyArg_ParseTuple(args, "Ok:SHGetNameFromIDList", &obpidl, &flags)) return NULL; - // @pyparm PIDL|parent|| - // @pyparm int|flags|| + // @pyparm <o PyIDL>|pidl||Absolute ID list of the item + // @pyparm int|flags||Type of name to return, shellcon.SIGDN_* if (!PyObject_AsPIDL(obpidl, &pidl)) goto done; HRESULT hr; { PY_INTERFACE_PRECALL; - hr = (*pfnSHGetNameFromIDList)(pidl, flags, &strret); + hr = (*pfnSHGetNameFromIDList)(pidl, flags, &name); PY_INTERFACE_POSTCALL; } if (FAILED(hr)) { PyCom_BuildPyException(hr); goto done; } - // ref on view consumed by ret object. - ret = PyWinObject_FromWCHAR(strret); + ret = PyWinObject_FromWCHAR(name); done: if (pidl) PyObject_FreePIDL(pidl); - if (strret) - CoTaskMemFree(strret); + if (name) + CoTaskMemFree(name); return ret; } @@ -2729,13 +2710,13 @@ IShellItemArray *sia_ret = NULL; if(!PyArg_ParseTuple(args, "OOO:SHCreateShellItemArray", &obParent, &obsf, &obChildren)) return NULL; - // @pyparm PIDL|parent|| + // @pyparm <o PyIDL>|parent||Absolute ID list of parent folder, or None if sf is specified if (!PyObject_AsPIDL(obParent, &parent, TRUE)) goto done; // @pyparm <o PyIShellFolder>|sf||The Shell data source object that is the parent of the child items specified in children. If parent is specified, this parameter can be NULL. if (!PyCom_InterfaceFromPyInstanceOrObject(obsf, IID_IShellFolder, (void **)&sf, TRUE/* bNoneOK */)) goto done; - // @pyparm [PIDL, ...]|children|| + // @pyparm [<o PyIDL>, ...]|children||Sequence of relative IDLs for items in the parent folder if (!PyObject_AsPIDLArray(obChildren, &nchildren, &children)) goto done; HRESULT hr; diff -r e647878b4ccc -r e7d21102da8d com/win32comext/shell/src/shell_pch.h --- a/com/win32comext/shell/src/shell_pch.h Thu Aug 23 18:07:43 2012 -0400 +++ b/com/win32comext/shell/src/shell_pch.h Fri Aug 24 10:50:19 2012 -0400 @@ -20,7 +20,6 @@ void PyObject_FreeCMINVOKECOMMANDINFO( CMINVOKECOMMANDINFO *pci ); PyObject *PyObject_FromCMINVOKECOMMANDINFO(const CMINVOKECOMMANDINFO *pci); -BOOL PyObject_AsSTRRET( PyObject *obout, STRRET &out ); void PyObject_FreeSTRRET(STRRET &); PyObject *PyObject_FromSTRRET(STRRET *pci, ITEMIDLIST *pidl, BOOL bFree); |