Navigation Menu

Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

x/sys/unix: Utsname is using [65]int8 for all its struct members #20753

Closed
mvo5 opened this issue Jun 22, 2017 · 3 comments
Closed

x/sys/unix: Utsname is using [65]int8 for all its struct members #20753

mvo5 opened this issue Jun 22, 2017 · 3 comments

Comments

@mvo5
Copy link
Contributor

mvo5 commented Jun 22, 2017

Please answer these questions before submitting your issue. Thanks!

What version of Go are you using (go version)?

go version go1.7.4 linux/amd64

What operating system and processor architecture are you using (go env)?

OARCH="amd64"
GOBIN=""
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH="/home/mvo/devel/go"
GORACE=""
GOROOT="/usr/lib/go-1.7"
GOTOOLDIR="/usr/lib/go-1.7/pkg/tool/linux_amd64"
CC="gcc"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build701945664=/tmp/go-build -gno-record-gcc-switches"
CXX="g++"
CGO_ENABLED="1"

What did you do?

I want to get information from unix.Uname() - this works fine, however the fact that Utsname has all members as int8 is making working with the result a bit cumbersome. It would be simpler if this would be a [65]byte instead because than the bytes package can be used on it. Unless I miss something the only ways to convert this are:

package main

import (
	"bytes"
	"golang.org/x/sys/unix"
	"unsafe"
)

func main() {
	var utsname unix.Utsname
	unix.Uname(&utsname)

	// convert using unsafe.Pointer()
        p := (*[len(utsname.Machine)]byte)(unsafe.Pointer(&utsname.Machine))
	println(string(p[:]))
	
	// iterate and convert
	buf := make([]byte, 0, len(utsname.Machine))
	for _, i := range utsname.Machine {
		buf = append(buf, byte(i))
	}
	println(string(buf))
}

What did you expect to see?

Ideally a simple println(string(utsname.Machine[:])) would be enough to convert it to a string without the need for the unsafe.Pointer() casting.

I am happy to work on a PR if there is a chance for this to get accepted.

@gopherbot gopherbot added this to the Unreleased milestone Jun 22, 2017
@bradfitz bradfitz changed the title x/sys/unix Utsname is using [65}int8 for all its struct members x/sys/unix: Utsname is using [65]int8 for all its struct members Jun 22, 2017
@bradfitz
Copy link
Contributor

Changing it in x/sys/unix seems fine to me. We just can't really change any version in the syscall package.

@ianlancetaylor ?

@ianlancetaylor
Copy link
Contributor

I agree that we can't change it in syscall. I suppose we could change it in x/sys/unix. It would be nicer going forward, but it could break some existing programs that use it. But there are probably very few, and they are easy to fix. I guess we should change it. Thanks.

@gopherbot
Copy link

Change https://golang.org/cl/74331 mentions this issue: unix: convert Utsname members from int8 array to byte array

tklauser added a commit to tklauser/moby that referenced this issue Oct 31, 2017
Update golang.org/x/sys to 95c6576299259db960f6c5b9b69ea52422860fce in
order to get the unix.Utsname with byte array instead of int8/uint8
members.

This allows to use simple byte slice to string conversions instead of
using charsToString or its open-coded version.

Also see golang/go#20753 for details.

Signed-off-by: Tobias Klauser <tklauser@distanz.ch>
salah-khan pushed a commit to salah-khan/moby that referenced this issue Nov 15, 2017
Update golang.org/x/sys to 95c6576299259db960f6c5b9b69ea52422860fce in
order to get the unix.Utsname with byte array instead of int8/uint8
members.

This allows to use simple byte slice to string conversions instead of
using charsToString or its open-coded version.

Also see golang/go#20753 for details.

Signed-off-by: Tobias Klauser <tklauser@distanz.ch>
andrewhsu pushed a commit to docker/docker-ce that referenced this issue Nov 29, 2017
Update golang.org/x/sys to 95c6576299259db960f6c5b9b69ea52422860fce in
order to get the unix.Utsname with byte array instead of int8/uint8
members.

This allows to use simple byte slice to string conversions instead of
using charsToString or its open-coded version.

Also see golang/go#20753 for details.

Signed-off-by: Tobias Klauser <tklauser@distanz.ch>
Upstream-commit: 6d068bc
Component: engine
@golang golang locked and limited conversation to collaborators Oct 31, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants