You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Remove default allocators from owned_object and fix allocator safety
This change extends the allocator refactoring to comprehensively prevent
allocator mismatch bugs by:
1. **Remove default allocators from owned_object constructors**
- String constructors now require explicit allocator parameter
- Prevents implicit use of default allocator when specific one needed
- Compile-time enforcement of correct allocator usage
2. **Privatize raw constructor, expose via create_unchecked()**
- `owned_object(detail::object, alloc)` now private
- Added `create_unchecked()` static factory to make danger explicit
- Updated call sites in interface.cpp and elsewhere
3. **Use null allocator for primitives**
- Primitives (null, boolean, numbers) use memory::get_default_null_resource()
- Null allocator throws if allocation attempted, catching bugs early
4. **Rename unsafe methods for clarity**
- `make_string_nocopy` → `unsafe_make_string_nocopy`
- Explicit naming indicates caller must ensure memory ownership
5. **Template improvements using std::constructible_from**
- attribute_collector insert() overloads use concept constraints
- writable_object emplace/emplace_back use std::constructible_from
- Cleaner distinction between allocating and non-allocating types
6. **Test infrastructure improvements**
- Added tests/common/ddwaf_object_da.hpp for test allocator utilities
- Updated all test files to use new constructor signatures
7. **Fix examples and benchmarks for current API**
- examples/example.cpp: Updated to use ddwaf_object_set_* functions
- tools/ip_match_benchmark.cpp: Fixed deprecated API and IPv6 code
- tools/infer_schema_bench.cpp: Updated include path (still needs API rewrite)
All 1,513 tests pass with zero memory leaks (51,813 allocs/deallocs balanced).
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude Sonnet 4.5 <[email protected]>
0 commit comments