Title: Define `_Py_TYPEOF` on MSVC and other compilers supporting `__typeof__` · Issue #121647 · python/cpython · GitHub
Open Graph Title: Define `_Py_TYPEOF` on MSVC and other compilers supporting `__typeof__` · Issue #121647 · python/cpython
X Title: Define `_Py_TYPEOF` on MSVC and other compilers supporting `__typeof__` · Issue #121647 · python/cpython
Description: Feature or enhancement Proposal: Recently, MSVC implemented __typeof__, which currently is defined as _Py_TYPEOF only on GCC and Clang. cpython/Include/pyport.h Lines 553 to 560 in 65feded // _Py_TYPEOF(expr) gets the type of an expressi...
Open Graph Description: Feature or enhancement Proposal: Recently, MSVC implemented __typeof__, which currently is defined as _Py_TYPEOF only on GCC and Clang. cpython/Include/pyport.h Lines 553 to 560 in 65feded // _Py_T...
X Description: Feature or enhancement Proposal: Recently, MSVC implemented __typeof__, which currently is defined as _Py_TYPEOF only on GCC and Clang. cpython/Include/pyport.h Lines 553 to 560 in 65feded // _Py_T...
Opengraph URL: https://github.com/python/cpython/issues/121647
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Define `_Py_TYPEOF` on MSVC and other compilers supporting `__typeof__`","articleBody":"# Feature or enhancement\r\n\r\n### Proposal:\r\n\r\nRecently, MSVC [implemented `__typeof__`](https://learn.microsoft.com/en-us/cpp/c-language/typeof-c), which currently is defined as `_Py_TYPEOF` only on GCC and Clang.\r\nhttps://github.com/python/cpython/blob/65fededf9cc1780d5edbef8a6e0a7cf9bc15aea6/Include/pyport.h#L553-L560\r\n\r\nThe only users of `_Py_TYPEOF` are macros [`Py_CLEAR()`](https://github.com/python/cpython/blob/65fededf9cc1780d5edbef8a6e0a7cf9bc15aea6/Include/refcount.h#L422), [`Py_SETREF()` and `Py_XSETREF()`](https://github.com/python/cpython/blob/65fededf9cc1780d5edbef8a6e0a7cf9bc15aea6/Include/cpython/object.h#L326-L365).\r\nIf `_Py_TYPEOF` is not defined, these macros fall back to slightly uglier implementations with `memcpy` calls.\r\nhttps://github.com/python/cpython/blob/65fededf9cc1780d5edbef8a6e0a7cf9bc15aea6/Include/refcount.h#L421-L442\r\n\r\nThe proposal is to define `_Py_TYPEOF` on:\r\n - latest MSVC versions that support [`__typeof__`](https://learn.microsoft.com/en-us/cpp/c-language/typeof-c)\r\n - arbitrary compilers that support `__typeof__`\r\n - arbitrary compilers that support C23 `typeof` or C++11 `decltype`\r\n\r\nBy defining `_Py_TYPEOF`, uses of `Py_CLEAR()`, `Py_SETREF()` and `Py_XSETREF()` are switched to the `_Py_TYPEOF` implementation; on these compilers, the benefits would be:\r\n - Less [worrying about miscompilation and machine code quality](https://github.com/python/cpython/issues/98724#issuecomment-1342256667).\r\n - Fewer surprises with hidden `memcpy` as seen in \r\n - - #100121 \r\n - - #121617\r\n - Reduced variance between optimization settings thanks to more straightforward implementation.\r\n\r\nAdditionally, this removes a differing detail between MSVC and GCC/Clang builds, which should be generally desirable.\r\n\r\n### Has this already been discussed elsewhere?\r\n\r\nNo response given\r\n\r\n### Links to previous discussion of this feature:\r\n\r\n- #98724\n\n\u003c!-- gh-linked-prs --\u003e\n### Linked PRs\n* gh-121648\n\u003c!-- /gh-linked-prs --\u003e\n","author":{"url":"https://github.com/fuhsnn","@type":"Person","name":"fuhsnn"},"datePublished":"2024-07-12T13:16:44.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":1},"url":"https://github.com/121647/cpython/issues/121647"}
| 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:237b08d3-9039-e7d5-7d52-369802fc928a |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | E99E:6F7C:541B0A:6ED0A8:696B4325 |
| html-safe-nonce | 51b6178972e8343329c8eb6e3bf0fb2527ff2dcfcbe6ff0e226ee3a3936962c1 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJFOTlFOjZGN0M6NTQxQjBBOjZFRDBBODo2OTZCNDMyNSIsInZpc2l0b3JfaWQiOiI4ODQzNzU2ODE4NjgwOTg4NDUzIiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | c68f0e45699c100c507b5edf15702370909936160a8c75e59bc81afb6836a651 |
| hovercard-subject-tag | issue:2405590250 |
| 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/121647/issue_layout |
| twitter:image | https://opengraph.githubassets.com/2fc5f1a6b331cc8f37d200e8cf425dfda6208ceba1032b3a344ad66c91d0130e/python/cpython/issues/121647 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/2fc5f1a6b331cc8f37d200e8cf425dfda6208ceba1032b3a344ad66c91d0130e/python/cpython/issues/121647 |
| og:image:alt | Feature or enhancement Proposal: Recently, MSVC implemented __typeof__, which currently is defined as _Py_TYPEOF only on GCC and Clang. cpython/Include/pyport.h Lines 553 to 560 in 65feded // _Py_T... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | fuhsnn |
| 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