-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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
More precise return_value_policy::automatic documentation. #2920
Conversation
9f439ac
to
d521169
Compare
…o `absltest`. * Background: b/183240258 * Migration CL: cl/363927286 * Initial attempt to fix the ASAN failure for std_containers_test: cl/363992952 This CL takes a different approach compared to cl/363992952 for std_containers_test, by replacing `new SomeType` with `static SomeType`, and returning a pointer to the statically allocated object. `std_containers.h` is revised accordingly in this CL. A detail regarding the `std::vector<bool> *` return in std_containers.h: currently the pybind11 behavior does not match the documentation in pybind11/docs/advanced/functions.rst. pybind11 does NOT `take_ownership` if no `return_value_policy` is specified (see [pybind11 PR #2920](pybind/pybind11#2920)). Therefore this CL is correct. TODO for a separate CL: change the pybind11 code generator to specify `return_value_policy::reference`, to be explicit and leave no room for doubt. PiperOrigin-RevId: 365616794
d521169
to
36eda14
Compare
5613cce
to
efee5df
Compare
2882871
to
fbf35ed
Compare
tests/test_stl.py
Outdated
while True: | ||
v = m.return_vector_bool_raw_ptr() | ||
assert isinstance(v, list) | ||
assert len(v) == 4513 | ||
break # Comment out for manual leak checking (use `top` command). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Kind of odd to have in a test? Maybe
while True: | |
v = m.return_vector_bool_raw_ptr() | |
assert isinstance(v, list) | |
assert len(v) == 4513 | |
break # Comment out for manual leak checking (use `top` command). | |
# Add while True: for manual leak checking | |
v = m.return_vector_bool_raw_ptr() | |
assert isinstance(v, list) | |
assert len(v) == 4513 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done. Thanks Henry!
Side remark & question:
- I have a lot of those on the smart_holder branch, and need to turn them on-off quite a bit when going into the smart_holder code.
- Do you happen to be aware of a pytest feature or plugin that would automate the fool-proof top-like leak check with adding a certain flag?
I've been thinking of this as a potential Google Summer of Code project if it doesn't exist already. Roughly: run decorated test functions in a loop while monitoring the equivalent of top's RES from within the same Python process, use some simple heuristics to decide "this could be a leak" or "no this doesn't look like a leak after running for N seconds".
… to be comprehensive, to not bloat the reference table with too many details.
fbf35ed
to
4ff6527
Compare
I decided to remove the needs changelog label. It's an important detail to have right for someone looking carefully at the docs, but I feel that highlighting this PR in the changelog gives it too much weight (more distracting than helpful). |
I wrote the test under this PR to convince myself that the existing documentation is not actually precise. I think it's nice to keep the test as a reference.