davecgh / go-spew

Implements a deep pretty printer for Go data structures to aid in debugging
ISC License
5.97k stars 361 forks source link

Better cgo support #11

Closed AlekSi closed 10 years ago

AlekSi commented 11 years ago

This can be made smaller:

 buf: ([1024]foo._Ctype_char) {
  (foo._Ctype_char) 115,
  (foo._Ctype_char) 100,
  (foo._Ctype_char) 102,
  (foo._Ctype_char) 115,
  (foo._Ctype_char) 100,
  (foo._Ctype_char) 102,
  (foo._Ctype_char) 115,
  (foo._Ctype_char) 100,
  (foo._Ctype_char) 102,
  (foo._Ctype_char) 115,
  (foo._Ctype_char) 0,
  (foo._Ctype_char) 0,
  (foo._Ctype_char) 0,
  ...
davecgh commented 11 years ago

This is a reasonable request. I haven't spent much time dealing with cgo types under reflection, so I'm not sure how much is possible, but I'll take a look.

davecgh commented 11 years ago

After looking into this a bit tonight, I see that C.char is considered signed as an int8 under reflection. As a result, the hexdump style functionality is bypassed since it only works with uint8.

There are a couple of ways to handle this. One way is to allow spew to hexdump int8 slices as well as uint8 slices, but I don't think that's really desirable for most cases. Another option that is a bit hackish is to look at the textual type (versus the reflected type) specifically to detect something like the pattern ^.*\._Ctype_char$ and hexdump it from there after a bit of casting.

Any thoughts?

AlekSi commented 11 years ago

I think looking for ^.*\._Ctype_char$ is okay if user is opted in for it.

davecgh commented 10 years ago

This feature, including new tests and an updated test coverage report has been implemented as of commit 1fe9f5ca4b46a8247ae5939097f5cfc5d8370729.