One function
Lazy in construct/construct
The author described this change as “Bug #938 fixed (thanks Henrique)”. It counts as a record because the check below fails on the code as it stood at 3d5d67f50 and passes on 188b0c709, with nothing else changed between the two runs.
Projectconstruct/construct
Fix saved2022-09-18
Sharing licenceMIT · LICENSE
Change size+1 −1
What the code was meant to do, written into the code itself as a docstring
Lazyfies a field. This wrapper allows you to do lazy parsing of individual fields inside a normal Struct (without using LazyStruct which may not work in every scenario). It is also used by KaitaiStruct compiler to emit `instances` because those are not processed greedily, and they may refer to other not yet parsed fields. Those are 2 entirely different applications but semantics are the same. Parsing saves the current stream offset and returns a lambda. If and when that lambda gets evaluated, it seeks the stream to then-current position, parses the subcon, and seeks the stream back to previous position. Building evaluates that lambda into an object (if needed), then defers to subcon. Size also defers to subcon. :param subcon: Construct instance :raises StreamError: requested reading negative amount, could not read enough bytes, requested writing different amount than actual data, or could not write all bytes :raises StreamError: stream is not seekable and tellable Example::
The change
| 38 | 38 | obj = self.subcon._parsereport(stream, context, path) | |
| 39 | 39 | stream_seek(stream, fallback, 0, path) | |
| 40 | 40 | return obj | |
| 41 | - | len = self.subcon._actualsize(self, context, path) | |
| 41 | + | len = self.subcon._actualsize(stream, context, path) | |
| 42 | 42 | stream_seek(stream, len, 1, path) | |
| 43 | 43 | return execute | |
| 44 | 44 |
The check that tells the two apart
fail→pass·tests/test_core.py::test_lazy_issue_938
Check file tests/test_core.py, taken without changes from the fix and copied onto the older code, so the exact same check runs against both versions.
Origin and history
The code before it3d5d67f50499047dfbe4058ebacc234ec204fad2
Broken version dated2022-09-18
Moduleconstruct.core
Units changedLazy
Fingerprint0cf5230bd6a21ac1
Checked2026-08-18 by goldset/0.1
Every field above is generated by our program. None of it is written by hand.
Other bugs found in construct/construct
- 2018-05-05Fix issue #709: Hex() might not always work.
- 2018-04-02VarInt
- 2018-03-03TransformData
- 2017-10-08FIX: Left-shift operator (#406)
- 2017-08-29Switch
- 2017-06-01RawCopy