geode-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jbarr...@apache.org
Subject [geode-native] branch develop updated: GEODE-3574 Removing GF_ALLOC/RESIZE/FREE macros
Date Fri, 08 Sep 2017 04:55:40 GMT
This is an automated email from the ASF dual-hosted git repository.

jbarrett pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/geode-native.git


The following commit(s) were added to refs/heads/develop by this push:
     new 9e24335  GEODE-3574 Removing GF_ALLOC/RESIZE/FREE macros
9e24335 is described below

commit 9e24335445f9b4772cbbc79ca2b8ebd97cb2b84f
Author: Mark Hanson <mhanson@pivotal.io>
AuthorDate: Thu Sep 7 14:30:28 2017 -0700

    GEODE-3574 Removing GF_ALLOC/RESIZE/FREE macros
---
 cppcache/include/geode/DataOutput.hpp              | 49 ++++++++--------------
 .../testThinClientCacheablesLimits.cpp             |  6 ++-
 cppcache/src/DataOutput.cpp                        |  8 +++-
 3 files changed, 29 insertions(+), 34 deletions(-)

diff --git a/cppcache/include/geode/DataOutput.hpp b/cppcache/include/geode/DataOutput.hpp
index 7c2aa84..a677ec5 100644
--- a/cppcache/include/geode/DataOutput.hpp
+++ b/cppcache/include/geode/DataOutput.hpp
@@ -39,33 +39,6 @@ namespace geode {
 namespace client {
 class SerializationRegistry;
 class DataOutputInternal;
-/**
- * C style memory allocation that throws OutOfMemoryException
- * if it fails
- */
-#define GF_ALLOC(v, t, s)                                                  \
-  {                                                                        \
-    v = (t*)malloc((s) * sizeof(t));                                       \
-    if ((v) == nullptr) {                                                  \
-      throw OutOfMemoryException(                                          \
-          "Out of Memory while allocating buffer for " #t " of size " #s); \
-    }                                                                      \
-  }
-
-/**
- * C style memory re-allocation that throws OutOfMemoryException
- * if it fails
- */
-#define GF_RESIZE(v, t, s)                                \
-  {                                                       \
-    v = (t*)realloc(v, (s) * sizeof(t));                  \
-    if ((v) == nullptr) {                                 \
-      throw OutOfMemoryException(                         \
-          "Out of Memory while resizing buffer for " #t); \
-    }                                                     \
-  }
-
-#define GF_FREE(v) free(v)
 
 /**
  * Provide operations for writing primitive data values, byte arrays,
@@ -652,7 +625,11 @@ class CPPCACHE_EXPORT DataOutput {
   inline uint8_t* getBufferCopy() {
     uint32_t size = static_cast<uint32_t>(m_buf - m_bytes);
     uint8_t* result;
-    GF_ALLOC(result, uint8_t, size);
+    result = (uint8_t *) std::malloc(size * sizeof(uint8_t));
+    if (result == nullptr) {
+      throw OutOfMemoryException(
+          "Out of Memory while resizing buffer");
+    }
     std::memcpy(result, m_bytes, size);
     return result;
   }
@@ -671,9 +648,13 @@ class CPPCACHE_EXPORT DataOutput {
   inline void reset() {
     if (m_haveBigBuffer) {
       // free existing buffer
-      GF_FREE(m_bytes);
+      std::free(m_bytes);
       // create smaller buffer
-      GF_ALLOC(m_bytes, uint8_t, m_lowWaterMark);
+      m_bytes = (uint8_t *) std::malloc(m_lowWaterMark* sizeof(uint8_t));
+      if (m_bytes == nullptr) {
+        throw OutOfMemoryException(
+            "Out of Memory while resizing buffer");
+      }
       m_size = m_lowWaterMark;
       // reset the flag
       m_haveBigBuffer = false;
@@ -695,7 +676,13 @@ class CPPCACHE_EXPORT DataOutput {
         m_haveBigBuffer = true;
       }
       m_size = newSize;
-      GF_RESIZE(m_bytes, uint8_t, m_size);
+
+      auto tmp = (uint8_t *) std::realloc(m_bytes, m_size * sizeof(uint8_t));
+      if (tmp == nullptr) {
+        throw OutOfMemoryException(
+            "Out of Memory while resizing buffer");
+      }
+      m_bytes = tmp;
       m_buf = m_bytes + offset;
     }
   }
diff --git a/cppcache/integration-test/testThinClientCacheablesLimits.cpp b/cppcache/integration-test/testThinClientCacheablesLimits.cpp
index 7f59aea..1b70a5f 100644
--- a/cppcache/integration-test/testThinClientCacheablesLimits.cpp
+++ b/cppcache/integration-test/testThinClientCacheablesLimits.cpp
@@ -78,7 +78,11 @@ uint8_t* createRandByteArray(int size) {
 }
 char* createRandCharArray(int size) {
   char* ch;
-  GF_ALLOC(ch, char, size + 1);
+  ch = (char *) std::malloc((size + 1) * sizeof(char));
+  if (ch == nullptr) {
+    throw OutOfMemoryException(
+        "Out of Memory while resizing buffer");
+  }
   ch[size] = '\0';
   int length = sizeof(charArray) / sizeof(char);
   for (int i = 0; i < size; i++) {
diff --git a/cppcache/src/DataOutput.cpp b/cppcache/src/DataOutput.cpp
index 061f822..62ba33a 100644
--- a/cppcache/src/DataOutput.cpp
+++ b/cppcache/src/DataOutput.cpp
@@ -79,7 +79,11 @@ class TSSDataOutput {
     } else {
       uint8_t* buf;
       *size = 8192;
-      GF_ALLOC(buf, uint8_t, 8192);
+      buf = (uint8_t *) std::malloc(8192 * sizeof(uint8_t));
+      if (buf == nullptr) {
+        throw OutOfMemoryException(
+            "Out of Memory while resizing buffer");
+      }
       return buf;
     }
   }
@@ -101,7 +105,7 @@ TSSDataOutput::~TSSDataOutput() {
   while (!m_buffers.empty()) {
     BufferDesc desc = m_buffers.back();
     m_buffers.pop_back();
-    GF_FREE(desc.m_buf);
+    std::free(desc.m_buf);
   }
 }
 

-- 
To stop receiving notification emails like this one, please contact
['"commits@geode.apache.org" <commits@geode.apache.org>'].

Mime
View raw message