Skip to content

Commit 5fc3620

Browse files
authored
Merge pull request #1616 from evoskuil/master
Allocator macro style and comments, remove unused vargs.
2 parents 770bc63 + 218f801 commit 5fc3620

File tree

2 files changed

+19
-5
lines changed

2 files changed

+19
-5
lines changed

include/bitcoin/system/allocator.hpp

+18-5
Original file line numberDiff line numberDiff line change
@@ -279,13 +279,26 @@ inline bool operator==(const allocator<Left>& left,
279279

280280
using byte_allocator = allocator<uint8_t>;
281281

282-
#define CREATE(Type, allocate, ...) \
283-
allocate.new_object<Type>(__VA_ARGS__), allocate.deleter<Type>(), allocate
282+
// If Type accepts an allocator on construct (e.g. vector) then
283+
// std::uses_allocator_construction_args supplies the allocator.
284+
285+
// Create a pointer to an instance of Type presumed to be allocated and
286+
// constructed by allocator, and pass it and deleter and allocator as:
287+
// shared_ptr<Type>(Type*, allocate.deleter<Type>(), allocate)
284288
#define POINTER(Type, allocate, ptr) \
285289
ptr, allocate.deleter<Type>(), allocate
286-
#define INPLACE(ptr, Type, allocate, ...) \
287-
allocate.construct<std::shared_ptr<const Type>>(ptr, __VA_ARGS__, \
288-
allocate.deleter<Type>(), allocate)
290+
291+
// Create a pointer to an instance of Type allocated and constructed by
292+
// allocator, and pass it and deleter and allocator as:
293+
// shared_ptr<Type>(allocate.new_object<Type>(...), allocate.deleter<Type>(), allocate)
294+
#define CREATE(Type, allocate, ...) \
295+
POINTER(Type, allocate, allocate.new_object<Type>(__VA_ARGS__))
296+
297+
// Construct a shared_ptr to allocated instance (ptr) of const Type on an
298+
// allocated address (at) passing deleter and allocator to shared_ptr construct.
299+
#define INPLACE(at, Type, allocate, ptr) \
300+
allocate.construct<std::shared_ptr<const Type>>( \
301+
at, ptr, allocate.deleter<Type>(), allocate)
289302

290303
// TODO: replace above macros with parameter pack expansion.
291304
////template <typename Type, typename Allocator, typename... Args>

include/bitcoin/system/impl/stream/streamers/byte_reader.ipp

+1
Original file line numberDiff line numberDiff line change
@@ -444,6 +444,7 @@ data_chunk* byte_reader<IStream>::read_bytes_raw(size_t size) NOEXCEPT
444444
return nullptr;
445445

446446
// TODO: bypass vector byte fill.
447+
// std::uses_allocator_construction_args supplies allocator to vector.
447448
const auto raw = allocator_.new_object<data_chunk>(size);
448449
if (raw == nullptr)
449450
{

0 commit comments

Comments
 (0)