mirror of
https://github.com/ghostty-org/ghostty.git
synced 2025-07-14 15:56:13 +03:00
cli: parseCLI for optionals should not be null in release modes
Fixes #2747 I admit I don't fully understand this. But somehow, doing `var x: ?T = undefined` in release fast mode makes `x` act as if its unset. I am guessing since undefined does nothing to the memory, the memory layout is such that it looks null for zeroed stack memory. This is a guess. To fix this, I now initialize the type `T` and set it onto the optional later. This commit also fixes an issue where calling `parseCLI` multiple times on an optional would not modify the previous value if set.
This commit is contained in:
@ -256,10 +256,20 @@ pub fn parseIntoField(
|
|||||||
.Enum,
|
.Enum,
|
||||||
=> try @field(dst, field.name).parseCLI(value),
|
=> try @field(dst, field.name).parseCLI(value),
|
||||||
|
|
||||||
.Optional => {
|
// If the field is optional and set, then we use
|
||||||
@field(dst, field.name) = undefined;
|
// the pointer value directly into it. If its not
|
||||||
try @field(dst, field.name).?.parseCLI(value);
|
// set we need to create a new instance.
|
||||||
|
.Optional => if (@field(dst, field.name)) |*v| {
|
||||||
|
try v.parseCLI(value);
|
||||||
|
} else {
|
||||||
|
// Note: you cannot do @field(dst, name) = undefined
|
||||||
|
// because this causes the value to be "null"
|
||||||
|
// in ReleaseFast modes.
|
||||||
|
var tmp: Field = undefined;
|
||||||
|
try tmp.parseCLI(value);
|
||||||
|
@field(dst, field.name) = tmp;
|
||||||
},
|
},
|
||||||
|
|
||||||
else => @compileError("unexpected field type"),
|
else => @compileError("unexpected field type"),
|
||||||
},
|
},
|
||||||
|
|
||||||
@ -270,10 +280,14 @@ pub fn parseIntoField(
|
|||||||
.Enum,
|
.Enum,
|
||||||
=> try @field(dst, field.name).parseCLI(alloc, value),
|
=> try @field(dst, field.name).parseCLI(alloc, value),
|
||||||
|
|
||||||
.Optional => {
|
.Optional => if (@field(dst, field.name)) |*v| {
|
||||||
@field(dst, field.name) = undefined;
|
try v.parseCLI(alloc, value);
|
||||||
try @field(dst, field.name).?.parseCLI(alloc, value);
|
} else {
|
||||||
|
var tmp: Field = undefined;
|
||||||
|
try tmp.parseCLI(alloc, value);
|
||||||
|
@field(dst, field.name) = tmp;
|
||||||
},
|
},
|
||||||
|
|
||||||
else => @compileError("unexpected field type"),
|
else => @compileError("unexpected field type"),
|
||||||
},
|
},
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user