Bug 1381727 (part 1) - Remove JS_smprintf_free(). r=sfink.
authorNicholas Nethercote <nnethercote@mozilla.com>
Tue, 25 Jul 2017 09:09:23 +1000
changeset 422102 edded26e7141609581dfabd39298af699ab3abd6
parent 422101 f39eaceb3ca0d81717297e52e493eb2fca7df2ea
child 422103 b441867efe7020c53e344e53200bc2915e854487
push id1517
push userjlorenzo@mozilla.com
push dateThu, 14 Sep 2017 16:50:54 +0000
treeherdermozilla-release@3b41fd564418 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssfink
bugs1381727
milestone56.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 1381727 (part 1) - Remove JS_smprintf_free(). r=sfink. Because it's just a wrapper for js_free(). Furthermore, JS_smprintf() and friends return a JS::UniqueChars, which is also wired up to free with js_free(). So having the indirection via JS_smprintf_free() obfuscates things.
dom/power/PowerManagerService.cpp
js/src/jsprf.cpp
js/src/jsprf.h
js/xpconnect/src/XPCThrower.cpp
js/xpconnect/src/xpcprivate.h
js/xpconnect/wrappers/XrayWrapper.cpp
--- a/dom/power/PowerManagerService.cpp
+++ b/dom/power/PowerManagerService.cpp
@@ -28,17 +28,17 @@
 #include <android/log.h>
 extern "C" char* PrintJSStack();
 static void LogFunctionAndJSStack(const char* funcname) {
   char *jsstack = PrintJSStack();
   __android_log_print(ANDROID_LOG_INFO, "PowerManagerService", \
                       "Call to %s. The JS stack is:\n%s\n",
                       funcname,
                       jsstack ? jsstack : "<no JS stack>");
-  JS_smprintf_free(jsstack);
+  js_free(jsstack);
 }
 // bug 839452
 #define LOG_FUNCTION_AND_JS_STACK() \
   LogFunctionAndJSStack(__PRETTY_FUNCTION__);
 #else
 #define LOG_FUNCTION_AND_JS_STACK()
 #endif
 
--- a/js/src/jsprf.cpp
+++ b/js/src/jsprf.cpp
@@ -24,21 +24,16 @@ JS_PUBLIC_API(JS::UniqueChars) JS_smprin
 {
     va_list ap;
     va_start(ap, fmt);
     JSSmprintfPointer result = mozilla::Vsmprintf<js::SystemAllocPolicy>(fmt, ap);
     va_end(ap);
     return JS::UniqueChars(result.release());
 }
 
