weekly.2011-06-23

173 views
Skip to first unread message

Andrew Gerrand

unread,
Jun 24, 2011, 2:30:53 AM6/24/11
to golang-nuts
We've just tagged a new Go weekly, weekly.2011-06-23. As usual, you
can update by running:
hg pull
hg update weekly

This release includes a language change that restricts the use of goto.
In essence, a "goto" statement outside a block cannot jump to a label inside
that block. Your code may require changes if it uses goto.
This changeset shows how the new rule affected the Go tree:
http://code.google.com/p/go/source/detail?r=dc6d3cf9279d

The os.ErrorString type has been hidden. If your code uses os.ErrorString it
must be changed. Most uses of os.ErrorString can be replaced with os.NewError.

Other changes:
* 5c: do not use R9 and R10.
* 8l: more fixes for Plan 9 (thanks Lucio De Re).
* build: Make.ccmd: link with mach lib (thanks Joe Poirier).
* build: exclude packages that fail on Plan 9 (thanks Anthony Martin).
* cc: nit: silence comment warnings (thanks Dave Cheney).
* codereview.py: note that hg change -d abandons a change list (thanks
Robert Hencke).
* crypto/openpgp: add ElGamal support.
* doc/faq: add question about converting from []T to []interface{}.
* doc: Effective Go: fix variadic function example (thanks Ben Lynn).
* exec: LookPath should not search %PATH% for files like c:cmd.exe
(thanks Alex Brainman),
add support for Plan 9 (thanks Anthony Martin),
better error message for windows LookPath (thanks Alex Brainman).
* fmt: catch panics from calls to String etc.
* gc: descriptive panic for nil pointer -> value method call,
implement goto restriction,
unsafe.Alignof, unsafe.Offsetof, unsafe.Sizeof now return uintptr.
* go/build: include Import objects in Script Inputs.
* godefs: rudimentary tests (thanks Robert Hencke).
* goinstall: refactor and generalize repo handling code (thanks Julian
Phillips),
temporarily use Makefiles by default (override with -make=false).
* gopprof: update list of memory allocators.
* http: add Server.ListenAndServeTLS,
buffer request.Write,
fix req.Cookie(name) with cookies in one header,
permit handlers to explicitly remove the Date header,
write Header keys with empty values.
* image: basic test for the 16-bits-per-color-channel types.
* io: clarify Read, ReadAt, Copy, Copyn EOF behavior.
* ld: don't attempt to build dynamic sections unnecessarily (thanks
Gustavo Niemeyer).
* libmach: fix disassembly of FCMOVcc and FCOMI (thanks Anthony Martin),
fix tracing on linux (for cov) (thanks Anthony Martin).
* mime: fix RFC references (thanks Pascal S. de Kloe).
* misc/gobuilder: run make single-threaded on windows (thanks Alex Brainman).
* misc/godashboard: Accept sub-directories for goinstall's report
(thanks Yasuhiro Matsumoto).
* nacl, tiny: remove vestiges (thanks Robert Hencke).
* net, syscall: interface for windows (thanks Yasuhiro Matsumoto).
* os: change Waitmsg String method to use pointer receiver (thanks
Graham Miller).
* runtime: don't use twice the memory with grsec-like kernels (thanks
Gustavo Niemeyer),
* spec: disallow goto into blocks.
* sync: restore GOMAXPROCS during benchmarks.
* syscall: add LSF support for linux (thanks Mikio Hara),
add socket control message support for darwin, freebsd, linux
(thanks Mikio Hara),
add tty support to StartProcess (thanks Ken Rockot),
fix build for Sizeof change.
* test: test of goto restrictions.
* time: add support for Plan 9 (thanks Anthony Martin).

Apologies if we missed anyone in the list above. We appreciate all your help.

To see a full list of changes between this and the previous weekly,
after updating, run:
hg log -r weekly.2011-06-16:weekly.2011-06-23

Enjoy.

Andrew

Steven Blenkinsop

unread,
Jun 24, 2011, 11:29:20 AM6/24/11
to Andrew Gerrand, golang-nuts
On Fri, Jun 24, 2011 at 2:30 AM, Andrew Gerrand <a...@google.com> wrote:
This release includes a language change that restricts the use of goto.
In essence, a "goto" statement outside a block cannot jump to a label inside
that block. Your code may require changes if it uses goto.
This changeset shows how the new rule affected the Go tree:
       http://code.google.com/p/go/source/detail?r=dc6d3cf9279d

Its unfortunate that you can no longer jump between cases in a switch. Common code now has to be pulled out of the switch (oddly making code more spaghetti-like) or copied and pasted, or else each case has to be guarded with an if statement so you can safely fall through them.

It's interesting that in the Go tree, the offending labels were mostly for 1 liners that could be copied, or error cases that didn't need the locality (there were a couple that were eliminated by some other refactoring, but that wasn't the general case). I was actually a bit surprised by some of the situations that got eliminated, where goto was teleporting you into some random if statement. By eliminating this code, then, it looks like the change was net benefit.

Ostsol

unread,
Jun 24, 2011, 9:14:19 PM6/24/11
to golan...@googlegroups.com, Andrew Gerrand
On Friday, 24 June 2011 09:29:20 UTC-6, Steven Blenkinsop wrote:

Its unfortunate that you can no longer jump between cases in a switch.

I didn't even know that each clause in a switch statement was an implicit block until now. There have been occasions in the past where I've explicitly created a new {} block in C switch statements just to keep local variable scope as narrow as possible (and avoid other C case oddities).

-Daniel

John Asmuth

unread,
Jun 24, 2011, 9:17:07 PM6/24/11
to golan...@googlegroups.com, Andrew Gerrand
I think it's so that type switching can work as it does...

switch x := y.(type) {
case A:
  //here x is of type A
case B:
  //here x is of type B
}

Steven Blenkinsop

unread,
Jun 24, 2011, 9:53:09 PM6/24/11
to golan...@googlegroups.com
And just generally for a normal switch:

switch {
case A:
     var x int
     // do something with x
case B:
     // x is not defined here
}

John Asmuth

unread,
Jun 24, 2011, 10:11:37 PM6/24/11
to golan...@googlegroups.com
Is this the case in C/C++ or java?

My point was that your case might be a side effect of the rules making my case possible.

Steven Blenkinsop

unread,
Jun 25, 2011, 12:32:42 AM6/25/11
to golan...@googlegroups.com
On Friday, June 24, 2011, John Asmuth <jas...@gmail.com> wrote:
> Is this the case in C/C++ or java?

Had to check. And no. In C/C++ and Java, switch cases are just labels
that get transferred to conditionally by the switch statement. It's an
error to declare the same variable in different cases. In C, that
means it's probably a bad idea to declare a variable inside a case. C
gives you a weird error if a declaration is the labelled statement.
In C++, it's an error (at least in my compiler) to have another case
after a declaration. You have to declare variables in a nested block,
or before any of the cases, where they will be declared but not
initialized.

Java's more forgiving and declares the variables in switch scope but
doesn't initialize them unless you actually execute that statement (at
least as far as I can tell from the test code). I'm not sure if its
actually safe, but it seems to work.

Yeah. They're a mess. This is why I like Go.

> My point was that your case might be a side effect of the rules making my case possible.

Could be. It could also be that the behavior of switches in C/C++ (and
Java) was just too confusing (and error prone), and was fixed.

Reply all
Reply to author
Forward
0 new messages