mirror of
https://github.com/idapython/src
synced 2026-06-08 14:47:00 +00:00
Backported fixes
This commit is contained in:
+9
-5
@@ -441,9 +441,13 @@ static void handle_python_error(
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
static const char *bomify(qstring *out)
|
||||
static const char *insert_coding_cookie(qstring *out)
|
||||
{
|
||||
out->insert(0, UTF8_BOM, UTF8_BOM_SZ);
|
||||
// This is necessary for pre-3.9 parsers, to parse the
|
||||
// input text as proper UTF-8. Python 3.9 switches to the PEG
|
||||
// parser that, by default (and in particular since we don't
|
||||
// pass PyCompilerFlags), will always assume UTF-8.
|
||||
out->insert(0, "# -*- coding: UTF-8 -*-\n");
|
||||
return out->c_str();
|
||||
}
|
||||
|
||||
@@ -1305,7 +1309,7 @@ bool idapython_plugin_t::_extlang_compile_expr(
|
||||
bool isfunc = false;
|
||||
|
||||
qstring qstr(expr);
|
||||
PyObject *code = Py_CompileString(bomify(&qstr), "<string>", Py_eval_input);
|
||||
PyObject *code = Py_CompileString(insert_coding_cookie(&qstr), "<string>", Py_eval_input);
|
||||
if ( code == NULL )
|
||||
{
|
||||
// try compiling as a list of statements
|
||||
@@ -1313,7 +1317,7 @@ bool idapython_plugin_t::_extlang_compile_expr(
|
||||
handle_python_error(errbuf);
|
||||
qstring func;
|
||||
wrap_in_function(&func, expr, name);
|
||||
bomify(&func);
|
||||
insert_coding_cookie(&func);
|
||||
code = Py_CompileString(func.c_str(), "<string>", Py_file_input);
|
||||
if ( code == NULL )
|
||||
{
|
||||
@@ -1872,7 +1876,7 @@ bool idapython_plugin_t::_cli_execute_line(const char *line)
|
||||
|
||||
// Compile as an expression
|
||||
qstring qstr(line);
|
||||
newref_t py_code(Py_CompileString(bomify(&qstr), "<string>", Py_eval_input));
|
||||
newref_t py_code(Py_CompileString(insert_coding_cookie(&qstr), "<string>", Py_eval_input));
|
||||
if ( py_code == NULL || PyErr_Occurred() )
|
||||
{
|
||||
// Not an expression?
|
||||
|
||||
Reference in New Issue
Block a user