Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions include/tscore/ink_memory.h
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,8 @@ char *_xstrdup(const char *str, int length, const char *path);

#ifdef __cplusplus

#include <memory>

// this is to help with migration to a std::string issue with older code that
// expects char* being copied. As more code moves to std::string, this can be
// removed to avoid these extra copies.
Expand Down Expand Up @@ -618,4 +620,15 @@ path_join(ats_scoped_str const &lhs, ats_scoped_str const &rhs)

return x.release();
}

struct ats_unique_buf_deleter {
void
operator()(uint8_t *p)
{
ats_free(p);
}
};
using ats_unique_buf = std::unique_ptr<uint8_t[], ats_unique_buf_deleter>;
ats_unique_buf ats_unique_malloc(size_t size);

#endif /* __cplusplus */
6 changes: 6 additions & 0 deletions src/tscore/ink_memory.cc
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,12 @@ ats_mallopt(int param ATS_UNUSED, int value ATS_UNUSED)
return 0;
}

ats_unique_buf
ats_unique_malloc(size_t size)
{
return ats_unique_buf(static_cast<uint8_t *>(ats_malloc(size)));
}

int
ats_msync(caddr_t addr, size_t len, caddr_t end, int flags)
{
Expand Down