-// Copyright (C) 2014-2017 CEA/DEN, EDF R&D
+// Copyright (C) 2014-2019 CEA/DEN, EDF R&D
//
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public
//
// You should have received a copy of the GNU Lesser General Public
// License along with this library; if not, write to the Free Software
-// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
//
-// See http://www.salome-platform.org/ or
-// email : webmaster.salome@opencascade.com<mailto:webmaster.salome@opencascade.com>
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
//
#include <InitializationPlugin_PyInterp.h>
// prepare a context
PyObject* aContext = PyDict_New();
- PyObject* aBuiltinModule = PyImport_AddModule("__builtin__");
- PyDict_SetItemString(aContext, "__builtins__", aBuiltinModule);
+ PyDict_SetItemString(aContext, "__builtins__", PyEval_GetBuiltins());
std::string anExpression = adjustExpression(theExpression);
// extend aContext with variables
- PyDict_SetItemString(aContext, "expression", PyString_FromString(anExpression.c_str()));
- PyDict_SetItemString(aContext, "name", PyString_FromString(theName.c_str()));
+ PyDict_SetItemString(aContext, "expression", PyUnicode_FromString(anExpression.c_str()));
+ PyDict_SetItemString(aContext, "name", PyUnicode_FromString(theName.c_str()));
PyDict_SetItemString(aContext, "positions", Py_BuildValue("[]"));
// run the search code
PyObject* aColOffset = PyTuple_GetItem(aPosition, 1);
aResult.push_back(
- std::pair<int, int>((int)PyInt_AsLong(aLineNo),
- (int)PyInt_AsLong(aColOffset)));
+ std::pair<int, int>((int)PyLong_AsLong(aLineNo),
+ (int)PyLong_AsLong(aColOffset)));
}
// TODO(spo): after this refCount of the variable is not 0. Is there memory leak?
}
PyCodeObject* aCodeObj = (PyCodeObject*) aCodePyObj;
- std::string aCodeName(PyString_AsString(aCodeObj->co_code));
+ std::string aCodeName(PyBytes_AsString(aCodeObj->co_code));
// co_names should be tuple, but can be changed in modern versions of python (>2.7.3)
- if(!PyTuple_Check(aCodeObj->co_names))
+ if(!PyTuple_Check(aCodeObj->co_names)) {
return aResult;
+ }
size_t params_size = PyTuple_Size(aCodeObj->co_names);
if (params_size > 0) {
for (size_t i = 0; i < params_size; i++) {
PyObject* aParamObj = PyTuple_GetItem(aCodeObj->co_names, i);
PyObject* aParamObjStr = PyObject_Str(aParamObj);
- std::string aParamName(PyString_AsString(aParamObjStr));
+ std::string aParamName(PyUnicode_AsUTF8(aParamObjStr));
aResult.push_back(aParamName);
Py_XDECREF(aParamObjStr);
}
return 0.;
}
- PyObject* anEvalResult = PyEval_EvalCode(anExprCode, _global_context, _local_context);
+ PyObject* anEvalResult = PyEval_EvalCode((PyObject *)anExprCode, _global_context, _local_context);
if(!anEvalResult) {
theError = errorMessage();
Py_XDECREF(anExprCode);
}
PyObject* anEvalStrObj = PyObject_Str(anEvalResult);
- std::string anEvalStr(PyString_AsString(anEvalStrObj));
+ std::string anEvalStr(PyUnicode_AsUTF8(anEvalStrObj));
Py_XDECREF(anExprCode);
Py_XDECREF(anEvalResult);
Py_XDECREF(anEvalStrObj);
PyErr_Fetch(&ptype, &pvalue, &ptraceback);
PyErr_NormalizeException(&ptype, &pvalue, &ptraceback);
pstr = PyObject_Str(pvalue);
- aPyError = std::string(PyString_AsString(pstr));
+ aPyError = std::string(PyUnicode_AsUTF8(pstr));
Py_XDECREF(pstr);
Py_XDECREF(ptype);
Py_XDECREF(pvalue);
_local_context = PyDict_New();
Py_INCREF(_local_context);
+ // to avoid "help()" hang in the python console
+ const static char* aHelpTxt = "def help(): print(\"Available modules:\\n"
+ " salome.shaper.model : higher level access to features and data model\\n"
+ " BuildAPI : Build plugin features allowing to build shapes\\n"
+ " ConfigAPI : configuration management: preferences and XML properties\\n"
+ " ConstructionAPI : Construction plugin for auxiliary features creation\\n"
+ " EventsAPI : application events receiving and emitting manager\\n"
+ " ExchangeAPI : Exchange plugin with import/export features\\n"
+ " FeaturesAPI : Features plugin with general 3D features\\n"
+ " GeomAlgoAPI : geometrical algorithms\\n"
+ " GeomAPI : geometrical data structures\\n"
+ " GeomDataAPI : specific geometrical data structures stored in the data model\\n"
+ " ModelAPI : general low-level interface to access data model\\n"
+ " ModelHighAPI : general high-level interface to access data model\\n"
+ " ParametersAPI : Parameters plugin for parameters feature management\\n"
+ " PartSetAPI : PartSet plugin for management Parts features\\n"
+ " SketchAPI : Sketch plugin with all sketch features\")";
+
+ PyRun_SimpleString(aHelpTxt);
+
return PyRun_SimpleString("from math import *") == 0;
}