mirror of
https://github.com/rwinkhart/sys.git
synced 2026-08-27 20:36:31 -04:00
windows: document the return type mismatch for CommandLineToArgv
For golang/go#63236. Change-Id: Id6c458e2ee2291e28685d24e86c05702d9fd132a Cq-Include-Trybots: luci.golang.try:x_sys-gotip-windows-amd64-longtest Reviewed-on: https://go-review.googlesource.com/c/sys/+/531175 Reviewed-by: Quim Muntal <quimmuntal@gmail.com> Auto-Submit: Bryan Mills <bcmills@google.com> Reviewed-by: Than McIntosh <thanm@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
This commit is contained in:
committed by
Gopher Robot
parent
e6494535b9
commit
01c413d3ff
+19
-6
@@ -153,22 +153,35 @@ func DecomposeCommandLine(commandLine string) ([]string, error) {
|
|||||||
return nil, errorspkg.New("string with NUL passed to DecomposeCommandLine")
|
return nil, errorspkg.New("string with NUL passed to DecomposeCommandLine")
|
||||||
}
|
}
|
||||||
var argc int32
|
var argc int32
|
||||||
argv8192, err := CommandLineToArgv(&utf16CommandLine[0], &argc)
|
argv, err := commandLineToArgv(&utf16CommandLine[0], &argc)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
defer LocalFree(Handle(unsafe.Pointer(argv8192)))
|
defer LocalFree(Handle(unsafe.Pointer(argv)))
|
||||||
|
|
||||||
var args []string
|
var args []string
|
||||||
// Note: CommandLineToArgv hard-codes an incorrect return type
|
for _, p := range unsafe.Slice(argv, argc) {
|
||||||
// (see https://go.dev/issue/63236).
|
|
||||||
// We use an unsafe.Pointer conversion here to work around it.
|
|
||||||
for _, p := range unsafe.Slice((**uint16)(unsafe.Pointer(argv8192)), argc) {
|
|
||||||
args = append(args, UTF16PtrToString(p))
|
args = append(args, UTF16PtrToString(p))
|
||||||
}
|
}
|
||||||
return args, nil
|
return args, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// CommandLineToArgv parses a Unicode command line string and sets
|
||||||
|
// argc to the number of parsed arguments.
|
||||||
|
//
|
||||||
|
// The returned memory should be freed using a single call to LocalFree.
|
||||||
|
//
|
||||||
|
// Note that although the return type of CommandLineToArgv indicates 8192
|
||||||
|
// entries of up to 8192 characters each, the actual count of parsed arguments
|
||||||
|
// may exceed 8192, and the documentation for CommandLineToArgvW does not mention
|
||||||
|
// any bound on the lengths of the individual argument strings.
|
||||||
|
// (See https://go.dev/issue/63236.)
|
||||||
|
func CommandLineToArgv(cmd *uint16, argc *int32) (argv *[8192]*[8192]uint16, err error) {
|
||||||
|
argp, err := commandLineToArgv(cmd, argc)
|
||||||
|
argv = (*[8192]*[8192]uint16)(unsafe.Pointer(argp))
|
||||||
|
return argv, err
|
||||||
|
}
|
||||||
|
|
||||||
func CloseOnExec(fd Handle) {
|
func CloseOnExec(fd Handle) {
|
||||||
SetHandleInformation(Handle(fd), HANDLE_FLAG_INHERIT, 0)
|
SetHandleInformation(Handle(fd), HANDLE_FLAG_INHERIT, 0)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -238,7 +238,7 @@ func NewCallbackCDecl(fn interface{}) uintptr {
|
|||||||
//sys SetFileAttributes(name *uint16, attrs uint32) (err error) = kernel32.SetFileAttributesW
|
//sys SetFileAttributes(name *uint16, attrs uint32) (err error) = kernel32.SetFileAttributesW
|
||||||
//sys GetFileAttributesEx(name *uint16, level uint32, info *byte) (err error) = kernel32.GetFileAttributesExW
|
//sys GetFileAttributesEx(name *uint16, level uint32, info *byte) (err error) = kernel32.GetFileAttributesExW
|
||||||
//sys GetCommandLine() (cmd *uint16) = kernel32.GetCommandLineW
|
//sys GetCommandLine() (cmd *uint16) = kernel32.GetCommandLineW
|
||||||
//sys CommandLineToArgv(cmd *uint16, argc *int32) (argv *[8192]*[8192]uint16, err error) [failretval==nil] = shell32.CommandLineToArgvW
|
//sys commandLineToArgv(cmd *uint16, argc *int32) (argv **uint16, err error) [failretval==nil] = shell32.CommandLineToArgvW
|
||||||
//sys LocalFree(hmem Handle) (handle Handle, err error) [failretval!=0]
|
//sys LocalFree(hmem Handle) (handle Handle, err error) [failretval!=0]
|
||||||
//sys LocalAlloc(flags uint32, length uint32) (ptr uintptr, err error)
|
//sys LocalAlloc(flags uint32, length uint32) (ptr uintptr, err error)
|
||||||
//sys SetHandleInformation(handle Handle, mask uint32, flags uint32) (err error)
|
//sys SetHandleInformation(handle Handle, mask uint32, flags uint32) (err error)
|
||||||
|
|||||||
@@ -3844,9 +3844,9 @@ func setupUninstallOEMInf(infFileName *uint16, flags SUOI, reserved uintptr) (er
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func CommandLineToArgv(cmd *uint16, argc *int32) (argv *[8192]*[8192]uint16, err error) {
|
func commandLineToArgv(cmd *uint16, argc *int32) (argv **uint16, err error) {
|
||||||
r0, _, e1 := syscall.Syscall(procCommandLineToArgvW.Addr(), 2, uintptr(unsafe.Pointer(cmd)), uintptr(unsafe.Pointer(argc)), 0)
|
r0, _, e1 := syscall.Syscall(procCommandLineToArgvW.Addr(), 2, uintptr(unsafe.Pointer(cmd)), uintptr(unsafe.Pointer(argc)), 0)
|
||||||
argv = (*[8192]*[8192]uint16)(unsafe.Pointer(r0))
|
argv = (**uint16)(unsafe.Pointer(r0))
|
||||||
if argv == nil {
|
if argv == nil {
|
||||||
err = errnoErr(e1)
|
err = errnoErr(e1)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user