-
-
Notifications
You must be signed in to change notification settings - Fork 2k
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: Ensure type object of inputs for cached any-value conversion functions are kept alive #19866
Conversation
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #19866 +/- ##
==========================================
- Coverage 79.44% 79.43% -0.01%
==========================================
Files 1550 1551 +1
Lines 215192 215243 +51
Branches 2447 2452 +5
==========================================
+ Hits 170952 170977 +25
- Misses 43683 43708 +25
- Partials 557 558 +1 ☔ View full report in Codecov by Sentry. 🚨 Try these New Features:
|
63754e3
to
0235eac
Compare
|
||
Python::with_gil(|py| { | ||
let conversion_function = get_conversion_function(ob, py, allow_object)?; |
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.
Fix a regression from ebd5302#diff-778ed52e7b4a402304a62e51974c92208369baf61c50ad78eca715b7f6f18d89R478-R485 that caused us to always call get_conversion_function
regardless of whether it existed in the cache.
#[derive(Debug, Clone)] | ||
pub struct TypeObjectKey { | ||
#[allow(unused)] | ||
type_object: Arc<Py<PyType>>, |
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.
Could we use PyObject
here? I believe we don't need the extra Arc alloc that way.
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.
Yes indeed - I was able to remove the Arc
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.
Nice one. Probably was an interesting debug. ;)
Fixes a non-deterministic bug in AnyValue conversion from Python, where the incorrect object conversion function would be used when constructing from a Python object. This occurs when there are multiple dynamically created classes being used.
We have a cache
static LUT
forget_conversion_function
keyed by theusize
pointer address of the Python type class. This didn't account for dynamically constructed type objects that may be freed during execution. If a different type object gets allocated to the same location as a previously freed type object, we would incorrectly use the conversion_function meant for the previous type object.Traceback
This is a traceback that I believe to be caused by the bug: