Bug 1060419 - introduce mozilla::Smprintf and friends; r=froydnj
authorTom Tromey <tom@tromey.com>
Fri, 13 Jan 2017 10:16:17 -0700
changeset 343525 e5f4fa3617fdbc1dccf66b681b1e8c6cac8757b7
parent 343524 6f71d06ae7090568bba2999a1b2fcc030ea25f10
child 343526 a69d8969642d40db1312c0b4b9bde8a5d6422556
push id31381
push userkwierso@gmail.com
push dateFri, 17 Feb 2017 20:45:51 +0000
treeherdermozilla-central@f302def88fe5 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersfroydnj
bugs1060419
milestone54.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 1060419 - introduce mozilla::Smprintf and friends; r=froydnj MozReview-Commit-ID: BsmaFtJEvQH
js/src/jsprf.cpp
js/src/jsprf.h
--- a/js/src/jsprf.cpp
+++ b/js/src/jsprf.cpp
@@ -882,67 +882,67 @@ GrowStuff(SprintfState* ss, const char* 
     }
     MOZ_ASSERT(size_t(ss->cur - ss->base) <= ss->maxlen);
     return true;
 }
 
 /*
  * sprintf into a js_malloc'd buffer
  */
-JS_PUBLIC_API(char*)
-JS_smprintf(const char* fmt, ...)
+char*
+mozilla::Smprintf(const char* fmt, ...)
 {
     va_list ap;
     char* rv;
 
     va_start(ap, fmt);
-    rv = JS_vsmprintf(fmt, ap);
+    rv = mozilla::Vsmprintf(fmt, ap);
     va_end(ap);
     return rv;
 }
 
 /*
- * Free memory allocated, for the caller, by JS_smprintf
+ * Free memory allocated, for the caller, by mozilla::Smprintf
  */
-JS_PUBLIC_API(void)
-JS_smprintf_free(char* mem)
+void
+mozilla::SmprintfFree(char* mem)
 {
     js_free(mem);
 }
 
-JS_PUBLIC_API(char*)
-JS_vsmprintf(const char* fmt, va_list ap)
+char*
+mozilla::Vsmprintf(const char* fmt, va_list ap)
 {
     SprintfState ss;
 
     ss.stuff = GrowStuff;
     ss.base = 0;
     ss.cur = 0;
     ss.maxlen = 0;
     if (!dosprintf(&ss, fmt, ap)) {
         js_free(ss.base);
         return 0;
     }
     return ss.base;
 }
 
-JS_PUBLIC_API(char*)
-JS_sprintf_append(char* last, const char* fmt, ...)
+char*
+mozilla::SmprintfAppend(char* last, const char* fmt, ...)
 {
     va_list ap;
     char* rv;
 
     va_start(ap, fmt);
-    rv = JS_vsprintf_append(last, fmt, ap);
+    rv = mozilla::VsmprintfAppend(last, fmt, ap);
     va_end(ap);
     return rv;
 }
 
