summaryrefslogtreecommitdiff
path: root/misc/cgo/life
diff options
context:
space:
mode:
authorOndřej Surý <ondrej@sury.org>2011-01-17 12:40:45 +0100
committerOndřej Surý <ondrej@sury.org>2011-01-17 12:40:45 +0100
commit3e45412327a2654a77944249962b3652e6142299 (patch)
treebc3bf69452afa055423cbe0c5cfa8ca357df6ccf /misc/cgo/life
parentc533680039762cacbc37db8dc7eed074c3e497be (diff)
downloadgolang-upstream/2011.01.12.tar.gz
Imported Upstream version 2011.01.12upstream/2011.01.12
Diffstat (limited to 'misc/cgo/life')
-rw-r--r--misc/cgo/life/Makefile20
-rw-r--r--misc/cgo/life/c-life.c2
-rw-r--r--misc/cgo/life/golden.out17
-rw-r--r--misc/cgo/life/life.go2
-rw-r--r--misc/cgo/life/life.h1
-rw-r--r--misc/cgo/life/main.go2
-rwxr-xr-xmisc/cgo/life/test.bash11
7 files changed, 38 insertions, 17 deletions
diff --git a/misc/cgo/life/Makefile b/misc/cgo/life/Makefile
index cbcdc9927..5a10380ed 100644
--- a/misc/cgo/life/Makefile
+++ b/misc/cgo/life/Makefile
@@ -2,30 +2,20 @@
# Use of this source code is governed by a BSD-style
# license that can be found in the LICENSE file.
-include ../../../src/Make.$(GOARCH)
+include ../../../src/Make.inc
TARG=life
CGOFILES=\
- life.go
+ life.go\
-LDPATH_freebsd=-Wl,-R,`pwd`
-LDPATH_linux=-Wl,-R,`pwd`
-LDPATH_darwin=
+CGO_OFILES=\
+ c-life.o\
-CGO_LDFLAGS=_cgo_export.o c-life.so $(LDPATH_$(GOOS))
-CGO_DEPS=_cgo_export.o c-life.so
-
-CLEANFILES += life
+CLEANFILES+=life
include ../../../src/Make.pkg
-c-life.o: c-life.c _cgo_export.h
- gcc $(_CGO_CFLAGS_$(GOARCH)) -g -c -fPIC $(CFLAGS) c-life.c
-
-c-life.so: c-life.o
- gcc $(_CGO_CFLAGS_$(GOARCH)) -o $@ c-life.o $(_CGO_LDFLAGS_$(GOOS))
-
life: install main.go
$(GC) main.go
$(LD) -o $@ main.$O
diff --git a/misc/cgo/life/c-life.c b/misc/cgo/life/c-life.c
index 71555a9c7..657245595 100644
--- a/misc/cgo/life/c-life.c
+++ b/misc/cgo/life/c-life.c
@@ -6,6 +6,8 @@
#include "life.h"
#include "_cgo_export.h"
+const int MYCONST = 0;
+
// Do the actual manipulation of the life board in C. This could be
// done easily in Go, we are just using C for demonstration
// purposes.
diff --git a/misc/cgo/life/golden.out b/misc/cgo/life/golden.out
new file mode 100644
index 000000000..539d2106d
--- /dev/null
+++ b/misc/cgo/life/golden.out
@@ -0,0 +1,17 @@
+* life
+
+
+ XXX XXX
+
+
+
+
+
+
+
+ XXX XXX
+
+
+
+
+
diff --git a/misc/cgo/life/life.go b/misc/cgo/life/life.go
index 036802853..ec000ce3a 100644
--- a/misc/cgo/life/life.go
+++ b/misc/cgo/life/life.go
@@ -23,7 +23,7 @@ var chans [4]chan bool
//export GoStart
// Double return value is just for testing.
func GoStart(i, xdim, ydim, xstart, xend, ystart, yend C.int, a *C.int, n *C.int) (int, int) {
- c := make(chan bool)
+ c := make(chan bool, int(C.MYCONST))
go func() {
C.DoStep(xdim, ydim, xstart, xend, ystart, yend, a, n)
c <- true
diff --git a/misc/cgo/life/life.h b/misc/cgo/life/life.h
index b6e94cf1d..b2011b25f 100644
--- a/misc/cgo/life/life.h
+++ b/misc/cgo/life/life.h
@@ -4,3 +4,4 @@
extern void Step(int, int, int *, int *);
extern void DoStep(int, int, int, int, int, int, int *, int *);
+extern const int MYCONST;
diff --git a/misc/cgo/life/main.go b/misc/cgo/life/main.go
index 7c2c0c73e..9cfed434b 100644
--- a/misc/cgo/life/main.go
+++ b/misc/cgo/life/main.go
@@ -29,7 +29,7 @@ func main() {
}
}
- life.Run(*gen, *dim, *dim, &a)
+ life.Run(*gen, *dim, *dim, a[:])
for i := 0; i < *dim; i++ {
for j := 0; j < *dim; j++ {
diff --git a/misc/cgo/life/test.bash b/misc/cgo/life/test.bash
new file mode 100755
index 000000000..5c5fba1a9
--- /dev/null
+++ b/misc/cgo/life/test.bash
@@ -0,0 +1,11 @@
+#!/bin/sh
+# Copyright 2010 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.
+
+set -e
+gomake life
+echo '*' life >run.out
+./life >>run.out
+diff run.out golden.out
+gomake clean