Skip to content

Commit

Permalink
Merge pull request #252 from OpenBioSim/backport_250
Browse files Browse the repository at this point in the history
Backport fixes from PR #250
  • Loading branch information
lohedges authored Oct 30, 2024
2 parents 41c9092 + 9bf8445 commit 52a0578
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 25 deletions.
23 changes: 21 additions & 2 deletions corelib/src/libs/SireBase/pagecache.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -662,9 +662,28 @@ void CacheData::cleanUpOnExit()
{
if (QThread::currentThread() != c.get())
{
if (not c->wait(50))
bool is_finished = false;

// give the thread a maximum of 10 attempts to finish
for (int i = 0; i < 10; i++)
{
// the thread didn't finish
if (not c->wait(100))
{
qDebug() << "Waiting for cache thread to finish:" << c->cacheDir();
}
// the thread finished
else
{
is_finished = true;
break;
}
}

// the thread still didn't finish, so kill it
if (not is_finished)
{
// kill it
qDebug() << "Terminating cache thread:" << c->cacheDir();
c->terminate();
}
}
Expand Down
46 changes: 23 additions & 23 deletions corelib/src/libs/SireMol/trajectory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1380,9 +1380,9 @@ QByteArray Frame::toByteArray() const
ds << spc << t.to(picosecond) << props;

nbytes += sizeof(quint32);
nbytes += extra.count();
nbytes += extra.size();

QByteArray data("\0", nbytes);
QByteArray data(nbytes, '\0');

auto data_ptr = data.data();

Expand Down Expand Up @@ -1425,7 +1425,7 @@ QByteArray Frame::toByteArray() const
data_ptr += val * sizeof(Force3D);
}

val = extra.count();
val = extra.size();
std::memcpy(data_ptr, &val, sizeof(quint32));
data_ptr += sizeof(quint32);

Expand All @@ -1435,12 +1435,12 @@ QByteArray Frame::toByteArray() const
data_ptr += val;
}

if (data_ptr - data.constData() != data.count())
if (data_ptr - data.constData() != data.size())
{
throw SireError::program_bug(QObject::tr(
"Memory corruption? %1 versus %2")
.arg(data_ptr - data.constData())
.arg(data.count()),
.arg(data.size()),
CODELOC);
}

Expand All @@ -1449,9 +1449,9 @@ QByteArray Frame::toByteArray() const

Frame Frame::fromByteArray(const QByteArray &data)
{
if (data.count() < 4)
if (data.size() < 4)
{
throw SireError::incompatible_error(QObject::tr("The data is too short to be a frame! %1").arg(data.count()),
throw SireError::incompatible_error(QObject::tr("The data is too short to be a frame! %1").arg(data.size()),
CODELOC);
}

Expand All @@ -1474,9 +1474,9 @@ Frame Frame::fromByteArray(const QByteArray &data)
throw SireStream::version_error(val, "1", r_frame, CODELOC);
}

if (data_ptr + sizeof(quint32) > data.constData() + data.count())
if (data_ptr + sizeof(quint32) > data.constData() + data.size())
{
throw SireError::incompatible_error(QObject::tr("The data is too short to be a frame! %1").arg(data.count()),
throw SireError::incompatible_error(QObject::tr("The data is too short to be a frame! %1").arg(data.size()),
CODELOC);
}

Expand All @@ -1487,9 +1487,9 @@ Frame Frame::fromByteArray(const QByteArray &data)

if (val != 0)
{
if (data_ptr + val * sizeof(Vector) > data.constData() + data.count())
if (data_ptr + val * sizeof(Vector) > data.constData() + data.size())
{
throw SireError::incompatible_error(QObject::tr("The data is too short to be a frame! %1").arg(data.count()),
throw SireError::incompatible_error(QObject::tr("The data is too short to be a frame! %1").arg(data.size()),
CODELOC);
}

Expand All @@ -1498,9 +1498,9 @@ Frame Frame::fromByteArray(const QByteArray &data)
data_ptr += val * sizeof(Vector);
}

if (data_ptr + sizeof(quint32) > data.constData() + data.count())
if (data_ptr + sizeof(quint32) > data.constData() + data.size())
{
throw SireError::incompatible_error(QObject::tr("The data is too short to be a frame! %1").arg(data.count()),
throw SireError::incompatible_error(QObject::tr("The data is too short to be a frame! %1").arg(data.size()),
CODELOC);
}

Expand All @@ -1511,9 +1511,9 @@ Frame Frame::fromByteArray(const QByteArray &data)

if (val != 0)
{
if (data_ptr + val * sizeof(Velocity3D) > data.constData() + data.count())
if (data_ptr + val * sizeof(Velocity3D) > data.constData() + data.size())
{
throw SireError::incompatible_error(QObject::tr("The data is too short to be a frame! %1").arg(data.count()),
throw SireError::incompatible_error(QObject::tr("The data is too short to be a frame! %1").arg(data.size()),
CODELOC);
}

Expand All @@ -1522,9 +1522,9 @@ Frame Frame::fromByteArray(const QByteArray &data)
data_ptr += val * sizeof(Velocity3D);
}

if (data_ptr + sizeof(quint32) > data.constData() + data.count())
if (data_ptr + sizeof(quint32) > data.constData() + data.size())
{
throw SireError::incompatible_error(QObject::tr("The data is too short to be a frame! %1").arg(data.count()),
throw SireError::incompatible_error(QObject::tr("The data is too short to be a frame! %1").arg(data.size()),
CODELOC);
}

Expand All @@ -1535,9 +1535,9 @@ Frame Frame::fromByteArray(const QByteArray &data)

if (val != 0)
{
if (data_ptr + val * sizeof(Force3D) > data.constData() + data.count())
if (data_ptr + val * sizeof(Force3D) > data.constData() + data.size())
{
throw SireError::incompatible_error(QObject::tr("The data is too short to be a frame! %1").arg(data.count()),
throw SireError::incompatible_error(QObject::tr("The data is too short to be a frame! %1").arg(data.size()),
CODELOC);
}

Expand All @@ -1546,9 +1546,9 @@ Frame Frame::fromByteArray(const QByteArray &data)
data_ptr += val * sizeof(Force3D);
}

if (data_ptr + sizeof(quint32) > data.constData() + data.count())
if (data_ptr + sizeof(quint32) > data.constData() + data.size())
{
throw SireError::incompatible_error(QObject::tr("The data is too short to be a frame! %1").arg(data.count()),
throw SireError::incompatible_error(QObject::tr("The data is too short to be a frame! %1").arg(data.size()),
CODELOC);
}

Expand All @@ -1561,9 +1561,9 @@ Frame Frame::fromByteArray(const QByteArray &data)

if (val != 0)
{
if (data_ptr + val > data.constData() + data.count())
if (data_ptr + val > data.constData() + data.size())
{
throw SireError::incompatible_error(QObject::tr("The data is too short to be a frame! %1").arg(data.count()),
throw SireError::incompatible_error(QObject::tr("The data is too short to be a frame! %1").arg(data.size()),
CODELOC);
}

Expand Down
7 changes: 7 additions & 0 deletions doc/source/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,13 @@ Development was migrated into the
`OpenBioSim <https://github.com/openbiosim>`__
organisation on `GitHub <https://github.com/openbiosim/sire>`__.

`2024.4.0 <https://github.com/openbiosim/sire/compare/2024.3.0...2024.4.0>`__ - December 2024
---------------------------------------------------------------------------------------------

* Please add an item to this CHANGELOG for any new features or bug fixes when creating a PR.
* Fixed instantiaton of ``QByteArray`` in ``Sire::Mol::Frame::toByteArray`` and count bytes with ``QByteArray::size``.
* Increase timeout before terminating ``QThread`` objects during ``PageCache`` cleanup.

`2024.3.0 <https://github.com/openbiosim/sire/compare/2024.2.0...2024.3.0>`__ - October 2024
--------------------------------------------------------------------------------------------

Expand Down

0 comments on commit 52a0578

Please sign in to comment.