Skip to content

[v640][Python] Fix crash unpickling a ROOT object without importing cppyy - #22975

Merged
guitargeek merged 1 commit into
root-project:v6-40-00-patchesfrom
guitargeek:bp_1
Jul 31, 2026
Merged

guitargeek merged 1 commit into
root-project:v6-40-00-patchesfrom
guitargeek:bp_1

Conversation

@guitargeek

Copy link
Copy Markdown
Contributor

Unpickling a ROOT object resolves its reduce callable
`ROOT.libROOTPythonizations._CPPInstance__expand__`, which only imports
the ROOT pythonizations extension and not the cppyy backend. It then
enters CPyCppyy through the public API (Instance_FromVoidPtr) to rebuild
the object.

In that state, `CPyCppyy::Initialize()` only imported the cppyy module
in the branch taken when Python was not yet initialized. When Python is
already running (the normal unpickling case), that branch is skipped and
`Initialize()` returned success without ever importing cppyy, leaving
gThisModule null. `CreateScopeProxy()` then dereferenced it as a fake
scope and crashed with a segmentation violation.

Ensure the cppyy extension module is imported whenever `gThisModule` is
still null, so the public API is usable regardless of how CPyCppyy was
entered.

Add a regression test that pickles a ROOT object and reads it back in a
fresh interpreter where cppyy has not been imported yet.

🤖 Done with the help of AI.

(cherry picked from commit f2e0f52)
@guitargeek guitargeek self-assigned this Jul 31, 2026
@guitargeek
guitargeek merged commit 442e832 into root-project:v6-40-00-patches Jul 31, 2026
33 of 34 checks passed
@guitargeek
guitargeek deleted the bp_1 branch July 31, 2026 14:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant