Bug 1060419 - make ManifestParser use Printf.h, r=froydnj
authorTom Tromey <tom@tromey.com>
Thu, 15 Dec 2016 20:13:08 -0700
changeset 372570 bd0976eeda5fd26cb627a6c13e1e45bcadc6b9fb
parent 372569 495b8a307555744c3b8320098a4e526b9bc6404e
child 372571 90b1959687b2adc7f5db7d9ea1a388c92ae6cdff
push id10863
push userjlorenzo@mozilla.com
push dateMon, 06 Mar 2017 23:02:23 +0000
treeherdermozilla-aurora@0931190cd725 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersfroydnj
bugs1060419
milestone54.0a1
Bug 1060419 - make ManifestParser use Printf.h, r=froydnj MozReview-Commit-ID: HBOOr5WScvU
xpcom/components/ManifestParser.cpp
xpcom/components/ManifestParser.h
--- a/xpcom/components/ManifestParser.cpp
+++ b/xpcom/components/ManifestParser.cpp
@@ -1,22 +1,23 @@
 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #include "mozilla/ArrayUtils.h"
+#include "mozilla/Printf.h"
+#include "mozilla/UniquePtr.h"
 
 #include "ManifestParser.h"
 
 #include <string.h>
 
 #include "prio.h"
-#include "prprf.h"
 #if defined(XP_WIN)
 #include <windows.h>
 #elif defined(MOZ_WIDGET_COCOA)
 #include <CoreServices/CoreServices.h>
 #include "nsCocoaFeatures.h"
 #elif defined(MOZ_WIDGET_GTK)
 #include <gtk/gtk.h>
 #endif
@@ -131,31 +132,24 @@ static const char kWhitespace[] = "\t ";
 
 static bool
 IsNewline(char aChar)
 {
   return aChar == '\n' || aChar == '\r';
 }
 
 namespace {
-struct AutoPR_smprintf_free
+struct SmprintfFreePolicy
 {
-  explicit AutoPR_smprintf_free(char* aBuf) : mBuf(aBuf) {}
+  void operator()(char* ptr) {
+    mozilla::SmprintfFree(ptr);
+  }
+};
 
-  ~AutoPR_smprintf_free()
-  {
-    if (mBuf) {
-      PR_smprintf_free(mBuf);
-    }
-  }
-
-  operator char*() const { return mBuf; }
-
-  char* mBuf;
-};
+typedef mozilla::UniquePtr<char, SmprintfFreePolicy> SmprintfPointer;
 
 } // namespace
 
 /**
  * If we are pre-loading XPTs, this method may do nothing because the
  * console service is not initialized.
  */
 void
@@ -168,35 +162,35 @@ LogMessage(const char* aMsg, ...)
   nsCOMPtr<nsIConsoleService> console =
     do_GetService(NS_CONSOLESERVICE_CONTRACTID);
   if (!console) {
     return;
   }
 
   va_list args;
   va_start(args, aMsg);
-  AutoPR_smprintf_free formatted(PR_vsmprintf(aMsg, args));
+  SmprintfPointer formatted(mozilla::Vsmprintf(aMsg, args));
   va_end(args);
 
   nsCOMPtr<nsIConsoleMessage> error =
-    new nsConsoleMessage(NS_ConvertUTF8toUTF16(formatted).get());
+    new nsConsoleMessage(NS_ConvertUTF8toUTF16(formatted.get()).get());
   console->LogMessage(error);
 }
 
 /**
  * If we are pre-loading XPTs, this method may do nothing because the
  * console service is not initialized.
  */
 void
 LogMessageWithContext(FileLocation& aFile,
                       uint32_t aLineNumber, const char* aMsg, ...)
 {
   va_list args;
   va_start(args, aMsg);
-  AutoPR_smprintf_free formatted(PR_vsmprintf(aMsg, args));
+  SmprintfPointer formatted(mozilla::Vsmprintf(aMsg, args));
   va_end(args);
   if (!formatted) {
     return;
   }
 
   if (!nsComponentManagerImpl::gComponentManager) {
     return;
   }
@@ -205,27 +199,27 @@ LogMessageWithContext(FileLocation& aFil
   aFile.GetURIString(file);
 
   nsCOMPtr<nsIScriptError> error =
     do_CreateInstance(NS_SCRIPTERROR_CONTRACTID);
   if (!error) {
     // This can happen early in component registration. Fall back to a
     // generic console message.
     LogMessage("Warning: in '%s', line %i: %s", file.get(),
-               aLineNumber, (char*)formatted);
+               aLineNumber, formatted.get());
     return;
   }
 
   nsCOMPtr<nsIConsoleService> console =
     do_GetService(NS_CONSOLESERVICE_CONTRACTID);
   if (!console) {
     return;
   }
 
-  nsresult rv = error->Init(NS_ConvertUTF8toUTF16(formatted),
+  nsresult rv = error->Init(NS_ConvertUTF8toUTF16(formatted.get()),
                             NS_ConvertUTF8toUTF16(file), EmptyString(),
                             aLineNumber, 0, nsIScriptError::warningFlag,
                             "chrome registration");
   if (NS_FAILED(rv)) {
     return;
   }
 
   console->LogMessage(error);
--- a/xpcom/components/ManifestParser.h
+++ b/xpcom/components/ManifestParser.h
@@ -4,19 +4,21 @@
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #ifndef ManifestParser_h
 #define ManifestParser_h
 
 #include "nsComponentManager.h"
 #include "nsChromeRegistry.h"
+#include "mozilla/Attributes.h"
 #include "mozilla/FileLocation.h"
 
 void ParseManifest(NSLocationType aType, mozilla::FileLocation& aFile,
                    char* aBuf, bool aChromeOnly, bool aXPTOnly = false);
 
-void LogMessage(const char* aMsg, ...);
+void LogMessage(const char* aMsg, ...) MOZ_FORMAT_PRINTF(1, 2);
 
 void LogMessageWithContext(mozilla::FileLocation& aFile,
-                           uint32_t aLineNumber, const char* aMsg, ...);
+                           uint32_t aLineNumber, const char* aMsg, ...)
+  MOZ_FORMAT_PRINTF(3, 4);
 
 #endif // ManifestParser_h