Bug 1471347 - part 1 - store an nsCString for SharedLibrary::mVersion; r=njn
authorNathan Froyd <froydnj@mozilla.com>
Thu, 19 Jul 2018 10:32:07 -0400
changeset 482430 6b7ad73f1f4364cd42459090062580bd7e34811a
parent 482429 ca12371f08ac33141994fc8ea51fe284c41368e4
child 482431 aadd0e8ef25069d17a5837c153a9e68d2f1a46bd
push id9719
push userffxbld-merge
push dateFri, 24 Aug 2018 17:49:46 +0000
treeherdermozilla-beta@719ec98fba77 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersnjn
bugs1471347
milestone63.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1471347 - part 1 - store an nsCString for SharedLibrary::mVersion; r=njn Using operator<< on stringstream on Windows dives into the registry for locale-specific formatting details. This behavior is neither desired or (probably) anticipated by the code. Instead, let's use our normal Gecko string classes for SharedLibrary::mVersion.
toolkit/components/telemetry/Telemetry.cpp
tools/profiler/core/shared-libraries-linux.cc
tools/profiler/core/shared-libraries-macos.cc
tools/profiler/core/shared-libraries-win32.cc
tools/profiler/public/shared-libraries.h
--- a/toolkit/components/telemetry/Telemetry.cpp
+++ b/toolkit/components/telemetry/Telemetry.cpp
@@ -808,18 +808,18 @@ public:
       if (!JS_DefineProperty(cx, moduleObj, "debugID", id, JSPROP_ENUMERATE)) {
         mPromise->MaybeReject(NS_ERROR_FAILURE);
         return NS_OK;
       }
 
       // Module version.
       JS::RootedValue version(cx);
 
-      if (!info.GetVersion().empty()) {
-        JS::RootedString v(cx, JS_NewStringCopyZ(cx, info.GetVersion().c_str()));
+      if (!info.GetVersion().IsEmpty()) {
+        JS::RootedString v(cx, JS_NewStringCopyZ(cx, info.GetVersion().BeginReading()));
         if (!v) {
           mPromise->MaybeReject(NS_ERROR_FAILURE);
           return NS_OK;
         }
         version.setString(v);
       } else {
         version.setNull();
       }
--- a/tools/profiler/core/shared-libraries-linux.cc
+++ b/tools/profiler/core/shared-libraries-linux.cc
@@ -105,17 +105,17 @@ SharedLibraryAtPath(const char* path, un
   nsAutoString nameStr = pathStr;
   int32_t pos = nameStr.RFindChar('/');
   if (pos != kNotFound) {
     nameStr.Cut(0, pos + 1);
   }
 
   return SharedLibrary(libStart, libEnd, offset, getId(path),
                        nameStr, pathStr, nameStr, pathStr,
-                       "", "");
+                       EmptyCString(), "");
 }
 
 static int
 dl_iterate_callback(struct dl_phdr_info *dl_info, size_t size, void *data)
 {
   auto libInfoList = reinterpret_cast<nsTArray<LoadedLibraryInfo>*>(data);
 
   if (dl_info->dlpi_phnum <= 0)
--- a/tools/profiler/core/shared-libraries-macos.cc
+++ b/tools/profiler/core/shared-libraries-macos.cc
@@ -148,17 +148,17 @@ void addSharedLibrary(const platform_mac
     nameStr.Cut(0, pos + 1);
   }
 
   const NXArchInfo* archInfo =
     NXGetArchInfoFromCpuType(header->cputype, header->cpusubtype);
 
   info.AddSharedLibrary(SharedLibrary(start, start + size, 0, uuid.str(),
                                       nameStr, pathStr, nameStr, pathStr,
-                                      "",
+                                      EmptyCString(),
                                       archInfo ? archInfo->name : ""));
 }
 
 // Translate the statically stored sSharedLibrariesList information into a
 // SharedLibraryInfo object.
 SharedLibraryInfo
 SharedLibraryInfo::GetInfoForSelf()
 {
--- a/tools/profiler/core/shared-libraries-win32.cc
+++ b/tools/profiler/core/shared-libraries-win32.cc
@@ -8,16 +8,18 @@
 #include <sstream>
 #include <psapi.h>
 
 #include "shared-libraries.h"
 #include "nsWindowsHelpers.h"
 #include "mozilla/UniquePtr.h"
 #include "mozilla/Unused.h"
 #include "nsNativeCharsetUtils.h"
+#include "nsPrintfCString.h"
+#include "nsReadableUtils.h"
 
 #define CV_SIGNATURE 0x53445352 // 'SDSR'
 
 struct CodeViewRecord70
 {
   uint32_t signature;
   GUID pdbSignature;
   uint32_t pdbAge;
@@ -74,44 +76,44 @@ static bool GetPdbInfo(uintptr_t aStart,
   return true;
 }
 
 static bool IsDashOrBraces(char c)
 {
   return c == '-' || c == '{' || c == '}';
 }
 
-std::string GetVersion(WCHAR* dllPath)
+static nsCString
+GetVersion(WCHAR* dllPath)
 {
   DWORD infoSize = GetFileVersionInfoSizeW(dllPath, nullptr);
   if (infoSize == 0) {
-    return "";
+    return EmptyCString();
   }
 
   mozilla::UniquePtr<unsigned char[]> infoData = mozilla::MakeUnique<unsigned char[]>(infoSize);
   if (!GetFileVersionInfoW(dllPath, 0, infoSize, infoData.get())) {
-    return "";
+    return EmptyCString();
   }
 
   VS_FIXEDFILEINFO* vInfo;
   UINT vInfoLen;
   if (!VerQueryValueW(infoData.get(), L"\\", (LPVOID*)&vInfo, &vInfoLen)) {
-    return "";
+    return EmptyCString();
   }
   if (!vInfo) {
-    return "";
+    return EmptyCString();
   }
 
-  std::ostringstream stream;
-  stream << (vInfo->dwFileVersionMS >> 16)    << "."
-         << (vInfo->dwFileVersionMS & 0xFFFF) << "."
-         << (vInfo->dwFileVersionLS >> 16)    << "."
-         << (vInfo->dwFileVersionLS & 0xFFFF);
-
-  return stream.str();
+  nsPrintfCString version("%d.%d.%d.%d",
+                          vInfo->dwFileVersionMS >> 16,
+                          vInfo->dwFileVersionMS & 0xFFFF,
+                          vInfo->dwFileVersionLS >> 16,
+                          vInfo->dwFileVersionLS & 0xFFFF);
+  return version;
 }
 
 SharedLibraryInfo SharedLibraryInfo::GetInfoForSelf()
 {
   SharedLibraryInfo sharedLibraryInfo;
 
   HANDLE hProcess = GetCurrentProcess();
   mozilla::UniquePtr<HMODULE[]> hMods;
--- a/tools/profiler/public/shared-libraries.h
+++ b/tools/profiler/public/shared-libraries.h
@@ -26,17 +26,17 @@ public:
   SharedLibrary(uintptr_t aStart,
                 uintptr_t aEnd,
                 uintptr_t aOffset,
                 const std::string& aBreakpadId,
                 const nsString& aModuleName,
                 const nsString& aModulePath,
                 const nsString& aDebugName,
                 const nsString& aDebugPath,
-                const std::string& aVersion,
+                const nsCString& aVersion,
                 const char* aArch)
     : mStart(aStart)
     , mEnd(aEnd)
     , mOffset(aOffset)
     , mBreakpadId(aBreakpadId)
     , mModuleName(aModuleName)
     , mModulePath(aModulePath)
     , mDebugName(aDebugName)
@@ -100,31 +100,31 @@ public:
     nsAutoCString debugPathStr;
 
     NS_CopyUnicodeToNative(mDebugPath, debugPathStr);
 
     return debugPathStr.get();
   }
   const nsString &GetDebugName() const { return mDebugName; }
   const nsString &GetDebugPath() const { return mDebugPath; }
-  const std::string &GetVersion() const { return mVersion; }
+  const nsCString &GetVersion() const { return mVersion; }
   const std::string &GetArch() const { return mArch; }
 
 private:
   SharedLibrary() : mStart{0}, mEnd{0}, mOffset{0} {}
 
   uintptr_t mStart;
   uintptr_t mEnd;
   uintptr_t mOffset;
   std::string mBreakpadId;
   nsString mModuleName;
   nsString mModulePath;
   nsString mDebugName;
   nsString mDebugPath;
-  std::string mVersion;
+  nsCString mVersion;
   std::string mArch;
 };
 
 static bool
 CompareAddresses(const SharedLibrary& first, const SharedLibrary& second)
 {
   return first.GetStart() < second.GetStart();
 }