diff options
author | Friedemann Kleint <Friedemann.Kleint@qt.io> | 2022-03-25 10:50:55 +0100 |
---|---|---|
committer | Friedemann Kleint <Friedemann.Kleint@qt.io> | 2022-03-25 13:16:48 +0100 |
commit | b606d2acea870bad92b7f438126cc848e02af072 (patch) | |
tree | dfc301076e3738eccbf5688f041aba6d4ccad6ae | |
parent | 1a192167cf2da765a7d4988abda0b1e865d64e88 (diff) |
shiboken6/smart pointer test suite: Improve logging
Print the instantiation name of the pointee and improve
the messages.
Task-number: PYSIDE-454
Change-Id: Ie2f585c79d46faff965fb077aaf7c4763ea12868
Reviewed-by: Cristian Maureira-Fredes <cristian.maureira-fredes@qt.io>
-rw-r--r-- | sources/shiboken6/tests/libsmart/smart.cpp | 39 | ||||
-rw-r--r-- | sources/shiboken6/tests/libsmart/smart_sharedptr.h | 20 |
2 files changed, 32 insertions, 27 deletions
diff --git a/sources/shiboken6/tests/libsmart/smart.cpp b/sources/shiboken6/tests/libsmart/smart.cpp index ae0ed6877..09e1274de 100644 --- a/sources/shiboken6/tests/libsmart/smart.cpp +++ b/sources/shiboken6/tests/libsmart/smart.cpp @@ -36,40 +36,43 @@ static inline bool verbose() return Registry::getInstance()->verbose(); } -void SharedPtrBase::logDefaultConstructor(const void *t) +void SharedPtrBase::logDefaultConstructor(const char *instantiation, const void *t) { if (verbose()) - std::cout << "shared_ptr default constructor " << t << '\n'; + std::cout << "SharedPtr<" << instantiation << "> default constructor " << t << '\n'; } -void SharedPtrBase::logConstructor(const void *t, const void *pointee) +void SharedPtrBase::logConstructor(const char *instantiation, const void *t, + const void *pointee) { if (verbose()) { - std::cout << "shared_ptr constructor " << t << " with pointer " - << pointee << '\n'; + std::cout << "SharedPtr<" << instantiation << "> constructor " + << t << " with pointer " << pointee << '\n'; } } -void SharedPtrBase::logCopyConstructor(const void *t, const void *refData) +void SharedPtrBase::logCopyConstructor(const char *instantiation, const void *t, + const void *refData) { if (verbose()) { - std::cout << "shared_ptr copy constructor " << t << " with pointer " - << refData << '\n'; + std::cout << "SharedPtr<" << instantiation << ">) copy constructor " + << t << " with pointer " << refData << '\n'; } } -void SharedPtrBase::logAssignment(const void *t, const void *refData) +void SharedPtrBase::logAssignment(const char *instantiation, const void *t, const void *refData) { if (verbose()) { - std::cout << "shared_ptr assignment operator " << t << " with pointer " - << refData << "\n"; + std::cout << "SharedPtr<" << instantiation << ">::operator= " << t + << " with pointer " << refData << "\n"; } } -void SharedPtrBase::logDestructor(const void *t, int remainingRefCount) +void SharedPtrBase::logDestructor(const char *instantiation, const void *t, + int remainingRefCount) { if (verbose()) { - std::cout << "shared_ptr destructor " << t << " remaining refcount " + std::cout << "~SharedPtr<" << instantiation << "> " << t << ", remaining refcount " << remainingRefCount << '\n'; } } @@ -78,7 +81,7 @@ Obj::Obj() : m_integer(123), m_internalInteger(new Integer) { Registry::getInstance()->add(this); if (verbose()) - std::cout << "Object constructor " << this << '\n'; + std::cout << "Obj constructor " << this << '\n'; } Obj::~Obj() @@ -86,13 +89,13 @@ Obj::~Obj() Registry::getInstance()->remove(this); delete m_internalInteger; if (verbose()) - std::cout << "Object destructor " << this << '\n'; + std::cout << "~Obj " << this << '\n'; } void Obj::printObj() { if (verbose()) { - std::cout << "integer value: " << m_integer + std::cout << "Obj::printObj(): integer value: " << m_integer << " internal integer value: " << m_internalInteger->value() << '\n'; } } @@ -207,7 +210,7 @@ Integer::~Integer() { Registry::getInstance()->remove(this); if (verbose()) - std::cout << "Integer destructor " << this << '\n'; + std::cout << "~Integer " << this << " (" << m_int << ")\n"; } int Integer::value() const @@ -218,6 +221,8 @@ int Integer::value() const void Integer::setValue(int v) { m_int = v; + if (verbose()) + std::cout << "Integer::setValue(" << v << ") " << this << '\n'; } int Integer::compare(const Integer &rhs) const diff --git a/sources/shiboken6/tests/libsmart/smart_sharedptr.h b/sources/shiboken6/tests/libsmart/smart_sharedptr.h index 65a489c68..b9043b36b 100644 --- a/sources/shiboken6/tests/libsmart/smart_sharedptr.h +++ b/sources/shiboken6/tests/libsmart/smart_sharedptr.h @@ -35,32 +35,32 @@ struct SharedPtrBase { - LIB_SMART_API static void logDefaultConstructor(const void *t); - LIB_SMART_API static void logConstructor(const void *t, const void *pointee); - LIB_SMART_API static void logCopyConstructor(const void *t, const void *refData); - LIB_SMART_API static void logAssignment(const void *t, const void *refData); - LIB_SMART_API static void logDestructor(const void *t, int remainingRefCount); + LIB_SMART_API static void logDefaultConstructor(const char *instantiation, const void *t); + LIB_SMART_API static void logConstructor(const char *instantiation, const void *t, const void *pointee); + LIB_SMART_API static void logCopyConstructor(const char *instantiation, const void *t, const void *refData); + LIB_SMART_API static void logAssignment(const char *instantiation, const void *t, const void *refData); + LIB_SMART_API static void logDestructor(const char *instantiation, const void *t, int remainingRefCount); }; template <class T> class SharedPtr : public SharedPtrBase { public: - SharedPtr() { logDefaultConstructor(this); } + SharedPtr() { logDefaultConstructor(typeid(T).name(), this); } SharedPtr(T *v) : mPtr(v) { - logConstructor(this, v); + logConstructor(typeid(T).name(), this, v); } SharedPtr(const SharedPtr<T> &other) : mPtr(other.mPtr) { - logCopyConstructor(this, data()); + logCopyConstructor(typeid(T).name(), this, data()); } template<class X> SharedPtr(const SharedPtr<X> &other) : mPtr(other.mPtr) { - logCopyConstructor(this, data()); + logCopyConstructor(typeid(T).name(), this, data()); } SharedPtr& operator=(const SharedPtr& other) @@ -107,7 +107,7 @@ public: ~SharedPtr() { if (mPtr.use_count() >= 1) - logDestructor(this, mPtr.use_count() - 1); + logDestructor(typeid(T).name(), this, mPtr.use_count() - 1); } std::shared_ptr<T> mPtr; |