gh-127271: Replace use of PyCell_GET/SET#127272
Conversation
These macros are not safe to use in the free-threaded build. Use `PyCell_GetRef()` and `PyCell_SetTakeRef()` instead. Add `PyCell_GET` to the free-threading howto table of APIs that return borrowed refs. Add critical sections to `PyCell_GET` and `PyCell_SET`.
ac281e2 to
10ac6e6
Compare
|
While tinkering with the cellobject code, I found a couple more data races. I've included the fixes for those in this PR. For the reviewer, the reference counting changes to |
Avoid the type error and return results as before.
mpage
left a comment
There was a problem hiding this comment.
I kicked off benchmark runs for this change for both the default and free-threaded builds. I'll post the results here once they're ready, likely tomorrow morning.
|
Performance on the default build looks neutral. |
|
|
I can't reproduce those two failing tests on my Debian dev machine. My guess is the failure is not related to this commit. I'll investigate some more though. |
* Replace uses of `PyCell_GET` and `PyCell_SET`. These macros are not safe to use in the free-threaded build. Use `PyCell_GetRef()` and `PyCell_SetTakeRef()` instead. * Since `PyCell_GetRef()` returns a strong rather than borrowed ref, some code restructuring was required, e.g. `frame_get_var()` returns a strong ref now. * Add critical sections to `PyCell_GET` and `PyCell_SET`. * Move critical_section.h earlier in the Python.h file. * Add `PyCell_GET` to the free-threading howto table of APIs that return borrowed refs. * Add additional unit tests for free-threading.
* Replace uses of `PyCell_GET` and `PyCell_SET`. These macros are not safe to use in the free-threaded build. Use `PyCell_GetRef()` and `PyCell_SetTakeRef()` instead. * Since `PyCell_GetRef()` returns a strong rather than borrowed ref, some code restructuring was required, e.g. `frame_get_var()` returns a strong ref now. * Add critical sections to `PyCell_GET` and `PyCell_SET`. * Move critical_section.h earlier in the Python.h file. * Add `PyCell_GET` to the free-threading howto table of APIs that return borrowed refs. * Add additional unit tests for free-threading.
These macros are not safe to use in the free-threaded build. Use
PyCell_GetRef()andPyCell_SetTakeRef()instead. AddPyCell_GETto the free-threading howto table of APIs that return borrowed refs. Add critical sections toPyCell_GETandPyCell_SET.Fix some thread safety issues with cell objects:
cell_richcompare,cell_repr,cell_set_contentsneeded some work. Add an addtional unit test module that tries to trigger data races for these.