Salome HOME
Python3 porting: stdout and stderr redirects in the embeded python console.
[modules/gui.git] / tools / PyInterp / src / PyInterp_Interp.cxx
index 4b8f8fe766059122c01860a840952a648c83c1d3..84cca0222e46171237e504be271887eee2d8a138 100644 (file)
 #define TOP_HISTORY_PY   "--- top of history ---"
 #define BEGIN_HISTORY_PY "--- begin of history ---"
 
-#if PY_VERSION_HEX < 0x03050000
-static wchar_t*
-Py_DecodeLocale(const char *arg, size_t *size)
-{
-    wchar_t *res;
-    unsigned char *in;
-    wchar_t *out;
-    size_t argsize = strlen(arg) + 1;
-
-    if (argsize > PY_SSIZE_T_MAX/sizeof(wchar_t))
-        return NULL;
-    res = (wchar_t*) PyMem_RawMalloc(argsize*sizeof(wchar_t));
-    if (!res)
-        return NULL;
-
-    in = (unsigned char*)arg;
-    out = res;
-    while(*in)
-        if(*in < 128)
-            *out++ = *in++;
-        else
-            *out++ = 0xdc00 + *in++;
-    *out = 0;
-    if (size != NULL)
-        *size = out - res;
-    return res;
-}
-#endif
-
 /*
   The following functions are used to hook the Python
   interpreter output.
@@ -84,8 +55,7 @@ static PyObject*
 PyStdOut_write(PyStdOut *self, PyObject *args)
 {
   char *c;
-  int l;
-  if (!PyArg_ParseTuple(args, "t#:write",&c, &l))
+  if (!PyArg_ParseTuple(args, "s",&c))
     return NULL;
   if(self->_cb==NULL) {
     if ( self->_iscerr )
@@ -165,6 +135,14 @@ static PyTypeObject PyStdOut_Type = {
   0,                            /*tp_new*/
   0,                            /*tp_free*/
   0,                            /*tp_is_gc*/
+  0,                            /*tp_bases*/
+  0,                            /*tp_mro*/
+  0,                            /*tp_cache*/
+  0,                            /*tp_subclasses*/
+  0,                            /*tp_weaklist*/
+  0,                            /*tp_del*/
+  0,                            /*tp_version_tag*/
+  0                             /*tp_finalize*/
 };
 
 #define PyStdOut_Check(v)  ((v)->ob_type == &PyStdOut_Type)
@@ -283,7 +261,7 @@ void PyInterp_Interp::initPython()
     PySys_SetArgv(_argc, changed_argv);
 
     PyEval_InitThreads(); // Create (and acquire) the Python global interpreter lock (GIL)
-    PyEval_ReleaseLock();
+    PyEval_SaveThread(); // release safely GIL
   }
 }