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

More precise return_value_policy::automatic documentation. #2920

Merged
merged 5 commits into from
Jul 12, 2021

Conversation

rwgk
Copy link
Collaborator

@rwgk rwgk commented Mar 26, 2021

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.

@rwgk rwgk force-pushed the test_return_vector_bool_raw_ptr branch from 9f439ac to d521169 Compare March 27, 2021 13:56
rwgk pushed a commit to google/clif that referenced this pull request Mar 29, 2021
…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
@rwgk rwgk force-pushed the test_return_vector_bool_raw_ptr branch from d521169 to 36eda14 Compare April 2, 2021 19:04
@rwgk rwgk added this to the v2.7 milestone Jul 3, 2021
@rwgk rwgk force-pushed the test_return_vector_bool_raw_ptr branch from 5613cce to efee5df Compare July 3, 2021 18:08
@rwgk rwgk force-pushed the test_return_vector_bool_raw_ptr branch from 2882871 to fbf35ed Compare July 12, 2021 21:39
@rwgk rwgk changed the title Adding test_return_vector_bool_raw_ptr to test_stl.py. More precise return_value_policy::automatic documentation. Jul 12, 2021
@rwgk rwgk marked this pull request as ready for review July 12, 2021 21:47
Comment on lines 289 to 293
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).
Copy link
Collaborator

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

Suggested change
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

Copy link
Collaborator Author

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".

@rwgk rwgk force-pushed the test_return_vector_bool_raw_ptr branch from fbf35ed to 4ff6527 Compare July 12, 2021 22:27
@rwgk rwgk merged commit 7509064 into pybind:master Jul 12, 2021
@rwgk rwgk deleted the test_return_vector_bool_raw_ptr branch July 12, 2021 23:56
@github-actions github-actions bot added the needs changelog Possibly needs a changelog entry label Jul 12, 2021
@rwgk rwgk removed the needs changelog Possibly needs a changelog entry label Jul 12, 2021
@rwgk
Copy link
Collaborator Author

rwgk commented Jul 12, 2021

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).

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.

2 participants