Skip to content

Commit 1f4afb9

Browse files
committed
improved SOO swap, fixed Darwin-clang build config
1 parent 6b871a8 commit 1f4afb9

4 files changed

Lines changed: 37 additions & 16 deletions

File tree

‎CHANGELOG‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ Release 1.5.2 (2013-03-??)
3333
- fixed GH #131: no timezone global var on OpenBSD
3434
- fixed GH #102: Some subprojects don't have x64 solutions for VS 2010
3535
- added GH #75: Poco::Uri addQueryParameter method
36-
- Poco::Environment::osDisplayName() now recognized Windows 8/Server 2012
36+
- Poco::Environment::osDisplayName() now recognizes Windows 8/Server 2012
3737
- fixed GH #140: Poco::Runnable threading cleanup issue
3838
- simplified default TCP/HTTPServer construction
3939
- fixed GH #141: Application::run() documentation/implementation discrepancy

‎Foundation/include/Poco/Any.h‎

Lines changed: 24 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -106,9 +106,9 @@ union Placeholder
106106
return pHolder;
107107
}
108108

109-
// MSVC71 doesn't extend friendship to nested class (Any::Holder)
110-
#if !defined(POCO_MSVC_VERSION) || (defined(POCO_MSVC_VERSION) && (POCO_MSVC_VERSION > 71))
111-
private:
109+
// MSVC71,80 won't extend friendship to nested class (Any::Holder)
110+
#if !defined(POCO_MSVC_VERSION) || (defined(POCO_MSVC_VERSION) && (POCO_MSVC_VERSION > 80))
111+
// private:
112112
#endif
113113

114114
PlaceholderT* pHolder;
@@ -165,7 +165,7 @@ class Any
165165
if(!empty())
166166
{
167167
if(_valueHolder.isLocal())
168-
content()->~ValueHolder();
168+
destruct();
169169
else
170170
delete content();
171171
}
@@ -174,9 +174,9 @@ class Any
174174
Any& swap(Any& other)
175175
/// Swaps the content of the two Anys.
176176
///
177-
/// When small object optimizaton is enabled,
178-
/// swap is only exception-safe when both (*this and
179-
/// other) objects are allocated on the heap.
177+
/// When small object optimizaton is enabled, swap only
178+
/// has no-throw guarantee when both (*this and other)
179+
/// objects are allocated on the heap.
180180
{
181181
if (this == &other) return *this;
182182

@@ -187,16 +187,24 @@ class Any
187187
else
188188
{
189189
Any tmp(*this);
190-
if (_valueHolder.isLocal()) this->~Any();
191-
construct(other);
192-
other = tmp;
190+
try
191+
{
192+
if (_valueHolder.isLocal()) destruct();
193+
construct(other);
194+
other = tmp;
195+
}
196+
catch (...)
197+
{
198+
construct(tmp);
199+
throw;
200+
}
193201
}
194202

195203
return *this;
196204
}
197205

198206
template<typename ValueType>
199-
Any & operator = (const ValueType& rhs)
207+
Any& operator = (const ValueType& rhs)
200208
/// Assignment operator for all types != Any.
201209
///
202210
/// Example:
@@ -309,6 +317,11 @@ class Any
309317
_valueHolder.erase();
310318
}
311319

320+
void destruct()
321+
{
322+
content()->~ValueHolder();
323+
}
324+
312325
Placeholder<ValueHolder> _valueHolder;
313326

314327

‎Foundation/include/Poco/Dynamic/Var.h‎

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -668,9 +668,17 @@ inline void Var::swap(Var& other)
668668
else
669669
{
670670
Var tmp(*this);
671-
if (_placeholder.isLocal()) destruct();
672-
construct(other);
673-
other = tmp;
671+
try
672+
{
673+
if (_placeholder.isLocal()) destruct();
674+
construct(other);
675+
other = tmp;
676+
}
677+
catch (...)
678+
{
679+
construct(tmp);
680+
throw;
681+
}
674682
}
675683

676684
#endif

‎build/config/Darwin-clang‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ LINK = $(CXX) -bind_at_load
3333
LIB = libtool -static -o
3434
RANLIB = ranlib
3535
SHLIB = $(CXX) -dynamiclib -o $@
36-
DYLIB = $(CXX) -dynamic -bundle $(RORELOCS) suppress -Wl,-bind_at_load -o $@
36+
DYLIB = $(CXX) -dynamic -bundle $(RORELOCS) -Wl,-bind_at_load -o $@
3737
SHLIBLN = $(POCO_BASE)/build/script/shlibln
3838
STRIP =
3939
DEP = $(POCO_BASE)/build/script/makedepend.clang

0 commit comments

Comments
 (0)