Backported fixes - mostly issues discovered with Python 3.11+

This commit is contained in:
Arnaud Diederen
2023-01-16 11:14:55 +01:00
parent 201a874e81
commit a2a75975f2
9 changed files with 60 additions and 15 deletions
+2 -2
View File
@@ -57,8 +57,8 @@ class painter_t(QtCore.QObject):
painter.setRenderHints(QtGui.QPainter.Antialiasing)
pxl, is_vertical = ida_kernwin.get_navband_pixel(ea)
if pxl >= 0:
x = (self.target.width() / 2) if is_vertical else pxl
y = pxl if is_vertical else (self.target.height() / 2)
x = (self.target.width() // 2) if is_vertical else pxl
y = pxl if is_vertical else (self.target.height() // 2)
painter.setPen(color)
painter.setBrush(color)
painter.drawEllipse(QtCore.QPoint(x, y), radius, radius)
+1
View File
@@ -15,6 +15,7 @@ global:
PyW_ShowCbErr;
PyW_SizeVecToPyList;
PyW_UvalVecToPyList;
PyW_StrVecToPyList;
PyW_TryGetAttrString;
PyW_TryImportModule;
PyW_register_compiled_form;
+1
View File
@@ -6,6 +6,7 @@ EXPORTS
PyW_GetStringAttr
PyW_SizeVecToPyList
PyW_UvalVecToPyList
PyW_StrVecToPyList
PyW_IsSequenceType
PyW_ObjectToString
PyW_PyListToEaVec
Binary file not shown.
+26 -2
View File
@@ -16,6 +16,20 @@ import os
import sys
import time
import warnings
import os
import os.path
if os.name == 'nt' and \
sys.version_info.major == 3 and \
sys.version_info.minor >= 11:
# Python 3.11 has a bug with DLLs directory missing from sys.path
# so add it if it's not there
base = sys.base_exec_prefix
dllspath = os.path.join(base, sys.platlibdir)
if os.path.exists(dllspath) and dllspath not in sys.path:
i = sys.path.index(base) if base in sys.path else len(sys.path)
sys.path.insert(i, dllspath)
# Prepare sys.path so loading of the shared objects works
lib_dynload = os.path.join(
@@ -107,10 +121,20 @@ sys.stdout = sys.stderr = IDAPythonStdOut()
# Initialize the help, with our own stdin wrapper, that'll query the user
# -----------------------------------------------------------------------
import pydoc
class IDAPythonHelpPrompter:
class IDAPythonHelpPrompter(object):
def readline(self):
return ida_kernwin.ask_str('', 0, 'Help topic?')
help = pydoc.Helper(input = IDAPythonHelpPrompter(), output = sys.stdout)
class IDAPythonHelp(pydoc.Helper):
def __init__(self):
super().__init__(input = IDAPythonHelpPrompter(), output = sys.stdout)
def help(self, *args):
try:
return super().help(*args)
except ImportError as e:
print(e)
help = IDAPythonHelp()
# Assign a default sys.argv
sys.argv = [""]
+12
View File
@@ -100,6 +100,18 @@ ref_t ida_export PyW_UvalVecToPyList(const uvalvec_t &vec)
return ref_t(py_list);
}
//-------------------------------------------------------------------------
ref_t ida_export PyW_StrVecToPyList(const qstrvec_t &vec)
{
size_t n = vec.size();
PYW_GIL_CHECK_LOCKED_SCOPE();
newref_t py_list(PyList_New(n));
for ( size_t i = 0; i < n; ++i )
PyList_SetItem(py_list.o, i, PyUnicode_from_qstring(vec[i]));
return ref_t(py_list);
}
//-------------------------------------------------------------------------
static Py_ssize_t pyvar_walk_list(
const ref_t &py_list,
+1
View File
@@ -489,6 +489,7 @@ idaman Py_ssize_t ida_export pyvar_walk_list(
// Converts a vector to a Python list object
idaman ref_t ida_export PyW_SizeVecToPyList(const sizevec_t &vec);
idaman ref_t ida_export PyW_UvalVecToPyList(const uvalvec_t &vec);
idaman ref_t ida_export PyW_StrVecToPyList(const qstrvec_t &vec);
// Converts a Python list, to a vector of the given type.
// An exception will be raised in case:
+12
View File
@@ -103,6 +103,18 @@ class Choose(object):
ALL_CHANGED = 1
SELECTION_CHANGED = 2
# to construct `forbidden_cb`
CHOOSE_HAVE_INIT = 0x0001
CHOOSE_HAVE_GETICON = 0x0002
CHOOSE_HAVE_GETATTR = 0x0004
CHOOSE_HAVE_INS = 0x0008
CHOOSE_HAVE_DEL = 0x0010
CHOOSE_HAVE_EDIT = 0x0020
CHOOSE_HAVE_ENTER = 0x0040
CHOOSE_HAVE_REFRESH = 0x0080
CHOOSE_HAVE_SELECT = 0x0100
CHOOSE_HAVE_ONCLOSE = 0x0200
class UI_Hooks_Trampoline(UI_Hooks):
def __init__(self, v):
UI_Hooks.__init__(self)
+5 -11
View File
@@ -7,21 +7,15 @@
static PyObject *_py_reg_subkey_children(const char *name, bool subkeys)
{
PYW_GIL_CHECK_LOCKED_SCOPE();
PyObject *result = nullptr;
qstrvec_t children;
SWIG_PYTHON_THREAD_BEGIN_ALLOW;
if ( reg_subkey_children(&children, name, subkeys) )
{
result = PyList_New(children.size());
if ( result != nullptr )
for ( size_t i = 0, n = children.size(); i < n; ++i )
PyList_SET_ITEM(result, i, PyUnicode_FromString(children[i].c_str()));
}
bool ok = reg_subkey_children(&children, name, subkeys);
SWIG_PYTHON_THREAD_END_ALLOW;
if ( result == nullptr )
if ( !ok )
Py_RETURN_NONE;
else
return result;
ref_t result = PyW_StrVecToPyList(children);
result.incref();
return result.o;
}
//</code(py_registry)>