Repository navigation
[Python] Add regression test for the exit-time crash of issue #23728 #23849
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,81 @@ | ||
| import os | ||
| import subprocess | ||
| import sys | ||
| import tempfile | ||
| import textwrap | ||
| import unittest | ||
|
|
||
|
|
||
| class Regression23728(unittest.TestCase): | ||
| """ | ||
| Deleting an object of a class without compiled dictionary during | ||
| TROOT::EndOfProcessCleanups() must not crash, even if the interpreter | ||
| already JIT-compiled a destructor earlier in the process. The cache of | ||
| compiled destructors used to be a function-local static, destroyed before | ||
| the end-of-process cleanup ran because its first use came after ROOT | ||
| registered its atexit handlers. | ||
|
|
||
| See https://github.com/root-project/root/issues/23728 | ||
| """ | ||
|
|
||
| def test_exit_cleanup_after_interpreted_destructor(self): | ||
| import ROOT | ||
|
|
||
| with tempfile.TemporaryDirectory() as tmpdir: | ||
| fname = os.path.join(tmpdir, "vv.root") | ||
|
|
||
| # vector<vector<int>> has no compiled dictionary, so its destructor | ||
| # has to be JIT-compiled when the branch object is deleted. | ||
| with ROOT.TFile(fname, "RECREATE") as f: | ||
| t = ROOT.TTree("t", "t") | ||
| v = ROOT.std.vector[ROOT.std.vector[int]]() | ||
| t.Branch("vv", v) | ||
| v.push_back(ROOT.std.vector[int]([1, 2])) | ||
| t.Fill() | ||
| f.Write() | ||
|
|
||
| script = textwrap.dedent( | ||
| f""" | ||
| import ROOT | ||
|
|
||
| f = ROOT.TFile({fname!r}) | ||
| # Let TROOT::EndOfProcessCleanups() delete the file, and with it | ||
| # the tree and its branch object, from the C atexit handler. | ||
| ROOT.SetOwnership(f, False) | ||
| t = f.Get("t") | ||
| t.GetEntry(0) | ||
|
|
||
| # That only happens if the file is registered with gROOT and owns | ||
| # the tree. Check it, so that the test fails loudly instead of | ||
| # silently losing its purpose if these defaults change. | ||
| if not ROOT.gROOT.GetListOfFiles().FindObject(f): | ||
| raise RuntimeError("the file is not in gROOT->GetListOfFiles()") | ||
| if t.GetDirectory() != f: | ||
| raise RuntimeError("the tree is not owned by the file") | ||
|
|
||
| # Make the interpreter JIT-compile a destructor before exit. | ||
| ROOT.std.vector[ROOT.TNamed]() | ||
|
|
||
| print("end of script") | ||
| """ | ||
| ) | ||
|
|
||
| # Poison freed memory, so that a use of destroyed objects (like the | ||
| # dead destructor cache of the issue) crashes deterministically, | ||
| # whatever the heap layout and the interpreter internals. | ||
| env = dict(os.environ, MALLOC_PERTURB_="85") | ||
|
|
||
| res = subprocess.run( | ||
| [sys.executable, "-c", script], | ||
| stdout=subprocess.PIPE, | ||
| stderr=subprocess.STDOUT, | ||
| text=True, | ||
| env=env, | ||
| ) | ||
|
|
||
| self.assertEqual(res.returncode, 0, msg=res.stdout) | ||
| self.assertIn("end of script", res.stdout) | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| unittest.main() | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.