-JS_PUBLIC_API(char*)
-JS_vsprintf_append(char* last, const char* fmt, va_list ap)
+char*
+mozilla::VsmprintfAppend(char* last, const char* fmt, va_list ap)
 {
     SprintfState ss;
 
     ss.stuff = GrowStuff;
     if (last) {
         size_t lastlen = strlen(last);
         ss.base = last;
         ss.cur = last + lastlen;
@@ -973,8 +973,41 @@ JS_vsprintf_append(char* last, const cha
 #undef TYPE_POINTER
 #undef TYPE_UNKNOWN
 
 #undef FLAG_LEFT
 #undef FLAG_SIGNED
 #undef FLAG_SPACED
 #undef FLAG_ZEROS
 #undef FLAG_NEG
+
+JS_PUBLIC_API(char*) JS_smprintf(const char* fmt, ...)
+{
+    va_list ap;
+    va_start(ap, fmt);
+    char* result = mozilla::Vsmprintf(fmt, ap);
+    va_end(ap);
+    return result;
+}
+
+JS_PUBLIC_API(void) JS_smprintf_free(char* mem)
+{
+    mozilla::SmprintfFree(mem);
+}
+
+JS_PUBLIC_API(char*) JS_sprintf_append(char* last, const char* fmt, ...)
+{
+    va_list ap;
+    va_start(ap, fmt);
+    char* result = mozilla::VsmprintfAppend(last, fmt, ap);
+    va_end(ap);
+    return result;
+}
+
+JS_PUBLIC_API(char*) JS_vsmprintf(const char* fmt, va_list ap)
+{
+    return mozilla::Vsmprintf(fmt, ap);
+}
+
+JS_PUBLIC_API(char*) JS_vsprintf_append(char* last, const char* fmt, va_list ap)
+{
+    return mozilla::VsmprintfAppend(last, fmt, ap);
+}
--- a/js/src/jsprf.h
+++ b/js/src/jsprf.h
@@ -24,43 +24,62 @@
 **      %c - character
 **      %p - pointer (deals with machine dependent pointer size)
 **      %f - float
 **      %g - float
 */
 
 #include "mozilla/IntegerPrintfMacros.h"
 #include "mozilla/SizePrintfMacros.h"
+#include "mozilla/Types.h"
 
 #include <stdarg.h>
 
 #include "jstypes.h"
 
+namespace mozilla {
+
 /*
 ** sprintf into a malloc'd buffer. Return a pointer to the malloc'd
-** buffer on success, nullptr on failure. Call "JS_smprintf_free" to release
+** buffer on success, nullptr on failure. Call "SmprintfFree" to release
 ** the memory returned.
 */
-extern JS_PUBLIC_API(char*) JS_smprintf(const char* fmt, ...)
+extern MFBT_API char* Smprintf(const char* fmt, ...)
     MOZ_FORMAT_PRINTF(1, 2);
 
 /*
-** Free the memory allocated, for the caller, by JS_smprintf
+** Free the memory allocated, for the caller, by Smprintf
 */
-extern JS_PUBLIC_API(void) JS_smprintf_free(char* mem);
+extern MFBT_API void SmprintfFree(char* mem);
 
 /*
 ** "append" sprintf into a malloc'd buffer. "last" is the last value of
 ** the malloc'd buffer. sprintf will append data to the end of last,
-** growing it as necessary using realloc. If last is nullptr, JS_sprintf_append
+** growing it as necessary using realloc. If last is nullptr, SmprintfAppend
 ** will allocate the initial string. The return value is the new value of
 ** last for subsequent calls, or nullptr if there is a malloc failure.
 */
-extern JS_PUBLIC_API(char*) JS_sprintf_append(char* last, const char* fmt, ...)
+extern MFBT_API char* SmprintfAppend(char* last, const char* fmt, ...)
     MOZ_FORMAT_PRINTF(2, 3);
 
 /*
 ** va_list forms of the above.
 */
+extern MFBT_API char* Vsmprintf(const char* fmt, va_list ap);
+extern MFBT_API char* VsmprintfAppend(char* last, const char* fmt, va_list ap);
+
+} // namespace mozilla
+
+/* Wrappers for mozilla::Smprintf and friends that are used throughout
+   JS.  */
+
+extern JS_PUBLIC_API(char*) JS_smprintf(const char* fmt, ...)
+    MOZ_FORMAT_PRINTF(1, 2);
+
+extern JS_PUBLIC_API(void) JS_smprintf_free(char* mem);
+
+extern JS_PUBLIC_API(char*) JS_sprintf_append(char* last, const char* fmt, ...)
+     MOZ_FORMAT_PRINTF(2, 3);
+
 extern JS_PUBLIC_API(char*) JS_vsmprintf(const char* fmt, va_list ap);
 extern JS_PUBLIC_API(char*) JS_vsprintf_append(char* last, const char* fmt, va_list ap);
 
 #endif /* jsprf_h */