diff options
| author | David Shah <dave@ds0.me> | 2020-04-24 19:01:04 +0100 | 
|---|---|---|
| committer | GitHub <noreply@github.com> | 2020-04-24 19:01:04 +0100 | 
| commit | 5c6b2cbafef7435bd697cedf30436bf16e70dc15 (patch) | |
| tree | 7fd3e809e960079aeacd66ae8a8fcfa37203e4c3 /3rdparty/python-console/modified | |
| parent | 5e40589114c1a61825d3772165f457895fc9acd0 (diff) | |
| parent | 25938500d6d0fbcd6e14d7d5ff3e45275ead6bb7 (diff) | |
| download | nextpnr-5c6b2cbafef7435bd697cedf30436bf16e70dc15.tar.gz nextpnr-5c6b2cbafef7435bd697cedf30436bf16e70dc15.tar.bz2 nextpnr-5c6b2cbafef7435bd697cedf30436bf16e70dc15.zip | |
Merge pull request #433 from YosysHQ/dave/pyfixes
python: Miscellaneous fixes
Diffstat (limited to '3rdparty/python-console/modified')
| -rw-r--r-- | 3rdparty/python-console/modified/pyinterpreter.cc | 14 | 
1 files changed, 12 insertions, 2 deletions
| diff --git a/3rdparty/python-console/modified/pyinterpreter.cc b/3rdparty/python-console/modified/pyinterpreter.cc index 89c9b88c..cbb6322f 100644 --- a/3rdparty/python-console/modified/pyinterpreter.cc +++ b/3rdparty/python-console/modified/pyinterpreter.cc @@ -82,19 +82,29 @@ const std::list<std::string> &pyinterpreter_suggest(const std::string &hint)      PyEval_AcquireThread(m_threadState);      m_suggestions.clear();      int i = 0; -    std::string command = string_format("sys.completer.complete('%s', %d)\n", hint.c_str(), i); +    std::string escaped; +    for (char c : hint) { +        if (c == '\'' || c == '\\') +            escaped += '\\'; +        escaped += c; +    } +    std::string command = string_format("sys.completer.complete('%s', %d)\n", escaped.c_str(), i);      std::string res;      do {          PyObject *py_result;          PyObject *dum;          py_result = Py_CompileString(command.c_str(), "<stdin>", Py_single_input); +        if (py_result == nullptr) +            break;          dum = PyEval_EvalCode(py_result, glb, loc); +        if (dum == nullptr) +            break;          Py_XDECREF(dum);          Py_XDECREF(py_result);          res = redirector_take_output(m_threadState);          ++i; -        command = string_format("sys.completer.complete('%s', %d)\n", hint.c_str(), i); +        command = string_format("sys.completer.complete('%s', %d)\n", escaped.c_str(), i);          if (res.size()) {              // throw away the newline              res = res.substr(1, res.size() - 3); | 
