Bug 1316120 - use more Win32 API-ish types in nsLocalFileWin.cpp; r?aklotz draft
authorNathan Froyd <froydnj@mozilla.com>
Tue, 27 Sep 2016 15:36:30 -0400
changeset 435539 5add0e9e029aedfed102c3e75c42fc93a2a12280
parent 429219 4bd3341c4b415dbc68ca9e93a361affcffc9b91c
child 536336 07dc75f8a0c10ca06ba022af3391100d7b395d06
push id35073
push userbmo:nfroyd@mozilla.com
push dateTue, 08 Nov 2016 21:31:06 +0000
reviewersaklotz
bugs1316120
milestone52.0a1
Bug 1316120 - use more Win32 API-ish types in nsLocalFileWin.cpp; r?aklotz This change works around issues with clang-cl being unable to drop the __unaligned modifier (which only has an effect on Itanium, which we don't support) when using static_cast. Instead of static_cast'ing our way to victory, we instead go through the approved Win32 APIs to do the translation between all the different types. MozReview-Commit-ID: 8Z9uL7xY9VN
xpcom/io/nsLocalFileWin.cpp
--- a/xpcom/io/nsLocalFileWin.cpp
+++ b/xpcom/io/nsLocalFileWin.cpp
@@ -175,55 +175,54 @@ private:
     DWORD attributes = GetFileAttributesW(mResolvedPath.get());
     if (INVALID_FILE_ATTRIBUTES == attributes) {
       return NS_ERROR_FILE_INVALID_PATH;
     }
 
     HRESULT hr;
     if (attributes & FILE_ATTRIBUTE_DIRECTORY) {
       // We have a directory so we should open the directory itself.
-      ITEMIDLIST* dir =
-        static_cast<ITEMIDLIST*>(ILCreateFromPathW(mResolvedPath.get()));
+      PIDLIST_ABSOLUTE dir = ILCreateFromPathW(mResolvedPath.get());
       if (!dir) {
         return NS_ERROR_FAILURE;
       }
 
-      const ITEMIDLIST* selection[] = { dir };
+      PUITEMID_CHILD child = ILFindLastID(dir);
+      PCUITEMID_CHILD selection[] = { child };
       UINT count = ArrayLength(selection);
 
       //Perform the open of the directory.
-      hr = SHOpenFolderAndSelectItems(dir, count, selection, 0);
+      hr = SHOpenFolderAndSelectItems(dir, count, &selection[0], 0);
       CoTaskMemFree(dir);
     } else {
       int32_t len = mResolvedPath.Length();
       // We don't currently handle UNC long paths of the form \\?\ anywhere so
       // this should be fine.
       if (len > MAX_PATH) {
         return NS_ERROR_FILE_INVALID_PATH;
       }
       WCHAR parentDirectoryPath[MAX_PATH + 1] = { 0 };
       wcsncpy(parentDirectoryPath, mResolvedPath.get(), MAX_PATH);
       PathRemoveFileSpecW(parentDirectoryPath);
 
       // We have a file so we should open the parent directory.
-      ITEMIDLIST* dir =
-        static_cast<ITEMIDLIST*>(ILCreateFromPathW(parentDirectoryPath));
+      PIDLIST_ABSOLUTE dir = ILCreateFromPathW(parentDirectoryPath);
       if (!dir) {
         return NS_ERROR_FAILURE;
       }
 
       // Set the item in the directory to select to the file we want to reveal.
-      ITEMIDLIST* item =
-        static_cast<ITEMIDLIST*>(ILCreateFromPathW(mResolvedPath.get()));
+      PIDLIST_ABSOLUTE item = ILCreateFromPathW(mResolvedPath.get());
       if (!item) {
         CoTaskMemFree(dir);
         return NS_ERROR_FAILURE;
       }
 
-      const ITEMIDLIST* selection[] = { item };
+      PUITEMID_CHILD child = ILFindLastID(dir);
+      PCUITEMID_CHILD selection[] = { child };
       UINT count = ArrayLength(selection);
 
       //Perform the selection of the file.
       hr = SHOpenFolderAndSelectItems(dir, count, selection, 0);
 
       CoTaskMemFree(dir);
       CoTaskMemFree(item);
     }