OSDN Git Service

Update Go compiler, library, and testsuite on gcc 4.7 branch.
authorian <ian@138bc75d-0d04-0410-961f-82ee72b054a4>
Sat, 10 Mar 2012 19:03:09 +0000 (19:03 +0000)
committerian <ian@138bc75d-0d04-0410-961f-82ee72b054a4>
Sat, 10 Mar 2012 19:03:09 +0000 (19:03 +0000)
* go-gcc.cc (Gcc_backend::assignment_statement): Convert the rhs
to the lhs type if necessary.

* go-gcc.cc (Gcc_backend::init_statement): Don't initialize a
zero-sized variable.
(go_non_zero_struct): New global variable.
(Gcc_backend::non_zero_size_type): New function.
(Gcc_backend::global_variable): Don't build an assignment for a
zero-sized value.
* go-c.h (go_non_zero_struct): Declare.
* config-lang.in (gtfiles): Add go-c.h.

git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/branches/gcc-4_7-branch@185180 138bc75d-0d04-0410-961f-82ee72b054a4

510 files changed:
gcc/go/ChangeLog
gcc/go/config-lang.in
gcc/go/go-c.h
gcc/go/go-gcc.cc
gcc/go/gofrontend/expressions.cc
gcc/go/gofrontend/gogo-tree.cc
gcc/go/gofrontend/gogo.cc
gcc/go/gofrontend/gogo.h
gcc/go/gofrontend/types.cc
gcc/go/gofrontend/unsafe.cc
gcc/testsuite/go.test/test/env.go
gcc/testsuite/go.test/test/fixedbugs/bug262.go
gcc/testsuite/go.test/test/fixedbugs/bug388.go
libgo/MERGE
libgo/Makefile.am
libgo/Makefile.in
libgo/config.h.in
libgo/configure
libgo/configure.ac
libgo/go/archive/zip/reader.go
libgo/go/archive/zip/reader_test.go
libgo/go/archive/zip/struct.go
libgo/go/archive/zip/writer.go
libgo/go/archive/zip/writer_test.go
libgo/go/archive/zip/zip_test.go
libgo/go/bufio/bufio.go
libgo/go/bufio/bufio_test.go
libgo/go/bytes/buffer.go
libgo/go/bytes/bytes.go
libgo/go/bytes/bytes_test.go
libgo/go/bytes/example_test.go
libgo/go/bytes/reader.go [new file with mode: 0644]
libgo/go/bytes/reader_test.go [new file with mode: 0644]
libgo/go/compress/flate/deflate.go
libgo/go/compress/flate/deflate_test.go
libgo/go/compress/flate/huffman_bit_writer.go
libgo/go/compress/gzip/gunzip.go
libgo/go/compress/gzip/gzip.go
libgo/go/compress/gzip/gzip_test.go
libgo/go/compress/zlib/reader.go
libgo/go/compress/zlib/writer.go
libgo/go/compress/zlib/writer_test.go
libgo/go/container/heap/example_test.go [new file with mode: 0644]
libgo/go/container/heap/heap.go
libgo/go/crypto/aes/cipher.go
libgo/go/crypto/cipher/cbc_aes_test.go
libgo/go/crypto/cipher/cfb_test.go
libgo/go/crypto/cipher/common_test.go
libgo/go/crypto/cipher/ctr_aes_test.go
libgo/go/crypto/cipher/ofb_test.go
libgo/go/crypto/des/block.go
libgo/go/crypto/des/cipher.go
libgo/go/crypto/des/des_test.go
libgo/go/crypto/dsa/dsa.go
libgo/go/crypto/ecdsa/ecdsa.go
libgo/go/crypto/md5/md5_test.go
libgo/go/crypto/rand/rand_test.go
libgo/go/crypto/rand/rand_unix.go
libgo/go/crypto/rsa/pkcs1v15.go
libgo/go/crypto/rsa/rsa.go
libgo/go/crypto/sha1/sha1_test.go
libgo/go/crypto/tls/conn.go
libgo/go/crypto/tls/generate_cert.go
libgo/go/crypto/tls/handshake_client.go
libgo/go/crypto/tls/handshake_client_test.go
libgo/go/crypto/tls/handshake_server.go
libgo/go/crypto/tls/handshake_server_test.go
libgo/go/crypto/tls/root_darwin.go
libgo/go/crypto/x509/verify.go
libgo/go/crypto/x509/x509.go
libgo/go/database/sql/convert.go
libgo/go/database/sql/convert_test.go
libgo/go/database/sql/driver/driver.go
libgo/go/database/sql/driver/types.go
libgo/go/database/sql/driver/types_test.go
libgo/go/database/sql/fakedb_test.go
libgo/go/database/sql/sql.go
libgo/go/database/sql/sql_test.go
libgo/go/debug/dwarf/buf.go
libgo/go/debug/dwarf/const.go
libgo/go/debug/dwarf/entry.go
libgo/go/debug/dwarf/line.go [new file with mode: 0644]
libgo/go/debug/dwarf/line_test.go [new file with mode: 0644]
libgo/go/debug/dwarf/open.go
libgo/go/debug/dwarf/testdata/typedef.c
libgo/go/debug/dwarf/testdata/typedef.elf
libgo/go/debug/dwarf/testdata/typedef.macho
libgo/go/debug/dwarf/type.go
libgo/go/debug/dwarf/type_test.go
libgo/go/debug/dwarf/unit.go
libgo/go/debug/elf/elf_test.go
libgo/go/debug/elf/file.go
libgo/go/debug/elf/file_test.go
libgo/go/debug/elf/runtime.go [new file with mode: 0644]
libgo/go/debug/gosym/pclntab_test.go
libgo/go/debug/macho/file.go
libgo/go/debug/macho/file_test.go
libgo/go/encoding/binary/binary.go
libgo/go/encoding/binary/binary_test.go
libgo/go/encoding/binary/export_test.go [new file with mode: 0644]
libgo/go/encoding/binary/varint_test.go
libgo/go/encoding/gob/codec_test.go
libgo/go/encoding/gob/debug.go
libgo/go/encoding/gob/decode.go
libgo/go/encoding/gob/dump.go
libgo/go/encoding/gob/encode.go
libgo/go/encoding/gob/encoder_test.go
libgo/go/encoding/gob/type.go
libgo/go/encoding/hex/hex_test.go
libgo/go/encoding/json/decode.go
libgo/go/encoding/json/decode_test.go
libgo/go/encoding/json/encode.go
libgo/go/encoding/json/encode_test.go
libgo/go/encoding/json/indent.go
libgo/go/encoding/json/stream.go
libgo/go/encoding/xml/atom_test.go
libgo/go/encoding/xml/marshal.go
libgo/go/encoding/xml/marshal_test.go
libgo/go/encoding/xml/read.go
libgo/go/encoding/xml/read_test.go
libgo/go/encoding/xml/typeinfo.go
libgo/go/errors/errors_test.go
libgo/go/exp/gotype/doc.go
libgo/go/exp/gotype/gotype.go
libgo/go/exp/html/node.go
libgo/go/exp/inotify/inotify_linux_test.go
libgo/go/exp/norm/composition.go
libgo/go/exp/norm/composition_test.go
libgo/go/exp/norm/forminfo.go
libgo/go/exp/norm/input.go
libgo/go/exp/norm/iter.go [new file with mode: 0644]
libgo/go/exp/norm/iter_test.go [new file with mode: 0644]
libgo/go/exp/norm/maketables.go
libgo/go/exp/norm/maketesttables.go
libgo/go/exp/norm/normalize.go
libgo/go/exp/norm/normalize_test.go
libgo/go/exp/norm/normregtest.go
libgo/go/exp/norm/tables.go
libgo/go/exp/norm/triegen.go
libgo/go/exp/proxy/per_host.go
libgo/go/exp/proxy/socks5.go
libgo/go/exp/signal/signal.go [deleted file]
libgo/go/exp/signal/signal_test.go [deleted file]
libgo/go/exp/terminal/terminal.go
libgo/go/exp/types/check.go
libgo/go/exp/types/gcimporter.go
libgo/go/exp/types/gcimporter_test.go
libgo/go/exp/types/types.go
libgo/go/exp/winfsnotify/winfsnotify_test.go
libgo/go/fmt/fmt_test.go
libgo/go/fmt/print.go
libgo/go/fmt/scan.go
libgo/go/fmt/scan_test.go
libgo/go/go/ast/print.go
libgo/go/go/ast/resolve.go
libgo/go/go/build/build.go
libgo/go/go/build/build_test.go
libgo/go/go/build/cgotest/cgotest.go [deleted file]
libgo/go/go/build/cmdtest/main.go [deleted file]
libgo/go/go/build/dir.go [deleted file]
libgo/go/go/build/doc.go [new file with mode: 0644]
libgo/go/go/build/path.go [deleted file]
libgo/go/go/build/pkgtest/pkgtest.go [deleted file]
libgo/go/go/build/pkgtest/sqrt_386_test.go [deleted file]
libgo/go/go/build/pkgtest/sqrt_amd64_test.go [deleted file]
libgo/go/go/build/pkgtest/sqrt_arm_test.go [deleted file]
libgo/go/go/build/pkgtest/sqrt_test.go [deleted file]
libgo/go/go/build/pkgtest/xsqrt_test.go [deleted file]
libgo/go/go/build/syslist_test.go
libgo/go/go/build/testdata/other/file/file.go [new file with mode: 0644]
libgo/go/go/build/testdata/other/main.go [new file with mode: 0644]
libgo/go/go/doc/doc_test.go
libgo/go/go/doc/example.go
libgo/go/go/doc/exports.go
libgo/go/go/doc/headscan.go
libgo/go/go/doc/reader.go
libgo/go/go/doc/synopsis.go [new file with mode: 0644]
libgo/go/go/doc/synopsis_test.go [new file with mode: 0644]
libgo/go/go/doc/testdata/b.0.golden
libgo/go/go/doc/testdata/b.1.golden
libgo/go/go/doc/testdata/b.2.golden
libgo/go/go/doc/testdata/b.go
libgo/go/go/doc/testdata/benchmark.go
libgo/go/go/doc/testdata/e.0.golden
libgo/go/go/doc/testdata/e.1.golden
libgo/go/go/doc/testdata/e.2.golden
libgo/go/go/doc/testdata/e.go
libgo/go/go/doc/testdata/error1.0.golden [new file with mode: 0644]
libgo/go/go/doc/testdata/error1.1.golden [new file with mode: 0644]
libgo/go/go/doc/testdata/error1.2.golden [new file with mode: 0644]
libgo/go/go/doc/testdata/error1.go [new file with mode: 0644]
libgo/go/go/doc/testdata/error2.0.golden [new file with mode: 0644]
libgo/go/go/doc/testdata/error2.1.golden [new file with mode: 0644]
libgo/go/go/doc/testdata/error2.2.golden [new file with mode: 0644]
libgo/go/go/doc/testdata/error2.go [new file with mode: 0644]
libgo/go/go/doc/testdata/f.go
libgo/go/go/doc/testdata/testing.1.golden
libgo/go/go/doc/testdata/testing.go
libgo/go/go/parser/interface.go
libgo/go/go/parser/parser.go
libgo/go/go/parser/parser_test.go
libgo/go/go/printer/nodes.go
libgo/go/go/printer/performance_test.go
libgo/go/go/printer/printer.go
libgo/go/go/printer/printer_test.go
libgo/go/go/printer/testdata/comments.golden
libgo/go/go/printer/testdata/comments.input
libgo/go/go/printer/testdata/declarations.golden
libgo/go/go/printer/testdata/declarations.input
libgo/go/go/printer/testdata/expressions.golden
libgo/go/go/printer/testdata/expressions.input
libgo/go/go/printer/testdata/expressions.raw
libgo/go/go/printer/testdata/parser.go
libgo/go/go/printer/testdata/statements.golden
libgo/go/go/printer/testdata/statements.input
libgo/go/go/scanner/errors.go
libgo/go/go/scanner/scanner.go
libgo/go/go/scanner/scanner_test.go
libgo/go/html/template/clone.go [deleted file]
libgo/go/html/template/clone_test.go
libgo/go/html/template/content.go
libgo/go/html/template/content_test.go
libgo/go/html/template/doc.go
libgo/go/html/template/escape.go
libgo/go/html/template/escape_test.go
libgo/go/html/template/html.go
libgo/go/html/template/template.go
libgo/go/image/decode_example_test.go [new file with mode: 0644]
libgo/go/image/png/reader_test.go
libgo/go/image/png/writer.go
libgo/go/image/ycbcr_test.go
libgo/go/io/io.go
libgo/go/io/ioutil/tempfile.go
libgo/go/io/pipe.go
libgo/go/log/log.go
libgo/go/log/log_test.go
libgo/go/log/syslog/syslog.go
libgo/go/log/syslog/syslog_test.go
libgo/go/log/syslog/syslog_unix.go
libgo/go/math/big/calibrate_test.go
libgo/go/math/big/nat.go
libgo/go/math/big/nat_test.go
libgo/go/math/const.go
libgo/go/math/gamma.go
libgo/go/math/rand/rand.go
libgo/go/math/rand/rand_test.go
libgo/go/mime/grammar.go
libgo/go/mime/mediatype.go
libgo/go/mime/multipart/formdata.go
libgo/go/net/dial.go
libgo/go/net/dial_test.go
libgo/go/net/dialgoogle_test.go
libgo/go/net/fd.go
libgo/go/net/fd_windows.go
libgo/go/net/file.go
libgo/go/net/file_plan9.go
libgo/go/net/hosts_test.go
libgo/go/net/http/cgi/child.go
libgo/go/net/http/cgi/host_test.go
libgo/go/net/http/cgi/matryoshka_test.go
libgo/go/net/http/cookie_test.go
libgo/go/net/http/doc.go
libgo/go/net/http/example_test.go [new file with mode: 0644]
libgo/go/net/http/fcgi/child.go
libgo/go/net/http/fs.go
libgo/go/net/http/fs_test.go
libgo/go/net/http/httptest/server.go
libgo/go/net/http/httptest/server_test.go [new file with mode: 0644]
libgo/go/net/http/httputil/dump.go
libgo/go/net/http/httputil/dump_test.go
libgo/go/net/http/httputil/persist.go
libgo/go/net/http/lex.go
libgo/go/net/http/pprof/pprof.go
libgo/go/net/http/request.go
libgo/go/net/http/response_test.go
libgo/go/net/http/serve_test.go
libgo/go/net/http/server.go
libgo/go/net/http/sniff.go
libgo/go/net/http/sniff_test.go
libgo/go/net/http/status.go
libgo/go/net/http/transfer.go
libgo/go/net/http/transport.go
libgo/go/net/http/transport_test.go
libgo/go/net/http/triv.go
libgo/go/net/interface.go
libgo/go/net/interface_linux.go
libgo/go/net/interface_test.go
libgo/go/net/ip_test.go
libgo/go/net/ipraw_test.go
libgo/go/net/iprawsock_plan9.go
libgo/go/net/iprawsock_posix.go
libgo/go/net/ipsock_plan9.go
libgo/go/net/ipsock_posix.go
libgo/go/net/lookup_plan9.go
libgo/go/net/lookup_test.go
libgo/go/net/mac.go [new file with mode: 0644]
libgo/go/net/mac_test.go [new file with mode: 0644]
libgo/go/net/multicast_test.go
libgo/go/net/net.go
libgo/go/net/net_test.go
libgo/go/net/newpollserver.go
libgo/go/net/parse.go
libgo/go/net/rpc/client.go
libgo/go/net/rpc/server.go
libgo/go/net/rpc/server_test.go
libgo/go/net/sendfile_linux.go
libgo/go/net/sendfile_windows.go
libgo/go/net/server_test.go
libgo/go/net/smtp/smtp.go
libgo/go/net/smtp/smtp_test.go
libgo/go/net/sock.go
libgo/go/net/sock_bsd.go
libgo/go/net/sock_linux.go
libgo/go/net/sock_windows.go
libgo/go/net/sockopt.go
libgo/go/net/sockopt_bsd.go
libgo/go/net/sockopt_linux.go
libgo/go/net/sockopt_windows.go
libgo/go/net/sockoptip.go
libgo/go/net/sockoptip_bsd.go
libgo/go/net/sockoptip_darwin.go
libgo/go/net/sockoptip_freebsd.go
libgo/go/net/sockoptip_linux.go
libgo/go/net/sockoptip_netbsd.go [new file with mode: 0644]
libgo/go/net/sockoptip_openbsd.go
libgo/go/net/sockoptip_windows.go
libgo/go/net/tcpsock_plan9.go
libgo/go/net/tcpsock_posix.go
libgo/go/net/testdata/hosts [new file with mode: 0644]
libgo/go/net/testdata/igmp [new file with mode: 0644]
libgo/go/net/testdata/igmp6 [new file with mode: 0644]
libgo/go/net/textproto/reader.go
libgo/go/net/textproto/reader_test.go
libgo/go/net/textproto/textproto.go
libgo/go/net/timeout_test.go
libgo/go/net/udp_test.go
libgo/go/net/udpsock_plan9.go
libgo/go/net/udpsock_posix.go
libgo/go/net/unixsock_plan9.go
libgo/go/net/unixsock_posix.go
libgo/go/net/url/url.go
libgo/go/net/url/url_test.go
libgo/go/old/netchan/netchan_test.go
libgo/go/os/dir_plan9.go
libgo/go/os/doc.go
libgo/go/os/env.go
libgo/go/os/error.go
libgo/go/os/error_plan9.go
libgo/go/os/error_posix.go
libgo/go/os/exec.go
libgo/go/os/exec/exec.go
libgo/go/os/exec/exec_test.go
libgo/go/os/exec/lp_plan9.go
libgo/go/os/exec/lp_unix.go
libgo/go/os/exec/lp_windows.go
libgo/go/os/exec_plan9.go
libgo/go/os/exec_posix.go
libgo/go/os/exec_unix.go
libgo/go/os/exec_windows.go
libgo/go/os/file.go
libgo/go/os/file_plan9.go
libgo/go/os/file_posix.go
libgo/go/os/file_unix.go
libgo/go/os/getwd.go
libgo/go/os/mkunixsignals.sh [deleted file]
libgo/go/os/os_test.go
libgo/go/os/path.go
libgo/go/os/path_test.go
libgo/go/os/signal/signal.go [new file with mode: 0644]
libgo/go/os/signal/signal_stub.go [new file with mode: 0644]
libgo/go/os/signal/signal_test.go [new file with mode: 0644]
libgo/go/os/signal/signal_unix.go [new file with mode: 0644]
libgo/go/os/stat_plan9.go
libgo/go/os/time.go [deleted file]
libgo/go/path/example_test.go
libgo/go/path/filepath/match.go
libgo/go/path/filepath/path.go
libgo/go/path/filepath/path_plan9.go
libgo/go/path/filepath/path_test.go
libgo/go/path/filepath/path_unix.go
libgo/go/path/filepath/path_windows.go
libgo/go/path/match.go
libgo/go/path/path.go
libgo/go/reflect/all_test.go
libgo/go/reflect/deepequal.go
libgo/go/reflect/type.go
libgo/go/reflect/value.go
libgo/go/regexp/all_test.go
libgo/go/regexp/regexp.go
libgo/go/regexp/syntax/parse.go
libgo/go/regexp/syntax/regexp.go
libgo/go/runtime/debug.go
libgo/go/runtime/debug/stack.go
libgo/go/runtime/error.go
libgo/go/runtime/extern.go
libgo/go/runtime/gc_test.go
libgo/go/runtime/malloc1.go [moved from gcc/testsuite/go.test/test/malloc1.go with 92% similarity]
libgo/go/runtime/mallocrand.go [moved from gcc/testsuite/go.test/test/mallocrand.go with 98% similarity]
libgo/go/runtime/mallocrep.go [moved from gcc/testsuite/go.test/test/mallocrep.go with 97% similarity]
libgo/go/runtime/mallocrep1.go [moved from gcc/testsuite/go.test/test/mallocrep1.go with 98% similarity]
libgo/go/runtime/mem.go
libgo/go/runtime/pprof/pprof.go
libgo/go/runtime/pprof/pprof_test.go
libgo/go/runtime/runtime_test.go [new file with mode: 0644]
libgo/go/runtime/sig.go [deleted file]
libgo/go/runtime/softfloat64.go
libgo/go/runtime/type.go
libgo/go/sort/example_interface_test.go [new file with mode: 0644]
libgo/go/sort/example_reverse_test.go [new file with mode: 0644]
libgo/go/sort/example_test.go
libgo/go/strconv/atof.go
libgo/go/strconv/atof_test.go
libgo/go/strconv/decimal.go
libgo/go/strconv/extfloat.go
libgo/go/strconv/itoa_test.go
libgo/go/strings/example_test.go
libgo/go/strings/reader.go
libgo/go/strings/reader_test.go [new file with mode: 0644]
libgo/go/sync/cond.go
libgo/go/sync/example_test.go [new file with mode: 0644]
libgo/go/sync/export_test.go [new file with mode: 0644]
libgo/go/sync/mutex.go
libgo/go/sync/mutex_test.go
libgo/go/sync/runtime.go [new file with mode: 0644]
libgo/go/sync/runtime_sema_test.go [moved from libgo/go/runtime/sema_test.go with 89% similarity]
libgo/go/sync/rwmutex.go
libgo/go/sync/rwmutex_test.go
libgo/go/sync/waitgroup.go
libgo/go/syscall/exec_bsd.go
libgo/go/syscall/exec_linux.go
libgo/go/syscall/exec_unix.go
libgo/go/syscall/exec_windows.go
libgo/go/syscall/libcall_linux.go
libgo/go/syscall/libcall_posix.go
libgo/go/syscall/signame.c [new file with mode: 0644]
libgo/go/syscall/socket.go
libgo/go/syscall/syscall_unix.go
libgo/go/testing/benchmark.go
libgo/go/testing/example.go
libgo/go/testing/iotest/reader.go
libgo/go/testing/quick/quick.go
libgo/go/testing/script/script.go [deleted file]
libgo/go/testing/script/script_test.go [deleted file]
libgo/go/testing/testing.go
libgo/go/text/scanner/scanner.go
libgo/go/text/tabwriter/example_test.go [new file with mode: 0644]
libgo/go/text/tabwriter/tabwriter.go
libgo/go/text/tabwriter/tabwriter_test.go
libgo/go/text/template/doc.go
libgo/go/text/template/exec.go
libgo/go/text/template/exec_test.go
libgo/go/text/template/funcs.go
libgo/go/text/template/multi_test.go
libgo/go/text/template/parse/lex.go
libgo/go/text/template/parse/node.go
libgo/go/text/template/parse/parse.go
libgo/go/text/template/parse/parse_test.go
libgo/go/text/template/template.go
libgo/go/time/example_test.go
libgo/go/time/format.go
libgo/go/time/sleep_test.go
libgo/go/time/sys_plan9.go
libgo/go/time/sys_unix.go
libgo/go/time/sys_windows.go
libgo/go/time/tick_test.go
libgo/go/time/time.go
libgo/go/time/time_test.go
libgo/go/time/zoneinfo.go
libgo/go/time/zoneinfo_plan9.go
libgo/go/time/zoneinfo_read.go [new file with mode: 0644]
libgo/go/time/zoneinfo_unix.go
libgo/go/time/zoneinfo_windows.go
libgo/go/unicode/graphic.go
libgo/go/unicode/letter.go
libgo/go/unicode/tables.go
libgo/go/unicode/utf8/utf8.go
libgo/merge.sh
libgo/mksysinfo.sh
libgo/runtime/chan.c
libgo/runtime/go-assert-interface.c
libgo/runtime/go-caller.c
libgo/runtime/go-callers.c [new file with mode: 0644]
libgo/runtime/go-check-interface.c
libgo/runtime/go-convert-interface.c
libgo/runtime/go-main.c
libgo/runtime/go-panic.c
libgo/runtime/go-panic.h
libgo/runtime/go-reflect.c [deleted file]
libgo/runtime/go-signal.c
libgo/runtime/go-type-identity.c
libgo/runtime/go-unreflect.c [deleted file]
libgo/runtime/go-unsafe-new.c
libgo/runtime/go-unsafe-newarray.c
libgo/runtime/lock_futex.c
libgo/runtime/lock_sema.c
libgo/runtime/malloc.goc
libgo/runtime/malloc.h
libgo/runtime/mem.c
libgo/runtime/mgc0.c
libgo/runtime/mheap.c
libgo/runtime/mprof.goc
libgo/runtime/proc.c
libgo/runtime/reflect.goc
libgo/runtime/runtime.c
libgo/runtime/runtime.h
libgo/runtime/sema.goc
libgo/runtime/signal_unix.c [new file with mode: 0644]
libgo/runtime/sigqueue.goc
libgo/runtime/thread-linux.c
libgo/runtime/thread.c

index 8b8e90c..f779e9b 100644 (file)
@@ -1,3 +1,19 @@
+2012-03-09  Ian Lance Taylor  <iant@google.com>
+
+       * go-gcc.cc (Gcc_backend::assignment_statement): Convert the rhs
+       to the lhs type if necessary.
+
+2012-03-08  Ian Lance Taylor  <iant@google.com>
+
+       * go-gcc.cc (Gcc_backend::init_statement): Don't initialize a
+       zero-sized variable.
+       (go_non_zero_struct): New global variable.
+       (Gcc_backend::non_zero_size_type): New function.
+       (Gcc_backend::global_variable): Don't build an assignment for a
+       zero-sized value.
+       * go-c.h (go_non_zero_struct): Declare.
+       * config-lang.in (gtfiles): Add go-c.h.
+
 2012-02-29  Ian Lance Taylor  <iant@google.com>
 
        * go-gcc.cc (class Gcc_tree): Add set_tree method.
index 4b5886e..586e070 100644 (file)
@@ -34,7 +34,7 @@ target_libs="target-libgo target-libffi"
 # compiler during stage 1.
 lang_requires_boot_languages=c++
 
-gtfiles="\$(srcdir)/go/go-lang.c"
+gtfiles="\$(srcdir)/go/go-lang.c \$(srcdir)/go/go-c.h"
 
 # Do not build by default.
 build_by_default="no"
index 0bfed85..e123d52 100644 (file)
@@ -69,6 +69,8 @@ extern void go_write_export_data (const char *, unsigned int);
 
 extern const char *go_read_export_data (int, off_t, char **, size_t *, int *);
 
+extern GTY(()) tree go_non_zero_struct;
+
 #if defined(__cplusplus) && !defined(ENABLE_BUILD_WITH_CXX)
 } /* End extern "C".  */
 #endif
index a19bb89..96c1718 100644 (file)
@@ -338,6 +338,9 @@ class Gcc_backend : public Backend
 
   Btype*
   fill_in_array(Btype*, Btype*, Bexpression*);
+
+  tree
+  non_zero_size_type(tree);
 };
 
 // A helper function.
@@ -870,9 +873,27 @@ Gcc_backend::init_statement(Bvariable* var, Bexpression* init)
   if (var_tree == error_mark_node || init_tree == error_mark_node)
     return this->error_statement();
   gcc_assert(TREE_CODE(var_tree) == VAR_DECL);
-  DECL_INITIAL(var_tree) = init_tree;
-  return this->make_statement(build1_loc(DECL_SOURCE_LOCATION(var_tree),
-                                        DECL_EXPR, void_type_node, var_tree));
+
+  // To avoid problems with GNU ld, we don't make zero-sized
+  // externally visible variables.  That might lead us to doing an
+  // initialization of a zero-sized expression to a non-zero sized
+  // variable, or vice-versa.  Avoid crashes by omitting the
+  // initializer.  Such initializations don't mean anything anyhow.
+  if (int_size_in_bytes(TREE_TYPE(var_tree)) != 0
+      && init_tree != NULL_TREE
+      && int_size_in_bytes(TREE_TYPE(init_tree)) != 0)
+    {
+      DECL_INITIAL(var_tree) = init_tree;
+      init_tree = NULL_TREE;
+    }
+
+  tree ret = build1_loc(DECL_SOURCE_LOCATION(var_tree), DECL_EXPR,
+                       void_type_node, var_tree);
+  if (init_tree != NULL_TREE)
+    ret = build2_loc(DECL_SOURCE_LOCATION(var_tree), COMPOUND_EXPR,
+                    void_type_node, init_tree, ret);
+
+  return this->make_statement(ret);
 }
 
 // Assignment.
