genbindings: detect argcargv pattern at any location

This commit is contained in:
mappu 2024-08-18 15:57:29 +12:00
parent 2a93cbf2d3
commit 148d8ea6e0
2 changed files with 12 additions and 9 deletions

View File

@ -113,7 +113,7 @@ func emitParametersGo(params []CppParameter) string {
for i, p := range params {
if i == 0 && IsArgcArgv(params) {
if IsArgcArgv(params, i) {
skipNext = true
tmp = append(tmp, "args []string")
@ -140,7 +140,7 @@ func emitParametersGo2CABIForwarding(m CppMethod) (preamble string, fowarding st
for i, p := range m.Parameters {
if i == 0 && IsArgcArgv(m.Parameters) {
if IsArgcArgv(m.Parameters, i) {
skipNext = true
// QApplication constructor. Convert 'args' into Qt's wanted types
// Qt has a warning in the docs saying these pointers must be valid

View File

@ -70,14 +70,17 @@ type CppMethod struct {
IsSignal bool
}
func IsArgcArgv(params []CppParameter) bool {
func IsArgcArgv(params []CppParameter, pos int) bool {
// Check if the arguments starting at position=pos are the argc/argv pattern.
// QApplication/QGuiApplication constructors are the only expected example of this.
return (len(params) > 1 &&
params[0].ParameterName == "argc" &&
params[0].ParameterType == "int" &&
params[0].ByRef &&
params[1].ParameterName == "argv" &&
params[1].ParameterType == "char **")
return (len(params) > pos+1 &&
params[pos].ParameterName == "argc" &&
params[pos].ParameterType == "int" &&
params[pos].ByRef &&
params[pos+1].ParameterName == "argv" &&
params[pos+1].ParameterType == "char **")
}
}
func (nm CppMethod) SafeMethodName() string {