mirror of
https://github.com/tinygo-org/tinygo.git
synced 2026-07-26 06:38:42 +00:00
cgo: fix calling CGo callback inside generic function
The package of the generic function might not be set, so we have to call Origin() for it. Found while porting mcufont to TinyGo.
This commit is contained in:
committed by
Ron Evans
parent
a40b11f535
commit
d0445d6f83
Vendored
+9
@@ -43,6 +43,7 @@ func main() {
|
||||
println("callback 1:", C.doCallback(20, 30, cb))
|
||||
cb = C.binop_t(C.mul)
|
||||
println("callback 2:", C.doCallback(20, 30, cb))
|
||||
genericCallbackCall[int]()
|
||||
|
||||
// variadic functions
|
||||
println("variadic0:", C.variadic0())
|
||||
@@ -197,3 +198,11 @@ func printBitfield(bitfield *C.bitfield_t) {
|
||||
println("bitfield d:", bitfield.d)
|
||||
println("bitfield e:", bitfield.e)
|
||||
}
|
||||
|
||||
type Int interface {
|
||||
int | uint
|
||||
}
|
||||
|
||||
func genericCallbackCall[T Int]() {
|
||||
println("callback inside generic function:", C.doCallback(20, 30, C.binop_t(C.add)))
|
||||
}
|
||||
|
||||
Vendored
+1
@@ -13,6 +13,7 @@ defined expr: 9
|
||||
25: 25
|
||||
callback 1: 50
|
||||
callback 2: 600
|
||||
callback inside generic function: 50
|
||||
variadic0: 1
|
||||
variadic2: 15
|
||||
headerfunc: 6
|
||||
|
||||
Reference in New Issue
Block a user