-JS_PUBLIC_API(void) JS_smprintf_free(char* mem)
-{
-    mozilla::SmprintfFree<js::SystemAllocPolicy>(mem);
-}
-
 JS_PUBLIC_API(JS::UniqueChars) JS_sprintf_append(JS::UniqueChars&& last, const char* fmt, ...)
 {
     va_list ap;
     va_start(ap, fmt);
     JSSmprintfPointer lastPtr(last.release());
     JSSmprintfPointer result =
         mozilla::VsmprintfAppend<js::SystemAllocPolicy>(Move(lastPtr), fmt, ap);
     va_end(ap);
--- a/js/src/jsprf.h
+++ b/js/src/jsprf.h
@@ -15,18 +15,16 @@
 #include "js/Utility.h"
 
 /* Wrappers for mozilla::Smprintf and friends that are used throughout
    JS.  */
 
 extern JS_PUBLIC_API(JS::UniqueChars) JS_smprintf(const char* fmt, ...)
     MOZ_FORMAT_PRINTF(1, 2);
 
-extern JS_PUBLIC_API(void) JS_smprintf_free(char* mem);
-
 extern JS_PUBLIC_API(JS::UniqueChars) JS_sprintf_append(JS::UniqueChars&& last,
                                                         const char* fmt, ...)
      MOZ_FORMAT_PRINTF(2, 3);
 
 extern JS_PUBLIC_API(JS::UniqueChars) JS_vsmprintf(const char* fmt, va_list ap)
     MOZ_FORMAT_PRINTF(1, 0);
 extern JS_PUBLIC_API(JS::UniqueChars) JS_vsprintf_append(JS::UniqueChars&& last,
                                                          const char* fmt, va_list ap)
--- a/js/xpconnect/src/XPCThrower.cpp
+++ b/js/xpconnect/src/XPCThrower.cpp
@@ -80,17 +80,17 @@ XPCThrower::Throw(nsresult rv, XPCCallCo
     NS_ENSURE_TRUE_VOID(sz);
 
     if (sz && sVerbose)
         Verbosify(ccx, &sz, false);
 
     dom::Throw(ccx, rv, nsDependentCString(sz));
 
     if (sz && sz != format)
-        JS_smprintf_free(sz);
+        js_free(sz);
 }
 
 
 // static
 void
 XPCThrower::ThrowBadResult(nsresult rv, nsresult result, XPCCallContext& ccx)
 {
     char* sz;
@@ -122,17 +122,17 @@ XPCThrower::ThrowBadResult(nsresult rv, 
     NS_ENSURE_TRUE_VOID(sz);
 
     if (sz && sVerbose)
         Verbosify(ccx, &sz, true);
 
     dom::Throw(ccx, result, nsDependentCString(sz));
 
     if (sz)
-        JS_smprintf_free(sz);
+        js_free(sz);
 }
 
 // static
 void
 XPCThrower::ThrowBadParam(nsresult rv, unsigned paramNum, XPCCallContext& ccx)
 {
     char* sz;
     const char* format;
@@ -144,17 +144,17 @@ XPCThrower::ThrowBadParam(nsresult rv, u
     NS_ENSURE_TRUE_VOID(sz);
 
     if (sz && sVerbose)
         Verbosify(ccx, &sz, true);
 
     dom::Throw(ccx, rv, nsDependentCString(sz));
 
     if (sz)
-        JS_smprintf_free(sz);
+        js_free(sz);
 }
 
 
 // static
 void
 XPCThrower::Verbosify(XPCCallContext& ccx,
                       char** psz, bool own)
 {
@@ -168,12 +168,12 @@ XPCThrower::Verbosify(XPCCallContext& cc
         if (!name) {
             name = "";
         }
         sz = JS_smprintf("%s [%s.%s]", *psz, iface->GetNameString(), name).release();
     }
 
     if (sz) {
         if (own)
-            JS_smprintf_free(*psz);
+            js_free(*psz);
         *psz = sz;
     }
 }
--- a/js/xpconnect/src/xpcprivate.h
+++ b/js/xpconnect/src/xpcprivate.h
@@ -1725,17 +1725,18 @@ public:
     static void Trace(JSTracer* trc, JSObject* obj);
 
     void AutoTrace(JSTracer* trc) {
         TraceSelf(trc);
     }
 
     inline void SweepTearOffs();
 
-    // Returns a string that shuld be free'd using JS_smprintf_free (or null).
+    // Returns a string that should be freed with js_free, or nullptr on
+    // failure.
     char* ToString(XPCWrappedNativeTearOff* to = nullptr) const;
 
     static nsIXPCScriptable* GatherProtoScriptable(nsIClassInfo* classInfo);
 
     bool HasExternalReference() const {return mRefCnt > 1;}
 
     void Suspect(nsCycleCollectionNoteRootCallback& cb);
     void NoteTearoffs(nsCycleCollectionTraversalCallback& cb);
--- a/js/xpconnect/wrappers/XrayWrapper.cpp
+++ b/js/xpconnect/wrappers/XrayWrapper.cpp
@@ -2048,17 +2048,17 @@ XrayToString(JSContext* cx, unsigned arg
     XPCCallContext ccx(cx, obj);
     XPCWrappedNative* wn = XPCWrappedNativeXrayTraits::getWN(wrapper);
     char* wrapperStr = wn->ToString();
     if (!wrapperStr) {
         JS_ReportOutOfMemory(cx);
         return false;
     }
     result.AppendASCII(wrapperStr);
-    JS_smprintf_free(wrapperStr);
+    js_free(wrapperStr);
 
     result.AppendASCII(end);
 
     JSString* str = JS_NewUCStringCopyN(cx, result.get(), result.Length());
     if (!str)
         return false;
 
     args.rval().setString(str);