Take the array the each family fills rather than making one - #38
Merged
estebanzimanyi merged 1 commit intoSep 3, 2026
Merged
Conversation
`jsonb_each` and its seven siblings fill an array the CALLER allocates: MEOS writes one `Jsonb *` per member of the object into the storage the parameter points at, and states how many it wrote through the count. The catalog now says so, and the wrappers take that array — `JsonbEach(IntPtr jb, IntPtr values)` answering the keys — instead of allocating one pointer's worth of storage, handing MEOS the address of it, and reading the first pointer MEOS wrote as the address of an array. For an object of more than one member the old shape wrote past its allocation and then walked whatever the first written pointer aimed at. The object layer defers the four methods over that shape. Nothing in a class's signature says how many members the value it is called on has, so a method answering `each` cannot size the array the call needs; the flat wrapper, whose caller holds the value, is where the size is known. The layer emits 1349 methods over 115 classes with 11 deferred. Its own test allocates room for eight, reads the two keys and the two values MEOS wrote, and so states the contract the wrapper now keeps.
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.
jsonb_eachand its seven siblings fill an array the CALLER allocates: MEOSwrites one
Jsonb *per member of the object into the storage the parameterpoints at, and states how many it wrote through the count. The catalog now says
so, and the wrappers take that array —
JsonbEach(IntPtr jb, IntPtr values)answering the keys — instead of allocating one pointer's worth of storage,
handing MEOS the address of it, and reading the first pointer MEOS wrote as the
address of an array. For an object of more than one member the old shape wrote
past its allocation and then walked whatever the first written pointer aimed at.
The object layer defers the four methods over that shape. Nothing in a class's
signature says how many members the value it is called on has, so a method
answering
eachcannot size the array the call needs; the flat wrapper, whosecaller holds the value, is where the size is known.
The layer emits 1349 methods over 115 classes with 11 deferred. Its own test
allocates room for eight, reads the two keys and the two values MEOS wrote, and
so states the contract the wrapper now keeps.