Bug 792625: Fix xpcshell to accept non-ASCII command line arguments on Windows. r=bsmedberg
authorKyle Huey <khuey@kylehuey.com>
Sun, 30 Sep 2012 09:45:05 -0700
changeset 108807 a9c4d0c92df1ab7cbe63193384ddbea24526795b
parent 108806 96f3db193c755b22956b50155b1ad36250df34db
child 108808 18e98f1040c2f97cbba36d144090c74bf9b385b6
push id82
push usershu@rfrn.org
push dateFri, 05 Oct 2012 13:20:22 +0000
reviewersbsmedberg
bugs792625
milestone18.0a1
Bug 792625: Fix xpcshell to accept non-ASCII command line arguments on Windows. r=bsmedberg
js/xpconnect/shell/Makefile.in
js/xpconnect/shell/xpcshell.cpp
toolkit/xre/nsWindowsWMain.cpp
--- a/js/xpconnect/shell/Makefile.in
+++ b/js/xpconnect/shell/Makefile.in
@@ -11,16 +11,20 @@ VPATH		= @srcdir@
 include $(DEPTH)/config/autoconf.mk
 
 MODULE		= xpcshell
 PROGRAM		= xpcshell$(BIN_SUFFIX)
 SDK_BINARY	= $(PROGRAM)
 
 CPPSRCS		= xpcshell.cpp
 
+LOCAL_INCLUDES += \
+  -I$(topsrcdir)/toolkit/xre \
+  $(NULL)
+
 ifeq (cocoa,$(MOZ_WIDGET_TOOLKIT))
 CMMSRCS += xpcshellMacUtils.mm
 endif
 
 ifeq (windows,$(MOZ_WIDGET_TOOLKIT))
   ifdef MOZ_APP_PROFILE
     DEFINES += -DMOZ_APP_PROFILE='"$(MOZ_APP_PROFILE)"'
   else
@@ -58,16 +62,23 @@ ifeq ($(OS_TEST),x86_64)
 WIN32_EXE_LDFLAGS += -STACK:2097152
 endif
 endif
 
 ifeq ($(OS_TEST),ia64)
 LIBS += $(JEMALLOC_LIBS)
 endif
 include $(topsrcdir)/config/config.mk
+
+ifdef _MSC_VER
+# Always enter a Windows program through wmain, whether or not we're
+# a console application.
+WIN32_EXE_LDFLAGS += -ENTRY:wmainCRTStartup
+endif
+
 include $(topsrcdir)/ipc/chromium/chromium-config.mk
 include $(topsrcdir)/config/rules.mk
 
 DEFINES		+= -DJS_THREADSAFE
 
 ifdef MOZ_SHARK
 DEFINES += -DMOZ_SHARK
 CFLAGS += -F/System/Library/PrivateFrameworks
--- a/js/xpconnect/shell/xpcshell.cpp
+++ b/js/xpconnect/shell/xpcshell.cpp
@@ -46,16 +46,23 @@
 #include "xpcpublic.h"
 #include "nsXULAppAPI.h"
 #ifdef XP_MACOSX
 #include "xpcshellMacUtils.h"
 #endif
 #ifdef XP_WIN
 #include <windows.h>
 #include <shlobj.h>
+
+// we want a wmain entry point
+#define XRE_DONT_PROTECT_DLL_LOAD
+#define XRE_WANT_ENVIRON
+#include "nsWindowsWMain.cpp"
+#define snprintf _snprintf
+#define strcasecmp _stricmp
 #endif
 
 #ifdef ANDROID
 #include <android/log.h>
 #endif
 
 #include "nsIScriptSecurityManager.h"
 #include "nsIPrincipal.h"
--- a/toolkit/xre/nsWindowsWMain.cpp
+++ b/toolkit/xre/nsWindowsWMain.cpp
@@ -37,17 +37,21 @@ int main(int argc, char **argv)
   int result = wmain(argcw, argvw);
   LocalFree(argvw);
   return result;
 }
 #endif /* __MINGW32__ */
 
 #define main NS_internal_main
 
+#ifndef XRE_WANT_ENVIRON
 int main(int argc, char **argv);
+#else
+int main(int argc, char **argv, char **envp);
+#endif
 
 static char*
 AllocConvertUTF16toUTF8(const WCHAR *arg)
 {
   // be generous... UTF16 units can expand up to 3 UTF8 units
   int len = wcslen(arg);
   char *s = new char[len * 3 + 1];
   if (!s)
@@ -92,15 +96,21 @@ int wmain(int argc, WCHAR **argv)
   // need to save argvConverted copy for later deletion.
   char **deleteUs = new char*[argc+1];
   if (!deleteUs) {
     FreeAllocStrings(argc, argvConverted);
     return 127;
   }
   for (int i = 0; i < argc; i++)
     deleteUs[i] = argvConverted[i];
+#ifndef XRE_WANT_ENVIRON
   int result = main(argc, argvConverted);
+#else
+  // Force creation of the multibyte _environ variable.
+  getenv("PATH");
+  int result = main(argc, argvConverted, _environ);
+#endif
 
   delete[] argvConverted;
   FreeAllocStrings(argc, deleteUs);
 
   return result;
 }