Title: enum_next and pairwise_next can result in tuple elements with zero reference count in free-threading build · Issue #121464 · python/cpython · GitHub
Open Graph Title: enum_next and pairwise_next can result in tuple elements with zero reference count in free-threading build · Issue #121464 · python/cpython
X Title: enum_next and pairwise_next can result in tuple elements with zero reference count in free-threading build · Issue #121464 · python/cpython
Description: Bug report Bug description: The enumerate object (and also the itertools.pairwise since #118219) re-uses tuples when possible. It does this by checking the reference count to be 1: // from enum_next in enumobject.c if (Py_REFCNT(result) ...
Open Graph Description: Bug report Bug description: The enumerate object (and also the itertools.pairwise since #118219) re-uses tuples when possible. It does this by checking the reference count to be 1: // from enum_nex...
X Description: Bug report Bug description: The enumerate object (and also the itertools.pairwise since #118219) re-uses tuples when possible. It does this by checking the reference count to be 1: // from enum_nex...
Opengraph URL: https://github.com/python/cpython/issues/121464
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"enum_next and pairwise_next can result in tuple elements with zero reference count in free-threading build","articleBody":"# Bug report\n\n### Bug description:\n\nThe enumerate object (and also the `itertools.pairwise` since https://github.com/python/cpython/pull/118219) re-uses tuples when possible. It does this by checking the reference count to be 1:\n```c\n // from enum_next in enumobject.c\n if (Py_REFCNT(result) == 1) {\n Py_INCREF(result);\n old_index = PyTuple_GET_ITEM(result, 0);\n old_item = PyTuple_GET_ITEM(result, 1);\n PyTuple_SET_ITEM(result, 0, next_index);\n PyTuple_SET_ITEM(result, 1, next_item);\n Py_DECREF(old_index);\n Py_DECREF(old_item);\n ....\n```\nThe refcount check and increment are not atomic, so in the free-threading build multiple threads can end up operating on the `result` object. It is possible that one thread already sets an item in the tuple, and another thread decrefs the item believing it is still an old item.\n\nIn the nogil reference implementation (https://github.com/colesbury/nogil) no changes are made to address this. So maybe the issue cannot occur?\n\nIn https://github.com/python/cpython/pull/120591 this problem is addressed with a lock, which might be too much overhead (see the discussion in https://github.com/python/cpython/issues/120496)\n\n@colesbury @hauntsaninja\n\n### CPython versions tested on:\n\nCPython main branch\n\n### Operating systems tested on:\n\nWindows\n\n\u003c!-- gh-linked-prs --\u003e\n### Linked PRs\n* gh-125734\n\u003c!-- /gh-linked-prs --\u003e\n","author":{"url":"https://github.com/eendebakpt","@type":"Person","name":"eendebakpt"},"datePublished":"2024-07-07T19:59:45.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":4},"url":"https://github.com/121464/cpython/issues/121464"}
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:7fa88d3c-25fb-b6ce-34da-415e1c139595 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | A012:31006B:20C8E61:2B5D8D5:696B0E77 |
| html-safe-nonce | 42daddfe067bdd1fdefb9889eb90fa434944da58dd842fcce847fe6f5e903929 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJBMDEyOjMxMDA2QjoyMEM4RTYxOjJCNUQ4RDU6Njk2QjBFNzciLCJ2aXNpdG9yX2lkIjoiNDUxNTY3OTUyMTAxMTg2MzE1OSIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 37cbe72dd40f4f00da35edbd938759ac27fcf304cf3bd0d121e9802429702eee |
| hovercard-subject-tag | issue:2394195453 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/python/cpython/121464/issue_layout |
| twitter:image | https://opengraph.githubassets.com/d3ad87393b2057eed7749278123aae5a7d886b181e885f35b315756ddee90da9/python/cpython/issues/121464 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/d3ad87393b2057eed7749278123aae5a7d886b181e885f35b315756ddee90da9/python/cpython/issues/121464 |
| og:image:alt | Bug report Bug description: The enumerate object (and also the itertools.pairwise since #118219) re-uses tuples when possible. It does this by checking the reference count to be 1: // from enum_nex... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | eendebakpt |
| hostname | github.com |
| expected-hostname | github.com |
| None | 5f99f7c1d70f01da5b93e5ca90303359738944d8ab470e396496262c66e60b8d |
| turbo-cache-control | no-preview |
| go-import | github.com/python/cpython git https://github.com/python/cpython.git |
| octolytics-dimension-user_id | 1525981 |
| octolytics-dimension-user_login | python |
| octolytics-dimension-repository_id | 81598961 |
| octolytics-dimension-repository_nwo | python/cpython |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 81598961 |
| octolytics-dimension-repository_network_root_nwo | python/cpython |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 82560a55c6b2054555076f46e683151ee28a19bc |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width