GObject template: Use get string and expose unset
...Also format :^)
- commit
- 91c587b8ce66233eba410616e284fd5ae46d3437
- author
- jwijenbergh · · 2023-08-25 11:00 UTC
- committer
- jwijenbergh · · 2023-08-25 11:01 UTC
- parent
- f979116
- signature
- GPG Unverified
1A2298F6C34F96E5The key is unknown
6 files · +39 -27
M internal/core/core.go +1 -3
| @@ -72,7 +72,7 @@ func findSo(path string, name string) string { | |||
| 72 | 72 | fn := filepath.Join(path, n) | |
| 73 | 73 | for _, s := range suffixes { | |
| 74 | 74 | if _, err := os.Stat(fn + s); err == nil { | |
| 75 | - | return fn+s | |
| 75 | + | return fn + s | |
| 76 | 76 | } | |
| 77 | 77 | } | |
| 78 | 78 | } | |
| @@ -138,8 +138,6 @@ func GetPath(name string) string { | |||
| 138 | 138 | panic(fmt.Sprintf("Path for library: %s not found. Please set the path to this library shared object file manually with env variable: %s. Or make sure pkg-config is setup correctly", strings.ToLower(name), ev)) | |
| 139 | 139 | } | |
| 140 | 140 | ||
| 141 | - | ||
| 142 | - | ||
| 143 | 141 | // GoString copies a char* to a Go string. | |
| 144 | 142 | // This function was copied from purego | |
| 145 | 143 | func GoString(c uintptr) string { | |
| @@ -72,7 +72,7 @@ func findSo(path string, name string) string { | |||||
| 72 | fn := filepath.Join(path, n) | 72 | fn := filepath.Join(path, n) | ||
| 73 | for _, s := range suffixes { | 73 | for _, s := range suffixes { | ||
| 74 | if _, err := os.Stat(fn + s); err == nil { | 74 | if _, err := os.Stat(fn + s); err == nil { | ||
| 75 | - | return fn+s | 75 | + | return fn + s |
| 76 | } | 76 | } | ||
| 77 | } | 77 | } | ||
| 78 | } | 78 | } | ||
| @@ -138,8 +138,6 @@ func GetPath(name string) string { | |||||
| 138 | panic(fmt.Sprintf("Path for library: %s not found. Please set the path to this library shared object file manually with env variable: %s. Or make sure pkg-config is setup correctly", strings.ToLower(name), ev)) | 138 | panic(fmt.Sprintf("Path for library: %s not found. Please set the path to this library shared object file manually with env variable: %s. Or make sure pkg-config is setup correctly", strings.ToLower(name), ev)) | ||
| 139 | } | 139 | } | ||
| 140 | 140 | ||||
| 141 | - | ||||
| 142 | - | ||||
| 143 | // GoString copies a char* to a Go string. | 141 | // GoString copies a char* to a Go string. | ||
| 144 | // This function was copied from purego | 142 | // This function was copied from purego | ||
| 145 | func GoString(c uintptr) string { | 143 | func GoString(c uintptr) string { | ||
M internal/gir/pass/pass.go +5 -5
| @@ -216,11 +216,11 @@ func (p *Pass) writeGo(r types.Repository, gotemp *template.Template, dir string | |||
| 216 | 216 | signals := make([]types.SignalsTemplate, len(cls.Signals)) | |
| 217 | 217 | for i, s := range cls.Signals { | |
| 218 | 218 | signals[i] = types.SignalsTemplate{ | |
| 219 | - | Doc: s.Doc.StringSafe(), | |
| 220 | - | Name: util.DashToCamel(s.Name), | |
| 221 | - | CName: s.Name, | |
| 222 | - | Args: s.Parameters.Template(ns.Name, "", p.Types, false), | |
| 223 | - | Ret: s.ReturnValue.Template(ns.Name, "", p.Types, false), | |
| 219 | + | Doc: s.Doc.StringSafe(), | |
| 220 | + | Name: util.DashToCamel(s.Name), | |
| 221 | + | CName: s.Name, | |
| 222 | + | Args: s.Parameters.Template(ns.Name, "", p.Types, false), | |
| 223 | + | Ret: s.ReturnValue.Template(ns.Name, "", p.Types, false), | |
| 224 | 224 | } | |
| 225 | 225 | } | |
| 226 | 226 | receivers := make([]types.FuncTemplate, len(cls.Methods)) | |
| @@ -216,11 +216,11 @@ func (p *Pass) writeGo(r types.Repository, gotemp *template.Template, dir string | |||||
| 216 | signals := make([]types.SignalsTemplate, len(cls.Signals)) | 216 | signals := make([]types.SignalsTemplate, len(cls.Signals)) | ||
| 217 | for i, s := range cls.Signals { | 217 | for i, s := range cls.Signals { | ||
| 218 | signals[i] = types.SignalsTemplate{ | 218 | signals[i] = types.SignalsTemplate{ | ||
| 219 | - | Doc: s.Doc.StringSafe(), | 219 | + | Doc: s.Doc.StringSafe(), |
| 220 | - | Name: util.DashToCamel(s.Name), | 220 | + | Name: util.DashToCamel(s.Name), |
| 221 | - | CName: s.Name, | 221 | + | CName: s.Name, |
| 222 | - | Args: s.Parameters.Template(ns.Name, "", p.Types, false), | 222 | + | Args: s.Parameters.Template(ns.Name, "", p.Types, false), |
| 223 | - | Ret: s.ReturnValue.Template(ns.Name, "", p.Types, false), | 223 | + | Ret: s.ReturnValue.Template(ns.Name, "", p.Types, false), |
| 224 | } | 224 | } | ||
| 225 | } | 225 | } | ||
| 226 | receivers := make([]types.FuncTemplate, len(cls.Methods)) | 226 | receivers := make([]types.FuncTemplate, len(cls.Methods)) | ||
M internal/gir/types/template.go +10 -10
| @@ -73,7 +73,7 @@ func (f *funcArgsTemplate) AddAPI(t string, n string, k Kind, ns string) { | |||
| 73 | 73 | func (f *funcArgsTemplate) AddPure(t string, n string, k Kind) { | |
| 74 | 74 | n += "p" | |
| 75 | 75 | c := n | |
| 76 | - | stars := strings.Count(t, "*") | |
| 76 | + | stars := strings.Count(t, "*") | |
| 77 | 77 | switch k { | |
| 78 | 78 | case RecordsType: | |
| 79 | 79 | if stars == 0 { | |
| @@ -82,7 +82,7 @@ func (f *funcArgsTemplate) AddPure(t string, n string, k Kind) { | |||
| 82 | 82 | case CallbackType: | |
| 83 | 83 | t = "uintptr" | |
| 84 | 84 | case ClassesType: | |
| 85 | - | if stars == 0 { | |
| 85 | + | if stars == 0 { | |
| 86 | 86 | c = n | |
| 87 | 87 | t = "uintptr" | |
| 88 | 88 | } else { | |
| @@ -212,7 +212,7 @@ type funcRetTemplate struct { | |||
| 212 | 212 | func (fr *funcRetTemplate) Instance() string { | |
| 213 | 213 | val := fr.Value + "{}" | |
| 214 | 214 | if strings.HasPrefix(fr.Value, "*") { | |
| 215 | - | return "&"+val[1:] | |
| 215 | + | return "&" + val[1:] | |
| 216 | 216 | } | |
| 217 | 217 | return val | |
| 218 | 218 | } | |
| @@ -287,14 +287,14 @@ func (fr *funcRetTemplate) Fmt(ngo bool) string { | |||
| 287 | 287 | after.WriteString(val) | |
| 288 | 288 | after.WriteString(",") | |
| 289 | 289 | } | |
| 290 | - | after.WriteString( "nil\n") | |
| 290 | + | after.WriteString("nil\n") | |
| 291 | 291 | after.WriteString("}\n") | |
| 292 | 292 | after.WriteString("return ") | |
| 293 | 293 | if fr.Value != "" { | |
| 294 | 294 | after.WriteString(val) | |
| 295 | 295 | after.WriteString(",") | |
| 296 | 296 | } | |
| 297 | - | after.WriteString( "cerr\n") | |
| 297 | + | after.WriteString("cerr\n") | |
| 298 | 298 | return after.String() | |
| 299 | 299 | } | |
| 300 | 300 | after.WriteString("return ") | |
| @@ -322,11 +322,11 @@ type InterfaceFuncTemplate struct { | |||
| 322 | 322 | } | |
| 323 | 323 | ||
| 324 | 324 | type SignalsTemplate struct { | |
| 325 | - | Doc string | |
| 326 | - | Name string | |
| 327 | - | CName string | |
| 328 | - | Args funcArgsTemplate | |
| 329 | - | Ret funcRetTemplate | |
| 325 | + | Doc string | |
| 326 | + | Name string | |
| 327 | + | CName string | |
| 328 | + | Args funcArgsTemplate | |
| 329 | + | Ret funcRetTemplate | |
| 330 | 330 | } | |
| 331 | 331 | ||
| 332 | 332 | type ClassTemplate struct { | |
| @@ -73,7 +73,7 @@ func (f *funcArgsTemplate) AddAPI(t string, n string, k Kind, ns string) { | |||||
| 73 | func (f *funcArgsTemplate) AddPure(t string, n string, k Kind) { | 73 | func (f *funcArgsTemplate) AddPure(t string, n string, k Kind) { | ||
| 74 | n += "p" | 74 | n += "p" | ||
| 75 | c := n | 75 | c := n | ||
| 76 | - | stars := strings.Count(t, "*") | 76 | + | stars := strings.Count(t, "*") |
| 77 | switch k { | 77 | switch k { | ||
| 78 | case RecordsType: | 78 | case RecordsType: | ||
| 79 | if stars == 0 { | 79 | if stars == 0 { | ||
| @@ -82,7 +82,7 @@ func (f *funcArgsTemplate) AddPure(t string, n string, k Kind) { | |||||
| 82 | case CallbackType: | 82 | case CallbackType: | ||
| 83 | t = "uintptr" | 83 | t = "uintptr" | ||
| 84 | case ClassesType: | 84 | case ClassesType: | ||
| 85 | - | if stars == 0 { | 85 | + | if stars == 0 { |
| 86 | c = n | 86 | c = n | ||
| 87 | t = "uintptr" | 87 | t = "uintptr" | ||
| 88 | } else { | 88 | } else { | ||
| @@ -212,7 +212,7 @@ type funcRetTemplate struct { | |||||
| 212 | func (fr *funcRetTemplate) Instance() string { | 212 | func (fr *funcRetTemplate) Instance() string { | ||
| 213 | val := fr.Value + "{}" | 213 | val := fr.Value + "{}" | ||
| 214 | if strings.HasPrefix(fr.Value, "*") { | 214 | if strings.HasPrefix(fr.Value, "*") { | ||
| 215 | - | return "&"+val[1:] | 215 | + | return "&" + val[1:] |
| 216 | } | 216 | } | ||
| 217 | return val | 217 | return val | ||
| 218 | } | 218 | } | ||
| @@ -287,14 +287,14 @@ func (fr *funcRetTemplate) Fmt(ngo bool) string { | |||||
| 287 | after.WriteString(val) | 287 | after.WriteString(val) | ||
| 288 | after.WriteString(",") | 288 | after.WriteString(",") | ||
| 289 | } | 289 | } | ||
| 290 | - | after.WriteString( "nil\n") | 290 | + | after.WriteString("nil\n") |
| 291 | after.WriteString("}\n") | 291 | after.WriteString("}\n") | ||
| 292 | after.WriteString("return ") | 292 | after.WriteString("return ") | ||
| 293 | if fr.Value != "" { | 293 | if fr.Value != "" { | ||
| 294 | after.WriteString(val) | 294 | after.WriteString(val) | ||
| 295 | after.WriteString(",") | 295 | after.WriteString(",") | ||
| 296 | } | 296 | } | ||
| 297 | - | after.WriteString( "cerr\n") | 297 | + | after.WriteString("cerr\n") |
| 298 | return after.String() | 298 | return after.String() | ||
| 299 | } | 299 | } | ||
| 300 | after.WriteString("return ") | 300 | after.WriteString("return ") | ||
| @@ -322,11 +322,11 @@ type InterfaceFuncTemplate struct { | |||||
| 322 | } | 322 | } | ||
| 323 | 323 | ||||
| 324 | type SignalsTemplate struct { | 324 | type SignalsTemplate struct { | ||
| 325 | - | Doc string | 325 | + | Doc string |
| 326 | - | Name string | 326 | + | Name string |
| 327 | - | CName string | 327 | + | CName string |
| 328 | - | Args funcArgsTemplate | 328 | + | Args funcArgsTemplate |
| 329 | - | Ret funcRetTemplate | 329 | + | Ret funcRetTemplate |
| 330 | } | 330 | } | ||
| 331 | 331 | ||||
| 332 | type ClassTemplate struct { | 332 | type ClassTemplate struct { | ||
M internal/gir/types/types.go +1 -1
| @@ -694,6 +694,6 @@ func (r *ReturnValue) Template(ns string, ins string, kinds KindMap, throws bool | |||
| 694 | 694 | Value: val, | |
| 695 | 695 | Class: class, | |
| 696 | 696 | RefSink: r.TransferOwnership.TransferOwnership == "none", | |
| 697 | - | Throws: throws, | |
| 697 | + | Throws: throws, | |
| 698 | 698 | } | |
| 699 | 699 | } | |
| @@ -694,6 +694,6 @@ func (r *ReturnValue) Template(ns string, ins string, kinds KindMap, throws bool | |||||
| 694 | Value: val, | 694 | Value: val, | ||
| 695 | Class: class, | 695 | Class: class, | ||
| 696 | RefSink: r.TransferOwnership.TransferOwnership == "none", | 696 | RefSink: r.TransferOwnership.TransferOwnership == "none", | ||
| 697 | - | Throws: throws, | 697 | + | Throws: throws, |
| 698 | } | 698 | } | ||
| 699 | } | 699 | } | ||
M templates/gobject +12 -5
| @@ -18,7 +18,7 @@ func ConvertPtr(a interface{}) *uintptr { | |||
| 18 | 18 | return nil | |
| 19 | 19 | } | |
| 20 | 20 | ptr := reflect.ValueOf(a).Elem() | |
| 21 | - | v, ok := ptr.Interface().(Ptr); | |
| 21 | + | v, ok := ptr.Interface().(Ptr) | |
| 22 | 22 | if !ok { | |
| 23 | 23 | panic("not valid") | |
| 24 | 24 | } | |
| @@ -27,7 +27,7 @@ func ConvertPtr(a interface{}) *uintptr { | |||
| 27 | 27 | } | |
| 28 | 28 | ||
| 29 | 29 | func IncreaseRef(a uintptr) { | |
| 30 | - | xObjectRefSink(a) | |
| 30 | + | xObjectRefSink(a) | |
| 31 | 31 | } | |
| 32 | 32 | ||
| 33 | 33 | func ObjectConnect(a uintptr, b string, c ...interface{}) uintptr { | |
| @@ -72,10 +72,10 @@ const ( | |||
| 72 | 72 | TypeReservedUserFirstVal = 49 << 2 | |
| 73 | 73 | ) | |
| 74 | 74 | ||
| 75 | - | var xValueDupString func(*Value) string | |
| 75 | + | var xValueGetString func(*Value) string | |
| 76 | 76 | ||
| 77 | 77 | func (v *Value) String() string { | |
| 78 | - | return xValueDupString(v) | |
| 78 | + | return xValueGetString(v) | |
| 79 | 79 | } | |
| 80 | 80 | ||
| 81 | 81 | var xValueGetInt func(*Value) int | |
| @@ -84,11 +84,18 @@ func (v *Value) Int() int { | |||
| 84 | 84 | return xValueGetInt(v) | |
| 85 | 85 | } | |
| 86 | 86 | ||
| 87 | + | var xValueUnset func(*Value) | |
| 88 | + | ||
| 89 | + | func (x *Value) Unset() { | |
| 90 | + | xValueUnset(x) | |
| 91 | + | } | |
| 92 | + | ||
| 87 | 93 | func init() { | |
| 88 | 94 | lib, err := purego.Dlopen(os.Getenv("PUREGOTK_GTK_PATH"), purego.RTLD_NOW|purego.RTLD_GLOBAL) | |
| 89 | 95 | if err != nil { | |
| 90 | 96 | panic(err) | |
| 91 | 97 | } | |
| 92 | - | core.PuregoSafeRegister(&xValueDupString, lib, "g_value_dup_string") | |
| 98 | + | core.PuregoSafeRegister(&xValueGetString, lib, "g_value_get_string") | |
| 93 | 99 | core.PuregoSafeRegister(&xValueGetInt, lib, "g_value_get_int") | |
| 100 | + | core.PuregoSafeRegister(&xValueUnset, lib, "g_value_unset") | |
| 94 | 101 | } | |
| @@ -18,7 +18,7 @@ func ConvertPtr(a interface{}) *uintptr { | |||||
| 18 | return nil | 18 | return nil | ||
| 19 | } | 19 | } | ||
| 20 | ptr := reflect.ValueOf(a).Elem() | 20 | ptr := reflect.ValueOf(a).Elem() | ||
| 21 | - | v, ok := ptr.Interface().(Ptr); | 21 | + | v, ok := ptr.Interface().(Ptr) |
| 22 | if !ok { | 22 | if !ok { | ||
| 23 | panic("not valid") | 23 | panic("not valid") | ||
| 24 | } | 24 | } | ||
| @@ -27,7 +27,7 @@ func ConvertPtr(a interface{}) *uintptr { | |||||
| 27 | } | 27 | } | ||
| 28 | 28 | ||||
| 29 | func IncreaseRef(a uintptr) { | 29 | func IncreaseRef(a uintptr) { | ||
| 30 | - | xObjectRefSink(a) | 30 | + | xObjectRefSink(a) |
| 31 | } | 31 | } | ||
| 32 | 32 | ||||
| 33 | func ObjectConnect(a uintptr, b string, c ...interface{}) uintptr { | 33 | func ObjectConnect(a uintptr, b string, c ...interface{}) uintptr { | ||
| @@ -72,10 +72,10 @@ const ( | |||||
| 72 | TypeReservedUserFirstVal = 49 << 2 | 72 | TypeReservedUserFirstVal = 49 << 2 | ||
| 73 | ) | 73 | ) | ||
| 74 | 74 | ||||
| 75 | - | var xValueDupString func(*Value) string | 75 | + | var xValueGetString func(*Value) string |
| 76 | 76 | ||||
| 77 | func (v *Value) String() string { | 77 | func (v *Value) String() string { | ||
| 78 | - | return xValueDupString(v) | 78 | + | return xValueGetString(v) |
| 79 | } | 79 | } | ||
| 80 | 80 | ||||
| 81 | var xValueGetInt func(*Value) int | 81 | var xValueGetInt func(*Value) int | ||
| @@ -84,11 +84,18 @@ func (v *Value) Int() int { | |||||
| 84 | return xValueGetInt(v) | 84 | return xValueGetInt(v) | ||
| 85 | } | 85 | } | ||
| 86 | 86 | ||||
| 87 | + | var xValueUnset func(*Value) | |||
| 88 | + | ||||
| 89 | + | func (x *Value) Unset() { | |||
| 90 | + | xValueUnset(x) | |||
| 91 | + | } | |||
| 92 | + | ||||
| 87 | func init() { | 93 | func init() { | ||
| 88 | lib, err := purego.Dlopen(os.Getenv("PUREGOTK_GTK_PATH"), purego.RTLD_NOW|purego.RTLD_GLOBAL) | 94 | lib, err := purego.Dlopen(os.Getenv("PUREGOTK_GTK_PATH"), purego.RTLD_NOW|purego.RTLD_GLOBAL) | ||
| 89 | if err != nil { | 95 | if err != nil { | ||
| 90 | panic(err) | 96 | panic(err) | ||
| 91 | } | 97 | } | ||
| 92 | - | core.PuregoSafeRegister(&xValueDupString, lib, "g_value_dup_string") | 98 | + | core.PuregoSafeRegister(&xValueGetString, lib, "g_value_get_string") |
| 93 | core.PuregoSafeRegister(&xValueGetInt, lib, "g_value_get_int") | 99 | core.PuregoSafeRegister(&xValueGetInt, lib, "g_value_get_int") | ||
| 100 | + | core.PuregoSafeRegister(&xValueUnset, lib, "g_value_unset") | |||
| 94 | } | 101 | } | ||
M v4/gobject/more.go +10 -3
| @@ -72,10 +72,10 @@ const ( | |||
| 72 | 72 | TypeReservedUserFirstVal = 49 << 2 | |
| 73 | 73 | ) | |
| 74 | 74 | ||
| 75 | - | var xValueDupString func(*Value) string | |
| 75 | + | var xValueGetString func(*Value) string | |
| 76 | 76 | ||
| 77 | 77 | func (v *Value) String() string { | |
| 78 | - | return xValueDupString(v) | |
| 78 | + | return xValueGetString(v) | |
| 79 | 79 | } | |
| 80 | 80 | ||
| 81 | 81 | var xValueGetInt func(*Value) int | |
| @@ -84,11 +84,18 @@ func (v *Value) Int() int { | |||
| 84 | 84 | return xValueGetInt(v) | |
| 85 | 85 | } | |
| 86 | 86 | ||
| 87 | + | var xValueUnset func(*Value) | |
| 88 | + | ||
| 89 | + | func (x *Value) Unset() { | |
| 90 | + | xValueUnset(x) | |
| 91 | + | } | |
| 92 | + | ||
| 87 | 93 | func init() { | |
| 88 | 94 | lib, err := purego.Dlopen(os.Getenv("PUREGOTK_GTK_PATH"), purego.RTLD_NOW|purego.RTLD_GLOBAL) | |
| 89 | 95 | if err != nil { | |
| 90 | 96 | panic(err) | |
| 91 | 97 | } | |
| 92 | - | core.PuregoSafeRegister(&xValueDupString, lib, "g_value_dup_string") | |
| 98 | + | core.PuregoSafeRegister(&xValueGetString, lib, "g_value_get_string") | |
| 93 | 99 | core.PuregoSafeRegister(&xValueGetInt, lib, "g_value_get_int") | |
| 100 | + | core.PuregoSafeRegister(&xValueUnset, lib, "g_value_unset") | |
| 94 | 101 | } | |
| @@ -72,10 +72,10 @@ const ( | |||||
| 72 | TypeReservedUserFirstVal = 49 << 2 | 72 | TypeReservedUserFirstVal = 49 << 2 | ||
| 73 | ) | 73 | ) | ||
| 74 | 74 | ||||
| 75 | - | var xValueDupString func(*Value) string | 75 | + | var xValueGetString func(*Value) string |
| 76 | 76 | ||||
| 77 | func (v *Value) String() string { | 77 | func (v *Value) String() string { | ||
| 78 | - | return xValueDupString(v) | 78 | + | return xValueGetString(v) |
| 79 | } | 79 | } | ||
| 80 | 80 | ||||
| 81 | var xValueGetInt func(*Value) int | 81 | var xValueGetInt func(*Value) int | ||
| @@ -84,11 +84,18 @@ func (v *Value) Int() int { | |||||
| 84 | return xValueGetInt(v) | 84 | return xValueGetInt(v) | ||
| 85 | } | 85 | } | ||
| 86 | 86 | ||||
| 87 | + | var xValueUnset func(*Value) | |||
| 88 | + | ||||
| 89 | + | func (x *Value) Unset() { | |||
| 90 | + | xValueUnset(x) | |||
| 91 | + | } | |||
| 92 | + | ||||
| 87 | func init() { | 93 | func init() { | ||
| 88 | lib, err := purego.Dlopen(os.Getenv("PUREGOTK_GTK_PATH"), purego.RTLD_NOW|purego.RTLD_GLOBAL) | 94 | lib, err := purego.Dlopen(os.Getenv("PUREGOTK_GTK_PATH"), purego.RTLD_NOW|purego.RTLD_GLOBAL) | ||
| 89 | if err != nil { | 95 | if err != nil { | ||
| 90 | panic(err) | 96 | panic(err) | ||
| 91 | } | 97 | } | ||
| 92 | - | core.PuregoSafeRegister(&xValueDupString, lib, "g_value_dup_string") | 98 | + | core.PuregoSafeRegister(&xValueGetString, lib, "g_value_get_string") |
| 93 | core.PuregoSafeRegister(&xValueGetInt, lib, "g_value_get_int") | 99 | core.PuregoSafeRegister(&xValueGetInt, lib, "g_value_get_int") | ||
| 100 | + | core.PuregoSafeRegister(&xValueUnset, lib, "g_value_unset") | |||
| 94 | } | 101 | } | ||