Bug 1060419 - make ManifestParser use Printf.h, r?froydnj
MozReview-Commit-ID: HBOOr5WScvU
--- 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