You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@geode.apache.org by jb...@apache.org on 2018/02/06 19:39:39 UTC
[geode-native] branch develop updated: GEODE-4605: Keep domain
object via shared_ptr. (#205)
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<void>. (#205)
f4f4c7b is described below
commit f4f4c7b34d194d5d4d68aad34cc2d6c95b3721c1
Author: Jacob Barrett <jb...@pivotal.io>
AuthorDate: Tue Feb 6 11:39:36 2018 -0800
GEODE-4605: Keep domain object via shared_ptr<void>. (#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<void(void*, const std::string&)>;
-
-/**
- * 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<size_t(const void*, const std::string&)>;
+using UserObjectSizer = std::function<size_t(const std::shared_ptr<const void>&,
+ 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<void> 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<const void>& 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<void> userObject, std::string className,
std::shared_ptr<PdxSerializer> 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<void> 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<void> m_userObject;
std::string m_className;
std::shared_ptr<PdxSerializer> 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 <string>
+
#include <ace/OS.h>
#include <ace/High_Res_Timer.h>
-#include <string>
+#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<TestPdxSerializer>());
+ serializationRegistry->setPdxSerializer(
+ std::make_shared<TestPdxSerializer>());
+
+ 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<PdxWrapper>(
- npt1, CLASSNAME1,
- CacheRegionHelper::getCacheImpl(getHelper()->getCache().get())
- ->getSerializationRegistry()
- ->getPdxSerializer());
+ auto npt1 = std::make_shared<PdxTests::NonPdxType>(pdxSerializer);
+ auto pdxobj = std::make_shared<PdxWrapper>(npt1, CLASSNAME1, pdxSerializer);
regPtr0->put(keyport, pdxobj);
auto obj2 = std::dynamic_pointer_cast<PdxWrapper>(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<PdxTests::NonPdxType*>(obj2->getObject());
+ auto npt2 =
+ std::static_pointer_cast<PdxTests::NonPdxType>(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<TestPdxSerializer>());
+ serializationRegistry->setPdxSerializer(
+ std::make_shared<TestPdxSerializer>());
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<PdxWrapper>(regPtr0->get(keyport1));
- auto npt1 = reinterpret_cast<PdxTests::NonPdxType*>(obj1->getObject());
+ auto npt1 =
+ std::static_pointer_cast<PdxTests::NonPdxType>(obj1->getObject());
LOGDEBUG("JavaGet-3 Line_316");
auto keyport2 = CacheableKey::create("putFromjava");
LOGDEBUG("JavaGet-4 Line_316");
auto obj2 = std::dynamic_pointer_cast<PdxWrapper>(regPtr0->get(keyport2));
- auto npt2 = reinterpret_cast<PdxTests::NonPdxType*>(obj2->getObject());
+ auto npt2 =
+ std::static_pointer_cast<PdxTests::NonPdxType>(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<TestPdxSerializerForV1>());
+ serializationRegistry->setPdxSerializer(
+ std::make_shared<TestPdxSerializerForV1>());
- // Create New object and wrap it in PdxWrapper (owner)
- auto npt1 = new PdxTests::TestDiffTypePdxSV1(true);
- auto pdxobj = std::make_shared<PdxWrapper>(
- 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<PdxTests::TestDiffTypePdxSV1>(true);
+ auto pdxobj =
+ std::make_shared<PdxWrapper>(npt1, V1CLASSNAME2, pdxSerializer);
// PUT
regPtr0->put(key, pdxobj);
// GET
auto obj2 = std::dynamic_pointer_cast<PdxWrapper>(regPtr0->get(key));
- auto npt2 =
- reinterpret_cast<PdxTests::TestDiffTypePdxSV1*>(obj2->getObject());
+ auto npt2 = std::static_pointer_cast<PdxTests::TestDiffTypePdxSV1>(
+ 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<PdxSerializer>(new TestPdxSerializerForV2));
- // Create New object and wrap it in PdxWrapper (owner)
- auto npt1 = new PdxTests::TestDiffTypePdxSV2(true);
- auto pdxobj = std::make_shared<PdxWrapper>(
- 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<PdxTests::TestDiffTypePdxSV2>(true);
+ auto pdxobj =
+ std::make_shared<PdxWrapper>(npt1, V2CLASSNAME4, pdxSerializer);
// PUT
regPtr0->put(key, pdxobj);
// GET
auto obj2 = std::dynamic_pointer_cast<PdxWrapper>(regPtr0->get(key));
- auto npt2 =
- reinterpret_cast<PdxTests::TestDiffTypePdxSV2*>(obj2->getObject());
+ auto npt2 = std::static_pointer_cast<PdxTests::TestDiffTypePdxSV2>(
+ 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<PdxWrapper>(regPtr0->get(key));
- auto npt2 =
- reinterpret_cast<PdxTests::TestDiffTypePdxSV1*>(obj2->getObject());
+ auto npt2 = std::static_pointer_cast<PdxTests::TestDiffTypePdxSV1>(
+ obj2->getObject());
// Create New object and Compare
- auto npt1 = new PdxTests::TestDiffTypePdxSV1(true);
- bool isEqual = npt1->equals(npt2);
+ auto npt1 = std::make_shared<PdxTests::TestDiffTypePdxSV1>(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<PdxWrapper>(regPtr0->get(key2));
- auto pRet =
- reinterpret_cast<PdxTests::TestDiffTypePdxSV1*>(obj2->getObject());
- isEqual = npt1->equals(pRet);
+ auto pRet = std::static_pointer_cast<PdxTests::TestDiffTypePdxSV1>(
+ 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<PdxWrapper>(
- 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<PdxWrapper>(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<PdxWrapper>(regPtr0->get(key));
- auto pRet =
- reinterpret_cast<PdxTests::TestDiffTypePdxSV2*>(obj2->getObject());
+ auto pRet = std::static_pointer_cast<PdxTests::TestDiffTypePdxSV2>(
+ 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<PdxWrapper>(regPtr0->get(key2));
- pRet = reinterpret_cast<PdxTests::TestDiffTypePdxSV2*>(obj2->getObject());
- isEqual = np->equals(pRet);
+ pRet = std::static_pointer_cast<PdxTests::TestDiffTypePdxSV2>(
+ 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<const void> &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<void> fromDataForAddress(PdxReader &pr) {
try {
- PdxTests::NonPdxAddress *npa = new PdxTests::NonPdxAddress;
+ auto npa = std::make_shared<PdxTests::NonPdxAddress>();
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<void> 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<PdxTests::NonPdxType>(
+ 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<const void> &testObject,
+ PdxWriter &pw) {
try {
- PdxTests::NonPdxAddress *npa =
- reinterpret_cast<PdxTests::NonPdxAddress *>(testObject);
+ auto npa =
+ std::static_pointer_cast<const PdxTests::NonPdxAddress>(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<const void> &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<PdxTests::NonPdxType *>(testObject);
+ auto npt = std::static_pointer_cast<const PdxTests::NonPdxType>(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<void> userObject, std::string className,
std::shared_ptr<PdxSerializer> 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<void> 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<PdxWrapper *>(const_cast<CacheableKey *>(&other));
+ auto wrapper = dynamic_cast<const PdxWrapper *>(&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<uint64_t>((intptr_t)m_userObject);
+ auto hash = static_cast<uint64_t>(
+ reinterpret_cast<std::uintptr_t>(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<PdxWrapper>(ot->m_objectArray->at(i));
- NonPdxAddress* otherAddr1 =
- reinterpret_cast<NonPdxAddress*>(wrapper1->getObject());
+ auto otherAddr1 =
+ std::static_pointer_cast<NonPdxAddress>(wrapper1->getObject());
auto wrapper2 =
std::dynamic_pointer_cast<PdxWrapper>(m_objectArray->at(i));
- NonPdxAddress* myAddr1 =
- reinterpret_cast<NonPdxAddress*>(wrapper2->getObject());
+ auto myAddr1 =
+ std::static_pointer_cast<NonPdxAddress>(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<Serializable> m_address;
- NonPdxAddress* m_add[10];
+ std::shared_ptr<NonPdxAddress> m_add[10];
std::shared_ptr<CacheableArrayList> m_arraylist;
std::shared_ptr<CacheableHashMap> 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<NonPdxAddress>(1, "street0", "city0");
+ m_add[1] = std::make_shared<NonPdxAddress>(2, "street1", "city1");
+ m_add[2] = std::make_shared<NonPdxAddress>(3, "street2", "city2");
+ m_add[3] = std::make_shared<NonPdxAddress>(4, "street3", "city3");
+ m_add[4] = std::make_shared<NonPdxAddress>(5, "street4", "city4");
+ m_add[5] = std::make_shared<NonPdxAddress>(6, "street5", "city5");
+ m_add[6] = std::make_shared<NonPdxAddress>(7, "street6", "city6");
+ m_add[7] = std::make_shared<NonPdxAddress>(8, "street7", "city7");
+ m_add[8] = std::make_shared<NonPdxAddress>(9, "street8", "city8");
+ m_add[9] = std::make_shared<NonPdxAddress>(10, "street9", "city9");
m_objectArray = CacheableObjectArray::create();
m_objectArray->push_back(std::shared_ptr<PdxWrapper>(
- new PdxWrapper(new NonPdxAddress(1, "street0", "city0"),
+ new PdxWrapper(std::make_shared<NonPdxAddress>(1, "street0", "city0"),
"PdxTests.Address", pdxSerializer)));
m_objectArray->push_back(std::shared_ptr<PdxWrapper>(
- new PdxWrapper(new NonPdxAddress(2, "street1", "city1"),
+ new PdxWrapper(std::make_shared<NonPdxAddress>(2, "street1", "city1"),
"PdxTests.Address", pdxSerializer)));
m_objectArray->push_back(std::shared_ptr<PdxWrapper>(
- new PdxWrapper(new NonPdxAddress(3, "street2", "city2"),
+ new PdxWrapper(std::make_shared<NonPdxAddress>(3, "street2", "city2"),
"PdxTests.Address", pdxSerializer)));
m_objectArray->push_back(std::shared_ptr<PdxWrapper>(
- new PdxWrapper(new NonPdxAddress(4, "street3", "city3"),
+ new PdxWrapper(std::make_shared<NonPdxAddress>(4, "street3", "city3"),
"PdxTests.Address", pdxSerializer)));
m_objectArray->push_back(std::shared_ptr<PdxWrapper>(
- new PdxWrapper(new NonPdxAddress(5, "street4", "city4"),
+ new PdxWrapper(std::make_shared<NonPdxAddress>(5, "street4", "city4"),
"PdxTests.Address", pdxSerializer)));
m_objectArray->push_back(std::shared_ptr<PdxWrapper>(
- new PdxWrapper(new NonPdxAddress(6, "street5", "city5"),
+ new PdxWrapper(std::make_shared<NonPdxAddress>(6, "street5", "city5"),
"PdxTests.Address", pdxSerializer)));
m_objectArray->push_back(std::shared_ptr<PdxWrapper>(
- new PdxWrapper(new NonPdxAddress(7, "street6", "city6"),
+ new PdxWrapper(std::make_shared<NonPdxAddress>(7, "street6", "city6"),
"PdxTests.Address", pdxSerializer)));
m_objectArray->push_back(std::shared_ptr<PdxWrapper>(
- new PdxWrapper(new NonPdxAddress(8, "street7", "city7"),
+ new PdxWrapper(std::make_shared<NonPdxAddress>(8, "street7", "city7"),
"PdxTests.Address", pdxSerializer)));
m_objectArray->push_back(std::shared_ptr<PdxWrapper>(
- new PdxWrapper(new NonPdxAddress(9, "street8", "city8"),
+ new PdxWrapper(std::make_shared<NonPdxAddress>(9, "street8", "city8"),
"PdxTests.Address", pdxSerializer)));
m_objectArray->push_back(std::shared_ptr<PdxWrapper>(
- new PdxWrapper(new NonPdxAddress(10, "street9", "city9"),
+ new PdxWrapper(std::make_shared<NonPdxAddress>(10, "street9", "city9"),
"PdxTests.Address", pdxSerializer)));
m_byte252 = std::vector<int8_t>(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<TestDiffTypePdxSV1 *>(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<const void>& 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<void> fromDataForTestKeyV1(PdxReader& pr) {
try {
- PdxTests::TestKeyV1* tkv1 = new PdxTests::TestKeyV1;
+ auto tkv1 = std::make_shared<PdxTests::TestKeyV1>();
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<const void>& testObject,
+ PdxWriter& pw) {
try {
- PdxTests::TestKeyV1* tkv1 =
- reinterpret_cast<PdxTests::TestKeyV1*>(testObject);
+ auto tkv1 =
+ std::static_pointer_cast<const PdxTests::TestKeyV1>(testObject);
pw.writeString("_id", tkv1->_id);
return true;
@@ -473,20 +468,22 @@ class TestPdxSerializerForV1 : public PdxSerializer {
}
}
- void* fromDataForTestDiffTypePdxSV1(PdxReader& pr) {
+ std::shared_ptr<void> fromDataForTestDiffTypePdxSV1(PdxReader& pr) {
try {
- PdxTests::TestDiffTypePdxSV1* dtpv1 = new PdxTests::TestDiffTypePdxSV1;
+ auto dtpv1 = std::make_shared<PdxTests::TestDiffTypePdxSV1>();
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<const void>& testObject, PdxWriter& pw) {
try {
- auto dtpv1 = reinterpret_cast<PdxTests::TestDiffTypePdxSV1*>(testObject);
+ auto dtpv1 = std::static_pointer_cast<const PdxTests::TestDiffTypePdxSV1>(
+ 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<void> 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<const void>& 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<TestDiffTypePdxSV2 *>(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<const void> 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<void> fromDataForTestKeyV2(PdxReader& pr) {
try {
- PdxTests::TestKeyV2* tkv1 = new PdxTests::TestKeyV2;
+ auto tkv1 = std::shared_ptr<PdxTests::TestKeyV2>();
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<const void>& testObject,
+ PdxWriter& pw) {
try {
- PdxTests::TestKeyV2* tkv1 =
- reinterpret_cast<PdxTests::TestKeyV2*>(testObject);
+ auto tkv1 =
+ std::static_pointer_cast<const PdxTests::TestKeyV2>(testObject);
pw.writeString("_id", tkv1->_id);
return true;
@@ -502,22 +496,23 @@ class TestPdxSerializerForV2 : public PdxSerializer {
}
}
- void* fromDataForTestDiffTypePdxSV2(PdxReader& pr) {
+ std::shared_ptr<void> fromDataForTestDiffTypePdxSV2(PdxReader& pr) {
try {
- PdxTests::TestDiffTypePdxSV2* dtpv1 = new PdxTests::TestDiffTypePdxSV2;
+ auto dtpv1 = std::make_shared<PdxTests::TestDiffTypePdxSV2>();
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<const void>& testObject, PdxWriter& pw) {
try {
- PdxTests::TestDiffTypePdxSV2* dtpv1 =
- reinterpret_cast<PdxTests::TestDiffTypePdxSV2*>(testObject);
+ auto dtpv1 = std::static_pointer_cast<const PdxTests::TestDiffTypePdxSV2>(
+ 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<void> 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<const void>& 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.