Merge pull request #433 from YosysHQ/dave/pyfixes
python: Miscellaneous fixes
This commit is contained in:
commit
5c6b2cbafe
@ -82,19 +82,29 @@ const std::list<std::string> &pyinterpreter_suggest(const std::string &hint)
|
|||||||
PyEval_AcquireThread(m_threadState);
|
PyEval_AcquireThread(m_threadState);
|
||||||
m_suggestions.clear();
|
m_suggestions.clear();
|
||||||
int i = 0;
|
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;
|
std::string res;
|
||||||
do {
|
do {
|
||||||
PyObject *py_result;
|
PyObject *py_result;
|
||||||
PyObject *dum;
|
PyObject *dum;
|
||||||
py_result = Py_CompileString(command.c_str(), "<stdin>", Py_single_input);
|
py_result = Py_CompileString(command.c_str(), "<stdin>", Py_single_input);
|
||||||
|
if (py_result == nullptr)
|
||||||
|
break;
|
||||||
dum = PyEval_EvalCode(py_result, glb, loc);
|
dum = PyEval_EvalCode(py_result, glb, loc);
|
||||||
|
if (dum == nullptr)
|
||||||
|
break;
|
||||||
Py_XDECREF(dum);
|
Py_XDECREF(dum);
|
||||||
Py_XDECREF(py_result);
|
Py_XDECREF(py_result);
|
||||||
res = redirector_take_output(m_threadState);
|
res = redirector_take_output(m_threadState);
|
||||||
|
|
||||||
++i;
|
++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()) {
|
if (res.size()) {
|
||||||
// throw away the newline
|
// throw away the newline
|
||||||
res = res.substr(1, res.size() - 3);
|
res = res.substr(1, res.size() - 3);
|
||||||
|
@ -285,7 +285,9 @@ template <typename T1, typename T2, typename value_conv> struct map_pair_wrapper
|
|||||||
{
|
{
|
||||||
if ((i >= 2) || (i < 0))
|
if ((i >= 2) || (i < 0))
|
||||||
KeyError();
|
KeyError();
|
||||||
return (i == 1) ? object(value_conv()(x.ctx, x.base.second)) : object(x.base.first);
|
return (i == 1) ? object(value_conv()(x.ctx, x.base.second))
|
||||||
|
: object(PythonConversion::string_converter<decltype(x.base.first)>().to_str(x.ctx,
|
||||||
|
x.base.first));
|
||||||
}
|
}
|
||||||
|
|
||||||
static int len(wrapped_pair &x) { return 2; }
|
static int len(wrapped_pair &x) { return 2; }
|
||||||
@ -410,7 +412,8 @@ template <typename T1, typename T2> struct map_pair_wrapper_uptr
|
|||||||
if ((i >= 2) || (i < 0))
|
if ((i >= 2) || (i < 0))
|
||||||
KeyError();
|
KeyError();
|
||||||
return (i == 1) ? object(PythonConversion::ContextualWrapper<V &>(x.ctx, *x.base.second.get()))
|
return (i == 1) ? object(PythonConversion::ContextualWrapper<V &>(x.ctx, *x.base.second.get()))
|
||||||
: object(x.base.first);
|
: object(PythonConversion::string_converter<decltype(x.base.first)>().to_str(x.ctx,
|
||||||
|
x.base.first));
|
||||||
}
|
}
|
||||||
|
|
||||||
static int len(wrapped_pair &x) { return 2; }
|
static int len(wrapped_pair &x) { return 2; }
|
||||||
|
Loading…
Reference in New Issue
Block a user