authorgravatar for elbeaston@gmail.comLachlan Easton <elbeaston@gmail.com> 2019-12-17 03:01:02+11:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2019-12-16 11:01:02-05:00
logfe0e8c87b762aba6eb5ff1fad8ad7d37404476f1
tree47045f781e6b478b97778dc3d3a3a181f98526ad
parent0f09ff49235e77af06056d3b5cdca0098aa050c3

Tokenizer: Copy optional tokens prior to being set to null #3737 (#3910)

* Tokenizer: Copy optional tokens prior to being set to null #3737 * Add TODO comments, reminder to audit copying optional pattern.

2 files changed, 7 insertions(+), 2 deletions(-)

lib/std/json.zig+1
......@@ -886,6 +886,7 @@ pub const TokenStream = struct {
886886
887887 pub fn next(self: *TokenStream) Error!?Token {
888888 if (self.token) |token| {
889 // TODO: Audit this pattern once #2915 is closed
889890 const copy = token;
890891 self.token = null;
891892 return copy;
lib/std/zig/tokenizer.zig+6-2
......@@ -411,8 +411,10 @@ pub const Tokenizer = struct {
411411
412412 pub fn next(self: *Tokenizer) Token {
413413 if (self.pending_invalid_token) |token| {
414 // TODO: Audit this pattern once #2915 is closed
415 const copy = token;
414416 self.pending_invalid_token = null;
415 return token;
417 return copy;
416418 }
417419 const start_index = self.index;
418420 var state = State.Start;
......@@ -1265,8 +1267,10 @@ pub const Tokenizer = struct {
12651267
12661268 if (result.id == Token.Id.Eof) {
12671269 if (self.pending_invalid_token) |token| {
1270 // TODO: Audit this pattern once #2915 is closed
1271 const copy = token;
12681272 self.pending_invalid_token = null;
1269 return token;
1273 return copy;
12701274 }
12711275 }
12721276