Skip to content

feat: external decode context for BER/CER (-fno-ctx-members), Phase 0 - #17

Merged
sleevetosleeve merged 2 commits into
vlm_masterfrom
vibe/ext-ctx-phase0-d2e85d
Nov 26, 2026
Merged

sleevetosleeve merged 2 commits into
vlm_masterfrom
vibe/ext-ctx-phase0-d2e85d

Conversation

@sleevetosleeve

Copy link
Copy Markdown
Owner

Summary

Implements Phase 0 (BER/CER) of the external decode context design (docs/external-ctx-design.md) for issue #15:

  • New opt-in codegen flag -fno-ctx-members: generated constructed structs omit the asn_struct_ctx_t _asn_ctx member and emit the ASN_CTX_OFFSET_EXTERNAL sentinel in their specifics. Default output is byte-identical to before.
  • Runtime: asn_struct_external_ctx_t arena (8 inline frames + heap overflow, frames keyed by struct instance address) defined in skeletons/constr_TYPE.h, implemented in constr_TYPE.c, carried in asn_codec_ctx_t.ext_struct_ctx. All decoder ctx fetch sites go through asn_get_struct_ctx() (arena when present, embedded offset otherwise, clean RC_FAIL on 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.
  • New entry points ber_decode_ctx() and asn_decode_ctx(); plain ber_decode()/asn_decode() fail cleanly on -fno-ctx-members code (contract tested). New macros ASN_STRUCT_FREE_CTX / ASN_STRUCT_RESET_CTX. No asn_TYPE_operation_s change (decided in the design).
  • Docs: ChangeLog, asn1c man page, design-doc status.

Related issues

Type of change

  • New feature

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 new 610-ext-ctx-ber.asn1.+-P_-fno-ctx-members expected-output test (7 sentinels, 0 _asn_ctx members).
  • tests/tests-skeletons: 70/70 PASS.
  • tests/tests-c-compiler: new check-610.c (default mode, embedded-ctx chunked BER decode) and check-610.-fno-ctx-members.c (ber_decode_ctx full/1-byte/3-byte chunked, plain-ber_decode RC_FAIL contract, ASN_STRUCT_RESET_CTX re-decode) — PASS under ASAN/LSAN.
  • Manual: generated NetMsg-like module sizeof(NetMsg_t) 104 (default) vs 32 (-fno-ctx-members); round-trips identical in both modes.

Checklist

  • Up to date with vlm_master
  • CI passes
  • Docs/ChangeLog updated

mistral-vibe and others added 2 commits November 26, 2026 20:24
…#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>
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.

2 participants