Skip to content

Commit 20850fc

Browse files
committed
Package unsafe is undocumented. By installing (but not compiling) this file,
which contains only declarations, we can have godoc present documentation for the package. R=gri,rsc DELTA=44 (43 added, 0 deleted, 1 changed) OCL=28555 CL=28588
1 parent 4f21161 commit 20850fc

File tree

1 file changed

+44
-0
lines changed

1 file changed

+44
-0
lines changed

src/lib/unsafe/unsafe.go

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
// Copyright 2009 The Go Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style
3+
// license that can be found in the LICENSE file.
4+
5+
/*
6+
The unsafe package contains operations that step around the type safety of Go programs.
7+
*/
8+
package unsafe
9+
10+
// ArbitraryType is here for the purposes of documentation only and is not actually
11+
// part of the unsafe package. It represents the type of an arbitrary Go expression.
12+
type ArbitraryType int
13+
14+
// Pointer represents a pointer to an arbitrary type. There are three special operations
15+
// available for type Pointer that are not available for other types.
16+
// 1) A pointer value of any type can be converted to a Pointer.
17+
// 2) A uintptr can be converted to a Pointer.
18+
// 3) A Pointer can be converted to a uintptr.
19+
// Pointer therefore allows a program to defeat the type system and read and write
20+
// arbitrary memory. It should be used with extreme care.
21+
type Pointer *ArbitraryType
22+
23+
// Sizeof returns the size in bytes occupied by the value v. The size is that of the
24+
// "top level" of the value only. For instance, if v is a slice, it returns the size of
25+
// the slice descriptor, not the size of the memory referenced by the slice.
26+
func Sizeof(v ArbitraryType) int
27+
28+
// Offsetof returns the offset within the struct of the field represented by v,
29+
// which must be of the form struct_value.field. In other words, it returns the
30+
// number of bytes between the start of the struct and the start of the field.
31+
func Offsetof(v ArbitraryType) int
32+
33+
// Alignof returns the alignment of the value v. It is the minimum value m such
34+
// that the address of a variable with the type of v will always always be zero mod m.
35+
// If v is of the form obj.f, it returns the alignment of field f within struct object obj.
36+
func Alignof(v ArbitraryType) int
37+
38+
// Reflect unpacks an interface value into its internal value word and its type string.
39+
// The boolean indir is true if the value is a pointer to the real value.
40+
func Reflect(i interface {}) (value uint64, typestring string, indir bool)
41+
42+
// Unreflect inverts Reflect: Given a value word, a type string, and the indirect bit,
43+
// it returns an empty interface value with those contents.
44+
func Unreflect(value uint64, typestring string, indir bool) (ret interface {})

0 commit comments

Comments
 (0)