From: mpv Date: Mon, 3 Oct 2016 11:10:31 +0000 (+0300) Subject: Fix for #1776: make division between integer produce floating point result when param... X-Git-Tag: V_2.5.1~4 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=c6d8bbc2d7becf58d0ef128e8a5aa861d9d2272b;p=modules%2Fshaper.git Fix for #1776: make division between integer produce floating point result when parameter is evaluated. --- diff --git a/src/ParametersPlugin/ParametersPlugin_PyInterp.cpp b/src/ParametersPlugin/ParametersPlugin_PyInterp.cpp index 054c8c3e2..1d9851b83 100644 --- a/src/ParametersPlugin/ParametersPlugin_PyInterp.cpp +++ b/src/ParametersPlugin/ParametersPlugin_PyInterp.cpp @@ -94,9 +94,9 @@ std::list ParametersPlugin_PyInterp::compile(const std::string& the if(!PyTuple_Check(aCodeObj->co_names)) return aResult; - int params_size = PyTuple_Size(aCodeObj->co_names); + size_t params_size = PyTuple_Size(aCodeObj->co_names); if (params_size > 0) { - for (int i = 0; i < params_size; i++) { + 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)); @@ -126,12 +126,13 @@ void ParametersPlugin_PyInterp::clearLocalContext() PyDict_Clear(_local_context); } - double ParametersPlugin_PyInterp::evaluate(const std::string& theExpression, std::string& theError) { PyLockWrapper lck; // Acquire GIL until the end of the method - PyCodeObject* anExprCode = (PyCodeObject *) Py_CompileString(theExpression.c_str(), - "", Py_eval_input); + PyCompilerFlags aFlags = {CO_FUTURE_DIVISION}; + aFlags.cf_flags = CO_FUTURE_DIVISION; + PyCodeObject* anExprCode = (PyCodeObject *) Py_CompileStringFlags(theExpression.c_str(), + "", Py_eval_input, &aFlags); if(!anExprCode) { theError = errorMessage(); Py_XDECREF(anExprCode);