[m-rev.] for review: unicode command line arguments on windows

Peter Wang novalazy at gmail.com
Sat Dec 17 09:16:08 AEDT 2011


Oops, I meant to send this yesterday.

On Fri, 16 Dec 2011 04:56:28 +1100 (EST), Julien Fischer <juliensf at csse.unimelb.edu.au> wrote:
> 
> compiler/compile_target_code.m:
>  	Use the wide entry point to the C runtime with MSVC so that
>  	wmain is invoke isntead of main.

invoked instead

> @@ -539,17 +538,15 @@
>       ** Convert wide-character representation of the command line
>       ** arguments to UTF-8.
>       */
> -    "#ifdef MR_WIN32\n"
> +    "#if defined(MR_MSVC)\n"
>       "static char **\n"
> -    "mercury_win32_args(int *argc_ptr)\n"
> +    "mercury_msvc_args(int argc, wchar_t **wargv)\n"
>       "{\n"
> -    "   LPWSTR  *wargv;\n"
>       "   char    **argv;\n"
>       "   int     i;\n"
>       "\n"
> -    "   wargv = CommandLineToArgvW(GetCommandLineW(), argc_ptr);\n"
> -    "   argv = MR_GC_NEW_ARRAY(char *, (*argc_ptr + 1));\n"
> -    "   for (i = 0; i < (*argc_ptr); i++) {\n"
> +    "   argv = MR_GC_NEW_ARRAY(char *, argc + 1);\n"
> +    "   for (i = 0; i < argc; i++) {\n"
>       "       int bytes = WideCharToMultiByte(CP_UTF8, 0, wargv[i], -1,\n"
>       "           NULL, 0, NULL, NULL);\n"
>       "       argv[i] = MR_GC_malloc(bytes);\n"

Actually, we are calling GC_malloc before the GC is initialised.
I think we need to use plain malloc to be safe in some situations(?).

Peter
--------------------------------------------------------------------------
mercury-reviews mailing list
Post messages to:       mercury-reviews at csse.unimelb.edu.au
Administrative Queries: owner-mercury-reviews at csse.unimelb.edu.au
Subscriptions:          mercury-reviews-request at csse.unimelb.edu.au
--------------------------------------------------------------------------



More information about the reviews mailing list