Skip to content

Take the array the each family fills rather than making one - #38

Merged
estebanzimanyi merged 1 commit into
MobilityDB:mainfrom
estebanzimanyi:fix/each-fills-the-callers-array
Sep 3, 2026
Merged

Take the array the each family fills rather than making one#38
estebanzimanyi merged 1 commit into
MobilityDB:mainfrom
estebanzimanyi:fix/each-fills-the-callers-array

Conversation

@estebanzimanyi

Copy link
Copy Markdown
Member

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.

`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.
@estebanzimanyi
estebanzimanyi merged commit b484615 into MobilityDB:main Sep 3, 2026
1 check passed
@estebanzimanyi
estebanzimanyi deleted the fix/each-fills-the-callers-array branch September 3, 2026 13:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant