Categorygithub.com/ii64/go-unsafe
repositorypackage
0.0.1
Repository: https://github.com/ii64/go-unsafe.git
Documentation: pkg.go.dev

# README

go-unsafe

Runtime interface type cast (and modification?)

since compiled types are live on binary .rodata, it is not writable*, we need to rebuild the type on runtime, calculate the hashcode (fnv1), assign methods etc etc.

interface represents:

  • rtype ptr, where used as type reference.
  • word/ptr data, where used as reference to data.

interface method implementation (dict.type|interface):

  • another rtype, contains functions/methods coresponding to itab.
  • referencing primitive type on (*rtype).ptrdata.

runtime inspect type modification:

  • example

generic pointer casting/reinterpretation:

  • example:
    var (
        a = new(uint64)
        b *int64
    )
    CastPtr(&b, a)
    
    var a = new(uint64)
    b := ReinterpretPtr[int64](a) // b *int64
    
    or if you wish to
    b := ReinterpretPtr[uint64](0x600000) // *uint64