+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.
# 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"
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
Btype*
fill_in_array(Btype*, Btype*, Bexpression*);
+
+ tree
+ non_zero_size_type(tree);
};
// A helper function.
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.
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,
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*
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);
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;
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,
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())
|| 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);
}
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(),
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.
++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();
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*);
{
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);
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.
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();
// 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 (
)
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)
}
}
package main
import (
- "os"
+ "errors"
"strconv"
)
}
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)
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() {
-52ba9506bd99
+f4470a54e6db
The first line of this file holds the Mercurial revision number of the
last merge done from the master library sources.
$(exp_inotify_gox) \
exp/norm.gox \
exp/proxy.gox \
- exp/signal.gox \
exp/terminal.gox \
exp/types.gox \
exp/utf8string.gox
toolexeclibgoos_DATA = \
os/exec.gox \
+ os/signal.gox \
os/user.gox
toolexeclibgopathdir = $(toolexeclibgodir)/path
toolexeclibgotesting_DATA = \
testing/iotest.gox \
- testing/quick.gox \
- testing/script.gox
+ testing/quick.gox
toolexeclibgotextdir = $(toolexeclibgodir)/text
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 \
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-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/msize.c \
runtime/proc.c \
runtime/runtime.c \
+ runtime/signal_unix.c \
runtime/thread.c \
runtime/yield.c \
$(rtems_task_variable_add_file) \
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
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
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
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 \
$(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 \
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
go/sync/cond.go \
go/sync/mutex.go \
go/sync/once.go \
+ go/sync/runtime.go \
go/sync/rwmutex.go \
go/sync/waitgroup.go
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 = \
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
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 \
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
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 \
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
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 \
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
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
syscall_arch.go
go_syscall_c_files = \
go/syscall/errno.c \
+ go/syscall/signame.c \
$(syscall_wait_c_file)
libcalls.go: s-libcalls; @true
exp/html.lo \
exp/norm.lo \
exp/proxy.lo \
- exp/signal.lo \
exp/terminal.lo \
exp/types.lo \
exp/utf8string.lo \
old/regexp.lo \
old/template.lo \
$(os_lib_inotify_lo) \
+ os/signal.lo \
os/user.lo \
path/filepath.lo \
regexp/syntax.lo \
sync/atomic_c.lo \
syscall/syscall.lo \
syscall/errno.lo \
+ syscall/signame.lo \
syscall/wait.lo \
text/scanner.lo \
text/tabwriter.lo \
testing/testing.lo \
testing/iotest.lo \
testing/quick.lo \
- testing/script.lo \
unicode/utf16.lo \
unicode/utf8.lo
@$(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)
@$(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)
@$(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)
@$(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)
$(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 $@ $<
$(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
os/exec.gox: os/exec.lo
$(BUILDGOX)
+os/signal.gox: os/signal.lo
+ $(BUILDGOX)
os/user.gox: os/user.lo
$(BUILDGOX)
$(BUILDGOX)
testing/quick.gox: testing/quick.lo
$(BUILDGOX)
-testing/script.gox: testing/script.lo
- $(BUILDGOX)
unicode/utf16.gox: unicode/utf16.lo
$(BUILDGOX)
$(exp_inotify_check) \
exp/norm/check \
exp/proxy/check \
- exp/signal/check \
exp/terminal/check \
exp/utf8string/check \
html/template/check \
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 \
old/regexp/check \
old/template/check \
os/exec/check \
+ os/signal/check \
os/user/check \
path/filepath/check \
regexp/syntax/check \
text/template/check \
text/template/parse/check \
testing/quick/check \
- testing/script/check \
unicode/utf16/check \
unicode/utf8/check
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) \
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 \
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 \
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
@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) \
$(exp_inotify_gox) \
exp/norm.gox \
exp/proxy.gox \
- exp/signal.gox \
exp/terminal.gox \
exp/types.gox \
exp/utf8string.gox
toolexeclibgoosdir = $(toolexeclibgodir)/os
toolexeclibgoos_DATA = \
os/exec.gox \
+ os/signal.gox \
os/user.gox
toolexeclibgopathdir = $(toolexeclibgodir)/path
toolexeclibgotestingdir = $(toolexeclibgodir)/testing
toolexeclibgotesting_DATA = \
testing/iotest.gox \
- testing/quick.gox \
- testing/script.gox
+ testing/quick.gox
toolexeclibgotextdir = $(toolexeclibgodir)/text
toolexeclibgotext_DATA = \
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 \
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-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/msize.c \
runtime/proc.c \
runtime/runtime.c \
+ runtime/signal_unix.c \
runtime/thread.c \
runtime/yield.c \
$(rtems_task_variable_add_file) \
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
@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
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 \
$(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 \
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
go/sync/cond.go \
go/sync/mutex.go \
go/sync/once.go \
+ go/sync/runtime.go \
go/sync/rwmutex.go \
go/sync/waitgroup.go
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 = \
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/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 \
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
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/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_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 \
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
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
go_syscall_c_files = \
go/syscall/errno.c \
+ go/syscall/signame.c \
$(syscall_wait_c_file)
@LIBGO_IS_LINUX_FALSE@os_lib_inotify_lo =
exp/html.lo \
exp/norm.lo \
exp/proxy.lo \
- exp/signal.lo \
exp/terminal.lo \
exp/types.lo \
exp/utf8string.lo \
old/regexp.lo \
old/template.lo \
$(os_lib_inotify_lo) \
+ os/signal.lo \
os/user.lo \
path/filepath.lo \
regexp/syntax.lo \
sync/atomic_c.lo \
syscall/syscall.lo \
syscall/errno.lo \
+ syscall/signame.lo \
syscall/wait.lo \
text/scanner.lo \
text/tabwriter.lo \
testing/testing.lo \
testing/iotest.lo \
testing/quick.lo \
- testing/script.lo \
unicode/utf16.lo \
unicode/utf8.lo
$(exp_inotify_check) \
exp/norm/check \
exp/proxy/check \
- exp/signal/check \
exp/terminal/check \
exp/utf8string/check \
html/template/check \
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 \
old/regexp/check \
old/template/check \
os/exec/check \
+ os/signal/check \
os/user/check \
path/filepath/check \
regexp/syntax/check \
text/template/check \
text/template/parse/check \
testing/quick/check \
- testing/script/check \
unicode/utf16/check \
unicode/utf8/check
@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@
@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@
@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@
@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@
@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
@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
@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
@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
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
@$(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)
@$(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)
@$(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)
@$(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)
$(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 $@ $<
$(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
os/exec.gox: os/exec.lo
$(BUILDGOX)
+os/signal.gox: os/signal.lo
+ $(BUILDGOX)
os/user.gox: os/user.lo
$(BUILDGOX)
$(BUILDGOX)
testing/quick.gox: testing/quick.lo
$(BUILDGOX)
-testing/script.gox: testing/script.lo
- $(BUILDGOX)
unicode/utf16.gox: unicode/utf16.lo
$(BUILDGOX)
/* 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. */
;;
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='#'
;;
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
#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)
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
}
// 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
}
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 {
}
// 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
}
}
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
+}
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
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)
}
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
-}
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
// Writer implements a zip file writer.
type Writer struct {
- countWriter
+ cw *countWriter
dir []*header
last *fileWriter
closed bool
// 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
}
}
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.
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
}
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
}
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 {
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
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 {
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:]
}
}
// 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)
}
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")
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)
}
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.
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
}
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) {
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)
// 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) {
}
// 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 {
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)
}
"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!
}
--- /dev/null
+// 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} }
--- /dev/null
+// 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)
+ }
+ }
+}
package flate
import (
+ "fmt"
"io"
"math"
)
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
}
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
// 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 {
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) {
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.
// 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
}
}
-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) {
}
}
-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{})
}
}
t.Error(err)
}
testToFromWithLimit(t, gold, test.label, test.limit)
+ if testing.Short() {
+ break
+ }
}
}
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()
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()
w.Close()
var b1 bytes.Buffer
- w = NewWriterDict(&b1, 5, []byte(dict))
+ w, _ = NewWriterDict(&b1, 5, []byte(dict))
w.Write([]byte(text))
w.Close()
// 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 {
import (
"io"
"math"
- "strconv"
)
const (
err error
}
-type WrongValueError struct {
- name string
- from int32
- to int32
- value int32
-}
-
func newHuffmanBitWriter(w io.Writer) *huffmanBitWriter {
return &huffmanBitWriter{
w: w,
}
}
-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
"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
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"
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
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
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++ {
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
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
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
}
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() }
import (
"compress/flate"
"errors"
+ "fmt"
"hash"
"hash/crc32"
"io"
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
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).
}
// 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")
}
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 {
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
}
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)
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
}
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)
- //}
}
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
import (
"compress/flate"
- "errors"
+ "fmt"
"hash"
"hash/adler32"
"io"
// 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.
// 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:
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
}
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
}
// 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
}
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
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)
--- /dev/null
+// 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
+}
// 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
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
}
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:
}
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) }
// 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"
)
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) {
// 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"
)
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)
// 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.
// 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"
)
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) {
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) {
// 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"
)
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)]) {
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)]) {
}
// 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[:])
package des
-import "strconv"
+import (
+ "crypto/cipher"
+ "strconv"
+)
// The DES block size in bytes.
const BlockSize = 8
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()
-}
[]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
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
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)
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)
// 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 (
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.
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
// 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"
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)
}
}
}
+
+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
+}
}
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 {
import (
"bufio"
"crypto/aes"
+ "crypto/cipher"
"io"
"os"
"sync"
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
}
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
}
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
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
}
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
}
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
tLen := len(prefix) + hashLen
k := (pub.N.BitLen() + 7) / 8
if k < tLen+11 {
- err = VerificationError{}
+ err = ErrVerification
return
}
}
if ok != 1 {
- return VerificationError{}
+ return ErrVerification
}
return nil
}
}
-// 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))
hash.Reset()
k := (pub.N.BitLen() + 7) / 8
if len(msg) > k-2*hash.Size()-2 {
- err = MessageTooLongError{}
+ err = ErrMessageTooLong
return
}
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).
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
}
k := (priv.N.BitLen() + 7) / 8
if len(ciphertext) > k ||
k < hash.Size()*2+2 {
- err = DecryptionError{}
+ err = ErrDecryption
return
}
}
if firstByteIsZero&lHash2Good&^invalid&^lookingForIndex != 1 {
- err = DecryptionError{}
+ err = ErrDecryption
return
}
// SHA1 hash algorithm. See RFC 3174.
-package sha1
+package sha1_test
import (
+ "crypto/sha1"
"fmt"
"io"
"testing"
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)
}
}
}
+
+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
+}
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)
}
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
}