Skip to content

Use core::ptr::fn_addr_eq for function pointer comparisons - #8430

Closed
kyokuping wants to merge 1 commit into
RustPython:mainfrom
kyokuping:refactor/use-fn-addr-eq
Closed

Use core::ptr::fn_addr_eq for function pointer comparisons#8430
kyokuping wants to merge 1 commit into
RustPython:mainfrom
kyokuping:refactor/use-fn-addr-eq

Conversation

@kyokuping

@kyokuping kyokuping commented Aug 2, 2026

Copy link
Copy Markdown
Contributor

Assisted-by: Codex-5.6-sol

Summary

  • Replaces raw pointer cast comparisons with core::ptr::fn_addr_eq to preserve pointer provenance.

Summary by CodeRabbit

  • Bug Fixes
    • Improved reliability when comparing hash implementations by using a safer function comparison method.

@coderabbitai

coderabbitai Bot commented Aug 2, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yml

Review profile: CHILL

Plan: Pro Plus

Run ID: 7ff0a862-33a1-49d2-b808-8d2caae16345

📥 Commits

Reviewing files that changed from the base of the PR and between 9d64587 and 9ae32de.

📒 Files selected for processing (1)
  • crates/vm/src/class.rs

📝 Walkthrough

Walkthrough

The __hash__ slot comparison now uses core::ptr::fn_addr_eq instead of integer-cast function pointer addresses. The change also imports HashFunc.

Changes

Hash slot comparison

Layer / File(s) Summary
Hash function pointer check
crates/vm/src/class.rs
The code imports HashFunc and compares hash_not_implemented function pointers with core::ptr::fn_addr_eq.

Estimated code review effort: 1 (Trivial) | ~2 minutes

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely describes the main change to use core::ptr::fn_addr_eq for function pointer comparisons.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches 💡 1
🛠️ Fix failing CI checks 💡
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@kyokuping kyokuping changed the title Use \core::ptr::fn_addr_eq\ for function pointer comparisons Use core::ptr::fn_addr_eq for function pointer comparisons Aug 2, 2026
@github-actions

github-actions Bot commented Aug 2, 2026

Copy link
Copy Markdown
Contributor

📦 Library Dependencies

The following Lib/ modules were modified. Here are their dependencies:

[x] lib: cpython/Lib/ssl.py
[x] test: cpython/Lib/test/test_ssl.py (TODO: 10)

dependencies:

  • ssl

dependent tests: (53 tests)

  • ssl: test_asyncio test_ftplib test_httplib test_httpservers test_imaplib test_logging test_poplib test_ssl test_urllib test_urllib2_localnet test_venv test_xmlrpc
    • asyncio.selector_events: test_asyncio
    • ftplib: test_urllib2
      • urllib.request: test_http_cookiejar test_pathlib test_pydoc test_sax test_site test_urllib2net test_urllibnet
    • http.client: test_docxmlrpc test_hashlib test_ucn test_unicodedata test_wsgiref
      • logging.handlers: test_concurrent_futures test_pkgutil
    • http.server: test_robotparser
      • pydoc: test_enum
    • smtplib: test_smtplib test_smtpnet
    • urllib.request:
      • pathlib: test_ast test_dbm_sqlite3 test_ensurepip test_importlib test_json test_launcher test_pathlib test_peg_generator test_pyrepl test_runpy test_tarfile test_tempfile test_tomllib test_tools test_traceback test_unparse test_winapi test_zipapp test_zipfile test_zoneinfo test_zstd

[x] lib: cpython/Lib/asyncio
[ ] test: cpython/Lib/test/test_asyncio (TODO: 31)

dependencies:

  • asyncio

dependent tests: (7 tests)

  • asyncio: test_asyncio test_external_inspection test_inspect test_logging test_os test_pdb test_unittest

Legend:

  • [+] path exists in CPython
  • [x] up-to-date, [ ] outdated

@kyokuping
kyokuping force-pushed the refactor/use-fn-addr-eq branch from 0bc0e80 to 9d64587 Compare August 2, 2026 06:00
@kyokuping
kyokuping marked this pull request as ready for review August 2, 2026 06:00
@moreal moreal added the z-ca-2026 Tag to track Contribution Academy 2026 label Aug 2, 2026
@kyokuping
kyokuping marked this pull request as draft August 2, 2026 06:07
@kyokuping
kyokuping force-pushed the refactor/use-fn-addr-eq branch from 9d64587 to 690f433 Compare August 2, 2026 06:27
@kyokuping

kyokuping commented Aug 2, 2026

Copy link
Copy Markdown
Contributor Author

While trying #8422, I noticed that this code compares function pointers by casting them to integers, so I tried replacing it with std::ptr::fn_addr_eq.

However, while this avoids the integer cast, the Miri job still reports UB when comparing this function pointer, so it doesn’t actually improve the current situation.

Since this change doesn’t resolve the underlying issue, I’m closing this PR for now. It can be revisited if a Miri-compatible approach is found.

@kyokuping
kyokuping marked this pull request as ready for review August 2, 2026 06:54
@kyokuping kyokuping closed this Aug 2, 2026
@kyokuping
kyokuping deleted the refactor/use-fn-addr-eq branch August 8, 2026 05:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

z-ca-2026 Tag to track Contribution Academy 2026

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants