Commit 4dd16b34 authored by EXT Arnaud Clère's avatar EXT Arnaud Clère
Browse files

More precise numbers handling (avoid overflow) at the expense of

performance, even write :(
parent fd881f91
......@@ -252,7 +252,7 @@ protected:
row++; col=0;
return true;
}
Q_UNUSED(isErrorFiltered(qBindUnexpectedItem));
Q_UNUSED(isErrorFiltered(qBindUnexpectedItem))
return false;
}
return true;
......@@ -267,7 +267,7 @@ protected:
row=0; col++;
return true;
}
Q_UNUSED(isErrorFiltered(qBindUnexpectedItem));
Q_UNUSED(isErrorFiltered(qBindUnexpectedItem))
return false;
}
return true;
......@@ -297,7 +297,7 @@ protected:
else {
col=columnNames.indexOf(n.utf8());
// TODO if (max(dimension())<=col) col=-1;
if (col<0 && !isErrorFiltered(qBindUnexpectedItem)) {
if (col<0 && !isErrorFiltered(qBindUnexpectedItem, n.latin1())) {
return false;
}
}
......@@ -315,7 +315,7 @@ protected:
}
else {
// TODO if (rowNames...
return isErrorFiltered(qBindUnexpectedItem);
return isErrorFiltered(qBindUnexpectedItem, n.latin1());
}
}
else { Q_ASSERT(I<=d);
......@@ -452,7 +452,7 @@ protected:
if (col < m->columnCount()) {
return true;
}
Q_UNUSED(isErrorFiltered(qBindUnexpectedItem));
Q_UNUSED(isErrorFiltered(qBindUnexpectedItem))
return false;
}
return true;
......@@ -470,7 +470,7 @@ protected:
row=0; col++;
return true;
}
Q_UNUSED(isErrorFiltered(qBindUnexpectedItem));
Q_UNUSED(isErrorFiltered(qBindUnexpectedItem))
return false;
}
return true;
......
......@@ -256,10 +256,10 @@ protected:
void _meta (QIdentifierLiteral& n,
QAsciiData& m) { if (Q_LIKELY(impl) ) impl->_meta(n,m); } //!< idempotent (can be called by more than one code)
bool tryAny ( ) { return Q_LIKELY(impl) && impl->tryAny(); }
bool trySequence( quint32* s=nullptr) { return Q_LIKELY(impl) && (impl->trySequence(s) || (impl->isErrorFiltered(qBindExpectedSequence) && impl->tryAny())); }
bool tryRecord ( quint32* s=nullptr) { return Q_LIKELY(impl) && (impl->tryRecord (s) || (impl->isErrorFiltered(qBindExpectedRecord ) && impl->tryAny())); }
bool tryNull ( ) { return Q_LIKELY(impl) && (impl->tryNull ( ) || (impl->isErrorFiltered(qBindExpectedNull ) && impl->tryAny())); }
bool tryAny ( ) { return Q_LIKELY(impl) && impl->tryAny(); }
bool trySequence(quint32* s=nullptr) { return Q_LIKELY(impl) && (impl->trySequence(s) || (impl->isErrorFiltered(qBindExpectedSequence ) && impl->tryAny())); }
bool tryRecord (quint32* s=nullptr) { return Q_LIKELY(impl) && (impl->tryRecord (s) || (impl->isErrorFiltered(qBindExpectedRecord ) && impl->tryAny())); }
bool tryNull ( ) { return Q_LIKELY(impl) && (impl->tryNull ( ) || (impl->isErrorFiltered(qBindExpectedNull ) && impl->tryAny())); }
bool tryBind( QUtf8Data& t) { return Q_LIKELY(impl) && (impl->tryBind(t) || (impl->isErrorFiltered(qBindExpectedText ) && impl->tryAny())); }
bool tryBind( QString& t) { return Q_LIKELY(impl) && (impl->tryBind(t) || (impl->isErrorFiltered(qBindExpectedText ) && impl->tryAny())); }
......@@ -332,7 +332,7 @@ private:
template<class T> friend class QVal;
template<class T> friend class QSeq;
template<class T> friend class QRec;
void stop() noexcept { Q_UNUSED(isErrorFiltered(qBindStopped)); impl = nullptr; }
void stop() noexcept { Q_VERIFY(isErrorFiltered(qBindStopped)); impl = nullptr; }
QCur _unsafeCopy() noexcept { return impl ? QCur(impl) : QCur(); } // FIXME replace with std::move(outer) to avoid resuming read/write when QCur was actually stopped!
......@@ -564,20 +564,12 @@ public:
/**/ QRec<T_> bind (const char* n, QLatin1String l) { auto i = item(n); if (i) { return i.bind (l) ; } Q_UNUSED(outer->isErrorFiltered(qBindUnexpectedItem, n)); return QRec<T_> (); }
/**/ QRec<T_> bind (const char* n, QStringView u) { auto i = item(n); if (i) { return i.bind (u) ; } Q_UNUSED(outer->isErrorFiltered(qBindUnexpectedItem, n)); return QRec<T_> (); }
template<typename T> QRec<T_> bind (const char* n, T&& t) {
auto i = item(n);
if (i) {
auto r = i.bind( std::forward<T>( t));
return r;
}
Q_UNUSED(outer->isErrorFiltered(qBindUnexpectedItem, n));
return QRec<T_>();
}
template<typename T> QRec<T_> bind (const char* n, T& t, T&& defaultT) { auto i = item(n); if (i) { return i.bind(t, std::forward<T>(defaultT)); } Q_UNUSED(outer->isErrorFiltered(qBindUnexpectedItem, n)); return QRec<T_>(); }
template<typename T> QRec<T_> bind(const char* n, T&& t ) { auto i = item(n); if (i) { return i.bind( std::forward<T>( t)); } Q_UNUSED(outer->isErrorFiltered(qBindUnexpectedItem, n)); return QRec<T_>(); }
template<typename T> QRec<T_> bind(const char* n, T& t, T&& defaultT) { auto i = item(n); if (i) { return i.bind(t, std::forward<T>(defaultT)); } Q_UNUSED(outer->isErrorFiltered(qBindUnexpectedItem, n)); return QRec<T_>(); }
// Custom bind support
/**/ QRec<T_> with (const char* n, QValLambda customBind) { auto i = item(n); if (i) { return i.with( customBind); } Q_UNUSED(outer->isErrorFiltered(qBindUnexpectedItem, n)); return QRec<T_>(); }
template<typename T> QRec<T_> with (const char* n, T& t, QValFunction<T> customBind) { auto i = item(n); if (i) { return i.bind(t, customBind); } Q_UNUSED(outer->isErrorFiltered(qBindUnexpectedItem, n)); return QRec<T_>(); }
/**/ QRec<T_> with(const char* n, QValLambda customBind) { auto i = item(n); if (i) { return i.with( customBind); } Q_UNUSED(outer->isErrorFiltered(qBindUnexpectedItem, n)); return QRec<T_>(); }
template<typename T> QRec<T_> with(const char* n, T& t, QValFunction<T> customBind) { auto i = item(n); if (i) { return i.bind(t, customBind); } Q_UNUSED(outer->isErrorFiltered(qBindUnexpectedItem, n)); return QRec<T_>(); }
private:
template<class T> friend class QVal;
explicit QRec(T_&& out) noexcept { outer = std::move(out); }
......@@ -793,31 +785,33 @@ struct QAbstractValueReader : public QAbstractValue
// }
virtual bool tryBind( const char* u) { return tryBind(QUtf8DataView(u)); }
virtual bool tryBind( QUtf8DataView u) { QUtf8Data r; if (!tryBind(r)) return false; Q_VERIFY(r.utf8()==u.data() || isErrorFiltered(qBindExpectedConstant)); return true; }
virtual bool tryBind(QAsciiDataView a) { QUtf8Data r; if (!tryBind(r)) return false; Q_VERIFY(r.utf8()==a.data() || isErrorFiltered(qBindExpectedConstant)); return true; }
virtual bool tryBind( QLatin1String l) { QString r; if (!tryBind(r)) return false; Q_VERIFY(r ==l || isErrorFiltered(qBindExpectedConstant)); return true; }
virtual bool tryBind( QStringView s) { QString r; if (!tryBind(r)) return false; Q_VERIFY(r ==s || isErrorFiltered(qBindExpectedConstant)); return true; }
virtual bool tryBind( QUtf8DataView u) { QUtf8Data r; if (!tryBind(r)) return false; Q_VERIFY(r.utf8()==u.data() || isErrorFiltered(qBindExpectedConstant)) return true; }
virtual bool tryBind(QAsciiDataView a) { QUtf8Data r; if (!tryBind(r)) return false; Q_VERIFY(r.utf8()==a.data() || isErrorFiltered(qBindExpectedConstant)) return true; }
virtual bool tryBind( QLatin1String l) { QString r; if (!tryBind(r)) return false; Q_VERIFY(r ==l || isErrorFiltered(qBindExpectedConstant)) return true; }
virtual bool tryBind( QStringView s) { QString r; if (!tryBind(r)) return false; Q_VERIFY(r ==s || isErrorFiltered(qBindExpectedConstant)) return true; }
virtual bool tryBind( QUtf8Data& s) = 0;
virtual bool tryBind( QString& s) { QUtf8Data u; if (!tryBind(u)) return false; s=QString::fromUtf8(u.utf8()); return true; }
virtual bool tryBind( bool& b) { QUtf8Data u; if (!tryBind(u)) return false;
if (u.utf8().compare("true" , Qt::CaseInsensitive)==0) { b=true ; }
else if (u.utf8().compare("false", Qt::CaseInsensitive)==0) { b=false; }
else { return false; } return true; }
// TODO Q_VERIFY(isErrorFiltered(qBindExpectedSmallerNumber)); n=... return true;
virtual bool tryBind( qint8& n) { qint64 l; if (!tryBind(l)) return false; if (l<std::numeric_limits< qint8>::min() || std::numeric_limits< qint8>::max()<l) { isErrorFiltered(qBindExpectedSmallerNumber); return false; } n= qint8(l); return true; }
virtual bool tryBind( quint8& n) { quint64 l; if (!tryBind(l)) return false; if ( std::numeric_limits< quint8>::max()<l) { isErrorFiltered(qBindExpectedSmallerNumber); return false; } n= quint8(l); return true; }
virtual bool tryBind( qint16& n) { qint64 l; if (!tryBind(l)) return false; if (l<std::numeric_limits<qint16>::min() || std::numeric_limits< qint16>::max()<l) { isErrorFiltered(qBindExpectedSmallerNumber); return false; } n= qint16(l); return true; }
virtual bool tryBind( quint16& n) { quint64 l; if (!tryBind(l)) return false; if ( std::numeric_limits<quint16>::max()<l) { isErrorFiltered(qBindExpectedSmallerNumber); return false; } n=quint16(l); return true; }
virtual bool tryBind( qint32& n) { qint64 l; if (!tryBind(l)) return false; if (l<std::numeric_limits<qint32>::min() || std::numeric_limits< qint32>::max()<l) { isErrorFiltered(qBindExpectedSmallerNumber); return false; } n= qint32(l); return true; }
virtual bool tryBind( quint32& n) { quint64 l; if (!tryBind(l)) return false; if ( std::numeric_limits<quint32>::max()<l) { isErrorFiltered(qBindExpectedSmallerNumber); return false; } n=quint32(l); return true; }
virtual bool tryBind( qint64& n) { QUtf8Data s; if (!tryBind(s)) return false; bool isOk=false; qint64 v; v=s.utf8().toLongLong (&isOk); if (isOk) { n=v; return true; } isErrorFiltered(qBindExpectedDecimal); return false; }
virtual bool tryBind( quint64& n) { QUtf8Data s; if (!tryBind(s)) return false; bool isOk=false; quint64 v; v=s.utf8().toULongLong(&isOk); if (isOk) { n=v; return true; } isErrorFiltered(qBindExpectedDecimal); return false; }
virtual bool tryBind( float& n) { double d; if (!tryBind(d)) return false; if (d<std::numeric_limits< float>::min() ) { Q_VERIFY(isErrorFiltered(qBindExpectedSmallerNumber)); n=std::numeric_limits<float>::min(); return true; } // using isErrorFiltered result to return false (allowing user to bind with a larger type) would require to cached the number read
if ( std::numeric_limits< float>::max()<d) { Q_VERIFY(isErrorFiltered(qBindExpectedSmallerNumber)); n=std::numeric_limits<float>::max(); return true; }
n=float(d); return true; }
virtual bool tryBind( double& n) { QUtf8Data s; if (!tryBind(s)) return false; bool isOk=false; double v; v=s.utf8().toDouble (&isOk); if (isOk) { n=v; return true; } isErrorFiltered(qBindExpectedDecimal ); return false; }
else { Q_VERIFY(isErrorFiltered(qBindExpectedBoolean)) } return true; }
virtual bool tryBind( qint8& n) { qint64 l; if (!tryBind(l)) return false; if (l<std::numeric_limits< qint8>::min() ) { Q_VERIFY(isErrorFiltered(qBindExpectedSmallerNumber)) n=std::numeric_limits< qint8>::min(); return true; }
if ( std::numeric_limits< qint8>::max()<l) { Q_VERIFY(isErrorFiltered(qBindExpectedSmallerNumber)) n=std::numeric_limits< qint8>::max(); return true; } n= qint8(l); return true; }
virtual bool tryBind( quint8& n) { quint64 l; if (!tryBind(l)) return false; if ( std::numeric_limits< quint8>::max()<l) { Q_VERIFY(isErrorFiltered(qBindExpectedSmallerNumber)) n=std::numeric_limits< quint8>::max(); return true; } n= quint8(l); return true; }
virtual bool tryBind( qint16& n) { qint64 l; if (!tryBind(l)) return false; if (l<std::numeric_limits< qint16>::min() ) { Q_VERIFY(isErrorFiltered(qBindExpectedSmallerNumber)) n=std::numeric_limits< qint16>::min(); return true; }
if ( std::numeric_limits< qint16>::max()<l) { Q_VERIFY(isErrorFiltered(qBindExpectedSmallerNumber)) n=std::numeric_limits< qint16>::max(); return true; } n= qint16(l); return true; }
virtual bool tryBind( quint16& n) { quint64 l; if (!tryBind(l)) return false; if ( std::numeric_limits<quint16>::max()<l) { Q_VERIFY(isErrorFiltered(qBindExpectedSmallerNumber)) n=std::numeric_limits<quint16>::max(); return true; } n=quint16(l); return true; }
virtual bool tryBind( qint32& n) { qint64 l; if (!tryBind(l)) return false; if (l<std::numeric_limits< qint32>::min() ) { Q_VERIFY(isErrorFiltered(qBindExpectedSmallerNumber)) n=std::numeric_limits< qint32>::min(); return true; }
if ( std::numeric_limits< qint32>::max()<l) { Q_VERIFY(isErrorFiltered(qBindExpectedSmallerNumber)) n=std::numeric_limits< qint32>::max(); return true; } n= qint32(l); return true; }
virtual bool tryBind( quint32& n) { quint64 l; if (!tryBind(l)) return false; if ( std::numeric_limits<quint32>::max()<l) { Q_VERIFY(isErrorFiltered(qBindExpectedSmallerNumber)) n=std::numeric_limits<quint32>::max(); return true; } n=quint32(l); return true; }
virtual bool tryBind( float& n) { double d; if (!tryBind(d)) return false; if (d<std::numeric_limits< float>::min() ) { Q_VERIFY(isErrorFiltered(qBindExpectedSmallerNumber)) n=std::numeric_limits< float>::min(); return true; } // using isErrorFiltered result to return false (allowing user to bind with a larger type) would require to cached the number read
if ( std::numeric_limits< float>::max()<d) { Q_VERIFY(isErrorFiltered(qBindExpectedSmallerNumber)) n=std::numeric_limits< float>::max(); return true; } n= float(d); return true; }
virtual bool tryBind( qint64& n) { QUtf8Data s; if (!tryBind(s)) return false; bool isOk=false; qint64 v; v=s.utf8().toLongLong (&isOk); if (isOk) { n=v; return true; } Q_VERIFY(isErrorFiltered(qBindExpectedInteger )) return true; }
virtual bool tryBind( quint64& n) { QUtf8Data s; if (!tryBind(s)) return false; bool isOk=false; quint64 v; v=s.utf8().toULongLong(&isOk); if (isOk) { n=v; return true; } Q_VERIFY(isErrorFiltered(qBindExpectedPositiveInteger)) return true; }
virtual bool tryBind( double& n) { QUtf8Data s; if (!tryBind(s)) return false; bool isOk=false; double v; v=s.utf8().toDouble (&isOk); if (isOk) { n=v; return true; } Q_VERIFY(isErrorFiltered(qBindExpectedDecimal )) return true; }
virtual bool tryBind( QByteArray& b) { QUtf8Data s; if (!tryBind(s)) return false; return toByteArray(b, s); }
virtual bool tryBind( QVariant& dst) {
{
......
......@@ -267,7 +267,8 @@ struct QTransmogrifier<QColor> {
do {
v=v.meta(n, m);
if (n==qmDataStreamVersion) {
if (m.utf8().toInt()<7) { v->isErrorFiltered("UnsupportedQDataStreamVersion");
if (m.utf8().toInt()<7) {
Q_UNUSED(v->isErrorFiltered("UnsupportedQDataStreamVersion"))
return v.null();
}
QRgba64 c64 = c.rgba64();
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment