Bug 1557794. Stop using [array] in nsIGfxInfo. r=jrmuizel
authorBoris Zbarsky <bzbarsky@mit.edu>
Fri, 07 Jun 2019 20:13:56 +0000
changeset 477894 061cca57657dbdcdd8a31ee58229dd92fca1be48
parent 477893 67000716b372d33425e9833a48be8b907c43fcdb
child 477895 79a73eadada0d75923d05c2fed11ac8310a5b3a7
push id36127
push usernbeleuzu@mozilla.com
push dateSat, 08 Jun 2019 09:39:25 +0000
treeherdermozilla-central@b26753fb35e7 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjrmuizel
bugs1557794
milestone69.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 1557794. Stop using [array] in nsIGfxInfo. r=jrmuizel Differential Revision: https://phabricator.services.mozilla.com/D34210
toolkit/modules/Troubleshoot.jsm
widget/GfxInfoBase.cpp
widget/GfxInfoBase.h
widget/nsIGfxInfo.idl
--- a/toolkit/modules/Troubleshoot.jsm
+++ b/toolkit/modules/Troubleshoot.jsm
@@ -549,20 +549,19 @@ var dataProviders = {
     GetWebGLInfo(data, "webgl1", "webgl");
     GetWebGLInfo(data, "webgl2", "webgl2");
 
 
     let infoInfo = gfxInfo.getInfo();
     if (infoInfo)
       data.info = infoInfo;
 
-    let failureCount = {};
     let failureIndices = {};
 
-    let failures = gfxInfo.getFailures(failureCount, failureIndices);
+    let failures = gfxInfo.getFailures(failureIndices);
     if (failures.length) {
       data.failures = failures;
       if (failureIndices.value.length == failures.length) {
         data.indices = failureIndices.value;
       }
     }
 
     data.featureLog = gfxInfo.getFeatureLog();
--- a/widget/GfxInfoBase.cpp
+++ b/widget/GfxInfoBase.cpp
@@ -1069,58 +1069,36 @@ GfxInfoBase::LogFailure(const nsACString
   // ::GetFailures()
   MutexAutoLock lock(mMutex);
 
   // By default, gfxCriticalError asserts; make it not assert in this case.
   gfxCriticalError(CriticalLog::DefaultOptions(false))
       << "(LF) " << failure.BeginReading();
 }
 
-/* XPConnect method of returning arrays is very ugly. Would not recommend. */
-NS_IMETHODIMP GfxInfoBase::GetFailures(uint32_t* failureCount,
-                                       int32_t** indices, char*** failures) {
+NS_IMETHODIMP GfxInfoBase::GetFailures(nsTArray<int32_t>& indices,
+                                       nsTArray<nsCString>& failures) {
   MutexAutoLock lock(mMutex);
 
-  NS_ENSURE_ARG_POINTER(failureCount);
-  NS_ENSURE_ARG_POINTER(failures);
-
-  *failures = nullptr;
-  *failureCount = 0;
-
-  // indices is "allowed" to be null, the caller may not care about them,
-  // although calling from JS doesn't seem to get us there.
-  if (indices) *indices = nullptr;
-
   LogForwarder* logForwarder = Factory::GetLogForwarder();
   if (!logForwarder) {
     return NS_ERROR_UNEXPECTED;
   }
 
-  // There are two stirng copies in this method, starting with this one. We are
+  // There are two string copies in this method, starting with this one. We are
   // assuming this is not a big deal, as the size of the array should be small
   // and the strings in it should be small as well (the error messages in the
-  // code.)  The second copy happens with the Clone() calls.  Technically,
-  // we don't need the mutex lock after the StringVectorCopy() call.
+  // code.)  The second copy happens with the AppendElement() calls.
+  // Technically, we don't need the mutex lock after the StringVectorCopy() call.
   LoggingRecord loggedStrings = logForwarder->LoggingRecordCopy();
-  *failureCount = loggedStrings.size();
-
-  if (*failureCount != 0) {
-    *failures = (char**)moz_xmalloc(*failureCount * sizeof(char*));
-    if (indices) {
-      *indices = (int32_t*)moz_xmalloc(*failureCount * sizeof(int32_t));
-    }
-
-    /* copy over the failure messages into the array we just allocated */
-    LoggingRecord::const_iterator it;
-    uint32_t i = 0;
-    for (it = loggedStrings.begin(); it != loggedStrings.end(); ++it, i++) {
-      (*failures)[i] =
-          (char*)moz_xmemdup(Get<1>(*it).c_str(), Get<1>(*it).size() + 1);
-      if (indices) (*indices)[i] = Get<0>(*it);
-    }
+  LoggingRecord::const_iterator it;
+  for (it = loggedStrings.begin(); it != loggedStrings.end(); ++it) {
+    failures.AppendElement(
+        nsDependentCSubstring(Get<1>(*it).c_str(), Get<1>(*it).size()));
+    indices.AppendElement(Get<0>(*it));
   }
 
   return NS_OK;
 }
 
 nsTArray<GfxInfoCollectorBase*>* sCollectors;
 
 static void InitCollectors() {
--- a/widget/GfxInfoBase.h
+++ b/widget/GfxInfoBase.h
@@ -50,18 +50,18 @@ class GfxInfoBase : public nsIGfxInfo,
   // to import the relevant methods into their namespace.
   NS_IMETHOD GetFeatureStatus(int32_t aFeature, nsACString& aFailureId,
                               int32_t* _retval) override;
   NS_IMETHOD GetFeatureSuggestedDriverVersion(int32_t aFeature,
                                               nsAString& _retval) override;
 
   NS_IMETHOD GetMonitors(JSContext* cx,
                          JS::MutableHandleValue _retval) override;
-  NS_IMETHOD GetFailures(uint32_t* failureCount, int32_t** indices,
-                         char*** failures) override;
+  NS_IMETHOD GetFailures(nsTArray<int32_t>& indices,
+                         nsTArray<nsCString>& failures) override;
   NS_IMETHOD_(void) LogFailure(const nsACString& failure) override;
   NS_IMETHOD GetInfo(JSContext*, JS::MutableHandle<JS::Value>) override;
   NS_IMETHOD GetFeatures(JSContext*, JS::MutableHandle<JS::Value>) override;
   NS_IMETHOD GetFeatureLog(JSContext*, JS::MutableHandle<JS::Value>) override;
   NS_IMETHOD GetActiveCrashGuards(JSContext*,
                                   JS::MutableHandle<JS::Value>) override;
   NS_IMETHOD GetContentBackend(nsAString& aContentBackend) override;
   NS_IMETHOD GetUsingGPUProcess(bool* aOutValue) override;
--- a/widget/nsIGfxInfo.idl
+++ b/widget/nsIGfxInfo.idl
@@ -80,20 +80,17 @@ interface nsIGfxInfo : nsISupports
    *
    * Windows additionally supplies "refreshRate" and "pseudoDisplay".
    *
    * OS X additionally supplies "scale".
    */
   [implicit_jscontext]
   jsval getMonitors();
 
-  void getFailures(
-               out unsigned long failureCount,
-               [optional, array, size_is(failureCount)] out long indices,
-               [retval, array, size_is(failureCount)] out string failures);
+  Array<ACString> getFailures(out Array<long> indices);
 
   [noscript, notxpcom] void logFailure(in ACString failure);
   /*
    * A set of constants for features that we can ask this GfxInfo object
    * about via GetFeatureStatus
    */
   /* Don't assign any value <= 0 */
   /* Whether Direct2D is supported for content rendering. */