fix(gir): consolidate callback wrapper logic and prevent namespace prefixing of builtin types
- commit
- 98b19e958b5cf9c79bcd810175eef320e39721a1
- author
- brice · · 2025-12-12 06:19 UTC
- parent
- b4abf4e
- signature
- unsigned
2 files · +32 -90
M internal/gir/util/util.go +32 -0
| @@ -93,15 +93,47 @@ func AddNamespace(val, ns string) string { | |||
| 93 | 93 | if ns == "" || strings.Count(val, ".") >= 1 { | |
| 94 | 94 | return val | |
| 95 | 95 | } | |
| 96 | + | // Don't add namespace to Go builtin types | |
| 97 | + | if isGoBuiltinType(val) { | |
| 98 | + | return val | |
| 99 | + | } | |
| 96 | 100 | return PrefixValue(val, ns+".") | |
| 97 | 101 | } | |
| 98 | 102 | ||
| 103 | + | // goBuiltinTypes contains Go builtin types that should never be namespace-prefixed | |
| 104 | + | var goBuiltinTypes = map[string]bool{ | |
| 105 | + | "bool": true, "byte": true, "complex64": true, "complex128": true, | |
| 106 | + | "error": true, "float32": true, "float64": true, "int": true, | |
| 107 | + | "int8": true, "int16": true, "int32": true, "int64": true, | |
| 108 | + | "rune": true, "string": true, "uint": true, "uint8": true, | |
| 109 | + | "uint16": true, "uint32": true, "uint64": true, "uintptr": true, | |
| 110 | + | } | |
| 111 | + | ||
| 112 | + | // isGoBuiltinType checks if the given type (after stripping pointers and slices) is a Go builtin | |
| 113 | + | func isGoBuiltinType(gotype string) bool { | |
| 114 | + | // Strip pointer prefixes | |
| 115 | + | baseType := strings.TrimLeft(gotype, "*") | |
| 116 | + | // Strip slice prefix | |
| 117 | + | baseType = strings.TrimPrefix(baseType, "[]") | |
| 118 | + | // Strip any remaining pointers (e.g., *[]byte -> []byte -> byte) | |
| 119 | + | baseType = strings.TrimLeft(baseType, "*") | |
| 120 | + | return goBuiltinTypes[baseType] | |
| 121 | + | } | |
| 122 | + | ||
| 99 | 123 | // NormalizeNamespace converts a type to one that always includes a lowercase namespace | |
| 100 | 124 | // if no namespace is found, it adds `ns`, unless if strip is True then namespaces always equaling `ns` will be removed | |
| 101 | 125 | func NormalizeNamespace(ns string, gotype string, strip bool) string { | |
| 102 | 126 | if ns == "" { | |
| 103 | 127 | return "" | |
| 104 | 128 | } | |
| 129 | + | ||
| 130 | + | // Check if this is a Go builtin type before any modifications | |
| 131 | + | // Note: gotype here may still have * prefixes which are trimmed below | |
| 132 | + | trimmedForCheck := strings.Trim(gotype, "*") | |
| 133 | + | if isGoBuiltinType(trimmedForCheck) { | |
| 134 | + | return trimmedForCheck | |
| 135 | + | } | |
| 136 | + | ||
| 105 | 137 | gotype = strings.Trim(gotype, "*") | |
| 106 | 138 | splt := strings.Split(gotype, ".") | |
| 107 | 139 | if len(splt) <= 1 { | |
| @@ -93,15 +93,47 @@ func AddNamespace(val, ns string) string { | |||||
| 93 | if ns == "" || strings.Count(val, ".") >= 1 { | 93 | if ns == "" || strings.Count(val, ".") >= 1 { | ||
| 94 | return val | 94 | return val | ||
| 95 | } | 95 | } | ||
| 96 | + | // Don't add namespace to Go builtin types | |||
| 97 | + | if isGoBuiltinType(val) { | |||
| 98 | + | return val | |||
| 99 | + | } | |||
| 96 | return PrefixValue(val, ns+".") | 100 | return PrefixValue(val, ns+".") | ||
| 97 | } | 101 | } | ||
| 98 | 102 | ||||
| 103 | + | // goBuiltinTypes contains Go builtin types that should never be namespace-prefixed | |||
| 104 | + | var goBuiltinTypes = map[string]bool{ | |||
| 105 | + | "bool": true, "byte": true, "complex64": true, "complex128": true, | |||
| 106 | + | "error": true, "float32": true, "float64": true, "int": true, | |||
| 107 | + | "int8": true, "int16": true, "int32": true, "int64": true, | |||
| 108 | + | "rune": true, "string": true, "uint": true, "uint8": true, | |||
| 109 | + | "uint16": true, "uint32": true, "uint64": true, "uintptr": true, | |||
| 110 | + | } | |||
| 111 | + | ||||
| 112 | + | // isGoBuiltinType checks if the given type (after stripping pointers and slices) is a Go builtin | |||
| 113 | + | func isGoBuiltinType(gotype string) bool { | |||
| 114 | + | // Strip pointer prefixes | |||
| 115 | + | baseType := strings.TrimLeft(gotype, "*") | |||
| 116 | + | // Strip slice prefix | |||
| 117 | + | baseType = strings.TrimPrefix(baseType, "[]") | |||
| 118 | + | // Strip any remaining pointers (e.g., *[]byte -> []byte -> byte) | |||
| 119 | + | baseType = strings.TrimLeft(baseType, "*") | |||
| 120 | + | return goBuiltinTypes[baseType] | |||
| 121 | + | } | |||
| 122 | + | ||||
| 99 | // NormalizeNamespace converts a type to one that always includes a lowercase namespace | 123 | // NormalizeNamespace converts a type to one that always includes a lowercase namespace | ||
| 100 | // if no namespace is found, it adds `ns`, unless if strip is True then namespaces always equaling `ns` will be removed | 124 | // if no namespace is found, it adds `ns`, unless if strip is True then namespaces always equaling `ns` will be removed | ||
| 101 | func NormalizeNamespace(ns string, gotype string, strip bool) string { | 125 | func NormalizeNamespace(ns string, gotype string, strip bool) string { | ||
| 102 | if ns == "" { | 126 | if ns == "" { | ||
| 103 | return "" | 127 | return "" | ||
| 104 | } | 128 | } | ||
| 129 | + | ||||
| 130 | + | // Check if this is a Go builtin type before any modifications | |||
| 131 | + | // Note: gotype here may still have * prefixes which are trimmed below | |||
| 132 | + | trimmedForCheck := strings.Trim(gotype, "*") | |||
| 133 | + | if isGoBuiltinType(trimmedForCheck) { | |||
| 134 | + | return trimmedForCheck | |||
| 135 | + | } | |||
| 136 | + | ||||
| 105 | gotype = strings.Trim(gotype, "*") | 137 | gotype = strings.Trim(gotype, "*") | ||
| 106 | splt := strings.Split(gotype, ".") | 138 | splt := strings.Split(gotype, ".") | ||
| 107 | if len(splt) <= 1 { | 139 | if len(splt) <= 1 { | ||
M templates/go +0 -90
| @@ -69,7 +69,6 @@ func {{.Name}}({{conv .Args.API.Full}}) {{.Ret.Return}} { | |||
| 69 | 69 | {{.Ret.Preamble $NotGLib}} | |
| 70 | 70 | {{- /* Generate closure wrappers for callback parameters */}} | |
| 71 | 71 | {{range .Args.Callbacks}} | |
| 72 | - | {{if .Nullable -}} | |
| 73 | 72 | var {{.Name}}Ref uintptr | |
| 74 | 73 | if {{.Name}} != nil { | |
| 75 | 74 | {{.Name}}Ptr := uintptr(unsafe.Pointer({{.Name}})) | |
| @@ -84,20 +83,6 @@ func {{.Name}}({{conv .Args.API.Full}}) {{.Ret.Return}} { | |||
| 84 | 83 | {{if $NotGLib}}glib.{{end}}SaveCallback({{.Name}}Ptr, {{.Name}}Ref) | |
| 85 | 84 | } | |
| 86 | 85 | } | |
| 87 | - | {{- else -}} | |
| 88 | - | {{.Name}}Ptr := uintptr(unsafe.Pointer({{.Name}})) | |
| 89 | - | var {{.Name}}Ref uintptr | |
| 90 | - | if cbRefPtr, ok := {{if $NotGLib}}glib.{{end}}GetCallback({{.Name}}Ptr); ok { | |
| 91 | - | {{.Name}}Ref = cbRefPtr | |
| 92 | - | } else { | |
| 93 | - | fcb := func({{range $i, $t := .PureTypes}}{{if $i}}, {{end}}arg{{$i}} {{$t}}{{end}}) {{.RetRaw}} { | |
| 94 | - | cbFn := *{{.Name}} | |
| 95 | - | {{if .RetRaw}}return {{end}}cbFn({{range $i, $t := .PureTypes}}{{if $i}}, {{end}}arg{{$i}}{{end}}) | |
| 96 | - | } | |
| 97 | - | {{.Name}}Ref = purego.NewCallback(fcb) | |
| 98 | - | {{if $NotGLib}}glib.{{end}}SaveCallback({{.Name}}Ptr, {{.Name}}Ref) | |
| 99 | - | } | |
| 100 | - | {{- end}} | |
| 101 | 86 | {{end}} | |
| 102 | 87 | {{if .Ret.Value}}cret :={{end}}x{{.Name}}({{convd .Args.API.CallWithRefs}}) | |
| 103 | 88 | {{.Ret.Fmt $NotGObject}} | |
| @@ -113,7 +98,6 @@ func (x *{{$outer.Name}}) {{.Name}}({{conv .Args.API.Full}}) {{.Ret.Return}} { | |||
| 113 | 98 | {{.Ret.Preamble $NotGLib}} | |
| 114 | 99 | {{- /* Generate closure wrappers for callback parameters */}} | |
| 115 | 100 | {{range .Args.Callbacks}} | |
| 116 | - | {{if .Nullable -}} | |
| 117 | 101 | var {{.Name}}Ref uintptr | |
| 118 | 102 | if {{.Name}} != nil { | |
| 119 | 103 | {{.Name}}Ptr := uintptr(unsafe.Pointer({{.Name}})) | |
| @@ -128,20 +112,6 @@ func (x *{{$outer.Name}}) {{.Name}}({{conv .Args.API.Full}}) {{.Ret.Return}} { | |||
| 128 | 112 | {{if $NotGLib}}glib.{{end}}SaveCallback({{.Name}}Ptr, {{.Name}}Ref) | |
| 129 | 113 | } | |
| 130 | 114 | } | |
| 131 | - | {{- else -}} | |
| 132 | - | {{.Name}}Ptr := uintptr(unsafe.Pointer({{.Name}})) | |
| 133 | - | var {{.Name}}Ref uintptr | |
| 134 | - | if cbRefPtr, ok := {{if $NotGLib}}glib.{{end}}GetCallback({{.Name}}Ptr); ok { | |
| 135 | - | {{.Name}}Ref = cbRefPtr | |
| 136 | - | } else { | |
| 137 | - | fcb := func({{range $i, $t := .PureTypes}}{{if $i}}, {{end}}arg{{$i}} {{$t}}{{end}}) {{.RetRaw}} { | |
| 138 | - | cbFn := *{{.Name}} | |
| 139 | - | {{if .RetRaw}}return {{end}}cbFn({{range $i, $t := .PureTypes}}{{if $i}}, {{end}}arg{{$i}}{{end}}) | |
| 140 | - | } | |
| 141 | - | {{.Name}}Ref = purego.NewCallback(fcb) | |
| 142 | - | {{if $NotGLib}}glib.{{end}}SaveCallback({{.Name}}Ptr, {{.Name}}Ref) | |
| 143 | - | } | |
| 144 | - | {{- end}} | |
| 145 | 115 | {{end}} | |
| 146 | 116 | {{if .Ret.Value}}cret :={{end}}x{{$outer.Name}}{{.Name}}(x.GoPointer() {{convcd .Args.API.CallWithRefs}}) | |
| 147 | 117 | {{.Ret.Fmt $NotGObject}} | |
| @@ -306,7 +276,6 @@ func {{.Name}}({{conv .Args.API.Full}}) {{.Ret.Return}} { | |||
| 306 | 276 | {{.Ret.Preamble $NotGLib}} | |
| 307 | 277 | {{- /* Generate closure wrappers for callback parameters */}} | |
| 308 | 278 | {{range .Args.Callbacks}} | |
| 309 | - | {{if .Nullable -}} | |
| 310 | 279 | var {{.Name}}Ref uintptr | |
| 311 | 280 | if {{.Name}} != nil { | |
| 312 | 281 | {{.Name}}Ptr := uintptr(unsafe.Pointer({{.Name}})) | |
| @@ -321,20 +290,6 @@ func {{.Name}}({{conv .Args.API.Full}}) {{.Ret.Return}} { | |||
| 321 | 290 | {{if $NotGLib}}glib.{{end}}SaveCallback({{.Name}}Ptr, {{.Name}}Ref) | |
| 322 | 291 | } | |
| 323 | 292 | } | |
| 324 | - | {{- else -}} | |
| 325 | - | {{.Name}}Ptr := uintptr(unsafe.Pointer({{.Name}})) | |
| 326 | - | var {{.Name}}Ref uintptr | |
| 327 | - | if cbRefPtr, ok := {{if $NotGLib}}glib.{{end}}GetCallback({{.Name}}Ptr); ok { | |
| 328 | - | {{.Name}}Ref = cbRefPtr | |
| 329 | - | } else { | |
| 330 | - | fcb := func({{range $i, $t := .PureTypes}}{{if $i}}, {{end}}arg{{$i}} {{$t}}{{end}}) {{.RetRaw}} { | |
| 331 | - | cbFn := *{{.Name}} | |
| 332 | - | {{if .RetRaw}}return {{end}}cbFn({{range $i, $t := .PureTypes}}{{if $i}}, {{end}}arg{{$i}}{{end}}) | |
| 333 | - | } | |
| 334 | - | {{.Name}}Ref = purego.NewCallback(fcb) | |
| 335 | - | {{if $NotGLib}}glib.{{end}}SaveCallback({{.Name}}Ptr, {{.Name}}Ref) | |
| 336 | - | } | |
| 337 | - | {{- end}} | |
| 338 | 293 | {{end}} | |
| 339 | 294 | {{if .Ret.Value}}cret := {{end}}x{{.Name}}({{convd .Args.API.CallWithRefs}}) | |
| 340 | 295 | {{.Ret.Fmt $NotGObject}} | |
| @@ -373,7 +328,6 @@ func {{.Name}}({{conv .Args.API.Full}}) {{.Ret.Return}} { | |||
| 373 | 328 | {{.Ret.Preamble $NotGLib}} | |
| 374 | 329 | {{- /* Generate closure wrappers for callback parameters */}} | |
| 375 | 330 | {{range .Args.Callbacks}} | |
| 376 | - | {{if .Nullable -}} | |
| 377 | 331 | var {{.Name}}Ref uintptr | |
| 378 | 332 | if {{.Name}} != nil { | |
| 379 | 333 | {{.Name}}Ptr := uintptr(unsafe.Pointer({{.Name}})) | |
| @@ -388,20 +342,6 @@ func {{.Name}}({{conv .Args.API.Full}}) {{.Ret.Return}} { | |||
| 388 | 342 | {{if $NotGLib}}glib.{{end}}SaveCallback({{.Name}}Ptr, {{.Name}}Ref) | |
| 389 | 343 | } | |
| 390 | 344 | } | |
| 391 | - | {{- else -}} | |
| 392 | - | {{.Name}}Ptr := uintptr(unsafe.Pointer({{.Name}})) | |
| 393 | - | var {{.Name}}Ref uintptr | |
| 394 | - | if cbRefPtr, ok := {{if $NotGLib}}glib.{{end}}GetCallback({{.Name}}Ptr); ok { | |
| 395 | - | {{.Name}}Ref = cbRefPtr | |
| 396 | - | } else { | |
| 397 | - | fcb := func({{range $i, $t := .PureTypes}}{{if $i}}, {{end}}arg{{$i}} {{$t}}{{end}}) {{.RetRaw}} { | |
| 398 | - | cbFn := *{{.Name}} | |
| 399 | - | {{if .RetRaw}}return {{end}}cbFn({{range $i, $t := .PureTypes}}{{if $i}}, {{end}}arg{{$i}}{{end}}) | |
| 400 | - | } | |
| 401 | - | {{.Name}}Ref = purego.NewCallback(fcb) | |
| 402 | - | {{if $NotGLib}}glib.{{end}}SaveCallback({{.Name}}Ptr, {{.Name}}Ref) | |
| 403 | - | } | |
| 404 | - | {{- end}} | |
| 405 | 345 | {{end}} | |
| 406 | 346 | {{if .Ret.Value}}cret :={{end}}x{{.Name}}({{convd .Args.API.CallWithRefs}}) | |
| 407 | 347 | {{.Ret.Fmt $NotGObject}} | |
| @@ -417,7 +357,6 @@ func (x *{{$outer.Name}}) {{.Name}}({{conv .Args.API.Full}}) {{.Ret.Return}} { | |||
| 417 | 357 | {{.Ret.Preamble $NotGLib}} | |
| 418 | 358 | {{- /* Generate closure wrappers for callback parameters */}} | |
| 419 | 359 | {{range .Args.Callbacks}} | |
| 420 | - | {{if .Nullable -}} | |
| 421 | 360 | var {{.Name}}Ref uintptr | |
| 422 | 361 | if {{.Name}} != nil { | |
| 423 | 362 | {{.Name}}Ptr := uintptr(unsafe.Pointer({{.Name}})) | |
| @@ -432,20 +371,6 @@ func (x *{{$outer.Name}}) {{.Name}}({{conv .Args.API.Full}}) {{.Ret.Return}} { | |||
| 432 | 371 | {{if $NotGLib}}glib.{{end}}SaveCallback({{.Name}}Ptr, {{.Name}}Ref) | |
| 433 | 372 | } | |
| 434 | 373 | } | |
| 435 | - | {{- else -}} | |
| 436 | - | {{.Name}}Ptr := uintptr(unsafe.Pointer({{.Name}})) | |
| 437 | - | var {{.Name}}Ref uintptr | |
| 438 | - | if cbRefPtr, ok := {{if $NotGLib}}glib.{{end}}GetCallback({{.Name}}Ptr); ok { | |
| 439 | - | {{.Name}}Ref = cbRefPtr | |
| 440 | - | } else { | |
| 441 | - | fcb := func({{range $i, $t := .PureTypes}}{{if $i}}, {{end}}arg{{$i}} {{$t}}{{end}}) {{.RetRaw}} { | |
| 442 | - | cbFn := *{{.Name}} | |
| 443 | - | {{if .RetRaw}}return {{end}}cbFn({{range $i, $t := .PureTypes}}{{if $i}}, {{end}}arg{{$i}}{{end}}) | |
| 444 | - | } | |
| 445 | - | {{.Name}}Ref = purego.NewCallback(fcb) | |
| 446 | - | {{if $NotGLib}}glib.{{end}}SaveCallback({{.Name}}Ptr, {{.Name}}Ref) | |
| 447 | - | } | |
| 448 | - | {{- end}} | |
| 449 | 374 | {{end}} | |
| 450 | 375 | {{if .Ret.Value}}cret :={{end}}x{{$outer.Name}}{{.Name}}(x.GoPointer() {{convcd .Args.API.CallWithRefs}}) | |
| 451 | 376 | {{.Ret.Fmt $NotGObject}} | |
| @@ -532,7 +457,6 @@ func {{.Name}}({{conv .Args.API.Full}}) {{.Ret.Return}} { | |||
| 532 | 457 | {{.Ret.Preamble $NotGLib}} | |
| 533 | 458 | {{- /* Generate closure wrappers for callback parameters */}} | |
| 534 | 459 | {{range .Args.Callbacks}} | |
| 535 | - | {{if .Nullable -}} | |
| 536 | 460 | var {{.Name}}Ref uintptr | |
| 537 | 461 | if {{.Name}} != nil { | |
| 538 | 462 | {{.Name}}Ptr := uintptr(unsafe.Pointer({{.Name}})) | |
| @@ -547,20 +471,6 @@ func {{.Name}}({{conv .Args.API.Full}}) {{.Ret.Return}} { | |||
| 547 | 471 | {{if $NotGLib}}glib.{{end}}SaveCallback({{.Name}}Ptr, {{.Name}}Ref) | |
| 548 | 472 | } | |
| 549 | 473 | } | |
| 550 | - | {{- else -}} | |
| 551 | - | {{.Name}}Ptr := uintptr(unsafe.Pointer({{.Name}})) | |
| 552 | - | var {{.Name}}Ref uintptr | |
| 553 | - | if cbRefPtr, ok := {{if $NotGLib}}glib.{{end}}GetCallback({{.Name}}Ptr); ok { | |
| 554 | - | {{.Name}}Ref = cbRefPtr | |
| 555 | - | } else { | |
| 556 | - | fcb := func({{range $i, $t := .PureTypes}}{{if $i}}, {{end}}arg{{$i}} {{$t}}{{end}}) {{.RetRaw}} { | |
| 557 | - | cbFn := *{{.Name}} | |
| 558 | - | {{if .RetRaw}}return {{end}}cbFn({{range $i, $t := .PureTypes}}{{if $i}}, {{end}}arg{{$i}}{{end}}) | |
| 559 | - | } | |
| 560 | - | {{.Name}}Ref = purego.NewCallback(fcb) | |
| 561 | - | {{if $NotGLib}}glib.{{end}}SaveCallback({{.Name}}Ptr, {{.Name}}Ref) | |
| 562 | - | } | |
| 563 | - | {{- end}} | |
| 564 | 474 | {{end}} | |
| 565 | 475 | {{if .Ret.Value}}cret := {{end}}x{{.Name}}({{convd .Args.API.CallWithRefs}}) | |
| 566 | 476 | {{.Ret.Fmt $NotGObject}} | |
| @@ -69,7 +69,6 @@ func {{.Name}}({{conv .Args.API.Full}}) {{.Ret.Return}} { | |||||
| 69 | {{.Ret.Preamble $NotGLib}} | 69 | {{.Ret.Preamble $NotGLib}} | ||
| 70 | {{- /* Generate closure wrappers for callback parameters */}} | 70 | {{- /* Generate closure wrappers for callback parameters */}} | ||
| 71 | {{range .Args.Callbacks}} | 71 | {{range .Args.Callbacks}} | ||
| 72 | - | {{if .Nullable -}} | |||
| 73 | var {{.Name}}Ref uintptr | 72 | var {{.Name}}Ref uintptr | ||
| 74 | if {{.Name}} != nil { | 73 | if {{.Name}} != nil { | ||
| 75 | {{.Name}}Ptr := uintptr(unsafe.Pointer({{.Name}})) | 74 | {{.Name}}Ptr := uintptr(unsafe.Pointer({{.Name}})) | ||
| @@ -84,20 +83,6 @@ func {{.Name}}({{conv .Args.API.Full}}) {{.Ret.Return}} { | |||||
| 84 | {{if $NotGLib}}glib.{{end}}SaveCallback({{.Name}}Ptr, {{.Name}}Ref) | 83 | {{if $NotGLib}}glib.{{end}}SaveCallback({{.Name}}Ptr, {{.Name}}Ref) | ||
| 85 | } | 84 | } | ||
| 86 | } | 85 | } | ||
| 87 | - | {{- else -}} | |||
| 88 | - | {{.Name}}Ptr := uintptr(unsafe.Pointer({{.Name}})) | |||
| 89 | - | var {{.Name}}Ref uintptr | |||
| 90 | - | if cbRefPtr, ok := {{if $NotGLib}}glib.{{end}}GetCallback({{.Name}}Ptr); ok { | |||
| 91 | - | {{.Name}}Ref = cbRefPtr | |||
| 92 | - | } else { | |||
| 93 | - | fcb := func({{range $i, $t := .PureTypes}}{{if $i}}, {{end}}arg{{$i}} {{$t}}{{end}}) {{.RetRaw}} { | |||
| 94 | - | cbFn := *{{.Name}} | |||
| 95 | - | {{if .RetRaw}}return {{end}}cbFn({{range $i, $t := .PureTypes}}{{if $i}}, {{end}}arg{{$i}}{{end}}) | |||
| 96 | - | } | |||
| 97 | - | {{.Name}}Ref = purego.NewCallback(fcb) | |||
| 98 | - | {{if $NotGLib}}glib.{{end}}SaveCallback({{.Name}}Ptr, {{.Name}}Ref) | |||
| 99 | - | } | |||
| 100 | - | {{- end}} | |||
| 101 | {{end}} | 86 | {{end}} | ||
| 102 | {{if .Ret.Value}}cret :={{end}}x{{.Name}}({{convd .Args.API.CallWithRefs}}) | 87 | {{if .Ret.Value}}cret :={{end}}x{{.Name}}({{convd .Args.API.CallWithRefs}}) | ||
| 103 | {{.Ret.Fmt $NotGObject}} | 88 | {{.Ret.Fmt $NotGObject}} | ||
| @@ -113,7 +98,6 @@ func (x *{{$outer.Name}}) {{.Name}}({{conv .Args.API.Full}}) {{.Ret.Return}} { | |||||
| 113 | {{.Ret.Preamble $NotGLib}} | 98 | {{.Ret.Preamble $NotGLib}} | ||
| 114 | {{- /* Generate closure wrappers for callback parameters */}} | 99 | {{- /* Generate closure wrappers for callback parameters */}} | ||
| 115 | {{range .Args.Callbacks}} | 100 | {{range .Args.Callbacks}} | ||
| 116 | - | {{if .Nullable -}} | |||
| 117 | var {{.Name}}Ref uintptr | 101 | var {{.Name}}Ref uintptr | ||
| 118 | if {{.Name}} != nil { | 102 | if {{.Name}} != nil { | ||
| 119 | {{.Name}}Ptr := uintptr(unsafe.Pointer({{.Name}})) | 103 | {{.Name}}Ptr := uintptr(unsafe.Pointer({{.Name}})) | ||
| @@ -128,20 +112,6 @@ func (x *{{$outer.Name}}) {{.Name}}({{conv .Args.API.Full}}) {{.Ret.Return}} { | |||||
| 128 | {{if $NotGLib}}glib.{{end}}SaveCallback({{.Name}}Ptr, {{.Name}}Ref) | 112 | {{if $NotGLib}}glib.{{end}}SaveCallback({{.Name}}Ptr, {{.Name}}Ref) | ||
| 129 | } | 113 | } | ||
| 130 | } | 114 | } | ||
| 131 | - | {{- else -}} | |||
| 132 | - | {{.Name}}Ptr := uintptr(unsafe.Pointer({{.Name}})) | |||
| 133 | - | var {{.Name}}Ref uintptr | |||
| 134 | - | if cbRefPtr, ok := {{if $NotGLib}}glib.{{end}}GetCallback({{.Name}}Ptr); ok { | |||
| 135 | - | {{.Name}}Ref = cbRefPtr | |||
| 136 | - | } else { | |||
| 137 | - | fcb := func({{range $i, $t := .PureTypes}}{{if $i}}, {{end}}arg{{$i}} {{$t}}{{end}}) {{.RetRaw}} { | |||
| 138 | - | cbFn := *{{.Name}} | |||
| 139 | - | {{if .RetRaw}}return {{end}}cbFn({{range $i, $t := .PureTypes}}{{if $i}}, {{end}}arg{{$i}}{{end}}) | |||
| 140 | - | } | |||
| 141 | - | {{.Name}}Ref = purego.NewCallback(fcb) | |||
| 142 | - | {{if $NotGLib}}glib.{{end}}SaveCallback({{.Name}}Ptr, {{.Name}}Ref) | |||
| 143 | - | } | |||
| 144 | - | {{- end}} | |||
| 145 | {{end}} | 115 | {{end}} | ||
| 146 | {{if .Ret.Value}}cret :={{end}}x{{$outer.Name}}{{.Name}}(x.GoPointer() {{convcd .Args.API.CallWithRefs}}) | 116 | {{if .Ret.Value}}cret :={{end}}x{{$outer.Name}}{{.Name}}(x.GoPointer() {{convcd .Args.API.CallWithRefs}}) | ||
| 147 | {{.Ret.Fmt $NotGObject}} | 117 | {{.Ret.Fmt $NotGObject}} | ||
| @@ -306,7 +276,6 @@ func {{.Name}}({{conv .Args.API.Full}}) {{.Ret.Return}} { | |||||
| 306 | {{.Ret.Preamble $NotGLib}} | 276 | {{.Ret.Preamble $NotGLib}} | ||
| 307 | {{- /* Generate closure wrappers for callback parameters */}} | 277 | {{- /* Generate closure wrappers for callback parameters */}} | ||
| 308 | {{range .Args.Callbacks}} | 278 | {{range .Args.Callbacks}} | ||
| 309 | - | {{if .Nullable -}} | |||
| 310 | var {{.Name}}Ref uintptr | 279 | var {{.Name}}Ref uintptr | ||
| 311 | if {{.Name}} != nil { | 280 | if {{.Name}} != nil { | ||
| 312 | {{.Name}}Ptr := uintptr(unsafe.Pointer({{.Name}})) | 281 | {{.Name}}Ptr := uintptr(unsafe.Pointer({{.Name}})) | ||
| @@ -321,20 +290,6 @@ func {{.Name}}({{conv .Args.API.Full}}) {{.Ret.Return}} { | |||||
| 321 | {{if $NotGLib}}glib.{{end}}SaveCallback({{.Name}}Ptr, {{.Name}}Ref) | 290 | {{if $NotGLib}}glib.{{end}}SaveCallback({{.Name}}Ptr, {{.Name}}Ref) | ||
| 322 | } | 291 | } | ||
| 323 | } | 292 | } | ||
| 324 | - | {{- else -}} | |||
| 325 | - | {{.Name}}Ptr := uintptr(unsafe.Pointer({{.Name}})) | |||
| 326 | - | var {{.Name}}Ref uintptr | |||
| 327 | - | if cbRefPtr, ok := {{if $NotGLib}}glib.{{end}}GetCallback({{.Name}}Ptr); ok { | |||
| 328 | - | {{.Name}}Ref = cbRefPtr | |||
| 329 | - | } else { | |||
| 330 | - | fcb := func({{range $i, $t := .PureTypes}}{{if $i}}, {{end}}arg{{$i}} {{$t}}{{end}}) {{.RetRaw}} { | |||
| 331 | - | cbFn := *{{.Name}} | |||
| 332 | - | {{if .RetRaw}}return {{end}}cbFn({{range $i, $t := .PureTypes}}{{if $i}}, {{end}}arg{{$i}}{{end}}) | |||
| 333 | - | } | |||
| 334 | - | {{.Name}}Ref = purego.NewCallback(fcb) | |||
| 335 | - | {{if $NotGLib}}glib.{{end}}SaveCallback({{.Name}}Ptr, {{.Name}}Ref) | |||
| 336 | - | } | |||
| 337 | - | {{- end}} | |||
| 338 | {{end}} | 293 | {{end}} | ||
| 339 | {{if .Ret.Value}}cret := {{end}}x{{.Name}}({{convd .Args.API.CallWithRefs}}) | 294 | {{if .Ret.Value}}cret := {{end}}x{{.Name}}({{convd .Args.API.CallWithRefs}}) | ||
| 340 | {{.Ret.Fmt $NotGObject}} | 295 | {{.Ret.Fmt $NotGObject}} | ||
| @@ -373,7 +328,6 @@ func {{.Name}}({{conv .Args.API.Full}}) {{.Ret.Return}} { | |||||
| 373 | {{.Ret.Preamble $NotGLib}} | 328 | {{.Ret.Preamble $NotGLib}} | ||
| 374 | {{- /* Generate closure wrappers for callback parameters */}} | 329 | {{- /* Generate closure wrappers for callback parameters */}} | ||
| 375 | {{range .Args.Callbacks}} | 330 | {{range .Args.Callbacks}} | ||
| 376 | - | {{if .Nullable -}} | |||
| 377 | var {{.Name}}Ref uintptr | 331 | var {{.Name}}Ref uintptr | ||
| 378 | if {{.Name}} != nil { | 332 | if {{.Name}} != nil { | ||
| 379 | {{.Name}}Ptr := uintptr(unsafe.Pointer({{.Name}})) | 333 | {{.Name}}Ptr := uintptr(unsafe.Pointer({{.Name}})) | ||
| @@ -388,20 +342,6 @@ func {{.Name}}({{conv .Args.API.Full}}) {{.Ret.Return}} { | |||||
| 388 | {{if $NotGLib}}glib.{{end}}SaveCallback({{.Name}}Ptr, {{.Name}}Ref) | 342 | {{if $NotGLib}}glib.{{end}}SaveCallback({{.Name}}Ptr, {{.Name}}Ref) | ||
| 389 | } | 343 | } | ||
| 390 | } | 344 | } | ||
| 391 | - | {{- else -}} | |||
| 392 | - | {{.Name}}Ptr := uintptr(unsafe.Pointer({{.Name}})) | |||
| 393 | - | var {{.Name}}Ref uintptr | |||
| 394 | - | if cbRefPtr, ok := {{if $NotGLib}}glib.{{end}}GetCallback({{.Name}}Ptr); ok { | |||
| 395 | - | {{.Name}}Ref = cbRefPtr | |||
| 396 | - | } else { | |||
| 397 | - | fcb := func({{range $i, $t := .PureTypes}}{{if $i}}, {{end}}arg{{$i}} {{$t}}{{end}}) {{.RetRaw}} { | |||
| 398 | - | cbFn := *{{.Name}} | |||
| 399 | - | {{if .RetRaw}}return {{end}}cbFn({{range $i, $t := .PureTypes}}{{if $i}}, {{end}}arg{{$i}}{{end}}) | |||
| 400 | - | } | |||
| 401 | - | {{.Name}}Ref = purego.NewCallback(fcb) | |||
| 402 | - | {{if $NotGLib}}glib.{{end}}SaveCallback({{.Name}}Ptr, {{.Name}}Ref) | |||
| 403 | - | } | |||
| 404 | - | {{- end}} | |||
| 405 | {{end}} | 345 | {{end}} | ||
| 406 | {{if .Ret.Value}}cret :={{end}}x{{.Name}}({{convd .Args.API.CallWithRefs}}) | 346 | {{if .Ret.Value}}cret :={{end}}x{{.Name}}({{convd .Args.API.CallWithRefs}}) | ||
| 407 | {{.Ret.Fmt $NotGObject}} | 347 | {{.Ret.Fmt $NotGObject}} | ||
| @@ -417,7 +357,6 @@ func (x *{{$outer.Name}}) {{.Name}}({{conv .Args.API.Full}}) {{.Ret.Return}} { | |||||
| 417 | {{.Ret.Preamble $NotGLib}} | 357 | {{.Ret.Preamble $NotGLib}} | ||
| 418 | {{- /* Generate closure wrappers for callback parameters */}} | 358 | {{- /* Generate closure wrappers for callback parameters */}} | ||
| 419 | {{range .Args.Callbacks}} | 359 | {{range .Args.Callbacks}} | ||
| 420 | - | {{if .Nullable -}} | |||
| 421 | var {{.Name}}Ref uintptr | 360 | var {{.Name}}Ref uintptr | ||
| 422 | if {{.Name}} != nil { | 361 | if {{.Name}} != nil { | ||
| 423 | {{.Name}}Ptr := uintptr(unsafe.Pointer({{.Name}})) | 362 | {{.Name}}Ptr := uintptr(unsafe.Pointer({{.Name}})) | ||
| @@ -432,20 +371,6 @@ func (x *{{$outer.Name}}) {{.Name}}({{conv .Args.API.Full}}) {{.Ret.Return}} { | |||||
| 432 | {{if $NotGLib}}glib.{{end}}SaveCallback({{.Name}}Ptr, {{.Name}}Ref) | 371 | {{if $NotGLib}}glib.{{end}}SaveCallback({{.Name}}Ptr, {{.Name}}Ref) | ||
| 433 | } | 372 | } | ||
| 434 | } | 373 | } | ||
| 435 | - | {{- else -}} | |||
| 436 | - | {{.Name}}Ptr := uintptr(unsafe.Pointer({{.Name}})) | |||
| 437 | - | var {{.Name}}Ref uintptr | |||
| 438 | - | if cbRefPtr, ok := {{if $NotGLib}}glib.{{end}}GetCallback({{.Name}}Ptr); ok { | |||
| 439 | - | {{.Name}}Ref = cbRefPtr | |||
| 440 | - | } else { | |||
| 441 | - | fcb := func({{range $i, $t := .PureTypes}}{{if $i}}, {{end}}arg{{$i}} {{$t}}{{end}}) {{.RetRaw}} { | |||
| 442 | - | cbFn := *{{.Name}} | |||
| 443 | - | {{if .RetRaw}}return {{end}}cbFn({{range $i, $t := .PureTypes}}{{if $i}}, {{end}}arg{{$i}}{{end}}) | |||
| 444 | - | } | |||
| 445 | - | {{.Name}}Ref = purego.NewCallback(fcb) | |||
| 446 | - | {{if $NotGLib}}glib.{{end}}SaveCallback({{.Name}}Ptr, {{.Name}}Ref) | |||
| 447 | - | } | |||
| 448 | - | {{- end}} | |||
| 449 | {{end}} | 374 | {{end}} | ||
| 450 | {{if .Ret.Value}}cret :={{end}}x{{$outer.Name}}{{.Name}}(x.GoPointer() {{convcd .Args.API.CallWithRefs}}) | 375 | {{if .Ret.Value}}cret :={{end}}x{{$outer.Name}}{{.Name}}(x.GoPointer() {{convcd .Args.API.CallWithRefs}}) | ||
| 451 | {{.Ret.Fmt $NotGObject}} | 376 | {{.Ret.Fmt $NotGObject}} | ||
| @@ -532,7 +457,6 @@ func {{.Name}}({{conv .Args.API.Full}}) {{.Ret.Return}} { | |||||
| 532 | {{.Ret.Preamble $NotGLib}} | 457 | {{.Ret.Preamble $NotGLib}} | ||
| 533 | {{- /* Generate closure wrappers for callback parameters */}} | 458 | {{- /* Generate closure wrappers for callback parameters */}} | ||
| 534 | {{range .Args.Callbacks}} | 459 | {{range .Args.Callbacks}} | ||
| 535 | - | {{if .Nullable -}} | |||
| 536 | var {{.Name}}Ref uintptr | 460 | var {{.Name}}Ref uintptr | ||
| 537 | if {{.Name}} != nil { | 461 | if {{.Name}} != nil { | ||
| 538 | {{.Name}}Ptr := uintptr(unsafe.Pointer({{.Name}})) | 462 | {{.Name}}Ptr := uintptr(unsafe.Pointer({{.Name}})) | ||
| @@ -547,20 +471,6 @@ func {{.Name}}({{conv .Args.API.Full}}) {{.Ret.Return}} { | |||||
| 547 | {{if $NotGLib}}glib.{{end}}SaveCallback({{.Name}}Ptr, {{.Name}}Ref) | 471 | {{if $NotGLib}}glib.{{end}}SaveCallback({{.Name}}Ptr, {{.Name}}Ref) | ||
| 548 | } | 472 | } | ||
| 549 | } | 473 | } | ||
| 550 | - | {{- else -}} | |||
| 551 | - | {{.Name}}Ptr := uintptr(unsafe.Pointer({{.Name}})) | |||
| 552 | - | var {{.Name}}Ref uintptr | |||
| 553 | - | if cbRefPtr, ok := {{if $NotGLib}}glib.{{end}}GetCallback({{.Name}}Ptr); ok { | |||
| 554 | - | {{.Name}}Ref = cbRefPtr | |||
| 555 | - | } else { | |||
| 556 | - | fcb := func({{range $i, $t := .PureTypes}}{{if $i}}, {{end}}arg{{$i}} {{$t}}{{end}}) {{.RetRaw}} { | |||
| 557 | - | cbFn := *{{.Name}} | |||
| 558 | - | {{if .RetRaw}}return {{end}}cbFn({{range $i, $t := .PureTypes}}{{if $i}}, {{end}}arg{{$i}}{{end}}) | |||
| 559 | - | } | |||
| 560 | - | {{.Name}}Ref = purego.NewCallback(fcb) | |||
| 561 | - | {{if $NotGLib}}glib.{{end}}SaveCallback({{.Name}}Ptr, {{.Name}}Ref) | |||
| 562 | - | } | |||
| 563 | - | {{- end}} | |||
| 564 | {{end}} | 474 | {{end}} | ||
| 565 | {{if .Ret.Value}}cret := {{end}}x{{.Name}}({{convd .Args.API.CallWithRefs}}) | 475 | {{if .Ret.Value}}cret := {{end}}x{{.Name}}({{convd .Args.API.CallWithRefs}}) | ||
| 566 | {{.Ret.Fmt $NotGObject}} | 476 | {{.Ret.Fmt $NotGObject}} | ||