Apologies, sent wrong version of the patch file, correct one attached now.
On 23/06/2016 18:12, NSS Ltd wrote:
> Here's a patch with the cleanups I think make sense. These may
> duplicate some Abhijit already has in the pipeline from my previous email.
>
diff --git a/aox/db.cpp b/aox/db.cpp
index 24a7dca..af5edbb 100644
--- a/aox/db.cpp
+++ b/aox/db.cpp
@@ -173,13 +173,16 @@ void Vacuum::execute()
qstate = 1;
log( "vacuum: delete from deliveries", Log::Significant );
do {
+ // Literals have changed meaning in c++11, we need spaces
+ // or they have potentially changed effect in future
+ // http://www.preney.ca/paul/archives/636
q = new Query( "delete from deliveries "
"where injected_at<current_timestamp-'" +
fn( days ) + " days'::interval "
"and id in "
"(select delivery from delivery_recipients "
" where action not in ($1,$2) "
- " limit "MSGBLOCKCOUNT") "
+ " limit " MSGBLOCKCOUNT ") "
"and id not in "
"(select delivery from delivery_recipients "
" where action in ($1,$2))", this );
@@ -209,7 +212,7 @@ void Vacuum::execute()
" left join deliveries d on
(m.id=d.message)"
" where mm.message is null and dm.message
is null"
" and d.message is null "
- " limit "MSGBLOCKCOUNT")", this );
+ " limit " MSGBLOCKCOUNT ")", this );
q->execute();
case 3:
if (!q->done())
@@ -221,7 +224,7 @@ void Vacuum::execute()
q = new Query( "delete from bodyparts where id in (select
id "
"from bodyparts b left join part_numbers p
on "
"(b.id=p.bodypart) where bodypart is null "
- " limit "MSGBLOCKCOUNT")", this );
+ " limit " MSGBLOCKCOUNT ")", this );
q->execute();
case 4:
if (!q->done())
diff --git a/core/allocator.cpp b/core/allocator.cpp
index 8571074..42c6a50 100644
--- a/core/allocator.cpp
+++ b/core/allocator.cpp
@@ -432,7 +432,7 @@ void Allocator::deallocate( void * p )
random binary data.
Scanning long strings is slow. Binary data can give false alarms
- during pointer scanning, which will lead ot memory not being
+ during pointer scanning, which will lead to memory not being
freed.
*/
@@ -533,8 +533,8 @@ void Allocator::mark()
}
-/*! Frees all memory that's no longer in use. This can take some time.
-
+/*! Frees all memory that's no longer in use. This can take some time.
+
Returns null if entries is null or empty, returns an object in
entries else. The returned object is (in some sense) the one
that's responsible for the largest share of allocated memory.
@@ -558,7 +558,7 @@ Garbage * Allocator::free( List<Garbage> * entries )
uint freed = 0;
objects = 0;
::marked = 0;
-
+
Garbage * biggest = 0;
// mark
@@ -918,7 +918,7 @@ void pointers( void * p )
if ( m->payload[n] == p ) {
fprintf( stderr,
"Pointer at 0x%p (in 0x%p, "
- "size <= %d, %d pointers)\n",
+ "size <= %d, %u pointers)\n",
&m->payload[n],
&m->payload[0],
a->step - bytes,
diff --git a/core/file.cpp b/core/file.cpp
index 70451d6..9f8f7db 100644
--- a/core/file.cpp
+++ b/core/file.cpp
@@ -22,8 +22,6 @@
#endif
-extern "C" void *memcpy(void *, const void *, uint);
-
class FileData
: public Garbage
diff --git a/db/query.cpp b/db/query.cpp
index 966e495..70d1bbe 100644
--- a/db/query.cpp
+++ b/db/query.cpp
@@ -562,7 +562,7 @@ void Query::notify()
try {
d->owner->execute();
}
- catch ( Exception e ) {
+ catch ( const Exception& e ) {
d->owner = 0; // so we can't get close to a segfault again
if ( e == Invariant ) {
setError( "Invariant failed while processing Query::notify()" );
@@ -599,7 +599,7 @@ void Query::notify()
}
}
else {
- throw e;
+ throw; // Re-throw without creating a copy (throw e makes a
redundant copy)
}
}
}
diff --git a/db/transaction.cpp b/db/transaction.cpp
index a85a7b5..d33ee4e 100644
--- a/db/transaction.cpp
+++ b/db/transaction.cpp
@@ -609,7 +609,7 @@ void Transaction::notify()
try {
d->owner->execute();
}
- catch ( Exception e ) {
+ catch ( const Exception& e ) {
d->owner = 0; // so we can't get close to a segfault again
if ( e == Invariant ) {
setError( 0,
@@ -633,7 +633,7 @@ void Transaction::notify()
}
}
else {
- throw e;
+ throw; // Rethrow without creating redundant copy (which throw e
does)
}
}
if ( done() && d->parent &&
diff --git a/encodings/utf.cpp b/encodings/utf.cpp
index 66bf4f2..7fc5cd1 100644
--- a/encodings/utf.cpp
+++ b/encodings/utf.cpp
@@ -230,18 +230,20 @@ EString Utf16Codec::fromUnicode( const UString & u )
{
EString r;
+ //
http://stackoverflow.com/questions/701624/difference-between-big-endian-and-little-endian-byte-order
+
if ( !bom ) {
// if we don't output a BOM, reader should assume BE, so we
// must be BE to conform
be = true;
}
else if ( be ) {
- r.append( 0xfe );
+ r.append( 0xfe ); // Big Endian UTF16-BE
r.append( 0xff );
}
else {
+ r.append( 0xff ); // Little Endian UTF16-LE
r.append( 0xfe );
- r.append( 0xff );
}
if ( be )
diff --git a/message/mimefields.cpp b/message/mimefields.cpp
index ccf3009..afd664a 100644
--- a/message/mimefields.cpp
+++ b/message/mimefields.cpp
@@ -381,10 +381,6 @@ void ContentType::parse( const EString &s )
t = "application";
st = "postscript";
}
- else if ( s == "postscript" ) {
- t = "application";
- st = "postscript";
- }
else if ( s == "sgml" ) {
t = "text";
st = "sgml";
diff --git a/server/eventloop.cpp b/server/eventloop.cpp
index 0db13e3..6e0953f 100644
--- a/server/eventloop.cpp
+++ b/server/eventloop.cpp
@@ -369,7 +369,7 @@ void EventLoop::start()
c->log( "Still have " +
EString::humanNumber( c->writeBuffer()->size() ) +
" bytes to write", Log::Debug );
- } catch ( Exception e ) {
+ } catch ( const Exception& e ) {
// we don't really care at this point, do we?
}
}
@@ -501,7 +501,7 @@ void EventLoop::dispatch( Connection * c, bool r, bool w,
uint now )
s && s == c->writeBuffer()->size() )
c->writeBuffer()->remove( s );
}
- catch ( Exception e ) {
+ catch ( const Exception& e ) {
EString s;
switch (e) {
case Invariant:
@@ -557,7 +557,7 @@ void EventLoop::stop( uint s )
else if ( s <= 1 && !c->hasProperty( Connection::Internal ) ) {
c->react( Connection::Shutdown );
}
- } catch ( Exception e ) {
+ } catch ( const Exception& e ) {
removeConnection( c );
}
}
diff --git a/server/selector.cpp b/server/selector.cpp
index 1b68a2a..c104bf8 100644
--- a/server/selector.cpp
+++ b/server/selector.cpp
@@ -1972,10 +1972,13 @@ EString Selector::debugString() const
break;
case Age:
w = "age";
+ break;
case DatabaseId:
w = "database-id";
+ break;
case ThreadId:
w = "thread-id";
+ break;
};
r = w + " " + o + " ";
diff --git a/server/server.cpp b/server/server.cpp
index b853071..4cd69ee 100644
--- a/server/server.cpp
+++ b/server/server.cpp
@@ -207,7 +207,7 @@ void Server::setup( Stage s )
}
d->stage = (Stage)(d->stage + 1);
}
- } catch ( Exception e ) {
+ } catch ( const Exception& e ) {
// don't allocate memory or call anything here.
const char * c = 0;
switch (e) {
diff --git a/server/timer.cpp b/server/timer.cpp
index f30a381..37f432b 100644
--- a/server/timer.cpp
+++ b/server/timer.cpp
@@ -135,7 +135,7 @@ void Timer::notify()
try {
d->owner->execute();
}
- catch ( Exception e ) {
+ catch ( const Exception& e ) {
d->owner = 0; // so we can't get close to a segfault again
if ( e == Invariant ) {
// Analogous to EventLoop::dispatch, we try to close the
@@ -161,7 +161,7 @@ void Timer::notify()
}
}
else {
- throw e;
+ throw; // Re-throws caught exception
}
}
}