Title: Use a correct and transparent definition of "code unit" in C code · Issue #100222 · python/cpython · GitHub
Open Graph Title: Use a correct and transparent definition of "code unit" in C code · Issue #100222 · python/cpython
X Title: Use a correct and transparent definition of "code unit" in C code · Issue #100222 · python/cpython
Description: We should define _Py_CODEUNIT properly without the need for type punning. Currently _Py_CODEUNIT is define as typedef uint16_t _Py_CODEUNIT; but it really an 8 bit opcode followed a bit operand aligned to 16 bits. Which means we need to ...
Open Graph Description: We should define _Py_CODEUNIT properly without the need for type punning. Currently _Py_CODEUNIT is define as typedef uint16_t _Py_CODEUNIT; but it really an 8 bit opcode followed a bit operand ali...
X Description: We should define _Py_CODEUNIT properly without the need for type punning. Currently _Py_CODEUNIT is define as typedef uint16_t _Py_CODEUNIT; but it really an 8 bit opcode followed a bit operand ali...
Opengraph URL: https://github.com/python/cpython/issues/100222
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Use a correct and transparent definition of \"code unit\" in C code","articleBody":"We should define `_Py_CODEUNIT` properly without the need for type punning.\r\n\r\nCurrently `_Py_CODEUNIT` is define as `typedef uint16_t _Py_CODEUNIT;` but it really an 8 bit opcode followed a bit operand aligned to 16 bits. Which means we need to resort to type punning to access the operand and oparg individually.\r\nE.g. https://github.com/python/cpython/blob/main/Include/cpython/code.h#L32\r\n\r\nPEP 7 states that \"Python 3.11 and newer versions use C11 without optional_features\".\r\nSo let's use a union with anonymous struct to define it properly:\r\n\r\n```C\r\ntypedef union {\r\n int16_t align;\r\n struct {\r\n uint8_t opcode;\r\n uint8_t oparg;\r\n };\r\n} _Py_CODEUNIT;\r\n```\r\n\r\n@iritkatriel thoughts?\r\n\n\n\u003c!-- gh-linked-prs --\u003e\n### Linked PRs\n* gh-100223\n* gh-100259\n\u003c!-- /gh-linked-prs --\u003e\n","author":{"url":"https://github.com/markshannon","@type":"Person","name":"markshannon"},"datePublished":"2022-12-13T14:11:05.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":2},"url":"https://github.com/100222/cpython/issues/100222"}
| 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:6beed74b-ed2e-8b0d-6412-97097d57cdd3 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | DD60:1F4CB1:1759660:1F305C2:6969BE87 |
| html-safe-nonce | 80f64556999bd17b9578b2d2f696f7a08c74950e47946e5b92c46ce8d4583c5e |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJERDYwOjFGNENCMToxNzU5NjYwOjFGMzA1QzI6Njk2OUJFODciLCJ2aXNpdG9yX2lkIjoiMjU2MjI2NzcyNzExNDg5MTU5IiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | ff4f4ba46952ed60ae7188c02328e660071dcf42f92337218272afca6fce7064 |
| hovercard-subject-tag | issue:1494316234 |
| 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/100222/issue_layout |
| twitter:image | https://opengraph.githubassets.com/67db3e156a30bbd2840a3e8dcb3ccb8adba9f2bfa7f98361de1291c3af4984ec/python/cpython/issues/100222 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/67db3e156a30bbd2840a3e8dcb3ccb8adba9f2bfa7f98361de1291c3af4984ec/python/cpython/issues/100222 |
| og:image:alt | We should define _Py_CODEUNIT properly without the need for type punning. Currently _Py_CODEUNIT is define as typedef uint16_t _Py_CODEUNIT; but it really an 8 bit opcode followed a bit operand ali... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | markshannon |
| hostname | github.com |
| expected-hostname | github.com |
| None | acedec8b5f975d9e3d494ddd8f949b0b8a0de59d393901e26f73df9dcba80056 |
| 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 | 83c08c21cdda978090dc44364b71aa5bc6dcea79 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width