trafficserver-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mas...@apache.org
Subject [trafficserver] branch master updated: Add ats_unique_buf
Date Fri, 28 Jun 2019 01:29:11 GMT
This is an automated email from the ASF dual-hosted git repository.

maskit pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/trafficserver.git


The following commit(s) were added to refs/heads/master by this push:
     new d2e6a9e  Add ats_unique_buf
d2e6a9e is described below

commit d2e6a9e4b49b73704db1ba8333bd6e0ab6c4ee79
Author: Masakazu Kitajo <maskit@apache.org>
AuthorDate: Tue Jun 25 17:00:58 2019 +0900

    Add ats_unique_buf
---
 include/tscore/ink_memory.h | 13 +++++++++++++
 src/tscore/ink_memory.cc    |  6 ++++++
 2 files changed, 19 insertions(+)

diff --git a/include/tscore/ink_memory.h b/include/tscore/ink_memory.h
index d024111..713cb02 100644
--- a/include/tscore/ink_memory.h
+++ b/include/tscore/ink_memory.h
@@ -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.
@@ -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 */
diff --git a/src/tscore/ink_memory.cc b/src/tscore/ink_memory.cc
index aca92b8..b34a726 100644
--- a/src/tscore/ink_memory.cc
+++ b/src/tscore/ink_memory.cc
@@ -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)
 {


Mime
View raw message