17#pragma comment(lib, "Ws2_32.lib")
18#define pipe(fds) _pipe(fds, 1048575, _O_BINARY)
23#define STDOUT_FILENO 1
24#define STDERR_FILENO 2
56#ifndef F_LINUX_SPECIFIC_BASE
57#define F_LINUX_SPECIFIC_BASE 1024
60#define F_SETPIPE_SZ (F_LINUX_SPECIFIC_BASE + 7)
67static void PollImpl(FILE *stdStream,
int *pipeHandle, std::string &pipeContent)
71 char buffer[60000] =
"";
73 _fstat(pipeHandle[0], &st);
75 _read(pipeHandle[0], buffer, 60000);
76 pipeContent += buffer;
82 buf_read = read(pipeHandle[0], &ch, 1);
99 savedStdStream = dup(FILENO);
100 if (pipe(pipeHandle) != 0) {
104 long flags_stdout = fcntl(pipeHandle[0], F_GETFL);
105 if (flags_stdout == -1)
107 flags_stdout |= O_NONBLOCK;
108 fcntl(pipeHandle[0], F_SETFL, flags_stdout);
111 dup2(pipeHandle[1], FILENO);
168 gInterpreter->ProcessLine(
"cerr << \"Unbalanced braces. This cell was not processed.\" << endl;");
193 if (!PyArg_ParseTuple(args,
"s", &code))
198 return PyLong_FromLong(res);
204 if (!PyArg_ParseTuple(args,
"s", &code))
209 return PyLong_FromLong(res);
223 gInterpreter->ProcessLine(
"SetErrorHandler((ErrorHandlerFunc_t)&DefaultErrorHandler);");
250 return PyUnicode_FromString(out);
256 return PyUnicode_FromString(err);
PyObject * JupyROOTExecutorHandler_Ctor(PyObject *, PyObject *)
PyObject * JupyROOTDeclarer(PyObject *, PyObject *args)
static void InitCaptureImpl(int &savedStdStream, int *pipeHandle, int FILENO)
JupyROOTExecutorHandler * JupyROOTExecutorHandler_ptr
constexpr long MAX_PIPE_SIZE
PyObject * JupyROOTExecutorHandler_GetStdout(PyObject *, PyObject *)
bool JupyROOTDeclarerImpl(const char *code)
static void PollImpl(FILE *stdStream, int *pipeHandle, std::string &pipeContent)
bool JupyROOTExecutorImpl(const char *code)
PyObject * JupyROOTExecutor(PyObject *, PyObject *args)
PyObject * JupyROOTExecutorHandler_EndCapture(PyObject *, PyObject *)
PyObject * JupyROOTExecutorHandler_Poll(PyObject *, PyObject *)
PyObject * JupyROOTExecutorHandler_Clear(PyObject *, PyObject *)
PyObject * JupyROOTExecutorHandler_GetStderr(PyObject *, PyObject *)
PyObject * JupyROOTExecutorHandler_InitCapture(PyObject *, PyObject *)
PyObject * JupyROOTExecutorHandler_Dtor(PyObject *, PyObject *)
JupyROOTExecutorHandler()
std::string & GetStderr()
std::string & GetStdout()