]> Cypherpunks.ru repositories - gostls13.git/commitdiff
gc: unsafe.Alignof, unsafe.Offsetof, unsafe.Sizeof now return uintptr
authorRuss Cox <rsc@golang.org>
Fri, 17 Jun 2011 20:12:14 +0000 (16:12 -0400)
committerRuss Cox <rsc@golang.org>
Fri, 17 Jun 2011 20:12:14 +0000 (16:12 -0400)
R=ken2
CC=golang-dev
https://golang.org/cl/4640045

24 files changed:
src/cmd/gc/builtin.c.boot
src/cmd/gc/unsafe.c
src/cmd/gc/unsafe.go
src/pkg/gob/decode.go
src/pkg/gob/encode.go
src/pkg/hash/fnv/fnv.go
src/pkg/reflect/type.go
src/pkg/reflect/value.go
src/pkg/runtime/malloc.goc
src/pkg/runtime/mem.go
src/pkg/runtime/pprof/pprof_test.go
src/pkg/syscall/exec_unix.go
src/pkg/syscall/syscall_bsd.go
src/pkg/syscall/syscall_linux.go
src/pkg/syscall/syscall_linux_386.go
src/pkg/syscall/syscall_linux_amd64.go
src/pkg/syscall/syscall_linux_arm.go
src/pkg/syscall/zsyscall_darwin_386.go
src/pkg/syscall/zsyscall_darwin_amd64.go
src/pkg/syscall/zsyscall_freebsd_386.go
src/pkg/syscall/zsyscall_freebsd_amd64.go
src/pkg/syscall/zsyscall_linux_amd64.go
src/pkg/syscall/zsyscall_linux_arm.go
test/sizeof.go [new file with mode: 0644]

index 7659ac5bb3d726ad60171e61a3c89e0ed1e26e79..95098c8afa3c83a43a2be6f456de616907711213 100644 (file)
@@ -103,9 +103,9 @@ char *unsafeimport =
        "package unsafe\n"
        "import runtime \"runtime\"\n"
        "type \"\".Pointer uintptr\n"
-       "func \"\".Offsetof (? any) int\n"
-       "func \"\".Sizeof (? any) int\n"
-       "func \"\".Alignof (? any) int\n"
+       "func \"\".Offsetof (? any) uintptr\n"
+       "func \"\".Sizeof (? any) uintptr\n"
+       "func \"\".Alignof (? any) uintptr\n"
        "func \"\".Typeof (i interface { }) interface { }\n"
        "func \"\".Reflect (i interface { }) (typ interface { }, addr \"\".Pointer)\n"
        "func \"\".Unreflect (typ interface { }, addr \"\".Pointer) interface { }\n"
index 540994dddb12cd37abd0c4b8a374639cd483c5f4..d304077c8e1bb5addb1e9da958b7912d3a291021 100644 (file)
@@ -92,6 +92,6 @@ ret:
        mpmovecfix(val.u.xval, v);
        n = nod(OLITERAL, N, N);
        n->val = val;
-       n->type = types[TINT];
+       n->type = types[TUINTPTR];
        return n;
 }
index b2a341d39154e32dee260ade9ff93348a2c9dfb1..db27d7425facaf47f083c66f08890792b379a2bb 100644 (file)
@@ -10,9 +10,11 @@ package PACKAGE
 
 type Pointer uintptr // not really; filled in by compiler
 
-func Offsetof(any) int
-func Sizeof(any) int
-func Alignof(any) int
+// return types here are ignored; see unsafe.c
+func Offsetof(any) uintptr
+func Sizeof(any) uintptr
+func Alignof(any) uintptr
+
 func Typeof(i interface{}) (typ interface{})
 func Reflect(i interface{}) (typ interface{}, addr Pointer)
 func Unreflect(typ interface{}, addr Pointer) (ret interface{})
index 381d44c05a079c3fa3a775fde657ff196b0c1ae2..f56d72a6a6e302cd1e1b0c846e84ac94f48b20da 100644 (file)
@@ -367,7 +367,7 @@ func decComplex64(i *decInstr, state *decoderState, p unsafe.Pointer) {
                p = *(*unsafe.Pointer)(p)
        }
        storeFloat32(i, state, p)
-       storeFloat32(i, state, unsafe.Pointer(uintptr(p)+uintptr(unsafe.Sizeof(float32(0)))))
+       storeFloat32(i, state, unsafe.Pointer(uintptr(p)+unsafe.Sizeof(float32(0))))
 }
 
 // decComplex128 decodes a pair of unsigned integers, treats them as a
