Title: _ctypes fails to extend the return value per libffi contract · Issue #156933 · python/cpython · GitHub
Open Graph Title: _ctypes fails to extend the return value per libffi contract · Issue #156933 · python/cpython
X Title: _ctypes fails to extend the return value per libffi contract · Issue #156933 · python/cpython
Description: Bug report Bug description: The current implementation is relying on restype->size to write the data into a buffer, however, per libffi contract integral types narrower than the system register size are widened Which is not happening her...
Open Graph Description: Bug report Bug description: The current implementation is relying on restype->size to write the data into a buffer, however, per libffi contract integral types narrower than the system register siz...
X Description: Bug report Bug description: The current implementation is relying on restype->size to write the data into a buffer, however, per libffi contract integral types narrower than the system register ...
Opengraph URL: https://github.com/python/cpython/issues/156933
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"_ctypes fails to extend the return value per libffi contract","articleBody":"# Bug report\n\n### Bug description:\n\nThe [current implementation](https://github.com/python/cpython/blob/59a691361cb7b1d4fde3b92f98a61490381c62c9/Modules/_ctypes/callbacks.c#L242) is relying on `restype->size` to write the data into a buffer, however, per [libffi contract](https://github.com/libffi/libffi/blob/33cfefc7d93deba08084557e05728c721b276ade/doc/libffi.texi#L1041)\n> integral types narrower than the system register size are widened\n\nWhich is not happening here. This has caused a failure on s390x when using libclang. cindex.py calls into libclang through ctypes, which builds the callback closures using libffi. With a c_int return, ctypes writes only the low 32 bits and skips the extension that both the ABI and libffi's closure contract require.\n\nWe have also opened a PR to fix this temporarily under llvm: https://github.com/llvm/llvm-project/pull/221024\n\n### CPython versions tested on:\n\n3.11\n\n### Operating systems tested on:\n\nLinux\n\n\u003c!-- gh-linked-prs -->\n### Linked PRs\n* gh-157045\n* gh-158295\n* gh-158296\n* gh-158297\n\u003c!-- /gh-linked-prs -->\n","author":{"url":"https://github.com/miladfarca","@type":"Person","name":"miladfarca"},"datePublished":"2026-09-04T12:32:40Z","url":"https://github.com/python/cpython/issues/156933"}
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| 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:4a2bebf3-51a0-faa5-6676-879c1ec78c55 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | DF6C:EA09B:36C1FAC:489292A:6B02077B |
| html-safe-nonce | 33e7c2a0667c112e2e0df283fd5515861c131652c97674f8c65ab9f1598473c6 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJERjZDOkVBMDlCOjM2QzFGQUM6NDg5MjkyQTo2QjAyMDc3QiIsInZpc2l0b3JfaWQiOiI4NzMwNzI4ODMxNTUzNTA1MTQ3IiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | d8d5d62be04f7d84b67c08e187a67d3644129c04162c554d95f3c2a7a248ea25 |
| hovercard-subject-tag | issue:5348102705 |
| 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/156933/issue_layout |
| twitter:image | https://opengraph.githubassets.com/996d0ff192cb05118801767ab7483d75f505c8289e472fdef02857d72b37643f/python/cpython/issues/156933 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/996d0ff192cb05118801767ab7483d75f505c8289e472fdef02857d72b37643f/python/cpython/issues/156933 |
| og:image:alt | Bug report Bug description: The current implementation is relying on restype->size to write the data into a buffer, however, per libffi contract integral types narrower than the system register siz... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | miladfarca |
| hostname | github.com |
| expected-hostname | github.com |
| None | 87e774ee7c6b3bee0490394e4d3e57ec9dbc956f74b87ea685dc8996c1676456 |
| 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 | 423dbb54c5e7bfecc838eb387c1435eb3d0e760d |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width