Resolve struct field types and byte offsets in the parsed IDL#45
Merged
estebanzimanyi merged 1 commit intoJul 10, 2026
Merged
Conversation
0bda23c to
a47cc0b
Compare
Struct field types and byte offsets in meos-idl.json come out FFI-accurate when run.py parses the installed MEOS headers instead of the source tree. `make install` writes the generated, self-contained headers — meos_export.h splices postgres_ext_defs.in.h in place of the source's `#include <postgres.h>` — so libclang resolves the bool / uint8 / Datum fields and their real byte offsets rather than degrading every field to int at offset -1 (unusable for the FFI bindings' #[repr(C)] structs and cgo/cffi field access). - The provision-meos action, on the build-libmeos path, stages the MEOS headers into a dedicated prefix and derives the catalog from there. A shared prefix like /usr/local/include carries unrelated system headers (OpenSSL, PostgreSQL) that run.py's header glob would otherwise pull into the catalog; the dedicated prefix holds only MEOS headers. The catalog-only path keeps the source-tree parse. - parser.py adds the compiler's own system include search path (from `clang -E -v`) so <stdbool.h> / <stddef.h> / size_t resolve; size_t is force-included because meos.h uses it without an explicit include. - extract_struct runs field types through _c_spelling, normalising clang's _Bool keyword to the catalog's bool spelling. - pytest.yml builds libmeos, derives the installed catalog, and runs the suite. - tests/test_struct_layout.py guards the resolved Span / STBox / TInstant layouts. Span resolves to spantype:uint8@0, basetype:uint8@8, lower_inc:bool@16, upper_inc:bool@24, padding:char[4]@32, lower:Datum@64, upper:Datum@128.
a47cc0b to
6872fa9
Compare
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.
The catalog derives its struct layouts from the installed MEOS headers, giving FFI consumers (
#[repr(C)]structs, cgo/cffi field access) accurate field types and byte offsets.Where the layout comes from. The install step writes the generated, self-contained headers:
meos_export.hsplicespostgres_ext_defs.in.hin place of the source tree's#include <postgres.h>. Parsing those headers, libclang resolves each field to its real C type and byte offset instead of degrading it tointat offset-1.provision-meos. On thebuild-libmeos: truepath the action builds libmeos and stages the MEOS headers into a dedicated prefix, then derivesmeos-idl.jsonfrom that prefix. A shared prefix such as/usr/local/includecarries unrelated system headers (OpenSSL, PostgreSQL) that the header glob would pull into the catalog; the dedicated prefix holds only MEOS headers. The catalog-only path (build-libmeos: false) keeps the source-tree parse.Parser.
_clang_extra_argsadds the compiler's own system include search path (fromclang -E -v) so<stdbool.h>/<stddef.h>/size_tresolve — the piplibclangwheel ships no configured search path.size_tis force-included becausemeos.huses it without an explicit#include.extract_structruns field types through_c_spelling, normalising clang's_Boolkeyword to the catalog'sboolspelling.CI. The
testsworkflow builds all-families libmeos through the action, derives the catalog from the staged headers, and runs the suite.tests/test_struct_layout.pyasserts theSpan/STBox/TInstantlayouts, that no field carries the_Boolkeyword, and that every CORE-family struct field has a resolved offset.