Skip to content

Commit fe2defa

Browse files
mkrzewicmatthiasrichter
authored andcommitted
Remove Stack::freefn
1 parent 64c4060 commit fe2defa

File tree

3 files changed

+12
-17
lines changed

3 files changed

+12
-17
lines changed

DataFormats/Headers/include/Headers/Stack.h

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -33,25 +33,19 @@ namespace header
3333
/// - returns a Stack ready to be shipped.
3434
struct Stack {
3535

36-
private:
37-
static void freefn(void* data, void* hint)
38-
{
39-
boost::container::pmr::memory_resource* resource = static_cast<boost::container::pmr::memory_resource*>(hint);
40-
resource->deallocate(data, 0, 0);
41-
}
36+
using memory_resource = o2::pmr::memory_resource;
4237

38+
private:
4339
struct freeobj {
44-
freeobj() {}
45-
freeobj(boost::container::pmr::memory_resource* mr) : resource(mr) {}
46-
47-
boost::container::pmr::memory_resource* resource{ nullptr };
48-
void operator()(o2::byte* ptr) { Stack::freefn(ptr, resource); }
40+
freeobj(memory_resource* mr) : resource(mr) {}
41+
memory_resource* resource{ nullptr };
42+
void operator()(o2::byte* ptr) { resource->deallocate(ptr, 0, 0); }
4943
};
5044

5145
public:
5246
using allocator_type = boost::container::pmr::polymorphic_allocator<o2::byte>;
5347
using value_type = o2::byte;
54-
using BufferType = std::unique_ptr<value_type[], freeobj>;
48+
using BufferType = std::unique_ptr<value_type[], freeobj>; //this gives us proper default move semantics for free
5549

5650
Stack() = default;
5751
Stack(Stack&&) = default;
@@ -64,8 +58,6 @@ struct Stack {
6458
allocator_type get_allocator() const { return allocator; }
6559

6660
//
67-
boost::container::pmr::memory_resource* getFreefnHint() const noexcept { return allocator.resource(); }
68-
static auto getFreefn() noexcept { return &freefn; }
6961

7062
/// The magic constructors: take arbitrary number of headers and serialize them
7163
/// into the buffer buffer allocated by the specified polymorphic allocator. By default
@@ -86,15 +78,15 @@ struct Stack {
8678
: allocator{ allocatorArg },
8779
bufferSize{ calculateSize(std::forward<Headers>(headers)...) },
8880
buffer{ static_cast<o2::byte*>(allocator.resource()->allocate(bufferSize, alignof(std::max_align_t))),
89-
freeobj(getFreefnHint()) }
81+
freeobj(allocator.resource()) }
9082
{
9183
inject(buffer.get(), std::forward<Headers>(headers)...);
9284
}
9385

9486
private:
9587
allocator_type allocator{ boost::container::pmr::new_delete_resource() };
9688
size_t bufferSize{ 0 };
97-
BufferType buffer{ nullptr, freeobj{ getFreefnHint() } };
89+
BufferType buffer{ nullptr, freeobj{ allocator.resource() } };
9890

9991
template <typename T, typename... Args>
10092
static size_t calculateSize(T&& h, Args&&... args) noexcept

Framework/Utils/include/Utils/Utils.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@ namespace o2
2525
{
2626
namespace workflows
2727
{
28+
//TODO: this is to make DPLmerger compile, but this code is (and always was) horribly broken - please remove.
29+
inline void freefn(void* data, void* /*hint*/) { delete static_cast<char*>(data); };
30+
2831
//
2932
o2f::Output getOutput(const o2f::OutputSpec outputSpec);
3033
std::shared_ptr<std::vector<o2f::Output>> getOutputList(const o2f::Outputs outputSpecs);

Framework/Utils/src/DPLMerger.cxx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ o2f::DataProcessorSpec defineMerger(std::string devName, o2f::Inputs usrInputs,
4646
(*mergerFuncPtr)(outputBuffer, itInputs);
4747
}
4848
// Adopting the buffer as new chunk
49-
ctx.outputs().adoptChunk((*outputPtr), &outputBuffer[0], outputBuffer.size(), header::Stack::getFreefn(),
49+
ctx.outputs().adoptChunk((*outputPtr), &outputBuffer[0], outputBuffer.size(), &freefn,
5050
nullptr);
5151
};
5252
} } };

0 commit comments

Comments
 (0)