index f9e691a2fa66eb19c8e06cf9ad7509579e49e58e..743e853e941aa275776e051a04c43a5f8c41a97e 100644 (file)
@@ -11,7 +11,7 @@ import (
        "unsafe"
 )
 
-const uint64Size = unsafe.Sizeof(uint64(0))
+const uint64Size = int(unsafe.Sizeof(uint64(0)))
 
 // encoderState is the global execution state of an instance of the encoder.
 // Field numbers are delta encoded and always increase. The field
index 9a1c6a0f2db97989ab3e891e76876f95f545053d..3ff7d7c75d7a2562b75d41be35c524260ec276ca 100644 (file)
@@ -11,7 +11,6 @@ import (
        "encoding/binary"
        "hash"
        "os"
-       "unsafe"
 )
 
 type (
@@ -102,31 +101,31 @@ func (s *sum64a) Write(data []byte) (int, os.Error) {
        return len(data), nil
 }
 
-func (s *sum32) Size() int  { return unsafe.Sizeof(*s) }
-func (s *sum32a) Size() int { return unsafe.Sizeof(*s) }
-func (s *sum64) Size() int  { return unsafe.Sizeof(*s) }
-func (s *sum64a) Size() int { return unsafe.Sizeof(*s) }
+func (s *sum32) Size() int  { return 4 }
+func (s *sum32a) Size() int { return 4 }
+func (s *sum64) Size() int  { return 8 }
+func (s *sum64a) Size() int { return 8 }
 
 func (s *sum32) Sum() []byte {
-       a := make([]byte, unsafe.Sizeof(*s))
+       a := make([]byte, 4)
        binary.BigEndian.PutUint32(a, uint32(*s))
        return a
 }
 
 func (s *sum32a) Sum() []byte {
-       a := make([]byte, unsafe.Sizeof(*s))
+       a := make([]byte, 4)
        binary.BigEndian.PutUint32(a, uint32(*s))
        return a
 }
 
 func (s *sum64) Sum() []byte {
-       a := make([]byte, unsafe.Sizeof(*s))
+       a := make([]byte, 8)
        binary.BigEndian.PutUint64(a, uint64(*s))
        return a
 }
 
 func (s *sum64a) Sum() []byte {
-       a := make([]byte, unsafe.Sizeof(*s))
+       a := make([]byte, 8)
        binary.BigEndian.PutUint64(a, uint64(*s))
        return a
 }
index aef6370dbcbe5f88478a9fa01766b222ce8c6697..6c1ab60982d185982e3367a4890c83e283dbc834 100644 (file)
@@ -827,7 +827,7 @@ func (t *commonType) runtimeType() *runtime.Type {
                i  runtime.Type
                ct commonType
        }
-       return (*runtime.Type)(unsafe.Pointer(uintptr(unsafe.Pointer(t)) - uintptr(unsafe.Offsetof(rt.ct))))
+       return (*runtime.Type)(unsafe.Pointer(uintptr(unsafe.Pointer(t)) - unsafe.Offsetof(rt.ct)))
 }
 
 // PtrTo returns the pointer type with element t.
@@ -888,7 +888,7 @@ func PtrTo(t Type) Type {
 
        p.uncommonType = nil
        p.ptrToThis = nil
-       p.elem = (*runtime.Type)(unsafe.Pointer(uintptr(unsafe.Pointer(ct)) - uintptr(unsafe.Offsetof(rt.ptrType))))
+       p.elem = (*runtime.Type)(unsafe.Pointer(uintptr(unsafe.Pointer(ct)) - unsafe.Offsetof(rt.ptrType)))
 
        ptrMap.m[ct] = p
        ptrMap.Unlock()
index 3abe13e04dc3cc155c3e5267b980cd97afcb71a6..b1999aa6348c5b4f4ec268812fd4ddc6df53cd27 100644 (file)
@@ -11,7 +11,7 @@ import (
        "unsafe"
 )
 
-const ptrSize = uintptr(unsafe.Sizeof((*byte)(nil)))
+const ptrSize = unsafe.Sizeof((*byte)(nil))
 const cannotSet = "cannot set value obtained from unexported struct field"
 
 // TODO: This will have to go away when
index c55be97729676984cd9d811c90c6ef3780c65f70..49ab24df86eabd896b2cbe9b0f047153d492b7bf 100644 (file)
@@ -229,7 +229,7 @@ runtime·allocmcache(void)
        return c;
 }
 
-int32 runtime·sizeof_C_MStats = sizeof(MStats);
+uintptr runtime·sizeof_C_MStats = sizeof(MStats);
 
 #define MaxArena32 (2U<<30)
 
