Fork of events package with fixes for Illumos

event_unsafe.go 730B

123456789101112131415161718192021222324252627282930
  1. // +build go1.5
  2. package events
  3. import (
  4. "reflect"
  5. "unsafe"
  6. )
  7. func cloneValue(v interface{}) interface{} {
  8. // Some sub-packages use optimizations that hack the type system by sharing
  9. // pointers to avoid generated calls to runtime.convT2E, this functions
  10. // basically does the opposite and ensures that a new value is created.
  11. rv := reflect.ValueOf(v)
  12. nv := reflect.New(rv.Type()).Elem()
  13. nv.Set(rv)
  14. return nv.Interface()
  15. }
  16. func bytesToString(b []byte) string {
  17. // The conversion of a byte slice ot a string is ensured not to cause a
  18. // dynamic memory allocation.
  19. if len(b) == 0 {
  20. return ""
  21. }
  22. return *(*string)(unsafe.Pointer(&reflect.StringHeader{
  23. Data: uintptr(unsafe.Pointer(&b[0])),
  24. Len: len(b),
  25. }))
  26. }