summaryrefslogtreecommitdiffstats
path: root/Python
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2023-06-23 18:13:07 (GMT)
committerGitHub <noreply@github.com>2023-06-23 18:13:07 (GMT)
commit26d87fd5c7a2f94ad0a9c5385722a13a9c75fa78 (patch)
treec2a071a05e91d105b1bc5d4c7364de3164592921 /Python
parent15f4bba7a795de20cc945e8aa61c458a7b30aaa2 (diff)
downloadcpython-26d87fd5c7a2f94ad0a9c5385722a13a9c75fa78.zip
cpython-26d87fd5c7a2f94ad0a9c5385722a13a9c75fa78.tar.gz
cpython-26d87fd5c7a2f94ad0a9c5385722a13a9c75fa78.tar.bz2
[3.11] gh-106030: Miscellaneous fixes in Python/suggestions.c (GH-106… (GH-106039)
* PyUnicode_CompareWithASCIIString() only works if the second argument is ASCII string. * Refleak in get_suggestions_for_name_error. * Add some missing error checks. (cherry picked from commit c8c162ef5294cddb7ac75fe93ab918e5661c68ee)
Diffstat (limited to 'Python')
-rw-r--r--Python/suggestions.c12
1 files changed, 6 insertions, 6 deletions
diff --git a/Python/suggestions.c b/Python/suggestions.c
index c336ec8..5a4cf93 100644
--- a/Python/suggestions.c
+++ b/Python/suggestions.c
@@ -147,14 +147,14 @@ calculate_suggestions(PyObject *dir,
for (int i = 0; i < dir_size; ++i) {
PyObject *item = PyList_GET_ITEM(dir, i);
+ if (_PyUnicode_Equal(name, item)) {
+ continue;
+ }
Py_ssize_t item_size;
const char *item_str = PyUnicode_AsUTF8AndSize(item, &item_size);
if (item_str == NULL) {
return NULL;
}
- if (PyUnicode_CompareWithASCIIString(name, item_str) == 0) {
- continue;
- }
// No more than 1/3 of the involved characters should need changed.
Py_ssize_t max_distance = (name_size + item_size + 3) * MOVE_COST / 6;
// Don't take matches we've already beaten.
@@ -225,19 +225,19 @@ offer_suggestions_for_name_error(PyNameErrorObject *exc)
PyCodeObject *code = PyFrame_GetCode(frame);
assert(code != NULL && code->co_localsplusnames != NULL);
PyObject *varnames = _PyCode_GetVarnames(code);
+ Py_DECREF(code);
if (varnames == NULL) {
return NULL;
}
PyObject *dir = PySequence_List(varnames);
Py_DECREF(varnames);
- Py_DECREF(code);
if (dir == NULL) {
return NULL;
}
PyObject *suggestions = calculate_suggestions(dir, name);
Py_DECREF(dir);
- if (suggestions != NULL) {
+ if (suggestions != NULL|| PyErr_Occurred()) {
return suggestions;
}
@@ -247,7 +247,7 @@ offer_suggestions_for_name_error(PyNameErrorObject *exc)
}
suggestions = calculate_suggestions(dir, name);
Py_DECREF(dir);
- if (suggestions != NULL) {
+ if (suggestions != NULL || PyErr_Occurred()) {
return suggestions;
}