René's URL Explorer Experiment


Title: ctypes: unify the foreign-call path on a single host_env `call()` API by youknowone · Pull Request #8235 · RustPython/RustPython · GitHub

Open Graph Title: ctypes: unify the foreign-call path on a single host_env `call()` API by youknowone · Pull Request #8235 · RustPython/RustPython

X Title: ctypes: unify the foreign-call path on a single host_env `call()` API by youknowone · Pull Request #8235 · RustPython/RustPython

Description: Summary Introduce a single libffi-hiding foreign-call entry point in host_env (ctypes::call) and route the VM _ctypes module through it, replacing the per-call libffi Type/Arg marshalling. On top of that, pass and return Structure/Union by value, and delete the now-unused pre-call scaffolding. Commits host_env: add unified high-level call foreign-call API — a call(addr, &[CallArg], CallRet, CallOptions) -> Result entry point that takes ctypes type codes and recursive CTypeLayouts plus raw buffers instead of libffi Type/Arg. Built on the existing Cif/ffi_* primitives; aggregate returns go through Cif::call_return_into. Adds 16 ABI unit tests over local extern "C" functions. _ctypes: route the VM call path through host_env call() — a behavior-preserving migration of ctypes_callproc and the argument/return marshalling onto call; the errno / last-error swap moves into CallOptions. _ctypes: pass and return structs and unions by value — struct/union arguments lower to CallArg::Aggregate and struct/union returns to CallRet::Aggregate. StgInfo carries per-field CTypeLayouts built incrementally from the base class, so struct inheritance is reflected. Also fixes a latent self-deadlock in the result path (a restype StgInfo read guard was held across result-instance construction, which write-locks the same StgInfo to finalize it — unreachable until a struct was actually returned by value). host_env: remove the pre-call foreign-call scaffolding — delete the old callproc / callproc_simple paths and the libffi-type builders (ffi_type_for_layout, CTypeParamKind, ffi_type_from_tag, …) that no longer have a consumer. Testing python -m test test_ctypes: run=322 skipped=58, unchanged across all four commits. New extra_tests/snippets/stdlib_ctypes_calls.py (libc calls over the live FFI path) and stdlib_ctypes_byvalue.py (div/imaxdiv struct returns, inet_ntoa struct and union arguments); output matches CPython. host_env ABI unit tests, workspace test suite, clippy, and pre-commit all pass. Known limitation carried over from the previous libffi field-type path: _pack_ / _swappedbytes_ layouts stay approximate, since CTypeLayout carries no explicit field offsets. Opening as a draft for early visibility / CI. 🤖 Generated with Claude Code Summary by CodeRabbit New Features ctypes now supports additional native call patterns, including passing and returning structs/unions by value. Improved foreign-call handling for simple scalar, pointer, and array types. Added mechanisms to preserve referenced buffer memory across calls. Bug Fixes Fixed foreign-call result decoding, including aggregate return values. Improved error handling for null function pointers, unsupported/unknown type codes, and short aggregate buffers. Enhanced errno/last-error behavior during calls. Tests Added new ctypes integration and regression coverage for by-value and call/errno scenarios.

Open Graph Description: Summary Introduce a single libffi-hiding foreign-call entry point in host_env (ctypes::call) and route the VM _ctypes module through it, replacing the per-call libffi Type/Arg marshalling. On top o...

X Description: Summary Introduce a single libffi-hiding foreign-call entry point in host_env (ctypes::call) and route the VM _ctypes module through it, replacing the per-call libffi Type/Arg marshalling. On top o...

Opengraph URL: https://github.com/RustPython/RustPython/pull/8235

X: @github

direct link

Domain: github.com

