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

Adding tests to exercise corner cases involving disowning. #2912

Merged
merged 4 commits into from
Mar 22, 2021

Conversation

rwgk
Copy link
Collaborator

@rwgk rwgk commented Mar 21, 2021

The most interesting corner case is in test_class_sh_disowning.py test_mixed. See comments there. A "maybe later" idea:

  • For each overloaded function considered, in the first pass keep track if the call will raise ValueError "disowned" for one or more arguments. If this is true for the winning overload, raise a special exception before actually converting any arguments, to make the behavior predictable/portable (no arguments will be disowned).

This PR also fixing minor namespace naming inconsistencies across test_class_sh_*.cpp files.

@rwgk
Copy link
Collaborator Author

rwgk commented Mar 21, 2021

CI run produces 34 failing, 30 successful, with the failure below (seems to be all of the 34).

Question: Is the order in which arguments are converted from Python to C++ not deterministic (across multiple platforms)?

EDIT a few hours later: The answer is https://en.cppreference.com/w/cpp/language/eval_order — Thanks @wjakob for pointing this out!

    def test_mixed():
        while True:
            obj1a = m.Atype1(90)
            obj2a = m.Atype2(25)
            assert m.mixed(obj1a, obj2a) == (90 * 10 + 1) * 200 + (25 * 10 + 2) * 20
            obj1b = m.Atype1(0)
            with pytest.raises(ValueError):
                m.mixed(obj1b, obj2a)
            with pytest.raises(ValueError):
>               obj1b.get()  # obj1b was disowned even though m.mixed(obj1b, obj2a) failed.
E               Failed: DID NOT RAISE <class 'ValueError'>

@rwgk
Copy link
Collaborator Author

rwgk commented Mar 22, 2021

The CI is green, also with PYBIND11_USE_SMART_HOLDER_AS_DEFAULT (#2879). This PR just affects tests, merging now to stay organized. This change will get reviewed internally. I'll open a new PR if there are requests for changes.

@rwgk rwgk marked this pull request as ready for review March 22, 2021 19:16
@rwgk rwgk merged commit 08339d6 into pybind:smart_holder Mar 22, 2021
@rwgk rwgk deleted the disowning_overloads branch March 22, 2021 19:16
@github-actions github-actions bot added the needs changelog Possibly needs a changelog entry label Mar 22, 2021
@rwgk rwgk removed the needs changelog Possibly needs a changelog entry label Mar 22, 2021
@EricCousineau-TRI EricCousineau-TRI added the smart holder See: https://github.com/pybind/pybind11/blob/smart_holder/README_smart_holder.rst label Apr 26, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
smart holder See: https://github.com/pybind/pybind11/blob/smart_holder/README_smart_holder.rst
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants