You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
PIDLs (PIDLIST_ABSOLUTE, PIDLIST_RELATIVE, PITEMID_CHILD -> ITEMIDLIST*) are heap allocations that must be released with ILFree (CoTaskMemFree). Today they are projected as plain pointers with no RAII, so CsWin32 consumers must hand-roll a SafeHandle/try-finally around every SHGetIDListFromObject, ILCreateFromPath, SHGetKnownFolderIDList, etc. This is error-prone and inconsistent with how other free-based types are modeled.
Precedent / pattern
generation/WinSDK/autoTypes.json already models pointer-typedefs-with-a-free-function. The closest precedent is BSTR:
CloseApi -> CsWin32 emits [RAIIFree(...)] -> generates a SafeHandle (per docs/projections.md, NativeTypedefStructsCreator.cs). Other free-based entries: HLOCAL->LocalFree, HMODULE->FreeLibrary, HDDEDATA->DdeFreeDataHandle.
Proposed change
Add PIDL typedefs to autoTypes.json with CloseApi: "ILFree/cotaskmemfree", generating e.g. ILFreeSafeHandle.
Design questions for maintainers
ILFree takes PIDLIST_RELATIVE; should all three PIDL typedefs share one SafeHandle via AlsoUsableFor (as HMODULE/HINSTANCE do)?
These are [wire_marshal] typedefs (typedef ITEMIDLIST_ABSOLUTE* PIDLIST_ABSOLUTE) - does the scraper model them cleanly as NativeTypedef?
Interaction with More issues with SHGetFileInfo #2160 (the SHGetFileInfo all-or-nothing friendly-overload problem) when a PIDL out-param becomes a SafeHandle return.
Problem
PIDLs (
PIDLIST_ABSOLUTE,PIDLIST_RELATIVE,PITEMID_CHILD->ITEMIDLIST*) are heap allocations that must be released withILFree(CoTaskMemFree). Today they are projected as plain pointers with no RAII, so CsWin32 consumers must hand-roll aSafeHandle/try-finallyaround everySHGetIDListFromObject,ILCreateFromPath,SHGetKnownFolderIDList, etc. This is error-prone and inconsistent with how other free-based types are modeled.Precedent / pattern
generation/WinSDK/autoTypes.jsonalready models pointer-typedefs-with-a-free-function. The closest precedent isBSTR:{ "Name": "BSTR", "ValueType": "char*", "CloseApi": "SysFreeString", "NativeTypedef": true }CloseApi-> CsWin32 emits[RAIIFree(...)]-> generates a SafeHandle (perdocs/projections.md,NativeTypedefStructsCreator.cs). Other free-based entries:HLOCAL->LocalFree,HMODULE->FreeLibrary,HDDEDATA->DdeFreeDataHandle.Proposed change
Add PIDL typedefs to
autoTypes.jsonwithCloseApi: "ILFree/cotaskmemfree", generating e.g.ILFreeSafeHandle.Design questions for maintainers
ILFreetakesPIDLIST_RELATIVE; should all three PIDL typedefs share one SafeHandle viaAlsoUsableFor(asHMODULE/HINSTANCEdo)?[wire_marshal]typedefs (typedef ITEMIDLIST_ABSOLUTE* PIDLIST_ABSOLUTE) - does the scraper model them cleanly asNativeTypedef?SHGetFileInfoall-or-nothing friendly-overload problem) when a PIDL out-param becomes a SafeHandle return.Related: #2160