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

Remove ::Ptr usage from SqliteFormat #56

Merged
merged 2 commits into from Apr 20, 2023
Merged

Conversation

dcaliste
Copy link
Contributor

@pvuorela, this is a proposition not to use ::Ptr internally in SqliteFormat. This is not really mandatory at the moment, nor simplifying much the code, but it helps to disconnect the SQLite backend from a calendar (and also does not pin the incidence ownership to the current thread). Now, SqliteFormat is just taking plain Incidence references to write to the database, or returning new objects on read that the caller is responsible to take ownership of.

It allows to catch some minor issues like changing some internal values of incidence on write, while it should be const.

@pvuorela
Copy link
Contributor

pvuorela commented Apr 4, 2023

Needs rebase and some adjustments, doesn't compile now on top of the search model changes.

@dcaliste
Copy link
Contributor Author

dcaliste commented Apr 4, 2023

I've corrected the code introduced by the search PR. Tests are passing as far as I can tell. Thank you for the notice.

@@ -656,7 +656,7 @@ int SqliteStorage::Private::loadIncidencesBySeries(sqlite3_stmt *stmt1, QStringL

while ((incidence = mFormat->selectComponents(stmt1, notebookUid))
&& (limit <= 0 || count < limit)) {
if (addIncidence(incidence, notebookUid)) {
if (addIncidence(Incidence::Ptr(incidence), notebookUid)) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks like potentially leaking memory. The selectComponents() returns an instance owned now by the caller, but then there are other filters above which can make this ctor skipped.

Perhaps safer if either the "incidence" instance is kept as Ptr or switched into some other similar type e.g. QScopedPointer, and the while loop assignment constructs a proper wrapped instance, or then we don't touch the return types at all if it should be Ptr always.

Maybe just better if we don't return instances owned by the caller?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, that's a good remark. Returning a pointer like that and not taking ownership immediately can be very error prone, as you demonstrated.

I'm withdrawing the third commit completely introducing this. Read routines will continue to return a QSharedPointer for the moment, up to when a real case for change appears.

src/sqliteformat.cpp Outdated Show resolved Hide resolved
@pvuorela
Copy link
Contributor

Indeed not sure how much this in practice helps, but cleaning up the side-effects to the incidences is nice and I have no objections either. So let's just have.

@pvuorela pvuorela merged commit 85854d2 into sailfishos:master Apr 20, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants