detached 4f772a5

Templates: Split platform-specific code into build-tagged templates

commit
4f772a561a1cf33f87bbfadb0229fd3f1621bf21
author
Peter Fern · · 2024-03-02 19:28 UTC
committer
Jeroen Wijenbergh · · 2024-03-05 11:56 UTC
parent
1c4bd82
signature
unsigned
5 files · +62 -19
M gen.go +12 -0
@@ -48,4 +48,16 @@ func main() {
4848 if err == nil {
4949 os.WriteFile("v4/glib/more.go", data, 0o644)
5050 }
51+ data, err = os.ReadFile("templates/glib_sysv")
52+ if err == nil {
53+ os.WriteFile("v4/glib/more_sysv.go", data, 0o644)
54+ }
55+ data, err = os.ReadFile("templates/glib_windows")
56+ if err == nil {
57+ os.WriteFile("v4/glib/more_windows.go", data, 0o644)
58+ }
59+ data, err = os.ReadFile("templates/glib_other")
60+ if err == nil {
61+ os.WriteFile("v4/glib/more_other.go", data, 0o644)
62+ }
5163 }
@@ -48,4 +48,16 @@ func main() {
48 if err == nil {48 if err == nil {
49 os.WriteFile("v4/glib/more.go", data, 0o644)49 os.WriteFile("v4/glib/more.go", data, 0o644)
50 }50 }
51+ data, err = os.ReadFile("templates/glib_sysv")
52+ if err == nil {
53+ os.WriteFile("v4/glib/more_sysv.go", data, 0o644)
54+ }
55+ data, err = os.ReadFile("templates/glib_windows")
56+ if err == nil {
57+ os.WriteFile("v4/glib/more_windows.go", data, 0o644)
58+ }
59+ data, err = os.ReadFile("templates/glib_other")
60+ if err == nil {
61+ os.WriteFile("v4/glib/more_other.go", data, 0o644)
62+ }
51 }63 }
M templates/glib +5 -19
@@ -2,7 +2,6 @@ package glib
22
33 import (
44 "fmt"
5- "reflect"
65 "sync"
76
87 "github.com/jwijenbergh/purego"
@@ -34,25 +33,12 @@ func SaveCallback(cbPtr uintptr, refPtr uintptr) {
3433 }
3534
3635 // UnrefCallbackValue unreferences the provided callback by reflect.value to free a purego slot
36+//
37+// NOTE: Windows does not support unreferencing callbacks, so on that platform this operation is
38+// a NOOP, callback memory is never freed, and there is a limit on maximum total callbacks.
39+// See the purego documentation for further details.
3740 func UnrefCallback(fnPtr interface{}) error {
38- val := reflect.ValueOf(fnPtr)
39- if val.IsNil() {
40- return fmt.Errorf("function pointer must not be nil")
41- }
42- if val.Kind() != reflect.Ptr || val.Elem().Kind() != reflect.Func {
43- return fmt.Errorf("type must be a function pointer")
44- }
45- cbPtr := reflect.ValueOf(fnPtr).Pointer()
46- refPtr, ok := GetCallback(cbPtr)
47- if !ok {
48- return purego.UnrefCallbackFnPtr(fnPtr)
49- }
50- defer func() {
51- callbacks.Lock()
52- delete(callbacks.refs, cbPtr)
53- callbacks.Unlock()
54- }()
55- return purego.UnrefCallback(refPtr)
41+ return unrefCallback(fnPtr)
5642 }
5743
5844 // NewCallback is an alias to purego.NewCallback
@@ -2,7 +2,6 @@ package glib
2 2
3 import (3 import (
4 "fmt"4 "fmt"
5- "reflect"
6 "sync"5 "sync"
7 6
8 "github.com/jwijenbergh/purego"7 "github.com/jwijenbergh/purego"
@@ -34,25 +33,12 @@ func SaveCallback(cbPtr uintptr, refPtr uintptr) {
34 }33 }
35 34
36 // UnrefCallbackValue unreferences the provided callback by reflect.value to free a purego slot35 // UnrefCallbackValue unreferences the provided callback by reflect.value to free a purego slot
36+//
37+// NOTE: Windows does not support unreferencing callbacks, so on that platform this operation is
38+// a NOOP, callback memory is never freed, and there is a limit on maximum total callbacks.
39+// See the purego documentation for further details.
37 func UnrefCallback(fnPtr interface{}) error {40 func UnrefCallback(fnPtr interface{}) error {
38- val := reflect.ValueOf(fnPtr)41+ return unrefCallback(fnPtr)
39- if val.IsNil() {
40- return fmt.Errorf("function pointer must not be nil")
41- }
42- if val.Kind() != reflect.Ptr || val.Elem().Kind() != reflect.Func {
43- return fmt.Errorf("type must be a function pointer")
44- }
45- cbPtr := reflect.ValueOf(fnPtr).Pointer()
46- refPtr, ok := GetCallback(cbPtr)
47- if !ok {
48- return purego.UnrefCallbackFnPtr(fnPtr)
49- }
50- defer func() {
51- callbacks.Lock()
52- delete(callbacks.refs, cbPtr)
53- callbacks.Unlock()
54- }()
55- return purego.UnrefCallback(refPtr)
56 }42 }
57 43
58 // NewCallback is an alias to purego.NewCallback44 // NewCallback is an alias to purego.NewCallback
A templates/glib_other +8 -0
@@ -0,0 +1,8 @@
1+//go:build !windows && !darwin && !freebsd && (!linux || (!amd64 && !arm64))
2+
3+package glib
4+
5+// unrefCallback on unsupported on other platforms
6+func unrefCallback(_ interface{}) error {
7+ panic("glib.UnrefCallback is unsupported on this platform")
8+}
@@ -0,0 +1,8 @@
1+//go:build !windows && !darwin && !freebsd && (!linux || (!amd64 && !arm64))
2+
3+package glib
4+
5+// unrefCallback on unsupported on other platforms
6+func unrefCallback(_ interface{}) error {
7+ panic("glib.UnrefCallback is unsupported on this platform")
8+}
A templates/glib_sysv +31 -0
@@ -0,0 +1,31 @@
1+//go:build darwin || freebsd || (linux && (amd64 || arm64))
2+
3+package glib
4+
5+import (
6+ "fmt"
7+ "reflect"
8+
9+ "github.com/jwijenbergh/purego"
10+)
11+
12+func unrefCallback(fnPtr interface{}) error {
13+ val := reflect.ValueOf(fnPtr)
14+ if val.IsNil() {
15+ return fmt.Errorf("function pointer must not be nil")
16+ }
17+ if val.Kind() != reflect.Ptr || val.Elem().Kind() != reflect.Func {
18+ return fmt.Errorf("type must be a function pointer")
19+ }
20+ cbPtr := reflect.ValueOf(fnPtr).Pointer()
21+ refPtr, ok := GetCallback(cbPtr)
22+ if !ok {
23+ return purego.UnrefCallbackFnPtr(fnPtr)
24+ }
25+ defer func() {
26+ callbacks.Lock()
27+ delete(callbacks.refs, cbPtr)
28+ callbacks.Unlock()
29+ }()
30+ return purego.UnrefCallback(refPtr)
31+}
@@ -0,0 +1,31 @@
1+//go:build darwin || freebsd || (linux && (amd64 || arm64))
2+
3+package glib
4+
5+import (
6+ "fmt"
7+ "reflect"
8+
9+ "github.com/jwijenbergh/purego"
10+)
11+
12+func unrefCallback(fnPtr interface{}) error {
13+ val := reflect.ValueOf(fnPtr)
14+ if val.IsNil() {
15+ return fmt.Errorf("function pointer must not be nil")
16+ }
17+ if val.Kind() != reflect.Ptr || val.Elem().Kind() != reflect.Func {
18+ return fmt.Errorf("type must be a function pointer")
19+ }
20+ cbPtr := reflect.ValueOf(fnPtr).Pointer()
21+ refPtr, ok := GetCallback(cbPtr)
22+ if !ok {
23+ return purego.UnrefCallbackFnPtr(fnPtr)
24+ }
25+ defer func() {
26+ callbacks.Lock()
27+ delete(callbacks.refs, cbPtr)
28+ callbacks.Unlock()
29+ }()
30+ return purego.UnrefCallback(refPtr)
31+}
A templates/glib_windows +6 -0
@@ -0,0 +1,6 @@
1+package glib
2+
3+// unrefCallback on Windows is a NOOP.
4+func unrefCallback(_ interface{}) error {
5+ return nil
6+}
@@ -0,0 +1,6 @@
1+package glib
2+
3+// unrefCallback on Windows is a NOOP.
4+func unrefCallback(_ interface{}) error {
5+ return nil
6+}

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