- 
    Type:Improvement 
- 
    Resolution: Unresolved
- 
    Priority:Unknown 
- 
    None
- 
    Affects Version/s: None
- 
    Component/s: None
- 
    None
- 
        None
- 
        C Drivers
- 
        None
- 
        None
- 
        None
- 
        None
- 
        None
- 
        None
libbson supports swapping out the global allocation functions with user-provided ones. Most libbson code will use the custom allocators.
mlib in mongo-c-driver (and mongocrypt) relies on the <stdlib.h> allocation APIs. mlib in amongoc supports allocators attached to individual objects. With the addition of mstr and mlib/vec.th, the library now has allocating containers that won't respect the libbson custom allocators.
There are two ways to add custom allocators to mlib in mongo-c-driver:
- Pull in mlib/allocator.h from amongoc and use it in mstr and mlib/vec.th APIs. This could use a libbson_allocator object to be defined that uses the same allocators as libbson. Embedding individual allocators is extremely versatile but may add some internal complexity, as you now need to pass the appropriate allocator to e.g. mstr_copy
- Alternatively, define mlib_set_allocator_stuff functions to match the libbson versions. This will require that globals with external linkage be introduced into mlib headers, which we've so far been able to avoid in mongo-c-driver. This will be less versatile but may be simpler as the allocator customization will be implicit e.g. when you call mstr_copy.