]> Cypherpunks repositories - gostls13.git/commitdiff
misc/cgo: prepare for 64-bit ints
authorRuss Cox <rsc@golang.org>
Mon, 24 Sep 2012 18:58:45 +0000 (14:58 -0400)
committerRuss Cox <rsc@golang.org>
Mon, 24 Sep 2012 18:58:45 +0000 (14:58 -0400)
In a few places, the existing cgo tests assume that a
Go int is the same as a C int. Making int 64 bits wide
on 64-bit platforms violates this assumption.
Change that code to assume that Go int32 and C int
are the same instead. That's still not great, but it's better,
and I am unaware of any systems we run on where it is not true.

Update #2188.

R=iant, r
CC=golang-dev
https://golang.org/cl/6552064

misc/cgo/life/life.go
misc/cgo/life/main.go
misc/cgo/test/issue1560.go

index bbec4c56fab6e0d61e4dcdc6cea8a95d5b4e8942..fda5495e5f4e77da4e1778c50cbb0d3d2d44825e 100644 (file)
@@ -11,8 +11,8 @@ import "C"
 
 import "unsafe"
 
-func Run(gen, x, y int, a []int) {
-       n := make([]int, x*y)
+func Run(gen, x, y int, a []int32) {
+       n := make([]int32, x*y)
        for i := 0; i < gen; i++ {
                C.Step(C.int(x), C.int(y), (*C.int)(unsafe.Pointer(&a[0])), (*C.int)(unsafe.Pointer(&n[0])))
                copy(a, n)
index dba0965eecf459329f675544dcf5f85f2e161ffe..725e10f76c262b3ce11a78bb7b92ec6c064f262d 100644 (file)
@@ -24,7 +24,7 @@ var gen = flag.Int("gen", 10, "generations")
 func main() {
        flag.Parse()
 
-       var a [MAXDIM * MAXDIM]int
+       var a [MAXDIM * MAXDIM]int32
        for i := 2; i < *dim; i += 8 {
                for j := 2; j < *dim-3; j += 8 {
                        for y := 0; y < 3; y++ {
index 4f49399545ffefc16553523dcf7f4ca22ea22ff9..0f43b8bd0a4e83e0f7a0cfc33656e30419af3d43 100644 (file)
@@ -28,7 +28,7 @@ func parallelSleep(n int) {
 }
 
 //export BackgroundSleep
-func BackgroundSleep(n int) {
+func BackgroundSleep(n int32) {
        go func() {
                C.sleep(C.uint(n))
                sleepDone <- true