mirror of
https://github.com/mappu/miqt.git
synced 2025-01-04 22:58:37 +00:00
genbindings: marshal cgo.Handle via intptr_t instead of void*
This commit is contained in:
parent
0e705a4e6e
commit
0154e3507b
@ -546,7 +546,7 @@ extern "C" {
|
|||||||
ret.WriteString(fmt.Sprintf("%s %s_%s(%s);\n", m.ReturnType.RenderTypeCabi(), cClassName, m.SafeMethodName(), emitParametersCabi(m, ifv(m.IsConst, "const ", "")+cClassName+"*")))
|
ret.WriteString(fmt.Sprintf("%s %s_%s(%s);\n", m.ReturnType.RenderTypeCabi(), cClassName, m.SafeMethodName(), emitParametersCabi(m, ifv(m.IsConst, "const ", "")+cClassName+"*")))
|
||||||
|
|
||||||
if m.IsSignal {
|
if m.IsSignal {
|
||||||
ret.WriteString(fmt.Sprintf("%s %s_connect_%s(%s* self, void* slot);\n", m.ReturnType.RenderTypeCabi(), cClassName, m.SafeMethodName(), cClassName))
|
ret.WriteString(fmt.Sprintf("%s %s_connect_%s(%s* self, intptr_t slot);\n", m.ReturnType.RenderTypeCabi(), cClassName, m.SafeMethodName(), cClassName))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -691,7 +691,7 @@ func emitBindingCpp(src *CppParsedHeader, filename string) (string, error) {
|
|||||||
exactSignal := `static_cast<void (` + c.ClassName + `::*)(` + emitParameterTypesCpp(m, true) + `)` + ifv(m.IsConst, ` const`, ``) + `>(&` + c.ClassName + `::` + m.CppCallTarget() + `)`
|
exactSignal := `static_cast<void (` + c.ClassName + `::*)(` + emitParameterTypesCpp(m, true) + `)` + ifv(m.IsConst, ` const`, ``) + `>(&` + c.ClassName + `::` + m.CppCallTarget() + `)`
|
||||||
|
|
||||||
paramArgs := []string{"slot"}
|
paramArgs := []string{"slot"}
|
||||||
paramArgDefs := []string{"void* cb"}
|
paramArgDefs := []string{"intptr_t cb"}
|
||||||
|
|
||||||
var signalCode string
|
var signalCode string
|
||||||
|
|
||||||
@ -704,7 +704,7 @@ func emitBindingCpp(src *CppParsedHeader, filename string) (string, error) {
|
|||||||
signalCode += "\t\t" + bindingFunc + "(" + strings.Join(paramArgs, `, `) + ");\n"
|
signalCode += "\t\t" + bindingFunc + "(" + strings.Join(paramArgs, `, `) + ");\n"
|
||||||
|
|
||||||
ret.WriteString(
|
ret.WriteString(
|
||||||
`void ` + cClassName + `_connect_` + m.SafeMethodName() + `(` + cClassName + `* self, void* slot) {` + "\n" +
|
`void ` + cClassName + `_connect_` + m.SafeMethodName() + `(` + cClassName + `* self, intptr_t slot) {` + "\n" +
|
||||||
"\t" + c.ClassName + `::connect(self, ` + exactSignal + `, self, [=](` + emitParametersCpp(m) + `) {` + "\n" +
|
"\t" + c.ClassName + `::connect(self, ` + exactSignal + `, self, [=](` + emitParametersCpp(m) + `) {` + "\n" +
|
||||||
signalCode +
|
signalCode +
|
||||||
"\t});\n" +
|
"\t});\n" +
|
||||||
|
@ -612,12 +612,12 @@ import "C"
|
|||||||
}
|
}
|
||||||
|
|
||||||
ret.WriteString(`func (this *` + goClassName + `) On` + m.SafeMethodName() + `(slot func(` + emitParametersGo(m.Parameters) + `)) {
|
ret.WriteString(`func (this *` + goClassName + `) On` + m.SafeMethodName() + `(slot func(` + emitParametersGo(m.Parameters) + `)) {
|
||||||
C.` + goClassName + `_connect_` + m.SafeMethodName() + `(this.h, unsafe.Pointer(uintptr(cgo.NewHandle(slot))))
|
C.` + goClassName + `_connect_` + m.SafeMethodName() + `(this.h, C.intptr_t(cgo.NewHandle(slot)) )
|
||||||
}
|
}
|
||||||
|
|
||||||
//export miqt_exec_callback_` + goClassName + `_` + m.SafeMethodName() + `
|
//export miqt_exec_callback_` + goClassName + `_` + m.SafeMethodName() + `
|
||||||
func miqt_exec_callback_` + goClassName + `_` + m.SafeMethodName() + `(cb *C.void` + ifv(len(m.Parameters) > 0, ", ", "") + strings.Join(cgoNamedParams, `, `) + `) {
|
func miqt_exec_callback_` + goClassName + `_` + m.SafeMethodName() + `(cb C.intptr_t` + ifv(len(m.Parameters) > 0, ", ", "") + strings.Join(cgoNamedParams, `, `) + `) {
|
||||||
gofunc, ok := (cgo.Handle(uintptr(unsafe.Pointer(cb))).Value()).(func(` + emitParametersGo(m.Parameters) + `))
|
gofunc, ok := cgo.Handle(cb).Value().(func(` + emitParametersGo(m.Parameters) + `))
|
||||||
if !ok {
|
if !ok {
|
||||||
panic("miqt: callback of non-callback type (heap corruption?)")
|
panic("miqt: callback of non-callback type (heap corruption?)")
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user