ADR-0768: C++23 Wave 9 — picture_pool + gpu_picture_pool¶
- Status: Accepted
- Date: 2026-05-29
- Deciders: lusoris
- Tags:
build,c++,cpp23,refactor,internals,fork-local,vmafx-rebrand
Context¶
Continuing the ADR-0708 cpp23 migration playbook. Two self-contained TUs in core/src/ are converted from C to C++23 in this wave:
| File | Lines | Notes |
|---|---|---|
gpu_picture_pool.c | 146 | Backend-agnostic round-robin GPU picture pool (ADR-0239). |
picture_pool.c | 256 | CPU picture pool with O(1) free-list stack. |
Note: gpu_dispatch_env.c was included in the original Wave 9 plan but was converted earlier and separately in ADR-0858 / PR #531. This ADR covers only the two pool files.
All conversions apply conservative idioms only: nullptr replacing NULL, <c…> headers replacing C headers, typedef struct S { } S replaced by struct S { }, and static_cast/reinterpret_cast replacing C casts where the types require it.
Extern "C" collateral¶
Four internal headers lacked extern "C" guards and are consumed by the new .cpp TUs:
core/src/picture.h— declaresvmaf_picture_ref,vmaf_picture_set_release_callback,vmaf_picture_priv_init.core/src/mem.h— declaresaligned_malloc,aligned_free.core/src/ref.h— declaresvmaf_ref_init,vmaf_ref_close, etc.core/src/picture_pool.h— declares the CPU pool API.
core/src/gpu_picture_pool.h and core/src/gpu_dispatch_env.h already had guards (ADR-0239, ADR-0461).
Adding extern "C" guards to headers that lacked them is a no-op for existing C TUs; it is required so the new C++ TUs resolve unmangled symbols at link time.
Decision¶
Convert picture_pool.c and gpu_picture_pool.c to .cpp with cpp_std=c++23, each isolated in its own static library (same pattern as metadata_handler_cpp20_lib in ADR-0708).
- Each file is renamed
.c→.cpp. - Each is compiled via an isolated
static_library()target withoverride_options: ['cpp_std=c++23']. - The two libs are linked into
libvmafviaobjects:at the top-levellibrary()call, replacing the previous direct-source entries. extern "C"guards are added topicture.h,mem.h,ref.h, andpicture_pool.h.- All occurrences of
'../src/gpu_picture_pool.c'incore/test/meson.buildare updated togpu_picture_pool.cpp.
Alternatives considered¶
| Option | Pros | Cons | Why not chosen |
|---|---|---|---|
| Wrap internal headers at the call site | No header changes | Causes "templates with C linkage" errors when pulling in C++ stdlib | Brittle |
Add extern "C" to public headers only | Smallest touch | Does not cover internal src/ headers | Incomplete |
| Defer extern-C guard sweep separately | Clean separation | Leaves the new .cpp TUs broken until sweep lands | Blocks wave |
Consequences¶
- Positive: Two more TUs migrate to C++23.
extern "C"guards land onpicture.h,mem.h, andref.h, unblocking future cpp23 waves. - Negative:
picture_pool.cppusesreinterpret_castfor the C-style first-member inheritance pattern; a future pass could use C++ inheritance, deferred per the wave's "conservative idioms only" policy. - Neutral: No user-visible surface change; no score impact.
References¶
- ADR-0708 — original C++23 migration playbook; defines the per-file conversion recipe and isolated-static-lib isolation pattern.
- ADR-0239 — backend-agnostic GPU picture pool.
- ADR-0858 — Wave 9
gpu_dispatch_envconversion (merged earlier in PR #531). - req: "cpp23 Wave 9: convert 2-3 more SMALL
core/src/*.cfiles to.cpp. Same SAFE pattern."