Repository navigation
Harden constant metadata tag tables (follow-up to #265) - #271
Merged
Merged
Conversation
Store metadata descriptors in sorted constant arrays instead of constructing per-model maps at initialization. Binary search handles tag IDs; reverse name lookup preserves the existing lowest-ID result for duplicate names. Descriptors and their strings keep static storage duration. Keep every current upstream table, including the empty Apple iOS model, and preserve tag IDs, strings, public model mappings, and unknown-tag fallbacks. Metadata initialization now performs zero allocations. In a native x86-64 measurement, the current tables previously retained 64,752 requested bytes in 1,349 allocations per initialized library instance. Add a standalone metadata regression test covering all 16-bit tag IDs for every registered model, sorted table invariants, reverse names, stable pointers, unknown models, and fallback strings.
Replace metadata string pointers with compiler-computed 16-bit offsets. Keep each model in its own constant pool so unused models can be discarded. A compile-time bound prevents offset overflow; no generator, heap allocation or runtime initialization is needed. Preserve the existing getters. Move the table rows and their original attribution to TagLibData.h. Update header dependencies and add exhaustive string, offset and lookup coverage.
Add an internal getTagFields method and use it at the ten callers that request both strings. This avoids repeating model dispatch and binary search. Keep the original three-argument getTagFieldName symbol as a wrapper, and leave getTagDescription available. Check both outputs for every model and 16-bit tag ID, including missing descriptions, unknown tags and fallback buffers. Verify that the original member-function signature and returned names are preserved.
Follow-up to the constant metadata tables: - Verify in debug builds that every table has strictly increasing tag IDs the first time TagLib::instance() is used, not only in TagLibTest. - Make getTagID return -1 for a NULL key and skip any NULL field name instead of passing it to strcmp. - Replace the reinterpret_cast over a string pool with a static_cast through void*, and add a compile-time check that the pool's leading empty string sits at offset zero. - Extend TagLibTest to cover the sort check and NULL keys for every model.
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.
Stacked on #265: the first three commits are that PR, so this will shrink to a single commit once #265 lands. Review only
Harden constant metadata tag tables.Follow-ups from review of #265:
TagLib::instance();TagLibTestcalls the same check. Swapping two rows inTagLibData.hmakes the test fail with an assertion.getTagIDreturns -1 for a NULL key and skips NULL field names rather than passing them tostrcmp.reinterpret_castover the pool is now astatic_castthroughvoid*, with a compile-time check that the pool starts with the empty string at offset 0.TagLibData.hare intact.master'sTagLib.cppand this branch's separately and dumped, for every model and every tag ID 0-0xFFFF, the field name (with the unknown-tag fallback), the description, and the reversegetTagIDlookup. The two outputs are byte-identical (1,574,165 lines).Tested on macOS (CMake, Release,
BUILD_TESTS=ON): 18/18 tests pass. MSVC and other platforms are left to CI.