Back to index

salome-gui  6.5.0
Defines | Functions | Variables
PyInterp_Interp.cxx File Reference
#include "PyInterp_Interp.h"
#include <pythread.h>
#include <cStringIO.h>
#include <structmember.h>
#include <string>
#include <vector>
#include <map>
#include <iostream>

Go to the source code of this file.


#define TOP_HISTORY_PY   "--- top of history ---"
#define BEGIN_HISTORY_PY   "--- begin of history ---"
#define PyStdOut_Check(v)   ((v)->ob_type == &PyStdOut_Type)


static void PyStdOut_dealloc (PyStdOut *self)
static PyObject * PyStdOut_write (PyStdOut *self, PyObject *args)
static PyObject * PyStdOut_flush (PyStdOut *self)
static PyStdOutnewPyStdOut (bool iscerr)
static int compile_command (const char *command, PyObject *context)
 Compile Python command and evaluate it in the python dictionary context if possible.


std::map< long, PyThreadState * > currentThreadMap
static PyMethodDef PyStdOut_methods []
static PyMemberDef PyStdOut_memberlist []
static PyTypeObject PyStdOut_Type

Define Documentation

#define BEGIN_HISTORY_PY   "--- begin of history ---"

Definition at line 39 of file PyInterp_Interp.cxx.

#define PyStdOut_Check (   v)    ((v)->ob_type == &PyStdOut_Type)

Definition at line 213 of file PyInterp_Interp.cxx.

#define TOP_HISTORY_PY   "--- top of history ---"

Definition at line 38 of file PyInterp_Interp.cxx.

Function Documentation

static int compile_command ( const char *  command,
PyObject *  context 
) [static]

Compile Python command and evaluate it in the python dictionary context if possible.

commandPython command string
contextPython context (dictionary)
-1 on fatal error, 1 if command is incomplete and 0 if command is executed successfully

Definition at line 376 of file PyInterp_Interp.cxx.

  PyObject *m = PyImport_AddModule("codeop");
  if(!m) { // Fatal error. No way to go on.
    return -1;
  PyObjWrapper v(PyObject_CallMethod(m,(char*)"compile_command",(char*)"s",command));
  if(!v) {
    // Error encountered. It should be SyntaxError,
    //so we don't write out traceback
    PyObjWrapper exception, value, tb;
    PyErr_Fetch(&exception, &value, &tb);
    PyErr_NormalizeException(&exception, &value, &tb);
    PyErr_Display(exception, value, NULL);
    return -1;
  else if (v == Py_None) {
    // Incomplete text we return 1 : we need a complete text to execute
    return 1;
  else {
    // Complete and correct text. We evaluate it.
    //#if PY_VERSION_HEX < 0x02040000 // python version earlier than 2.4.0
    //    PyObjWrapper r(PyEval_EvalCode(v,context,context));
    PyObjWrapper r(PyEval_EvalCode((PyCodeObject *)(void *)v,context,context));
    if(!r) {
      // Execution error. We return -1
      return -1;
    // The command has been successfully executed. Return 0
    return 0;
static PyStdOut* newPyStdOut ( bool  iscerr) [static]

Definition at line 215 of file PyInterp_Interp.cxx.

  PyStdOut *self;
  self = PyObject_New(PyStdOut, &PyStdOut_Type);
  if (self == NULL)
    return NULL;
  self->softspace = 0;
  self->_cb = NULL;
  self->_iscerr = iscerr;
  return self;
static void PyStdOut_dealloc ( PyStdOut self) [static]

Definition at line 121 of file PyInterp_Interp.cxx.

static PyObject* PyStdOut_flush ( PyStdOut self) [static]

Definition at line 147 of file PyInterp_Interp.cxx.

  return Py_None;
static PyObject* PyStdOut_write ( PyStdOut self,
PyObject *  args 
) [static]

Definition at line 127 of file PyInterp_Interp.cxx.

  char *c;
  int l;
  if (!PyArg_ParseTuple(args, "t#:write",&c, &l))
    return NULL;
  if(self->_cb==NULL) {
    if ( self->_iscerr )
      std::cerr << c ;
      std::cout << c ;
  else {
  return Py_None;

Variable Documentation

std::map<long,PyThreadState*> currentThreadMap

Definition at line 42 of file PyInterp_Interp.cxx.

PyMemberDef PyStdOut_memberlist[] [static]
Initial value:
  {(char*)"softspace", T_INT,  offsetof(PyStdOut, softspace), 0,
   (char*)"flag indicating that a space needs to be printed; used by print"},

Definition at line 159 of file PyInterp_Interp.cxx.

PyMethodDef PyStdOut_methods[] [static]
Initial value:
  {"write",  (PyCFunction)PyStdOut_write,  METH_VARARGS, PyDoc_STR("write(string) -> None")},
  {"flush",  (PyCFunction)PyStdOut_flush,  METH_NOARGS,  PyDoc_STR("flush() -> None")},
  {NULL,    NULL}   

Definition at line 153 of file PyInterp_Interp.cxx.

PyTypeObject PyStdOut_Type [static]

Definition at line 165 of file PyInterp_Interp.cxx.