forked from root-project/root
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPythonInterface.cxx
More file actions
30 lines (24 loc) · 951 Bytes
/
Copy pathPythonInterface.cxx
File metadata and controls
30 lines (24 loc) · 951 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#include "./PythonInterface.h"
#include <TSystem.h>
namespace xPython {
// https://docs.python.org/3.11/c-api/init.html#c.Py_IsInitialized
bool isPythonInitialized() {
using fn_t = int (*)();
static auto f = reinterpret_cast<fn_t>(gSystem->DynFindSymbol("*", "Py_IsInitialized"));
return f && f();
}
// https://docs.python.org/3/c-api/sys.html#c.PySys_WriteStdout
void writeStdoutLine(const char *msg) {
using fn_t = void (*)(const char *, ...);
static auto f = reinterpret_cast<fn_t>(gSystem->DynFindSymbol("*", "PySys_WriteStdout"));
if (f)
f("%s\n", msg);
}
// https://docs.python.org/3/c-api/sys.html#c.PySys_WriteStderr
void writeStderrLine(const char *msg) {
using fn_t = void (*)(const char *, ...);
static auto f = reinterpret_cast<fn_t>(gSystem->DynFindSymbol("*", "PySys_WriteStderr"));
if (f)
f("%s\n", msg);
}
} // namespace xPython