Skip to content

feat: per-codec external-context decode entry points (-fno-ctx-members, Phases 1-4) - #18

Merged
sleevetosleeve merged 3 commits into
vlm_masterfrom
vibe/ext-ctx-phases1-4-d2e85d
Nov 27, 2026
Merged

sleevetosleeve merged 3 commits into
vlm_masterfrom
vibe/ext-ctx-phases1-4-d2e85d

Conversation

@sleevetosleeve

Copy link
Copy Markdown
Owner

Summary

  • Adds the remaining per-codec _ctx decode entry points for code generated with -fno-ctx-members (issue Feature request: external decode context (-fno-ctx-members) #15): xer_decode_ctx(), jer_decode_ctx(), oer_decode_ctx(), uper_decode_ctx(), aper_decode_ctx(), cbor_decode_ctx(), alongside Phase 0's ber_decode_ctx() / asn_decode_ctx().
  • Each entry point stack-copies the codec context and carries the caller-owned asn_struct_external_ctx_t arena in asn_codec_ctx_t.ext_struct_ctx, so it reaches every nested decoder through the existing parameter. uper_decode() / aper_decode() were split into a static *_impl taking the arena, so the plain entry points keep their exact former behavior.
  • Decoder headers declare the arena parameter as struct asn_struct_external_ctx_s * (tag forward-declared in asn_application.h): uper_decoder.h / aper_decoder.h are pulled in from asn_internal.h before the constr_TYPE.h typedef is visible.
  • Contract refinement, verified by test: plain entry points of the resumable codecs (BER/CER, XER, JER, OER) return RC_FAIL on -fno-ctx-members output; UPER/APER/CBOR plain entry points are unaffected because those decoders never fetch the embedded context at decode time (PER is single-shot; CBOR/PER ctx_offset uses are layout guards only). The _ctx variants exist for API symmetry and are exercised for all seven codecs.
  • check-610 now round-trips all seven codecs in both generation modes (default and -fno-ctx-members), including 1-byte chunked BER/XER/JER resumes (RC_WMORE) through the arena, plus the ASN_STRUCT_RESET_CTX re-decode and asn_decode_ctx dispatcher coverage. sizeof(NetMsg_t) stays 104 (default) vs 32 (-fno-ctx-members).
  • Design doc status and ChangeLog updated (docs/external-ctx-design.md).

Related issues

Type of change

  • New feature

Testing

  • Local (sandbox build with automake 1.16.5 / autoconf 2.71 / bison 3.8.2 / flex 2.6.4):
    • tests-c-compiler: 94/94 PASS (incl. check-610.c and check-610.-fno-ctx-members.c, built with ASan+UBSan)
    • tests-skeletons: 70/70 PASS; tests-asn1c-compiler: 14/14 PASS; libasn1fix: 3/3 PASS (check_fixer accepts 610-ext-ctx-ber-OK.asn1)
    • scratch harness over generated 610 module: all 7 codecs decode via asn_decode_ctx and per-codec _ctx entries; plain BER/XER/JER/OER return RC_FAIL on ext code; XER/JER 1-byte chunked resume PASS under ASan/UBSan, no leaks
    • tests-rust-compiler fails locally only because cargo-clippy is not installed in the sandbox (unit tests themselves pass); Rust CI is green on feat: external decode context for BER/CER (-fno-ctx-members), Phase 0 #17 for the same code paths

Checklist

mistral-vibe and others added 3 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>
Add xer_decode_ctx(), jer_decode_ctx(), oer_decode_ctx(), uper_decode_ctx(),
aper_decode_ctx() and cbor_decode_ctx() alongside ber_decode_ctx() and the
asn_decode_ctx() dispatcher (issue #15). Each stack-copies the codec context
and carries the caller-owned asn_struct_external_ctx_t arena in
asn_codec_ctx_t.ext_struct_ctx; uper_decode/aper_decode were split into a
static *_impl so the plain entry points keep their exact former behavior.
Decoder headers declare the arena parameter as struct
asn_struct_external_ctx_s * (the tag forward-declared in asn_application.h),
since uper/aper_decoder.h are included from asn_internal.h before the
constr_TYPE.h typedef is visible.

Plain entry points of the resumable codecs (BER/CER, XER, JER, OER) fail
with RC_FAIL on -fno-ctx-members output; PER/CBOR plain entry points are
unaffected because those decoders never fetch the embedded context at decode
time. check-610 now round-trips all seven codecs in both generation modes,
including 1-byte chunked XER/JER resumes through the arena.

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