detached 91c587b

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 Unverified1A2298F6C34F96E5 The 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 {
7272 fn := filepath.Join(path, n)
7373 for _, s := range suffixes {
7474 if _, err := os.Stat(fn + s); err == nil {
75- return fn+s
75+ return fn + s
7676 }
7777 }
7878 }
@@ -138,8 +138,6 @@ func GetPath(name string) string {
138138 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))
139139 }
140140
141-
142-
143141 // GoString copies a char* to a Go string.
144142 // This function was copied from purego
145143 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+s75+ 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 purego142 // 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
216216 signals := make([]types.SignalsTemplate, len(cls.Signals))
217217 for i, s := range cls.Signals {
218218 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),
224224 }
225225 }
226226 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) {
7373 func (f *funcArgsTemplate) AddPure(t string, n string, k Kind) {
7474 n += "p"
7575 c := n
76- stars := strings.Count(t, "*")
76+ stars := strings.Count(t, "*")
7777 switch k {
7878 case RecordsType:
7979 if stars == 0 {
@@ -82,7 +82,7 @@ func (f *funcArgsTemplate) AddPure(t string, n string, k Kind) {
8282 case CallbackType:
8383 t = "uintptr"
8484 case ClassesType:
85- if stars == 0 {
85+ if stars == 0 {
8686 c = n
8787 t = "uintptr"
8888 } else {
@@ -212,7 +212,7 @@ type funcRetTemplate struct {
212212 func (fr *funcRetTemplate) Instance() string {
213213 val := fr.Value + "{}"
214214 if strings.HasPrefix(fr.Value, "*") {
215- return "&"+val[1:]
215+ return "&" + val[1:]
216216 }
217217 return val
218218 }
@@ -287,14 +287,14 @@ func (fr *funcRetTemplate) Fmt(ngo bool) string {
287287 after.WriteString(val)
288288 after.WriteString(",")
289289 }
290- after.WriteString( "nil\n")
290+ after.WriteString("nil\n")
291291 after.WriteString("}\n")
292292 after.WriteString("return ")
293293 if fr.Value != "" {
294294 after.WriteString(val)
295295 after.WriteString(",")
296296 }
297- after.WriteString( "cerr\n")
297+ after.WriteString("cerr\n")
298298 return after.String()
299299 }
300300 after.WriteString("return ")
@@ -322,11 +322,11 @@ type InterfaceFuncTemplate struct {
322322 }
323323
324324 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
330330 }
331331
332332 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 := n75 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 = n86 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 val217 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 string325+ Doc string
326- Name string326+ Name string
327- CName string327+ CName string
328- Args funcArgsTemplate328+ Args funcArgsTemplate
329- Ret funcRetTemplate329+ 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
694694 Value: val,
695695 Class: class,
696696 RefSink: r.TransferOwnership.TransferOwnership == "none",
697- Throws: throws,
697+ Throws: throws,
698698 }
699699 }
@@ -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 {
1818 return nil
1919 }
2020 ptr := reflect.ValueOf(a).Elem()
21- v, ok := ptr.Interface().(Ptr);
21+ v, ok := ptr.Interface().(Ptr)
2222 if !ok {
2323 panic("not valid")
2424 }
@@ -27,7 +27,7 @@ func ConvertPtr(a interface{}) *uintptr {
2727 }
2828
2929 func IncreaseRef(a uintptr) {
30- xObjectRefSink(a)
30+ xObjectRefSink(a)
3131 }
3232
3333 func ObjectConnect(a uintptr, b string, c ...interface{}) uintptr {
@@ -72,10 +72,10 @@ const (
7272 TypeReservedUserFirstVal = 49 << 2
7373 )
7474
75-var xValueDupString func(*Value) string
75+var xValueGetString func(*Value) string
7676
7777 func (v *Value) String() string {
78- return xValueDupString(v)
78+ return xValueGetString(v)
7979 }
8080
8181 var xValueGetInt func(*Value) int
@@ -84,11 +84,18 @@ func (v *Value) Int() int {
8484 return xValueGetInt(v)
8585 }
8686
87+var xValueUnset func(*Value)
88+
89+func (x *Value) Unset() {
90+ xValueUnset(x)
91+}
92+
8793 func init() {
8894 lib, err := purego.Dlopen(os.Getenv("PUREGOTK_GTK_PATH"), purego.RTLD_NOW|purego.RTLD_GLOBAL)
8995 if err != nil {
9096 panic(err)
9197 }
92- core.PuregoSafeRegister(&xValueDupString, lib, "g_value_dup_string")
98+ core.PuregoSafeRegister(&xValueGetString, lib, "g_value_get_string")
9399 core.PuregoSafeRegister(&xValueGetInt, lib, "g_value_get_int")
100+ core.PuregoSafeRegister(&xValueUnset, lib, "g_value_unset")
94101 }
@@ -18,7 +18,7 @@ func ConvertPtr(a interface{}) *uintptr {
18 return nil18 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 << 272 TypeReservedUserFirstVal = 49 << 2
73 )73 )
74 74
75-var xValueDupString func(*Value) string75+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) int81 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 (
7272 TypeReservedUserFirstVal = 49 << 2
7373 )
7474
75-var xValueDupString func(*Value) string
75+var xValueGetString func(*Value) string
7676
7777 func (v *Value) String() string {
78- return xValueDupString(v)
78+ return xValueGetString(v)
7979 }
8080
8181 var xValueGetInt func(*Value) int
@@ -84,11 +84,18 @@ func (v *Value) Int() int {
8484 return xValueGetInt(v)
8585 }
8686
87+var xValueUnset func(*Value)
88+
89+func (x *Value) Unset() {
90+ xValueUnset(x)
91+}
92+
8793 func init() {
8894 lib, err := purego.Dlopen(os.Getenv("PUREGOTK_GTK_PATH"), purego.RTLD_NOW|purego.RTLD_GLOBAL)
8995 if err != nil {
9096 panic(err)
9197 }
92- core.PuregoSafeRegister(&xValueDupString, lib, "g_value_dup_string")
98+ core.PuregoSafeRegister(&xValueGetString, lib, "g_value_get_string")
9399 core.PuregoSafeRegister(&xValueGetInt, lib, "g_value_get_int")
100+ core.PuregoSafeRegister(&xValueUnset, lib, "g_value_unset")
94101 }
@@ -72,10 +72,10 @@ const (
72 TypeReservedUserFirstVal = 49 << 272 TypeReservedUserFirstVal = 49 << 2
73 )73 )
74 74
75-var xValueDupString func(*Value) string75+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) int81 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 }

Keyboard shortcuts

Single-key shortcuts are on. ctrl k and esc work whatever this says.

ctrl k :
go to a section, branch, tag, file or repository
?
this list
j k
move the row cursor down / up
enter
open the row under the cursor; on Files, a directory opens or closes in place
↑ ↓ ← → home end
in the file tree (focus on a row): previous / next row, close / open a directory or go to its parent / first entry, first / last row. They never open a file
l h
on Files: open a directory or a file / close a directory or go up to its parent, then to the parent page. Elsewhere: into the side panel (on a merge request, its files) / back to the content; there j k move between its controls
g g G
first / last row
/
filter the list; on Files, find a file anywhere in the repository (esc clears, enter opens the best match)
b
switch branch or tag
g s g f g c g b g m g i g r g a
tabs: summary, files, commits, branches & tags, merge requests, issues, releases, actions (when available)
g h
home
w
wide mode: use the whole width of the screen, or not (remembered)
y
copy a permalink pinned to the commit
d u x
diff: split / unified / collapse or expand all
e E
diff: the whole file in view / every file, with the lines the hunks hide
n
merge request: next note in the diff
esc
close a dialog, leave a field

Branches 1

Tags 102

↑↓ moveenter openesc close