Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
PythonInterface.cxx
Go to the documentation of this file.
1#include "./PythonInterface.h"
2
3#include <TSystem.h>
4
5namespace xPython {
6
7 // https://docs.python.org/3.11/c-api/init.html#c.Py_IsInitialized
9 using fn_t = int (*)();
10 static auto f = reinterpret_cast<fn_t>(gSystem->DynFindSymbol("*", "Py_IsInitialized"));
11 return f && f();
12 }
13
14 // https://docs.python.org/3/c-api/sys.html#c.PySys_WriteStdout
15 void writeStdoutLine(const char *msg) {
16 using fn_t = void (*)(const char *, ...);
17 static auto f = reinterpret_cast<fn_t>(gSystem->DynFindSymbol("*", "PySys_WriteStdout"));
18 if (f)
19 f("%s\n", msg);
20 }
21
22 // https://docs.python.org/3/c-api/sys.html#c.PySys_WriteStderr
23 void writeStderrLine(const char *msg) {
24 using fn_t = void (*)(const char *, ...);
25 static auto f = reinterpret_cast<fn_t>(gSystem->DynFindSymbol("*", "PySys_WriteStderr"));
26 if (f)
27 f("%s\n", msg);
28 }
29
30} // namespace xPython
#define f(i)
Definition RSha256.hxx:104
R__EXTERN TSystem * gSystem
Definition TSystem.h:582
virtual Func_t DynFindSymbol(const char *module, const char *entry)
Find specific entry point in specified library.
Definition TSystem.cxx:2059
void writeStdoutLine(const char *msg)
bool isPythonInitialized()
void writeStderrLine(const char *msg)