Title: Align socket receive and control argument binding by youknowdot · Pull Request #9668 · RustPython/RustPython · GitHub
Open Graph Title: Align socket receive and control argument binding by youknowdot · Pull Request #9668 · RustPython/RustPython
X Title: Align socket receive and control argument binding by youknowdot · Pull Request #9668 · RustPython/RustPython
Description: Summary Share recv_into/recvfrom_into keyword binding through the VM's existing ArgSpec helper, preserving buffer export and numeric conversion order. Return immediately from zero-length recv and recv_into, including on closed sockets, as CPython does. Bind sendto and setsockopt arguments before conversion, retain original arguments through I/O, and acquire sendto's buffer export before converting flags without holding its data lock across callbacks. Only production Rust files change. Existing special no-keyword and sendto overload diagnostics remain. Evidence and validation Checked CPython 3.15 source (Modules/socketmodule.c: sock_recv_guts, sock_recv_into, sock_recvfrom_into, sock_sendto, and sock_setsockopt). Bounded CPython 3.15.0 probes using only an owned socketpair confirmed: Both into-methods accept buffer, nbytes, and flags keywords. Buffer rejection precedes numeric callbacks; valid numeric callbacks precede duplicate/unknown keyword errors. Numeric callbacks can mutate exported buffer contents. Zero-byte recv and recv_into return immediately, including after closing the socket. sendto rejects an invalid buffer before invoking a flags callback. Invalid setsockopt arity does not invoke numeric callbacks. rustfmt and git diff --check passed. Exact-head cached patches for #9638, #9640, and #9642 each apply cleanly over this change. Passed on Linux against main 0b081b0283987c7b2d79327dd481f403d515580b: cargo check -p rustpython-vm -p rustpython-host_env -p rustpython-stdlib --features rustpython-stdlib/threading --locked --offline -j1 cargo clippy -p rustpython-vm -p rustpython-host_env -p rustpython-stdlib --features rustpython-stdlib/threading --locked --offline -j1 -- -D warnings RustPython runtime tests, the full Rust suites, Python suites, and other-platform testing were not run. CPython probes establish reference behavior, not execution of the patched RustPython interpreter. Known limits The receive methods already had a text-signature mismatch with CPython's keyword support. Their representation now becomes generic (*args, **kwargs); this patch does not repair introspection metadata. Writable-buffer error wording remains that of the shared buffer helper rather than claiming exact CPython wording. The zero-byte results above were observed on Linux. On non-poll platforms CPython checks high-descriptor selectability before returning zero, so these observations do not establish blanket cross-platform equivalence. Independent source review passed with no blocker. Integration note #9651 changes ArgSpec::parse_with from Fn to FnMut. This change exposes that existing helper and deliberately does not duplicate #9651's callback change. There is one adjacent-line textual conflict: preserve pub fn parse_with from this change and mut check: impl FnMut from #9651. The receive parser remains compatible with either callback signature. AI assistance The source investigation, patch, reference probes, and this draft were prepared with OpenAI Codex assistance under the maintainer's direction. Human review is requested before merge. Summary by CodeRabbit Bug Fixes Socket receive operations now return immediately with an empty result when given a zero-length buffer. Receive operations validate requested byte counts, including negative and oversized values, with appropriate errors. Socket send methods now enforce their supported argument counts and reject keyword arguments where unsupported.
Open Graph Description: Summary Share recv_into/recvfrom_into keyword binding through the VM's existing ArgSpec helper, preserving buffer export and numeric conversion order. Return immediately from zero-length recv ...
X Description: Summary Share recv_into/recvfrom_into keyword binding through the VM's existing ArgSpec helper, preserving buffer export and numeric conversion order. Return immediately from zero-length r...
Opengraph URL: https://github.com/RustPython/RustPython/pull/9668
X: @github
Domain: github.com
| 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 | /:user_id/:repository/pull/:id/files(.:format) |
| route-controller | pull_requests |
| route-action | files |
| fetch-nonce | v2:1b275e97-f937-8ecd-0054-28092815ffe4 |
| current-catalog-service-hash | ae870bc5e265a340912cde392f23dad3671a0a881730ffdadd82f2f57d81641b |
| request-id | 8724:EA09B:337C58B:4444F3D:6B01F3B1 |
| html-safe-nonce | d97207bcc50f2e3b8784b390e428422ec1ef7294c7a889cebb644bbc2ef5ca7b |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI4NzI0OkVBMDlCOjMzN0M1OEI6NDQ0NEYzRDo2QjAxRjNCMSIsInZpc2l0b3JfaWQiOiIyNzQyMzI1NTEyNDgzNjAzNjkiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 2087a59fed00d2ca101502da9cafdeb32f4ccd2bb7077c168a9fe0829ba60bca |
| hovercard-subject-tag | pull_request:5145830072 |
| github-keyboard-shortcuts | repository,pull-request-list,pull-request-conversation,pull-request-files-changed,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/RustPython/RustPython/pull/9668/files |
| twitter:image | https://avatars.githubusercontent.com/u/336763669?s=400&v=4 |
| twitter:card | summary_large_image |
| og:image | https://avatars.githubusercontent.com/u/336763669?s=400&v=4 |
| og:image:alt | Summary Share recv_into/recvfrom_into keyword binding through the VM's existing ArgSpec helper, preserving buffer export and numeric conversion order. Return immediately from zero-length recv ... |
| og:site_name | GitHub |
| og:type | object |
| hostname | github.com |
| expected-hostname | github.com |
| None | 87e774ee7c6b3bee0490394e4d3e57ec9dbc956f74b87ea685dc8996c1676456 |
| turbo-cache-control | no-preview |
| diff-view | unified |
| go-import | github.com/RustPython/RustPython git https://github.com/RustPython/RustPython.git |
| octolytics-dimension-user_id | 39710557 |
| octolytics-dimension-user_login | RustPython |
| octolytics-dimension-repository_id | 135201145 |
| octolytics-dimension-repository_nwo | RustPython/RustPython |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 135201145 |
| octolytics-dimension-repository_network_root_nwo | RustPython/RustPython |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | true |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 423dbb54c5e7bfecc838eb387c1435eb3d0e760d |
| ui-target | canary-2 |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width