diff --git a/dumper.go b/dumper.go index 28352b8..8e7d640 100644 --- a/dumper.go +++ b/dumper.go @@ -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()))) } } diff --git a/dumper_test.go b/dumper_test.go index 0fa57e6..6bdac40 100644 --- a/dumper_test.go +++ b/dumper_test.go @@ -5,9 +5,11 @@ import ( "os" "reflect" "testing" + "unsafe" ) func TestCanDumpPrimitives(t *testing.T) { + type IntType int type Int8Type int8 type Int16Type int16 @@ -181,6 +183,9 @@ func TestCanDumpPrimitives(t *testing.T) { PtrTypedChan *ChanType PtrTypedChan1 *Chan1Type PtrTypedChan2 *Chan2Type + + UnsafePointer1 unsafe.Pointer + UnsafePointer2 *unsafe.Pointer } node := Node{ @@ -221,6 +226,8 @@ func TestCanDumpPrimitives(t *testing.T) { TypedString: StringType("foo bar"), Nil: nil, + + UnsafePointer1: nil, } node.IntPtr = &node.Int @@ -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)) diff --git a/testdata/primitives.txt b/testdata/primitives.txt index 681c0b5..9bb3b88 100644 --- a/testdata/primitives.txt +++ b/testdata/primitives.txt @@ -113,4 +113,6 @@ godump.Node { PtrTypedChan: &godump.ChanType, PtrTypedChan1: &godump.Chan1Type, PtrTypedChan2: &godump.Chan2Type, + UnsafePointer1: unsafe.Pointer(), + UnsafePointer2: &unsafe.Pointer(0x7b), } \ No newline at end of file