route-pattern/:user_id/:repository/pull/:id/files(.:format)
route-controllerpull_requests
route-actionfiles
fetch-noncev2:08cd4cc3-fb18-9769-2074-a1d7d845ff4e
current-catalog-service-hashae870bc5e265a340912cde392f23dad3671a0a881730ffdadd82f2f57d81641b
request-id93EC:348628:BC89B9:FE568D:6A601BA2
html-safe-nonceff651ddca37baf26274798675e951860c5d0160e3b55fea7b0ff892c82716f99
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI5M0VDOjM0ODYyODpCQzg5Qjk6RkU1NjhEOjZBNjAxQkEyIiwidmlzaXRvcl9pZCI6IjY1OTI3NzkyNTUwMjU3NjkzNzgiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ==
visitor-hmacca6c10ec66a8313f2d04e22bca255b0679303aa0f5e72396f64cb29aa6496d2e
hovercard-subject-tagpull_request:4008300142
github-keyboard-shortcutsrepository,pull-request-list,pull-request-conversation,pull-request-files-changed,copilot
google-site-verificationApib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I
octolytics-urlhttps://collector.github.com/github/collect
analytics-location///pull_requests/show/files
fb:app_id1401488693436528
apple-itunes-appapp-id=1477376905, app-argument=https://github.com/RustPython/RustPython/pull/8235/files
twitter:imagehttps://avatars.githubusercontent.com/u/69878?s=400&v=4
twitter:cardsummary_large_image
og:imagehttps://avatars.githubusercontent.com/u/69878?s=400&v=4
og:image:altSummary Introduce a single libffi-hiding foreign-call entry point in host_env (ctypes::call) and route the VM _ctypes module through it, replacing the per-call libffi Type/Arg marshalling. On top o...
og:site_nameGitHub
og:typeobject
hostnamegithub.com
expected-hostnamegithub.com
None7e86a727ba4abf81d0638c5ead57286c17d3b2706f57813445c4316d8e848673
turbo-cache-controlno-preview
diff-viewunified
go-importgithub.com/RustPython/RustPython git https://github.com/RustPython/RustPython.git
octolytics-dimension-user_id39710557
octolytics-dimension-user_loginRustPython
octolytics-dimension-repository_id135201145
octolytics-dimension-repository_nwoRustPython/RustPython
octolytics-dimension-repository_publictrue
octolytics-dimension-repository_is_forkfalse
octolytics-dimension-repository_network_root_id135201145
octolytics-dimension-repository_network_root_nwoRustPython/RustPython
turbo-body-classeslogged-out env-production page-responsive full-width
disable-turbotrue
browser-stats-urlhttps://api.github.com/_private/browser/stats
browser-errors-urlhttps://api.github.com/_private/browser/errors
releasef13d8ac548fb76838b3d703c7fe2100887547d0e
ui-targetfull
theme-color#1e2327
color-schemelight dark

Links:

