Debian Codegraph @

internal/spew/testdata/dumpcgo.go

raw
1 // Copyright (c) 2013 Dave Collins <[email protected]>
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
25 //go:build cgo && testcgo
26 // +build cgo,testcgo
27
28 package testdata
29
30 /*
31 #include <stdint.h>
32 typedef unsigned char custom_uchar_t;
33
34 char *ncp = 0;
35 char *cp = "test";
36 char ca[6] = {'t', 'e', 's', 't', '2', '\0'};
37 unsigned char uca[6] = {'t', 'e', 's', 't', '3', '\0'};
38 signed char sca[6] = {'t', 'e', 's', 't', '4', '\0'};
39 uint8_t ui8ta[6] = {'t', 'e', 's', 't', '5', '\0'};
40 custom_uchar_t tuca[6] = {'t', 'e', 's', 't', '6', '\0'};
41 */
42 import "C"
43
44 // GetCgoNullCharPointer returns a null char pointer via cgo. This is only
45 // used for tests.
46 func GetCgoNullCharPointer() any {
47 return C.ncp
48 }
49
50 // GetCgoCharPointer returns a char pointer via cgo. This is only used for
51 // tests.
52 func GetCgoCharPointer() any {
53 return C.cp
54 }
55
56 // GetCgoCharArray returns a char array via cgo and the array's len and cap.
57 // This is only used for tests.
58 func GetCgoCharArray() (any, int) {
59 return C.ca, len(C.ca)
60 }
61
62 // GetCgoUnsignedCharArray returns an unsigned char array via cgo and the
63 // array's len and cap. This is only used for tests.
64 func GetCgoUnsignedCharArray() (any, int) {
65 return C.uca, len(C.uca)
66 }
67
68 // GetCgoSignedCharArray returns a signed char array via cgo and the array's len
69 // and cap. This is only used for tests.
70 func GetCgoSignedCharArray() (any, int) {
71 return C.sca, len(C.sca)
72 }
73
74 // GetCgoUint8tArray returns a uint8_t array via cgo and the array's len and
75 // cap. This is only used for tests.
76 func GetCgoUint8tArray() (any, int) {
77 return C.ui8ta, len(C.ui8ta)
78 }
79
80 // GetCgoTypdefedUnsignedCharArray returns a typedefed unsigned char array via
81 // cgo and the array's len and cap. This is only used for tests.
82 func GetCgoTypdefedUnsignedCharArray() (any, int) {
83 return C.tuca, len(C.tuca)
84 }