Title: long_subtype_new underallocates for zero · Issue #101037 · python/cpython · GitHub
Open Graph Title: long_subtype_new underallocates for zero · Issue #101037 · python/cpython
X Title: long_subtype_new underallocates for zero · Issue #101037 · python/cpython
Description: When creating int instances, we always allocate space for and initialise at least one digit, since the medium_value function that's used for fast paths assumes the existence of that digit. This change was introduced for Python 3.11 in PR...
Open Graph Description: When creating int instances, we always allocate space for and initialise at least one digit, since the medium_value function that's used for fast paths assumes the existence of that digit. This cha...
X Description: When creating int instances, we always allocate space for and initialise at least one digit, since the medium_value function that's used for fast paths assumes the existence of that digit. This...
Opengraph URL: https://github.com/python/cpython/issues/101037
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"long_subtype_new underallocates for zero","articleBody":"When creating `int` instances, we [always allocate](https://github.com/python/cpython/blob/ef633e5000222a3dba74473c49d6a81fca0a44ec/Objects/longobject.c#L157) space for and initialise at least one digit, since the `medium_value` function that's used for fast paths [assumes the existence](https://github.com/python/cpython/blob/ef633e5000222a3dba74473c49d6a81fca0a44ec/Objects/longobject.c#L33) of that digit. This change was introduced for Python 3.11 in PR #27832.\r\n\r\nHowever, the corresponding change in `long_subtype_new` was missed; this results in us asking for zero digits in the case of creating an instance of a subclass of `int` with value zero - e.g.,\r\n\r\n```python\r\nclass MyInt(int):\r\n pass\r\n\r\nmyint = MyInt() # problem\r\n```\r\n\r\nThat's then a problem if `myint` is used in a context where `medium_value` might be called on it, for example as in `int(myint)`.\r\n\r\nWe've got away with this so far because of a compensating _overallocation_ issue: see #81381; this bug blocked an attempt to address #81381 in #100855. But I believe this should still be fixed.\r\n\r\nI'll make a PR shortly.\r\n\r\n\r\n\u003c!-- gh-linked-prs --\u003e\r\n### Linked PRs\r\n* gh-101038\r\n* gh-101219\n\u003c!-- /gh-linked-prs --\u003e\r\n","author":{"url":"https://github.com/mdickinson","@type":"Person","name":"mdickinson"},"datePublished":"2023-01-14T16:47:42.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":0},"url":"https://github.com/101037/cpython/issues/101037"}
| 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:f7d1eae9-7497-59f0-103a-8d22547af179 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | C9AE:196750:72A04E:9A41DA:6969DC33 |
| html-safe-nonce | b518aa166833348678bf4c0d8c6be17760ce0b7d48e29be1b81ffdd79a273a0f |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJDOUFFOjE5Njc1MDo3MkEwNEU6OUE0MURBOjY5NjlEQzMzIiwidmlzaXRvcl9pZCI6IjU4NzU3OTc5NzQ2MjM4MzcyMzUiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | b18806f9c5fcc0e95c3330074fc3a435756edea0b9837da77add5a3c2c41a613 |
| hovercard-subject-tag | issue:1533356827 |
| 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/101037/issue_layout |
| twitter:image | https://opengraph.githubassets.com/93a554986a34c177ac0d120b2df2326debe83081aa9a8e5a414bb2de71ac39a5/python/cpython/issues/101037 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/93a554986a34c177ac0d120b2df2326debe83081aa9a8e5a414bb2de71ac39a5/python/cpython/issues/101037 |
| og:image:alt | When creating int instances, we always allocate space for and initialise at least one digit, since the medium_value function that's used for fast paths assumes the existence of that digit. This cha... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | mdickinson |
| 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 | canary-1 |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width