-
Notifications
You must be signed in to change notification settings - Fork 85
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
Fix ref count error issue #906 #907
Fix ref count error issue #906 #907
Conversation
Codecov Report
@@ Coverage Diff @@
## master #907 +/- ##
==========================================
+ Coverage 72.59% 72.89% +0.29%
==========================================
Files 51 51
Lines 6474 6474
Branches 1302 1302
==========================================
+ Hits 4700 4719 +19
+ Misses 1378 1355 -23
- Partials 396 400 +4
Continue to review full report at Codecov.
|
Changes look good. I'll see if I can put together a regression test (but it might take me a few days to get around to it). |
…nt_callable_allow_none
I merged the branch for #910 (which contains a regression test) into this one. |
Looking at the code, there are some other issues here: for example the |
Have expanded the tests somewhat and streamlined the code a bit to test the quicker cases first. |
@@ -2921,7 +2921,7 @@ trait_new(PyTypeObject *trait_type, PyObject *args, PyObject *kw) | |||
} | |||
|
|||
PyErr_Format( | |||
TraitError, | |||
TraitError, |
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.
Unrelated change: VS Code automatically trims trailing whitespace.
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.
Sneakily approving my own changes
@midhun-pm I've made a bunch of changes on this PR; please could you review the current state after the changes? |
traits/tests/test_callable.py
Outdated
string_value = "some string" | ||
callable_value = my_function | ||
|
||
for _ in range(10): |
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.
Why is it 10 ?
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.
Hmm. No really good reason. Let me take out the loop and see if a single iteration is sufficient to cause the segfault.
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.
So a single iteration is not enough: on my own machine, I need at least 3. I've added a comment about the number of iterations.
My (unverified) conjecture is that what's happening is that on each iteration through the loop, my_function
loses one of its references; when its reference count gets to zero, it gets garbage collected. Everything's fine unless we try to access my_function
after it's been garbage collected. The second iteration is probably reducing the reference count to zero, and causing my_function
to be garbage collected. The third iteration then accesses my_function
and causes the segfault.
These changes look good. It's clean. Thanks! |
PR fixes issue #906