Merge branch 'poco-1.10.1' into devel

This commit is contained in:
Günter Obiltschnig 2020-02-07 18:14:46 +01:00
commit bc69ddb128
6 changed files with 59 additions and 28 deletions

View File

@ -13,6 +13,7 @@ Release 1.10.1 (2020-02-10)
- GH #2818: Add getSpecifiedPort() method in Poco::URI. - GH #2818: Add getSpecifiedPort() method in Poco::URI.
- MySQL: resetting the session when putting it back into a SessionPool is now optional - MySQL: resetting the session when putting it back into a SessionPool is now optional
(and disabled by default) due to a bug in MySQL messing up the character encoding when doing so. (and disabled by default) due to a bug in MySQL messing up the character encoding when doing so.
- Poco::AutoPtr and Poco::SharedPtr now support comparison with nullptr.
Release 1.10.0 (2020-01-27) Release 1.10.0 (2020-01-27)

View File

@ -21,6 +21,7 @@
#include "Poco/Foundation.h" #include "Poco/Foundation.h"
#include "Poco/Exception.h" #include "Poco/Exception.h"
#include <algorithm> #include <algorithm>
#include <cstddef>
namespace Poco { namespace Poco {
@ -306,6 +307,11 @@ public:
return _ptr == ptr; return _ptr == ptr;
} }
bool operator == (std::nullptr_t ptr) const
{
return _ptr == ptr;
}
bool operator != (const AutoPtr& ptr) const bool operator != (const AutoPtr& ptr) const
{ {
return _ptr != ptr._ptr; return _ptr != ptr._ptr;
@ -321,6 +327,11 @@ public:
return _ptr != ptr; return _ptr != ptr;
} }
bool operator != (std::nullptr_t ptr) const
{
return _ptr != ptr;
}
bool operator < (const AutoPtr& ptr) const bool operator < (const AutoPtr& ptr) const
{ {
return _ptr < ptr._ptr; return _ptr < ptr._ptr;

View File

@ -22,6 +22,7 @@
#include "Poco/Exception.h" #include "Poco/Exception.h"
#include "Poco/AtomicCounter.h" #include "Poco/AtomicCounter.h"
#include <algorithm> #include <algorithm>
#include <cstddef>
namespace Poco { namespace Poco {
@ -336,6 +337,11 @@ public:
return get() == ptr; return get() == ptr;
} }
bool operator == (std::nullptr_t ptr) const
{
return get() == ptr;
}
bool operator != (const SharedPtr& ptr) const bool operator != (const SharedPtr& ptr) const
{ {
return get() != ptr.get(); return get() != ptr.get();
@ -351,6 +357,11 @@ public:
return get() != ptr; return get() != ptr;
} }
bool operator != (std::nullptr_t ptr) const
{
return get() != ptr;
}
bool operator < (const SharedPtr& ptr) const bool operator < (const SharedPtr& ptr) const
{ {
return get() < ptr.get(); return get() < ptr.get();

View File

@ -37,39 +37,39 @@ namespace
TestObj(int value1, const std::string& value2): _rc(1) TestObj(int value1, const std::string& value2): _rc(1)
{ {
} }
void duplicate() void duplicate()
{ {
++_rc; ++_rc;
} }
void release() void release()
{ {
if (--_rc == 0) if (--_rc == 0)
delete this; delete this;
} }
int rc() const int rc() const
{ {
return _rc; return _rc;
} }
static int count() static int count()
{ {
return _count; return _count;
} }
protected: protected:
~TestObj() ~TestObj()
{ {
--_count; --_count;
} }
private: private:
int _rc; int _rc;
static int _count; static int _count;
}; };
int TestObj::_count = 0; int TestObj::_count = 0;
} }
@ -137,27 +137,27 @@ void AutoPtrTest::testOps()
assertTrue (ptr2 == pTO2); assertTrue (ptr2 == pTO2);
assertTrue (ptr3.get() == pTO1); assertTrue (ptr3.get() == pTO1);
assertTrue (ptr3 == pTO1); assertTrue (ptr3 == pTO1);
assertTrue (ptr1 == pTO1); assertTrue (ptr1 == pTO1);
assertTrue (ptr1 != pTO2); assertTrue (ptr1 != pTO2);
assertTrue (ptr1 < pTO2); assertTrue (ptr1 < pTO2);
assertTrue (ptr1 <= pTO2); assertTrue (ptr1 <= pTO2);
assertTrue (ptr2 > pTO1); assertTrue (ptr2 > pTO1);
assertTrue (ptr2 >= pTO1); assertTrue (ptr2 >= pTO1);
assertTrue (ptr1 == ptr3); assertTrue (ptr1 == ptr3);
assertTrue (ptr1 != ptr2); assertTrue (ptr1 != ptr2);
assertTrue (ptr1 < ptr2); assertTrue (ptr1 < ptr2);
assertTrue (ptr1 <= ptr2); assertTrue (ptr1 <= ptr2);
assertTrue (ptr2 > ptr1); assertTrue (ptr2 > ptr1);
assertTrue (ptr2 >= ptr1); assertTrue (ptr2 >= ptr1);
ptr1 = pTO1; ptr1 = pTO1;
ptr2 = pTO2; ptr2 = pTO2;
ptr1.swap(ptr2); ptr1.swap(ptr2);
assertTrue (ptr2.get() == pTO1); assertTrue (ptr2.get() == pTO1);
assertTrue (ptr1.get() == pTO2); assertTrue (ptr1.get() == pTO2);
try try
{ {
assertTrue (ptr4->rc() > 0); assertTrue (ptr4->rc() > 0);
@ -171,14 +171,17 @@ void AutoPtrTest::testOps()
assertTrue (!(ptr4 == ptr2)); assertTrue (!(ptr4 == ptr2));
assertTrue (ptr4 != ptr1); assertTrue (ptr4 != ptr1);
assertTrue (ptr4 != ptr2); assertTrue (ptr4 != ptr2);
ptr4 = ptr2; ptr4 = ptr2;
assertTrue (ptr4 == ptr2); assertTrue (ptr4 == ptr2);
assertTrue (!(ptr4 != ptr2)); assertTrue (!(ptr4 != ptr2));
assertTrue (!(!ptr1)); assertTrue (!(!ptr1));
ptr1 = 0; ptr1 = 0;
assertTrue (!ptr1); assertTrue (!ptr1);
assertTrue (ptr1 == nullptr);
assertTrue (ptr2 != nullptr);
} }

View File

@ -28,27 +28,27 @@ namespace
{ {
++_count; ++_count;
} }
virtual ~TestObject() virtual ~TestObject()
{ {
--_count; --_count;
} }
const std::string& data() const std::string& data()
{ {
return _data; return _data;
} }
static int count() static int count()
{ {
return _count; return _count;
} }
private: private:
std::string _data; std::string _data;
static int _count; static int _count;
}; };
int TestObject::_count = 0; int TestObject::_count = 0;
class DerivedObject: public TestObject class DerivedObject: public TestObject
@ -62,7 +62,7 @@ namespace
{ {
return _number; return _number;
} }
private: private:
int _number; int _number;
}; };
@ -83,7 +83,10 @@ void SharedPtrTest::testSharedPtr()
{ {
SharedPtr<TestObject> ptr1; SharedPtr<TestObject> ptr1;
assertNull(ptr1.get()); assertNull(ptr1.get());
assertTrue (ptr1 == nullptr);
TestObject* pTO1 = new TestObject("one"); TestObject* pTO1 = new TestObject("one");
TestObject* pTO2 = new TestObject("two"); TestObject* pTO2 = new TestObject("two");
if (pTO2 < pTO1) if (pTO2 < pTO1)
{ {
@ -93,6 +96,8 @@ void SharedPtrTest::testSharedPtr()
} }
assertTrue (pTO1 < pTO2); assertTrue (pTO1 < pTO2);
ptr1 = pTO1; ptr1 = pTO1;
assertTrue (ptr1 != nullptr);
assertTrue (ptr1.referenceCount() == 1); assertTrue (ptr1.referenceCount() == 1);
SharedPtr<TestObject> ptr2 = pTO2; SharedPtr<TestObject> ptr2 = pTO2;
SharedPtr<TestObject> ptr3 = ptr1; SharedPtr<TestObject> ptr3 = ptr1;
@ -104,27 +109,27 @@ void SharedPtrTest::testSharedPtr()
assertTrue (ptr2 == pTO2); assertTrue (ptr2 == pTO2);
assertTrue (ptr3.get() == pTO1); assertTrue (ptr3.get() == pTO1);
assertTrue (ptr3 == pTO1); assertTrue (ptr3 == pTO1);
assertTrue (ptr1 == pTO1); assertTrue (ptr1 == pTO1);
assertTrue (ptr1 != pTO2); assertTrue (ptr1 != pTO2);
assertTrue (ptr1 < pTO2); assertTrue (ptr1 < pTO2);
assertTrue (ptr1 <= pTO2); assertTrue (ptr1 <= pTO2);
assertTrue (ptr2 > pTO1); assertTrue (ptr2 > pTO1);
assertTrue (ptr2 >= pTO1); assertTrue (ptr2 >= pTO1);
assertTrue (ptr1 == ptr3); assertTrue (ptr1 == ptr3);
assertTrue (ptr1 != ptr2); assertTrue (ptr1 != ptr2);
assertTrue (ptr1 < ptr2); assertTrue (ptr1 < ptr2);
assertTrue (ptr1 <= ptr2); assertTrue (ptr1 <= ptr2);
assertTrue (ptr2 > ptr1); assertTrue (ptr2 > ptr1);
assertTrue (ptr2 >= ptr1); assertTrue (ptr2 >= ptr1);
ptr1.swap(ptr2); ptr1.swap(ptr2);
assertTrue (ptr2 < ptr1); assertTrue (ptr2 < ptr1);
ptr2.swap(ptr1); ptr2.swap(ptr1);
assertTrue ((ptr1->data() == "one" && ptr2->data() == "two") || (ptr1->data() == "two" && ptr2->data() == "one")); assertTrue ((ptr1->data() == "one" && ptr2->data() == "two") || (ptr1->data() == "two" && ptr2->data() == "one"));
try try
{ {
assertTrue (ptr4->data() == "four"); assertTrue (ptr4->data() == "four");
@ -133,23 +138,23 @@ void SharedPtrTest::testSharedPtr()
catch (NullPointerException&) catch (NullPointerException&)
{ {
} }
assertTrue (!(ptr4 == ptr1)); assertTrue (!(ptr4 == ptr1));
assertTrue (!(ptr4 == ptr2)); assertTrue (!(ptr4 == ptr2));
assertTrue (ptr4 != ptr1); assertTrue (ptr4 != ptr1);
assertTrue (ptr4 != ptr2); assertTrue (ptr4 != ptr2);
ptr4 = ptr2; ptr4 = ptr2;
assertTrue (ptr4 == ptr2); assertTrue (ptr4 == ptr2);
assertTrue (!(ptr4 != ptr2)); assertTrue (!(ptr4 != ptr2));
assertTrue (TestObject::count() == 2); assertTrue (TestObject::count() == 2);
ptr1 = 0; ptr1 = 0;
ptr2 = 0; ptr2 = 0;
ptr3 = 0; ptr3 = 0;
ptr4 = 0; ptr4 = 0;
assertTrue (TestObject::count() == 0); assertTrue (TestObject::count() == 0);
{ {
SharedPtr<TestObject> ptr = new TestObject(""); SharedPtr<TestObject> ptr = new TestObject("");
assertTrue (TestObject::count() == 1); assertTrue (TestObject::count() == 1);

View File

@ -15,7 +15,7 @@ AAAIntroduction
- GH #2818: Add getSpecifiedPort() method in Poco::URI. - GH #2818: Add getSpecifiedPort() method in Poco::URI.
- MySQL: resetting the session when putting it back into a SessionPool is now optional - MySQL: resetting the session when putting it back into a SessionPool is now optional
(and disabled by default) due to a bug in MySQL messing up the character encoding when doing so. (and disabled by default) due to a bug in MySQL messing up the character encoding when doing so.
- Poco::AutoPtr and Poco::SharedPtr now support comparison with nullptr.
!!!Release 1.10.0 !!!Release 1.10.0