Skip to content

Don't add duplicate patients #2289

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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

EricCousineau-TRI
Copy link
Collaborator

@EricCousineau-TRI EricCousineau-TRI commented Jul 10, 2020

Fixes #1251
Either an alternative or precursor for #1253 - this does not create any ABI issues.

This is the forward-port of 56c1edb from v2.2.2, as mentioned here:
#1251 (comment)

Filed per @YannickJadoul's request:
#1251 (comment)

This fixes pybind#1251 (patient vector grows without bounds) for the 2.2.2
branch by checking that the vector doesn't already have the given
patient.

This is a little less elegant than the same fix for `master` in pybind#1253 (which
changes the patients `vector` to an `unordered_set`), but that requires
an internals layout change, which this approach avoids.
- Checks `not m.has_patients()` after nurse is gc'd
- Uses Python implementation of `refcount`
Copy link
Collaborator

@YannickJadoul YannickJadoul left a comment

Choose a reason for hiding this comment

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

Looks pretty clean/unobjectionable to me. Especially since it has already been merged at some point.

instance->has_patients = true;
for (auto &p : current_patients)
Copy link
Collaborator

Choose a reason for hiding this comment

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

This could be if (std::find(current_patients.begin(), current_patients.end(), patient) != current_patients.end()), I suppose. Normally that would be cleaner, but now it's actually lengthier. So probably not worth it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Using py::keep_alive<N, P>() may cause internals.patients[nurse] to grow without bounds
3 participants