Open
Conversation
This is an attempt to fix PyO3#3357. The function is used relatively frequently in tests, so have left it with #[cfg(test)] and pub(crate). This avoids coating the tests with `unsafe`, and something that doesn't indicate intent as well. TODO: [ ] Fix docs that refer to `get_refcnt` as an example - is there another function I can use instead?
LilyFirefly
reviewed
Jun 9, 2024
Contributor
There was a problem hiding this comment.
Looks like a good start to me.
I had a look at the failing tests and found these places we'll need more changes:
- We'll need a different example (maybe
is_truthy?):Lines 855 to 859 in d2dca21
- We'll need a different example in or to mark it as
Lines 1537 to 1558 in d2dca21
compile_failtoo. @davidhewitt do you have a preference here?
Comment on lines
+245
to
+254
| assert_eq!(unsafe { pyo3::ffi::Py_REFCNT(dict_sub.as_ptr()) }, 1); | ||
|
|
||
| let item = &py.eval_bound("object()", None, None).unwrap(); | ||
| assert_eq!(item.get_refcnt(), 1); | ||
| assert_eq!(unsafe { pyo3::ffi::Py_REFCNT(item.as_ptr()) }, 1); | ||
|
|
||
| dict_sub.bind(py).set_item("foo", item).unwrap(); | ||
| assert_eq!(item.get_refcnt(), 2); | ||
| assert_eq!(unsafe { pyo3::ffi::Py_REFCNT(item.as_ptr()) }, 2); | ||
|
|
||
| drop(dict_sub); | ||
| assert_eq!(item.get_refcnt(), 1); | ||
| assert_eq!(unsafe { pyo3::ffi::Py_REFCNT(item.as_ptr()) }, 1); |
Contributor
There was a problem hiding this comment.
What was the reasoning for changing these? If I understand the issue, we want to keep get_refcnt for internal tests like this.
Contributor
There was a problem hiding this comment.
The tests in tests are integration tests, they are compiled as a separate crate, and thus don't have access to private functions internal to the crate.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This is an attempt to fix #3357.
The function is used relatively frequently in tests, so have left it with #[cfg(test)] and pub(crate).
This avoids coating the tests with
unsafe, and something that doesn't indicate intent as well.(As has been done in
test_inheiritance.rs)TODO:
get_refcntas an example - is there another function I can use instead?