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
59#ifndef F_LINUX_SPECIFIC_BASE
60#define F_LINUX_SPECIFIC_BASE 1024
63#define F_SETPIPE_SZ (F_LINUX_SPECIFIC_BASE + 7)
70static void PollImpl(FILE *stdStream,
int *pipeHandle, std::string &pipeContent)
74 char buffer[60000] =
"";
76 _fstat(pipeHandle[0], &st);
78 _read(pipeHandle[0], buffer, 60000);
79 pipeContent += buffer;
85 buf_read = read(pipeHandle[0], &ch, 1);
102 savedStdStream = dup(FILENO);
103 if (pipe(pipeHandle) != 0) {
107 long flags_stdout = fcntl(pipeHandle[0], F_GETFL);
108 if (flags_stdout == -1)
110 flags_stdout |= O_NONBLOCK;
111 fcntl(pipeHandle[0], F_SETFL, flags_stdout);
114 dup2(pipeHandle[1], FILENO);
167 const char *demangledType = err ?
"<UNKNOWN>" : demangledType_c;
168 ::Error(location,
"%s caught: %s", demangledType,
e.what());
169 free(demangledType_c);
183 gInterpreter->ProcessLine(
"cerr << \"Unbalanced braces. This cell was not processed.\" << endl;");
185 }
catch (std::exception &
e) {
188 ::Error(
"JupyROOTExecutor",
"Exception caught!");
201 }
catch (std::exception &
e) {
204 ::Error(
"JupyROOTDeclarer",
"Exception caught!");
212 if (!PyArg_ParseTuple(args,
"s", &code))
217 return PyLong_FromLong(res);
223 if (!PyArg_ParseTuple(args,
"s", &code))
228 return PyLong_FromLong(res);
242 gInterpreter->ProcessLine(
"SetErrorHandler((ErrorHandlerFunc_t)&DefaultErrorHandler);");
269 return PyUnicode_FromString(out);
275 return PyUnicode_FromString(err);
PyObject * JupyROOTExecutorHandler_Ctor(PyObject *, PyObject *)
static void ReportCaughtException(const char *location, const std::exception &e)
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 *)
void Error(const char *location, const char *msgfmt,...)
Use this function in case an error occurred.
JupyROOTExecutorHandler()
std::string & GetStderr()
std::string & GetStdout()
char * DemangleTypeIdName(const std::type_info &ti, int &errorCode)
Demangle in a portable way the type id name.