unsafeheader

package
v2.14.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 23, 2024 License: MIT Imports: 2 Imported by: 0

Documentation

Overview

Package unsafeheader contains header declarations copied from Go's runtime.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BytesToString

func BytesToString(b []byte) string

func SliceData added in v2.12.0

func SliceData[T any](slice []T) unsafe.Pointer

SliceData returns a pointer to the underlying array of the argument slice.

  • If len(slice) == 0, it returns nil.
  • Otherwise, it returns the underlying pointer.

func StringData added in v2.12.0

func StringData(str string) unsafe.Pointer

StringData returns a pointer to the underlying bytes of str.

  • If str == "", it returns nil.
  • Otherwise, it returns the underlying pointer.

func StringToBytes

func StringToBytes(s string) []byte

func ToRType added in v2.12.0

func ToRType(t reflect.Type) unsafe.Pointer

ToRType gets the underlying [*reflect.rtype] from a reflect.Type.

func ToReflectType added in v2.12.0

func ToReflectType(rtype unsafe.Pointer) reflect.Type

ToReflectType convert an [*reflect.rtype] pointer to a reflect.Type value. It is the reverse operation of ToRType.

Types

type Eface added in v2.12.0

type Eface struct {
	RType unsafe.Pointer // *rtype
	Word  unsafe.Pointer // data pointer
}

Eface is the header for an empty interface{} value. It is a copy type of [runtime.eface].

func ToEface added in v2.12.0

func ToEface(ep *any) Eface

ToEface casts an empty interface{} value to an Eface value.

type Iface added in v2.12.0

type Iface struct {
	Tab  unsafe.Pointer // *itab
	Data unsafe.Pointer
}

Iface is the header of a non-empty interface value. It is a copy type of [runtime.iface].

func ToIface added in v2.12.0

func ToIface(t reflect.Type) Iface

ToIface casts a reflect.Type to an Iface value.

type SliceHeader added in v2.12.0

type SliceHeader struct {
	Data unsafe.Pointer
	Len  int
	Cap  int
}

SliceHeader is the runtime representation of a slice.

Unlike reflect.SliceHeader, its Data field is sufficient to guarantee the data it references will not be garbage collected.

type StringHeader added in v2.12.0

type StringHeader struct {
	Data unsafe.Pointer
	Len  int
}

StringHeader is the runtime representation of a string.

Unlike reflect.StringHeader, its Data field is sufficient to guarantee the data it references will not be garbage collected.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL