Repository navigation
Fix value conversions, Lua string coercion and stream reads - #394
Merged
Merged
Conversation
Reject out-of-range int, long, uint and ulong reads before casting, using exclusive double upper bounds for 64-bit targets. TryRead returns false instead of clamping or throwing, and generated argument errors remain Lua errors. Read booleans as boxed bool values for object-typed interop. Advance StringStream after its full-content fast path. Scan leading whitespace once for memory-backed numeric reads and preserve nonnumeric input when conversion fails. Use a shared Lua-library string reader that accepts numeric arguments in the selected platform format and updates the argument slot like Lua 5.2. Keep public typed C# string reads strict and preserve caller values across reentrant callbacks. Add 54 regression cases for integer boundaries, boxing, generated bindings, stream cursor sequences, numeric string arguments, format policies and reentrant debug inspection. The original binary fails the regression cases for all five bugs; native Lua 5.2 confirms the argument-slot behavior. Validation: 2,697 runtime tests pass on each of .NET 8 and .NET 10, plus 73 generator tests. Release solution build passes for all four runtime targets with no warnings. CSharpier, diff checks and benchmark --verify pass. Paired .NET 10 samples show string workloads 6-10% faster, unchanged allocations and no host-call slowdown. Direct signed integer reads add about 2% for range validation; unsigned reads improve after eliminating checked conversion helpers.
Read file:seek offsets as long to match ILuaStream.Seek and FileHandle.Seek. This avoids a 32-bit restriction when the underlying .NET stream supports larger offsets and keeps range validation at the existing conversion boundary. Lua 5.2 likewise sizes offsets for its configured file backend. Add a position-only regression covering a 3 GB absolute seek, querying the position, and a negative relative offset beyond Int32 range. The original binary fails this case; no large files or buffers are created by the test. Validation: Release solution builds all runtime targets without warnings. All 77 focused conversion, memory-stream, file-seek and I/O tests pass on .NET 8 and .NET 10. CSharpier and diff checks pass.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fix incorrect C# value conversions, memory-stream consumption and Lua library string arguments.
int,long,uintandulongconversions before casting.TryReadreturns false instead of clamping or throwing; generated bindings report Lua argument errors. Exclusive double upper bounds handle the rounded 64-bit maxima correctly.Read<object>(), preserving object-typed C# arguments and round trips.StringStreamafter reading all content, and preserve nonnumeric input after a failed memory-stream number read. Leading whitespace is scanned once.file:seekoffsets aslong, matching the stream API and supporting positions beyond 2 GiB.For example,
string.len(123)now returns 3, reading all of a string-backed stream leaves it at EOF, and reading a number fromx12leavesx12available for the next read.Validation
debug.getlocal.--verifypass.