Russ Cox [Sat, 5 Mar 2011 19:35:03 +0000 (14:35 -0500)]
compress/flate: fix test
The test was checking for a buffer to be empty but
actually racing with the background goroutine that
was emptying it. Left a comment so that the check
is not reintroduced later.
Russ Cox [Sat, 5 Mar 2011 19:24:44 +0000 (14:24 -0500)]
cgo: use correct frame size for 0 arguments
Passing a frame size of 1 was causing the cgo callback
to push 1 byte of arguments onto the stack, making
the stack pointer misaligned, which had the effect of
hiding all the pointers on the stack from the garbage
collector.
SWIG only wraps calls to C++ virtual methods, so it
always has at least 1 argument, so SWIG does not need
to be fixed too.
Rob Pike [Fri, 4 Mar 2011 22:18:52 +0000 (14:18 -0800)]
gob: enable the GobEncoder and GobDecoder interfaces.
These allow data items to control their own representation.
For now, the implementation requires that the value passed
to Encode and Decode must be exactly the type of the
methods' receiver; it cannot be, for instance, T if the receiver
is of type *T. This will be fixed in a later CL.
Rob Pike [Fri, 4 Mar 2011 20:25:18 +0000 (12:25 -0800)]
gob: beginning of support for GobEncoder/GobDecoder interfaces.
This allows a data item that can marshal itself to be transmitted by its
own encoding, enabling some types to be handled that cannot be
normally, plus providing a way to use gobs on data with unexported
fields.
In this CL, the necessary methods are protected by leading _, so only
package gob can use the facilities (in its tests, of course); this
code is not ready for real use yet. I could be talked into enabling
it for experimentation, though. The main drawback is that the
methods must be implemented by the actual type passed through,
not by an indirection from it. For instance, if *T implements
GobEncoder, you must send a *T, not a T. This will be addressed
in due course.
Also there is improved commentary and a couple of unrelated
minor bug fixes.
Brad Fitzpatrick [Thu, 3 Mar 2011 20:22:13 +0000 (12:22 -0800)]
http: allow handlers to send non-chunked responses
Currently all http handlers reply to HTTP/1.1 requests with
chunked responses. This patch allows handlers to opt-out of
that behavior by pre-declaring their Content-Length (which is
then enforced) and unsetting their Transfer-Encoding or
setting it to the "identity" encoding.
Russ Cox [Thu, 3 Mar 2011 19:51:49 +0000 (14:51 -0500)]
io/ioutil: add TempDir
It's a little confusing that os.TempDir and ioutil.TempDir have
different meanings. I don't know what to change the names to,
if anything. At least they also have different signatures.
Roger Peppe [Thu, 3 Mar 2011 18:43:29 +0000 (10:43 -0800)]
fmt: make recursive scan more efficient.
Detect when scan is being called recursively and
re-use the same scan state.
On my machine, for a recursion-heavy benchmark, this
results in 44x speed up. This does impose a 4% penalty
on the non-recursive case, which can be removed by
heap-allocating the saved state, at 40% performance penalty
on the recursive case. Either way is fine with me.
Adam Langley [Thu, 3 Mar 2011 14:13:06 +0000 (09:13 -0500)]
bzip2: speed up decompression.
This borrows a trick from the bzip2 source and effects a decent speed
up when decompressing highly compressed sources. Rather than unshuffle
the BTW block when performing the IBTW, a linked-list is threaded
through the array, in place. This improves cache hit rates.
Gustavo Niemeyer [Wed, 2 Mar 2011 21:18:17 +0000 (16:18 -0500)]
gc: fix init of packages named main
This change removes the special case which existed
for handling the initalization of the main package,
so that other modules named 'main' get properly
initialized when imported.
Note that gotest of main packages will break in most
cases without this.
Roger Peppe [Wed, 2 Mar 2011 20:04:08 +0000 (15:04 -0500)]
goinstall: protect against malicious filenames.
It was possible to make package run arbitrary
commands when installing if its filenames contained
make metacharacters.
Roger Peppe [Wed, 2 Mar 2011 19:22:33 +0000 (14:22 -0500)]
cgo: put temporary source files in _obj.
Fixes #1572.
Initially I tried changing things so all object
files get put in _obj, but it's too much - everything
needs changing. Perhaps some other time.
Roger Peppe [Wed, 2 Mar 2011 18:54:23 +0000 (10:54 -0800)]
fmt: allow recursive calls to Fscan etc.
Add a new Read method to ScanState so that it
satisfies the io.Reader interface; rename
Getrune and Ungetrune to ReadRune and UnreadRune.
Make sure ReadRune does not read past width restrictions;
remove now-unnecessary Width method from ScanState.
Also make the documentation a little clearer as to
how ReadRune and UnreadRune are used.
Rob Pike [Tue, 1 Mar 2011 21:54:22 +0000 (13:54 -0800)]
docs: make "runtime" a word only as a name for the package.
Computer people have an agglutinating streak that I like to resist.
As a time of execution: run time.
As an adjective: run-time.
As a noun: run-time support/code/library.
Russ Cox [Mon, 28 Feb 2011 04:32:42 +0000 (23:32 -0500)]
runtime: idle goroutine
This functionality might be used in environments
where programs are limited to a single thread,
to simulate a select-driven network server. It is
not exposed via the standard runtime API.
Russ Cox [Thu, 24 Feb 2011 21:46:44 +0000 (13:46 -0800)]
runtime: fix signal stack bug
In CL 4188061 I changed malg to allocate the requested
number of bytes n, not n+StackGuard, so that the
allocations would use rounder numbers.
The allocation of the signal stack asks for 32k and
then used g->stackguard as the base, but g->stackguard
is StackGuard bytes above the base. Previously, asking
for 32k meant getting 32k+StackGuard bytes, so using
g->stackguard as the base was safe. Now, the actual base
must be computed, so that the signal handler does not
run StackGuard bytes past the top of the stack.
Was causing flakiness mainly in programs that use the
network, because they sometimes write to closed network
connections, causing SIGPIPEs. Was also causing problems
in the doc/progs test.
Also fix Makefile so that changes to stack.h trigger rebuild.
Russ Cox [Thu, 24 Feb 2011 21:45:45 +0000 (16:45 -0500)]
ld: weak symbols
A reference to the address of weak.foo resolves at link time
to the address of the symbol foo if foo would end up in the
binary anyway, or to zero if foo would not be in the binary.
For example:
int xxx = 1;
int yyy = 2;
int weak·xxx;
int weak·yyy;
Robert Griesemer [Thu, 24 Feb 2011 19:13:20 +0000 (11:13 -0800)]
godoc: fix writeFileAtomically utility function
If the filename was absolute, writeFileAtomically
used the wrong filename for ioutil.TempFile leading
to non-existent directories and the TempFile would
fail.
Russ Cox [Wed, 23 Feb 2011 20:51:20 +0000 (15:51 -0500)]
runtime: always run stackalloc on scheduler stack
Avoids deadlocks like the one below, in which a stack split happened
in order to call lock(&stacks), but then the stack unsplit cannot run
because stacks is now locked.
The only code calling stackalloc that wasn't on a scheduler
stack already was malg, which creates a new goroutine.
Russ Cox [Wed, 23 Feb 2011 20:42:13 +0000 (15:42 -0500)]
runtime: omit breakpoint during terminal panic
A terminal panic (one that prints a stack trace and exits)
has been calling runtime.breakpoint before calling exit,
so that if running under a debugger, the debugger can
take control. When not running under a debugger, though,
this causes an additional SIGTRAP on Unix and pop-up
dialogs on Windows.
Support for debugging Go programs has gotten good
enough that we can rely on the debugger to set its own
breakpoint on runtime.exit if it wants to look around.
Brad Fitzpatrick [Wed, 23 Feb 2011 20:20:50 +0000 (12:20 -0800)]
http: introduce start of Client and ClientTransport
Much yet to come, but this is a safe first step, introducing
an in-the-future configurable Client object (where policy for
cookies, auth, redirects will live) as well as introducing a
ClientTransport interface for sending requests.
The CL intentionally ignores everything around the creation
and configuration of Clients and merely ports/wraps the old
interfaces to/around Client/ClientTransport.
Russ Cox [Wed, 23 Feb 2011 19:47:42 +0000 (14:47 -0500)]
runtime: pass to signal handler value of g at time of signal
The existing code assumed that signals only arrived
while executing on the goroutine stack (g == m->curg),
not while executing on the scheduler stack (g == m->g0).
Most of the signal handling trampolines correctly saved
and restored g already, but the sighandler C code did not
have access to it.
Some rewriting of assembly to make the various
implementations as similar as possible.
Will need to change Windows too but I don't
understand how sigtramp gets called there.
Russ Cox [Wed, 23 Feb 2011 19:47:22 +0000 (14:47 -0500)]
runtime: traceback through active lessstack
With this change, a panic trace due to a signal arriving while
running on the scheduler stack during a lessstack
(a stack unsplit) will trace through the lessstack to show
the state of the goroutine that was unsplitting its stack.
Russ Cox [Wed, 23 Feb 2011 18:21:39 +0000 (13:21 -0500)]
5g: fix optimizer bug
same as in issue below, never fixed on ARM
changeset: 5498:3fa1372ca694
user: Ken Thompson <ken@golang.org>
date: Thu May 20 17:31:28 2010 -0700
description:
fix issue 798
cannot allocate an audomatic temp
while real registers are allocated.
there is a chance that the automatic
will be allocated to one of the
allocated registers. the fix is to
not registerize such variables.
Rob Pike [Wed, 23 Feb 2011 17:49:35 +0000 (09:49 -0800)]
gob: protect against pure recursive types.
There are further changes required for things like
recursive map types. Recursive struct types work
but the mechanism needs generalization. The
case handled in this CL is pathological since it
cannot be represented at all by gob, so it should
be handled separately. (Prior to this CL, encode
would recur forever.)
Gustavo Niemeyer [Wed, 23 Feb 2011 16:48:40 +0000 (11:48 -0500)]
codereview: fix clpatch with empty diffs
Avoid passing the placeholder diff to hgpatch, so that
clpatch-ing an empty diff grabs the metadata and warns
about it being empty, rather than failing with a
hard-to-debug problem ("mkdir: no such file or dir",
no metadata, etc).