@@ -885,6 +906,42 @@ Gcc_backend::assignment_statement(Bexpression* lhs, Bexpression* rhs,
   tree rhs_tree = rhs->get_tree();
   if (lhs_tree == error_mark_node || rhs_tree == error_mark_node)
     return this->error_statement();
+
+  // To avoid problems with GNU ld, we don't make zero-sized
+  // externally visible variables.  That might lead us to doing an
+  // assignment of a zero-sized expression to a non-zero sized
+  // expression; avoid crashes here by avoiding assignments of
+  // zero-sized expressions.  Such assignments don't really mean
+  // anything anyhow.
+  if (int_size_in_bytes(TREE_TYPE(lhs_tree)) == 0
+      || int_size_in_bytes(TREE_TYPE(rhs_tree)) == 0)
+    return this->compound_statement(this->expression_statement(lhs),
+                                   this->expression_statement(rhs));
+
+  // Sometimes the same unnamed Go type can be created multiple times
+  // and thus have multiple tree representations.  Make sure this does
+  // not confuse the middle-end.
+  if (TREE_TYPE(lhs_tree) != TREE_TYPE(rhs_tree))
+    {
+      tree lhs_type_tree = TREE_TYPE(lhs_tree);
+      gcc_assert(TREE_CODE(lhs_type_tree) == TREE_CODE(TREE_TYPE(rhs_tree)));
+      if (POINTER_TYPE_P(lhs_type_tree)
+         || INTEGRAL_TYPE_P(lhs_type_tree)
+         || SCALAR_FLOAT_TYPE_P(lhs_type_tree)
+         || COMPLEX_FLOAT_TYPE_P(lhs_type_tree))
+       rhs_tree = fold_convert_loc(location.gcc_location(), lhs_type_tree,
+                                   rhs_tree);
+      else if (TREE_CODE(lhs_type_tree) == RECORD_TYPE
+              || TREE_CODE(lhs_type_tree) == ARRAY_TYPE)
+       {
+         gcc_assert(int_size_in_bytes(lhs_type_tree)
+                    == int_size_in_bytes(TREE_TYPE(rhs_tree)));
+         rhs_tree = fold_build1_loc(location.gcc_location(),
+                                    VIEW_CONVERT_EXPR,
+                                    lhs_type_tree, rhs_tree);
+       }
+    }
+
   return this->make_statement(fold_build2_loc(location.gcc_location(),
                                               MODIFY_EXPR,
                                              void_type_node,
@@ -1178,6 +1235,48 @@ Gcc_backend::block_statement(Bblock* bblock)
   return this->make_statement(bind_tree);
 }
 
+// This is not static because we declare it with GTY(()) in go-c.h.
+tree go_non_zero_struct;
+
+// Return a type corresponding to TYPE with non-zero size.
+
+tree
+Gcc_backend::non_zero_size_type(tree type)
+{
+  if (int_size_in_bytes(type) != 0)
+    return type;
+
+  switch (TREE_CODE(type))
+    {
+    case RECORD_TYPE:
+      {
+       if (go_non_zero_struct == NULL_TREE)
+         {
+           type = make_node(RECORD_TYPE);
+           tree field = build_decl(UNKNOWN_LOCATION, FIELD_DECL,
+                                   get_identifier("dummy"),
+                                   boolean_type_node);
+           DECL_CONTEXT(field) = type;
+           TYPE_FIELDS(type) = field;
+           layout_type(type);
+           go_non_zero_struct = type;
+         }
+       return go_non_zero_struct;
+      }
+
+    case ARRAY_TYPE:
+      {
+       tree element_type = non_zero_size_type(TREE_TYPE(type));
+       return build_array_type_nelts(element_type, 1);
+      }
+
+    default:
+      gcc_unreachable();
+    }
+
+  gcc_unreachable();
+}
+
 // Make a global variable.
 
 Bvariable*
@@ -1193,6 +1292,10 @@ Gcc_backend::global_variable(const std::string& package_name,
   if (type_tree == error_mark_node)
     return this->error_variable();
 
+  // The GNU linker does not like dynamic variables with zero size.
+  if ((is_external || !is_hidden) && int_size_in_bytes(type_tree) == 0)
+    type_tree = this->non_zero_size_type(type_tree);
+
   std::string var_name(package_name);
   var_name.push_back('.');
   var_name.append(name);
index a2097e0..90cf6f3 100644 (file)
@@ -205,9 +205,6 @@ Expression::convert_for_assignment(Translate_context* context, Type* lhs_type,
                                   Type* rhs_type, tree rhs_tree,
                                   Location location)
 {
-  if (lhs_type == rhs_type)
-    return rhs_tree;
-
   if (lhs_type->is_error() || rhs_type->is_error())
     return error_mark_node;
 
@@ -220,7 +217,7 @@ Expression::convert_for_assignment(Translate_context* context, Type* lhs_type,
   if (lhs_type_tree == error_mark_node)
     return error_mark_node;
 
-  if (lhs_type->interface_type() != NULL)
+  if (lhs_type != rhs_type && lhs_type->interface_type() != NULL)
     {
       if (rhs_type->interface_type() == NULL)
        return Expression::convert_type_to_interface(context, lhs_type,
@@ -231,7 +228,7 @@ Expression::convert_for_assignment(Translate_context* context, Type* lhs_type,
                                                          rhs_type, rhs_tree,
                                                          false, location);
     }
-  else if (rhs_type->interface_type() != NULL)
+  else if (lhs_type != rhs_type && rhs_type->interface_type() != NULL)
     return Expression::convert_interface_to_type(context, lhs_type, rhs_type,
                                                 rhs_tree, location);
   else if (lhs_type->is_slice_type() && rhs_type->is_nil_type())
@@ -284,13 +281,21 @@ Expression::convert_for_assignment(Translate_context* context, Type* lhs_type,
           || SCALAR_FLOAT_TYPE_P(lhs_type_tree)
           || COMPLEX_FLOAT_TYPE_P(lhs_type_tree))
     return fold_convert_loc(location.gcc_location(), lhs_type_tree, rhs_tree);
-  else if (TREE_CODE(lhs_type_tree) == RECORD_TYPE
-          && TREE_CODE(TREE_TYPE(rhs_tree)) == RECORD_TYPE)
+  else if ((TREE_CODE(lhs_type_tree) == RECORD_TYPE
+           && TREE_CODE(TREE_TYPE(rhs_tree)) == RECORD_TYPE)
+          || (TREE_CODE(lhs_type_tree) == ARRAY_TYPE
+              && TREE_CODE(TREE_TYPE(rhs_tree)) == ARRAY_TYPE))
     {
+      // Avoid confusion from zero sized variables which may be
+      // represented as non-zero-sized.
+      if (int_size_in_bytes(lhs_type_tree) == 0
+         || int_size_in_bytes(TREE_TYPE(rhs_tree)) == 0)
+       return rhs_tree;
+
       // This conversion must be permitted by Go, or we wouldn't have
       // gotten here.
       go_assert(int_size_in_bytes(lhs_type_tree)
-                == int_size_in_bytes(TREE_TYPE(rhs_tree)));
+               == int_size_in_bytes(TREE_TYPE(rhs_tree)));
       return fold_build1_loc(location.gcc_location(), VIEW_CONVERT_EXPR,
                              lhs_type_tree, rhs_tree);
     }
index 603b97e..fa22932 100644 (file)
@@ -843,7 +843,9 @@ Gogo::write_globals()
                  this->backend()->global_variable_set_init(var,
                                                            tree_to_expr(init));
                }
-             else if (is_sink)
+             else if (is_sink
+                      || int_size_in_bytes(TREE_TYPE(init)) == 0
+                      || int_size_in_bytes(TREE_TYPE(vec[i])) == 0)
                var_init_tree = init;
              else
                var_init_tree = fold_build2_loc(no->location().gcc_location(),
index ca57aea..5fe5aea 100644 (file)
@@ -628,7 +628,7 @@ Gogo::start_function(const std::string& name, Function_type* type,
       Variable* this_param = new Variable(receiver->type(), NULL, false,
                                          true, true, location);
       std::string rname = receiver->name();
-      if (rname.empty())
+      if (rname.empty() || Gogo::is_sink_name(rname))
        {
          // We need to give receivers a name since they wind up in
          // DECL_ARGUMENTS.  FIXME.
@@ -638,8 +638,7 @@ Gogo::start_function(const std::string& name, Function_type* type,
          ++count;
          rname = buf;
        }
-      if (!Gogo::is_sink_name(rname))
-       block->bindings()->add_variable(rname, NULL, this_param);
+      block->bindings()->add_variable(rname, NULL, this_param);
     }
 
   const Typed_identifier_list* parameters = type->parameters();
index 008c8a0..6c77c3b 100644 (file)
@@ -398,6 +398,11 @@ class Gogo
   void
   write_specific_type_functions();
 
+  // Whether we are done writing out specific type functions.
+  bool
+  specific_type_functions_are_written() const
+  { return this->specific_type_functions_are_written_; }
+
   // Traverse the tree.  See the Traverse class.
   void
   traverse(Traverse*);
index 3c33a6d..03f1b3e 100644 (file)
@@ -1790,6 +1790,12 @@ Type::write_specific_type_functions(Gogo* gogo, Named_type* name,
 {
   Location bloc = Linemap::predeclared_location();
 
+  if (gogo->specific_type_functions_are_written())
+    {
+      go_assert(saw_errors());
+      return;
+    }
+
   Named_object* hash_fn = gogo->start_function(hash_name, hash_fntype, false,
                                               bloc);
   gogo->start_block(bloc);
@@ -3744,8 +3750,12 @@ Function_type::copy_with_receiver(Type* receiver_type) const
   go_assert(!this->is_method());
   Typed_identifier* receiver = new Typed_identifier("", receiver_type,
                                                    this->location_);
-  return Type::make_function_type(receiver, this->parameters_,
-                                 this->results_, this->location_);
+  Function_type* ret = Type::make_function_type(receiver, this->parameters_,
+                                               this->results_,
+                                               this->location_);
+  if (this->is_varargs_)
+    ret->set_is_varargs();
+  return ret;
 }
 
 // Make a function type.
index 9508fea..bc949c6 100644 (file)
@@ -88,60 +88,6 @@ Gogo::import_unsafe(const std::string& local_name, bool is_local_name_exported,
   if (add_to_globals)
     this->add_named_object(no);
 
-  // Typeof.
-  Type* empty_interface = Type::make_empty_interface_type(bloc);
-  Typed_identifier_list* parameters = new Typed_identifier_list;
-  parameters->push_back(Typed_identifier("i", empty_interface, bloc));
-  results = new Typed_identifier_list;
-  results->push_back(Typed_identifier("", empty_interface, bloc));
-  fntype = Type::make_function_type(NULL, parameters, results, bloc);
-  no = bindings->add_function_declaration("Typeof", package, fntype, bloc);
-  if (add_to_globals)
-    this->add_named_object(no);
-
-  // Reflect.
-  parameters = new Typed_identifier_list;
-  parameters->push_back(Typed_identifier("it", empty_interface, bloc));
-  results = new Typed_identifier_list;
-  results->push_back(Typed_identifier("", empty_interface, bloc));
-  results->push_back(Typed_identifier("", pointer_type, bloc));
-  fntype = Type::make_function_type(NULL, parameters, results, bloc);
-  no = bindings->add_function_declaration("Reflect", package, fntype, bloc);
-  if (add_to_globals)
-    this->add_named_object(no);
-
-  // Unreflect.
-  parameters = new Typed_identifier_list;
-  parameters->push_back(Typed_identifier("typ", empty_interface, bloc));
-  parameters->push_back(Typed_identifier("addr", pointer_type, bloc));
-  results = new Typed_identifier_list;
-  results->push_back(Typed_identifier("", empty_interface, bloc));
-  fntype = Type::make_function_type(NULL, parameters, results, bloc);
-  no = bindings->add_function_declaration("Unreflect", package, fntype, bloc);
-  if (add_to_globals)
-    this->add_named_object(no);
-
-  // New.
-  parameters = new Typed_identifier_list;
-  parameters->push_back(Typed_identifier("typ", empty_interface, bloc));
-  results = new Typed_identifier_list;
-  results->push_back(Typed_identifier("", pointer_type, bloc));
-  fntype = Type::make_function_type(NULL, parameters, results, bloc);
-  no = bindings->add_function_declaration("New", package, fntype, bloc);
-  if (add_to_globals)
-    this->add_named_object(no);
-
-  // NewArray.
-  parameters = new Typed_identifier_list;
-  parameters->push_back(Typed_identifier("typ", empty_interface, bloc));
-  parameters->push_back(Typed_identifier("n", int_type, bloc));
-  results = new Typed_identifier_list;
-  results->push_back(Typed_identifier("", pointer_type, bloc));
-  fntype = Type::make_function_type(NULL, parameters, results, bloc);
-  no = bindings->add_function_declaration("NewArray", package, fntype, bloc);
-  if (add_to_globals)
-    this->add_named_object(no);
-
   if (!this->imported_unsafe_)
     {
       go_imported_unsafe();
index a4b9d05..3c8e423 100644 (file)
@@ -4,6 +4,9 @@
 // Use of this source code is governed by a BSD-style
 // license that can be found in the LICENSE file.
 
+// Test that the Go environment variables are present and accessible through
+// package os and package runtime.
+
 package main
 
 import (
@@ -12,18 +15,14 @@ import (
 )
 
 func main() {
-       ga, e0 := os.Getenverror("GOARCH")
-       if e0 != nil {
-               print("$GOARCH: ", e0.Error(), "\n")
-               os.Exit(1)
-       }
+       ga := os.Getenv("GOARCH")
        if ga != runtime.GOARCH {
                print("$GOARCH=", ga, "!= runtime.GOARCH=", runtime.GOARCH, "\n")
                os.Exit(1)
        }
-       xxx, e1 := os.Getenverror("DOES_NOT_EXIST")
-       if e1 != os.ENOENV {
-               print("$DOES_NOT_EXIST=", xxx, "; err = ", e1.Error(), "\n")
+       xxx := os.Getenv("DOES_NOT_EXIST")
+       if xxx != "" {
+               print("$DOES_NOT_EXIST=", xxx, "\n")
                os.Exit(1)
        }
 }
index f5f2c35..ebca790 100644 (file)
@@ -7,7 +7,7 @@
 package main
 
 import (
-       "os"
+       "errors"
        "strconv"
 )
 
@@ -44,7 +44,7 @@ func main() {
        }
        mm := make(map[string]error)
        trace = ""
-       mm["abc"] = os.EINVAL
+       mm["abc"] = errors.New("invalid")
        *i(), mm[f()] = strconv.Atoi(h())
        if mm["abc"] != nil || trace != "ifh" {
                println("BUG1", mm["abc"], trace)
index 1459285..c17fd7c 100644 (file)
@@ -9,13 +9,13 @@
 package main
 import "runtime"
 
-func foo(runtime.UintType, i int) {  // ERROR "cannot declare name runtime.UintType|named/anonymous mix"
-       println(i, runtime.UintType) 
+func foo(runtime.UintType, i int) {  // ERROR "cannot declare name runtime.UintType|named/anonymous mix|undefined identifier"
+       println(i, runtime.UintType) // GCCGO_ERROR "undefined identifier"
 }
 
 func bar(i int) {
-       runtime.UintType := i       // ERROR "cannot declare name runtime.UintType|non-name on left side"
-       println(runtime.UintType)       // GCCGO_ERROR "invalid use of type"
+       runtime.UintType := i       // ERROR "cannot declare name runtime.UintType|non-name on left side|undefined identifier"
+       println(runtime.UintType)       // GCCGO_ERROR "invalid use of type|undefined identifier"
 }
 
 func baz() {
index 569aa9c..17d01ce 100644 (file)
@@ -1,4 +1,4 @@
-52ba9506bd99
+f4470a54e6db
 
 The first line of this file holds the Mercurial revision number of the
 last merge done from the master library sources.
index 69244a8..99294f1 100644 (file)
@@ -225,7 +225,6 @@ toolexeclibgoexp_DATA = \
        $(exp_inotify_gox) \
        exp/norm.gox \
        exp/proxy.gox \
-       exp/signal.gox \
        exp/terminal.gox \
        exp/types.gox \
        exp/utf8string.gox
@@ -325,6 +324,7 @@ toolexeclibgoosdir = $(toolexeclibgodir)/os
 
 toolexeclibgoos_DATA = \
        os/exec.gox \
+       os/signal.gox \
        os/user.gox
 
 toolexeclibgopathdir = $(toolexeclibgodir)/path
@@ -352,8 +352,7 @@ toolexeclibgotestingdir = $(toolexeclibgodir)/testing
 
 toolexeclibgotesting_DATA = \
        testing/iotest.gox \
-       testing/quick.gox \
-       testing/script.gox
+       testing/quick.gox
 
 toolexeclibgotextdir = $(toolexeclibgodir)/text
 
@@ -398,6 +397,7 @@ runtime_files = \
        runtime/go-byte-array-to-string.c \
        runtime/go-breakpoint.c \
        runtime/go-caller.c \
+       runtime/go-callers.c \
        runtime/go-can-convert-interface.c \
        runtime/go-cgo.c \
        runtime/go-check-interface.c \
@@ -428,7 +428,6 @@ runtime_files = \
        runtime/go-panic.c \
        runtime/go-print.c \
        runtime/go-recover.c \
-       runtime/go-reflect.c \
        runtime/go-reflect-call.c \
        runtime/go-reflect-map.c \
        runtime/go-rune.c \
@@ -450,7 +449,6 @@ runtime_files = \
        runtime/go-type-string.c \
        runtime/go-typedesc-equal.c \
        runtime/go-typestring.c \
-       runtime/go-unreflect.c \
        runtime/go-unsafe-new.c \
        runtime/go-unsafe-newarray.c \
        runtime/go-unsafe-pointer.c \
@@ -468,6 +466,7 @@ runtime_files = \
        runtime/msize.c \
        runtime/proc.c \
        runtime/runtime.c \
+       runtime/signal_unix.c \
        runtime/thread.c \
        runtime/yield.c \
        $(rtems_task_variable_add_file) \
@@ -505,11 +504,11 @@ runtime1.c: $(srcdir)/runtime/runtime1.goc goc2c
        mv -f $@.tmp $@
 
 sema.c: $(srcdir)/runtime/sema.goc goc2c
-       ./goc2c --gcc --go-prefix libgo_runtime $< > $@.tmp
+       ./goc2c --gcc --go-prefix libgo_sync $< > $@.tmp
        mv -f $@.tmp $@
 
 sigqueue.c: $(srcdir)/runtime/sigqueue.goc goc2c
-       ./goc2c --gcc --go-prefix libgo_runtime $< > $@.tmp
+       ./goc2c --gcc --go-prefix libgo_os $< > $@.tmp
        mv -f $@.tmp $@
 
 time.c: $(srcdir)/runtime/time.goc goc2c
@@ -526,7 +525,8 @@ go_bufio_files = \
 go_bytes_files = \
        go/bytes/buffer.go \
        go/bytes/bytes.go \
-       go/bytes/bytes_decl.go
+       go/bytes/bytes_decl.go \
+       go/bytes/reader.go
 go_bytes_c_files = \
        go/bytes/indexbyte.c
 
@@ -658,10 +658,17 @@ go_net_sock_file = go/net/sock_linux.go
 go_net_sockopt_file = go/net/sockopt_linux.go
 go_net_sockoptip_file = go/net/sockoptip_linux.go
 else
+if LIBGO_IS_FREEBSD
 go_net_cgo_file = go/net/cgo_bsd.go
 go_net_sock_file = go/net/sock_bsd.go
 go_net_sockopt_file = go/net/sockopt_bsd.go
-go_net_sockoptip_file = go/net/sockoptip_bsd.go
+go_net_sockoptip_file = go/net/sockoptip_bsd.go go/net/sockoptip_freebsd.go
+else
+go_net_cgo_file = go/net/cgo_bsd.go
+go_net_sock_file = go/net/sock_bsd.go
+go_net_sockopt_file = go/net/sockopt_bsd.go
+go_net_sockoptip_file = go/net/sockoptip_bsd.go go/net/sockoptip_netbsd.go
+endif
 endif
 endif
 endif
@@ -704,6 +711,7 @@ go_net_files = \
        go/net/ipsock.go \
        go/net/ipsock_posix.go \
        go/net/lookup_unix.go \
+       go/net/mac.go \
        go/net/net.go \
        go/net/parse.go \
        go/net/pipe.go \
@@ -784,9 +792,7 @@ go_os_files = \
        $(go_os_stat_file) \
        go/os/str.go \
        $(go_os_sys_file) \
-       go/os/time.go \
-       go/os/types.go \
-       signal_unix.go
+       go/os/types.go
 
 go_path_files = \
        go/path/match.go \
@@ -811,7 +817,6 @@ go_runtime_files = \
        go/runtime/error.go \
        go/runtime/extern.go \
        go/runtime/mem.go \
-       go/runtime/sig.go \
        go/runtime/softfloat64.go \
        go/runtime/type.go \
        version.go
@@ -850,6 +855,7 @@ go_sync_files = \
        go/sync/cond.go \
        go/sync/mutex.go \
        go/sync/once.go \
+       go/sync/runtime.go \
        go/sync/rwmutex.go \
        go/sync/waitgroup.go
 
@@ -881,6 +887,7 @@ go_time_files = \
        go/time/tick.go \
        go/time/time.go \
        go/time/zoneinfo.go \
+       go/time/zoneinfo_read.go \
        go/time/zoneinfo_unix.go
 
 go_unicode_files = \
@@ -1017,12 +1024,14 @@ go_debug_dwarf_files = \
        go/debug/dwarf/buf.go \
        go/debug/dwarf/const.go \
        go/debug/dwarf/entry.go \
+       go/debug/dwarf/line.go \
        go/debug/dwarf/open.go \
        go/debug/dwarf/type.go \
        go/debug/dwarf/unit.go
 go_debug_elf_files = \
        go/debug/elf/elf.go \
-       go/debug/elf/file.go
+       go/debug/elf/file.go \
+       go/debug/elf/runtime.go
 go_debug_gosym_files = \
        go/debug/gosym/pclntab.go \
        go/debug/gosym/symtab.go
@@ -1094,6 +1103,7 @@ go_exp_norm_files = \
        go/exp/norm/composition.go \
        go/exp/norm/forminfo.go \
        go/exp/norm/input.go \
+       go/exp/norm/iter.go \
        go/exp/norm/normalize.go \
        go/exp/norm/readwriter.go \
        go/exp/norm/tables.go \
@@ -1103,8 +1113,6 @@ go_exp_proxy_files = \
        go/exp/proxy/per_host.go \
        go/exp/proxy/proxy.go \
        go/exp/proxy/socks5.go
-go_exp_signal_files = \
-       go/exp/signal/signal.go
 go_exp_terminal_files = \
        go/exp/terminal/terminal.go \
        go/exp/terminal/util.go
@@ -1128,8 +1136,7 @@ go_go_ast_files = \
        go/go/ast/walk.go
 go_go_build_files = \
        go/go/build/build.go \
-       go/go/build/dir.go \
-       go/go/build/path.go \
+       go/go/build/doc.go \
        syslist.go
 go_go_doc_files = \
        go/go/doc/comment.go \
@@ -1137,7 +1144,8 @@ go_go_doc_files = \
        go/go/doc/example.go \
        go/go/doc/exports.go \
        go/go/doc/filter.go \
-       go/go/doc/reader.go
+       go/go/doc/reader.go \
+       go/go/doc/synopsis.go
 go_go_parser_files = \
        go/go/parser/interface.go \
        go/go/parser/parser.go
@@ -1164,7 +1172,6 @@ go_hash_fnv_files = \
 
 go_html_template_files = \
        go/html/template/attr.go \
-       go/html/template/clone.go \
        go/html/template/content.go \
        go/html/template/context.go \
        go/html/template/css.go \
@@ -1302,6 +1309,10 @@ go_os_exec_files = \
        go/os/exec/exec.go \
        go/os/exec/lp_unix.go
 
+go_os_signal_files = \
+       go/os/signal/signal.go \
+       go/os/signal/signal_unix.go
+
 go_os_user_files = \
        go/os/user/user.go \
        go/os/user/lookup_unix.go
@@ -1352,8 +1363,6 @@ go_testing_iotest_files = \
        go/testing/iotest/writer.go
 go_testing_quick_files = \
        go/testing/quick/quick.go
-go_testing_script_files = \
-       go/testing/script/script.go
 
 go_text_scanner_files = \
        go/text/scanner/scanner.go
@@ -1529,6 +1538,7 @@ go_syscall_files = \
        syscall_arch.go
 go_syscall_c_files = \
        go/syscall/errno.c \
+       go/syscall/signame.c \
        $(syscall_wait_c_file)
 
 libcalls.go: s-libcalls; @true
@@ -1667,7 +1677,6 @@ libgo_go_objs = \
        exp/html.lo \
        exp/norm.lo \
        exp/proxy.lo \
-       exp/signal.lo \
        exp/terminal.lo \
        exp/types.lo \
        exp/utf8string.lo \
@@ -1712,6 +1721,7 @@ libgo_go_objs = \
        old/regexp.lo \
        old/template.lo \
        $(os_lib_inotify_lo) \
+       os/signal.lo \
        os/user.lo \
        path/filepath.lo \
        regexp/syntax.lo \
@@ -1722,6 +1732,7 @@ libgo_go_objs = \
        sync/atomic_c.lo \
        syscall/syscall.lo \
        syscall/errno.lo \
+       syscall/signame.lo \
        syscall/wait.lo \
        text/scanner.lo \
        text/tabwriter.lo \
@@ -1730,7 +1741,6 @@ libgo_go_objs = \
        testing/testing.lo \
        testing/iotest.lo \
        testing/quick.lo \
-       testing/script.lo \
        unicode/utf16.lo \
        unicode/utf8.lo
 
@@ -1986,10 +1996,6 @@ os/check: $(CHECK_DEPS)
        @$(CHECK)
 .PHONY: os/check
 
-signal_unix.go: $(srcdir)/go/os/mkunixsignals.sh sysinfo.go
-       $(SHELL) $(srcdir)/go/os/mkunixsignals.sh sysinfo.go > $@.tmp
-       mv -f $@.tmp $@
-
 @go_include@ path/path.lo.dep
 path/path.lo.dep: $(go_path_files)
        $(BUILDDEPS)
@@ -2599,16 +2605,6 @@ exp/proxy/check: $(CHECK_DEPS)
        @$(CHECK)
 .PHONY: exp/proxy/check
 
-@go_include@ exp/signal.lo.dep
-exp/signal.lo.dep: $(go_exp_signal_files)
-       $(BUILDDEPS)
-exp/signal.lo: $(go_exp_signal_files)
-       $(BUILDPACKAGE)
-exp/signal/check: $(CHECK_DEPS)
-       @$(MKDIR_P) exp/signal
-       @$(CHECK)
-.PHONY: exp/signal/check
-
 @go_include@ exp/terminal.lo.dep
 exp/terminal.lo.dep: $(go_exp_terminal_files)
        $(BUILDDEPS)
@@ -3060,6 +3056,16 @@ os/exec/check: $(CHECK_DEPS)
        @$(CHECK)
 .PHONY: os/exec/check
 
+@go_include@ os/signal.lo.dep
+os/signal.lo.dep: $(go_os_signal_files)
+       $(BUILDDEPS)
+os/signal.lo: $(go_os_signal_files)
+       $(BUILDPACKAGE)
+os/signal/check: $(CHECK_DEPS)
+       @$(MKDIR_P) os/signal
+       @$(CHECK)
+.PHONY: os/signal/check
+
 @go_include@ os/user.lo.dep
 os/user.lo.dep: $(go_os_user_files)
        $(BUILDDEPS)
@@ -3171,16 +3177,6 @@ testing/quick/check: $(CHECK_DEPS)
        @$(CHECK)
 .PHONY: testing/quick/check
 
-@go_include@ testing/script.lo.dep
-testing/script.lo.dep: $(go_testing_script_files)
-       $(BUILDDEPS)
-testing/script.lo: $(go_testing_script_files)
-       $(BUILDPACKAGE)
-testing/script/check: $(CHECK_DEPS)
-       @$(MKDIR_P) testing/script
-       @$(CHECK)
-.PHONY: testing/script/check
-
 @go_include@ unicode/utf16.lo.dep
 unicode/utf16.lo.dep: $(go_unicode_utf16_files)
        $(BUILDDEPS)
@@ -3208,6 +3204,8 @@ syscall/syscall.lo: $(go_syscall_files)
        $(BUILDPACKAGE)
 syscall/errno.lo: go/syscall/errno.c
        $(LTCOMPILE) -c -o $@ $<
+syscall/signame.lo: go/syscall/signame.c
+       $(LTCOMPILE) -c -o $@ $<
 syscall/wait.lo: go/syscall/wait.c
        $(LTCOMPILE) -c -o $@ $<
 
@@ -3384,8 +3382,6 @@ exp/norm.gox: exp/norm.lo
        $(BUILDGOX)
 exp/proxy.gox: exp/proxy.lo
        $(BUILDGOX)
-exp/signal.gox: exp/signal.lo
-       $(BUILDGOX)
 exp/terminal.gox: exp/terminal.lo
        $(BUILDGOX)
 exp/types.gox: exp/types.lo
@@ -3486,6 +3482,8 @@ old/template.gox: old/template.lo
 
 os/exec.gox: os/exec.lo
        $(BUILDGOX)
+os/signal.gox: os/signal.lo
+       $(BUILDGOX)
 os/user.gox: os/user.lo
        $(BUILDGOX)
 
@@ -3516,8 +3514,6 @@ testing/iotest.gox: testing/iotest.lo
        $(BUILDGOX)
 testing/quick.gox: testing/quick.lo
        $(BUILDGOX)
-testing/script.gox: testing/script.lo
-       $(BUILDGOX)
 
 unicode/utf16.gox: unicode/utf16.lo
        $(BUILDGOX)
@@ -3605,7 +3601,6 @@ TEST_PACKAGES = \
        $(exp_inotify_check) \
        exp/norm/check \
        exp/proxy/check \
-       exp/signal/check \
        exp/terminal/check \
        exp/utf8string/check \
        html/template/check \
@@ -3635,6 +3630,7 @@ TEST_PACKAGES = \
        net/http/check \
        net/http/cgi/check \
        net/http/fcgi/check \
+       net/http/httptest/check \
        net/http/httputil/check \
        net/mail/check \
        net/rpc/check \
@@ -3646,6 +3642,7 @@ TEST_PACKAGES = \
        old/regexp/check \
        old/template/check \
        os/exec/check \
+       os/signal/check \
        os/user/check \
        path/filepath/check \
        regexp/syntax/check \
@@ -3655,7 +3652,6 @@ TEST_PACKAGES = \
        text/template/check \
        text/template/parse/check \
        testing/quick/check \
-       testing/script/check \
        unicode/utf16/check \
        unicode/utf8/check
 
index 0fac351..b57d929 100644 (file)
@@ -154,25 +154,25 @@ am__DEPENDENCIES_2 = bufio/bufio.lo bytes/bytes.lo bytes/index.lo \
        encoding/base32.lo encoding/base64.lo encoding/binary.lo \
        encoding/csv.lo encoding/gob.lo encoding/hex.lo \
        encoding/json.lo encoding/pem.lo encoding/xml.lo exp/ebnf.lo \
-       exp/html.lo exp/norm.lo exp/proxy.lo exp/signal.lo \
-       exp/terminal.lo exp/types.lo exp/utf8string.lo \
-       html/template.lo go/ast.lo go/build.lo go/doc.lo go/parser.lo \
-       go/printer.lo go/scanner.lo go/token.lo hash/adler32.lo \
-       hash/crc32.lo hash/crc64.lo hash/fnv.lo net/http/cgi.lo \
-       net/http/fcgi.lo net/http/httptest.lo net/http/httputil.lo \
-       net/http/pprof.lo image/color.lo image/draw.lo image/gif.lo \
-       image/jpeg.lo image/png.lo index/suffixarray.lo io/ioutil.lo \
-       log/syslog.lo log/syslog/syslog_c.lo math/big.lo math/cmplx.lo \
-       math/rand.lo mime/mime.lo mime/multipart.lo net/http.lo \
-       net/mail.lo net/rpc.lo net/smtp.lo net/textproto.lo net/url.lo \
+       exp/html.lo exp/norm.lo exp/proxy.lo exp/terminal.lo \
+       exp/types.lo exp/utf8string.lo html/template.lo go/ast.lo \
+       go/build.lo go/doc.lo go/parser.lo go/printer.lo go/scanner.lo \
+       go/token.lo hash/adler32.lo hash/crc32.lo hash/crc64.lo \
+       hash/fnv.lo net/http/cgi.lo net/http/fcgi.lo \
+       net/http/httptest.lo net/http/httputil.lo net/http/pprof.lo \
+       image/color.lo image/draw.lo image/gif.lo image/jpeg.lo \
+       image/png.lo index/suffixarray.lo io/ioutil.lo log/syslog.lo \
+       log/syslog/syslog_c.lo math/big.lo math/cmplx.lo math/rand.lo \
+       mime/mime.lo mime/multipart.lo net/http.lo net/mail.lo \
+       net/rpc.lo net/smtp.lo net/textproto.lo net/url.lo \
        old/netchan.lo old/regexp.lo old/template.lo \
-       $(am__DEPENDENCIES_1) os/user.lo path/filepath.lo \
+       $(am__DEPENDENCIES_1) os/signal.lo os/user.lo path/filepath.lo \
        regexp/syntax.lo net/rpc/jsonrpc.lo runtime/debug.lo \
        runtime/pprof.lo sync/atomic.lo sync/atomic_c.lo \
-       syscall/syscall.lo syscall/errno.lo syscall/wait.lo \
-       text/scanner.lo text/tabwriter.lo text/template.lo \
-       text/template/parse.lo testing/testing.lo testing/iotest.lo \
-       testing/quick.lo testing/script.lo unicode/utf16.lo \
+       syscall/syscall.lo syscall/errno.lo syscall/signame.lo \
+       syscall/wait.lo text/scanner.lo text/tabwriter.lo \
+       text/template.lo text/template/parse.lo testing/testing.lo \
+       testing/iotest.lo testing/quick.lo unicode/utf16.lo \
        unicode/utf8.lo
 libgo_la_DEPENDENCIES = $(am__DEPENDENCIES_2) $(am__DEPENDENCIES_1) \
        $(am__DEPENDENCIES_1) $(am__DEPENDENCIES_1) \
@@ -180,14 +180,14 @@ libgo_la_DEPENDENCIES = $(am__DEPENDENCIES_2) $(am__DEPENDENCIES_1) \
 am__libgo_la_SOURCES_DIST = runtime/go-append.c runtime/go-assert.c \
        runtime/go-assert-interface.c \
        runtime/go-byte-array-to-string.c runtime/go-breakpoint.c \
-       runtime/go-caller.c runtime/go-can-convert-interface.c \
-       runtime/go-cgo.c runtime/go-check-interface.c \
-       runtime/go-construct-map.c runtime/go-convert-interface.c \
-       runtime/go-copy.c runtime/go-defer.c \
-       runtime/go-deferred-recover.c runtime/go-eface-compare.c \
-       runtime/go-eface-val-compare.c runtime/go-getgoroot.c \
-       runtime/go-int-array-to-string.c runtime/go-int-to-string.c \
-       runtime/go-interface-compare.c \
+       runtime/go-caller.c runtime/go-callers.c \
+       runtime/go-can-convert-interface.c runtime/go-cgo.c \
+       runtime/go-check-interface.c runtime/go-construct-map.c \
+       runtime/go-convert-interface.c runtime/go-copy.c \
+       runtime/go-defer.c runtime/go-deferred-recover.c \
+       runtime/go-eface-compare.c runtime/go-eface-val-compare.c \
+       runtime/go-getgoroot.c runtime/go-int-array-to-string.c \
+       runtime/go-int-to-string.c runtime/go-interface-compare.c \
        runtime/go-interface-eface-compare.c \
        runtime/go-interface-val-compare.c runtime/go-make-slice.c \
        runtime/go-map-delete.c runtime/go-map-index.c \
@@ -195,10 +195,9 @@ am__libgo_la_SOURCES_DIST = runtime/go-append.c runtime/go-assert.c \
        runtime/go-matherr.c runtime/go-nanotime.c runtime/go-now.c \
        runtime/go-new-map.c runtime/go-new.c runtime/go-nosys.c \
        runtime/go-panic.c runtime/go-print.c runtime/go-recover.c \
-       runtime/go-reflect.c runtime/go-reflect-call.c \
-       runtime/go-reflect-map.c runtime/go-rune.c \
-       runtime/go-runtime-error.c runtime/go-setenv.c \
-       runtime/go-signal.c runtime/go-strcmp.c \
+       runtime/go-reflect-call.c runtime/go-reflect-map.c \
+       runtime/go-rune.c runtime/go-runtime-error.c \
+       runtime/go-setenv.c runtime/go-signal.c runtime/go-strcmp.c \
        runtime/go-string-to-byte-array.c \
        runtime/go-string-to-int-array.c runtime/go-strplus.c \
        runtime/go-strslice.c runtime/go-trampoline.c \
@@ -206,15 +205,15 @@ am__libgo_la_SOURCES_DIST = runtime/go-append.c runtime/go-assert.c \
        runtime/go-type-error.c runtime/go-type-float.c \
        runtime/go-type-identity.c runtime/go-type-interface.c \
        runtime/go-type-string.c runtime/go-typedesc-equal.c \
-       runtime/go-typestring.c runtime/go-unreflect.c \
-       runtime/go-unsafe-new.c runtime/go-unsafe-newarray.c \
-       runtime/go-unsafe-pointer.c runtime/go-unwind.c runtime/chan.c \
-       runtime/cpuprof.c runtime/lock_sema.c runtime/thread-sema.c \
-       runtime/lock_futex.c runtime/thread-linux.c runtime/mcache.c \
-       runtime/mcentral.c runtime/mem_posix_memalign.c runtime/mem.c \
-       runtime/mfinal.c runtime/mfixalloc.c runtime/mgc0.c \
-       runtime/mheap.c runtime/msize.c runtime/proc.c \
-       runtime/runtime.c runtime/thread.c runtime/yield.c \
+       runtime/go-typestring.c runtime/go-unsafe-new.c \
+       runtime/go-unsafe-newarray.c runtime/go-unsafe-pointer.c \
+       runtime/go-unwind.c runtime/chan.c runtime/cpuprof.c \
+       runtime/lock_sema.c runtime/thread-sema.c runtime/lock_futex.c \
+       runtime/thread-linux.c runtime/mcache.c runtime/mcentral.c \
+       runtime/mem_posix_memalign.c runtime/mem.c runtime/mfinal.c \
+       runtime/mfixalloc.c runtime/mgc0.c runtime/mheap.c \
+       runtime/msize.c runtime/proc.c runtime/runtime.c \
+       runtime/signal_unix.c runtime/thread.c runtime/yield.c \
        runtime/rtems-task-variable-add.c iface.c malloc.c map.c \
        mprof.c reflect.c runtime1.c sema.c sigqueue.c string.c time.c
 @LIBGO_IS_LINUX_FALSE@am__objects_1 = lock_sema.lo thread-sema.lo
@@ -224,30 +223,30 @@ am__libgo_la_SOURCES_DIST = runtime/go-append.c runtime/go-assert.c \
 @LIBGO_IS_RTEMS_TRUE@am__objects_3 = rtems-task-variable-add.lo
 am__objects_4 = go-append.lo go-assert.lo go-assert-interface.lo \
        go-byte-array-to-string.lo go-breakpoint.lo go-caller.lo \
-       go-can-convert-interface.lo go-cgo.lo go-check-interface.lo \
-       go-construct-map.lo go-convert-interface.lo go-copy.lo \
-       go-defer.lo go-deferred-recover.lo go-eface-compare.lo \
+       go-callers.lo go-can-convert-interface.lo go-cgo.lo \
+       go-check-interface.lo go-construct-map.lo \
+       go-convert-interface.lo go-copy.lo go-defer.lo \
+       go-deferred-recover.lo go-eface-compare.lo \
        go-eface-val-compare.lo go-getgoroot.lo \
        go-int-array-to-string.lo go-int-to-string.lo \
        go-interface-compare.lo go-interface-eface-compare.lo \
        go-interface-val-compare.lo go-make-slice.lo go-map-delete.lo \
        go-map-index.lo go-map-len.lo go-map-range.lo go-matherr.lo \
        go-nanotime.lo go-now.lo go-new-map.lo go-new.lo go-nosys.lo \
-       go-panic.lo go-print.lo go-recover.lo go-reflect.lo \
-       go-reflect-call.lo go-reflect-map.lo go-rune.lo \
-       go-runtime-error.lo go-setenv.lo go-signal.lo go-strcmp.lo \
-       go-string-to-byte-array.lo go-string-to-int-array.lo \
-       go-strplus.lo go-strslice.lo go-trampoline.lo \
-       go-type-complex.lo go-type-eface.lo go-type-error.lo \
-       go-type-float.lo go-type-identity.lo go-type-interface.lo \
-       go-type-string.lo go-typedesc-equal.lo go-typestring.lo \
-       go-unreflect.lo go-unsafe-new.lo go-unsafe-newarray.lo \
+       go-panic.lo go-print.lo go-recover.lo go-reflect-call.lo \
+       go-reflect-map.lo go-rune.lo go-runtime-error.lo go-setenv.lo \
+       go-signal.lo go-strcmp.lo go-string-to-byte-array.lo \
+       go-string-to-int-array.lo go-strplus.lo go-strslice.lo \
+       go-trampoline.lo go-type-complex.lo go-type-eface.lo \
+       go-type-error.lo go-type-float.lo go-type-identity.lo \
+       go-type-interface.lo go-type-string.lo go-typedesc-equal.lo \
+       go-typestring.lo go-unsafe-new.lo go-unsafe-newarray.lo \
        go-unsafe-pointer.lo go-unwind.lo chan.lo cpuprof.lo \
        $(am__objects_1) mcache.lo mcentral.lo $(am__objects_2) \
        mfinal.lo mfixalloc.lo mgc0.lo mheap.lo msize.lo proc.lo \
-       runtime.lo thread.lo yield.lo $(am__objects_3) iface.lo \
-       malloc.lo map.lo mprof.lo reflect.lo runtime1.lo sema.lo \
-       sigqueue.lo string.lo time.lo
+       runtime.lo signal_unix.lo thread.lo yield.lo $(am__objects_3) \
+       iface.lo malloc.lo map.lo mprof.lo reflect.lo runtime1.lo \
+       sema.lo sigqueue.lo string.lo time.lo
 am_libgo_la_OBJECTS = $(am__objects_4)
 libgo_la_OBJECTS = $(am_libgo_la_OBJECTS)
 libgo_la_LINK = $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) \
@@ -679,7 +678,6 @@ toolexeclibgoexp_DATA = \
        $(exp_inotify_gox) \
        exp/norm.gox \
        exp/proxy.gox \
-       exp/signal.gox \
        exp/terminal.gox \
        exp/types.gox \
        exp/utf8string.gox
@@ -765,6 +763,7 @@ toolexeclibgoold_DATA = \
 toolexeclibgoosdir = $(toolexeclibgodir)/os
 toolexeclibgoos_DATA = \
        os/exec.gox \
+       os/signal.gox \
        os/user.gox
 
 toolexeclibgopathdir = $(toolexeclibgodir)/path
@@ -787,8 +786,7 @@ toolexeclibgosync_DATA = \
 toolexeclibgotestingdir = $(toolexeclibgodir)/testing
 toolexeclibgotesting_DATA = \
        testing/iotest.gox \
-       testing/quick.gox \
-       testing/script.gox
+       testing/quick.gox
 
 toolexeclibgotextdir = $(toolexeclibgodir)/text
 toolexeclibgotext_DATA = \
@@ -818,6 +816,7 @@ runtime_files = \
        runtime/go-byte-array-to-string.c \
        runtime/go-breakpoint.c \
        runtime/go-caller.c \
+       runtime/go-callers.c \
        runtime/go-can-convert-interface.c \
        runtime/go-cgo.c \
        runtime/go-check-interface.c \
@@ -848,7 +847,6 @@ runtime_files = \
        runtime/go-panic.c \
        runtime/go-print.c \
        runtime/go-recover.c \
-       runtime/go-reflect.c \
        runtime/go-reflect-call.c \
        runtime/go-reflect-map.c \
        runtime/go-rune.c \
@@ -870,7 +868,6 @@ runtime_files = \
        runtime/go-type-string.c \
        runtime/go-typedesc-equal.c \
        runtime/go-typestring.c \
-       runtime/go-unreflect.c \
        runtime/go-unsafe-new.c \
        runtime/go-unsafe-newarray.c \
        runtime/go-unsafe-pointer.c \
@@ -888,6 +885,7 @@ runtime_files = \
        runtime/msize.c \
        runtime/proc.c \
        runtime/runtime.c \
+       runtime/signal_unix.c \
        runtime/thread.c \
        runtime/yield.c \
        $(rtems_task_variable_add_file) \
@@ -908,7 +906,8 @@ go_bufio_files = \
 go_bytes_files = \
        go/bytes/buffer.go \
        go/bytes/bytes.go \
-       go/bytes/bytes_decl.go
+       go/bytes/bytes_decl.go \
+       go/bytes/reader.go
 
 go_bytes_c_files = \
        go/bytes/indexbyte.c
@@ -1013,19 +1012,23 @@ go_mime_files = \
 @LIBGO_IS_LINUX_FALSE@@LIBGO_IS_NETBSD_TRUE@@LIBGO_IS_RTEMS_FALSE@go_net_newpollserver_file = go/net/newpollserver.go
 @LIBGO_IS_LINUX_TRUE@@LIBGO_IS_RTEMS_FALSE@go_net_newpollserver_file = go/net/newpollserver.go
 @LIBGO_IS_RTEMS_TRUE@go_net_newpollserver_file = go/net/newpollserver_rtems.go
-@LIBGO_IS_IRIX_FALSE@@LIBGO_IS_LINUX_FALSE@@LIBGO_IS_SOLARIS_FALSE@go_net_cgo_file = go/net/cgo_bsd.go
+@LIBGO_IS_FREEBSD_FALSE@@LIBGO_IS_IRIX_FALSE@@LIBGO_IS_LINUX_FALSE@@LIBGO_IS_SOLARIS_FALSE@go_net_cgo_file = go/net/cgo_bsd.go
+@LIBGO_IS_FREEBSD_TRUE@@LIBGO_IS_IRIX_FALSE@@LIBGO_IS_LINUX_FALSE@@LIBGO_IS_SOLARIS_FALSE@go_net_cgo_file = go/net/cgo_bsd.go
 @LIBGO_IS_IRIX_FALSE@@LIBGO_IS_LINUX_FALSE@@LIBGO_IS_SOLARIS_TRUE@go_net_cgo_file = go/net/cgo_linux.go
 @LIBGO_IS_IRIX_TRUE@@LIBGO_IS_LINUX_FALSE@go_net_cgo_file = go/net/cgo_linux.go
 @LIBGO_IS_LINUX_TRUE@go_net_cgo_file = go/net/cgo_linux.go
-@LIBGO_IS_IRIX_FALSE@@LIBGO_IS_LINUX_FALSE@@LIBGO_IS_SOLARIS_FALSE@go_net_sock_file = go/net/sock_bsd.go
+@LIBGO_IS_FREEBSD_FALSE@@LIBGO_IS_IRIX_FALSE@@LIBGO_IS_LINUX_FALSE@@LIBGO_IS_SOLARIS_FALSE@go_net_sock_file = go/net/sock_bsd.go
+@LIBGO_IS_FREEBSD_TRUE@@LIBGO_IS_IRIX_FALSE@@LIBGO_IS_LINUX_FALSE@@LIBGO_IS_SOLARIS_FALSE@go_net_sock_file = go/net/sock_bsd.go
 @LIBGO_IS_IRIX_FALSE@@LIBGO_IS_LINUX_FALSE@@LIBGO_IS_SOLARIS_TRUE@go_net_sock_file = go/net/sock_linux.go
 @LIBGO_IS_IRIX_TRUE@@LIBGO_IS_LINUX_FALSE@go_net_sock_file = go/net/sock_linux.go
 @LIBGO_IS_LINUX_TRUE@go_net_sock_file = go/net/sock_linux.go
-@LIBGO_IS_IRIX_FALSE@@LIBGO_IS_LINUX_FALSE@@LIBGO_IS_SOLARIS_FALSE@go_net_sockopt_file = go/net/sockopt_bsd.go
+@LIBGO_IS_FREEBSD_FALSE@@LIBGO_IS_IRIX_FALSE@@LIBGO_IS_LINUX_FALSE@@LIBGO_IS_SOLARIS_FALSE@go_net_sockopt_file = go/net/sockopt_bsd.go
+@LIBGO_IS_FREEBSD_TRUE@@LIBGO_IS_IRIX_FALSE@@LIBGO_IS_LINUX_FALSE@@LIBGO_IS_SOLARIS_FALSE@go_net_sockopt_file = go/net/sockopt_bsd.go
 @LIBGO_IS_IRIX_FALSE@@LIBGO_IS_LINUX_FALSE@@LIBGO_IS_SOLARIS_TRUE@go_net_sockopt_file = go/net/sockopt_linux.go
 @LIBGO_IS_IRIX_TRUE@@LIBGO_IS_LINUX_FALSE@go_net_sockopt_file = go/net/sockopt_linux.go
 @LIBGO_IS_LINUX_TRUE@go_net_sockopt_file = go/net/sockopt_linux.go
-@LIBGO_IS_IRIX_FALSE@@LIBGO_IS_LINUX_FALSE@@LIBGO_IS_SOLARIS_FALSE@go_net_sockoptip_file = go/net/sockoptip_bsd.go
+@LIBGO_IS_FREEBSD_FALSE@@LIBGO_IS_IRIX_FALSE@@LIBGO_IS_LINUX_FALSE@@LIBGO_IS_SOLARIS_FALSE@go_net_sockoptip_file = go/net/sockoptip_bsd.go go/net/sockoptip_netbsd.go
+@LIBGO_IS_FREEBSD_TRUE@@LIBGO_IS_IRIX_FALSE@@LIBGO_IS_LINUX_FALSE@@LIBGO_IS_SOLARIS_FALSE@go_net_sockoptip_file = go/net/sockoptip_bsd.go go/net/sockoptip_freebsd.go
 @LIBGO_IS_IRIX_FALSE@@LIBGO_IS_LINUX_FALSE@@LIBGO_IS_SOLARIS_TRUE@go_net_sockoptip_file = go/net/sockoptip_linux.go
 @LIBGO_IS_IRIX_TRUE@@LIBGO_IS_LINUX_FALSE@go_net_sockoptip_file = go/net/sockoptip_linux.go
 @LIBGO_IS_LINUX_TRUE@go_net_sockoptip_file = go/net/sockoptip_linux.go
@@ -1056,6 +1059,7 @@ go_net_files = \
        go/net/ipsock.go \
        go/net/ipsock_posix.go \
        go/net/lookup_unix.go \
+       go/net/mac.go \
        go/net/net.go \
        go/net/parse.go \
        go/net/pipe.go \
@@ -1106,9 +1110,7 @@ go_os_files = \
        $(go_os_stat_file) \
        go/os/str.go \
        $(go_os_sys_file) \
-       go/os/time.go \
-       go/os/types.go \
-       signal_unix.go
+       go/os/types.go
 
 go_path_files = \
        go/path/match.go \
@@ -1133,7 +1135,6 @@ go_runtime_files = \
        go/runtime/error.go \
        go/runtime/extern.go \
        go/runtime/mem.go \
-       go/runtime/sig.go \
        go/runtime/softfloat64.go \
        go/runtime/type.go \
        version.go
@@ -1161,6 +1162,7 @@ go_sync_files = \
        go/sync/cond.go \
        go/sync/mutex.go \
        go/sync/once.go \
+       go/sync/runtime.go \
        go/sync/rwmutex.go \
        go/sync/waitgroup.go
 
@@ -1186,6 +1188,7 @@ go_time_files = \
        go/time/tick.go \
        go/time/time.go \
        go/time/zoneinfo.go \
+       go/time/zoneinfo_read.go \
        go/time/zoneinfo_unix.go
 
 go_unicode_files = \
@@ -1337,13 +1340,15 @@ go_debug_dwarf_files = \
        go/debug/dwarf/buf.go \
        go/debug/dwarf/const.go \
        go/debug/dwarf/entry.go \
+       go/debug/dwarf/line.go \
        go/debug/dwarf/open.go \
        go/debug/dwarf/type.go \
        go/debug/dwarf/unit.go
 
 go_debug_elf_files = \
        go/debug/elf/elf.go \
-       go/debug/elf/file.go
+       go/debug/elf/file.go \
+       go/debug/elf/runtime.go
 
 go_debug_gosym_files = \
        go/debug/gosym/pclntab.go \
@@ -1431,6 +1436,7 @@ go_exp_norm_files = \
        go/exp/norm/composition.go \
        go/exp/norm/forminfo.go \
        go/exp/norm/input.go \
+       go/exp/norm/iter.go \
        go/exp/norm/normalize.go \
        go/exp/norm/readwriter.go \
        go/exp/norm/tables.go \
@@ -1442,9 +1448,6 @@ go_exp_proxy_files = \
        go/exp/proxy/proxy.go \
        go/exp/proxy/socks5.go
 
-go_exp_signal_files = \
-       go/exp/signal/signal.go
-
 go_exp_terminal_files = \
        go/exp/terminal/terminal.go \
        go/exp/terminal/util.go
@@ -1471,8 +1474,7 @@ go_go_ast_files = \
 
 go_go_build_files = \
        go/go/build/build.go \
-       go/go/build/dir.go \
-       go/go/build/path.go \
+       go/go/build/doc.go \
        syslist.go
 
 go_go_doc_files = \
@@ -1481,7 +1483,8 @@ go_go_doc_files = \
        go/go/doc/example.go \
        go/go/doc/exports.go \
        go/go/doc/filter.go \
-       go/go/doc/reader.go
+       go/go/doc/reader.go \
+       go/go/doc/synopsis.go
 
 go_go_parser_files = \
        go/go/parser/interface.go \
@@ -1515,7 +1518,6 @@ go_hash_fnv_files = \
 
 go_html_template_files = \
        go/html/template/attr.go \
-       go/html/template/clone.go \
        go/html/template/content.go \
        go/html/template/context.go \
        go/html/template/css.go \
@@ -1664,6 +1666,10 @@ go_os_exec_files = \
        go/os/exec/exec.go \
        go/os/exec/lp_unix.go
 
+go_os_signal_files = \
+       go/os/signal/signal.go \
+       go/os/signal/signal_unix.go
+
 go_os_user_files = \
        go/os/user/user.go \
        go/os/user/lookup_unix.go
@@ -1720,9 +1726,6 @@ go_testing_iotest_files = \
 go_testing_quick_files = \
        go/testing/quick/quick.go
 
-go_testing_script_files = \
-       go/testing/script/script.go
-
 go_text_scanner_files = \
        go/text/scanner/scanner.go
 
@@ -1833,6 +1836,7 @@ go_syscall_files = \
 
 go_syscall_c_files = \
        go/syscall/errno.c \
+       go/syscall/signame.c \
        $(syscall_wait_c_file)
 
 @LIBGO_IS_LINUX_FALSE@os_lib_inotify_lo = 
@@ -1917,7 +1921,6 @@ libgo_go_objs = \
        exp/html.lo \
        exp/norm.lo \
        exp/proxy.lo \
-       exp/signal.lo \
        exp/terminal.lo \
        exp/types.lo \
        exp/utf8string.lo \
@@ -1962,6 +1965,7 @@ libgo_go_objs = \
        old/regexp.lo \
        old/template.lo \
        $(os_lib_inotify_lo) \
+       os/signal.lo \
        os/user.lo \
        path/filepath.lo \
        regexp/syntax.lo \
@@ -1972,6 +1976,7 @@ libgo_go_objs = \
        sync/atomic_c.lo \
        syscall/syscall.lo \
        syscall/errno.lo \
+       syscall/signame.lo \
        syscall/wait.lo \
        text/scanner.lo \
        text/tabwriter.lo \
@@ -1980,7 +1985,6 @@ libgo_go_objs = \
        testing/testing.lo \
        testing/iotest.lo \
        testing/quick.lo \
-       testing/script.lo \
        unicode/utf16.lo \
        unicode/utf8.lo
 
@@ -2166,7 +2170,6 @@ TEST_PACKAGES = \
        $(exp_inotify_check) \
        exp/norm/check \
        exp/proxy/check \
-       exp/signal/check \
        exp/terminal/check \
        exp/utf8string/check \
        html/template/check \
@@ -2196,6 +2199,7 @@ TEST_PACKAGES = \
        net/http/check \
        net/http/cgi/check \
        net/http/fcgi/check \
+       net/http/httptest/check \
        net/http/httputil/check \
        net/mail/check \
        net/rpc/check \
@@ -2207,6 +2211,7 @@ TEST_PACKAGES = \
        old/regexp/check \
        old/template/check \
        os/exec/check \
+       os/signal/check \
        os/user/check \
        path/filepath/check \
        regexp/syntax/check \
@@ -2216,7 +2221,6 @@ TEST_PACKAGES = \
        text/template/check \
        text/template/parse/check \
        testing/quick/check \
-       testing/script/check \
        unicode/utf16/check \
        unicode/utf8/check
 
@@ -2362,6 +2366,7 @@ distclean-compile:
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/go-breakpoint.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/go-byte-array-to-string.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/go-caller.Plo@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/go-callers.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/go-can-convert-interface.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/go-cgo.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/go-check-interface.Plo@am__quote@
@@ -2395,7 +2400,6 @@ distclean-compile:
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/go-recover.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/go-reflect-call.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/go-reflect-map.Plo@am__quote@
-@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/go-reflect.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/go-rune.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/go-runtime-error.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/go-setenv.Plo@am__quote@
@@ -2415,7 +2419,6 @@ distclean-compile:
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/go-type-string.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/go-typedesc-equal.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/go-typestring.Plo@am__quote@
-@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/go-unreflect.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/go-unsafe-new.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/go-unsafe-newarray.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/go-unsafe-pointer.Plo@am__quote@
@@ -2441,6 +2444,7 @@ distclean-compile:
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/runtime.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/runtime1.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/sema.Plo@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/signal_unix.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/sigqueue.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/string.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/thread-linux.Plo@am__quote@
@@ -2526,6 +2530,13 @@ go-caller.lo: runtime/go-caller.c
 @AMDEP_TRUE@@am__fastdepCC_FALSE@      DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
 @am__fastdepCC_FALSE@  $(LIBTOOL)  --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o go-caller.lo `test -f 'runtime/go-caller.c' || echo '$(srcdir)/'`runtime/go-caller.c
 
+go-callers.lo: runtime/go-callers.c
+@am__fastdepCC_TRUE@   $(LIBTOOL)  --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT go-callers.lo -MD -MP -MF $(DEPDIR)/go-callers.Tpo -c -o go-callers.lo `test -f 'runtime/go-callers.c' || echo '$(srcdir)/'`runtime/go-callers.c
+@am__fastdepCC_TRUE@   $(am__mv) $(DEPDIR)/go-callers.Tpo $(DEPDIR)/go-callers.Plo
+@AMDEP_TRUE@@am__fastdepCC_FALSE@      source='runtime/go-callers.c' object='go-callers.lo' libtool=yes @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@      DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@  $(LIBTOOL)  --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o go-callers.lo `test -f 'runtime/go-callers.c' || echo '$(srcdir)/'`runtime/go-callers.c
+
 go-can-convert-interface.lo: runtime/go-can-convert-interface.c
 @am__fastdepCC_TRUE@   $(LIBTOOL)  --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT go-can-convert-interface.lo -MD -MP -MF $(DEPDIR)/go-can-convert-interface.Tpo -c -o go-can-convert-interface.lo `test -f 'runtime/go-can-convert-interface.c' || echo '$(srcdir)/'`runtime/go-can-convert-interface.c
 @am__fastdepCC_TRUE@   $(am__mv) $(DEPDIR)/go-can-convert-interface.Tpo $(DEPDIR)/go-can-convert-interface.Plo
@@ -2736,13 +2747,6 @@ go-recover.lo: runtime/go-recover.c
 @AMDEP_TRUE@@am__fastdepCC_FALSE@      DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
 @am__fastdepCC_FALSE@  $(LIBTOOL)  --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o go-recover.lo `test -f 'runtime/go-recover.c' || echo '$(srcdir)/'`runtime/go-recover.c
 
-go-reflect.lo: runtime/go-reflect.c
-@am__fastdepCC_TRUE@   $(LIBTOOL)  --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT go-reflect.lo -MD -MP -MF $(DEPDIR)/go-reflect.Tpo -c -o go-reflect.lo `test -f 'runtime/go-reflect.c' || echo '$(srcdir)/'`runtime/go-reflect.c
-@am__fastdepCC_TRUE@   $(am__mv) $(DEPDIR)/go-reflect.Tpo $(DEPDIR)/go-reflect.Plo
-@AMDEP_TRUE@@am__fastdepCC_FALSE@      source='runtime/go-reflect.c' object='go-reflect.lo' libtool=yes @AMDEPBACKSLASH@
-@AMDEP_TRUE@@am__fastdepCC_FALSE@      DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
-@am__fastdepCC_FALSE@  $(LIBTOOL)  --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o go-reflect.lo `test -f 'runtime/go-reflect.c' || echo '$(srcdir)/'`runtime/go-reflect.c
-
 go-reflect-call.lo: runtime/go-reflect-call.c
 @am__fastdepCC_TRUE@   $(LIBTOOL)  --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT go-reflect-call.lo -MD -MP -MF $(DEPDIR)/go-reflect-call.Tpo -c -o go-reflect-call.lo `test -f 'runtime/go-reflect-call.c' || echo '$(srcdir)/'`runtime/go-reflect-call.c
 @am__fastdepCC_TRUE@   $(am__mv) $(DEPDIR)/go-reflect-call.Tpo $(DEPDIR)/go-reflect-call.Plo
@@ -2890,13 +2894,6 @@ go-typestring.lo: runtime/go-typestring.c
 @AMDEP_TRUE@@am__fastdepCC_FALSE@      DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
 @am__fastdepCC_FALSE@  $(LIBTOOL)  --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o go-typestring.lo `test -f 'runtime/go-typestring.c' || echo '$(srcdir)/'`runtime/go-typestring.c
 
-go-unreflect.lo: runtime/go-unreflect.c
-@am__fastdepCC_TRUE@   $(LIBTOOL)  --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT go-unreflect.lo -MD -MP -MF $(DEPDIR)/go-unreflect.Tpo -c -o go-unreflect.lo `test -f 'runtime/go-unreflect.c' || echo '$(srcdir)/'`runtime/go-unreflect.c
-@am__fastdepCC_TRUE@   $(am__mv) $(DEPDIR)/go-unreflect.Tpo $(DEPDIR)/go-unreflect.Plo
-@AMDEP_TRUE@@am__fastdepCC_FALSE@      source='runtime/go-unreflect.c' object='go-unreflect.lo' libtool=yes @AMDEPBACKSLASH@
-@AMDEP_TRUE@@am__fastdepCC_FALSE@      DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
-@am__fastdepCC_FALSE@  $(LIBTOOL)  --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o go-unreflect.lo `test -f 'runtime/go-unreflect.c' || echo '$(srcdir)/'`runtime/go-unreflect.c
-
 go-unsafe-new.lo: runtime/go-unsafe-new.c
 @am__fastdepCC_TRUE@   $(LIBTOOL)  --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT go-unsafe-new.lo -MD -MP -MF $(DEPDIR)/go-unsafe-new.Tpo -c -o go-unsafe-new.lo `test -f 'runtime/go-unsafe-new.c' || echo '$(srcdir)/'`runtime/go-unsafe-new.c
 @am__fastdepCC_TRUE@   $(am__mv) $(DEPDIR)/go-unsafe-new.Tpo $(DEPDIR)/go-unsafe-new.Plo
@@ -3044,6 +3041,13 @@ runtime.lo: runtime/runtime.c
 @AMDEP_TRUE@@am__fastdepCC_FALSE@      DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
 @am__fastdepCC_FALSE@  $(LIBTOOL)  --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o runtime.lo `test -f 'runtime/runtime.c' || echo '$(srcdir)/'`runtime/runtime.c
 
+signal_unix.lo: runtime/signal_unix.c
+@am__fastdepCC_TRUE@   $(LIBTOOL)  --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT signal_unix.lo -MD -MP -MF $(DEPDIR)/signal_unix.Tpo -c -o signal_unix.lo `test -f 'runtime/signal_unix.c' || echo '$(srcdir)/'`runtime/signal_unix.c
+@am__fastdepCC_TRUE@   $(am__mv) $(DEPDIR)/signal_unix.Tpo $(DEPDIR)/signal_unix.Plo
+@AMDEP_TRUE@@am__fastdepCC_FALSE@      source='runtime/signal_unix.c' object='signal_unix.lo' libtool=yes @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@      DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@  $(LIBTOOL)  --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o signal_unix.lo `test -f 'runtime/signal_unix.c' || echo '$(srcdir)/'`runtime/signal_unix.c
+
 thread.lo: runtime/thread.c
 @am__fastdepCC_TRUE@   $(LIBTOOL)  --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT thread.lo -MD -MP -MF $(DEPDIR)/thread.Tpo -c -o thread.lo `test -f 'runtime/thread.c' || echo '$(srcdir)/'`runtime/thread.c
 @am__fastdepCC_TRUE@   $(am__mv) $(DEPDIR)/thread.Tpo $(DEPDIR)/thread.Plo
@@ -4323,11 +4327,11 @@ runtime1.c: $(srcdir)/runtime/runtime1.goc goc2c
        mv -f $@.tmp $@
 
 sema.c: $(srcdir)/runtime/sema.goc goc2c
-       ./goc2c --gcc --go-prefix libgo_runtime $< > $@.tmp
+       ./goc2c --gcc --go-prefix libgo_sync $< > $@.tmp
        mv -f $@.tmp $@
 
 sigqueue.c: $(srcdir)/runtime/sigqueue.goc goc2c
-       ./goc2c --gcc --go-prefix libgo_runtime $< > $@.tmp
+       ./goc2c --gcc --go-prefix libgo_os $< > $@.tmp
        mv -f $@.tmp $@
 
 time.c: $(srcdir)/runtime/time.goc goc2c
@@ -4548,10 +4552,6 @@ os/check: $(CHECK_DEPS)
        @$(CHECK)
 .PHONY: os/check
 
-signal_unix.go: $(srcdir)/go/os/mkunixsignals.sh sysinfo.go
-       $(SHELL) $(srcdir)/go/os/mkunixsignals.sh sysinfo.go > $@.tmp
-       mv -f $@.tmp $@
-
 @go_include@ path/path.lo.dep
 path/path.lo.dep: $(go_path_files)
        $(BUILDDEPS)
@@ -5161,16 +5161,6 @@ exp/proxy/check: $(CHECK_DEPS)
        @$(CHECK)
 .PHONY: exp/proxy/check
 
-@go_include@ exp/signal.lo.dep
-exp/signal.lo.dep: $(go_exp_signal_files)
-       $(BUILDDEPS)
-exp/signal.lo: $(go_exp_signal_files)
-       $(BUILDPACKAGE)
-exp/signal/check: $(CHECK_DEPS)
-       @$(MKDIR_P) exp/signal
-       @$(CHECK)
-.PHONY: exp/signal/check
-
 @go_include@ exp/terminal.lo.dep
 exp/terminal.lo.dep: $(go_exp_terminal_files)
        $(BUILDDEPS)
@@ -5622,6 +5612,16 @@ os/exec/check: $(CHECK_DEPS)
        @$(CHECK)
 .PHONY: os/exec/check
 
+@go_include@ os/signal.lo.dep
+os/signal.lo.dep: $(go_os_signal_files)
+       $(BUILDDEPS)
+os/signal.lo: $(go_os_signal_files)
+       $(BUILDPACKAGE)
+os/signal/check: $(CHECK_DEPS)
+       @$(MKDIR_P) os/signal
+       @$(CHECK)
+.PHONY: os/signal/check
+
 @go_include@ os/user.lo.dep
 os/user.lo.dep: $(go_os_user_files)
        $(BUILDDEPS)
@@ -5733,16 +5733,6 @@ testing/quick/check: $(CHECK_DEPS)
        @$(CHECK)
 .PHONY: testing/quick/check
 
-@go_include@ testing/script.lo.dep
-testing/script.lo.dep: $(go_testing_script_files)
-       $(BUILDDEPS)
-testing/script.lo: $(go_testing_script_files)
-       $(BUILDPACKAGE)
-testing/script/check: $(CHECK_DEPS)
-       @$(MKDIR_P) testing/script
-       @$(CHECK)
-.PHONY: testing/script/check
-
 @go_include@ unicode/utf16.lo.dep
 unicode/utf16.lo.dep: $(go_unicode_utf16_files)
        $(BUILDDEPS)
@@ -5770,6 +5760,8 @@ syscall/syscall.lo: $(go_syscall_files)
        $(BUILDPACKAGE)
 syscall/errno.lo: go/syscall/errno.c
        $(LTCOMPILE) -c -o $@ $<
+syscall/signame.lo: go/syscall/signame.c
+       $(LTCOMPILE) -c -o $@ $<
 syscall/wait.lo: go/syscall/wait.c
        $(LTCOMPILE) -c -o $@ $<
 
@@ -5941,8 +5933,6 @@ exp/norm.gox: exp/norm.lo
        $(BUILDGOX)
 exp/proxy.gox: exp/proxy.lo
        $(BUILDGOX)
-exp/signal.gox: exp/signal.lo
-       $(BUILDGOX)
 exp/terminal.gox: exp/terminal.lo
        $(BUILDGOX)
 exp/types.gox: exp/types.lo
@@ -6043,6 +6033,8 @@ old/template.gox: old/template.lo
 
 os/exec.gox: os/exec.lo
        $(BUILDGOX)
+os/signal.gox: os/signal.lo
+       $(BUILDGOX)
 os/user.gox: os/user.lo
        $(BUILDGOX)
 
@@ -6073,8 +6065,6 @@ testing/iotest.gox: testing/iotest.lo
        $(BUILDGOX)
 testing/quick.gox: testing/quick.lo
        $(BUILDGOX)
-testing/script.gox: testing/script.lo
-       $(BUILDGOX)
 
 unicode/utf16.gox: unicode/utf16.lo
        $(BUILDGOX)
index 22f2969..ccb79e1 100644 (file)
 /* Define to 1 if you have the `unshare' function. */
 #undef HAVE_UNSHARE
 
-/* Define to 1 if you have the <ustat.h> header file. */
+/* Define to 1 if you have the <ustat.h> header file and it works. */
 #undef HAVE_USTAT_H
 
 /* Define to 1 if you have the <utime.h> header file. */
index 6a4fb91..d1c17f1 100755 (executable)
@@ -14508,7 +14508,7 @@ no)
   ;;
 esac
 
-for ac_header in sys/mman.h syscall.h sys/epoll.h sys/ptrace.h sys/syscall.h sys/user.h sys/utsname.h sys/select.h sys/socket.h net/if.h sys/prctl.h sys/mount.h sys/vfs.h sys/statfs.h sys/timex.h sys/sysinfo.h ustat.h utime.h linux/reboot.h
+for ac_header in sys/mman.h syscall.h sys/epoll.h sys/ptrace.h sys/syscall.h sys/user.h sys/utsname.h sys/select.h sys/socket.h net/if.h sys/prctl.h sys/mount.h sys/vfs.h sys/statfs.h sys/timex.h sys/sysinfo.h utime.h linux/reboot.h
 do :
   as_ac_Header=`$as_echo "ac_cv_header_$ac_header" | $as_tr_sh`
 ac_fn_c_check_header_mongrel "$LINENO" "$ac_header" "$as_ac_Header" "$ac_includes_default"
 done
 
 
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether <ustat.h> can be used" >&5
+$as_echo_n "checking whether <ustat.h> can be used... " >&6; }
+if test "${libgo_cv_c_ustat_h+set}" = set; then :
+  $as_echo_n "(cached) " >&6
+else
+  CFLAGS_hold=$CFLAGS
+CFLAGS="$CFLAGS -D_LARGEFILE_SOURCE -D_LARGEFILE64_SOURCE $OSCFLAGS"
+cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+
+#include <sys/types.h>
+#ifdef HAVE_LINUX_FILTER_H
+#include <linux/filter.h>
+#endif
+#include <ustat.h>
+
+_ACEOF
+if ac_fn_c_try_compile "$LINENO"; then :
+  libgo_cv_c_ustat_h=yes
+else
+  libgo_cv_c_ustat_h=no
+fi
+rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
+CFLAGS=$CFLAGS_hold
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $libgo_cv_c_ustat_h" >&5
+$as_echo "$libgo_cv_c_ustat_h" >&6; }
+if test $libgo_cv_c_ustat_h = yes; then
+
+$as_echo "#define HAVE_USTAT_H 1" >>confdefs.h
+
+fi
+
  if test "$ac_cv_header_sys_mman_h" = yes; then
   HAVE_SYS_MMAN_H_TRUE=
   HAVE_SYS_MMAN_H_FALSE='#'
index f2e23a6..63c5faf 100644 (file)
@@ -453,7 +453,7 @@ no)
   ;;
 esac
 
-AC_CHECK_HEADERS(sys/mman.h syscall.h sys/epoll.h sys/ptrace.h sys/syscall.h sys/user.h sys/utsname.h sys/select.h sys/socket.h net/if.h sys/prctl.h sys/mount.h sys/vfs.h sys/statfs.h sys/timex.h sys/sysinfo.h ustat.h utime.h linux/reboot.h)
+AC_CHECK_HEADERS(sys/mman.h syscall.h sys/epoll.h sys/ptrace.h sys/syscall.h sys/user.h sys/utsname.h sys/select.h sys/socket.h net/if.h sys/prctl.h sys/mount.h sys/vfs.h sys/statfs.h sys/timex.h sys/sysinfo.h utime.h linux/reboot.h)
 
 AC_CHECK_HEADERS([linux/filter.h linux/netlink.h linux/rtnetlink.h], [], [],
 [#ifdef HAVE_SYS_SOCKET_H
@@ -461,6 +461,24 @@ AC_CHECK_HEADERS([linux/filter.h linux/netlink.h linux/rtnetlink.h], [], [],
 #endif
 ])
 
+AC_CACHE_CHECK([whether <ustat.h> can be used],
+[libgo_cv_c_ustat_h],
+[CFLAGS_hold=$CFLAGS
+CFLAGS="$CFLAGS -D_LARGEFILE_SOURCE -D_LARGEFILE64_SOURCE $OSCFLAGS"
+AC_COMPILE_IFELSE(
+[AC_LANG_SOURCE([
+#include <sys/types.h>
+#ifdef HAVE_LINUX_FILTER_H
+#include <linux/filter.h>
+#endif
+#include <ustat.h>
+])], [libgo_cv_c_ustat_h=yes], [libgo_cv_c_ustat_h=no])
+CFLAGS=$CFLAGS_hold])
+if test $libgo_cv_c_ustat_h = yes; then
+  AC_DEFINE(HAVE_USTAT_H, 1,
+    [Define to 1 if you have the <ustat.h> header file and it works.])
+fi
+
 AM_CONDITIONAL(HAVE_SYS_MMAN_H, test "$ac_cv_header_sys_mman_h" = yes)
 
 AC_CHECK_FUNCS(strerror_r strsignal wait4 mincore setenv)
index c300986..f3826dc 100644 (file)
@@ -169,48 +169,21 @@ func (r *checksumReader) Read(b []byte) (n int, err error) {
 
 func (r *checksumReader) Close() error { return r.rc.Close() }
 
-func readFileHeader(f *File, r io.Reader) error {
-       var b [fileHeaderLen]byte
-       if _, err := io.ReadFull(r, b[:]); err != nil {
-               return err
-       }
-       c := binary.LittleEndian
-       if sig := c.Uint32(b[:4]); sig != fileHeaderSignature {
-               return ErrFormat
-       }
-       f.ReaderVersion = c.Uint16(b[4:6])
-       f.Flags = c.Uint16(b[6:8])
-       f.Method = c.Uint16(b[8:10])
-       f.ModifiedTime = c.Uint16(b[10:12])
-       f.ModifiedDate = c.Uint16(b[12:14])
-       f.CRC32 = c.Uint32(b[14:18])
-       f.CompressedSize = c.Uint32(b[18:22])
-       f.UncompressedSize = c.Uint32(b[22:26])
-       filenameLen := int(c.Uint16(b[26:28]))
-       extraLen := int(c.Uint16(b[28:30]))
-       d := make([]byte, filenameLen+extraLen)
-       if _, err := io.ReadFull(r, d); err != nil {
-               return err
-       }
-       f.Name = string(d[:filenameLen])
-       f.Extra = d[filenameLen:]
-       return nil
-}
-
 // findBodyOffset does the minimum work to verify the file has a header
 // and returns the file body offset.
 func (f *File) findBodyOffset() (int64, error) {
        r := io.NewSectionReader(f.zipr, f.headerOffset, f.zipsize-f.headerOffset)
-       var b [fileHeaderLen]byte
-       if _, err := io.ReadFull(r, b[:]); err != nil {
+       var buf [fileHeaderLen]byte
+       if _, err := io.ReadFull(r, buf[:]); err != nil {
                return 0, err
        }
-       c := binary.LittleEndian
-       if sig := c.Uint32(b[:4]); sig != fileHeaderSignature {
+       b := readBuf(buf[:])
+       if sig := b.uint32(); sig != fileHeaderSignature {
                return 0, ErrFormat
        }
-       filenameLen := int(c.Uint16(b[26:28]))
-       extraLen := int(c.Uint16(b[28:30]))
+       b = b[22:] // skip over most of the header
+       filenameLen := int(b.uint16())
+       extraLen := int(b.uint16())
        return int64(fileHeaderLen + filenameLen + extraLen), nil
 }
 
@@ -218,30 +191,29 @@ func (f *File) findBodyOffset() (int64, error) {
 // It returns io.ErrUnexpectedEOF if it cannot read a complete header,
 // and ErrFormat if it doesn't find a valid header signature.
 func readDirectoryHeader(f *File, r io.Reader) error {
-       var b [directoryHeaderLen]byte
-       if _, err := io.ReadFull(r, b[:]); err != nil {
+       var buf [directoryHeaderLen]byte
+       if _, err := io.ReadFull(r, buf[:]); err != nil {
                return err
        }
-       c := binary.LittleEndian
-       if sig := c.Uint32(b[:4]); sig != directoryHeaderSignature {
+       b := readBuf(buf[:])
+       if sig := b.uint32(); sig != directoryHeaderSignature {
                return ErrFormat
        }
-       f.CreatorVersion = c.Uint16(b[4:6])
-       f.ReaderVersion = c.Uint16(b[6:8])
-       f.Flags = c.Uint16(b[8:10])
-       f.Method = c.Uint16(b[10:12])
-       f.ModifiedTime = c.Uint16(b[12:14])
-       f.ModifiedDate = c.Uint16(b[14:16])
-       f.CRC32 = c.Uint32(b[16:20])
-       f.CompressedSize = c.Uint32(b[20:24])
-       f.UncompressedSize = c.Uint32(b[24:28])
-       filenameLen := int(c.Uint16(b[28:30]))
-       extraLen := int(c.Uint16(b[30:32]))
-       commentLen := int(c.Uint16(b[32:34]))
-       // startDiskNumber := c.Uint16(b[34:36])    // Unused
-       // internalAttributes := c.Uint16(b[36:38]) // Unused
-       f.ExternalAttrs = c.Uint32(b[38:42])
-       f.headerOffset = int64(c.Uint32(b[42:46]))
+       f.CreatorVersion = b.uint16()
+       f.ReaderVersion = b.uint16()
+       f.Flags = b.uint16()
+       f.Method = b.uint16()
+       f.ModifiedTime = b.uint16()
+       f.ModifiedDate = b.uint16()
+       f.CRC32 = b.uint32()
+       f.CompressedSize = b.uint32()
+       f.UncompressedSize = b.uint32()
+       filenameLen := int(b.uint16())
+       extraLen := int(b.uint16())
+       commentLen := int(b.uint16())
+       b = b[4:] // skipped start disk number and internal attributes (2x uint16)
+       f.ExternalAttrs = b.uint32()
+       f.headerOffset = int64(b.uint32())
        d := make([]byte, filenameLen+extraLen+commentLen)
        if _, err := io.ReadFull(r, d); err != nil {
                return err
@@ -253,30 +225,30 @@ func readDirectoryHeader(f *File, r io.Reader) error {
 }
 
 func readDataDescriptor(r io.Reader, f *File) error {
-       var b [dataDescriptorLen]byte
-       if _, err := io.ReadFull(r, b[:]); err != nil {
+       var buf [dataDescriptorLen]byte
+       if _, err := io.ReadFull(r, buf[:]); err != nil {
                return err
        }
-       c := binary.LittleEndian
-       f.CRC32 = c.Uint32(b[:4])
-       f.CompressedSize = c.Uint32(b[4:8])
-       f.UncompressedSize = c.Uint32(b[8:12])
+       b := readBuf(buf[:])
+       f.CRC32 = b.uint32()
+       f.CompressedSize = b.uint32()
+       f.UncompressedSize = b.uint32()
        return nil
 }
 
 func readDirectoryEnd(r io.ReaderAt, size int64) (dir *directoryEnd, err error) {
        // look for directoryEndSignature in the last 1k, then in the last 65k
-       var b []byte
+       var buf []byte
        for i, bLen := range []int64{1024, 65 * 1024} {
                if bLen > size {
                        bLen = size
                }
-               b = make([]byte, int(bLen))
-               if _, err := r.ReadAt(b, size-bLen); err != nil && err != io.EOF {
+               buf = make([]byte, int(bLen))
+               if _, err := r.ReadAt(buf, size-bLen); err != nil && err != io.EOF {
                        return nil, err
                }
-               if p := findSignatureInBlock(b); p >= 0 {
-                       b = b[p:]
+               if p := findSignatureInBlock(buf); p >= 0 {
+                       buf = buf[p:]
                        break
                }
                if i == 1 || bLen == size {
@@ -285,16 +257,21 @@ func readDirectoryEnd(r io.ReaderAt, size int64) (dir *directoryEnd, err error)
        }
 
        // read header into struct
-       c := binary.LittleEndian
-       d := new(directoryEnd)
-       d.diskNbr = c.Uint16(b[4:6])
-       d.dirDiskNbr = c.Uint16(b[6:8])
-       d.dirRecordsThisDisk = c.Uint16(b[8:10])
-       d.directoryRecords = c.Uint16(b[10:12])
-       d.directorySize = c.Uint32(b[12:16])
-       d.directoryOffset = c.Uint32(b[16:20])
-       d.commentLen = c.Uint16(b[20:22])
-       d.comment = string(b[22 : 22+int(d.commentLen)])
+       b := readBuf(buf[4:]) // skip signature
+       d := &directoryEnd{
+               diskNbr:            b.uint16(),
+               dirDiskNbr:         b.uint16(),
+               dirRecordsThisDisk: b.uint16(),
+               directoryRecords:   b.uint16(),
+               directorySize:      b.uint32(),
+               directoryOffset:    b.uint32(),
+               commentLen:         b.uint16(),
+       }
+       l := int(d.commentLen)
+       if l > len(b) {
+               return nil, errors.New("zip: invalid comment length")
+       }
+       d.comment = string(b[:l])
        return d, nil
 }
 
@@ -311,3 +288,17 @@ func findSignatureInBlock(b []byte) int {
        }
        return -1
 }
+
+type readBuf []byte
+
+func (b *readBuf) uint16() uint16 {
+       v := binary.LittleEndian.Uint16(*b)
+       *b = (*b)[2:]
+       return v
+}
+
+func (b *readBuf) uint32() uint32 {
+       v := binary.LittleEndian.Uint32(*b)
+       *b = (*b)[4:]
+       return v
+}
index 935860e..066a615 100644 (file)
@@ -165,7 +165,7 @@ func readTestZip(t *testing.T, zt ZipTest) {
                t.Errorf("%s: comment=%q, want %q", zt.Name, z.Comment, zt.Comment)
        }
        if len(z.File) != len(zt.File) {
-               t.Errorf("%s: file count=%d, want %d", zt.Name, len(z.File), len(zt.File))
+               t.Fatalf("%s: file count=%d, want %d", zt.Name, len(z.File), len(zt.File))
        }
 
        // test read of each file
@@ -278,7 +278,7 @@ func TestInvalidFiles(t *testing.T) {
        b := make([]byte, size)
 
        // zeroes
-       _, err := NewReader(sliceReaderAt(b), size)
+       _, err := NewReader(bytes.NewReader(b), size)
        if err != ErrFormat {
                t.Errorf("zeroes: error=%v, want %v", err, ErrFormat)
        }
@@ -289,15 +289,8 @@ func TestInvalidFiles(t *testing.T) {
        for i := 0; i < size-4; i += 4 {
                copy(b[i:i+4], sig)
        }
-       _, err = NewReader(sliceReaderAt(b), size)
+       _, err = NewReader(bytes.NewReader(b), size)
        if err != ErrFormat {
                t.Errorf("sigs: error=%v, want %v", err, ErrFormat)
        }
 }
-
-type sliceReaderAt []byte
-
-func (r sliceReaderAt) ReadAt(b []byte, off int64) (int, error) {
-       copy(b, r[int(off):int(off)+len(b)])
-       return len(b), nil
-}
index 35dcec6..fdbd16d 100644 (file)
@@ -100,16 +100,6 @@ type directoryEnd struct {
        comment            string
 }
 
-func recoverError(errp *error) {
-       if e := recover(); e != nil {
-               if err, ok := e.(error); ok {
-                       *errp = err
-                       return
-               }
-               panic(e)
-       }
-}
-
 // msDosTimeToTime converts an MS-DOS date and time into a time.Time.
 // The resolution is 2s.
 // See: http://msdn.microsoft.com/en-us/library/ms724247(v=VS.85).aspx
index a4f0654..b2cc55b 100644 (file)
@@ -19,7 +19,7 @@ import (
 
 // Writer implements a zip file writer.
 type Writer struct {
-       countWriter
+       cw     *countWriter
        dir    []*header
        last   *fileWriter
        closed bool
@@ -32,15 +32,15 @@ type header struct {
 
 // NewWriter returns a new Writer writing a zip file to w.
 func NewWriter(w io.Writer) *Writer {
-       return &Writer{countWriter: countWriter{w: bufio.NewWriter(w)}}
+       return &Writer{cw: &countWriter{w: bufio.NewWriter(w)}}
 }
 
 // Close finishes writing the zip file by writing the central directory.
 // It does not (and can not) close the underlying writer.
-func (w *Writer) Close() (err error) {
+func (w *Writer) Close() error {
        if w.last != nil && !w.last.closed {
-               if err = w.last.close(); err != nil {
-                       return
+               if err := w.last.close(); err != nil {
+                       return err
                }
                w.last = nil
        }
@@ -49,45 +49,57 @@ func (w *Writer) Close() (err error) {
        }
        w.closed = true
 
-       defer recoverError(&err)
-
        // write central directory
-       start := w.count
+       start := w.cw.count
        for _, h := range w.dir {
-               write(w, uint32(directoryHeaderSignature))
-               write(w, h.CreatorVersion)
-               write(w, h.ReaderVersion)
-               write(w, h.Flags)
-               write(w, h.Method)
-               write(w, h.ModifiedTime)
-               write(w, h.ModifiedDate)
-               write(w, h.CRC32)
-               write(w, h.CompressedSize)
-               write(w, h.UncompressedSize)
-               write(w, uint16(len(h.Name)))
-               write(w, uint16(len(h.Extra)))
-               write(w, uint16(len(h.Comment)))
-               write(w, uint16(0)) // disk number start
-               write(w, uint16(0)) // internal file attributes
-               write(w, h.ExternalAttrs)
-               write(w, h.offset)
-               writeBytes(w, []byte(h.Name))
-               writeBytes(w, h.Extra)
-               writeBytes(w, []byte(h.Comment))
+               var buf [directoryHeaderLen]byte
+               b := writeBuf(buf[:])
+               b.uint32(uint32(directoryHeaderSignature))
+               b.uint16(h.CreatorVersion)
+               b.uint16(h.ReaderVersion)
+               b.uint16(h.Flags)
+               b.uint16(h.Method)
+               b.uint16(h.ModifiedTime)
+               b.uint16(h.ModifiedDate)
+               b.uint32(h.CRC32)
+               b.uint32(h.CompressedSize)
+               b.uint32(h.UncompressedSize)
+               b.uint16(uint16(len(h.Name)))
+               b.uint16(uint16(len(h.Extra)))
+               b.uint16(uint16(len(h.Comment)))
+               b = b[4:] // skip disk number start and internal file attr (2x uint16)
+               b.uint32(h.ExternalAttrs)
+               b.uint32(h.offset)
+               if _, err := w.cw.Write(buf[:]); err != nil {
+                       return err
+               }
+               if _, err := io.WriteString(w.cw, h.Name); err != nil {
+                       return err
+               }
+               if _, err := w.cw.Write(h.Extra); err != nil {
+                       return err
+               }
+               if _, err := io.WriteString(w.cw, h.Comment); err != nil {
+                       return err
+               }
        }
-       end := w.count
+       end := w.cw.count
 
        // write end record
-       write(w, uint32(directoryEndSignature))
-       write(w, uint16(0))          // disk number
-       write(w, uint16(0))          // disk number where directory starts
-       write(w, uint16(len(w.dir))) // number of entries this disk
-       write(w, uint16(len(w.dir))) // number of entries total
-       write(w, uint32(end-start))  // size of directory
-       write(w, uint32(start))      // start of directory
-       write(w, uint16(0))          // size of comment
+       var buf [directoryEndLen]byte
+       b := writeBuf(buf[:])
+       b.uint32(uint32(directoryEndSignature))
+       b = b[4:]                     // skip over disk number and first disk number (2x uint16)
+       b.uint16(uint16(len(w.dir)))  // number of entries this disk
+       b.uint16(uint16(len(w.dir)))  // number of entries total
+       b.uint32(uint32(end - start)) // size of directory
+       b.uint32(uint32(start))       // start of directory
+       // skipped size of comment (always zero)
+       if _, err := w.cw.Write(buf[:]); err != nil {
+               return err
+       }
 
-       return w.w.(*bufio.Writer).Flush()
+       return w.cw.w.(*bufio.Writer).Flush()
 }
 
 // Create adds a file to the zip file using the provided name.
@@ -119,15 +131,19 @@ func (w *Writer) CreateHeader(fh *FileHeader) (io.Writer, error) {
        fh.ReaderVersion = 0x14
 
        fw := &fileWriter{
-               zipw:      w,
-               compCount: &countWriter{w: w},
+               zipw:      w.cw,
+               compCount: &countWriter{w: w.cw},
                crc32:     crc32.NewIEEE(),
        }
        switch fh.Method {
        case Store:
                fw.comp = nopCloser{fw.compCount}
        case Deflate:
-               fw.comp = flate.NewWriter(fw.compCount, 5)
+               var err error
+               fw.comp, err = flate.NewWriter(fw.compCount, 5)
+               if err != nil {
+                       return nil, err
+               }
        default:
                return nil, ErrAlgorithm
        }
@@ -135,12 +151,12 @@ func (w *Writer) CreateHeader(fh *FileHeader) (io.Writer, error) {
 
        h := &header{
                FileHeader: fh,
-               offset:     uint32(w.count),
+               offset:     uint32(w.cw.count),
        }
        w.dir = append(w.dir, h)
        fw.header = h
 
-       if err := writeHeader(w, fh); err != nil {
+       if err := writeHeader(w.cw, fh); err != nil {
                return nil, err
        }
 
@@ -148,22 +164,28 @@ func (w *Writer) CreateHeader(fh *FileHeader) (io.Writer, error) {
        return fw, nil
 }
 
-func writeHeader(w io.Writer, h *FileHeader) (err error) {
-       defer recoverError(&err)
-       write(w, uint32(fileHeaderSignature))
-       write(w, h.ReaderVersion)
-       write(w, h.Flags)
-       write(w, h.Method)
-       write(w, h.ModifiedTime)
-       write(w, h.ModifiedDate)
-       write(w, h.CRC32)
-       write(w, h.CompressedSize)
-       write(w, h.UncompressedSize)
-       write(w, uint16(len(h.Name)))
-       write(w, uint16(len(h.Extra)))
-       writeBytes(w, []byte(h.Name))
-       writeBytes(w, h.Extra)
-       return nil
+func writeHeader(w io.Writer, h *FileHeader) error {
+       var buf [fileHeaderLen]byte
+       b := writeBuf(buf[:])
+       b.uint32(uint32(fileHeaderSignature))
+       b.uint16(h.ReaderVersion)
+       b.uint16(h.Flags)
+       b.uint16(h.Method)
+       b.uint16(h.ModifiedTime)
+       b.uint16(h.ModifiedDate)
+       b.uint32(h.CRC32)
+       b.uint32(h.CompressedSize)
+       b.uint32(h.UncompressedSize)
+       b.uint16(uint16(len(h.Name)))
+       b.uint16(uint16(len(h.Extra)))
+       if _, err := w.Write(buf[:]); err != nil {
+               return err
+       }
+       if _, err := io.WriteString(w, h.Name); err != nil {
+               return err
+       }
+       _, err := w.Write(h.Extra)
+       return err
 }
 
 type fileWriter struct {
@@ -184,13 +206,13 @@ func (w *fileWriter) Write(p []byte) (int, error) {
        return w.rawCount.Write(p)
 }
 
-func (w *fileWriter) close() (err error) {
+func (w *fileWriter) close() error {
        if w.closed {
                return errors.New("zip: file closed twice")
        }
        w.closed = true
-       if err = w.comp.Close(); err != nil {
-               return
+       if err := w.comp.Close(); err != nil {
+               return err
        }
 
        // update FileHeader
@@ -200,12 +222,13 @@ func (w *fileWriter) close() (err error) {
        fh.UncompressedSize = uint32(w.rawCount.count)
 
        // write data descriptor
-       defer recoverError(&err)
-       write(w.zipw, fh.CRC32)
-       write(w.zipw, fh.CompressedSize)
-       write(w.zipw, fh.UncompressedSize)
-
-       return nil
+       var buf [dataDescriptorLen]byte
+       b := writeBuf(buf[:])
+       b.uint32(fh.CRC32)
+       b.uint32(fh.CompressedSize)
+       b.uint32(fh.UncompressedSize)
+       _, err := w.zipw.Write(buf[:])
+       return err
 }
 
 type countWriter struct {
@@ -227,18 +250,14 @@ func (w nopCloser) Close() error {
        return nil
 }
 
-func write(w io.Writer, data interface{}) {
-       if err := binary.Write(w, binary.LittleEndian, data); err != nil {
-               panic(err)
-       }
+type writeBuf []byte
+
+func (b *writeBuf) uint16(v uint16) {
+       binary.LittleEndian.PutUint16(*b, v)
+       *b = (*b)[2:]
 }
 
-func writeBytes(w io.Writer, b []byte) {
-       n, err := w.Write(b)
-       if err != nil {
-               panic(err)
-       }
-       if n != len(b) {
-               panic(io.ErrShortWrite)
-       }
+func (b *writeBuf) uint32(v uint32) {
+       binary.LittleEndian.PutUint32(*b, v)
+       *b = (*b)[4:]
 }
index ce93fae..88e5211 100644 (file)
@@ -77,7 +77,7 @@ func TestWriter(t *testing.T) {
        }
 
        // read it back
-       r, err := NewReader(sliceReaderAt(buf.Bytes()), int64(buf.Len()))
+       r, err := NewReader(bytes.NewReader(buf.Bytes()), int64(buf.Len()))
        if err != nil {
                t.Fatal(err)
        }
index 1a260cc..d6490c4 100644 (file)
@@ -9,22 +9,12 @@ package zip
 import (
        "bytes"
        "fmt"
-       "io"
        "reflect"
+       "strings"
        "testing"
        "time"
 )
 
-type stringReaderAt string
-
-func (s stringReaderAt) ReadAt(p []byte, off int64) (n int, err error) {
-       if off >= int64(len(s)) {
-               return 0, io.EOF
-       }
-       n = copy(p, s[off:])
-       return
-}
-
 func TestOver65kFiles(t *testing.T) {
        if testing.Short() {
                t.Logf("slow test; skipping")
@@ -42,8 +32,8 @@ func TestOver65kFiles(t *testing.T) {
        if err := w.Close(); err != nil {
                t.Fatalf("Writer.Close: %v", err)
        }
-       rat := stringReaderAt(buf.String())
-       zr, err := NewReader(rat, int64(len(rat)))
+       s := buf.String()
+       zr, err := NewReader(strings.NewReader(s), int64(len(s)))
        if err != nil {
                t.Fatalf("NewReader: %v", err)
        }
index 156dddf..b44d0e7 100644 (file)
@@ -23,7 +23,6 @@ var (
        ErrInvalidUnreadRune = errors.New("bufio: invalid use of UnreadRune")
        ErrBufferFull        = errors.New("bufio: buffer full")
        ErrNegativeCount     = errors.New("bufio: negative count")
-       errInternal          = errors.New("bufio: internal error")
 )
 
 // Buffered input.
@@ -106,9 +105,12 @@ func (b *Reader) Peek(n int) ([]byte, error) {
        if m > n {
                m = n
        }
-       err := b.readErr()
-       if m < n && err == nil {
-               err = ErrBufferFull
+       var err error
+       if m < n {
+               err = b.readErr()
+               if err == nil {
+                       err = ErrBufferFull
+               }
        }
        return b.buf[b.r : b.r+m], err
 }
index 9aec61e..a43cbd2 100644 (file)
@@ -539,6 +539,27 @@ func TestPeek(t *testing.T) {
        if _, err := buf.Peek(1); err != io.EOF {
                t.Fatalf("want EOF got %v", err)
        }
+
+       // Test for issue 3022, not exposing a reader's error on a successful Peek.
+       buf = NewReaderSize(dataAndEOFReader("abcd"), 32)
+       if s, err := buf.Peek(2); string(s) != "ab" || err != nil {
+               t.Errorf(`Peek(2) on "abcd", EOF = %q, %v; want "ab", nil`, string(s), err)
+       }
+       if s, err := buf.Peek(4); string(s) != "abcd" || err != nil {
+               t.Errorf(`Peek(4) on "abcd", EOF = %q, %v; want "abcd", nil`, string(s), err)
+       }
+       if n, err := buf.Read(p[0:5]); string(p[0:n]) != "abcd" || err != nil {
+               t.Fatalf("Read after peek = %q, %v; want abcd, EOF", p[0:n], err)
+       }
+       if n, err := buf.Read(p[0:1]); string(p[0:n]) != "" || err != io.EOF {
+               t.Fatalf(`second Read after peek = %q, %v; want "", EOF`, p[0:n], err)
+       }
+}
+
+type dataAndEOFReader string
+
+func (r dataAndEOFReader) Read(p []byte) (int, error) {
+       return copy(p, r), io.EOF
 }
 
 func TestPeekThenUnreadRune(t *testing.T) {
index a95c2af..afdf220 100644 (file)
@@ -182,14 +182,21 @@ func makeSlice(n int) []byte {
 func (b *Buffer) WriteTo(w io.Writer) (n int64, err error) {
        b.lastRead = opInvalid
        if b.off < len(b.buf) {
+               nBytes := b.Len()
                m, e := w.Write(b.buf[b.off:])
+               if m > nBytes {
+                       panic("bytes.Buffer.WriteTo: invalid Write count")
+               }
                b.off += m
                n = int64(m)
                if e != nil {
                        return n, e
                }
-               // otherwise all bytes were written, by definition of
+               // all bytes should have been written, by definition of
                // Write method in io.Writer
+               if m != nBytes {
+                       return n, io.ErrShortWrite
+               }
        }
        // Buffer is now empty; reset.
        b.Truncate(0)
index e94a0ec..7d1426f 100644 (file)
@@ -13,6 +13,7 @@ import (
 
 // Compare returns an integer comparing the two byte arrays lexicographically.
 // The result will be 0 if a==b, -1 if a < b, and +1 if a > b
+// A nil argument is equivalent to an empty slice.
 func Compare(a, b []byte) int {
        m := len(a)
        if m > len(b) {
@@ -37,6 +38,7 @@ func Compare(a, b []byte) int {
 }
 
 // Equal returns a boolean reporting whether a == b.
+// A nil argument is equivalent to an empty slice.
 func Equal(a, b []byte) bool
 
 func equalPortable(a, b []byte) bool {
index 2a1d41b..000f235 100644 (file)
@@ -46,32 +46,39 @@ type BinOpTest struct {
        i int
 }
 
-var comparetests = []BinOpTest{
-       {"", "", 0},
-       {"a", "", 1},
-       {"", "a", -1},
-       {"abc", "abc", 0},
-       {"ab", "abc", -1},
-       {"abc", "ab", 1},
-       {"x", "ab", 1},
-       {"ab", "x", -1},
-       {"x", "a", 1},
-       {"b", "x", -1},
+var compareTests = []struct {
+       a, b []byte
+       i    int
+}{
+       {[]byte(""), []byte(""), 0},
+       {[]byte("a"), []byte(""), 1},
+       {[]byte(""), []byte("a"), -1},
+       {[]byte("abc"), []byte("abc"), 0},
+       {[]byte("ab"), []byte("abc"), -1},
+       {[]byte("abc"), []byte("ab"), 1},
+       {[]byte("x"), []byte("ab"), 1},
+       {[]byte("ab"), []byte("x"), -1},
+       {[]byte("x"), []byte("a"), 1},
+       {[]byte("b"), []byte("x"), -1},
+       // nil tests
+       {nil, nil, 0},
+       {[]byte(""), nil, 0},
+       {nil, []byte(""), 0},
+       {[]byte("a"), nil, 1},
+       {nil, []byte("a"), -1},
 }
 
 func TestCompare(t *testing.T) {
-       for _, tt := range comparetests {
-               a := []byte(tt.a)
-               b := []byte(tt.b)
-               cmp := Compare(a, b)
+       for _, tt := range compareTests {
+               cmp := Compare(tt.a, tt.b)
                if cmp != tt.i {
                        t.Errorf(`Compare(%q, %q) = %v`, tt.a, tt.b, cmp)
                }
-               eql := Equal(a, b)
+               eql := Equal(tt.a, tt.b)
                if eql != (tt.i == 0) {
                        t.Errorf(`Equal(%q, %q) = %v`, tt.a, tt.b, eql)
                }
-               eql = EqualPortable(a, b)
+               eql = EqualPortable(tt.a, tt.b)
                if eql != (tt.i == 0) {
                        t.Errorf(`EqualPortable(%q, %q) = %v`, tt.a, tt.b, eql)
                }
index 0234a01..6fe8cd5 100644 (file)
@@ -11,18 +11,18 @@ import (
        "os"
 )
 
-// Hello world!
 func ExampleBuffer() {
        var b Buffer // A Buffer needs no initialization.
        b.Write([]byte("Hello "))
        b.Write([]byte("world!"))
        b.WriteTo(os.Stdout)
+       // Output: Hello world!
 }
 
-// Gophers rule!
 func ExampleBuffer_reader() {
        // A Buffer can turn a string or a []byte into an io.Reader.
        buf := NewBufferString("R29waGVycyBydWxlIQ==")
        dec := base64.NewDecoder(base64.StdEncoding, buf)
        io.Copy(os.Stdout, dec)
+       // Output: Gophers rule!
 }
diff --git a/libgo/go/bytes/reader.go b/libgo/go/bytes/reader.go
new file mode 100644 (file)
index 0000000..a062e54
--- /dev/null
@@ -0,0 +1,125 @@
+// 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 bytes
+
+import (
+       "errors"
+       "io"
+       "unicode/utf8"
+)
+
+// A Reader implements the io.Reader, io.ReaderAt, io.Seeker,
+// io.ByteScanner, and io.RuneScanner interfaces by reading from
+// a byte slice.
+// Unlike a Buffer, a Reader is read-only and supports seeking.
+type Reader struct {
+       s        []byte
+       i        int // current reading index
+       prevRune int // index of previous rune; or < 0
+}
+
+// Len returns the number of bytes of the unread portion of the
+// slice.
+func (r *Reader) Len() int {
+       if r.i >= len(r.s) {
+               return 0
+       }
+       return len(r.s) - r.i
+}
+
+func (r *Reader) Read(b []byte) (n int, err error) {
+       if len(b) == 0 {
+               return 0, nil
+       }
+       if r.i >= len(r.s) {
+               return 0, io.EOF
+       }
+       n = copy(b, r.s[r.i:])
+       r.i += n
+       r.prevRune = -1
+       return
+}
+
+func (r *Reader) ReadAt(b []byte, off int64) (n int, err error) {
+       if off < 0 {
+               return 0, errors.New("bytes: invalid offset")
+       }
+       if off >= int64(len(r.s)) {
+               return 0, io.EOF
+       }
+       n = copy(b, r.s[int(off):])
+       if n < len(b) {
+               err = io.EOF
+       }
+       return
+}
+
+func (r *Reader) ReadByte() (b byte, err error) {
+       if r.i >= len(r.s) {
+               return 0, io.EOF
+       }
+       b = r.s[r.i]
+       r.i++
+       r.prevRune = -1
+       return
+}
+
+func (r *Reader) UnreadByte() error {
+       if r.i <= 0 {
+               return errors.New("bytes.Reader: at beginning of slice")
+       }
+       r.i--
+       r.prevRune = -1
+       return nil
+}
+
+func (r *Reader) ReadRune() (ch rune, size int, err error) {
+       if r.i >= len(r.s) {
+               return 0, 0, io.EOF
+       }
+       r.prevRune = r.i
+       if c := r.s[r.i]; c < utf8.RuneSelf {
+               r.i++
+               return rune(c), 1, nil
+       }
+       ch, size = utf8.DecodeRune(r.s[r.i:])
+       r.i += size
+       return
+}
+
+func (r *Reader) UnreadRune() error {
+       if r.prevRune < 0 {
+               return errors.New("bytes.Reader: previous operation was not ReadRune")
+       }
+       r.i = r.prevRune
+       r.prevRune = -1
+       return nil
+}
+
+// Seek implements the io.Seeker interface.
+func (r *Reader) Seek(offset int64, whence int) (int64, error) {
+       var abs int64
+       switch whence {
+       case 0:
+               abs = offset
+       case 1:
+               abs = int64(r.i) + offset
+       case 2:
+               abs = int64(len(r.s)) + offset
+       default:
+               return 0, errors.New("bytes: invalid whence")
+       }
+       if abs < 0 {
+               return 0, errors.New("bytes: negative position")
+       }
+       if abs >= 1<<31 {
+               return 0, errors.New("bytes: position out of range")
+       }
+       r.i = int(abs)
+       return abs, nil
+}
+
+// NewReader returns a new Reader reading from b.
+func NewReader(b []byte) *Reader { return &Reader{b, 0, -1} }
diff --git a/libgo/go/bytes/reader_test.go b/libgo/go/bytes/reader_test.go
new file mode 100644 (file)
index 0000000..2e4b1f2
--- /dev/null
@@ -0,0 +1,88 @@
+// 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 bytes_test
+
+import (
+       . "bytes"
+       "fmt"
+       "io"
+       "os"
+       "testing"
+)
+
+func TestReader(t *testing.T) {
+       r := NewReader([]byte("0123456789"))
+       tests := []struct {
+               off     int64
+               seek    int
+               n       int
+               want    string
+               wantpos int64
+               seekerr string
+       }{
+               {seek: os.SEEK_SET, off: 0, n: 20, want: "0123456789"},
+               {seek: os.SEEK_SET, off: 1, n: 1, want: "1"},
+               {seek: os.SEEK_CUR, off: 1, wantpos: 3, n: 2, want: "34"},
+               {seek: os.SEEK_SET, off: -1, seekerr: "bytes: negative position"},
+               {seek: os.SEEK_SET, off: 1<<31 - 1},
+               {seek: os.SEEK_CUR, off: 1, seekerr: "bytes: position out of range"},
+               {seek: os.SEEK_SET, n: 5, want: "01234"},
+               {seek: os.SEEK_CUR, n: 5, want: "56789"},
+               {seek: os.SEEK_END, off: -1, n: 1, wantpos: 9, want: "9"},
+       }
+
+       for i, tt := range tests {
+               pos, err := r.Seek(tt.off, tt.seek)
+               if err == nil && tt.seekerr != "" {
+                       t.Errorf("%d. want seek error %q", i, tt.seekerr)
+                       continue
+               }
+               if err != nil && err.Error() != tt.seekerr {
+                       t.Errorf("%d. seek error = %q; want %q", i, err.Error(), tt.seekerr)
+                       continue
+               }
+               if tt.wantpos != 0 && tt.wantpos != pos {
+                       t.Errorf("%d. pos = %d, want %d", i, pos, tt.wantpos)
+               }
+               buf := make([]byte, tt.n)
+               n, err := r.Read(buf)
+               if err != nil {
+                       t.Errorf("%d. read = %v", i, err)
+                       continue
+               }
+               got := string(buf[:n])
+               if got != tt.want {
+                       t.Errorf("%d. got %q; want %q", i, got, tt.want)
+               }
+       }
+}
+
+func TestReaderAt(t *testing.T) {
+       r := NewReader([]byte("0123456789"))
+       tests := []struct {
+               off     int64
+               n       int
+               want    string
+               wanterr interface{}
+       }{
+               {0, 10, "0123456789", nil},
+               {1, 10, "123456789", io.EOF},
+               {1, 9, "123456789", nil},
+               {11, 10, "", io.EOF},
+               {0, 0, "", nil},
+               {-1, 0, "", "bytes: invalid offset"},
+       }
+       for i, tt := range tests {
+               b := make([]byte, tt.n)
+               rn, err := r.ReadAt(b, tt.off)
+               got := string(b[:rn])
+               if got != tt.want {
+                       t.Errorf("%d. got %q; want %q", i, got, tt.want)
+               }
+               if fmt.Sprintf("%v", err) != fmt.Sprintf("%v", tt.wanterr) {
+                       t.Errorf("%d. got error = %v; want %v", i, err, tt.wanterr)
+               }
+       }
+}
index 8505da7..2040840 100644 (file)
@@ -5,6 +5,7 @@
 package flate
 
 import (
+       "fmt"
        "io"
        "math"
 )
@@ -390,7 +391,7 @@ func (d *compressor) init(w io.Writer, level int) (err error) {
                d.fill = (*compressor).fillDeflate
                d.step = (*compressor).deflate
        default:
-               return WrongValueError{"level", 0, 9, int32(level)}
+               return fmt.Errorf("flate: invalid compression level %d: want value in range [-1, 9]", level)
        }
        return nil
 }
@@ -408,17 +409,22 @@ func (d *compressor) close() error {
        return d.w.err
 }
 
-// NewWriter returns a new Writer compressing
-// data at the given level.  Following zlib, levels
-// range from 1 (BestSpeed) to 9 (BestCompression);
-// higher levels typically run slower but compress more.
-// Level 0 (NoCompression) does not attempt any
-// compression; it only adds the necessary DEFLATE framing.
-func NewWriter(w io.Writer, level int) *Writer {
+// NewWriter returns a new Writer compressing data at the given level.
+// Following zlib, levels range from 1 (BestSpeed) to 9 (BestCompression);
+// higher levels typically run slower but compress more. Level 0
+// (NoCompression) does not attempt any compression; it only adds the
+// necessary DEFLATE framing. Level -1 (DefaultCompression) uses the default
+// compression level.
+//
+// If level is in the range [-1, 9] then the error returned will be nil.
+// Otherwise the error returned will be non-nil.
+func NewWriter(w io.Writer, level int) (*Writer, error) {
        const logWindowSize = logMaxOffsetSize
        var dw Writer
-       dw.d.init(w, level)
-       return &dw
+       if err := dw.d.init(w, level); err != nil {
+               return nil, err
+       }
+       return &dw, nil
 }
 
 // NewWriterDict is like NewWriter but initializes the new
@@ -427,13 +433,16 @@ func NewWriter(w io.Writer, level int) *Writer {
 // any compressed output.  The compressed data written to w
 // can only be decompressed by a Reader initialized with the
 // same dictionary.
-func NewWriterDict(w io.Writer, level int, dict []byte) *Writer {
+func NewWriterDict(w io.Writer, level int, dict []byte) (*Writer, error) {
        dw := &dictWriter{w, false}
-       zw := NewWriter(dw, level)
+       zw, err := NewWriter(dw, level)
+       if err != nil {
+               return nil, err
+       }
        zw.Write(dict)
        zw.Flush()
        dw.enabled = true
-       return zw
+       return zw, err
 }
 
 type dictWriter struct {
index 75d801d..543c595 100644 (file)
@@ -81,7 +81,11 @@ func largeDataChunk() []byte {
 func TestDeflate(t *testing.T) {
        for _, h := range deflateTests {
                var buf bytes.Buffer
-               w := NewWriter(&buf, h.level)
+               w, err := NewWriter(&buf, h.level)
+               if err != nil {
+                       t.Errorf("NewWriter: %v", err)
+                       continue
+               }
                w.Write(h.in)
                w.Close()
                if !bytes.Equal(buf.Bytes(), h.out) {
@@ -151,7 +155,11 @@ func testSync(t *testing.T, level int, input []byte, name string) {
        buf := newSyncBuffer()
        buf1 := new(bytes.Buffer)
        buf.WriteMode()
-       w := NewWriter(io.MultiWriter(buf, buf1), level)
+       w, err := NewWriter(io.MultiWriter(buf, buf1), level)
+       if err != nil {
+               t.Errorf("NewWriter: %v", err)
+               return
+       }
        r := NewReader(buf)
 
        // Write half the input and read back.
@@ -213,7 +221,7 @@ func testSync(t *testing.T, level int, input []byte, name string) {
 
        // stream should work for ordinary reader too
        r = NewReader(buf1)
-       out, err := ioutil.ReadAll(r)
+       out, err = ioutil.ReadAll(r)
        if err != nil {
                t.Errorf("testSync: read: %s", err)
                return
@@ -224,31 +232,31 @@ func testSync(t *testing.T, level int, input []byte, name string) {
        }
 }
 
-func testToFromWithLevel(t *testing.T, level int, input []byte, name string) error {
-       return testToFromWithLevelAndLimit(t, level, input, name, -1)
-}
-
-func testToFromWithLevelAndLimit(t *testing.T, level int, input []byte, name string, limit int) error {
+func testToFromWithLevelAndLimit(t *testing.T, level int, input []byte, name string, limit int) {
        var buffer bytes.Buffer
-       w := NewWriter(&buffer, level)
+       w, err := NewWriter(&buffer, level)
+       if err != nil {
+               t.Errorf("NewWriter: %v", err)
+               return
+       }
        w.Write(input)
        w.Close()
        if limit > 0 && buffer.Len() > limit {
                t.Errorf("level: %d, len(compress(data)) = %d > limit = %d", level, buffer.Len(), limit)
+               return
        }
        r := NewReader(&buffer)
        out, err := ioutil.ReadAll(r)
        if err != nil {
                t.Errorf("read: %s", err)
-               return err
+               return
        }
        r.Close()
        if !bytes.Equal(input, out) {
                t.Errorf("decompress(compress(data)) != data: level=%d input=%s", level, name)
+               return
        }
-
        testSync(t, level, input, name)
-       return nil
 }
 
 func testToFromWithLimit(t *testing.T, input []byte, name string, limit [10]int) {
@@ -257,13 +265,9 @@ func testToFromWithLimit(t *testing.T, input []byte, name string, limit [10]int)
        }
 }
 
-func testToFrom(t *testing.T, input []byte, name string) {
-       testToFromWithLimit(t, input, name, [10]int{})
-}
-
 func TestDeflateInflate(t *testing.T) {
        for i, h := range deflateInflateTests {
-               testToFrom(t, h.in, fmt.Sprintf("#%d", i))
+               testToFromWithLimit(t, h.in, fmt.Sprintf("#%d", i), [10]int{})
        }
 }
 
@@ -302,6 +306,9 @@ func TestDeflateInflateString(t *testing.T) {
                        t.Error(err)
                }
                testToFromWithLimit(t, gold, test.label, test.limit)
+               if testing.Short() {
+                       break
+               }
        }
 }
 
@@ -311,7 +318,10 @@ func TestReaderDict(t *testing.T) {
                text = "hello again world"
        )
        var b bytes.Buffer
-       w := NewWriter(&b, 5)
+       w, err := NewWriter(&b, 5)
+       if err != nil {
+               t.Fatalf("NewWriter: %v", err)
+       }
        w.Write([]byte(dict))
        w.Flush()
        b.Reset()
@@ -334,7 +344,10 @@ func TestWriterDict(t *testing.T) {
                text = "hello again world"
        )
        var b bytes.Buffer
-       w := NewWriter(&b, 5)
+       w, err := NewWriter(&b, 5)
+       if err != nil {
+               t.Fatalf("NewWriter: %v", err)
+       }
        w.Write([]byte(dict))
        w.Flush()
        b.Reset()
@@ -342,7 +355,7 @@ func TestWriterDict(t *testing.T) {
        w.Close()
 
        var b1 bytes.Buffer
-       w = NewWriterDict(&b1, 5, []byte(dict))
+       w, _ = NewWriterDict(&b1, 5, []byte(dict))
        w.Write([]byte(text))
        w.Close()
 
@@ -353,7 +366,14 @@ func TestWriterDict(t *testing.T) {
 
 // See http://code.google.com/p/go/issues/detail?id=2508
 func TestRegression2508(t *testing.T) {
-       w := NewWriter(ioutil.Discard, 1)
+       if testing.Short() {
+               t.Logf("test disabled with -short")
+               return
+       }
+       w, err := NewWriter(ioutil.Discard, 1)
+       if err != nil {
+               t.Fatalf("NewWriter: %v", err)
+       }
        buf := make([]byte, 1024)
        for i := 0; i < 131072; i++ {
                if _, err := w.Write(buf); err != nil {
index 57b56b5..25e1da3 100644 (file)
@@ -7,7 +7,6 @@ package flate
 import (
        "io"
        "math"
-       "strconv"
 )
 
 const (
@@ -85,13 +84,6 @@ type huffmanBitWriter struct {
        err             error
 }
 
-type WrongValueError struct {
-       name  string
-       from  int32
-       to    int32
-       value int32
-}
-
 func newHuffmanBitWriter(w io.Writer) *huffmanBitWriter {
        return &huffmanBitWriter{
                w:               w,
@@ -105,11 +97,6 @@ func newHuffmanBitWriter(w io.Writer) *huffmanBitWriter {
        }
 }
 
-func (err WrongValueError) Error() string {
-       return "huffmanBitWriter: " + err.name + " should belong to [" + strconv.FormatInt(int64(err.from), 10) + ";" +
-               strconv.FormatInt(int64(err.to), 10) + "] but actual value is " + strconv.FormatInt(int64(err.value), 10)
-}
-
 func (w *huffmanBitWriter) flushBits() {
        if w.err != nil {
                w.nbits = 0
index d374310..33736f6 100644 (file)
@@ -16,9 +16,6 @@ import (
        "time"
 )
 
-// BUG(nigeltao): Comments and Names don't properly map UTF-8 character codes outside of
-// the 0x00-0x7f range to ISO 8859-1 (Latin-1).
-
 const (
        gzipID1     = 0x1f
        gzipID2     = 0x8b
@@ -37,11 +34,15 @@ func makeReader(r io.Reader) flate.Reader {
        return bufio.NewReader(r)
 }
 
-var ErrHeader = errors.New("invalid gzip header")
-var ErrChecksum = errors.New("gzip checksum error")
+var (
+       // ErrChecksum is returned when reading GZIP data that has an invalid checksum.
+       ErrChecksum = errors.New("gzip: invalid checksum")
+       // ErrHeader is returned when reading GZIP data that has an invalid header.
+       ErrHeader = errors.New("gzip: invalid header")
+)
 
 // The gzip file stores a header giving metadata about the compressed file.
-// That header is exposed as the fields of the Compressor and Decompressor structs.
+// That header is exposed as the fields of the Writer and Reader structs.
 type Header struct {
        Comment string    // comment
        Extra   []byte    // "extra data"
@@ -50,21 +51,21 @@ type Header struct {
        OS      byte      // operating system type
 }
 
-// An Decompressor is an io.Reader that can be read to retrieve
+// A Reader is an io.Reader that can be read to retrieve
 // uncompressed data from a gzip-format compressed file.
 //
 // In general, a gzip file can be a concatenation of gzip files,
-// each with its own header.  Reads from the Decompressor
+// each with its own header.  Reads from the Reader
 // return the concatenation of the uncompressed data of each.
-// Only the first header is recorded in the Decompressor fields.
+// Only the first header is recorded in the Reader fields.
 //
 // Gzip files store a length and checksum of the uncompressed data.
-// The Decompressor will return a ErrChecksum when Read
+// The Reader will return a ErrChecksum when Read
 // reaches the end of the uncompressed data if it does not
 // have the expected length or checksum.  Clients should treat data
-// returned by Read as tentative until they receive the successful
-// (zero length, nil error) Read marking the end of the data.
-type Decompressor struct {
+// returned by Read as tentative until they receive the io.EOF
+// marking the end of the data.
+type Reader struct {
        Header
        r            flate.Reader
        decompressor io.ReadCloser
@@ -75,15 +76,14 @@ type Decompressor struct {
        err          error
 }
 
-// NewReader creates a new Decompressor reading the given reader.
+// NewReader creates a new Reader reading the given reader.
 // The implementation buffers input and may read more data than necessary from r.
-// It is the caller's responsibility to call Close on the Decompressor when done.
-func NewReader(r io.Reader) (*Decompressor, error) {
-       z := new(Decompressor)
+// It is the caller's responsibility to call Close on the Reader when done.
+func NewReader(r io.Reader) (*Reader, error) {
+       z := new(Reader)
        z.r = makeReader(r)
        z.digest = crc32.NewIEEE()
        if err := z.readHeader(true); err != nil {
-               z.err = err
                return nil, err
        }
        return z, nil
@@ -94,7 +94,7 @@ func get4(p []byte) uint32 {
        return uint32(p[0]) | uint32(p[1])<<8 | uint32(p[2])<<16 | uint32(p[3])<<24
 }
 
-func (z *Decompressor) readString() (string, error) {
+func (z *Reader) readString() (string, error) {
        var err error
        needconv := false
        for i := 0; ; i++ {
@@ -123,7 +123,7 @@ func (z *Decompressor) readString() (string, error) {
        panic("not reached")
 }
 
-func (z *Decompressor) read2() (uint32, error) {
+func (z *Reader) read2() (uint32, error) {
        _, err := io.ReadFull(z.r, z.buf[0:2])
        if err != nil {
                return 0, err
@@ -131,7 +131,7 @@ func (z *Decompressor) read2() (uint32, error) {
        return uint32(z.buf[0]) | uint32(z.buf[1])<<8, nil
 }
 
-func (z *Decompressor) readHeader(save bool) error {
+func (z *Reader) readHeader(save bool) error {
        _, err := io.ReadFull(z.r, z.buf[0:10])
        if err != nil {
                return err
@@ -197,7 +197,7 @@ func (z *Decompressor) readHeader(save bool) error {
        return nil
 }
 
-func (z *Decompressor) Read(p []byte) (n int, err error) {
+func (z *Reader) Read(p []byte) (n int, err error) {
        if z.err != nil {
                return 0, z.err
        }
@@ -237,5 +237,5 @@ func (z *Decompressor) Read(p []byte) (n int, err error) {
        return z.Read(p)
 }
 
-// Calling Close does not close the wrapped io.Reader originally passed to NewReader.
-func (z *Decompressor) Close() error { return z.decompressor.Close() }
+// Close closes the Reader. It does not close the underlying io.Reader.
+func (z *Reader) Close() error { return z.decompressor.Close() }
index f2639a6..3035dff 100644 (file)
@@ -7,6 +7,7 @@ package gzip
 import (
        "compress/flate"
        "errors"
+       "fmt"
        "hash"
        "hash/crc32"
        "io"
@@ -21,9 +22,9 @@ const (
        DefaultCompression = flate.DefaultCompression
 )
 
-// A Compressor is an io.WriteCloser that satisfies writes by compressing data written
+// A Writer is an io.WriteCloser that satisfies writes by compressing data written
 // to its wrapped io.Writer.
-type Compressor struct {
+type Writer struct {
        Header
        w          io.Writer
        level      int
@@ -35,25 +36,40 @@ type Compressor struct {
        err        error
 }
 
-// NewWriter calls NewWriterLevel with the default compression level.
-func NewWriter(w io.Writer) (*Compressor, error) {
-       return NewWriterLevel(w, DefaultCompression)
+// NewWriter creates a new Writer that satisfies writes by compressing data
+// written to w.
+//
+// It is the caller's responsibility to call Close on the WriteCloser when done.
+// Writes may be buffered and not flushed until Close.
+//
+// Callers that wish to set the fields in Writer.Header must do so before
+// the first call to Write or Close. The Comment and Name header fields are
+// UTF-8 strings in Go, but the underlying format requires NUL-terminated ISO
+// 8859-1 (Latin-1). NUL or non-Latin-1 runes in those strings will lead to an
+// error on Write.
+func NewWriter(w io.Writer) *Writer {
+       z, _ := NewWriterLevel(w, DefaultCompression)
+       return z
 }
 
-// NewWriterLevel creates a new Compressor writing to the given writer.
-// Writes may be buffered and not flushed until Close.
-// Callers that wish to set the fields in Compressor.Header must
-// do so before the first call to Write or Close.
-// It is the caller's responsibility to call Close on the WriteCloser when done.
-// level is the compression level, which can be DefaultCompression, NoCompression,
-// or any integer value between BestSpeed and BestCompression (inclusive).
-func NewWriterLevel(w io.Writer, level int) (*Compressor, error) {
-       z := new(Compressor)
-       z.OS = 255 // unknown
-       z.w = w
-       z.level = level
-       z.digest = crc32.NewIEEE()
-       return z, nil
+// NewWriterLevel is like NewWriter but specifies the compression level instead
+// of assuming DefaultCompression.
+//
+// The compression level can be DefaultCompression, NoCompression, or any
+// integer value between BestSpeed and BestCompression inclusive. The error
+// returned will be nil if the level is valid.
+func NewWriterLevel(w io.Writer, level int) (*Writer, error) {
+       if level < DefaultCompression || level > BestCompression {
+               return nil, fmt.Errorf("gzip: invalid compression level: %d", level)
+       }
+       return &Writer{
+               Header: Header{
+                       OS: 255, // unknown
+               },
+               w:      w,
+               level:  level,
+               digest: crc32.NewIEEE(),
+       }, nil
 }
 
 // GZIP (RFC 1952) is little-endian, unlike ZLIB (RFC 1950).
@@ -70,7 +86,7 @@ func put4(p []byte, v uint32) {
 }
 
 // writeBytes writes a length-prefixed byte slice to z.w.
-func (z *Compressor) writeBytes(b []byte) error {
+func (z *Writer) writeBytes(b []byte) error {
        if len(b) > 0xffff {
                return errors.New("gzip.Write: Extra data is too large")
        }
@@ -83,10 +99,10 @@ func (z *Compressor) writeBytes(b []byte) error {
        return err
 }
 
-// writeString writes a string (in ISO 8859-1 (Latin-1) format) to z.w.
-func (z *Compressor) writeString(s string) error {
-       // GZIP (RFC 1952) specifies that strings are NUL-terminated ISO 8859-1 (Latin-1).
-       var err error
+// writeString writes a UTF-8 string s in GZIP's format to z.w.
+// GZIP (RFC 1952) specifies that strings are NUL-terminated ISO 8859-1 (Latin-1).
+func (z *Writer) writeString(s string) (err error) {
+       // GZIP stores Latin-1 strings; error if non-Latin-1; convert if non-ASCII.
        needconv := false
        for _, v := range s {
                if v == 0 || v > 0xff {
@@ -114,7 +130,9 @@ func (z *Compressor) writeString(s string) error {
        return err
 }
 
-func (z *Compressor) Write(p []byte) (int, error) {
+// Write writes a compressed form of p to the underlying io.Writer. The
+// compressed bytes are not necessarily flushed until the Writer is closed.
+func (z *Writer) Write(p []byte) (int, error) {
        if z.err != nil {
                return 0, z.err
        }
@@ -165,7 +183,7 @@ func (z *Compressor) Write(p []byte) (int, error) {
                                return n, z.err
                        }
                }
-               z.compressor = flate.NewWriter(z.w, z.level)
+               z.compressor, _ = flate.NewWriter(z.w, z.level)
        }
        z.size += uint32(len(p))
        z.digest.Write(p)
@@ -173,8 +191,8 @@ func (z *Compressor) Write(p []byte) (int, error) {
        return n, z.err
 }
 
-// Calling Close does not close the wrapped io.Writer originally passed to NewWriter.
-func (z *Compressor) Close() error {
+// Close closes the Writer. It does not close the underlying io.Writer.
+func (z *Writer) Close() error {
        if z.err != nil {
                return z.err
        }
index eb7a7ec..6f7b593 100644 (file)
@@ -7,108 +7,153 @@ package gzip
 import (
        "bufio"
        "bytes"
-       "io"
        "io/ioutil"
        "testing"
        "time"
 )
 
-// pipe creates two ends of a pipe that gzip and gunzip, and runs dfunc at the
-// writer end and cfunc at the reader end.
-func pipe(t *testing.T, dfunc func(*Compressor), cfunc func(*Decompressor)) {
-       piper, pipew := io.Pipe()
-       defer piper.Close()
-       go func() {
-               defer pipew.Close()
-               compressor, err := NewWriter(pipew)
-               if err != nil {
-                       t.Fatalf("%v", err)
-               }
-               defer compressor.Close()
-               dfunc(compressor)
-       }()
-       decompressor, err := NewReader(piper)
+// TestEmpty tests that an empty payload still forms a valid GZIP stream.
+func TestEmpty(t *testing.T) {
+       buf := new(bytes.Buffer)
+
+       if err := NewWriter(buf).Close(); err != nil {
+               t.Fatalf("Writer.Close: %v", err)
+       }
+
+       r, err := NewReader(buf)
+       if err != nil {
+               t.Fatalf("NewReader: %v", err)
+       }
+       b, err := ioutil.ReadAll(r)
        if err != nil {
-               t.Fatalf("%v", err)
+               t.Fatalf("ReadAll: %v", err)
+       }
+       if len(b) != 0 {
+               t.Fatalf("got %d bytes, want 0", len(b))
+       }
+       if err := r.Close(); err != nil {
+               t.Fatalf("Reader.Close: %v", err)
        }
-       defer decompressor.Close()
-       cfunc(decompressor)
 }
 
-// Tests that an empty payload still forms a valid GZIP stream.
-func TestEmpty(t *testing.T) {
-       pipe(t,
-               func(compressor *Compressor) {},
-               func(decompressor *Decompressor) {
-                       b, err := ioutil.ReadAll(decompressor)
-                       if err != nil {
-                               t.Fatalf("%v", err)
-                       }
-                       if len(b) != 0 {
-                               t.Fatalf("did not read an empty slice")
-                       }
-               })
-}
+// TestRoundTrip tests that gzipping and then gunzipping is the identity
+// function.
+func TestRoundTrip(t *testing.T) {
+       buf := new(bytes.Buffer)
+
+       w := NewWriter(buf)
+       w.Comment = "comment"
+       w.Extra = []byte("extra")
+       w.ModTime = time.Unix(1e8, 0)
+       w.Name = "name"
+       if _, err := w.Write([]byte("payload")); err != nil {
+               t.Fatalf("Write: %v", err)
+       }
+       if err := w.Close(); err != nil {
+               t.Fatalf("Writer.Close: %v", err)
+       }
 
-// Tests that gzipping and then gunzipping is the identity function.
-func TestWriter(t *testing.T) {
-       pipe(t,
-               func(compressor *Compressor) {
-                       compressor.Comment = "Äußerung"
-                       //compressor.Comment = "comment"
-                       compressor.Extra = []byte("extra")
-                       compressor.ModTime = time.Unix(1e8, 0)
-                       compressor.Name = "name"
-                       _, err := compressor.Write([]byte("payload"))
-                       if err != nil {
-                               t.Fatalf("%v", err)
-                       }
-               },
-               func(decompressor *Decompressor) {
-                       b, err := ioutil.ReadAll(decompressor)
-                       if err != nil {
-                               t.Fatalf("%v", err)
-                       }
-                       if string(b) != "payload" {
-                               t.Fatalf("payload is %q, want %q", string(b), "payload")
-                       }
-                       if decompressor.Comment != "Äußerung" {
-                               t.Fatalf("comment is %q, want %q", decompressor.Comment, "Äußerung")
-                       }
-                       if string(decompressor.Extra) != "extra" {
-                               t.Fatalf("extra is %q, want %q", decompressor.Extra, "extra")
-                       }
-                       if decompressor.ModTime.Unix() != 1e8 {
-                               t.Fatalf("mtime is %d, want %d", decompressor.ModTime.Unix(), uint32(1e8))
-                       }
-                       if decompressor.Name != "name" {
-                               t.Fatalf("name is %q, want %q", decompressor.Name, "name")
-                       }
-               })
+       r, err := NewReader(buf)
+       if err != nil {
+               t.Fatalf("NewReader: %v", err)
+       }
+       b, err := ioutil.ReadAll(r)
+       if err != nil {
+               t.Fatalf("ReadAll: %v", err)
+       }
+       if string(b) != "payload" {
+               t.Fatalf("payload is %q, want %q", string(b), "payload")
+       }
+       if r.Comment != "comment" {
+               t.Fatalf("comment is %q, want %q", r.Comment, "comment")
+       }
+       if string(r.Extra) != "extra" {
+               t.Fatalf("extra is %q, want %q", r.Extra, "extra")
+       }
+       if r.ModTime.Unix() != 1e8 {
+               t.Fatalf("mtime is %d, want %d", r.ModTime.Unix(), uint32(1e8))
+       }
+       if r.Name != "name" {
+               t.Fatalf("name is %q, want %q", r.Name, "name")
+       }
+       if err := r.Close(); err != nil {
+               t.Fatalf("Reader.Close: %v", err)
+       }
 }
 
+// TestLatin1 tests the internal functions for converting to and from Latin-1.
 func TestLatin1(t *testing.T) {
        latin1 := []byte{0xc4, 'u', 0xdf, 'e', 'r', 'u', 'n', 'g', 0}
        utf8 := "Äußerung"
-       z := Decompressor{r: bufio.NewReader(bytes.NewBuffer(latin1))}
+       z := Reader{r: bufio.NewReader(bytes.NewBuffer(latin1))}
        s, err := z.readString()
        if err != nil {
-               t.Fatalf("%v", err)
+               t.Fatalf("readString: %v", err)
        }
        if s != utf8 {
-               t.Fatalf("string is %q, want %q", s, utf8)
+               t.Fatalf("read latin-1: got %q, want %q", s, utf8)
        }
 
        buf := bytes.NewBuffer(make([]byte, 0, len(latin1)))
-       c := Compressor{w: buf}
+       c := Writer{w: buf}
        if err = c.writeString(utf8); err != nil {
-               t.Fatalf("%v", err)
+               t.Fatalf("writeString: %v", err)
        }
        s = buf.String()
        if s != string(latin1) {
-               t.Fatalf("string is %v, want %v", s, latin1)
+               t.Fatalf("write utf-8: got %q, want %q", s, string(latin1))
+       }
+}
+
+// TestLatin1RoundTrip tests that metadata that is representable in Latin-1
+// survives a round trip.
+func TestLatin1RoundTrip(t *testing.T) {
+       testCases := []struct {
+               name string
+               ok   bool
+       }{
+               {"", true},
+               {"ASCII is OK", true},
+               {"unless it contains a NUL\x00", false},
+               {"no matter where \x00 occurs", false},
+               {"\x00\x00\x00", false},
+               {"Látin-1 also passes (U+00E1)", true},
+               {"but LÄ€tin Extended-A (U+0100) does not", false},
+               {"neither does æ—¥æœ¬èªž", false},
+               {"invalid UTF-8 also \xffails", false},
+               {"\x00 as does Látin-1 with NUL", false},
+       }
+       for _, tc := range testCases {
+               buf := new(bytes.Buffer)
+
+               w := NewWriter(buf)
+               w.Name = tc.name
+               err := w.Close()
+               if (err == nil) != tc.ok {
+                       t.Errorf("Writer.Close: name = %q, err = %v", tc.name, err)
+                       continue
+               }
+               if !tc.ok {
+                       continue
+               }
+
+               r, err := NewReader(buf)
+               if err != nil {
+                       t.Errorf("NewReader: %v", err)
+                       continue
+               }
+               _, err = ioutil.ReadAll(r)
+               if err != nil {
+                       t.Errorf("ReadAll: %v", err)
+                       continue
+               }
+               if r.Name != tc.name {
+                       t.Errorf("name is %q, want %q", r.Name, tc.name)
+                       continue
+               }
+               if err := r.Close(); err != nil {
+                       t.Errorf("Reader.Close: %v", err)
+                       continue
+               }
        }
-       //if s, err = buf.ReadString(0); err != nil {
-       //t.Fatalf("%v", err)
-       //}
 }
index 4638a65..f38ef5a 100644 (file)
@@ -34,9 +34,14 @@ import (
 
 const zlibDeflate = 8
 
-var ErrChecksum = errors.New("zlib checksum error")
-var ErrHeader = errors.New("invalid zlib header")
-var ErrDictionary = errors.New("invalid zlib dictionary")
+var (
+       // ErrChecksum is returned when reading ZLIB data that has an invalid checksum.
+       ErrChecksum = errors.New("zlib: invalid checksum")
+       // ErrDictionary is returned when reading ZLIB data that has an invalid dictionary.
+       ErrDictionary = errors.New("zlib: invalid dictionary")
+       // ErrHeader is returned when reading ZLIB data that has an invalid header.
+       ErrHeader = errors.New("zlib: invalid header")
+)
 
 type reader struct {
        r            flate.Reader
index bbff637..cd8dea4 100644 (file)
@@ -6,7 +6,7 @@ package zlib
 
 import (
        "compress/flate"
-       "errors"
+       "fmt"
        "hash"
        "hash/adler32"
        "io"
@@ -24,30 +24,55 @@ const (
 // A Writer takes data written to it and writes the compressed
 // form of that data to an underlying writer (see NewWriter).
 type Writer struct {
-       w          io.Writer
-       compressor *flate.Writer
-       digest     hash.Hash32
-       err        error
-       scratch    [4]byte
+       w           io.Writer
+       level       int
+       dict        []byte
+       compressor  *flate.Writer
+       digest      hash.Hash32
+       err         error
+       scratch     [4]byte
+       wroteHeader bool
 }
 
-// NewWriter calls NewWriterLevel with the default compression level.
-func NewWriter(w io.Writer) (*Writer, error) {
-       return NewWriterLevel(w, DefaultCompression)
+// NewWriter creates a new Writer that satisfies writes by compressing data
+// written to w.
+//
+// It is the caller's responsibility to call Close on the WriteCloser when done.
+// Writes may be buffered and not flushed until Close.
+func NewWriter(w io.Writer) *Writer {
+       z, _ := NewWriterLevelDict(w, DefaultCompression, nil)
+       return z
 }
 
-// NewWriterLevel calls NewWriterDict with no dictionary.
+// NewWriterLevel is like NewWriter but specifies the compression level instead
+// of assuming DefaultCompression.
+//
+// The compression level can be DefaultCompression, NoCompression, or any
+// integer value between BestSpeed and BestCompression inclusive. The error
+// returned will be nil if the level is valid.
 func NewWriterLevel(w io.Writer, level int) (*Writer, error) {
-       return NewWriterDict(w, level, nil)
+       return NewWriterLevelDict(w, level, nil)
 }
 
-// NewWriterDict creates a new io.WriteCloser that satisfies writes by compressing data written to w.
-// It is the caller's responsibility to call Close on the WriteCloser when done.
-// level is the compression level, which can be DefaultCompression, NoCompression,
-// or any integer value between BestSpeed and BestCompression (inclusive).
-// dict is the preset dictionary to compress with, or nil to use no dictionary.
-func NewWriterDict(w io.Writer, level int, dict []byte) (*Writer, error) {
-       z := new(Writer)
+// NewWriterLevelDict is like NewWriterLevel but specifies a dictionary to
+// compress with.
+//
+// The dictionary may be nil. If not, its contents should not be modified until
+// the Writer is closed.
+func NewWriterLevelDict(w io.Writer, level int, dict []byte) (*Writer, error) {
+       if level < DefaultCompression || level > BestCompression {
+               return nil, fmt.Errorf("zlib: invalid compression level: %d", level)
+       }
+       return &Writer{
+               w:     w,
+               level: level,
+               dict:  dict,
+       }, nil
+}
+
+// writeHeader writes the ZLIB header.
+func (z *Writer) writeHeader() (err error) {
+       z.wroteHeader = true
        // ZLIB has a two-byte header (as documented in RFC 1950).
        // The first four bits is the CINFO (compression info), which is 7 for the default deflate window size.
        // The next four bits is the CM (compression method), which is 8 for deflate.
@@ -56,7 +81,7 @@ func NewWriterDict(w io.Writer, level int, dict []byte) (*Writer, error) {
        // 0=fastest, 1=fast, 2=default, 3=best.
        // The next bit, FDICT, is set if a dictionary is given.
        // The final five FCHECK bits form a mod-31 checksum.
-       switch level {
+       switch z.level {
        case 0, 1:
                z.scratch[1] = 0 << 6
        case 2, 3, 4, 5:
@@ -66,35 +91,41 @@ func NewWriterDict(w io.Writer, level int, dict []byte) (*Writer, error) {
        case 7, 8, 9:
                z.scratch[1] = 3 << 6
        default:
-               return nil, errors.New("level out of range")
+               panic("unreachable")
        }
-       if dict != nil {
+       if z.dict != nil {
                z.scratch[1] |= 1 << 5
        }
        z.scratch[1] += uint8(31 - (uint16(z.scratch[0])<<8+uint16(z.scratch[1]))%31)
-       _, err := w.Write(z.scratch[0:2])
-       if err != nil {
-               return nil, err
+       if _, err = z.w.Write(z.scratch[0:2]); err != nil {
+               return err
        }
-       if dict != nil {
+       if z.dict != nil {
                // The next four bytes are the Adler-32 checksum of the dictionary.
-               checksum := adler32.Checksum(dict)
+               checksum := adler32.Checksum(z.dict)
                z.scratch[0] = uint8(checksum >> 24)
                z.scratch[1] = uint8(checksum >> 16)
                z.scratch[2] = uint8(checksum >> 8)
                z.scratch[3] = uint8(checksum >> 0)
-               _, err = w.Write(z.scratch[0:4])
-               if err != nil {
-                       return nil, err
+               if _, err = z.w.Write(z.scratch[0:4]); err != nil {
+                       return err
                }
        }
-       z.w = w
-       z.compressor = flate.NewWriterDict(w, level, dict)
+       z.compressor, err = flate.NewWriterDict(z.w, z.level, z.dict)
+       if err != nil {
+               return err
+       }
        z.digest = adler32.New()
-       return z, nil
+       return nil
 }
 
+// Write writes a compressed form of p to the underlying io.Writer. The
+// compressed bytes are not necessarily flushed until the Writer is closed or
+// explicitly flushed.
 func (z *Writer) Write(p []byte) (n int, err error) {
+       if !z.wroteHeader {
+               z.err = z.writeHeader()
+       }
        if z.err != nil {
                return 0, z.err
        }
@@ -110,8 +141,11 @@ func (z *Writer) Write(p []byte) (n int, err error) {
        return
 }
 
-// Flush flushes the underlying compressor.
+// Flush flushes the Writer to its underlying io.Writer.
 func (z *Writer) Flush() error {
+       if !z.wroteHeader {
+               z.err = z.writeHeader()
+       }
        if z.err != nil {
                return z.err
        }
@@ -121,6 +155,9 @@ func (z *Writer) Flush() error {
 
 // Calling Close does not close the wrapped io.Writer originally passed to NewWriter.
 func (z *Writer) Close() error {
+       if !z.wroteHeader {
+               z.err = z.writeHeader()
+       }
        if z.err != nil {
                return z.err
        }
index 1c75d08..aee1a5c 100644 (file)
@@ -52,7 +52,7 @@ func testLevelDict(t *testing.T, fn string, b0 []byte, level int, d string) {
        defer piper.Close()
        go func() {
                defer pipew.Close()
-               zlibw, err := NewWriterDict(pipew, level, dict)
+               zlibw, err := NewWriterLevelDict(pipew, level, dict)
                if err != nil {
                        t.Errorf("%s (level=%d, dict=%q): %v", fn, level, d, err)
                        return
@@ -125,9 +125,9 @@ func TestWriterDict(t *testing.T) {
 func TestWriterDictIsUsed(t *testing.T) {
        var input = []byte("Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.")
        var buf bytes.Buffer
-       compressor, err := NewWriterDict(&buf, BestCompression, input)
+       compressor, err := NewWriterLevelDict(&buf, BestCompression, input)
        if err != nil {
-               t.Errorf("error in NewWriterDict: %s", err)
+               t.Errorf("error in NewWriterLevelDict: %s", err)
                return
        }
        compressor.Write(input)
diff --git a/libgo/go/container/heap/example_test.go b/libgo/go/container/heap/example_test.go
new file mode 100644 (file)
index 0000000..2050bc8
--- /dev/null
@@ -0,0 +1,105 @@
+// 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.
+
+// This example demonstrates a priority queue built using the heap interface.
+package heap_test
+
+import (
+       "container/heap"
+       "fmt"
+)
+
+// An Item is something we manage in a priority queue.
+type Item struct {
+       value    string // The value of the item; arbitrary.
+       priority int    // The priority of the item in the queue.
+       // The index is needed by changePriority and is maintained by the heap.Interface methods.
+       index int // The index of the item in the heap.
+}
+
+// A PriorityQueue implements heap.Interface and holds Items.
+type PriorityQueue []*Item
+
+func (pq PriorityQueue) Len() int { return len(pq) }
+
+func (pq PriorityQueue) Less(i, j int) bool {
+       // We want Pop to give us the highest, not lowest, priority so we use greater than here.
+       return pq[i].priority > pq[j].priority
+}
+
+func (pq PriorityQueue) Swap(i, j int) {
+       pq[i], pq[j] = pq[j], pq[i]
+       pq[i].index = i
+       pq[j].index = j
+}
+
+func (pq *PriorityQueue) Push(x interface{}) {
+       // Push and Pop use pointer receivers because they modify the slice's length,
+       // not just its contents.
+       // To simplify indexing expressions in these methods, we save a copy of the
+       // slice object. We could instead write (*pq)[i].
+       a := *pq
+       n := len(a)
+       a = a[0 : n+1]
+       item := x.(*Item)
+       item.index = n
+       a[n] = item
+       *pq = a
+}
+
+func (pq *PriorityQueue) Pop() interface{} {
+       a := *pq
+       n := len(a)
+       item := a[n-1]
+       item.index = -1 // for safety
+       *pq = a[0 : n-1]
+       return item
+}
+
+// update is not used by the example but shows how to take the top item from
+// the queue, update its priority and value, and put it back.
+func (pq *PriorityQueue) update(value string, priority int) {
+       item := heap.Pop(pq).(*Item)
+       item.value = value
+       item.priority = priority
+       heap.Push(pq, item)
+}
+
+// changePriority is not used by the example but shows how to change the
+// priority of an arbitrary item.
+func (pq *PriorityQueue) changePriority(item *Item, priority int) {
+       heap.Remove(pq, item.index)
+       item.priority = priority
+       heap.Push(pq, item)
+}
+
+// This example pushes 10 items into a PriorityQueue and takes them out in
+// order of priority.
+func Example() {
+       const nItem = 10
+       // Random priorities for the items (a permutation of 0..9, times 11)).
+       priorities := [nItem]int{
+               77, 22, 44, 55, 11, 88, 33, 99, 00, 66,
+       }
+       values := [nItem]string{
+               "zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine",
+       }
+       // Create a priority queue and put some items in it.
+       pq := make(PriorityQueue, 0, nItem)
+       for i := 0; i < cap(pq); i++ {
+               item := &Item{
+                       value:    values[i],
+                       priority: priorities[i],
+               }
+               heap.Push(&pq, item)
+       }
+       // Take the items out; should arrive in decreasing priority order.
+       // For example, the highest priority (99) is the seventh item, so output starts with 99:"seven".
+       for i := 0; i < nItem; i++ {
+               item := heap.Pop(&pq).(*Item)
+               fmt.Printf("%.2d:%s ", item.priority, item.value)
+       }
+       // Output:
+       // 99:seven 88:five 77:zero 66:nine 55:three 44:two 33:six 22:one 11:four 00:eight
+}
index 7af636b..67018e6 100644 (file)
@@ -6,10 +6,11 @@
 // heap.Interface. A heap is a tree with the property that each node is the
 // highest-valued node in its subtree.
 //
-// A heap is a common way to impement a priority queue. To build a priority
+// A heap is a common way to implement a priority queue. To build a priority
 // queue, implement the Heap interface with the (negative) priority as the
 // ordering for the Less method, so Push adds items while Pop removes the
-// highest-priority item from the queue.
+// highest-priority item from the queue. The Examples include such an
+// implementation; the file example_test.go has the complete source.
 //
 package heap
 
index 28752e7..7d307c9 100644 (file)
@@ -4,13 +4,16 @@
 
 package aes
 
-import "strconv"
+import (
+       "crypto/cipher"
+       "strconv"
+)
 
 // The AES block size in bytes.
 const BlockSize = 16
 
-// A Cipher is an instance of AES encryption using a particular key.
-type Cipher struct {
+// A cipher is an instance of AES encryption using a particular key.
+type aesCipher struct {
        enc []uint32
        dec []uint32
 }
@@ -21,11 +24,11 @@ func (k KeySizeError) Error() string {
        return "crypto/aes: invalid key size " + strconv.Itoa(int(k))
 }
 
-// NewCipher creates and returns a new Cipher.
+// NewCipher creates and returns a new cipher.Block.
 // The key argument should be the AES key,
 // either 16, 24, or 32 bytes to select
 // AES-128, AES-192, or AES-256.
-func NewCipher(key []byte) (*Cipher, error) {
+func NewCipher(key []byte) (cipher.Block, error) {
        k := len(key)
        switch k {
        default:
@@ -35,34 +38,13 @@ func NewCipher(key []byte) (*Cipher, error) {
        }
 
        n := k + 28
-       c := &Cipher{make([]uint32, n), make([]uint32, n)}
+       c := &aesCipher{make([]uint32, n), make([]uint32, n)}
        expandKey(key, c.enc, c.dec)
        return c, nil
 }
 
-// BlockSize returns the AES block size, 16 bytes.
-// It is necessary to satisfy the Block interface in the
-// package "crypto/cipher".
-func (c *Cipher) BlockSize() int { return BlockSize }
+func (c *aesCipher) BlockSize() int { return BlockSize }
 
-// Encrypt encrypts the 16-byte buffer src using the key k
-// and stores the result in dst.
-// Note that for amounts of data larger than a block,
-// it is not safe to just call Encrypt on successive blocks;
-// instead, use an encryption mode like CBC (see crypto/cipher/cbc.go).
-func (c *Cipher) Encrypt(dst, src []byte) { encryptBlock(c.enc, dst, src) }
+func (c *aesCipher) Encrypt(dst, src []byte) { encryptBlock(c.enc, dst, src) }
 
-// Decrypt decrypts the 16-byte buffer src using the key k
-// and stores the result in dst.
-func (c *Cipher) Decrypt(dst, src []byte) { decryptBlock(c.dec, dst, src) }
-
-// Reset zeros the key data, so that it will no longer
-// appear in the process's memory.
-func (c *Cipher) Reset() {
-       for i := 0; i < len(c.enc); i++ {
-               c.enc[i] = 0
-       }
-       for i := 0; i < len(c.dec); i++ {
-               c.dec[i] = 0
-       }
-}
+func (c *aesCipher) Decrypt(dst, src []byte) { decryptBlock(c.dec, dst, src) }
index 944ca1b..cee3a78 100644 (file)
@@ -8,11 +8,12 @@
 // Special Publication 800-38A, ``Recommendation for Block Cipher
 // Modes of Operation,'' 2001 Edition, pp. 24-29.
 
-package cipher
+package cipher_test
 
 import (
        "bytes"
        "crypto/aes"
+       "crypto/cipher"
        "testing"
 )
 
@@ -72,14 +73,14 @@ func TestCBC_AES(t *testing.T) {
                        continue
                }
 
-               encrypter := NewCBCEncrypter(c, tt.iv)
+               encrypter := cipher.NewCBCEncrypter(c, tt.iv)
                d := make([]byte, len(tt.in))
                encrypter.CryptBlocks(d, tt.in)
                if !bytes.Equal(tt.out, d) {
                        t.Errorf("%s: CBCEncrypter\nhave %x\nwant %x", test, d, tt.out)
                }
 
-               decrypter := NewCBCDecrypter(c, tt.iv)
+               decrypter := cipher.NewCBCDecrypter(c, tt.iv)
                p := make([]byte, len(d))
                decrypter.CryptBlocks(p, d)
                if !bytes.Equal(tt.in, p) {
index 9547bfc..f704b33 100644 (file)
@@ -2,11 +2,12 @@
 // Use of this source code is governed by a BSD-style
 // license that can be found in the LICENSE file.
 
-package cipher
+package cipher_test
 
 import (
        "bytes"
        "crypto/aes"
+       "crypto/cipher"
        "crypto/rand"
        "testing"
 )
@@ -21,11 +22,11 @@ func TestCFB(t *testing.T) {
        plaintext := []byte("this is the plaintext")
        iv := make([]byte, block.BlockSize())
        rand.Reader.Read(iv)
-       cfb := NewCFBEncrypter(block, iv)
+       cfb := cipher.NewCFBEncrypter(block, iv)
        ciphertext := make([]byte, len(plaintext))
        cfb.XORKeyStream(ciphertext, plaintext)
 
-       cfbdec := NewCFBDecrypter(block, iv)
+       cfbdec := cipher.NewCFBDecrypter(block, iv)
        plaintextCopy := make([]byte, len(plaintext))
        cfbdec.XORKeyStream(plaintextCopy, ciphertext)
 
index fb75575..c75c919 100644 (file)
@@ -2,7 +2,7 @@
 // Use of this source code is governed by a BSD-style
 // license that can be found in the LICENSE file.
 
-package cipher
+package cipher_test
 
 // Common values for tests.
 
index 8dca996..d019ae0 100644 (file)
@@ -8,11 +8,12 @@
 // Special Publication 800-38A, ``Recommendation for Block Cipher
 // Modes of Operation,'' 2001 Edition, pp. 55-58.
 
-package cipher
+package cipher_test
 
 import (
        "bytes"
        "crypto/aes"
+       "crypto/cipher"
        "testing"
 )
 
@@ -76,7 +77,7 @@ func TestCTR_AES(t *testing.T) {
 
                for j := 0; j <= 5; j += 5 {
                        in := tt.in[0 : len(tt.in)-j]
-                       ctr := NewCTR(c, tt.iv)
+                       ctr := cipher.NewCTR(c, tt.iv)
                        encrypted := make([]byte, len(in))
                        ctr.XORKeyStream(encrypted, in)
                        if out := tt.out[0:len(in)]; !bytes.Equal(out, encrypted) {
@@ -86,7 +87,7 @@ func TestCTR_AES(t *testing.T) {
 
                for j := 0; j <= 7; j += 7 {
                        in := tt.out[0 : len(tt.out)-j]
-                       ctr := NewCTR(c, tt.iv)
+                       ctr := cipher.NewCTR(c, tt.iv)
                        plain := make([]byte, len(in))
                        ctr.XORKeyStream(plain, in)
                        if out := tt.in[0:len(in)]; !bytes.Equal(out, plain) {
index 9b4495c..8d3c5d3 100644 (file)
@@ -8,11 +8,12 @@
 // Special Publication 800-38A, ``Recommendation for Block Cipher
 // Modes of Operation,'' 2001 Edition, pp. 52-55.
 
-package cipher
+package cipher_test
 
 import (
        "bytes"
        "crypto/aes"
+       "crypto/cipher"
        "testing"
 )
 
@@ -76,7 +77,7 @@ func TestOFB(t *testing.T) {
 
                for j := 0; j <= 5; j += 5 {
                        plaintext := tt.in[0 : len(tt.in)-j]
-                       ofb := NewOFB(c, tt.iv)
+                       ofb := cipher.NewOFB(c, tt.iv)
                        ciphertext := make([]byte, len(plaintext))
                        ofb.XORKeyStream(ciphertext, plaintext)
                        if !bytes.Equal(ciphertext, tt.out[:len(plaintext)]) {
@@ -86,7 +87,7 @@ func TestOFB(t *testing.T) {
 
                for j := 0; j <= 5; j += 5 {
                        ciphertext := tt.out[0 : len(tt.in)-j]
-                       ofb := NewOFB(c, tt.iv)
+                       ofb := cipher.NewOFB(c, tt.iv)
                        plaintext := make([]byte, len(ciphertext))
                        ofb.XORKeyStream(plaintext, ciphertext)
                        if !bytes.Equal(plaintext, tt.in[:len(ciphertext)]) {
index e18eaed..c11c62c 100644 (file)
@@ -79,7 +79,7 @@ func ksRotate(in uint32) (out []uint32) {
 }
 
 // creates 16 56-bit subkeys from the original key
-func (c *Cipher) generateSubkeys(keyBytes []byte) {
+func (c *desCipher) generateSubkeys(keyBytes []byte) {
        // apply PC1 permutation to key
        key := binary.BigEndian.Uint64(keyBytes)
        permutedKey := permuteBlock(key, permutedChoice1[:])
index 1c41e29..2f929ca 100644 (file)
@@ -4,7 +4,10 @@
 
 package des
 
-import "strconv"
+import (
+       "crypto/cipher"
+       "strconv"
+)
 
 // The DES block size in bytes.
 const BlockSize = 8
@@ -15,86 +18,56 @@ func (k KeySizeError) Error() string {
        return "crypto/des: invalid key size " + strconv.Itoa(int(k))
 }
 
-// Cipher is an instance of DES encryption.
-type Cipher struct {
+// desCipher is an instance of DES encryption.
+type desCipher struct {
        subkeys [16]uint64
 }
 
-// NewCipher creates and returns a new Cipher.
-func NewCipher(key []byte) (*Cipher, error) {
+// NewCipher creates and returns a new cipher.Block.
+func NewCipher(key []byte) (cipher.Block, error) {
        if len(key) != 8 {
                return nil, KeySizeError(len(key))
        }
 
-       c := new(Cipher)
+       c := new(desCipher)
        c.generateSubkeys(key)
        return c, nil
 }
 
-// BlockSize returns the DES block size, 8 bytes.
-func (c *Cipher) BlockSize() int { return BlockSize }
+func (c *desCipher) BlockSize() int { return BlockSize }
 
-// Encrypt encrypts the 8-byte buffer src and stores the result in dst.
-// Note that for amounts of data larger than a block,
-// it is not safe to just call Encrypt on successive blocks;
-// instead, use an encryption mode like CBC (see crypto/cipher/cbc.go).
-func (c *Cipher) Encrypt(dst, src []byte) { encryptBlock(c.subkeys[:], dst, src) }
+func (c *desCipher) Encrypt(dst, src []byte) { encryptBlock(c.subkeys[:], dst, src) }
 
-// Decrypt decrypts the 8-byte buffer src and stores the result in dst.
-func (c *Cipher) Decrypt(dst, src []byte) { decryptBlock(c.subkeys[:], dst, src) }
+func (c *desCipher) Decrypt(dst, src []byte) { decryptBlock(c.subkeys[:], dst, src) }
 
-// Reset zeros the key data, so that it will no longer
-// appear in the process's memory.
-func (c *Cipher) Reset() {
-       for i := 0; i < len(c.subkeys); i++ {
-               c.subkeys[i] = 0
-       }
-}
-
-// A TripleDESCipher is an instance of TripleDES encryption.
-type TripleDESCipher struct {
-       cipher1, cipher2, cipher3 Cipher
+// A tripleDESCipher is an instance of TripleDES encryption.
+type tripleDESCipher struct {
+       cipher1, cipher2, cipher3 desCipher
 }
 
-// NewCipher creates and returns a new Cipher.
-func NewTripleDESCipher(key []byte) (*TripleDESCipher, error) {
+// NewTripleDESCipher creates and returns a new cipher.Block.
+func NewTripleDESCipher(key []byte) (cipher.Block, error) {
        if len(key) != 24 {
                return nil, KeySizeError(len(key))
        }
 
-       c := new(TripleDESCipher)
+       c := new(tripleDESCipher)
        c.cipher1.generateSubkeys(key[:8])
        c.cipher2.generateSubkeys(key[8:16])
        c.cipher3.generateSubkeys(key[16:])
        return c, nil
 }
 
-// BlockSize returns the TripleDES block size, 8 bytes.
-// It is necessary to satisfy the Block interface in the
-// package "crypto/cipher".
-func (c *TripleDESCipher) BlockSize() int { return BlockSize }
+func (c *tripleDESCipher) BlockSize() int { return BlockSize }
 
-// Encrypts the 8-byte buffer src and stores the result in dst.
-// Note that for amounts of data larger than a block,
-// it is not safe to just call Encrypt on successive blocks;
-// instead, use an encryption mode like CBC (see crypto/cipher/cbc.go).
-func (c *TripleDESCipher) Encrypt(dst, src []byte) {
+func (c *tripleDESCipher) Encrypt(dst, src []byte) {
        c.cipher1.Encrypt(dst, src)
        c.cipher2.Decrypt(dst, dst)
        c.cipher3.Encrypt(dst, dst)
 }
 
-// Decrypts the 8-byte buffer src and stores the result in dst.
-func (c *TripleDESCipher) Decrypt(dst, src []byte) {
+func (c *tripleDESCipher) Decrypt(dst, src []byte) {
        c.cipher3.Decrypt(dst, src)
        c.cipher2.Encrypt(dst, dst)
        c.cipher1.Decrypt(dst, dst)
 }
-
-// Reset zeros the key data, so that it will no longer
-// appear in the process's memory.
-func (c *TripleDESCipher) Reset() {
-       c.cipher1.Reset()
-       c.cipher2.Reset()
-       c.cipher3.Reset()
-}
index d1f3aa7..e9fc236 100644 (file)
@@ -1260,11 +1260,19 @@ var tableA4Tests = []CryptTest{
                []byte{0x63, 0xfa, 0xc0, 0xd0, 0x34, 0xd9, 0xf7, 0x93}},
 }
 
+func newCipher(key []byte) *desCipher {
+       c, err := NewCipher(key)
+       if err != nil {
+               panic("NewCipher failed: " + err.Error())
+       }
+       return c.(*desCipher)
+}
+
 // Use the known weak keys to test DES implementation
 func TestWeakKeys(t *testing.T) {
        for i, tt := range weakKeyTests {
                var encrypt = func(in []byte) (out []byte) {
-                       c, _ := NewCipher(tt.key)
+                       c := newCipher(tt.key)
                        out = make([]byte, len(in))
                        encryptBlock(c.subkeys[:], out, in)
                        return
@@ -1285,7 +1293,7 @@ func TestWeakKeys(t *testing.T) {
 func TestSemiWeakKeyPairs(t *testing.T) {
        for i, tt := range semiWeakKeyTests {
                var encrypt = func(key, in []byte) (out []byte) {
-                       c, _ := NewCipher(key)
+                       c := newCipher(key)
                        out = make([]byte, len(in))
                        encryptBlock(c.subkeys[:], out, in)
                        return
@@ -1305,7 +1313,7 @@ func TestSemiWeakKeyPairs(t *testing.T) {
 
 func TestDESEncryptBlock(t *testing.T) {
        for i, tt := range encryptDESTests {
-               c, _ := NewCipher(tt.key)
+               c := newCipher(tt.key)
                out := make([]byte, len(tt.in))
                encryptBlock(c.subkeys[:], out, tt.in)
 
@@ -1317,7 +1325,7 @@ func TestDESEncryptBlock(t *testing.T) {
 
 func TestDESDecryptBlock(t *testing.T) {
        for i, tt := range encryptDESTests {
-               c, _ := NewCipher(tt.key)
+               c := newCipher(tt.key)
                plain := make([]byte, len(tt.in))
                decryptBlock(c.subkeys[:], plain, tt.out)
 
index 81487f6..05766a2 100644 (file)
@@ -2,7 +2,7 @@
 // Use of this source code is governed by a BSD-style
 // license that can be found in the LICENSE file.
 
-// Package dsa implements the Digital Signature Algorithm, as defined in FIPS 186-3
+// Package dsa implements the Digital Signature Algorithm, as defined in FIPS 186-3.
 package dsa
 
 import (
@@ -29,17 +29,11 @@ type PrivateKey struct {
        X *big.Int
 }
 
-type invalidPublicKeyError int
-
-func (invalidPublicKeyError) Error() string {
-       return "crypto/dsa: invalid public key"
-}
-
 // ErrInvalidPublicKey results when a public key is not usable by this code.
 // FIPS is quite strict about the format of DSA keys, but other code may be
 // less so. Thus, when using keys which may have been generated by other code,
 // this error must be handled.
-var ErrInvalidPublicKey error = invalidPublicKeyError(0)
+var ErrInvalidPublicKey = errors.New("crypto/dsa: invalid public key")
 
 // ParameterSizes is a enumeration of the acceptable bit lengths of the primes
 // in a set of DSA parameters. See FIPS 186-3, section 4.2.
index d2f7d8f..b28239b 100644 (file)
@@ -7,7 +7,7 @@
 package ecdsa
 
 // References:
-//   [NSA]: Suite B implementor's guide to FIPS 186-3,
+//   [NSA]: Suite B implementer's guide to FIPS 186-3,
 //     http://www.nsa.gov/ia/_files/ecdsa.pdf
 //   [SECG]: SECG, SEC1
 //     http://www.secg.org/download/aid-780/sec1-v2.pdf
index b15e466..aae8754 100644 (file)
@@ -2,9 +2,10 @@
 // Use of this source code is governed by a BSD-style
 // license that can be found in the LICENSE file.
 
-package md5
+package md5_test
 
 import (
+       "crypto/md5"
        "fmt"
        "io"
        "testing"
@@ -52,7 +53,7 @@ var golden = []md5Test{
 func TestGolden(t *testing.T) {
        for i := 0; i < len(golden); i++ {
                g := golden[i]
-               c := New()
+               c := md5.New()
                for j := 0; j < 3; j++ {
                        if j < 2 {
                                io.WriteString(c, g.in)
@@ -69,3 +70,11 @@ func TestGolden(t *testing.T) {
                }
        }
 }
+
+func ExampleNew() {
+       h := md5.New()
+       io.WriteString(h, "The fog is getting thicker!")
+       io.WriteString(h, "And Leon's getting laaarger!")
+       fmt.Printf("%x", h.Sum(nil))
+       // Output: e2c569be17396eca2a2e3c11578123ed
+}
index bfae7ce..be3a5a2 100644 (file)
@@ -22,7 +22,7 @@ func TestRead(t *testing.T) {
        }
 
        var z bytes.Buffer
-       f := flate.NewWriter(&z, 5)
+       f, _ := flate.NewWriter(&z, 5)
        f.Write(b)
        f.Close()
        if z.Len() < len(b)*99/100 {
index 5d4fc81..5eb4cda 100644 (file)
@@ -12,6 +12,7 @@ package rand
 import (
        "bufio"
        "crypto/aes"
+       "crypto/cipher"
        "io"
        "os"
        "sync"
@@ -66,7 +67,7 @@ func newReader(entropy io.Reader) io.Reader {
 type reader struct {
        mu                   sync.Mutex
        budget               int // number of bytes that can be generated
-       cipher               *aes.Cipher
+       cipher               cipher.Block
        entropy              io.Reader
        time, seed, dst, key [aes.BlockSize]byte
 }
index 4f12cbe..254f4a3 100644 (file)
@@ -21,7 +21,7 @@ import (
 func EncryptPKCS1v15(rand io.Reader, pub *PublicKey, msg []byte) (out []byte, err error) {
        k := (pub.N.BitLen() + 7) / 8
        if len(msg) > k-11 {
-               err = MessageTooLongError{}
+               err = ErrMessageTooLong
                return
        }
 
@@ -47,7 +47,7 @@ func EncryptPKCS1v15(rand io.Reader, pub *PublicKey, msg []byte) (out []byte, er
 func DecryptPKCS1v15(rand io.Reader, priv *PrivateKey, ciphertext []byte) (out []byte, err error) {
        valid, out, err := decryptPKCS1v15(rand, priv, ciphertext)
        if err == nil && valid == 0 {
-               err = DecryptionError{}
+               err = ErrDecryption
        }
 
        return
@@ -69,7 +69,7 @@ func DecryptPKCS1v15(rand io.Reader, priv *PrivateKey, ciphertext []byte) (out [
 func DecryptPKCS1v15SessionKey(rand io.Reader, priv *PrivateKey, ciphertext []byte, key []byte) (err error) {
        k := (priv.N.BitLen() + 7) / 8
        if k-(len(key)+3+8) < 0 {
-               err = DecryptionError{}
+               err = ErrDecryption
                return
        }
 
@@ -86,7 +86,7 @@ func DecryptPKCS1v15SessionKey(rand io.Reader, priv *PrivateKey, ciphertext []by
 func decryptPKCS1v15(rand io.Reader, priv *PrivateKey, ciphertext []byte) (valid int, msg []byte, err error) {
        k := (priv.N.BitLen() + 7) / 8
        if k < 11 {
-               err = DecryptionError{}
+               err = ErrDecryption
                return
        }
 
@@ -170,7 +170,7 @@ func SignPKCS1v15(rand io.Reader, priv *PrivateKey, hash crypto.Hash, hashed []b
        tLen := len(prefix) + hashLen
        k := (priv.N.BitLen() + 7) / 8
        if k < tLen+11 {
-               return nil, MessageTooLongError{}
+               return nil, ErrMessageTooLong
        }
 
        // EM = 0x00 || 0x01 || PS || 0x00 || T
@@ -203,7 +203,7 @@ func VerifyPKCS1v15(pub *PublicKey, hash crypto.Hash, hashed []byte, sig []byte)
        tLen := len(prefix) + hashLen
        k := (pub.N.BitLen() + 7) / 8
        if k < tLen+11 {
-               err = VerificationError{}
+               err = ErrVerification
                return
        }
 
@@ -223,7 +223,7 @@ func VerifyPKCS1v15(pub *PublicKey, hash crypto.Hash, hashed []byte, sig []byte)
        }
 
        if ok != 1 {
-               return VerificationError{}
+               return ErrVerification
        }
 
        return nil
index 677d27b..ec77e68 100644 (file)
@@ -206,13 +206,9 @@ func mgf1XOR(out []byte, hash hash.Hash, seed []byte) {
        }
 }
 
-// MessageTooLongError is returned when attempting to encrypt a message which
-// is too large for the size of the public key.
-type MessageTooLongError struct{}
-
-func (MessageTooLongError) Error() string {
-       return "message too long for RSA public key size"
-}
+// ErrMessageTooLong is returned when attempting to encrypt a message which is
+// too large for the size of the public key.
+var ErrMessageTooLong = errors.New("crypto/rsa: message too long for RSA public key size")
 
 func encrypt(c *big.Int, pub *PublicKey, m *big.Int) *big.Int {
        e := big.NewInt(int64(pub.E))
@@ -227,7 +223,7 @@ func EncryptOAEP(hash hash.Hash, random io.Reader, pub *PublicKey, msg []byte, l
        hash.Reset()
        k := (pub.N.BitLen() + 7) / 8
        if len(msg) > k-2*hash.Size()-2 {
-               err = MessageTooLongError{}
+               err = ErrMessageTooLong
                return
        }
 
@@ -266,17 +262,13 @@ func EncryptOAEP(hash hash.Hash, random io.Reader, pub *PublicKey, msg []byte, l
        return
 }
 
-// A DecryptionError represents a failure to decrypt a message.
+// ErrDecryption represents a failure to decrypt a message.
 // It is deliberately vague to avoid adaptive attacks.
-type DecryptionError struct{}
+var ErrDecryption = errors.New("crypto/rsa: decryption error")
 
-func (DecryptionError) Error() string { return "RSA decryption error" }
-
-// A VerificationError represents a failure to verify a signature.
+// ErrVerification represents a failure to verify a signature.
 // It is deliberately vague to avoid adaptive attacks.
-type VerificationError struct{}
-
-func (VerificationError) Error() string { return "RSA verification error" }
+var ErrVerification = errors.New("crypto/rsa: verification error")
 
 // modInverse returns ia, the inverse of a in the multiplicative group of prime
 // order n. It requires that a be a member of the group (i.e. less than n).
@@ -338,7 +330,7 @@ func (priv *PrivateKey) Precompute() {
 func decrypt(random io.Reader, priv *PrivateKey, c *big.Int) (m *big.Int, err error) {
        // TODO(agl): can we get away with reusing blinds?
        if c.Cmp(priv.N) > 0 {
-               err = DecryptionError{}
+               err = ErrDecryption
                return
        }
 
@@ -417,7 +409,7 @@ func DecryptOAEP(hash hash.Hash, random io.Reader, priv *PrivateKey, ciphertext
        k := (priv.N.BitLen() + 7) / 8
        if len(ciphertext) > k ||
                k < hash.Size()*2+2 {
-               err = DecryptionError{}
+               err = ErrDecryption
                return
        }
 
@@ -473,7 +465,7 @@ func DecryptOAEP(hash hash.Hash, random io.Reader, priv *PrivateKey, ciphertext
        }
 
        if firstByteIsZero&lHash2Good&^invalid&^lookingForIndex != 1 {
-               err = DecryptionError{}
+               err = ErrDecryption
                return
        }
 
index c23df6c..2dc14ac 100644 (file)
@@ -4,9 +4,10 @@
 
 // SHA1 hash algorithm.  See RFC 3174.
 
-package sha1
+package sha1_test
 
 import (
+       "crypto/sha1"
        "fmt"
        "io"
        "testing"
@@ -54,7 +55,7 @@ var golden = []sha1Test{
 func TestGolden(t *testing.T) {
        for i := 0; i < len(golden); i++ {
                g := golden[i]
-               c := New()
+               c := sha1.New()
                for j := 0; j < 3; j++ {
                        if j < 2 {
                                io.WriteString(c, g.in)
@@ -71,3 +72,10 @@ func TestGolden(t *testing.T) {
                }
        }
 }
+
+func ExampleNew() {
+       h := sha1.New()
+       io.WriteString(h, "His money is twice tainted: 'taint yours and 'taint mine.")
+       fmt.Printf("% x", h.Sum(nil))
+       // Output: 59 7f 6a 54 00 10 f9 4c 15 d7 18 06 a9 9a 2c 87 10 e7 47 bd
+}
index e6cee12..2a5115d 100644 (file)
@@ -87,9 +87,9 @@ func (c *Conn) RemoteAddr() net.Addr {
        return c.conn.RemoteAddr()
 }
 
-// SetDeadline sets the read deadline associated with the connection.
-// There is no write deadline.
-// A zero value for t means Read will not time out.
+// SetDeadline sets the read and write deadlines associated with the connection.
+// A zero value for t means Read and Write will not time out.
+// After a Write has timed out, the TLS state is corrupt and all future writes will return the same error.
 func (c *Conn) SetDeadline(t time.Time) error {
        return c.conn.SetDeadline(t)
 }
@@ -100,10 +100,11 @@ func (c *Conn) SetReadDeadline(t time.Time) error {
        return c.conn.SetReadDeadline(t)
 }
 
-// SetWriteDeadline exists to satisfy the net.Conn interface
-// but is not implemented by TLS.  It always returns an error.
+// SetWriteDeadline sets the write deadline on the underlying conneciton.
+// A zero value for t means Write will not time out.
+// After a Write has timed out, the TLS state is corrupt and all future writes will return the same error.
 func (c *Conn) SetWriteDeadline(t time.Time) error {
-       return errors.New("TLS does not support SetWriteDeadline")
+       return c.conn.SetWriteDeadline(t)
 }
 
 // A halfConn represents one direction of the record layer
@@ -726,9 +727,13 @@ func (c *Conn) readHandshake() (interface{}, error) {
 }