Title: Fix forced arg format in AC-processed modules with custom converters · Issue #94512 · python/cpython · GitHub
Open Graph Title: Fix forced arg format in AC-processed modules with custom converters · Issue #94512 · python/cpython
X Title: Fix forced arg format in AC-processed modules with custom converters · Issue #94512 · python/cpython
Description: There are custom Argument Clinic converters that define format_unit but omit parse_arg. As a result, generation of positional argument parsers is forced to back up from the fastest possible _PyArg_CheckPositional to slower _PyArg_ParseSt...
Open Graph Description: There are custom Argument Clinic converters that define format_unit but omit parse_arg. As a result, generation of positional argument parsers is forced to back up from the fastest possible _PyArg_...
X Description: There are custom Argument Clinic converters that define format_unit but omit parse_arg. As a result, generation of positional argument parsers is forced to back up from the fastest possible _PyArg_...
Opengraph URL: https://github.com/python/cpython/issues/94512
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Fix forced arg format in AC-processed modules with custom converters","articleBody":"There are custom Argument Clinic converters that define `format_unit` but omit `parse_arg`. As a result, generation of positional argument parsers is forced to back up from the fastest possible `_PyArg_CheckPositional` to slower `_PyArg_ParseStack`-based format strings.\r\n\r\nHere is a list of such classes (and fixing PRs except complex cases):\r\n\r\n- [x] Modules\\\\_multiprocessing\\multiprocessing.c (gh-94517)\r\n - HANDLE_converter\r\n\r\n- [ ] Modules\\\\_multiprocessing\\semaphore.c\r\n - SEM_HANDLE_converter\r\n\r\n- [x] Modules\\overlapped.c (gh-94516)\r\n - OVERLAPPED_converter\r\n - HANDLE_converter\r\n - ULONG_PTR_converter\r\n - DWORD_converter\r\n - BOOL_converter\r\n\r\n- [x] Modules\\posixmodule.c (gh-122516)\r\n - pid_t_converter\r\n - idtype_t_converter\r\n - id_t_converter\r\n - intptr_t_converter\r\n - Py_off_t_converter\r\n\r\n- [x] Modules\\resource.c (gh-94515)\r\n - pid_t_converter\r\n\r\n- [x] PC\\msvcrtmodule.c (gh-94514)\r\n - HANDLE_converter\r\n\r\n- [x] PC\\winreg.c (gh-94513)\r\n - REGSAM_converter\r\n - DWORD_converter\r\n - HKEY_converter\r\n\r\nAn example of such a converter:\r\n\r\n```cpp\r\nclass BOOL_converter(CConverter):\r\n type = 'BOOL'\r\n format_unit = 'i'\r\n\r\nclass pid_t_converter(CConverter):\r\n type = 'pid_t'\r\n format_unit = '\" _Py_PARSE_PID \"'\r\n```\r\n\r\nI'm going to teach all of them about low-level generation by replacing manual `format_unit` definitions with:\r\n\r\n- inheritance from a corresponding builtin converter where possible\r\n- and custom `parse_arg`s in other places.\r\n\r\nFor the example it gives:\r\n\r\n```cpp\r\nclass BOOL_converter(int_converter):\r\n type = 'BOOL'\r\n\r\nclass pid_t_converter(CConverter):\r\n type = 'pid_t'\r\n # Left as a backup for potential complex cases\r\n format_unit = '\" _Py_PARSE_PID \"'\r\n\r\n def parse_arg(self, argname, displayname):\r\n return \"\"\"\r\n {paramname} = PyLong_AsPid({argname});\r\n if ({paramname} == -1 \u0026\u0026 PyErr_Occurred()) {{{{\r\n goto exit;\r\n }}}}\r\n \"\"\".format(argname=argname, paramname=self.parser_name)\r\n```\r\n","author":{"url":"https://github.com/arhadthedev","@type":"Person","name":"arhadthedev"},"datePublished":"2022-07-02T19:31:36.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":0},"url":"https://github.com/94512/cpython/issues/94512"}
| 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:2e664a4e-a1cb-0416-10e4-553db61939da |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | BEA2:A981C:D38436:1288B01:696A265F |
| html-safe-nonce | f83801c3fe34b8a89087eefa65f9abef639ebf84e2ee492686f37d0299d21752 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJCRUEyOkE5ODFDOkQzODQzNjoxMjg4QjAxOjY5NkEyNjVGIiwidmlzaXRvcl9pZCI6IjM4NTI3MjA2MDEyNjgxMDI3NTEiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | acd278674896ba37a0f34b08ae8fbfd1d811d78f20f3dc5b44913160e9607648 |
| hovercard-subject-tag | issue:1292126101 |
| 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/94512/issue_layout |
| twitter:image | https://opengraph.githubassets.com/bd19243b8b7141519adab74cb91c40a83dc92142512e7695716e42c046cc4779/python/cpython/issues/94512 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/bd19243b8b7141519adab74cb91c40a83dc92142512e7695716e42c046cc4779/python/cpython/issues/94512 |
| og:image:alt | There are custom Argument Clinic converters that define format_unit but omit parse_arg. As a result, generation of positional argument parsers is forced to back up from the fastest possible _PyArg_... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | arhadthedev |
| hostname | github.com |
| expected-hostname | github.com |
| None | a1022f03e4f0d91ea173e4e5dac892c982e0588c62f1ce56121d755a320a3569 |
| 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 | f472b8e6c7b3fdd5d0354972a3f4c516289bf0be |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width