Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id 24C21200D01 for ; Fri, 8 Sep 2017 06:55:45 +0200 (CEST) Received: by cust-asf.ponee.io (Postfix) id 232631609C0; Fri, 8 Sep 2017 04:55:45 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id 6922E1609BE for ; Fri, 8 Sep 2017 06:55:44 +0200 (CEST) Received: (qmail 91617 invoked by uid 500); 8 Sep 2017 04:55:42 -0000 Mailing-List: contact commits-help@geode.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@geode.apache.org Delivered-To: mailing list commits@geode.apache.org Received: (qmail 91607 invoked by uid 99); 8 Sep 2017 04:55:41 -0000 Received: from ec2-52-202-80-70.compute-1.amazonaws.com (HELO gitbox.apache.org) (52.202.80.70) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 08 Sep 2017 04:55:41 +0000 Received: by gitbox.apache.org (ASF Mail Server at gitbox.apache.org, from userid 33) id 7AEFF817D7; Fri, 8 Sep 2017 04:55:40 +0000 (UTC) Date: Fri, 08 Sep 2017 04:55:40 +0000 To: "commits@geode.apache.org" Subject: [geode-native] branch develop updated: GEODE-3574 Removing GF_ALLOC/RESIZE/FREE macros MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit Message-ID: <150484654000.5392.4502517510490587601@gitbox.apache.org> From: jbarrett@apache.org Reply-To: "commits@geode.apache.org" X-Git-Host: gitbox.apache.org X-Git-Repo: geode-native X-Git-Refname: refs/heads/develop X-Git-Reftype: branch X-Git-Oldrev: 6ece91c5254e6a1b6b9bd0beb9e48abb9aa1196e X-Git-Newrev: 9e24335445f9b4772cbbc79ca2b8ebd97cb2b84f X-Git-Rev: 9e24335445f9b4772cbbc79ca2b8ebd97cb2b84f X-Git-NotificationType: ref_changed_plus_diff X-Git-Multimail-Version: 1.5.dev Auto-Submitted: auto-generated archived-at: Fri, 08 Sep 2017 04:55:45 -0000 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 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(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" '].