From commits-return-25543-archive-asf-public=cust-asf.ponee.io@geode.apache.org Tue Feb 6 20:39:43 2018 Return-Path: X-Original-To: archive-asf-public@eu.ponee.io Delivered-To: archive-asf-public@eu.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by mx-eu-01.ponee.io (Postfix) with ESMTP id 728E4180657 for ; Tue, 6 Feb 2018 20:39:43 +0100 (CET) Received: by cust-asf.ponee.io (Postfix) id 61377160C45; Tue, 6 Feb 2018 19:39:43 +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 B42A3160C37 for ; Tue, 6 Feb 2018 20:39:41 +0100 (CET) Received: (qmail 11373 invoked by uid 500); 6 Feb 2018 19:39:40 -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 11364 invoked by uid 99); 6 Feb 2018 19:39:40 -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; Tue, 06 Feb 2018 19:39:40 +0000 Received: by gitbox.apache.org (ASF Mail Server at gitbox.apache.org, from userid 33) id A5FE78217F; Tue, 6 Feb 2018 19:39:39 +0000 (UTC) Date: Tue, 06 Feb 2018 19:39:39 +0000 To: "commits@geode.apache.org" Subject: [geode-native] branch develop updated: GEODE-4605: Keep domain object via shared_ptr. (#205) MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit Message-ID: <151794597958.16690.3224968085194816258@gitbox.apache.org> From: jbarrett@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: 2fb2d83d0ca38e0d7eecae81f3e69ab3bcdb1f35 X-Git-Newrev: f4f4c7b34d194d5d4d68aad34cc2d6c95b3721c1 X-Git-Rev: f4f4c7b34d194d5d4d68aad34cc2d6c95b3721c1 X-Git-NotificationType: ref_changed_plus_diff X-Git-Multimail-Version: 1.5.dev Auto-Submitted: auto-generated 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 f4f4c7b GEODE-4605: Keep domain object via shared_ptr. (#205) f4f4c7b is described below commit f4f4c7b34d194d5d4d68aad34cc2d6c95b3721c1 Author: Jacob Barrett AuthorDate: Tue Feb 6 11:39:36 2018 -0800 GEODE-4605: Keep domain object via shared_ptr. (#205) - Removes UserDeallocator function. --- cppcache/include/geode/PdxSerializer.hpp | 23 +--- cppcache/include/geode/PdxWrapper.hpp | 51 ++++----- .../integration-test/ThinClientPdxSerializer.hpp | 127 +++++++++++---------- .../integration-test/ThinClientPdxSerializers.hpp | 41 +++---- cppcache/src/PdxWrapper.cpp | 53 ++------- tests/cpp/testobject/NonPdxType.cpp | 8 +- tests/cpp/testobject/NonPdxType.hpp | 42 +++---- tests/cpp/testobject/PdxClassV1.cpp | 9 +- tests/cpp/testobject/PdxClassV1.hpp | 48 ++++---- tests/cpp/testobject/PdxClassV2.cpp | 19 ++- tests/cpp/testobject/PdxClassV2.hpp | 48 ++++---- 11 files changed, 203 insertions(+), 266 deletions(-) diff --git a/cppcache/include/geode/PdxSerializer.hpp b/cppcache/include/geode/PdxSerializer.hpp index ba65ebf..3a89f91 100644 --- a/cppcache/include/geode/PdxSerializer.hpp +++ b/cppcache/include/geode/PdxSerializer.hpp @@ -30,15 +30,10 @@ namespace client { /** * Function pointer type which takes a void pointer to an instance of a user - * object to delete and class name. - */ -using UserDeallocator = std::function; - -/** - * Function pointer type which takes a void pointer to an instance of a user * object and class name to return the size of the user object. */ -using UserObjectSizer = std::function; +using UserObjectSizer = std::function&, + const std::string&)>; /** * The PdxSerializer class allows domain classes to be @@ -60,22 +55,16 @@ class _GEODE_EXPORT PdxSerializer { * @param className the class name whose object need to de-serialize * @param pr the PdxReader stream to use for reading the object data */ - virtual void* fromData(const std::string& className, - PdxReader& pdxReader) = 0; + virtual std::shared_ptr fromData(const std::string& className, + PdxReader& pdxReader) = 0; /** * Serializes this object in geode PDX format. * @param userObject the object which need to serialize * @param pw the PdxWriter object to use for serializing the object */ - virtual bool toData(void* userObject, const std::string& className, - PdxWriter& pdxWriter) = 0; - - /** - * Get the function pointer to the user deallocator - * @param className to help select a deallocator for the correct class - */ - virtual UserDeallocator getDeallocator(const std::string& className) = 0; + virtual bool toData(const std::shared_ptr& userObject, + const std::string& className, PdxWriter& pdxWriter) = 0; /** * Get the function pointer to the user function that returns the size of an diff --git a/cppcache/include/geode/PdxWrapper.hpp b/cppcache/include/geode/PdxWrapper.hpp index f591888..aa6b0e2 100644 --- a/cppcache/include/geode/PdxWrapper.hpp +++ b/cppcache/include/geode/PdxWrapper.hpp @@ -38,12 +38,12 @@ class DataOutput; class PdxReader; class PdxWriter; +/** + * The PdxWrapper class allows domain classes to be used in Region operations. + * A user domain object should be wrapped in an instance of a PdxWrapper with + * a PdxSerializer registered that can handle the user domain class. + */ class _GEODE_EXPORT PdxWrapper : public PdxSerializable { - /** - * The PdxWrapper class allows domain classes to be used in Region operations. - * A user domain object should be wrapped in an instance of a PdxWrapper with - * a PdxSerializer registered that can handle the user domain class. - */ public: /** @@ -54,7 +54,7 @@ class _GEODE_EXPORT PdxWrapper : public PdxSerializable { * @param className the fully qualified class name to map this user object to * the Java side. */ - PdxWrapper(void* userObject, std::string className, + PdxWrapper(std::shared_ptr userObject, std::string className, std::shared_ptr pdxSerializerPtr); /** @@ -65,44 +65,49 @@ class _GEODE_EXPORT PdxWrapper : public PdxSerializable { * @param detach if set to true will release ownership of the object and * future calls to getObject() return nullptr. */ - void* getObject(bool detach = false); + std::shared_ptr getObject(); /** * Get the class name for the user domain object. */ - virtual const std::string& getClassName() const override; + const std::string& getClassName() const override; /** return true if this key matches other. */ - virtual bool operator==(const CacheableKey& other) const override; + bool operator==(const CacheableKey& other) const override; /** return the hashcode for this key. */ - virtual int32_t hashcode() const override; + int32_t hashcode() const override; /** *@brief serialize this object in geode PDX format *@param PdxWriter to serialize the PDX object **/ - virtual void toData(PdxWriter& output) const override; + void toData(PdxWriter& output) const override; + /** *@brief Deserialize this object *@param PdxReader to Deserialize the PDX object **/ - virtual void fromData(PdxReader& input) override; + void fromData(PdxReader& input) override; + /** *@brief serialize this object **/ - virtual void toData(DataOutput& output) const override; + void toData(DataOutput& output) const override; + /** *@brief deserialize this object, typical implementation should return * the 'this' pointer. **/ - virtual void fromData(DataInput& input) override; + void fromData(DataInput& input) override; + /** *@brief return the classId of the instance being serialized. * This is used by deserialization to determine what instance * type to create and derserialize into. */ - virtual int32_t classId() const override { return 0; } + int32_t classId() const override { return 0; } + /** *@brief return the size in bytes of the instance being serialized. * This is used to determine whether the cache is using up more @@ -111,15 +116,16 @@ class _GEODE_EXPORT PdxWrapper : public PdxSerializable { * cache memory utilization. * Note that you must implement this only if you use the HeapLRU feature. */ - virtual size_t objectSize() const override; + size_t objectSize() const override; + /** * Display this object as 'string', which depends on the implementation in * the subclasses. * The default implementation renders the classname. */ - virtual std::string toString() const override; + std::string toString() const override; - virtual ~PdxWrapper(); + ~PdxWrapper() override = default; private: PdxWrapper() = delete; @@ -128,18 +134,11 @@ class _GEODE_EXPORT PdxWrapper : public PdxSerializable { _GEODE_FRIEND_STD_SHARED_PTR(PdxWrapper) - void* m_userObject; + std::shared_ptr m_userObject; std::string m_className; std::shared_ptr m_serializer; - - UserDeallocator m_deallocator; UserObjectSizer m_sizer; - // friend class SerializationRegistry; - - PdxWrapper(const PdxWrapper&); - - const PdxWrapper& operator=(const PdxWrapper&); }; } // namespace client } // namespace geode diff --git a/cppcache/integration-test/ThinClientPdxSerializer.hpp b/cppcache/integration-test/ThinClientPdxSerializer.hpp index 338b9e8..acbeea2 100644 --- a/cppcache/integration-test/ThinClientPdxSerializer.hpp +++ b/cppcache/integration-test/ThinClientPdxSerializer.hpp @@ -1,8 +1,3 @@ -#pragma once - -#ifndef GEODE_INTEGRATION_TEST_THINCLIENTPDXSERIALIZER_H_ -#define GEODE_INTEGRATION_TEST_THINCLIENTPDXSERIALIZER_H_ - /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with @@ -19,18 +14,18 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -/* - * testThinClientPdxSerializer.cpp - * - * Created on: Apr 19, 2012 - * Author: vrao - */ -#include "fw_dunit.hpp" +#pragma once + +#ifndef GEODE_INTEGRATION_TEST_THINCLIENTPDXSERIALIZER_H_ +#define GEODE_INTEGRATION_TEST_THINCLIENTPDXSERIALIZER_H_ + +#include + #include #include -#include +#include "fw_dunit.hpp" #include "ThinClientHelper.hpp" #include "Utils.hpp" #include "testobject/PdxClassV1.hpp" @@ -38,6 +33,7 @@ #include "testobject/NonPdxType.hpp" #include "ThinClientPdxSerializers.hpp" #include "CacheRegionHelper.hpp" + using namespace apache::geode::client; using namespace test; using namespace PdxTests; @@ -165,20 +161,19 @@ DUNIT_TASK_DEFINITION(CLIENT1, JavaPutGet) auto serializationRegistry = CacheRegionHelper::getCacheImpl(cacheHelper->getCache().get()) ->getSerializationRegistry(); - serializationRegistry->setPdxSerializer(std::make_shared()); + serializationRegistry->setPdxSerializer( + std::make_shared()); + + auto pdxSerializer = + CacheRegionHelper::getCacheImpl(getHelper()->getCache().get()) + ->getSerializationRegistry() + ->getPdxSerializer(); auto regPtr0 = getHelper()->getRegion("DistRegionAck"); auto keyport = CacheableKey::create(1); - auto npt1 = new PdxTests::NonPdxType( - CacheRegionHelper::getCacheImpl(getHelper()->getCache().get()) - ->getSerializationRegistry() - ->getPdxSerializer()); - auto pdxobj = std::make_shared( - npt1, CLASSNAME1, - CacheRegionHelper::getCacheImpl(getHelper()->getCache().get()) - ->getSerializationRegistry() - ->getPdxSerializer()); + auto npt1 = std::make_shared(pdxSerializer); + auto pdxobj = std::make_shared(npt1, CLASSNAME1, pdxSerializer); regPtr0->put(keyport, pdxobj); auto obj2 = std::dynamic_pointer_cast(regPtr0->get(keyport)); @@ -189,7 +184,8 @@ DUNIT_TASK_DEFINITION(CLIENT1, JavaPutGet) ASSERT(isEqual == true, "Task JavaPutGet:Objects of type NonPdxType should be equal"); - auto npt2 = reinterpret_cast(obj2->getObject()); + auto npt2 = + std::static_pointer_cast(obj2->getObject()); ASSERT(npt1->equals(*npt2, false), "NonPdxType compare"); } END_TASK_DEFINITION @@ -199,7 +195,8 @@ DUNIT_TASK_DEFINITION(CLIENT2, JavaGet) auto serializationRegistry = CacheRegionHelper::getCacheImpl(cacheHelper->getCache().get()) ->getSerializationRegistry(); - serializationRegistry->setPdxSerializer(std::make_shared()); + serializationRegistry->setPdxSerializer( + std::make_shared()); LOGDEBUG("JavaGet-1 Line_309"); auto regPtr0 = getHelper()->getRegion("DistRegionAck"); @@ -207,12 +204,14 @@ DUNIT_TASK_DEFINITION(CLIENT2, JavaGet) auto keyport1 = CacheableKey::create(1); LOGDEBUG("JavaGet-2 Line_314"); auto obj1 = std::dynamic_pointer_cast(regPtr0->get(keyport1)); - auto npt1 = reinterpret_cast(obj1->getObject()); + auto npt1 = + std::static_pointer_cast(obj1->getObject()); LOGDEBUG("JavaGet-3 Line_316"); auto keyport2 = CacheableKey::create("putFromjava"); LOGDEBUG("JavaGet-4 Line_316"); auto obj2 = std::dynamic_pointer_cast(regPtr0->get(keyport2)); - auto npt2 = reinterpret_cast(obj2->getObject()); + auto npt2 = + std::static_pointer_cast(obj2->getObject()); LOGDEBUG("JavaGet-5 Line_320"); } END_TASK_DEFINITION @@ -225,26 +224,29 @@ DUNIT_TASK_DEFINITION(CLIENT1, putFromVersion1_PS) auto serializationRegistry = CacheRegionHelper::getCacheImpl(cacheHelper->getCache().get()) ->getSerializationRegistry(); - serializationRegistry->setPdxSerializer(std::make_shared()); + serializationRegistry->setPdxSerializer( + std::make_shared()); - // Create New object and wrap it in PdxWrapper (owner) - auto npt1 = new PdxTests::TestDiffTypePdxSV1(true); - auto pdxobj = std::make_shared( - npt1, V1CLASSNAME2, + auto pdxSerializer = CacheRegionHelper::getCacheImpl(getHelper()->getCache().get()) ->getSerializationRegistry() - ->getPdxSerializer()); + ->getPdxSerializer(); + + // Create New object and wrap it in PdxWrapper (owner) + auto npt1 = std::make_shared(true); + auto pdxobj = + std::make_shared(npt1, V1CLASSNAME2, pdxSerializer); // PUT regPtr0->put(key, pdxobj); // GET auto obj2 = std::dynamic_pointer_cast(regPtr0->get(key)); - auto npt2 = - reinterpret_cast(obj2->getObject()); + auto npt2 = std::static_pointer_cast( + obj2->getObject()); // Equal check - bool isEqual = npt1->equals(npt2); + bool isEqual = npt1->equals(*npt2); LOGDEBUG("putFromVersion1_PS isEqual = %d", isEqual); ASSERT(isEqual == true, "Task putFromVersion1_PS:Objects of type TestPdxSerializerForV1 " @@ -263,24 +265,26 @@ DUNIT_TASK_DEFINITION(CLIENT2, putFromVersion2_PS) serializationRegistry->setPdxSerializer( std::shared_ptr(new TestPdxSerializerForV2)); - // Create New object and wrap it in PdxWrapper (owner) - auto npt1 = new PdxTests::TestDiffTypePdxSV2(true); - auto pdxobj = std::make_shared( - npt1, V2CLASSNAME4, + auto pdxSerializer = CacheRegionHelper::getCacheImpl(getHelper()->getCache().get()) ->getSerializationRegistry() - ->getPdxSerializer()); + ->getPdxSerializer(); + + // Create New object and wrap it in PdxWrapper (owner) + auto npt1 = std::make_shared(true); + auto pdxobj = + std::make_shared(npt1, V2CLASSNAME4, pdxSerializer); // PUT regPtr0->put(key, pdxobj); // GET auto obj2 = std::dynamic_pointer_cast(regPtr0->get(key)); - auto npt2 = - reinterpret_cast(obj2->getObject()); + auto npt2 = std::static_pointer_cast( + obj2->getObject()); // Equal check - bool isEqual = npt1->equals(npt2); + bool isEqual = npt1->equals(*npt2); LOGDEBUG("putFromVersion2_PS isEqual = %d", isEqual); ASSERT(isEqual == true, "Task putFromVersion2_PS:Objects of type TestPdxSerializerForV2 " @@ -298,12 +302,12 @@ DUNIT_TASK_DEFINITION(CLIENT1, getputFromVersion1_PS) // GET auto obj2 = std::dynamic_pointer_cast(regPtr0->get(key)); - auto npt2 = - reinterpret_cast(obj2->getObject()); + auto npt2 = std::static_pointer_cast( + obj2->getObject()); // Create New object and Compare - auto npt1 = new PdxTests::TestDiffTypePdxSV1(true); - bool isEqual = npt1->equals(npt2); + auto npt1 = std::make_shared(true); + bool isEqual = npt1->equals(*npt2); LOGDEBUG("getputFromVersion1_PS-1 isEqual = %d", isEqual); ASSERT(isEqual == true, "Task getputFromVersion1_PS:Objects of type TestPdxSerializerForV1 " @@ -314,20 +318,22 @@ DUNIT_TASK_DEFINITION(CLIENT1, getputFromVersion1_PS) auto key2 = CacheableKey::create(2); obj2 = std::dynamic_pointer_cast(regPtr0->get(key2)); - auto pRet = - reinterpret_cast(obj2->getObject()); - isEqual = npt1->equals(pRet); + auto pRet = std::static_pointer_cast( + obj2->getObject()); + isEqual = npt1->equals(*pRet); LOGDEBUG("getputFromVersion1_PS-2 isEqual = %d", isEqual); ASSERT(isEqual == true, "Task getputFromVersion1_PS:Objects of type TestPdxSerializerForV1 " "should be equal"); - // Get then Put.. this should Not merge data back - auto pdxobj = std::make_shared( - npt1, V1CLASSNAME2, + auto pdxSerializer = CacheRegionHelper::getCacheImpl(getHelper()->getCache().get()) ->getSerializationRegistry() - ->getPdxSerializer()); + ->getPdxSerializer(); + + // Get then Put.. this should Not merge data back + auto pdxobj = + std::make_shared(npt1, V1CLASSNAME2, pdxSerializer); regPtr0->put(key2, pdxobj); } END_TASK_DEFINITION @@ -342,10 +348,10 @@ DUNIT_TASK_DEFINITION(CLIENT2, getAtVersion2_PS) // GET auto obj2 = std::dynamic_pointer_cast(regPtr0->get(key)); - auto pRet = - reinterpret_cast(obj2->getObject()); + auto pRet = std::static_pointer_cast( + obj2->getObject()); - bool isEqual = np->equals(pRet); + bool isEqual = np->equals(*pRet); LOGDEBUG("getAtVersion2_PS-1 isEqual = %d", isEqual); ASSERT( isEqual == true, @@ -356,8 +362,9 @@ DUNIT_TASK_DEFINITION(CLIENT2, getAtVersion2_PS) np = new PdxTests::TestDiffTypePdxSV2(true); obj2 = std::dynamic_pointer_cast(regPtr0->get(key2)); - pRet = reinterpret_cast(obj2->getObject()); - isEqual = np->equals(pRet); + pRet = std::static_pointer_cast( + obj2->getObject()); + isEqual = np->equals(*pRet); LOGDEBUG("getAtVersion2_PS-2 isEqual = %d", isEqual); ASSERT( diff --git a/cppcache/integration-test/ThinClientPdxSerializers.hpp b/cppcache/integration-test/ThinClientPdxSerializers.hpp index 043b914..95ec188 100644 --- a/cppcache/integration-test/ThinClientPdxSerializers.hpp +++ b/cppcache/integration-test/ThinClientPdxSerializers.hpp @@ -40,7 +40,7 @@ class TestPdxSerializer : public PdxSerializer { } } - static size_t objectSize(const void *testObject, + static size_t objectSize(const std::shared_ptr &testObject, const std::string &className) { ASSERT(className == CLASSNAME1 || className == CLASSNAME2, "Unexpected classname in objectSize()"); @@ -48,31 +48,26 @@ class TestPdxSerializer : public PdxSerializer { return 12345; // dummy value } - UserDeallocator getDeallocator(const std::string &className) override { - ASSERT(className == CLASSNAME1 || className == CLASSNAME2, - "Unexpected classname in getDeallocator"); - return deallocate; - } - UserObjectSizer getObjectSizer(const std::string &className) override { ASSERT(className == CLASSNAME1 || className == CLASSNAME2, "Unexpected classname in getObjectSizer"); return objectSize; } - void *fromDataForAddress(PdxReader &pr) { + std::shared_ptr fromDataForAddress(PdxReader &pr) { try { - PdxTests::NonPdxAddress *npa = new PdxTests::NonPdxAddress; + auto npa = std::make_shared(); npa->_aptNumber = pr.readInt("_aptNumber"); npa->_street = pr.readString("_street"); npa->_city = pr.readString("_city"); - return (void *)npa; + return npa; } catch (...) { return nullptr; } } - void *fromData(const std::string &className, PdxReader &pr) override { + std::shared_ptr fromData(const std::string &className, + PdxReader &pr) override { ASSERT(className == CLASSNAME1 || className == CLASSNAME2, "Unexpected classname in fromData"); @@ -80,10 +75,10 @@ class TestPdxSerializer : public PdxSerializer { return fromDataForAddress(pr); } - PdxTests::NonPdxType *npt = - new PdxTests::NonPdxType(CacheRegionHelper::getCacheImpl(getHelper()->getCache().get()) - ->getSerializationRegistry() - ->getPdxSerializer()); + auto npt = std::make_shared( + CacheRegionHelper::getCacheImpl(getHelper()->getCache().get()) + ->getSerializationRegistry() + ->getPdxSerializer()); try { auto Lengtharr = new int32_t[2]; @@ -170,13 +165,14 @@ class TestPdxSerializer : public PdxSerializer { } catch (...) { return nullptr; } - return (void *)npt; + return npt; } - bool toDataForAddress(void *testObject, PdxWriter &pw) { + bool toDataForAddress(const std::shared_ptr &testObject, + PdxWriter &pw) { try { - PdxTests::NonPdxAddress *npa = - reinterpret_cast(testObject); + auto npa = + std::static_pointer_cast(testObject); pw.writeInt("_aptNumber", npa->_aptNumber); pw.writeString("_street", npa->_street); pw.writeString("_city", npa->_city); @@ -186,8 +182,8 @@ class TestPdxSerializer : public PdxSerializer { } } - bool toData(void *testObject, const std::string &className, - PdxWriter &pw) override { + bool toData(const std::shared_ptr &testObject, + const std::string &className, PdxWriter &pw) override { ASSERT(className == CLASSNAME1 || className == CLASSNAME2, "Unexpected classname in toData"); @@ -195,8 +191,7 @@ class TestPdxSerializer : public PdxSerializer { return toDataForAddress(testObject, pw); } - PdxTests::NonPdxType *npt = - reinterpret_cast(testObject); + auto npt = std::static_pointer_cast(testObject); try { int *lengthArr = new int[2]; diff --git a/cppcache/src/PdxWrapper.cpp b/cppcache/src/PdxWrapper.cpp index bd4265c..a46a6c0 100644 --- a/cppcache/src/PdxWrapper.cpp +++ b/cppcache/src/PdxWrapper.cpp @@ -25,7 +25,7 @@ namespace apache { namespace geode { namespace client { -PdxWrapper::PdxWrapper(void *userObject, std::string className, +PdxWrapper::PdxWrapper(std::shared_ptr userObject, std::string className, std::shared_ptr pdxSerializerPtr) : m_userObject(userObject), m_className(className), @@ -36,17 +36,6 @@ PdxWrapper::PdxWrapper(void *userObject, std::string className, "No registered PDX serializer found for PdxWrapper"); } - m_deallocator = m_serializer->getDeallocator(className); - - if (m_deallocator == nullptr) { - LOGERROR( - "No deallocator function found from PDX serializer for PdxWrapper " - "for " + - className); - throw IllegalArgumentException( - "No deallocator function found from PDX serializer for PdxWrapper"); - } - /* m_sizer can be nullptr - required only if heap LRU is enabled */ m_sizer = m_serializer->getObjectSizer(className); } @@ -61,48 +50,27 @@ PdxWrapper::PdxWrapper(std::string className, "No registered PDX serializer found for PdxWrapper deserialization"); } - m_deallocator = m_serializer->getDeallocator(className.c_str()); - - if (m_deallocator == nullptr) { - LOGERROR( - "No deallocator function found from PDX serializer for PdxWrapper " - "deserialization for " + - className); - throw IllegalArgumentException( - "No deallocator function found from PDX serializer for PdxWrapper " - "deserialization"); - } - /* m_sizer can be nullptr - required only if heap LRU is enabled */ m_sizer = m_serializer->getObjectSizer(className); - /* adongre - Coverity II - * CID 29277: Uninitialized pointer field (UNINIT_CTOR) - */ - m_userObject = (void *)0; + m_userObject = nullptr; } -void *PdxWrapper::getObject(bool detach) { - void *retVal = m_userObject; - if (detach) { - m_userObject = nullptr; - } - return retVal; -} +std::shared_ptr PdxWrapper::getObject() { return m_userObject; } const std::string &PdxWrapper::getClassName() const { return m_className; } bool PdxWrapper::operator==(const CacheableKey &other) const { - PdxWrapper *wrapper = - dynamic_cast(const_cast(&other)); + auto wrapper = dynamic_cast(&other); if (wrapper == nullptr) { return false; } - return (intptr_t)m_userObject == (intptr_t)wrapper->m_userObject; + return m_userObject == wrapper->m_userObject; } int32_t PdxWrapper::hashcode() const { - uint64_t hash = static_cast((intptr_t)m_userObject); + auto hash = static_cast( + reinterpret_cast(m_userObject.get())); return apache::geode::client::serializer::hashcode(hash); } @@ -137,18 +105,13 @@ size_t PdxWrapper::objectSize() const { return m_sizer(m_userObject, m_className.c_str()); } } + std::string PdxWrapper::toString() const { std::string message = "PdxWrapper for "; message += m_className; return message.c_str(); } -PdxWrapper::~PdxWrapper() { - if (m_userObject != nullptr) { - m_deallocator(m_userObject, m_className); - } -} - } // namespace client } // namespace geode } // namespace apache diff --git a/tests/cpp/testobject/NonPdxType.cpp b/tests/cpp/testobject/NonPdxType.cpp index 47b5a87..5f22cba 100644 --- a/tests/cpp/testobject/NonPdxType.cpp +++ b/tests/cpp/testobject/NonPdxType.cpp @@ -114,12 +114,12 @@ bool PdxTests::NonPdxType::equals(PdxTests::NonPdxType& other, for (int i = 0; i < m_objectArray->size(); i++) { auto wrapper1 = std::dynamic_pointer_cast(ot->m_objectArray->at(i)); - NonPdxAddress* otherAddr1 = - reinterpret_cast(wrapper1->getObject()); + auto otherAddr1 = + std::static_pointer_cast(wrapper1->getObject()); auto wrapper2 = std::dynamic_pointer_cast(m_objectArray->at(i)); - NonPdxAddress* myAddr1 = - reinterpret_cast(wrapper2->getObject()); + auto myAddr1 = + std::static_pointer_cast(wrapper2->getObject()); if (!otherAddr1->equals(*myAddr1)) return false; } } diff --git a/tests/cpp/testobject/NonPdxType.hpp b/tests/cpp/testobject/NonPdxType.hpp index 65acde6..e292d81 100644 --- a/tests/cpp/testobject/NonPdxType.hpp +++ b/tests/cpp/testobject/NonPdxType.hpp @@ -129,7 +129,7 @@ class TESTOBJECT_EXPORT NonPdxType { std::shared_ptr m_address; - NonPdxAddress* m_add[10]; + std::shared_ptr m_add[10]; std::shared_ptr m_arraylist; std::shared_ptr m_map; @@ -283,47 +283,47 @@ class TESTOBJECT_EXPORT NonPdxType { m_pdxEnum = CacheableEnum::create("PdxTests.pdxEnumTest", "pdx2", pdx2); - m_add[0] = new NonPdxAddress(1, "street0", "city0"); - m_add[1] = new NonPdxAddress(2, "street1", "city1"); - m_add[2] = new NonPdxAddress(3, "street2", "city2"); - m_add[3] = new NonPdxAddress(4, "street3", "city3"); - m_add[4] = new NonPdxAddress(5, "street4", "city4"); - m_add[5] = new NonPdxAddress(6, "street5", "city5"); - m_add[6] = new NonPdxAddress(7, "street6", "city6"); - m_add[7] = new NonPdxAddress(8, "street7", "city7"); - m_add[8] = new NonPdxAddress(9, "street8", "city8"); - m_add[9] = new NonPdxAddress(10, "street9", "city9"); + m_add[0] = std::make_shared(1, "street0", "city0"); + m_add[1] = std::make_shared(2, "street1", "city1"); + m_add[2] = std::make_shared(3, "street2", "city2"); + m_add[3] = std::make_shared(4, "street3", "city3"); + m_add[4] = std::make_shared(5, "street4", "city4"); + m_add[5] = std::make_shared(6, "street5", "city5"); + m_add[6] = std::make_shared(7, "street6", "city6"); + m_add[7] = std::make_shared(8, "street7", "city7"); + m_add[8] = std::make_shared(9, "street8", "city8"); + m_add[9] = std::make_shared(10, "street9", "city9"); m_objectArray = CacheableObjectArray::create(); m_objectArray->push_back(std::shared_ptr( - new PdxWrapper(new NonPdxAddress(1, "street0", "city0"), + new PdxWrapper(std::make_shared(1, "street0", "city0"), "PdxTests.Address", pdxSerializer))); m_objectArray->push_back(std::shared_ptr( - new PdxWrapper(new NonPdxAddress(2, "street1", "city1"), + new PdxWrapper(std::make_shared(2, "street1", "city1"), "PdxTests.Address", pdxSerializer))); m_objectArray->push_back(std::shared_ptr( - new PdxWrapper(new NonPdxAddress(3, "street2", "city2"), + new PdxWrapper(std::make_shared(3, "street2", "city2"), "PdxTests.Address", pdxSerializer))); m_objectArray->push_back(std::shared_ptr( - new PdxWrapper(new NonPdxAddress(4, "street3", "city3"), + new PdxWrapper(std::make_shared(4, "street3", "city3"), "PdxTests.Address", pdxSerializer))); m_objectArray->push_back(std::shared_ptr( - new PdxWrapper(new NonPdxAddress(5, "street4", "city4"), + new PdxWrapper(std::make_shared(5, "street4", "city4"), "PdxTests.Address", pdxSerializer))); m_objectArray->push_back(std::shared_ptr( - new PdxWrapper(new NonPdxAddress(6, "street5", "city5"), + new PdxWrapper(std::make_shared(6, "street5", "city5"), "PdxTests.Address", pdxSerializer))); m_objectArray->push_back(std::shared_ptr( - new PdxWrapper(new NonPdxAddress(7, "street6", "city6"), + new PdxWrapper(std::make_shared(7, "street6", "city6"), "PdxTests.Address", pdxSerializer))); m_objectArray->push_back(std::shared_ptr( - new PdxWrapper(new NonPdxAddress(8, "street7", "city7"), + new PdxWrapper(std::make_shared(8, "street7", "city7"), "PdxTests.Address", pdxSerializer))); m_objectArray->push_back(std::shared_ptr( - new PdxWrapper(new NonPdxAddress(9, "street8", "city8"), + new PdxWrapper(std::make_shared(9, "street8", "city8"), "PdxTests.Address", pdxSerializer))); m_objectArray->push_back(std::shared_ptr( - new PdxWrapper(new NonPdxAddress(10, "street9", "city9"), + new PdxWrapper(std::make_shared(10, "street9", "city9"), "PdxTests.Address", pdxSerializer))); m_byte252 = std::vector(252); diff --git a/tests/cpp/testobject/PdxClassV1.cpp b/tests/cpp/testobject/PdxClassV1.cpp index 2d7d6aa..c887a02 100644 --- a/tests/cpp/testobject/PdxClassV1.cpp +++ b/tests/cpp/testobject/PdxClassV1.cpp @@ -681,13 +681,8 @@ TestDiffTypePdxSV1::TestDiffTypePdxSV1(bool init) { } } -bool TestDiffTypePdxSV1::equals(TestDiffTypePdxSV1 *obj) { - if (obj == NULL) return false; - - TestDiffTypePdxSV1 *other = dynamic_cast(obj); - if (other == NULL) return false; - - if (other->_id == _id && other->_name == _name) { +bool TestDiffTypePdxSV1::equals(const TestDiffTypePdxSV1& obj) { + if (obj._id == _id && obj._name == _name) { return true; } diff --git a/tests/cpp/testobject/PdxClassV1.hpp b/tests/cpp/testobject/PdxClassV1.hpp index b155b0f..e535d99 100644 --- a/tests/cpp/testobject/PdxClassV1.hpp +++ b/tests/cpp/testobject/PdxClassV1.hpp @@ -403,7 +403,7 @@ class TESTOBJECT_EXPORT TestDiffTypePdxSV1 { TestDiffTypePdxSV1(bool init); - bool equals(TestDiffTypePdxSV1* obj); + bool equals(const TestDiffTypePdxSV1& obj); }; /************************************************************ @@ -431,7 +431,7 @@ class TestPdxSerializerForV1 : public PdxSerializer { } } - static size_t objectSize(const void* testObject, + static size_t objectSize(const std::shared_ptr& testObject, const std::string& className) { // ASSERT(strcmp(className, V1CLASSNAME1) == 0 || strcmp(className, // V1CLASSNAME2) == 0, "Unexpected classname in objectSize()"); @@ -439,32 +439,27 @@ class TestPdxSerializerForV1 : public PdxSerializer { return 12345; // dummy value } - UserDeallocator getDeallocator(const std::string& className) override { - // ASSERT(strcmp(className, V1CLASSNAME1) == 0 || strcmp(className, - // V1CLASSNAME2) == 0, "Unexpected classname in getDeallocator"); - return deallocate; - } - UserObjectSizer getObjectSizer(const std::string& className) override { // ASSERT(strcmp(className, V1CLASSNAME1) == 0 || strcmp(className, // V1CLASSNAME2) == 0, "Unexpected classname in getObjectSizer"); return objectSize; } - void* fromDataForTestKeyV1(PdxReader& pr) { + std::shared_ptr fromDataForTestKeyV1(PdxReader& pr) { try { - PdxTests::TestKeyV1* tkv1 = new PdxTests::TestKeyV1; + auto tkv1 = std::make_shared(); tkv1->_id = pr.readString("_id"); - return (void*)tkv1; + return tkv1; } catch (...) { - return NULL; + return nullptr; } } - bool toDataForTestKeyV1(void* testObject, PdxWriter& pw) { + bool toDataForTestKeyV1(const std::shared_ptr& testObject, + PdxWriter& pw) { try { - PdxTests::TestKeyV1* tkv1 = - reinterpret_cast(testObject); + auto tkv1 = + std::static_pointer_cast(testObject); pw.writeString("_id", tkv1->_id); return true; @@ -473,20 +468,22 @@ class TestPdxSerializerForV1 : public PdxSerializer { } } - void* fromDataForTestDiffTypePdxSV1(PdxReader& pr) { + std::shared_ptr fromDataForTestDiffTypePdxSV1(PdxReader& pr) { try { - PdxTests::TestDiffTypePdxSV1* dtpv1 = new PdxTests::TestDiffTypePdxSV1; + auto dtpv1 = std::make_shared(); dtpv1->_id = pr.readString("_id"); dtpv1->_name = pr.readString("_name"); - return (void*)dtpv1; + return dtpv1; } catch (...) { - return NULL; + return nullptr; } } - bool toDataForTestDiffTypePdxSV1(void* testObject, PdxWriter& pw) { + bool toDataForTestDiffTypePdxSV1( + const std::shared_ptr& testObject, PdxWriter& pw) { try { - auto dtpv1 = reinterpret_cast(testObject); + auto dtpv1 = std::static_pointer_cast( + testObject); pw.writeString("_id", dtpv1->_id); pw.writeString("_name", dtpv1->_name); @@ -496,7 +493,8 @@ class TestPdxSerializerForV1 : public PdxSerializer { } } - virtual void* fromData(const std::string& className, PdxReader& pr) override { + std::shared_ptr fromData(const std::string& className, + PdxReader& pr) override { // ASSERT(strcmp(className, V1CLASSNAME1) == 0 || strcmp(className, // V1CLASSNAME2) == 0, "Unexpected classname in fromData"); @@ -508,12 +506,12 @@ class TestPdxSerializerForV1 : public PdxSerializer { } else { LOGINFO("TestPdxSerializerForV1::fromdata() Invalid Class Name"); - return NULL; + return nullptr; } } - virtual bool toData(void* testObject, const std::string& className, - PdxWriter& pw) override { + virtual bool toData(const std::shared_ptr& testObject, + const std::string& className, PdxWriter& pw) override { // ASSERT(strcmp(className, V1CLASSNAME1) == 0 || strcmp(className, // V1CLASSNAME2) == 0, "Unexpected classname in toData"); diff --git a/tests/cpp/testobject/PdxClassV2.cpp b/tests/cpp/testobject/PdxClassV2.cpp index 2bbc6bb..1100e40 100644 --- a/tests/cpp/testobject/PdxClassV2.cpp +++ b/tests/cpp/testobject/PdxClassV2.cpp @@ -729,20 +729,15 @@ TestDiffTypePdxSV2::TestDiffTypePdxSV2(bool init) { } } -bool TestDiffTypePdxSV2::equals(TestDiffTypePdxSV2 *obj) { - if (obj == NULL) return false; - - TestDiffTypePdxSV2 *other = dynamic_cast(obj); - if (other == NULL) return false; - - LOGINFO("TestDiffTypePdxSV2 other->_coun = %d and _count = %d ", - other->_count, _count); - LOGINFO("TestDiffTypePdxSV2 other->_id = %s and _id = %s ", - other->_id.c_str(), _id.c_str()); +bool TestDiffTypePdxSV2::equals(const TestDiffTypePdxSV2& other) { + LOGINFO("TestDiffTypePdxSV2 other->_coun = %d and _count = %d ", other._count, + _count); + LOGINFO("TestDiffTypePdxSV2 other->_id = %s and _id = %s ", other._id.c_str(), + _id.c_str()); LOGINFO("TestDiffTypePdxSV2 other->_name = %s and _name = %s ", - other->_name.c_str(), _name.c_str()); + other._name.c_str(), _name.c_str()); - if (other->_count == _count && other->_id == _id && other->_name == _name) { + if (other._count == _count && other._id == _id && other._name == _name) { return true; } diff --git a/tests/cpp/testobject/PdxClassV2.hpp b/tests/cpp/testobject/PdxClassV2.hpp index e1252a5..063b444 100644 --- a/tests/cpp/testobject/PdxClassV2.hpp +++ b/tests/cpp/testobject/PdxClassV2.hpp @@ -430,7 +430,7 @@ class TESTOBJECT_EXPORT TestDiffTypePdxSV2 { TestDiffTypePdxSV2(bool init); - bool equals(TestDiffTypePdxSV2* obj); + bool equals(const TestDiffTypePdxSV2& obj); }; /************************************************************ @@ -458,7 +458,7 @@ class TestPdxSerializerForV2 : public PdxSerializer { } } - static size_t objectSize(const void* testObject, + static size_t objectSize(const std::shared_ptr testObject, const std::string& className) { // ASSERT(strcmp(className, V2CLASSNAME3) == 0 || strcmp(className, // V2CLASSNAME4) == 0, "Unexpected classname in objectSize()"); @@ -466,13 +466,6 @@ class TestPdxSerializerForV2 : public PdxSerializer { return 12345; // dummy value } - virtual UserDeallocator getDeallocator( - const std::string& className) override { - // ASSERT(strcmp(className, V2CLASSNAME3) == 0 || strcmp(className, - // V2CLASSNAME4) == 0, "Unexpected classname in getDeallocator"); - return deallocate; - } - virtual UserObjectSizer getObjectSizer( const std::string& className) override { // ASSERT(strcmp(className, V2CLASSNAME3) == 0 || strcmp(className, @@ -480,20 +473,21 @@ class TestPdxSerializerForV2 : public PdxSerializer { return objectSize; } - void* fromDataForTestKeyV2(PdxReader& pr) { + std::shared_ptr fromDataForTestKeyV2(PdxReader& pr) { try { - PdxTests::TestKeyV2* tkv1 = new PdxTests::TestKeyV2; + auto tkv1 = std::shared_ptr(); tkv1->_id = pr.readString("_id"); - return (void*)tkv1; + return tkv1; } catch (...) { - return NULL; + return nullptr; } } - bool toDataForTestKeyV2(void* testObject, PdxWriter& pw) { + bool toDataForTestKeyV2(const std::shared_ptr& testObject, + PdxWriter& pw) { try { - PdxTests::TestKeyV2* tkv1 = - reinterpret_cast(testObject); + auto tkv1 = + std::static_pointer_cast(testObject); pw.writeString("_id", tkv1->_id); return true; @@ -502,22 +496,23 @@ class TestPdxSerializerForV2 : public PdxSerializer { } } - void* fromDataForTestDiffTypePdxSV2(PdxReader& pr) { + std::shared_ptr fromDataForTestDiffTypePdxSV2(PdxReader& pr) { try { - PdxTests::TestDiffTypePdxSV2* dtpv1 = new PdxTests::TestDiffTypePdxSV2; + auto dtpv1 = std::make_shared(); dtpv1->_id = pr.readString("_id"); dtpv1->_name = pr.readString("_name"); dtpv1->_count = pr.readInt("_count"); - return (void*)dtpv1; + return dtpv1; } catch (...) { - return NULL; + return nullptr; } } - bool toDataForTestDiffTypePdxSV2(void* testObject, PdxWriter& pw) { + bool toDataForTestDiffTypePdxSV2( + const std::shared_ptr& testObject, PdxWriter& pw) { try { - PdxTests::TestDiffTypePdxSV2* dtpv1 = - reinterpret_cast(testObject); + auto dtpv1 = std::static_pointer_cast( + testObject); pw.writeString("_id", dtpv1->_id); pw.markIdentityField("_id"); pw.writeString("_name", dtpv1->_name); @@ -529,7 +524,8 @@ class TestPdxSerializerForV2 : public PdxSerializer { } } - void* fromData(const std::string& className, PdxReader& pr) override { + std::shared_ptr fromData(const std::string& className, + PdxReader& pr) override { // ASSERT(strcmp(className, V2CLASSNAME3) == 0 || strcmp(className, // V2CLASSNAME4) == 0, "Unexpected classname in fromData"); @@ -545,8 +541,8 @@ class TestPdxSerializerForV2 : public PdxSerializer { } } - bool toData(void* testObject, const std::string& className, - PdxWriter& pw) override { + bool toData(const std::shared_ptr& testObject, + const std::string& className, PdxWriter& pw) override { // ASSERT(strcmp(className, V2CLASSNAME3) == 0 || strcmp(className, // V2CLASSNAME4) == 0, "Unexpected classname in toData"); -- To stop receiving notification emails like this one, please contact jbarrett@apache.org.