Skip to content

Commit

Permalink
added unsafe.Pointer support
Browse files Browse the repository at this point in the history
  • Loading branch information
yassinebenaid committed Jun 11, 2024
1 parent bfa6c4f commit f9b3a07
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 0 deletions.
2 changes: 2 additions & 0 deletions dumper.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ func (d *dumper) dump(val reflect.Value, ignore_depth ...bool) {
d.write(d.theme.Nil.apply("nil"))
case reflect.Interface:
d.dump(val.Elem(), true)
case reflect.UnsafePointer:
d.write(d.theme.VarType.apply(fmt.Sprintf("unsafe.Pointer(%v)", val.UnsafePointer())))
}
}

Expand Down
9 changes: 9 additions & 0 deletions dumper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@ import (
"os"
"reflect"
"testing"
"unsafe"
)

func TestCanDumpPrimitives(t *testing.T) {

type IntType int
type Int8Type int8
type Int16Type int16
Expand Down Expand Up @@ -181,6 +183,9 @@ func TestCanDumpPrimitives(t *testing.T) {
PtrTypedChan *ChanType
PtrTypedChan1 *Chan1Type
PtrTypedChan2 *Chan2Type

UnsafePointer1 unsafe.Pointer
UnsafePointer2 *unsafe.Pointer
}

node := Node{
Expand Down Expand Up @@ -221,6 +226,8 @@ func TestCanDumpPrimitives(t *testing.T) {
TypedString: StringType("foo bar"),

Nil: nil,

UnsafePointer1: nil,
}

node.IntPtr = &node.Int
Expand Down Expand Up @@ -304,6 +311,8 @@ func TestCanDumpPrimitives(t *testing.T) {
node.PtrTypedChan1 = &tch1
node.PtrTypedChan2 = &tch2

node.UnsafePointer2 = (*unsafe.Pointer)(unsafe.Pointer(&node))

var d dumper
d.dump(reflect.ValueOf(node))

Expand Down
2 changes: 2 additions & 0 deletions testdata/primitives.txt
Original file line number Diff line number Diff line change
Expand Up @@ -113,4 +113,6 @@ godump.Node {
PtrTypedChan: &godump.ChanType,
PtrTypedChan1: &godump.Chan1Type,
PtrTypedChan2: &godump.Chan2Type,
UnsafePointer1: unsafe.Pointer(<nil>),
UnsafePointer2: &unsafe.Pointer(0x7b),
}

0 comments on commit f9b3a07

Please sign in to comment.