Logo ROOT  
Reference Guide
PyROOTStrings.cxx
Go to the documentation of this file.
1 // Author: Enric Tejedor CERN 06/2018
2 // Original PyROOT code by Wim Lavrijsen, LBL
3 
4 /*************************************************************************
5  * Copyright (C) 1995-2018, Rene Brun and Fons Rademakers. *
6  * All rights reserved. *
7  * *
8  * For the licensing terms see $ROOTSYS/LICENSE. *
9  * For the list of contributors see $ROOTSYS/README/CREDITS. *
10  *************************************************************************/
11 
12 // Bindings
13 #include "CPyCppyy.h"
14 #include "PyROOTStrings.h"
15 
16 // Define cached python strings
24 
25 #define PYROOT_INITIALIZE_STRING(var, str) \
26  if (!(PyStrings::var = CPyCppyy_PyText_InternFromString((char *)#str))) \
27  return false
28 
30 {
31  // Build cache of commonly used python strings (the cache is python intern, so
32  // all strings are shared python-wide, not just in PyROOT).
38  PYROOT_INITIALIZE_STRING(gTClassDynCast, _TClass__DynamicCast);
39  PYROOT_INITIALIZE_STRING(gClass, __class__);
40 
41  return true;
42 }
43 
44 /// Remove all cached python strings.
45 
47 {
48  Py_DECREF(PyStrings::gBranch);
49  PyStrings::gBranch = nullptr;
50  Py_DECREF(PyStrings::gFitFCN);
51  PyStrings::gFitFCN = nullptr;
52  Py_DECREF(PyStrings::gROOTns);
53  PyStrings::gROOTns = nullptr;
56  Py_DECREF(PyStrings::gSetFCN);
57  PyStrings::gSetFCN = nullptr;
58  Py_DECREF(PyStrings::gTClassDynCast);
59  PyStrings::gTClassDynCast = nullptr;
60  Py_DECREF(PyStrings::gClass);
61  PyStrings::gClass = nullptr;
62 
63  Py_INCREF(Py_None);
64  return Py_None;
65 }
PyObject
_object PyObject
Definition: PyMethodBase.h:42
PyROOT::PyStrings::gSetFCN
R__EXTERN PyObject * gSetFCN
Definition: PyROOTStrings.h:28
PyROOT::DestroyPyStrings
PyObject * DestroyPyStrings()
Remove all cached python strings.
Definition: PyROOTStrings.cxx:46
PyROOT::PyStrings::gFitFCN
R__EXTERN PyObject * gFitFCN
Definition: PyROOTStrings.h:25
PyROOT::PyStrings::gTClassDynCast
R__EXTERN PyObject * gTClassDynCast
Definition: PyROOTStrings.h:29
PyROOT::CreatePyStrings
bool CreatePyStrings()
Definition: PyROOTStrings.cxx:29
PyROOT::PyStrings::gBranch
R__EXTERN PyObject * gBranch
Definition: PyROOTStrings.h:24
PYROOT_INITIALIZE_STRING
#define PYROOT_INITIALIZE_STRING(var, str)
Definition: PyROOTStrings.cxx:25
PyROOT::PyStrings::gClass
R__EXTERN PyObject * gClass
Definition: PyROOTStrings.h:31
CPyCppyy.h
PyROOT::PyStrings::gROOTns
R__EXTERN PyObject * gROOTns
Definition: PyROOTStrings.h:26
PyROOT::PyStrings::gSetBranchAddress
R__EXTERN PyObject * gSetBranchAddress
Definition: PyROOTStrings.h:27
PyROOTStrings.h
ROOT
VSD Structures.
Definition: StringConv.hxx:21