forked from root-project/root
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[PyROOT] Retain C++ ownership for TF2, TF3
Fixes root-project#16942
- Loading branch information
1 parent
d738be2
commit e013235
Showing
4 changed files
with
65 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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
25 changes: 25 additions & 0 deletions
25
bindings/pyroot/pythonizations/python/ROOT/_pythonization/_tf2.py
This file contains 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,25 @@ | ||
# Author: Vincenzo Eduardo Padulano CERN 11/2024 | ||
|
||
################################################################################ | ||
# Copyright (C) 1995-2024, Rene Brun and Fons Rademakers. # | ||
# All rights reserved. # | ||
# # | ||
# For the licensing terms see $ROOTSYS/LICENSE. # | ||
# For the list of contributors see $ROOTSYS/README/CREDITS. # | ||
################################################################################ | ||
from . import pythonization | ||
|
||
def _TF2_constructor(self, *args, **kwargs): | ||
""" | ||
Forward the arguments to the C++ constructor and retain ownership. This | ||
helps avoiding double deletes due to ROOT automatic memory management. | ||
""" | ||
self._cpp_constructor(*args, **kwargs) | ||
import ROOT | ||
ROOT.SetOwnership(self, False) | ||
|
||
|
||
@pythonization("TF2") | ||
def pythonize_tf1(klass): | ||
klass._cpp_constructor = klass.__init__ | ||
klass.__init__ = _TF2_constructor |
25 changes: 25 additions & 0 deletions
25
bindings/pyroot/pythonizations/python/ROOT/_pythonization/_tf3.py
This file contains 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,25 @@ | ||
# Author: Vincenzo Eduardo Padulano CERN 11/2024 | ||
|
||
################################################################################ | ||
# Copyright (C) 1995-2024, Rene Brun and Fons Rademakers. # | ||
# All rights reserved. # | ||
# # | ||
# For the licensing terms see $ROOTSYS/LICENSE. # | ||
# For the list of contributors see $ROOTSYS/README/CREDITS. # | ||
################################################################################ | ||
from . import pythonization | ||
|
||
def _TF3_constructor(self, *args, **kwargs): | ||
""" | ||
Forward the arguments to the C++ constructor and retain ownership. This | ||
helps avoiding double deletes due to ROOT automatic memory management. | ||
""" | ||
self._cpp_constructor(*args, **kwargs) | ||
import ROOT | ||
ROOT.SetOwnership(self, False) | ||
|
||
|
||
@pythonization("TF3") | ||
def pythonize_tf1(klass): | ||
klass._cpp_constructor = klass.__init__ | ||
klass.__init__ = _TF3_constructor |
This file contains 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