[v2] Propagate allocators from context#420
Conversation
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## anilm3/v2 #420 +/- ##
=============================================
- Coverage 85.57% 85.53% -0.05%
=============================================
Files 177 178 +1
Lines 9138 9179 +41
Branches 3940 3983 +43
=============================================
+ Hits 7820 7851 +31
+ Misses 497 491 -6
- Partials 821 837 +16
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Benchmarks clangBenchmark execution time: 2025-07-09 11:54:17 Comparing candidate commit 651b1ee in PR branch Found 1 performance improvements and 0 performance regressions! Performance is the same for 0 metrics, 0 unstable metrics. scenario:global-benchmark.random.clang
|
Benchmarks gccBenchmark execution time: 2025-07-09 11:55:53 Comparing candidate commit 651b1ee in PR branch Found 1 performance improvements and 0 performance regressions! Performance is the same for 0 metrics, 0 unstable metrics. scenario:global-benchmark.random.gcc
|
Benchmarks clang-pgoBenchmark execution time: 2025-07-09 12:10:10 Comparing candidate commit 651b1ee in PR branch Found 0 performance improvements and 0 performance regressions! Performance is the same for 1 metrics, 0 unstable metrics. |
Artifact Size Comparison 📦
|
8f48385 to
d06b96b
Compare
d06b96b to
7381270
Compare
dd9fed2 to
154cbfe
Compare
7381270 to
ac33899
Compare
8548fad to
f63853b
Compare
f63853b to
01232e3
Compare
| } | ||
|
|
||
| to_ref(object) = owned_object{string, length}.move(); | ||
| to_ref(object) = owned_object{string, static_cast<uint32_t>(length)}.move(); |
There was a problem hiding this comment.
should bound check length. same in other points in this file.
There was a problem hiding this comment.
I didn't do it here because the function will be removed and the new one will use uint32_t rather than size_t.
There was a problem hiding this comment.
Pull Request Overview
This PR propagates a user-specified memory resource (allocator) throughout all API calls that produce output objects, without exposing allocators in the public interface yet. It also introduces a zero-cost nonnull_ptr wrapper to guarantee non-null resource pointers.
- Added
nonnull_ptr<memory_resource>parameters to constructors andeval_implmethods across all processors and serializers - Updated
result_serializerto store the allocator instance and madeinitialise_result_objectnon-static - Revised unit tests to pass the default allocator into every call path producing owned objects
Reviewed Changes
Copilot reviewed 40 out of 40 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| tests/unit/*.cpp | Updated all tests to call eval/initialise_result_object with a default allocator |
| src/serializer.hpp/cpp | result_serializer now holds an allocator; serialization routines use it when building maps and arrays |
| src/processor/*.hpp/cpp | All eval_impl signatures now accept nonnull_ptr<memory_resource> before the deadline parameter |
| src/object.hpp / object_store code | Cloning, builders, and destroy helpers all updated to carry allocators via nonnull_ptr |
| src/dynamic_string.hpp/cpp | dynamic_string constructors and to_object take an allocator; reserve/resize APIs updated |
| src/cow_string.hpp | replace_buffer and move now carry allocator throughnonnull_ptr |
| src/utf8.cpp | Integrated allocator usage into normalize_string, guarding zero-length allocations |
| src/json_utils.hpp/cpp | JSON parser handler now accepts allocator and passes it to object construction |
| src/utils.hpp | Cleaned up unused includes and added literal case-insensitive comparison helpers |
Comments suppressed due to low confidence (1)
tests/unit/object_test.cpp:930
- [nitpick] The
ObjectWithNullAllocatortest has been commented out; consider re-enabling or replacing it to ensure allocator logic is fully exercised.
// TODO Reevaluate once allocators are exposed through the interface
* Object view: read only abstraction to ddwaf_object (#341) * [v2] Remove mingw builds (#381) * Writable objects: owned and borrowed object and object limits removal (#378, #382) * [v2] Refactor and improve object types (#387) * [v2] Update unit tests to use new abstractions (#389) * [v2] Update `raw_configuration` type to use `object_view` (#390) * [v2] Remove remaining uses of ddwaf_object in `src` and `tests/unit` (#391) * [v2] JWT Decoding Processor (#401) * [v2] First iteration of object layout changes (#394) * Split context data insertion from evaluation (#407) * [v2] Second iteration of object layout changes (#408) * [v2] Add new fingerprint and object view tests (#414) * Reenable attribute collector unit test (#415) * [v2] Container view types (#413) * Exclude assertions from coverage (#416) * [v2] Use allocators internally instead of malloc/free and stop generating zero-terminated strings (#418) * Add memory resource to owned and borrowed objects (#428) * [v2] Propagate allocators from context (#420) * [v2] Update interface and expose allocators (#427) * Refactor evaluation stages out of the context (#442) * Subcontext: replace ephemerals with a new scope with user-defined lifetime derived from the context (#443) * Validator: Add support for testing subcontexts and attributes (#451) * [v2] Pass allocator to context and subcontext eval and add new allocators (#452) * Update logger to avoid dependencies on ddwaf.h (#453) * [v2] Return DDWAF_MATCH when there are events, attributes or actions (#455) * [v2] Cleanup: remove exclusion namespace and some redundant references (#456)
This PR completes #419 by propagating the relevant allocator (memory resource) to all classes and methods which generate an output for the caller. The allocator remains unexposed through the interface as that will be handled in the next PR.
This PR also introduces
nonnull_ptr, a zero-cost class holding a pointer which can't benullptr, this is based ongsl::not_null.Remaining work (Next PRs):
Update objects to use allocators more effectively.Check for allocator compatibility where relevant.Propagate allocator from the context.Have a clear distinction between input , output and internal allocators.Removefrom_mutable_bufferuse case oncow_stringcontext_init/context_eval.ddwaf_objectfunctions.