index fe505a329296c3cd7fa8a4c5f5ed1f56595d815e..c3316d44c0df835000504348afeea50bd0bdf3e7 100644 (file)
@@ -52,7 +52,7 @@ type MemStatsType struct {
        }
 }
 
-var sizeof_C_MStats int // filled in by malloc.goc
+var sizeof_C_MStats uintptr // filled in by malloc.goc
 
 func init() {
        if sizeof_C_MStats != unsafe.Sizeof(MemStats) {
index a060917a280871e3040de554f238ece6ec3f5fb1..4486d5525f7d6e1c524853760cdf6fa5435b8b51 100644 (file)
@@ -43,7 +43,7 @@ func TestCPUProfile(t *testing.T) {
        // Convert []byte to []uintptr.
        bytes := prof.Bytes()
        val := *(*[]uintptr)(unsafe.Pointer(&bytes))
-       val = val[:len(bytes)/unsafe.Sizeof(uintptr(0))]
+       val = val[:len(bytes)/int(unsafe.Sizeof(uintptr(0)))]
 
        if len(val) < 10 {
                t.Fatalf("profile too short: %#x", val)
index a6ac3983df4d182428007372a9cb03e2b4c96f08..4b3cfe47fc9d5cb9a817ad631dbd005e9f158433 100644 (file)
@@ -249,7 +249,7 @@ func forkAndExecInChild(argv0 *byte, argv, envv []*byte, chroot, dir *byte, attr
 
 childerror:
        // send error code on pipe
-       RawSyscall(SYS_WRITE, uintptr(pipe), uintptr(unsafe.Pointer(&err1)), uintptr(unsafe.Sizeof(err1)))
+       RawSyscall(SYS_WRITE, uintptr(pipe), uintptr(unsafe.Pointer(&err1)), unsafe.Sizeof(err1))
        for {
                RawSyscall(SYS_EXIT, 253, 0, 0)
        }
@@ -343,10 +343,10 @@ func forkExec(argv0 string, argv []string, attr *ProcAttr) (pid int, err int) {
 
        // Read child error status from pipe.
        Close(p[1])
-       n, err = read(p[0], (*byte)(unsafe.Pointer(&err1)), unsafe.Sizeof(err1))
+       n, err = read(p[0], (*byte)(unsafe.Pointer(&err1)), int(unsafe.Sizeof(err1)))
        Close(p[0])
        if err != 0 || n != 0 {
-               if n == unsafe.Sizeof(err1) {
+               if n == int(unsafe.Sizeof(err1)) {
                        err = int(err1)
                }
                if err == 0 {
index 89bcc7f0e3fd38634759bd95b37d9128852a774b..321d9d36bb7b576a563f9211d06dc2d2f5865f56 100644 (file)
@@ -155,7 +155,7 @@ func Sleep(ns int64) (errno int) {
 //sys  connect(s int, addr uintptr, addrlen _Socklen) (errno int)
 //sysnb        socket(domain int, typ int, proto int) (fd int, errno int)
 //sys  getsockopt(s int, level int, name int, val uintptr, vallen *_Socklen) (errno int)
-//sys  setsockopt(s int, level int, name int, val uintptr, vallen int) (errno int)
+//sys  setsockopt(s int, level int, name int, val uintptr, vallen uintptr) (errno int)
 //sysnb        getpeername(fd int, rsa *RawSockaddrAny, addrlen *_Socklen) (errno int)
 //sysnb        getsockname(fd int, rsa *RawSockaddrAny, addrlen *_Socklen) (errno int)
 //sys  Shutdown(s int, how int) (errno int)
@@ -451,7 +451,7 @@ func Kevent(kq int, changes, events []Kevent_t, timeout *Timespec) (n int, errno
 
 // Translate "kern.hostname" to []_C_int{0,1,2,3}.
 func nametomib(name string) (mib []_C_int, errno int) {
-       const siz = uintptr(unsafe.Sizeof(mib[0]))
+       const siz = unsafe.Sizeof(mib[0])
 
        // NOTE(rsc): It seems strange to set the buffer to have
        // size CTL_MAXNAME+2 but use only CTL_MAXNAME
index 63682d23c49ee92991042ae4ebe4a897dbc50335..3b8f36da6388fe6556427d0e039ed4164a475d2a 100644 (file)
@@ -472,7 +472,7 @@ func SetsockoptIPv6Mreq(fd, level, opt int, mreq *IPv6Mreq) (errno int) {
 }
 
 func SetsockoptString(fd, level, opt int, s string) (errno int) {
-       return setsockopt(fd, level, opt, uintptr(unsafe.Pointer(&[]byte(s)[0])), len(s))
+       return setsockopt(fd, level, opt, uintptr(unsafe.Pointer(&[]byte(s)[0])), uintptr(len(s)))
 }
 
 func Recvfrom(fd int, p []byte, flags int) (n int, from Sockaddr, errno int) {
index 5195179a2cbd0617c0f3b847e524e7b03c177427..44891de873cba0c322c74bb728ca690a79733860 100644 (file)
@@ -146,8 +146,8 @@ func getsockopt(s int, level int, name int, val uintptr, vallen *_Socklen) (errn
        return
 }
 
-func setsockopt(s int, level int, name int, val uintptr, vallen int) (errno int) {
-       _, errno = socketcall(_SETSOCKOPT, uintptr(s), uintptr(level), uintptr(name), uintptr(val), uintptr(vallen), 0)
+func setsockopt(s int, level int, name int, val uintptr, vallen uintptr) (errno int) {
+       _, errno = socketcall(_SETSOCKOPT, uintptr(s), uintptr(level), uintptr(name), val, vallen, 0)
        return
 }
 
@@ -190,13 +190,13 @@ func Shutdown(s, how int) (errno int) {
 }
 
 func Fstatfs(fd int, buf *Statfs_t) (errno int) {
-       _, _, e1 := Syscall(SYS_FSTATFS64, uintptr(fd), uintptr(unsafe.Sizeof(*buf)), uintptr(unsafe.Pointer(buf)))
+       _, _, e1 := Syscall(SYS_FSTATFS64, uintptr(fd), unsafe.Sizeof(*buf), uintptr(unsafe.Pointer(buf)))
        errno = int(e1)
        return
 }
 
 func Statfs(path string, buf *Statfs_t) (errno int) {
-       _, _, e1 := Syscall(SYS_STATFS64, uintptr(unsafe.Pointer(StringBytePtr(path))), uintptr(unsafe.Sizeof(*buf)), uintptr(unsafe.Pointer(buf)))
+       _, _, e1 := Syscall(SYS_STATFS64, uintptr(unsafe.Pointer(StringBytePtr(path))), unsafe.Sizeof(*buf), uintptr(unsafe.Pointer(buf)))
        errno = int(e1)
        return
 }
index db9524668235c30dccde86a39c435a7818be84c3..8b206ad0a303104dd2f216824f114b366943f2bf 100644 (file)
@@ -42,7 +42,7 @@ package syscall
 //sysnb        getgroups(n int, list *_Gid_t) (nn int, errno int)
 //sysnb        setgroups(n int, list *_Gid_t) (errno int)
 //sys  getsockopt(s int, level int, name int, val uintptr, vallen *_Socklen) (errno int)
-//sys  setsockopt(s int, level int, name int, val uintptr, vallen int) (errno int)
+//sys  setsockopt(s int, level int, name int, val uintptr, vallen uintptr) (errno int)
 //sysnb        socket(domain int, typ int, proto int) (fd int, errno int)
 //sysnb        socketpair(domain int, typ int, proto int, fd *[2]int) (errno int)
 //sysnb        getpeername(fd int, rsa *RawSockaddrAny, addrlen *_Socklen) (errno int)
index 37845301ff0cf6fc42d6e11c9fd30769de760086..8c03c765c164b3ae627e90ec13f46146382a3c66 100644 (file)
@@ -71,7 +71,7 @@ func Seek(fd int, offset int64, whence int) (newoffset int64, errno int)
 //sysnb        getgroups(n int, list *_Gid_t) (nn int, errno int) = SYS_GETGROUPS32
 //sysnb        setgroups(n int, list *_Gid_t) (errno int) = SYS_SETGROUPS32
 //sys  getsockopt(s int, level int, name int, val uintptr, vallen *_Socklen) (errno int)
-//sys  setsockopt(s int, level int, name int, val uintptr, vallen int) (errno int)
+//sys  setsockopt(s int, level int, name int, val uintptr, vallen uintptr) (errno int)
 //sysnb        socket(domain int, typ int, proto int) (fd int, errno int)
 //sysnb        getpeername(fd int, rsa *RawSockaddrAny, addrlen *_Socklen) (errno int)
 //sysnb        getsockname(fd int, rsa *RawSockaddrAny, addrlen *_Socklen) (errno int)
index 13a8ed0f67a71cdfed02ddb15804c8b518ef9dd6..bbaceee19638ebb04a20fa835e8f6b625cde831c 100644 (file)
@@ -85,7 +85,7 @@ func getsockopt(s int, level int, name int, val uintptr, vallen *_Socklen) (errn
 
 // THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT
 
-func setsockopt(s int, level int, name int, val uintptr, vallen int) (errno int) {
+func setsockopt(s int, level int, name int, val uintptr, vallen uintptr) (errno int) {
        _, _, e1 := Syscall6(SYS_SETSOCKOPT, uintptr(s), uintptr(level), uintptr(name), uintptr(val), uintptr(vallen), 0)
        errno = int(e1)
        return
index c671d7150e7682b21a5d85992cd5f7dc238353bb..ee39eadc11a6e301f67dda332d9ea746e855e15d 100644 (file)
@@ -85,7 +85,7 @@ func getsockopt(s int, level int, name int, val uintptr, vallen *_Socklen) (errn
 
 // THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT
 
-func setsockopt(s int, level int, name int, val uintptr, vallen int) (errno int) {
+func setsockopt(s int, level int, name int, val uintptr, vallen uintptr) (errno int) {
        _, _, e1 := Syscall6(SYS_SETSOCKOPT, uintptr(s), uintptr(level), uintptr(name), uintptr(val), uintptr(vallen), 0)
        errno = int(e1)
        return
index 0ffb9a4b9f200ec3e60e94894c680e230350921f..4f7fdefba18d4bec89dcde36b48dafa1eb11b0ae 100644 (file)
@@ -85,7 +85,7 @@ func getsockopt(s int, level int, name int, val uintptr, vallen *_Socklen) (errn
 
 // THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT
 
-func setsockopt(s int, level int, name int, val uintptr, vallen int) (errno int) {
+func setsockopt(s int, level int, name int, val uintptr, vallen uintptr) (errno int) {
        _, _, e1 := Syscall6(SYS_SETSOCKOPT, uintptr(s), uintptr(level), uintptr(name), uintptr(val), uintptr(vallen), 0)
        errno = int(e1)
        return
index 38a06ae3b0e7c4b3d6e892339f6572636e664d63..609ecdd2a9ee485a5aed78e0eb1b10e97eea8840 100644 (file)
@@ -85,7 +85,7 @@ func getsockopt(s int, level int, name int, val uintptr, vallen *_Socklen) (errn
 
 // THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT
 
-func setsockopt(s int, level int, name int, val uintptr, vallen int) (errno int) {
+func setsockopt(s int, level int, name int, val uintptr, vallen uintptr) (errno int) {
        _, _, e1 := Syscall6(SYS_SETSOCKOPT, uintptr(s), uintptr(level), uintptr(name), uintptr(val), uintptr(vallen), 0)
        errno = int(e1)
        return
index d6e287967b33426c9150327a5d5ee244d87bf3a2..fa20ff57abc6e177b9519f52edbecd3a18b3f5fa 100644 (file)
@@ -1169,7 +1169,7 @@ func getsockopt(s int, level int, name int, val uintptr, vallen *_Socklen) (errn
 
 // THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT
 
-func setsockopt(s int, level int, name int, val uintptr, vallen int) (errno int) {
+func setsockopt(s int, level int, name int, val uintptr, vallen uintptr) (errno int) {
        _, _, e1 := Syscall6(SYS_SETSOCKOPT, uintptr(s), uintptr(level), uintptr(name), uintptr(val), uintptr(vallen), 0)
        errno = int(e1)
        return
index af5f7c50cfaf1dc07bc7c960648c7c7d4ea2a403..560a65b12ceed228f89d70ffcecf5ea23f33eab5 100644 (file)
@@ -895,7 +895,7 @@ func getsockopt(s int, level int, name int, val uintptr, vallen *_Socklen) (errn
 
 // THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT
 
-func setsockopt(s int, level int, name int, val uintptr, vallen int) (errno int) {
+func setsockopt(s int, level int, name int, val uintptr, vallen uintptr) (errno int) {
        _, _, e1 := Syscall6(SYS_SETSOCKOPT, uintptr(s), uintptr(level), uintptr(name), uintptr(val), uintptr(vallen), 0)
        errno = int(e1)
        return
diff --git a/test/sizeof.go b/test/sizeof.go
new file mode 100644 (file)
index 0000000..544e4c5
--- /dev/null
@@ -0,0 +1,23 @@
+// $G $D/$F.go
+
+// Copyright 2011 The Go Authors.  All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+package main
+
+import "unsafe"
+
+type T struct {
+       X int
+}
+
+var t T
+
+func isUintptr(uintptr) {}
+
+func main() {
+       isUintptr(unsafe.Sizeof(t))
+       isUintptr(unsafe.Alignof(t))
+       isUintptr(unsafe.Offsetof(t.X))
+}