Skip to content

Commit

Permalink
[PyROOT] Merge PyROOTWrapper with PyROOTModule
Browse files Browse the repository at this point in the history
The PyROOTWrapper is a small piece of code that is only used in
PyROOTModuce.cxx, so I don't think it needs its own translation unit.
  • Loading branch information
guitargeek committed Nov 8, 2024
1 parent 2cb627c commit 167ea46
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 71 deletions.
1 change: 0 additions & 1 deletion bindings/pyroot/pythonizations/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,6 @@ set(py_sources

set(cpp_sources
src/PyROOTModule.cxx
src/PyROOTWrapper.cxx
src/RPyROOTApplication.cxx
src/GenericPyz.cxx
src/TClassPyz.cxx
Expand Down
27 changes: 23 additions & 4 deletions bindings/pyroot/pythonizations/src/PyROOTModule.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@

// Bindings
#include "PyROOTPythonize.h"
#include "PyROOTWrapper.h"
#include "RPyROOTApplication.h"
#include "TMemoryRegulator.h"

// Cppyy
#include "CPyCppyy/API.h"
Expand All @@ -34,7 +34,7 @@

namespace PyROOT {

PyObject *gRootModule = nullptr;
R__EXTERN PyObject *gRootModule = nullptr;

PyObject *RegisterConverterAlias(PyObject * /*self*/, PyObject *args)
{
Expand Down Expand Up @@ -62,6 +62,20 @@ PyObject *RegisterExecutorAlias(PyObject * /*self*/, PyObject *args)

} // namespace PyROOT

namespace {

PyROOT::RegulatorCleanup &GetRegulatorCleanup()
{
// The object is thread-local because it can happen that we call into
// C++ code (from the PyROOT CPython extension, from CPyCppyy or from cling)
// from different Python threads. A notable example is within a distributed
// RDataFrame application running on Dask.
thread_local PyROOT::RegulatorCleanup m;
return m;
}

} // namespace

// Methods offered by the interface
static PyMethodDef gPyROOTMethods[] = {
{(char *)"AddCPPInstancePickling", (PyCFunction)PyROOT::AddCPPInstancePickling, METH_VARARGS,
Expand Down Expand Up @@ -144,8 +158,13 @@ extern "C" PyObject *PyInit_libROOTPythonizations()
// keep gRootModule, but do not increase its reference count even as it is borrowed,
// or a self-referencing cycle would be created

// setup PyROOT
PyROOT::Init();
// Initialize and acquire the GIL to allow for threading in ROOT
#if PY_VERSION_HEX < 0x03090000
PyEval_InitThreads();
#endif

// Memory management
gROOT->GetListOfCleanups()->Add(&GetRegulatorCleanup());

// signal policy: don't abort interpreter in interactive mode
CallContext::SetGlobalSignalPolicy(!gROOT->IsBatch());
Expand Down
42 changes: 0 additions & 42 deletions bindings/pyroot/pythonizations/src/PyROOTWrapper.cxx

This file was deleted.

24 changes: 0 additions & 24 deletions bindings/pyroot/pythonizations/src/PyROOTWrapper.h

This file was deleted.

0 comments on commit 167ea46

Please sign in to comment.