GIR: Add getters and setters for `[]byte` and `[]uintptr` to generator
Signed-off-by: Felicitas Pojtinger <felicitas@pojtinger.com>
- commit
- ce1ffcb63dfe539ef018187d22de348aa2157f2f
- author
- Felicitas Pojtinger · · 2025-11-01 02:56 UTC
- committer
- Jeroen Wijenbergh · · 2025-12-01 16:10 UTC
- parent
- 9216b3f
- signature
- unsigned
3 files · +41 -8
M internal/gir/types/types.go +4 -0
| @@ -773,6 +773,10 @@ func mapGoTypeToGValue(goType string) (gvalueType, setMethod, getMethod string) | |||
| 773 | 773 | return "TypePointerVal", "SetPointer", "GetPointer" | |
| 774 | 774 | case "[]string": | |
| 775 | 775 | return "BoxedStrv", "SetBoxed", "GetBoxed" | |
| 776 | + | case "[]byte": | |
| 777 | + | return "BoxedByteArray", "SetBoxed", "GetBoxed" | |
| 778 | + | case "[]uintptr": | |
| 779 | + | return "BoxedPtrArray", "SetBoxed", "GetBoxed" | |
| 776 | 780 | default: | |
| 777 | 781 | return "", "", "" | |
| 778 | 782 | } | |
| @@ -773,6 +773,10 @@ func mapGoTypeToGValue(goType string) (gvalueType, setMethod, getMethod string) | |||||
| 773 | return "TypePointerVal", "SetPointer", "GetPointer" | 773 | return "TypePointerVal", "SetPointer", "GetPointer" | ||
| 774 | case "[]string": | 774 | case "[]string": | ||
| 775 | return "BoxedStrv", "SetBoxed", "GetBoxed" | 775 | return "BoxedStrv", "SetBoxed", "GetBoxed" | ||
| 776 | + | case "[]byte": | |||
| 777 | + | return "BoxedByteArray", "SetBoxed", "GetBoxed" | |||
| 778 | + | case "[]uintptr": | |||
| 779 | + | return "BoxedPtrArray", "SetBoxed", "GetBoxed" | |||
| 776 | default: | 780 | default: | ||
| 777 | return "", "", "" | 781 | return "", "", "" | ||
| 778 | } | 782 | } | ||
M internal/gir/util/util.go +33 -4
| @@ -229,17 +229,46 @@ func PropertyScalarGet(getMethod string) string { | |||
| 229 | 229 | } | |
| 230 | 230 | ||
| 231 | 231 | // PropertyVectorSet returns the code for setting a vector property value | |
| 232 | - | func PropertyVectorSet(notGLib bool) string { | |
| 232 | + | func PropertyVectorSet(notGLib bool, goType string) string { | |
| 233 | 233 | prefix := "" | |
| 234 | 234 | if notGLib { | |
| 235 | 235 | prefix = "glib." | |
| 236 | 236 | } | |
| 237 | 237 | ||
| 238 | - | return prefix + `StrvGetType()) | |
| 238 | + | switch goType { | |
| 239 | + | case "[]string": | |
| 240 | + | return prefix + `StrvGetType()) | |
| 239 | 241 | v.SetBoxed(uintptr(unsafe.Pointer(core.ByteSlice(value))))` | |
| 242 | + | case "[]byte": | |
| 243 | + | return prefix + `ByteArrayGLibType()) | |
| 244 | + | v.SetBoxed(uintptr(unsafe.Pointer(&value[0])))` | |
| 245 | + | case "[]uintptr": | |
| 246 | + | return prefix + `PtrArrayGLibType()) | |
| 247 | + | v.SetBoxed(uintptr(unsafe.Pointer(&value[0])))` | |
| 248 | + | default: | |
| 249 | + | return prefix + `StrvGetType()) | |
| 250 | + | v.SetBoxed(uintptr(unsafe.Pointer(core.ByteSlice(value))))` | |
| 251 | + | } | |
| 240 | 252 | } | |
| 241 | 253 | ||
| 242 | 254 | // PropertyVectorGet returns the code for getting a vector property value | |
| 243 | - | func PropertyVectorGet() string { | |
| 244 | - | return `return core.GoStringSlice(v.GetBoxed())` | |
| 255 | + | func PropertyVectorGet(goType string) string { | |
| 256 | + | switch goType { | |
| 257 | + | case "[]string": | |
| 258 | + | return `return core.GoStringSlice(v.GetBoxed())` | |
| 259 | + | case "[]byte": | |
| 260 | + | return `ptr := v.GetBoxed() | |
| 261 | + | if ptr == 0 { | |
| 262 | + | return nil | |
| 263 | + | } | |
| 264 | + | return unsafe.Slice((*byte)(unsafe.Pointer(ptr)), 0)[:0]` | |
| 265 | + | case "[]uintptr": | |
| 266 | + | return `ptr := v.GetBoxed() | |
| 267 | + | if ptr == 0 { | |
| 268 | + | return nil | |
| 269 | + | } | |
| 270 | + | return unsafe.Slice((*uintptr)(unsafe.Pointer(ptr)), 0)[:0]` | |
| 271 | + | default: | |
| 272 | + | return `return core.GoStringSlice(v.GetBoxed())` | |
| 273 | + | } | |
| 245 | 274 | } | |
| @@ -229,17 +229,46 @@ func PropertyScalarGet(getMethod string) string { | |||||
| 229 | } | 229 | } | ||
| 230 | 230 | ||||
| 231 | // PropertyVectorSet returns the code for setting a vector property value | 231 | // PropertyVectorSet returns the code for setting a vector property value | ||
| 232 | - | func PropertyVectorSet(notGLib bool) string { | 232 | + | func PropertyVectorSet(notGLib bool, goType string) string { |
| 233 | prefix := "" | 233 | prefix := "" | ||
| 234 | if notGLib { | 234 | if notGLib { | ||
| 235 | prefix = "glib." | 235 | prefix = "glib." | ||
| 236 | } | 236 | } | ||
| 237 | 237 | ||||
| 238 | - | return prefix + `StrvGetType()) | 238 | + | switch goType { |
| 239 | + | case "[]string": | |||
| 240 | + | return prefix + `StrvGetType()) | |||
| 239 | v.SetBoxed(uintptr(unsafe.Pointer(core.ByteSlice(value))))` | 241 | v.SetBoxed(uintptr(unsafe.Pointer(core.ByteSlice(value))))` | ||
| 242 | + | case "[]byte": | |||
| 243 | + | return prefix + `ByteArrayGLibType()) | |||
| 244 | + | v.SetBoxed(uintptr(unsafe.Pointer(&value[0])))` | |||
| 245 | + | case "[]uintptr": | |||
| 246 | + | return prefix + `PtrArrayGLibType()) | |||
| 247 | + | v.SetBoxed(uintptr(unsafe.Pointer(&value[0])))` | |||
| 248 | + | default: | |||
| 249 | + | return prefix + `StrvGetType()) | |||
| 250 | + | v.SetBoxed(uintptr(unsafe.Pointer(core.ByteSlice(value))))` | |||
| 251 | + | } | |||
| 240 | } | 252 | } | ||
| 241 | 253 | ||||
| 242 | // PropertyVectorGet returns the code for getting a vector property value | 254 | // PropertyVectorGet returns the code for getting a vector property value | ||
| 243 | - | func PropertyVectorGet() string { | 255 | + | func PropertyVectorGet(goType string) string { |
| 244 | - | return `return core.GoStringSlice(v.GetBoxed())` | 256 | + | switch goType { |
| 257 | + | case "[]string": | |||
| 258 | + | return `return core.GoStringSlice(v.GetBoxed())` | |||
| 259 | + | case "[]byte": | |||
| 260 | + | return `ptr := v.GetBoxed() | |||
| 261 | + | if ptr == 0 { | |||
| 262 | + | return nil | |||
| 263 | + | } | |||
| 264 | + | return unsafe.Slice((*byte)(unsafe.Pointer(ptr)), 0)[:0]` | |||
| 265 | + | case "[]uintptr": | |||
| 266 | + | return `ptr := v.GetBoxed() | |||
| 267 | + | if ptr == 0 { | |||
| 268 | + | return nil | |||
| 269 | + | } | |||
| 270 | + | return unsafe.Slice((*uintptr)(unsafe.Pointer(ptr)), 0)[:0]` | |||
| 271 | + | default: | |||
| 272 | + | return `return core.GoStringSlice(v.GetBoxed())` | |||
| 273 | + | } | |||
| 245 | } | 274 | } | ||
M templates/go +4 -4
| @@ -172,7 +172,7 @@ func (x *{{$outer.Name}}Base) {{.Name}}({{conv .Args.API.Full}}) {{.Ret.Return}} | |||
| 172 | 172 | obj := {{if $NotGObject}}gobject.{{end}}Object{} | |
| 173 | 173 | obj.Ptr = x.GoPointer() | |
| 174 | 174 | var v {{if $NotGObject}}gobject.{{end}}Value | |
| 175 | - | {{if eq .GValueType "BoxedStrv"}}v.Init({{propvset $NotGLib}}{{else}}v.Init({{propsset $NotGObject .GValueType .SetMethod}}){{end}} | |
| 175 | + | {{if or (eq .GValueType "BoxedStrv") (eq .GValueType "BoxedByteArray") (eq .GValueType "BoxedPtrArray")}}v.Init({{propvset $NotGLib .GoType}}{{else}}v.Init({{propsset $NotGObject .GValueType .SetMethod}}){{end}} | |
| 176 | 176 | obj.SetProperty("{{.CName}}", &v) | |
| 177 | 177 | } | |
| 178 | 178 | {{end}} | |
| @@ -185,7 +185,7 @@ func (x *{{$outer.Name}}Base) {{.Name}}({{conv .Args.API.Full}}) {{.Ret.Return}} | |||
| 185 | 185 | obj.Ptr = x.GoPointer() | |
| 186 | 186 | var v {{if $NotGObject}}gobject.{{end}}Value | |
| 187 | 187 | obj.GetProperty("{{.CName}}", &v) | |
| 188 | - | {{if eq .GValueType "BoxedStrv"}}{{propvget}}{{else}}return {{propsget .GetMethod}}{{end}} | |
| 188 | + | {{if or (eq .GValueType "BoxedStrv") (eq .GValueType "BoxedByteArray") (eq .GValueType "BoxedPtrArray")}}{{propvget .GoType}}{{else}}return {{propsget .GetMethod}}{{end}} | |
| 189 | 189 | } | |
| 190 | 190 | {{end}} | |
| 191 | 191 | {{end}} | |
| @@ -308,7 +308,7 @@ func (c *{{.Name}}) SetGoPointer(ptr uintptr) { | |||
| 308 | 308 | {{if .Doc}}{{.Doc}} | |
| 309 | 309 | {{end}}func (x *{{$outer.Name}}) SetProperty{{.Name}}(value {{.GoType}}) { | |
| 310 | 310 | var v {{if $NotGObject}}gobject.{{end}}Value | |
| 311 | - | {{if eq .GValueType "BoxedStrv"}}v.Init({{propvset $NotGLib}}{{else}}v.Init({{propsset $NotGObject .GValueType .SetMethod}}){{end}} | |
| 311 | + | {{if or (eq .GValueType "BoxedStrv") (eq .GValueType "BoxedByteArray") (eq .GValueType "BoxedPtrArray")}}v.Init({{propvset $NotGLib .GoType}}{{else}}v.Init({{propsset $NotGObject .GValueType .SetMethod}}){{end}} | |
| 312 | 312 | x.SetProperty("{{.CName}}", &v) | |
| 313 | 313 | } | |
| 314 | 314 | {{end}} | |
| @@ -319,7 +319,7 @@ func (c *{{.Name}}) SetGoPointer(ptr uintptr) { | |||
| 319 | 319 | {{end}}func (x *{{$outer.Name}}) GetProperty{{.Name}}() {{.GoType}} { | |
| 320 | 320 | var v {{if $NotGObject}}gobject.{{end}}Value | |
| 321 | 321 | x.GetProperty("{{.CName}}", &v) | |
| 322 | - | {{if eq .GValueType "BoxedStrv"}}{{propvget}}{{else}}return {{propsget .GetMethod}}{{end}} | |
| 322 | + | {{if or (eq .GValueType "BoxedStrv") (eq .GValueType "BoxedByteArray") (eq .GValueType "BoxedPtrArray")}}{{propvget .GoType}}{{else}}return {{propsget .GetMethod}}{{end}} | |
| 323 | 323 | } | |
| 324 | 324 | {{end}} | |
| 325 | 325 | {{end}} | |
| @@ -172,7 +172,7 @@ func (x *{{$outer.Name}}Base) {{.Name}}({{conv .Args.API.Full}}) {{.Ret.Return}} | |||||
| 172 | obj := {{if $NotGObject}}gobject.{{end}}Object{} | 172 | obj := {{if $NotGObject}}gobject.{{end}}Object{} | ||
| 173 | obj.Ptr = x.GoPointer() | 173 | obj.Ptr = x.GoPointer() | ||
| 174 | var v {{if $NotGObject}}gobject.{{end}}Value | 174 | var v {{if $NotGObject}}gobject.{{end}}Value | ||
| 175 | - | {{if eq .GValueType "BoxedStrv"}}v.Init({{propvset $NotGLib}}{{else}}v.Init({{propsset $NotGObject .GValueType .SetMethod}}){{end}} | 175 | + | {{if or (eq .GValueType "BoxedStrv") (eq .GValueType "BoxedByteArray") (eq .GValueType "BoxedPtrArray")}}v.Init({{propvset $NotGLib .GoType}}{{else}}v.Init({{propsset $NotGObject .GValueType .SetMethod}}){{end}} |
| 176 | obj.SetProperty("{{.CName}}", &v) | 176 | obj.SetProperty("{{.CName}}", &v) | ||
| 177 | } | 177 | } | ||
| 178 | {{end}} | 178 | {{end}} | ||
| @@ -185,7 +185,7 @@ func (x *{{$outer.Name}}Base) {{.Name}}({{conv .Args.API.Full}}) {{.Ret.Return}} | |||||
| 185 | obj.Ptr = x.GoPointer() | 185 | obj.Ptr = x.GoPointer() | ||
| 186 | var v {{if $NotGObject}}gobject.{{end}}Value | 186 | var v {{if $NotGObject}}gobject.{{end}}Value | ||
| 187 | obj.GetProperty("{{.CName}}", &v) | 187 | obj.GetProperty("{{.CName}}", &v) | ||
| 188 | - | {{if eq .GValueType "BoxedStrv"}}{{propvget}}{{else}}return {{propsget .GetMethod}}{{end}} | 188 | + | {{if or (eq .GValueType "BoxedStrv") (eq .GValueType "BoxedByteArray") (eq .GValueType "BoxedPtrArray")}}{{propvget .GoType}}{{else}}return {{propsget .GetMethod}}{{end}} |
| 189 | } | 189 | } | ||
| 190 | {{end}} | 190 | {{end}} | ||
| 191 | {{end}} | 191 | {{end}} | ||
| @@ -308,7 +308,7 @@ func (c *{{.Name}}) SetGoPointer(ptr uintptr) { | |||||
| 308 | {{if .Doc}}{{.Doc}} | 308 | {{if .Doc}}{{.Doc}} | ||
| 309 | {{end}}func (x *{{$outer.Name}}) SetProperty{{.Name}}(value {{.GoType}}) { | 309 | {{end}}func (x *{{$outer.Name}}) SetProperty{{.Name}}(value {{.GoType}}) { | ||
| 310 | var v {{if $NotGObject}}gobject.{{end}}Value | 310 | var v {{if $NotGObject}}gobject.{{end}}Value | ||
| 311 | - | {{if eq .GValueType "BoxedStrv"}}v.Init({{propvset $NotGLib}}{{else}}v.Init({{propsset $NotGObject .GValueType .SetMethod}}){{end}} | 311 | + | {{if or (eq .GValueType "BoxedStrv") (eq .GValueType "BoxedByteArray") (eq .GValueType "BoxedPtrArray")}}v.Init({{propvset $NotGLib .GoType}}{{else}}v.Init({{propsset $NotGObject .GValueType .SetMethod}}){{end}} |
| 312 | x.SetProperty("{{.CName}}", &v) | 312 | x.SetProperty("{{.CName}}", &v) | ||
| 313 | } | 313 | } | ||
| 314 | {{end}} | 314 | {{end}} | ||
| @@ -319,7 +319,7 @@ func (c *{{.Name}}) SetGoPointer(ptr uintptr) { | |||||
| 319 | {{end}}func (x *{{$outer.Name}}) GetProperty{{.Name}}() {{.GoType}} { | 319 | {{end}}func (x *{{$outer.Name}}) GetProperty{{.Name}}() {{.GoType}} { | ||
| 320 | var v {{if $NotGObject}}gobject.{{end}}Value | 320 | var v {{if $NotGObject}}gobject.{{end}}Value | ||
| 321 | x.GetProperty("{{.CName}}", &v) | 321 | x.GetProperty("{{.CName}}", &v) | ||
| 322 | - | {{if eq .GValueType "BoxedStrv"}}{{propvget}}{{else}}return {{propsget .GetMethod}}{{end}} | 322 | + | {{if or (eq .GValueType "BoxedStrv") (eq .GValueType "BoxedByteArray") (eq .GValueType "BoxedPtrArray")}}{{propvget .GoType}}{{else}}return {{propsget .GetMethod}}{{end}} |
| 323 | } | 323 | } | ||
| 324 | {{end}} | 324 | {{end}} | ||
| 325 | {{end}} | 325 | {{end}} | ||