Title: C API: Add internal C API to build a tuple: _PyTupleBuilder · Issue #107137 · python/cpython · GitHub
Open Graph Title: C API: Add internal C API to build a tuple: _PyTupleBuilder · Issue #107137 · python/cpython
X Title: C API: Add internal C API to build a tuple: _PyTupleBuilder · Issue #107137 · python/cpython
Description: The current Python C API PyTuple_New() to build a tuple has multiple flaws: The Python tuple object is immediately tracked by the GC, whereas its items are initialized to NULL (inconsistent tuple) The PyTuple_SET_ITEM() function must onl...
Open Graph Description: The current Python C API PyTuple_New() to build a tuple has multiple flaws: The Python tuple object is immediately tracked by the GC, whereas its items are initialized to NULL (inconsistent tuple) ...
X Description: The current Python C API PyTuple_New() to build a tuple has multiple flaws: The Python tuple object is immediately tracked by the GC, whereas its items are initialized to NULL (inconsistent tuple) ...
Opengraph URL: https://github.com/python/cpython/issues/107137
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"C API: Add internal C API to build a tuple: _PyTupleBuilder","articleBody":"The current Python C API PyTuple_New() to build a tuple has multiple flaws:\r\n\r\n* The Python tuple object is immediately tracked by the GC, whereas its items are initialized to NULL (inconsistent tuple)\r\n* The PyTuple_SET_ITEM() function must only used on a tuple while is being created\r\n\r\nI propose adding a new internal C API to build a tuple: _PyTupleBuilder.\r\n\r\n* User of the API doesn't access the tuple directly but uses higher API\r\n* Over-allocate the tuple (by 25%) to reduce the number of _PyTuple_Resize() calls\r\n* _PyTupleBuild_Append() grows the tuple if needed\r\n* _PyTupleBuild_AppendUnsafe() is a thin wrapper to PyTuple_SET_ITEM()\r\n* Only track the tuple once its fully initialized: correct size, all items are set\r\n* Less error-prone API\r\n\r\nLater, once we will consider this API stable, we can add it to the public C API and deprecate the old API to create an incomplete tuple:\r\n\r\n* PyTuple_New()\r\n* PyTuple_SetItem()\r\n* PyTuple_SET_ITEM()\r\n* _PyTuple_Resize()\r\n\r\nSee https://github.com/capi-workgroup/problems/issues/56 for details on problems caused by API which let creating incomplete/inconsistent objects.\r\n\r\n\u003c!-- gh-linked-prs --\u003e\r\n### Linked PRs\r\n* gh-107139\r\n* gh-107183\n\u003c!-- /gh-linked-prs --\u003e\r\n","author":{"url":"https://github.com/vstinner","@type":"Person","name":"vstinner"},"datePublished":"2023-07-23T15:37:44.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":10},"url":"https://github.com/107137/cpython/issues/107137"}
| 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:8ded90b4-77f8-66d3-4c20-bca16fcda673 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 9752:1B40D2:BBC1B2:10354FF:6969F206 |
| html-safe-nonce | c3a28922aad5686cef7108f1678184ffc4cded500385120af0f5848bd0378798 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI5NzUyOjFCNDBEMjpCQkMxQjI6MTAzNTRGRjo2OTY5RjIwNiIsInZpc2l0b3JfaWQiOiI0MjcxMTg1MTE4OTU3NzkzNzk4IiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | 82dd7fe745ff98b4fd1f6052f52a955f09eabdeaf4efb8d4de28e460bb63878a |
| hovercard-subject-tag | issue:1817175760 |
| 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/107137/issue_layout |
| twitter:image | https://opengraph.githubassets.com/55787bffcd162ee0efcce9766ad5e3b0a96dff36c16d88194d371c429ffb492f/python/cpython/issues/107137 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/55787bffcd162ee0efcce9766ad5e3b0a96dff36c16d88194d371c429ffb492f/python/cpython/issues/107137 |
| og:image:alt | The current Python C API PyTuple_New() to build a tuple has multiple flaws: The Python tuple object is immediately tracked by the GC, whereas its items are initialized to NULL (inconsistent tuple) ... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | vstinner |
| hostname | github.com |
| expected-hostname | github.com |
| None | 7b32f1c7c4549428ee399213e8345494fc55b5637195d3fc5f493657579235e8 |
| 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 | bdde15ad1b403e23b08bbd89b53fbe6bdf688cad |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width