cbytes_go16_unix.go 330 B

12345678910111213141516171819202122
  1. // Copyright 2018 visualfc. All rights reserved.
  2. // +build !go1.7,!windows
  3. package interp
  4. import (
  5. "unsafe"
  6. )
  7. /*
  8. #include <stdlib.h>
  9. #include <string.h>
  10. */
  11. import "C"
  12. func toCBytes(data []byte) unsafe.Pointer {
  13. size := C.size_t(len(data))
  14. ptr := C.malloc(size)
  15. C.memcpy(ptr, unsafe.Pointer(&data[0]), size)
  16. return ptr
  17. }