mirror of
https://github.com/tinygo-org/tinygo.git
synced 2026-07-28 15:48:40 +00:00
b7a3fd8d2f
Here is the proposal: https://github.com/golang/go/issues/56378 They are documented here: https://pkg.go.dev/cmd/cgo@master#hdr-Optimizing_calls_of_C_code This would have been very useful to fix https://github.com/tinygo-org/bluetooth/issues/176 in a nice way. That bug is now fixed in a different way using a wrapper function, but once this new noescape pragma gets included in TinyGo we could remove the workaround and use `#cgo noescape` instead.
68 lines
1.3 KiB
Go
68 lines
1.3 KiB
Go
package main
|
|
|
|
/*
|
|
#warning some warning
|
|
|
|
typedef struct {
|
|
int x;
|
|
int y;
|
|
} point_t;
|
|
|
|
typedef someType noType; // undefined type
|
|
|
|
// Some invalid noescape lines
|
|
#cgo noescape
|
|
#cgo noescape foo bar
|
|
#cgo noescape unusedFunction
|
|
|
|
#define SOME_CONST_1 5) // invalid const syntax
|
|
#define SOME_CONST_2 6) // const not used (so no error)
|
|
#define SOME_CONST_3 1234 // const too large for byte
|
|
#define SOME_CONST_b 3 ) // const with lots of weird whitespace (to test error locations)
|
|
# define SOME_CONST_startspace 3)
|
|
*/
|
|
//
|
|
//
|
|
// #define SOME_CONST_4 8) // after some empty lines
|
|
// #cgo CFLAGS: -DSOME_PARAM_CONST_invalid=3/+3
|
|
// #cgo CFLAGS: -DSOME_PARAM_CONST_valid=3+4
|
|
import "C"
|
|
|
|
// #warning another warning
|
|
import "C"
|
|
|
|
// #define add(a, b) (a+b)
|
|
// #define add_toomuch add(1, 2, 3)
|
|
// #define add_toolittle add(1)
|
|
import "C"
|
|
|
|
// Make sure that errors for the following lines won't change with future
|
|
// additions to the CGo preamble.
|
|
//
|
|
//line errors.go:100
|
|
var (
|
|
// constant too large
|
|
_ C.char = 2 << 10
|
|
|
|
// z member does not exist
|
|
_ C.point_t = C.point_t{z: 3}
|
|
|
|
// constant has syntax error
|
|
_ = C.SOME_CONST_1
|
|
|
|
_ byte = C.SOME_CONST_3
|
|
|
|
_ = C.SOME_CONST_4
|
|
|
|
_ = C.SOME_CONST_b
|
|
|
|
_ = C.SOME_CONST_startspace
|
|
|
|
// constants passed by a command line parameter
|
|
_ = C.SOME_PARAM_CONST_invalid
|
|
_ = C.SOME_PARAM_CONST_valid
|
|
|
|
_ = C.add_toomuch
|
|
_ = C.add_toolittle
|
|
)
|