mirror of
https://git.sr.ht/~eliasnaur/gio
synced 2026-07-01 15:45:38 +00:00
ui: fill out the MacroOp opcode in Record to support unfinished macros
Before this change MacroOp.Record simply reserved enough space for Stop to fill out. If a user Record but never Stop'ed a MacroOp, the resulting Ops buffer would end up with a zero, invalid opcode and panic at decode. Fill out an empty MacroOp at Record, ensuring the Ops remains valid. Signed-off-by: Elias Naur <mail@eliasnaur.com>
This commit is contained in:
@@ -157,8 +157,9 @@ func (m *MacroOp) Record(o *Ops) {
|
||||
m.recording = true
|
||||
m.ops = o
|
||||
m.pc = o.pc()
|
||||
// Make room for a macro definition. Filled out in Stop.
|
||||
// Reserve room for a macro definition. Updated in Stop.
|
||||
m.ops.Write(make([]byte, opconst.TypeMacroDefLen))
|
||||
m.fill()
|
||||
}
|
||||
|
||||
// Stop ends a previously started recording.
|
||||
@@ -167,6 +168,10 @@ func (m *MacroOp) Stop() {
|
||||
panic("not recording")
|
||||
}
|
||||
m.recording = false
|
||||
m.fill()
|
||||
}
|
||||
|
||||
func (m *MacroOp) fill() {
|
||||
pc := m.ops.pc()
|
||||
// Fill out the macro definition reserved in Record.
|
||||
data := m.ops.data[m.pc.data:]
|
||||
|
||||
Reference in New Issue
Block a user