gh-132097: remove unnecessary clinic casts to `PyCFunction` and others by picnixz · Pull Request #131665 · python/cpython
@vstinner This one is purely cosmetic but it affects lots of files. It's about removing redundant casts. I've removed some redundant casts with non-clinic files but this one just removes the casts generated by clinic.
I'm not entirely sure I want to merge this for the following reason:
- let's say clinic incorrectly generates a signature, and the signature then becomes incompatible. With this change, this would affect the PR with a bad clinic signature. However, this means that we need to fix clinic in the meantime.
- Without removing the explicit casts, we can at least make other PRs relying on clinic not affected by subtle UBs that may or may not be impactful.
- For WASM, UBs are strictly checked: "Bad fpcasts are an issue in WebAssembly. WASM's indirect_call has strict function signature checks. Argument count, types, and return type must match." (this is a comment for
_PyCFunction_TrampolineCallinpycore_object.h(which is also duplicated inpycore_emscripten_trampoline.h). - So technically, while it's a UB for all platforms, it's much more annoying on Emscripten. So maybe it's better that UBs are always detected at compile time.
I'm going to first address the fastcall issue before continuing here so take your time. I won't commit if you're not happy with this change or if you prefer that we hold it until we see a real issue.