summaryrefslogtreecommitdiff
path: root/misc/cgo/stdio
diff options
context:
space:
mode:
Diffstat (limited to 'misc/cgo/stdio')
-rw-r--r--misc/cgo/stdio/Makefile3
-rw-r--r--misc/cgo/stdio/align.go78
-rw-r--r--misc/cgo/stdio/hello.go20
-rw-r--r--misc/cgo/stdio/test.go144
-rw-r--r--misc/cgo/stdio/test1.go29
5 files changed, 1 insertions, 273 deletions
diff --git a/misc/cgo/stdio/Makefile b/misc/cgo/stdio/Makefile
index fc925e607..3f7a4c01c 100644
--- a/misc/cgo/stdio/Makefile
+++ b/misc/cgo/stdio/Makefile
@@ -6,10 +6,7 @@ include ../../../src/Make.inc
TARG=stdio
CGOFILES=\
- align.go\
file.go\
- test.go\
- test1.go\
CLEANFILES+=hello fib chain run.out
diff --git a/misc/cgo/stdio/align.go b/misc/cgo/stdio/align.go
deleted file mode 100644
index 6cdfd902f..000000000
--- a/misc/cgo/stdio/align.go
+++ /dev/null
@@ -1,78 +0,0 @@
-package stdio
-
-/*
-#include <stdio.h>
-
-typedef unsigned char Uint8;
-typedef unsigned short Uint16;
-
-typedef enum {
- MOD1 = 0x0000,
- MODX = 0x8000
-} SDLMod;
-
-typedef enum {
- A = 1,
- B = 322,
- SDLK_LAST
-} SDLKey;
-
-typedef struct SDL_keysym {
- Uint8 scancode;
- SDLKey sym;
- SDLMod mod;
- Uint16 unicode;
-} SDL_keysym;
-
-typedef struct SDL_KeyboardEvent {
- Uint8 typ;
- Uint8 which;
- Uint8 state;
- SDL_keysym keysym;
-} SDL_KeyboardEvent;
-
-void makeEvent(SDL_KeyboardEvent *event) {
- unsigned char *p;
- int i;
-
- p = (unsigned char*)event;
- for (i=0; i<sizeof *event; i++) {
- p[i] = i;
- }
-}
-
-int same(SDL_KeyboardEvent* e, Uint8 typ, Uint8 which, Uint8 state, Uint8 scan, SDLKey sym, SDLMod mod, Uint16 uni) {
- return e->typ == typ && e->which == which && e->state == state && e->keysym.scancode == scan && e->keysym.sym == sym && e->keysym.mod == mod && e->keysym.unicode == uni;
-}
-
-void cTest(SDL_KeyboardEvent *event) {
- printf("C: %#x %#x %#x %#x %#x %#x %#x\n", event->typ, event->which, event->state,
- event->keysym.scancode, event->keysym.sym, event->keysym.mod, event->keysym.unicode);
- fflush(stdout);
-}
-
-*/
-import "C"
-
-import (
- "fmt"
- "syscall"
-)
-
-func TestAlign() {
- if syscall.ARCH == "amd64" {
- // alignment is known to be broken on amd64.
- // http://code.google.com/p/go/issues/detail?id=609
- return
- }
- var evt C.SDL_KeyboardEvent
- C.makeEvent(&evt)
- if C.same(&evt, evt.typ, evt.which, evt.state, evt.keysym.scancode, evt.keysym.sym, evt.keysym.mod, evt.keysym.unicode) == 0 {
- fmt.Println("*** bad alignment")
- C.cTest(&evt)
- fmt.Printf("Go: %#x %#x %#x %#x %#x %#x %#x\n",
- evt.typ, evt.which, evt.state, evt.keysym.scancode,
- evt.keysym.sym, evt.keysym.mod, evt.keysym.unicode)
- fmt.Println(evt)
- }
-}
diff --git a/misc/cgo/stdio/hello.go b/misc/cgo/stdio/hello.go
index 9cb6e6884..58fc6d574 100644
--- a/misc/cgo/stdio/hello.go
+++ b/misc/cgo/stdio/hello.go
@@ -4,26 +4,8 @@
package main
-import (
- "os"
- "stdio"
-)
+import "stdio"
func main() {
stdio.Stdout.WriteString(stdio.Greeting + "\n")
-
- l := stdio.Atol("123")
- if l != 123 {
- println("Atol 123: ", l)
- panic("bad atol")
- }
-
- n, err := stdio.Strtol("asdf", 123)
- if n != 0 || err != os.EINVAL {
- println("Strtol: ", n, err)
- panic("bad atoi2")
- }
-
- stdio.TestAlign()
- stdio.TestEnum()
}
diff --git a/misc/cgo/stdio/test.go b/misc/cgo/stdio/test.go
deleted file mode 100644
index 8f21603ca..000000000
--- a/misc/cgo/stdio/test.go
+++ /dev/null
@@ -1,144 +0,0 @@
-// 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.
-
-// This file contains test cases for cgo.
-
-package stdio
-
-/*
-#include <stdio.h>
-#include <stdlib.h>
-#include <sys/stat.h>
-#include <errno.h>
-
-#define SHIFT(x, y) ((x)<<(y))
-#define KILO SHIFT(1, 10)
-
-enum E {
- Enum1 = 1,
- Enum2 = 2,
-};
-
-typedef unsigned char uuid_t[20];
-
-void uuid_generate(uuid_t x) {
- x[0] = 0;
-}
-
-struct S {
- int x;
-};
-
-extern enum E myConstFunc(struct S* const ctx, int const id, struct S **const filter);
-
-enum E myConstFunc(struct S *const ctx, int const id, struct S **const filter) { return 0; }
-
-// issue 1222
-typedef union {
- long align;
-} xxpthread_mutex_t;
-
-struct ibv_async_event {
- union {
- int x;
- } element;
-};
-
-struct ibv_context {
- xxpthread_mutex_t mutex;
-};
-*/
-import "C"
-import (
- "os"
- "unsafe"
-)
-
-const EINVAL = C.EINVAL /* test #define */
-
-var KILO = C.KILO
-
-func uuidgen() {
- var uuid C.uuid_t
- C.uuid_generate(&uuid[0])
-}
-
-func Size(name string) (int64, os.Error) {
- var st C.struct_stat
- p := C.CString(name)
- _, err := C.stat(p, &st)
- C.free(unsafe.Pointer(p))
- if err != nil {
- return 0, err
- }
- return int64(C.ulong(st.st_size)), nil
-}
-
-func Strtol(s string, base int) (int, os.Error) {
- p := C.CString(s)
- n, err := C.strtol(p, nil, C.int(base))
- C.free(unsafe.Pointer(p))
- return int(n), err
-}
-
-func Atol(s string) int {
- p := C.CString(s)
- n := C.atol(p)
- C.free(unsafe.Pointer(p))
- return int(n)
-}
-
-func TestConst() {
- C.myConstFunc(nil, 0, nil)
-}
-
-func TestEnum() {
- if C.Enum1 != 1 || C.Enum2 != 2 {
- println("bad enum", C.Enum1, C.Enum2)
- }
-}
-
-func TestAtol() {
- l := Atol("123")
- if l != 123 {
- println("Atol 123: ", l)
- panic("bad atol")
- }
-}
-
-func TestErrno() {
- n, err := Strtol("asdf", 123)
- if n != 0 || err != os.EINVAL {
- println("Strtol: ", n, err)
- panic("bad strtol")
- }
-}
-
-func TestMultipleAssign() {
- p := C.CString("123")
- n, m := C.strtol(p, nil, 345), C.strtol(p, nil, 10)
- if n != 0 || m != 234 {
- println("Strtol x2: ", n, m)
- panic("bad strtol x2")
- }
- C.free(unsafe.Pointer(p))
-}
-
-var (
- uint = (C.uint)(0)
- ulong C.ulong
- char C.char
-)
-
-type Context struct {
- ctx *C.struct_ibv_context
-}
-
-func Test() {
- TestAlign()
- TestAtol()
- TestEnum()
- TestErrno()
- TestConst()
-}
diff --git a/misc/cgo/stdio/test1.go b/misc/cgo/stdio/test1.go
deleted file mode 100644
index dce2ef83c..000000000
--- a/misc/cgo/stdio/test1.go
+++ /dev/null
@@ -1,29 +0,0 @@
-// 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.
-
-// This file contains test cases for cgo.
-
-package stdio
-
-/*
-// issue 1222
-typedef union {
- long align;
-} xxpthread_mutex_t;
-
-struct ibv_async_event {
- union {
- int x;
- } element;
-};
-
-struct ibv_context {
- xxpthread_mutex_t mutex;
-};
-*/
-import "C"
-
-type AsyncEvent struct {
- event C.struct_ibv_async_event
-}