ROOT
Version master
v6.34
v6.32
v6.30
v6.28
v6.26
v6.24
v6.22
v6.20
v6.18
v6.16
v6.14
v6.12
v6.10
v6.08
v6.06
Reference Guide
▼
ROOT
ROOT Reference Documentation
Tutorials
►
Functional Parts
►
Namespaces
►
All Classes
▼
Files
▼
File List
▼
bindings
▼
pyroot
▼
cppyy
►
cppyy
►
cppyy-backend
▼
CPyCppyy
►
include
▼
src
►
API.cxx
CallContext.cxx
►
CallContext.h
►
Converters.cxx
►
Converters.h
CPPClassMethod.cxx
►
CPPClassMethod.h
CPPConstructor.cxx
►
CPPConstructor.h
►
CPPDataMember.cxx
►
CPPDataMember.h
►
CPPEnum.cxx
►
CPPEnum.h
►
CPPExcInstance.cxx
►
CPPExcInstance.h
CPPFunction.cxx
►
CPPFunction.h
►
CPPGetSetItem.cxx
►
CPPGetSetItem.h
►
CPPInstance.cxx
►
CPPInstance.h
►
CPPMethod.cxx
►
CPPMethod.h
CPPOperator.cxx
►
CPPOperator.h
►
CPPOverload.cxx
►
CPPOverload.h
►
CPPScope.cxx
►
CPPScope.h
►
Cppyy.h
►
CPyCppyy.h
►
CPyCppyyModule.cxx
►
CustomPyTypes.cxx
►
CustomPyTypes.h
►
DeclareConverters.h
►
DeclareExecutors.h
►
Dimensions.h
►
Dispatcher.cxx
►
Dispatcher.h
►
DispatchPtr.cxx
►
Executors.cxx
►
Executors.h
►
LowLevelViews.cxx
►
LowLevelViews.h
►
MemoryRegulator.cxx
►
MemoryRegulator.h
►
ProxyWrappers.cxx
►
ProxyWrappers.h
►
PyCallable.h
►
PyException.cxx
PyObjectDir27.inc
►
PyResult.cxx
►
PyStrings.cxx
►
PyStrings.h
►
Pythonize.cxx
►
Pythonize.h
►
SignalTryCatch.h
►
TemplateProxy.cxx
►
TemplateProxy.h
►
TPyArg.cxx
TPyClassGenerator.cxx
TPyClassGenerator.h
►
TupleOfInstances.cxx
►
TupleOfInstances.h
►
TypeManip.cxx
►
TypeManip.h
►
Utility.cxx
►
Utility.h
►
pythonizations
►
r
►
tpython
►
core
►
documentation
►
geom
►
graf2d
►
graf3d
►
gui
►
hist
►
io
►
main
►
master
►
math
►
montecarlo
►
net
►
proof
►
roofit
►
sql
►
tmva
►
tree
►
tutorials
►
File Members
Release Notes
•
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Properties
Friends
Macros
Modules
Pages
Loading...
Searching...
No Matches
DispatchPtr.cxx
Go to the documentation of this file.
1
// Bindings
2
#include "
CPyCppyy.h
"
3
#define CPYCPPYY_INTERNAL 1
4
#include "
CPyCppyy/DispatchPtr.h
"
5
#undef CPYCPPYY_INTERNAL
6
#include "
CPPInstance.h
"
7
#include "
CPPScope.h
"
8
9
10
//-----------------------------------------------------------------------------
11
PyObject
*
CPyCppyy::DispatchPtr::Get
(
bool
borrowed
)
const
12
{
13
if
(
fPyHardRef
) {
14
if
(!
borrowed
)
Py_INCREF
(
fPyHardRef
);
15
return
fPyHardRef
;
16
}
17
if
(
fPyWeakRef
) {
18
PyObject
*
disp
=
CPyCppyy_GetWeakRef
(
fPyWeakRef
);
19
if
(
disp
) {
// dispatcher object disappeared?
20
if
(
borrowed
)
Py_DECREF
(
disp
);
21
return
disp
;
22
}
23
}
24
return
nullptr
;
25
}
26
27
//-----------------------------------------------------------------------------
28
CPyCppyy::DispatchPtr::DispatchPtr
(
PyObject
*
pyobj
,
bool
strong
) : fPyHardRef(nullptr)
29
{
30
if
(
strong
) {
31
Py_INCREF
(
pyobj
);
32
fPyHardRef
=
pyobj
;
33
fPyWeakRef
=
nullptr
;
34
}
else
{
35
fPyHardRef
=
nullptr
;
36
fPyWeakRef
=
PyWeakref_NewRef
(
pyobj
,
nullptr
);
37
}
38
((
CPPInstance
*)
pyobj
)->SetDispatchPtr(
this
);
39
}
40
41
//-----------------------------------------------------------------------------
42
CPyCppyy::DispatchPtr::DispatchPtr
(
const
DispatchPtr
&
other
,
void
*
cppinst
) : fPyWeakRef(nullptr)
43
{
44
PyObject
*
pyobj
=
other
.Get(
false
/* not borrowed */
);
45
fPyHardRef
=
pyobj
? (
PyObject
*)((
CPPInstance
*)
pyobj
)->Copy(
cppinst
) :
nullptr
;
46
if
(
fPyHardRef
) ((
CPPInstance
*)
fPyHardRef
)->SetDispatchPtr(
this
);
47
Py_XDECREF
(
pyobj
);
48
}
49
50
//-----------------------------------------------------------------------------
51
CPyCppyy::DispatchPtr::~DispatchPtr
() {
52
// if we're holding a hard reference, or holding weak reference while being part
53
// of a dispatcher intermediate, then this delete is from the C++ side, and Python
54
// is "notified" by nulling out the reference and an exception will be raised on
55
// continued access
56
if
(fPyWeakRef) {
57
PyObject
*
pyobj
=
CPyCppyy_GetWeakRef
(fPyWeakRef);
58
if
(
pyobj
&& ((
CPPScope
*)
Py_TYPE
(
pyobj
))->
fFlags
&
CPPScope::kIsPython
)
59
((
CPPInstance
*)
pyobj
)->GetObjectRaw() =
nullptr
;
60
Py_XDECREF
(
pyobj
);
61
Py_DECREF
(fPyWeakRef);
62
}
else
if
(fPyHardRef) {
63
((
CPPInstance
*)fPyHardRef)->GetObjectRaw() =
nullptr
;
64
Py_DECREF
(fPyHardRef);
65
}
66
}
67
68
//-----------------------------------------------------------------------------
69
CPyCppyy::DispatchPtr
&
CPyCppyy::DispatchPtr::assign
(
const
DispatchPtr
&
other
,
void
*
cppinst
)
70
{
71
if
(
this
!= &
other
) {
72
Py_XDECREF
(fPyWeakRef); fPyWeakRef =
nullptr
;
73
Py_XDECREF
(fPyHardRef);
74
PyObject
*
pyobj
=
other
.Get(
false
/* not borrowed */
);
75
fPyHardRef =
pyobj
? (
PyObject
*)((
CPPInstance
*)
pyobj
)->Copy(
cppinst
) :
nullptr
;
76
if
(fPyHardRef) ((
CPPInstance
*)fPyHardRef)->SetDispatchPtr(
this
);
77
Py_XDECREF
(
pyobj
);
78
}
79
return
*
this
;
80
}
81
82
//-----------------------------------------------------------------------------
83
void
CPyCppyy::DispatchPtr::PythonOwns
()
84
{
85
// Python maintains the hardref, so only allowed a weakref here
86
if
(fPyHardRef) {
87
fPyWeakRef =
PyWeakref_NewRef
(fPyHardRef,
nullptr
);
88
Py_DECREF
(fPyHardRef); fPyHardRef =
nullptr
;
89
}
90
}
91
92
//-----------------------------------------------------------------------------
93
void
CPyCppyy::DispatchPtr::CppOwns
()
94
{
95
// C++ maintains the hardref, keeping the PyObject alive w/o outstanding ref
96
if
(fPyWeakRef) {
97
fPyHardRef =
CPyCppyy_GetWeakRef
(fPyWeakRef);
98
Py_DECREF
(fPyWeakRef); fPyWeakRef =
nullptr
;
99
}
100
}
CPPInstance.h
CPPScope.h
CPyCppyy.h
CPyCppyy_GetWeakRef
static PyObject * CPyCppyy_GetWeakRef(PyObject *ref)
Definition
CPyCppyy.h:356
Py_TYPE
#define Py_TYPE(ob)
Definition
CPyCppyy.h:196
DispatchPtr.h
PyObject
_object PyObject
Definition
PyMethodBase.h:43
fFlags
std::ios_base::fmtflags fFlags
Definition
RDFHelpers.cxx:202
TRangeDynCast
ROOT::Detail::TRangeCast< T, true > TRangeDynCast
TRangeDynCast is an adapter class that allows the typed iteration through a TCollection.
Definition
TCollection.h:358
CPyCppyy::CPPInstance
Definition
CPPInstance.h:26
CPyCppyy::CPPScope
Definition
CPPScope.h:37
CPyCppyy::CPPScope::kIsPython
@ kIsPython
Definition
CPPScope.h:45
CPyCppyy::DispatchPtr
Definition
DispatchPtr.h:23
CPyCppyy::DispatchPtr::CppOwns
void CppOwns()
Definition
DispatchPtr.cxx:93
CPyCppyy::DispatchPtr::assign
DispatchPtr & assign(const DispatchPtr &other, void *cppinst)
Definition
DispatchPtr.cxx:69
CPyCppyy::DispatchPtr::DispatchPtr
DispatchPtr()
Definition
DispatchPtr.h:29
CPyCppyy::DispatchPtr::fPyWeakRef
PyObject * fPyWeakRef
Definition
DispatchPtr.h:71
CPyCppyy::DispatchPtr::Get
PyObject * Get(bool borrowed=true) const
Definition
DispatchPtr.cxx:11
CPyCppyy::DispatchPtr::~DispatchPtr
~DispatchPtr()
Definition
DispatchPtr.cxx:51
CPyCppyy::DispatchPtr::fPyHardRef
PyObject * fPyHardRef
Definition
DispatchPtr.h:70
CPyCppyy::DispatchPtr::PythonOwns
void PythonOwns()
Definition
DispatchPtr.cxx:83
ROOT::Detail::TRangeCast
Definition
TCollection.h:311
bindings
pyroot
cppyy
CPyCppyy
src
DispatchPtr.cxx
ROOT master - Reference Guide Generated on Wed Apr 2 2025 07:35:00 (GVA Time) using Doxygen 1.10.0