Title: Make Argument Clinic aware of possible UBSan failures · Issue #128180 · python/cpython · GitHub
Open Graph Title: Make Argument Clinic aware of possible UBSan failures · Issue #128180 · python/cpython
X Title: Make Argument Clinic aware of possible UBSan failures · Issue #128180 · python/cpython
Description: Feature or enhancement A huge part of the CPython code base uses Argument Clinic for generating methods for classes or standalone functions. Generally, methods are then used as follows: static PyMethodDef foo_methods[] = { _FOOMODULE_FOO...
Open Graph Description: Feature or enhancement A huge part of the CPython code base uses Argument Clinic for generating methods for classes or standalone functions. Generally, methods are then used as follows: static PyMe...
X Description: Feature or enhancement A huge part of the CPython code base uses Argument Clinic for generating methods for classes or standalone functions. Generally, methods are then used as follows: static PyMe...
Opengraph URL: https://github.com/python/cpython/issues/128180
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Make Argument Clinic aware of possible UBSan failures ","articleBody":"# Feature or enhancement\r\n\r\nA huge part of the CPython code base uses Argument Clinic for generating methods for classes or standalone functions. Generally, methods are then used as follows:\r\n\r\n```C\r\nstatic PyMethodDef foo_methods[] = {\r\n _FOOMODULE_FOO_BAR_METHODDEF\r\n {NULL, NULL}\r\n};\r\n```\r\n\r\nwhere each `\u003cMODULE\u003e_\u003cCLASS\u003e_\u003cMETHOD\u003e_METHODDEF` is something like\r\n\r\n```C\r\nPyDoc_STRVAR(_foomodule_Foo_bar__doc__,\r\n\"bar($self, /)\\n\"\r\n\"--\\n\"\r\n\"\\n\");\r\n\r\n#define _FOOMODULE_FOO_BAR_METHODDEF \t\t\\\r\n {\t\t\t\t\t\t\t\t\t\t\\\r\n \"bar\", \t\t\t\t\t\t\t\t\\\r\n (PyCFunction)_foomodule_Foo_bar, \t\\\r\n METH_NOARGS, \t\t\t\t\t\t\\\r\n _foomodule_Foo_bar__doc__ \\\r\n },\r\n```\r\n\r\nWe also have\r\n\r\n```C\r\n// @file Modules/foomodule.c\r\n\r\n/*[clinic input]\r\n_foomodule.Foo.bar\r\n\r\n[clinic start generated code]*/\r\n\r\nstatic PyObject *\r\n_foomodule_Foo_bar_impl(FooObject *self)\r\n/*[clinic end generated code: output=... input=...]*/\r\n{\r\n\tPy_RETURN_NONE;\r\n}\r\n\r\n// @file Modules/clinic/foomodule.c.h\r\n\r\nstatic PyObject *\r\n_foomodule_Foo_bar_impl(FooObject *self);\r\n\r\nstatic PyObject *\r\n_foomodule_Foo_bar(FooObject *self, PyObject *Py_UNUSED(ignored))\r\n{\r\n return _foomodule_Foo_bar_impl(self);\r\n}\r\n```\r\n\r\nNow, in order to fix #111178, we generally convert non-AC clinic methods by changing `FooObject *` to `PyObject *` and doing a pointer cast in the function body. See #111178 for a wider discussion. The issue is that we cannot easily do the same for AC-generated code since the prototype is part of the auto-generated block.\r\n\r\nWe can do it if we specify `self: self(type=\"PyObject *\")` instead of not specifying `self` in the AC input, but this is an overkill. Instead, AC should always generate two functions: an implementation function which takes a typed object (i.e., FooObject) and a public dispatcher which takes a PyObject *self and possibly unused arguments. Stated otherwise:\r\n\r\n```diff\r\nstatic PyObject *\r\n-_foomodule_Foo_bar(FooObject *self, PyObject *Py_UNUSED(ignored))\r\n+_foomodule_Foo_bar(PyObject *self, PyObject *Py_UNUSED(ignored))\r\n{\r\n- return _foomodule_Foo_bar_impl(self);\r\n+ return _foomodule_Foo_bar_impl((FooObject *)self);\r\n}\r\n```\r\n\r\nI decided to open a separate issue to track this change orthogonally to the UBSan failures fixes that can be achieved without any AC changes. I hope that this will not deterioriate the performances of CPython too much.\r\n\r\n---\r\n\r\nNote: this does not only affect methods as above; this affects any *method* that is casted to `PyCFunction` or anything else with incompatible function pointer signatures.","author":{"url":"https://github.com/picnixz","@type":"Person","name":"picnixz"},"datePublished":"2024-12-22T15:02:59.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":4},"url":"https://github.com/128180/cpython/issues/128180"}
| 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:f4ac495d-15e4-e5b8-1c31-80b2e83a6a8b |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 843A:CE9E9:E616D0:140E605:696A2679 |
| html-safe-nonce | 319d0d26e1182c060261c74bdddfdc8c3bceff478e208d5775ed1b0e939157a9 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI4NDNBOkNFOUU5OkU2MTZEMDoxNDBFNjA1OjY5NkEyNjc5IiwidmlzaXRvcl9pZCI6IjcyMDM0ODc4NTMxOTMwNzgzOTMiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 0cd7d0b4ab3e9b3567dc4cfc46b8e1c749732a976ac26c4ff4d88ffb538d07c2 |
| hovercard-subject-tag | issue:2754699799 |
| 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/128180/issue_layout |
| twitter:image | https://opengraph.githubassets.com/15791fae02ed2ace72fae7e53bca5d3fbf4843d68f6200fc3c48ba165e8f11d3/python/cpython/issues/128180 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/15791fae02ed2ace72fae7e53bca5d3fbf4843d68f6200fc3c48ba165e8f11d3/python/cpython/issues/128180 |
| og:image:alt | Feature or enhancement A huge part of the CPython code base uses Argument Clinic for generating methods for classes or standalone functions. Generally, methods are then used as follows: static PyMe... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | picnixz |
| 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