From 04b08da9af0c450d645ab7389d1467308cfc2db8 Mon Sep 17 00:00:00 2001 From: Michael Stapelberg Date: Mon, 4 Mar 2013 21:27:36 +0100 Subject: Imported Upstream version 1.1~hg20130304 --- misc/swig/stdio/file.swig | 15 ++++++++++++++- misc/swig/stdio/file_test.go | 22 ++++++++++++++++++++++ misc/swig/stdio/hello.go | 11 ----------- 3 files changed, 36 insertions(+), 12 deletions(-) create mode 100644 misc/swig/stdio/file_test.go delete mode 100644 misc/swig/stdio/hello.go (limited to 'misc/swig/stdio') diff --git a/misc/swig/stdio/file.swig b/misc/swig/stdio/file.swig index 57c623f8f..8ba341d08 100644 --- a/misc/swig/stdio/file.swig +++ b/misc/swig/stdio/file.swig @@ -6,6 +6,19 @@ %{ #include +#include %} -int puts(const char *); +%typemap(gotype) const char * "string" +%typemap(in) const char * %{ + $1 = malloc($input.n + 1); + memcpy($1, $input.p, $input.n); + $1[$input.n] = '\0'; +%} +%typemap(freearg) const char * %{ + free($1); +%} + +FILE *fopen(const char *name, const char *mode); +int fclose(FILE *); +int fgetc(FILE *); diff --git a/misc/swig/stdio/file_test.go b/misc/swig/stdio/file_test.go new file mode 100644 index 000000000..6478a7cf3 --- /dev/null +++ b/misc/swig/stdio/file_test.go @@ -0,0 +1,22 @@ +// Copyright 2012 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 file + +import "testing" + +// Open this file itself and verify that the first few characters are +// as expected. +func TestRead(t *testing.T) { + f := Fopen("file_test.go", "r") + if f == nil { + t.Fatal("fopen failed") + } + if Fgetc(f) != '/' || Fgetc(f) != '/' || Fgetc(f) != ' ' || Fgetc(f) != 'C' { + t.Error("read unexpected characters") + } + if Fclose(f) != 0 { + t.Error("fclose failed") + } +} diff --git a/misc/swig/stdio/hello.go b/misc/swig/stdio/hello.go deleted file mode 100644 index eec294278..000000000 --- a/misc/swig/stdio/hello.go +++ /dev/null @@ -1,11 +0,0 @@ -// 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 "swig/file" - -func main() { - file.Puts("Hello, world") -} -- cgit v1.2.3