From d5eeb64c865b82ac46107e6aa1116b21c4c4426f Mon Sep 17 00:00:00 2001 From: mappu Date: Sun, 18 Aug 2024 18:55:28 +1200 Subject: [PATCH] genbindings/connect: only generate connect() stubs for the fully expanded overload --- cmd/genbindings/emitcabi.go | 4 ++-- cmd/genbindings/emitgo.go | 2 +- cmd/genbindings/intermediate.go | 1 + cmd/genbindings/transformoptional.go | 2 ++ 4 files changed, 6 insertions(+), 3 deletions(-) diff --git a/cmd/genbindings/emitcabi.go b/cmd/genbindings/emitcabi.go index 6e8a63f2..a4608c63 100644 --- a/cmd/genbindings/emitcabi.go +++ b/cmd/genbindings/emitcabi.go @@ -386,7 +386,7 @@ extern "C" { for _, m := range c.Methods { ret.WriteString(fmt.Sprintf("%s %s_%s(%s);\n", emitReturnTypeCabi(m.ReturnType), c.ClassName, m.SafeMethodName(), emitParametersCabi(m, c.ClassName+"*"))) - if m.IsSignal { + if m.IsSignal && !m.HasHiddenParams { ret.WriteString(fmt.Sprintf("%s %s_connect_%s(void* slot);\n", emitReturnTypeCabi(m.ReturnType), c.ClassName, m.SafeMethodName())) } } @@ -550,7 +550,7 @@ extern "C" { afterCall, )) - if m.IsSignal { + if m.IsSignal && !m.HasHiddenParams { exactSignal := `static_cast(&` + c.ClassName + `::` + nativeMethodName + `)` ret.WriteString( diff --git a/cmd/genbindings/emitgo.go b/cmd/genbindings/emitgo.go index edceccfe..ff12c294 100644 --- a/cmd/genbindings/emitgo.go +++ b/cmd/genbindings/emitgo.go @@ -376,7 +376,7 @@ import "C" `) // Add Connect() wrappers for signal functions - if m.IsSignal { + if m.IsSignal && !m.HasHiddenParams { imports["unsafe"] = struct{}{} imports["runtime/cgo"] = struct{}{} ret.WriteString(`func (this *` + c.ClassName + `) On` + m.SafeMethodName() + `(slot func()) { diff --git a/cmd/genbindings/intermediate.go b/cmd/genbindings/intermediate.go index 4b8c5c29..dcd59651 100644 --- a/cmd/genbindings/intermediate.go +++ b/cmd/genbindings/intermediate.go @@ -68,6 +68,7 @@ type CppMethod struct { Parameters []CppParameter IsStatic bool IsSignal bool + HasHiddenParams bool // Set to true if there is an overload with more parameters } func IsArgcArgv(params []CppParameter, pos int) bool { diff --git a/cmd/genbindings/transformoptional.go b/cmd/genbindings/transformoptional.go index 5d5d868b..3cf1800c 100644 --- a/cmd/genbindings/transformoptional.go +++ b/cmd/genbindings/transformoptional.go @@ -35,6 +35,7 @@ func astTransformOptional(parsed *CppParsedHeader) { Parameters: nil, IsSignal: m.IsSignal, IsStatic: m.IsStatic, + HasHiddenParams: (x != len(m.Parameters)-1), } dupMethod.Parameters = append(dupMethod.Parameters, m.Parameters[0:x+1]...) c.Methods = append(c.Methods, dupMethod) // TODO can we insert them next, instead of at the end? @@ -43,6 +44,7 @@ func astTransformOptional(parsed *CppParsedHeader) { // Truncate the original method's parameters to only the // mandatory ones m.Parameters = m.Parameters[0:optionalStart] + m.HasHiddenParams = true c.Methods[j] = m }