dumpcgo.go 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. // Copyright (c) 2013 Dave Collins <dave@davec.name>
  2. //
  3. // Permission to use, copy, modify, and distribute this software for any
  4. // purpose with or without fee is hereby granted, provided that the above
  5. // copyright notice and this permission notice appear in all copies.
  6. //
  7. // THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
  8. // WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
  9. // MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
  10. // ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  11. // WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
  12. // ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
  13. // OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  14. // NOTE: Due to the following build constraints, this file will only be compiled
  15. // when both cgo is supported and "-tags testcgo" is added to the go test
  16. // command line. This code should really only be in the dumpcgo_test.go file,
  17. // but unfortunately Go will not allow cgo in test files, so this is a
  18. // workaround to allow cgo types to be tested. This configuration is used
  19. // because spew itself does not require cgo to run even though it does handle
  20. // certain cgo types specially. Rather than forcing all clients to require cgo
  21. // and an external C compiler just to run the tests, this scheme makes them
  22. // optional.
  23. // +build cgo,testcgo
  24. package testdata
  25. /*
  26. #include <stdint.h>
  27. typedef unsigned char custom_uchar_t;
  28. char *ncp = 0;
  29. char *cp = "test";
  30. char ca[6] = {'t', 'e', 's', 't', '2', '\0'};
  31. unsigned char uca[6] = {'t', 'e', 's', 't', '3', '\0'};
  32. signed char sca[6] = {'t', 'e', 's', 't', '4', '\0'};
  33. uint8_t ui8ta[6] = {'t', 'e', 's', 't', '5', '\0'};
  34. custom_uchar_t tuca[6] = {'t', 'e', 's', 't', '6', '\0'};
  35. */
  36. import "C"
  37. // GetCgoNullCharPointer returns a null char pointer via cgo. This is only
  38. // used for tests.
  39. func GetCgoNullCharPointer() interface{} {
  40. return C.ncp
  41. }
  42. // GetCgoCharPointer returns a char pointer via cgo. This is only used for
  43. // tests.
  44. func GetCgoCharPointer() interface{} {
  45. return C.cp
  46. }
  47. // GetCgoCharArray returns a char array via cgo. This is only used for tests.
  48. func GetCgoCharArray() interface{} {
  49. return C.ca
  50. }
  51. // GetCgoUnsignedCharArray returns an unsigned char array via cgo. This is only
  52. // used for tests.
  53. func GetCgoUnsignedCharArray() interface{} {
  54. return C.uca
  55. }
  56. // GetCgoSignedCharArray returns a signed char array via cgo. This is only used
  57. // for tests.
  58. func GetCgoSignedCharArray() interface{} {
  59. return C.sca
  60. }
  61. // GetCgoUint8tArray returns a uint8_t array via cgo. This is only used for
  62. // tests.
  63. func GetCgoUint8tArray() interface{} {
  64. return C.ui8ta
  65. }
  66. // GetCgoTypdefedUnsignedCharArray returns a typedefed unsigned char array via
  67. // cgo. This is only used for tests.
  68. func GetCgoTypdefedUnsignedCharArray() interface{} {
  69. return C.tuca
  70. }