Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix issue #249 #250

Merged
merged 4 commits into from
Oct 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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