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

Revert regression of memory unsafe append_array (same vector into same vector). #101386

Merged

Conversation

Ivorforce
Copy link
Member

Follow-up of #101385

This will cause a minor performance regression. But Vector is CoW so it won't be noticeable (and probably not even observable).

See #31736.

@Ivorforce Ivorforce requested a review from a team as a code owner January 10, 2025 11:21
@AThousandShips AThousandShips added this to the 4.4 milestone Jan 10, 2025
@lawnjelly
Copy link
Member

lawnjelly commented Jan 10, 2025

#31736 was a great issue, I have to commend the author.

I've since been guilty of exactly this mistake myself (in LocalVector::erase_multiple_unordered(), it's a really easy thing to overlook. I suspect there's a lot of const T & in the containers that could do with reviewing for this bug.

Incidentally, for things like append in the long run, it could be worth checking for within the vector to avoid making a copy, because the benefits to doing the "check within" were higher the larger the size of the object being copied. As you say, here, COW might mostly negate this cost luckily.

@akien-mga
Copy link
Member

akien-mga commented Jan 10, 2025

I would amend #101385 into this PR's commit, it seems weird for #101385 to add comments for 3 cases and leave it to another PR to add the comment to the 4th case.

And add more exhaustive docs while fixing a regression to prevent such regressions in the future makes sense to me semantically.

@akien-mga akien-mga changed the title Revert regression of memory unsafe append_array (same vector into same vector). Revert regression of memory unsafe append_array (same vector into same vector). Jan 10, 2025
@akien-mga
Copy link
Member

For the record this was changed in #86966 (CC @Muller-Castro).
Might be worth re-reviewing that PR and its open follow-ups with #31736 in mind.

@Ivorforce
Copy link
Member Author

Ivorforce commented Jan 10, 2025

I would amend #101385 into this PR's commit, it seems weird for #101385 to add comments for 3 cases and leave it to another PR to add the comment to the 4th case.

And add more exhaustive docs while fixing a regression to prevent such regressions in the future makes sense to me semantically.

I did it this way because I like to have separate no-op commits (like adding docs) and behavior change commits. But I'm happy to oblige if you'd prefer to have it all in one.

Edit: Done!

… (append vector to itself). Add comments to prevent future regressions.
@Muller-Castro
Copy link
Contributor

Hello! 🤝 should I rollback the Vector<T> params?

@Ivorforce
Copy link
Member Author

Ivorforce commented Jan 11, 2025

Hello! 🤝 should I rollback the Vector<T> params?

Hi! 👋
No, it's not necessary, except when container elements may be moved around. I think in the case of Vector this PR just about covers it, but we may have missed more instances of this bug in other containers.

@akien-mga akien-mga merged commit 65af5ae into godotengine:master Jan 11, 2025
20 checks passed
@akien-mga
Copy link
Member

Thanks!

@Ivorforce Ivorforce deleted the vector-append-array-memorysafe branch January 11, 2025 21:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants