Skip to content

Fix hash segfault with PyCall 1.97 - #565

Merged
jverzani merged 20 commits into
JuliaPy:masterfrom
jverzani:fix_hash
Oct 26, 2026
Merged

jverzani merged 20 commits into
JuliaPy:masterfrom
jverzani:fix_hash

Conversation

@jverzani

@jverzani jverzani commented Oct 26, 2026 •

Copy link
Copy Markdown
Collaborator

Problem

@syms c() a; Dict(c(0) => a) segfaults, as does hashing any Sym (hash(a), Set, unique).

hash is defined for Sym, but it called PyObject_Hash directly through a raw ccall. PyCall 1.97 releases the GIL between calls and wraps its own C-API calls in @with_GIL. The raw call ran without the GIL and Python crashed in slot_tp_hash.

Fix

  • Defer to PyCall's hash(::PyObject, ::UInt), which acquires the GIL. The old method was a workaround until PyCall shipped a 2-arg hash, and 1.97 has one.
  • Bump PyCall compat to 1.97 (1.96.x only defines the 1-arg hash).
  • Add a regression testset, run before the shared SymPyCore suite.
  • Version 2.3.4. Also ignores JetBrains IDE files.
  • CI: replace deprecated actions/cache@v1 (now hard-failing) in ci-nightly.yml with julia-actions/cache, bump all actions to current majors, and add .github/dependabot.yml for GitHub Actions and Julia deps.

CI note

On Julia 1.13 (the 1 job), two test-legacy.jl tests in SymPyCore fail independently of this PR. They expect 3 ^ [x 1] and 3 ^ [x 1; 1 x] to throw a MethodError. In 1.13, LinearAlgebra's ^(::Number, ::AbstractMatrix) calls exp(A) instead of exp!, so the calls no longer throw. The fix belongs in SymPyCore, and this package's compat will pick up that release. The hash testset runs before the shared suite, so it still reports on 1.13.

🤖 Generated with Claude Code

jverzani and others added 20 commits October 21, 2023 18:52
Co-Authored-By: Claude Opus 5.5 <[email protected]>
PyCall 1.97 releases the GIL between calls, so the raw ccall to
PyObject_Hash crashed on any Sym (e.g. `@syms c() a; Dict(c(0)=>a)`).
Defer to PyCall's hash(::PyObject, ::UInt), which acquires the GIL,
and require PyCall >= 1.97.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Replace deprecated actions/cache@v1 in ci-nightly with julia-actions/cache,
bump all actions to current major versions, and add dependabot to keep
GitHub Actions and Julia deps up to date.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@jverzani
jverzani merged commit 357d0a0 into JuliaPy:master Oct 26, 2026
1 of 6 checks passed
@jverzani
jverzani deleted the fix_hash branch October 26, 2026 16:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant