v0.6.0 d4696de

arena.go RawHistoryFolder

1package server
2
3import (
4	"encoding/binary"
5	"fmt"
6	"unsafe"
7
8	"golang.org/x/sys/unix"
9)
10
11// arena is C-visible memory the Go GC never moves or frees. It holds
12// wl_interface and wl_message tables and their strings for the whole
13// process lifetime. It grows by mapping new chunks; chunks are never unmapped.
14type arena struct {
15	mem  []byte
16	base uintptr
17	off  int
18}
19
20const arenaChunk = 1 << 20
21
22func (a *arena) grow(n int) error {
23	size := max(arenaChunk, n)
24	mem, err := unix.Mmap(-1, 0, size, unix.PROT_READ|unix.PROT_WRITE, unix.MAP_PRIVATE|unix.MAP_ANONYMOUS)
25	if err != nil {
26		return fmt.Errorf("purego-libwayland: arena mmap: %w", err)
27	}
28	a.mem, a.base, a.off = mem, uintptr(unsafe.Pointer(&mem[0])), 0
29	return nil
30}
31
32// reserve makes sure n more bytes fit in the current chunk. Callers reserve
33// the whole size of a table set up front so offsets stay in one chunk.
34func (a *arena) reserve(n int) error {
35	if a.mem != nil && ((a.off+7)&^7)+n <= len(a.mem) {
36		return nil
37	}
38	return a.grow(n)
39}
40
41// alloc returns the offset and C address of n zeroed, 8-byte aligned bytes.
42func (a *arena) alloc(n int) (int, uintptr) {
43	a.off = (a.off + 7) &^ 7
44	if a.off+n > len(a.mem) {
45		panic("purego-libwayland: arena reservation too small")
46	}
47	off := a.off
48	a.off += n
49	return off, a.base + uintptr(off)
50}
51
52func (a *arena) cstring(s string) uintptr {
53	off, addr := a.alloc(len(s) + 1)
54	copy(a.mem[off:], s)
55	return addr
56}
57
58func (a *arena) putPtr(off int, v uintptr) { binary.LittleEndian.PutUint64(a.mem[off:], uint64(v)) }
59func (a *arena) putI32(off int, v int32)   { binary.LittleEndian.PutUint32(a.mem[off:], uint32(v)) }

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 14

↑↓ moveenter openesc close