|
| 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