Repository navigation
feat: external decode context for BER/CER (-fno-ctx-members), Phase 0 - #17
Merged
Merged
Conversation
…#15) New opt-in codegen flag -fno-ctx-members: generated constructed structs omit the asn_struct_ctx_t _asn_ctx member and carry the ASN_CTX_OFFSET_EXTERNAL sentinel in their specifics (PCTX_DEF/OUT_CTX_OFFSET in asn1c_C.c). Default output is unchanged. Runtime: new asn_struct_external_ctx_t arena (8 inline frames + heap overflow, frames keyed by struct instance address) in constr_TYPE.h/.c, carried in asn_codec_ctx_t.ext_struct_ctx. All decoder ctx fetch sites now go through asn_get_struct_ctx() (arena when present, embedded offset otherwise, clean RC_FAIL on sentinel without arena), free paths and layout guards are sentinel-aware, and per-codec SET prepare helpers take the codec ctx. New entry points ber_decode_ctx() and asn_decode_ctx(); plain ber_decode()/asn_decode() fail cleanly on -fno-ctx-members code. New macros ASN_STRUCT_FREE_CTX/ASN_STRUCT_RESET_CTX (existing free_struct + arena reset). No asn_TYPE_operation_s change. Tests: tests-asn1c-compiler expected output for -P -fno-ctx-members (610-ext-ctx-ber); tests-c-compiler drivers check-610.c (default mode, embedded ctx chunked BER decode) and check-610.-fno-ctx-members.c (ber_decode_ctx full/1B/3B chunked, plain-decode RC_FAIL contract, RESET_CTX re-decode). ChangeLog, man page, design doc status updated. Local verification: tests-asn1c-compiler 14/14, tests-skeletons 70/70, check-610 pair PASS under ASAN/LSAN; generated NetMsg sizeof 104 -> 32. Generated by Mistral Vibe. Co-Authored-By: Mistral Vibe <vibe@mistral.ai> Co-authored-by: sleevetosleeve <sleevetosleeve@users.noreply.github.com>
check_fixer (libasn1fix) requires every *.asn1 in tests-asn1c-compiler to carry a -OK./-NP./-SE./-SW. suffix; the new ext-ctx module now does. Generated by Mistral Vibe. Co-Authored-By: Mistral Vibe <vibe@mistral.ai> Co-authored-by: sleevetosleeve <sleevetosleeve@users.noreply.github.com>
3 of 4 tasks
This was referenced Nov 27, 2026
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.
Summary
Implements Phase 0 (BER/CER) of the external decode context design (
docs/external-ctx-design.md) for issue #15:-fno-ctx-members: generated constructed structs omit theasn_struct_ctx_t _asn_ctxmember and emit theASN_CTX_OFFSET_EXTERNALsentinel in their specifics. Default output is byte-identical to before.asn_struct_external_ctx_tarena (8 inline frames + heap overflow, frames keyed by struct instance address) defined inskeletons/constr_TYPE.h, implemented inconstr_TYPE.c, carried inasn_codec_ctx_t.ext_struct_ctx. All decoder ctx fetch sites go throughasn_get_struct_ctx()(arena when present, embedded offset otherwise, cleanRC_FAILon sentinel without arena); free paths (constr_SEQUENCE.c,constr_SET.c,constr_SET_OF.c,OCTET_STRING.c) and all layout guards are sentinel-aware.ber_decode_ctx()andasn_decode_ctx(); plainber_decode()/asn_decode()fail cleanly on-fno-ctx-memberscode (contract tested). New macrosASN_STRUCT_FREE_CTX/ASN_STRUCT_RESET_CTX. Noasn_TYPE_operation_schange (decided in the design).asn1cman page, design-doc status.Related issues
-fno-ctx-members) #15 (feature request; this PR is Phase 0 — later phases XER/JER, OER, UPER/APER, CBOR follow separately, so this does not close it)Type of change
Testing
Local (sandbox toolchain: autoconf 2.71 / automake 1.16.5 / bison 3.8.2 / flex 2.6.4):
tests/tests-asn1c-compiler: 14/14 PASS, including the new610-ext-ctx-ber.asn1.+-P_-fno-ctx-membersexpected-output test (7 sentinels, 0_asn_ctxmembers).tests/tests-skeletons: 70/70 PASS.tests/tests-c-compiler: newcheck-610.c(default mode, embedded-ctx chunked BER decode) andcheck-610.-fno-ctx-members.c(ber_decode_ctxfull/1-byte/3-byte chunked, plain-ber_decodeRC_FAILcontract,ASN_STRUCT_RESET_CTXre-decode) — PASS under ASAN/LSAN.sizeof(NetMsg_t)104 (default) vs 32 (-fno-ctx-members); round-trips identical in both modes.Checklist
vlm_master