2024-08-18 05:48:17 +00:00
|
|
|
package qt
|
|
|
|
|
|
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
|
2024-08-18 07:02:32 +00:00
|
|
|
import (
|
|
|
|
"C"
|
2024-08-23 23:46:26 +00:00
|
|
|
"runtime/cgo"
|
|
|
|
"unsafe"
|
2024-08-18 07:02:32 +00:00
|
|
|
)
|
|
|
|
|
2024-08-18 05:48:17 +00:00
|
|
|
type miqtCallbackFunc func(argc C.int, args *C.void)
|
|
|
|
|
|
|
|
//export miqt_exec_callback
|
|
|
|
func miqt_exec_callback(cb *C.void, argc C.int, args *C.void) {
|
|
|
|
// Our CABI for all callbacks is void(int, void*).
|
|
|
|
// Our Go ABI is CallbackFunc
|
|
|
|
// Then the Go bindings can unmarshal the arguments and C.free() them as necessary
|
|
|
|
cfunc, ok := (cgo.Handle(uintptr(unsafe.Pointer(cb))).Value()).(miqtCallbackFunc)
|
|
|
|
if !ok {
|
|
|
|
panic("miqt: callback of non-callback type (heap corruption?)")
|
|
|
|
}
|
|
|
|
|
|
|
|
cfunc(argc, args)
|
|
|
|
}
|