7#pragma comment(lib, "Ws2_32.lib")
8#define pipe(fds) _pipe(fds, 1048575, _O_BINARY)
13#define STDOUT_FILENO 1
14#define STDERR_FILENO 2
25class JupyROOTExecutorHandler {
27 bool fCapturing =
false;
28 std::string fStdoutpipe;
29 std::string fStderrpipe;
30 int fStdout_pipe[2] = {0,0};
31 int fStderr_pipe[2] = {0,0};
32 int fSaved_stderr = 0;
33 int fSaved_stdout = 0;
35 JupyROOTExecutorHandler();
40 std::string &GetStdout();
41 std::string &GetStderr();
45#ifndef F_LINUX_SPECIFIC_BASE
46#define F_LINUX_SPECIFIC_BASE 1024
49#define F_SETPIPE_SZ (F_LINUX_SPECIFIC_BASE + 7)
54JupyROOTExecutorHandler::JupyROOTExecutorHandler() {}
57static void PollImpl(FILE *stdStream,
int *pipeHandle, std::string &pipeContent)
63 buf_read = read(pipeHandle[0], &ch, 1);
70void JupyROOTExecutorHandler::Poll()
72 PollImpl(stdout, fStdout_pipe, fStdoutpipe);
73 PollImpl(stderr, fStderr_pipe, fStderrpipe);
78 savedStdStream = dup(FILENO);
79 if (pipe(pipeHandle) != 0) {
83 unsigned long mode = 1;
84 ioctlsocket(pipeHandle[0], FIONBIO, &mode);
86 long flags_stdout = fcntl(pipeHandle[0], F_GETFL);
87 if (flags_stdout == -1)
return;
88 flags_stdout |= O_NONBLOCK;
89 fcntl(pipeHandle[0], F_SETFL, flags_stdout);
92 dup2(pipeHandle[1], FILENO);
96void JupyROOTExecutorHandler::InitCapture()
105void JupyROOTExecutorHandler::EndCapture()
109 dup2(fSaved_stdout, STDOUT_FILENO);
110 dup2(fSaved_stderr, STDERR_FILENO);
115void JupyROOTExecutorHandler::Clear()
121std::string &JupyROOTExecutorHandler::GetStdout()
126std::string &JupyROOTExecutorHandler::GetStderr()
145 gInterpreter->ProcessLine(
"cerr << \"Unbalanced braces. This cell was not processed.\" << endl;");
188 gInterpreter->ProcessLine(
"SetErrorHandler((ErrorHandlerFunc_t)&DefaultErrorHandler);");
int JupyROOTDeclarer(const char *code)
void JupyROOTExecutorHandler_Dtor()
void JupyROOTExecutorHandler_InitCapture()
static void InitCaptureImpl(int &savedStdStream, int *pipeHandle, int FILENO)
JupyROOTExecutorHandler * JupyROOTExecutorHandler_ptr
void JupyROOTExecutorHandler_Poll()
int JupyROOTExecutor(const char *code)
constexpr long MAX_PIPE_SIZE
const char * JupyROOTExecutorHandler_GetStderr()
void JupyROOTExecutorHandler_Ctor()
bool JupyROOTDeclarerImpl(const char *code)
static void PollImpl(FILE *stdStream, int *pipeHandle, std::string &pipeContent)
bool JupyROOTExecutorImpl(const char *code)
const char * JupyROOTExecutorHandler_GetStdout()
void JupyROOTExecutorHandler_Clear()
void JupyROOTExecutorHandler_EndCapture()