Skip to contenthttps://github.com/RustPython/RustPython/pull/8235/files#start-of-content
https://github.com/
Sign in https://github.com/login?return_to=https%3A%2F%2Fgithub.com%2FRustPython%2FRustPython%2Fpull%2F8235%2Ffiles
GitHub CopilotWrite better code with AIhttps://github.com/features/copilot
GitHub Copilot appDirect agents from issue to mergehttps://github.com/features/ai/github-app
MCP RegistryNewIntegrate external toolshttps://github.com/mcp
ActionsAutomate any workflowhttps://github.com/features/actions
CodespacesInstant dev environmentshttps://github.com/features/codespaces
IssuesPlan and track workhttps://github.com/features/issues
Code ReviewManage code changeshttps://github.com/features/code-review
Code QualityEnforce quality at mergehttps://github.com/features/code-quality
GitHub Advanced SecurityFind and fix vulnerabilitieshttps://github.com/security/advanced-security
Code securitySecure your code as you buildhttps://github.com/security/advanced-security/code-security
Secret protectionStop leaks before they starthttps://github.com/security/advanced-security/secret-protection
Why GitHubhttps://github.com/why-github
Documentationhttps://docs.github.com
Bloghttps://github.blog
Changeloghttps://github.blog/changelog
Marketplacehttps://github.com/marketplace
View all featureshttps://github.com/features
Enterpriseshttps://github.com/enterprise
Small and medium teamshttps://github.com/team
Startupshttps://github.com/enterprise/startups
Nonprofitshttps://github.com/solutions/industry/nonprofits
App Modernizationhttps://github.com/solutions/use-case/app-modernization
DevSecOpshttps://github.com/solutions/use-case/devsecops
DevOpshttps://github.com/solutions/use-case/devops
CI/CDhttps://github.com/solutions/use-case/ci-cd
View all use caseshttps://github.com/solutions/use-case
Healthcarehttps://github.com/solutions/industry/healthcare
Financial serviceshttps://github.com/solutions/industry/financial-services
Manufacturinghttps://github.com/solutions/industry/manufacturing
Governmenthttps://github.com/solutions/industry/government
View all industrieshttps://github.com/solutions/industry
View all solutionshttps://github.com/solutions
AIhttps://github.com/resources/articles?topic=ai
Software Developmenthttps://github.com/resources/articles?topic=software-development
DevOpshttps://github.com/resources/articles?topic=devops
Securityhttps://github.com/resources/articles?topic=security
View all topicshttps://github.com/resources/articles
Customer storieshttps://github.com/customer-stories
Events & webinarshttps://github.com/resources/events
Ebooks & reportshttps://github.com/resources/whitepapers
Business insightshttps://github.com/solutions/executive-insights
GitHub Skillshttps://skills.github.com
Documentationhttps://docs.github.com
Customer supporthttps://support.github.com
Community forumhttps://github.com/orgs/community/discussions
Trust centerhttps://github.com/trust-center
Partnershttps://github.com/partners
View all resourceshttps://github.com/resources
GitHub SponsorsFund open source developershttps://github.com/open-source/sponsors
Security Labhttps://securitylab.github.com
Maintainer Communityhttps://maintainers.github.com
Acceleratorhttps://github.com/open-source/accelerator
GitHub Starshttps://stars.github.com
Archive Programhttps://archiveprogram.github.com
Topicshttps://github.com/topics
Trendinghttps://github.com/trending
Collectionshttps://github.com/collections
Enterprise platformAI-powered developer platformhttps://github.com/enterprise
GitHub Advanced SecurityEnterprise-grade security featureshttps://github.com/security/advanced-security
Copilot for BusinessEnterprise-grade AI featureshttps://github.com/features/copilot/copilot-business
Premium SupportEnterprise-grade 24/7 supporthttps://github.com/enterprise/premium-support
Pricinghttps://github.com/pricing
Search syntax tipshttps://docs.github.com/search-github/github-code-search/understanding-github-code-search-syntax
documentationhttps://docs.github.com/search-github/github-code-search/understanding-github-code-search-syntax
Sign in https://github.com/login?return_to=https%3A%2F%2Fgithub.com%2FRustPython%2FRustPython%2Fpull%2F8235%2Ffiles
Sign up https://github.com/signup?ref_cta=Sign+up&ref_loc=header+logged+out&ref_page=%2F%3Cuser-name%3E%2F%3Crepo-name%3E%2Fpull_requests%2Fshow%2Ffiles&source=header-repo&source_repo=RustPython%2FRustPython
Reloadhttps://github.com/RustPython/RustPython/pull/8235/files
Reloadhttps://github.com/RustPython/RustPython/pull/8235/files
Reloadhttps://github.com/RustPython/RustPython/pull/8235/files
Please reload this pagehttps://github.com/RustPython/RustPython/pull/8235/files
RustPython https://github.com/RustPython
RustPythonhttps://github.com/RustPython/RustPython
Notifications https://github.com/login?return_to=%2FRustPython%2FRustPython
Fork 1.5k https://github.com/login?return_to=%2FRustPython%2FRustPython
Star 22.2k https://github.com/login?return_to=%2FRustPython%2FRustPython
Code https://github.com/RustPython/RustPython
Issues 294 https://github.com/RustPython/RustPython/issues
Pull requests 105 https://github.com/RustPython/RustPython/pulls
Discussions https://github.com/RustPython/RustPython/discussions
Actions https://github.com/RustPython/RustPython/actions
Projects https://github.com/RustPython/RustPython/projects
Models https://github.com/RustPython/RustPython/models
Wiki https://github.com/RustPython/RustPython/wiki
Security and quality 0 https://github.com/RustPython/RustPython/security
Insights https://github.com/RustPython/RustPython/pulse
Code https://github.com/RustPython/RustPython
Issues https://github.com/RustPython/RustPython/issues
Pull requests https://github.com/RustPython/RustPython/pulls
Discussions https://github.com/RustPython/RustPython/discussions
Actions https://github.com/RustPython/RustPython/actions
Projects https://github.com/RustPython/RustPython/projects
Models https://github.com/RustPython/RustPython/models
Wiki https://github.com/RustPython/RustPython/wiki
Security and quality https://github.com/RustPython/RustPython/security
Insights https://github.com/RustPython/RustPython/pulse
Sign up for GitHub https://github.com/signup?return_to=%2FRustPython%2FRustPython%2Fissues%2Fnew%2Fchoose
terms of servicehttps://docs.github.com/terms
privacy statementhttps://docs.github.com/privacy
Sign inhttps://github.com/login?return_to=%2FRustPython%2FRustPython%2Fissues%2Fnew%2Fchoose
youknowonehttps://github.com/youknowone
RustPython:mainhttps://github.com/RustPython/RustPython/tree/main
youknowone:hostenv-ctypes-callhttps://github.com/youknowone/RustPython/tree/hostenv-ctypes-call
Conversation 6 https://github.com/RustPython/RustPython/pull/8235
Commits 8 https://github.com/RustPython/RustPython/pull/8235/commits
Checks 25 https://github.com/RustPython/RustPython/pull/8235/checks
Files changed https://github.com/RustPython/RustPython/pull/8235/files
Please reload this pagehttps://github.com/RustPython/RustPython/pull/8235/files
ctypes: unify the foreign-call path on a single host_env call() API https://github.com/RustPython/RustPython/pull/8235/files#top
Show all changes 8 commits https://github.com/RustPython/RustPython/pull/8235/files
1c5b113 host_env: add unified high-level `call` foreign-call API youknowone Jul 7, 2026 https://github.com/RustPython/RustPython/pull/8235/commits/1c5b1135d227e40e475f9395fb67396acc74d572
2802682 _ctypes: route the VM call path through host_env call() youknowone Jul 7, 2026 https://github.com/RustPython/RustPython/pull/8235/commits/28026827be63bb761f910f1a4d154b950d0a8cae
b5c8870 _ctypes: pass and return structs and unions by value youknowone Jul 7, 2026 https://github.com/RustPython/RustPython/pull/8235/commits/b5c88708c37fba8281b1693e673de45b54ea5d06
c49d465 host_env: remove the pre-`call` foreign-call scaffolding youknowone Jul 7, 2026 https://github.com/RustPython/RustPython/pull/8235/commits/c49d4655761aa850c1f26325a17ddbdb7b1c6958
88eb784 host_env: read `call` scalar returns as a full register, use `add_i32` youknowone Jul 7, 2026 https://github.com/RustPython/RustPython/pull/8235/commits/88eb78403e5f50c6e09747615effdbaa33365c7e
9ccb216 _ctypes: skip the by-value snippet on Windows youknowone Jul 7, 2026 https://github.com/RustPython/RustPython/pull/8235/commits/9ccb21693fc6598046b9de043a301d6114982593
40d63d7 _ctypes: keep the converted argument alive for by-value aggregates youknowone Jul 8, 2026 https://github.com/RustPython/RustPython/pull/8235/commits/40d63d765d73a6737943a76f1191a4529f2c4e64
4681347 host_env: avoid indexing an empty by-value aggregate buffer in `call` youknowone Jul 8, 2026 https://github.com/RustPython/RustPython/pull/8235/commits/4681347c9ea29f0f4d35bd8ec0464880d89f5307
Clear filters https://github.com/RustPython/RustPython/pull/8235/files
Please reload this pagehttps://github.com/RustPython/RustPython/pull/8235/files
Please reload this pagehttps://github.com/RustPython/RustPython/pull/8235/files
ctypes.rs https://github.com/RustPython/RustPython/pull/8235/files#diff-0c472fcbece94f09d8398d170b05bde9f0b147557347c454000d0a7252190fc8
_ctypes.rs https://github.com/RustPython/RustPython/pull/8235/files#diff-d2bf8c03d89a90728436dbecb8b7f929c67d08ff5d6e18b2a0fc279e8fe77a8d
base.rs https://github.com/RustPython/RustPython/pull/8235/files#diff-16c64cd355bd8034d61677ad8e407239d548e0e35c48ee05e951e03e93aa1781
function.rs https://github.com/RustPython/RustPython/pull/8235/files#diff-d4cf72f95963a6d3e08f9e7e53594d6b5e2cc7711afbc0b490894d97dc8d8648
simple.rs https://github.com/RustPython/RustPython/pull/8235/files#diff-640c11bed665f401309f30eaa8f59ef7ca4c930c57bc97dbf036e19030e1e64a
structure.rs https://github.com/RustPython/RustPython/pull/8235/files#diff-694b74e6249e2ecc75f0c09aec5f2dcfb83e5d4d33eb5a03fced0fdac480eb50
union.rs https://github.com/RustPython/RustPython/pull/8235/files#diff-b63027fcd8299331dd4f4574367c8d501d9e1dde787275f50bea86875b06dcb0
stdlib_ctypes_byvalue.py https://github.com/RustPython/RustPython/pull/8235/files#diff-ab57a9c8ad3f8d55028bd1d06a678bdb099569c240be244334b5d683623b65e1
stdlib_ctypes_calls.py https://github.com/RustPython/RustPython/pull/8235/files#diff-1d6b5c6958c0456a8f254a2eaa63b6e4e6823753556d961efd848db4d18e0d30
crates/host_env/src/ctypes.rshttps://github.com/RustPython/RustPython/pull/8235/files#diff-0c472fcbece94f09d8398d170b05bde9f0b147557347c454000d0a7252190fc8
View file https://github.com/youknowone/RustPython/blob/4681347c9ea29f0f4d35bd8ec0464880d89f5307/crates/host_env/src/ctypes.rs
Open in desktop https://desktop.github.com
Please reload this pagehttps://github.com/RustPython/RustPython/pull/8235/files
crates/vm/src/stdlib/_ctypes.rshttps://github.com/RustPython/RustPython/pull/8235/files#diff-d2bf8c03d89a90728436dbecb8b7f929c67d08ff5d6e18b2a0fc279e8fe77a8d
View file https://github.com/youknowone/RustPython/blob/4681347c9ea29f0f4d35bd8ec0464880d89f5307/crates/vm/src/stdlib/_ctypes.rs
Open in desktop https://desktop.github.com
https://github.co/hiddenchars
https://github.com/RustPython/RustPython/pull/8235/{{ revealButtonHref }}
https://github.com/RustPython/RustPython/pull/8235/files#diff-d2bf8c03d89a90728436dbecb8b7f929c67d08ff5d6e18b2a0fc279e8fe77a8d
https://github.com/RustPython/RustPython/pull/8235/files#diff-d2bf8c03d89a90728436dbecb8b7f929c67d08ff5d6e18b2a0fc279e8fe77a8d
https://github.com/RustPython/RustPython/pull/8235/files#diff-d2bf8c03d89a90728436dbecb8b7f929c67d08ff5d6e18b2a0fc279e8fe77a8d
https://github.com/RustPython/RustPython/pull/8235/files#diff-d2bf8c03d89a90728436dbecb8b7f929c67d08ff5d6e18b2a0fc279e8fe77a8d
https://github.com/RustPython/RustPython/pull/8235/files#diff-d2bf8c03d89a90728436dbecb8b7f929c67d08ff5d6e18b2a0fc279e8fe77a8d
https://github.com/RustPython/RustPython/pull/8235/files#diff-d2bf8c03d89a90728436dbecb8b7f929c67d08ff5d6e18b2a0fc279e8fe77a8d
https://github.com/RustPython/RustPython/pull/8235/files#diff-d2bf8c03d89a90728436dbecb8b7f929c67d08ff5d6e18b2a0fc279e8fe77a8d
https://github.com/RustPython/RustPython/pull/8235/files#diff-d2bf8c03d89a90728436dbecb8b7f929c67d08ff5d6e18b2a0fc279e8fe77a8d
https://github.com/RustPython/RustPython/pull/8235/files#diff-d2bf8c03d89a90728436dbecb8b7f929c67d08ff5d6e18b2a0fc279e8fe77a8d
https://github.com/RustPython/RustPython/pull/8235/files#diff-d2bf8c03d89a90728436dbecb8b7f929c67d08ff5d6e18b2a0fc279e8fe77a8d
Please reload this pagehttps://github.com/RustPython/RustPython/pull/8235/files
Please reload this pagehttps://github.com/RustPython/RustPython/pull/8235/files
https://github.com
Termshttps://docs.github.com/site-policy/github-terms/github-terms-of-service
Privacyhttps://docs.github.com/site-policy/privacy-policies/github-privacy-statement
Securityhttps://github.com/security
Statushttps://www.githubstatus.com/
Communityhttps://github.community/
Docshttps://docs.github.com/
Contacthttps://support.github.com?tags=dotcom-footer

Viewport: width=device-width


URLs of crawlers that visited me.