github.com/v2pro/plz@v0.0.0-20221028024117-e5f9aec5b631/test/go-spew/spew/testdata/dumpcgo.go (about) 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 15 // NOTE: Due to the following build constraints, this file will only be compiled 16 // when both cgo is supported and "-tags testcgo" is added to the go test 17 // command line. This code should really only be in the dumpcgo_test.go file, 18 // but unfortunately Go will not allow cgo in test files, so this is a 19 // workaround to allow cgo types to be tested. This configuration is used 20 // because spew itself does not require cgo to run even though it does handle 21 // certain cgo types specially. Rather than forcing all clients to require cgo 22 // and an external C compiler just to run the tests, this scheme makes them 23 // optional. 24 // +build cgo,testcgo 25 26 package testdata 27 28 /* 29 #include <stdint.h> 30 typedef unsigned char custom_uchar_t; 31 32 char *ncp = 0; 33 char *cp = "test"; 34 char ca[6] = {'t', 'e', 's', 't', '2', '\0'}; 35 unsigned char uca[6] = {'t', 'e', 's', 't', '3', '\0'}; 36 signed char sca[6] = {'t', 'e', 's', 't', '4', '\0'}; 37 uint8_t ui8ta[6] = {'t', 'e', 's', 't', '5', '\0'}; 38 custom_uchar_t tuca[6] = {'t', 'e', 's', 't', '6', '\0'}; 39 */ 40 import "C" 41 42 // GetCgoNullCharPointer returns a null char pointer via cgo. This is only 43 // used for tests. 44 func GetCgoNullCharPointer() interface{} { 45 return C.ncp 46 } 47 48 // GetCgoCharPointer returns a char pointer via cgo. This is only used for 49 // tests. 50 func GetCgoCharPointer() interface{} { 51 return C.cp 52 } 53 54 // GetCgoCharArray returns a char array via cgo and the array's len and cap. 55 // This is only used for tests. 56 func GetCgoCharArray() (interface{}, int, int) { 57 return C.ca, len(C.ca), cap(C.ca) 58 } 59 60 // GetCgoUnsignedCharArray returns an unsigned char array via cgo and the 61 // array's len and cap. This is only used for tests. 62 func GetCgoUnsignedCharArray() (interface{}, int, int) { 63 return C.uca, len(C.uca), cap(C.uca) 64 } 65 66 // GetCgoSignedCharArray returns a signed char array via cgo and the array's len 67 // and cap. This is only used for tests. 68 func GetCgoSignedCharArray() (interface{}, int, int) { 69 return C.sca, len(C.sca), cap(C.sca) 70 } 71 72 // GetCgoUint8tArray returns a uint8_t array via cgo and the array's len and 73 // cap. This is only used for tests. 74 func GetCgoUint8tArray() (interface{}, int, int) { 75 return C.ui8ta, len(C.ui8ta), cap(C.ui8ta) 76 } 77 78 // GetCgoTypdefedUnsignedCharArray returns a typedefed unsigned char array via 79 // cgo and the array's len and cap. This is only used for tests. 80 func GetCgoTypdefedUnsignedCharArray() (interface{}, int, int) { 81 return C.tuca, len(C.tuca), cap(C.tuca) 82 }