]> Cypherpunks repositories - gostls13.git/commitdiff
doc/go1.3.html: add note about unsafe.Pointer strictness
authorRuss Cox <rsc@golang.org>
Thu, 15 May 2014 20:16:26 +0000 (16:16 -0400)
committerRuss Cox <rsc@golang.org>
Thu, 15 May 2014 20:16:26 +0000 (16:16 -0400)
The vet check is in CL 10470044.

LGTM=bradfitz, r
R=r, bradfitz
CC=golang-codereviews
https://golang.org/cl/91480044

doc/go1.3.html

index e13faa1b085c0d58d713c985384174e0064fca90..056c4cbe81af3b531c595d652cced3032e687b98 100644 (file)
@@ -117,6 +117,26 @@ This means that a non-pointer Go value such as an integer will never be mistaken
 pointer and prevent unused memory from being reclaimed.
 </p>
 
+<p>
+Starting with Go 1.3, the runtime assumes that values with pointer type
+contain pointers and other values do not.
+This assumption is fundamental to the precise behavior of both stack expansion
+and garbage collection.
+Programs that use <a href="/pkg/unsafe/">package unsafe</a>
+to store <code>uintptrs</code> in pointer values are illegal and will crash if the runtime detects the behavior.
+Programs that use <a href="/pkg/unsafe/">package unsafe</a> to store pointers
+in <code>uintptr</code> values are also illegal but more difficult to diagnose during execution.
+Because the pointers are hidden from the runtime, a stack expansion or garbage collection
+may reclaim the memory they point at, creating
+<a href="http://en.wikipedia.org/wiki/Dangling_pointer">dangling pointers</a>.
+</p>
+
+<p>
+<em>Updating</em>: Code that converts a <code>uintptr</code> value stored in memory
+to <code>unsafe.Pointer</code> is illegal and must be rewritten.
+Such code can be identified by <code>go vet</code>.
+</p>
+
 <h3 id="liblink">The linker</h3>
 
 <p>