Skip to content

Commit

Permalink
CreateProcess needs CREATE_UNICODE_ENVIRONMENT
Browse files Browse the repository at this point in the history
> If the environment block pointed to by lpEnvironment contains
> Unicode characters, be sure that dwCreationFlags includes
> CREATE_UNICODE_ENVIRONMENT. If this parameter is NULL and the
> environment block of the parent process contains Unicode characters,
> you must also ensure that dwCreationFlags includes
> CREATE_UNICODE_ENVIRONMENT.

From [doc1][].

> If this flag is set, the environment block pointed to by
> lpEnvironment uses Unicode characters. Otherwise, the environment
> block uses ANSI characters.

From [doc2][].

This was forgotten from PR ocsigen#843 that switched to Unicode strings on
Windows (including the environment).

[doc1]: https://docs.microsoft.com/en-us/windows/win32/api/processthreadsapi/nf-processthreadsapi-createprocessw
[doc2]: https://docs.microsoft.com/en-us/windows/win32/procthread/process-creation-flags#CREATE_UNICODE_ENVIRONMENT
  • Loading branch information
MisterDA committed Nov 19, 2021
1 parent a6abacb commit 518ed27
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 3 deletions.
2 changes: 1 addition & 1 deletion CHANGES
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@

* Code quality improvement: remove an uneeded Obj.magic (#844, Benoit Montagu).

* On Windows, use the Unicode API in C stubs and functions introduced in OCaml 4.06 to handle Unicode strings. Raise the minimum requirement to OCaml 4.06 (on Windows only). (#843, Antonin Décimo)
* On Windows, use the Unicode API in C stubs and functions introduced in OCaml 4.06 to handle Unicode strings. Raise the minimum requirement to OCaml 4.06 (on Windows only). (#843, #903, Antonin Décimo)

===== 5.4.2 =====

Expand Down
3 changes: 2 additions & 1 deletion src/unix/lwt_process_stubs.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ CAMLprim value lwt_process_create_process(value prog, value cmdline, value env,

STARTUPINFO si;
PROCESS_INFORMATION pi;
DWORD flags = CREATE_UNICODE_ENVIRONMENT;
BOOL ret;

#define string_option(opt) \
Expand All @@ -62,7 +63,7 @@ CAMLprim value lwt_process_create_process(value prog, value cmdline, value env,
si.hStdOutput = get_handle(Field(fds, 1));
si.hStdError = get_handle(Field(fds, 2));

ret = CreateProcess(progs, cmdlines, NULL, NULL, TRUE, 0,
ret = CreateProcess(progs, cmdlines, NULL, NULL, TRUE, flags,
envs, cwds, &si, &pi);
caml_stat_free(progs);
caml_stat_free(cmdlines);
Expand Down
3 changes: 2 additions & 1 deletion src/unix/windows_c/windows_system_job.c
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ CAMLprim value lwt_unix_system_job(value cmdline)
CAMLparam1(cmdline);
STARTUPINFO si;
PROCESS_INFORMATION pi;
DWORD flags = CREATE_UNICODE_ENVIRONMENT;
BOOL ret;

char_os *cmdlines = caml_stat_strdup_to_os(String_val(cmdline));
Expand All @@ -60,7 +61,7 @@ CAMLprim value lwt_unix_system_job(value cmdline)
si.cb = sizeof(si);

ret = CreateProcess(NULL, cmdlines, NULL, NULL, TRUE, 0,
NULL, NULL, &si, &pi);
flags, NULL, &si, &pi);
caml_stat_free(cmdlines);
if (!ret) {
win32_maperr(GetLastError());
Expand Down

0 comments on commit 518ed27

Please sign in to comment.