@@ -129,10 +129,9 @@ pub const ChildProcess = struct {
129
129
/// POSIX-only. `StdIo.Ignore` was selected and opening `/dev/null` returned ENODEV.
130
130
NoDevice ,
131
131
132
- /// Windows-only. One of:
133
- /// * `cwd` was provided and it could not be re-encoded into UTF16LE, or
134
- /// * The `PATH` or `PATHEXT` environment variable contained invalid UTF-8.
135
- InvalidUtf8 ,
132
+ /// Windows-only. `cwd` or `argv` was provided and it was invalid WTF-8.
133
+ /// https://simonsapin.github.io/wtf-8/
134
+ InvalidWtf8 ,
136
135
137
136
/// Windows-only. `cwd` was provided, but the path did not exist when spawning the child process.
138
137
CurrentWorkingDirectoryUnlinked ,
@@ -767,16 +766,16 @@ pub const ChildProcess = struct {
767
766
};
768
767
var piProcInfo : windows.PROCESS_INFORMATION = undefined ;
769
768
770
- const cwd_w = if (self .cwd ) | cwd | try unicode .utf8ToUtf16LeAllocZ (self .allocator , cwd ) else null ;
769
+ const cwd_w = if (self .cwd ) | cwd | try unicode .wtf8ToWtf16LeAllocZ (self .allocator , cwd ) else null ;
771
770
defer if (cwd_w ) | cwd | self .allocator .free (cwd );
772
771
const cwd_w_ptr = if (cwd_w ) | cwd | cwd .ptr else null ;
773
772
774
773
const maybe_envp_buf = if (self .env_map ) | env_map | try createWindowsEnvBlock (self .allocator , env_map ) else null ;
775
774
defer if (maybe_envp_buf ) | envp_buf | self .allocator .free (envp_buf );
776
775
const envp_ptr = if (maybe_envp_buf ) | envp_buf | envp_buf .ptr else null ;
777
776
778
- const app_name_utf8 = self .argv [0 ];
779
- const app_name_is_absolute = fs .path .isAbsolute (app_name_utf8 );
777
+ const app_name_wtf8 = self .argv [0 ];
778
+ const app_name_is_absolute = fs .path .isAbsolute (app_name_wtf8 );
780
779
781
780
// the cwd set in ChildProcess is in effect when choosing the executable path
782
781
// to match posix semantics
@@ -785,11 +784,11 @@ pub const ChildProcess = struct {
785
784
// If the app name is absolute, then we need to use its dirname as the cwd
786
785
if (app_name_is_absolute ) {
787
786
cwd_path_w_needs_free = true ;
788
- const dir = fs .path .dirname (app_name_utf8 ).? ;
789
- break :x try unicode .utf8ToUtf16LeAllocZ (self .allocator , dir );
787
+ const dir = fs .path .dirname (app_name_wtf8 ).? ;
788
+ break :x try unicode .wtf8ToWtf16LeAllocZ (self .allocator , dir );
790
789
} else if (self .cwd ) | cwd | {
791
790
cwd_path_w_needs_free = true ;
792
- break :x try unicode .utf8ToUtf16LeAllocZ (self .allocator , cwd );
791
+ break :x try unicode .wtf8ToWtf16LeAllocZ (self .allocator , cwd );
793
792
} else {
794
793
break :x &[_ :0 ]u16 {}; // empty for cwd
795
794
}
@@ -800,19 +799,19 @@ pub const ChildProcess = struct {
800
799
// into the basename and dirname and use the dirname as an addition to the cwd
801
800
// path. This is because NtQueryDirectoryFile cannot accept FileName params with
802
801
// path separators.
803
- const app_basename_utf8 = fs .path .basename (app_name_utf8 );
802
+ const app_basename_wtf8 = fs .path .basename (app_name_wtf8 );
804
803
// If the app name is absolute, then the cwd will already have the app's dirname in it,
805
804
// so only populate app_dirname if app name is a relative path with > 0 path separators.
806
- const maybe_app_dirname_utf8 = if (! app_name_is_absolute ) fs .path .dirname (app_name_utf8 ) else null ;
805
+ const maybe_app_dirname_wtf8 = if (! app_name_is_absolute ) fs .path .dirname (app_name_wtf8 ) else null ;
807
806
const app_dirname_w : ? [:0 ]u16 = x : {
808
- if (maybe_app_dirname_utf8 ) | app_dirname_utf8 | {
809
- break :x try unicode .utf8ToUtf16LeAllocZ (self .allocator , app_dirname_utf8 );
807
+ if (maybe_app_dirname_wtf8 ) | app_dirname_wtf8 | {
808
+ break :x try unicode .wtf8ToWtf16LeAllocZ (self .allocator , app_dirname_wtf8 );
810
809
}
811
810
break :x null ;
812
811
};
813
812
defer if (app_dirname_w != null ) self .allocator .free (app_dirname_w .? );
814
813
815
- const app_name_w = try unicode .utf8ToUtf16LeAllocZ (self .allocator , app_basename_utf8 );
814
+ const app_name_w = try unicode .wtf8ToWtf16LeAllocZ (self .allocator , app_basename_wtf8 );
816
815
defer self .allocator .free (app_name_w );
817
816
818
817
const cmd_line_w = argvToCommandLineWindows (self .allocator , self .argv ) catch | err | switch (err ) {
@@ -1173,7 +1172,7 @@ const CreateProcessSupportedExtension = enum {
1173
1172
exe ,
1174
1173
};
1175
1174
1176
- /// Case-insensitive UTF -16 lookup
1175
+ /// Case-insensitive WTF -16 lookup
1177
1176
fn windowsCreateProcessSupportsExtension (ext : []const u16 ) ? CreateProcessSupportedExtension {
1178
1177
if (ext .len != 4 ) return null ;
1179
1178
const State = enum {
@@ -1237,7 +1236,7 @@ test "windowsCreateProcessSupportsExtension" {
1237
1236
try std .testing .expect (windowsCreateProcessSupportsExtension (&[_ ]u16 { '.' , 'e' , 'X' , 'e' , 'c' }) == null );
1238
1237
}
1239
1238
1240
- pub const ArgvToCommandLineError = error { OutOfMemory , InvalidUtf8 , InvalidArg0 };
1239
+ pub const ArgvToCommandLineError = error { OutOfMemory , InvalidWtf8 , InvalidArg0 };
1241
1240
1242
1241
/// Serializes `argv` to a Windows command-line string suitable for passing to a child process and
1243
1242
/// parsing by the `CommandLineToArgvW` algorithm. The caller owns the returned slice.
@@ -1320,7 +1319,7 @@ pub fn argvToCommandLineWindows(
1320
1319
}
1321
1320
}
1322
1321
1323
- return try unicode .utf8ToUtf16LeAllocZ (allocator , buf .items );
1322
+ return try unicode .wtf8ToWtf16LeAllocZ (allocator , buf .items );
1324
1323
}
1325
1324
1326
1325
test "argvToCommandLineWindows" {
@@ -1386,7 +1385,7 @@ fn testArgvToCommandLineWindows(argv: []const []const u8, expected_cmd_line: []c
1386
1385
const cmd_line_w = try argvToCommandLineWindows (std .testing .allocator , argv );
1387
1386
defer std .testing .allocator .free (cmd_line_w );
1388
1387
1389
- const cmd_line = try unicode .utf16LeToUtf8Alloc (std .testing .allocator , cmd_line_w );
1388
+ const cmd_line = try unicode .wtf16LeToWtf8Alloc (std .testing .allocator , cmd_line_w );
1390
1389
defer std .testing .allocator .free (cmd_line );
1391
1390
1392
1391
try std .testing .expectEqualStrings (expected_cmd_line , cmd_line );
@@ -1424,7 +1423,7 @@ fn windowsMakeAsyncPipe(rd: *?windows.HANDLE, wr: *?windows.HANDLE, sattr: *cons
1424
1423
"\\\\ .\\ pipe\\ zig-childprocess-{d}-{d}" ,
1425
1424
.{ windows .kernel32 .GetCurrentProcessId (), pipe_name_counter .fetchAdd (1 , .Monotonic ) },
1426
1425
) catch unreachable ;
1427
- const len = std .unicode .utf8ToUtf16Le (& tmp_bufw , pipe_path ) catch unreachable ;
1426
+ const len = std .unicode .wtf8ToWtf16Le (& tmp_bufw , pipe_path ) catch unreachable ;
1428
1427
tmp_bufw [len ] = 0 ;
1429
1428
break :blk tmp_bufw [0.. len :0 ];
1430
1429
};
@@ -1521,10 +1520,10 @@ pub fn createWindowsEnvBlock(allocator: mem.Allocator, env_map: *const EnvMap) !
1521
1520
var it = env_map .iterator ();
1522
1521
var i : usize = 0 ;
1523
1522
while (it .next ()) | pair | {
1524
- i += try unicode .utf8ToUtf16Le (result [i .. ], pair .key_ptr .* );
1523
+ i += try unicode .wtf8ToWtf16Le (result [i .. ], pair .key_ptr .* );
1525
1524
result [i ] = '=' ;
1526
1525
i += 1 ;
1527
- i += try unicode .utf8ToUtf16Le (result [i .. ], pair .value_ptr .* );
1526
+ i += try unicode .wtf8ToWtf16Le (result [i .. ], pair .value_ptr .* );
1528
1527
result [i ] = 0 ;
1529
1528
i += 1 ;
1530
1529
}
0 commit comments