Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit26d87fd

Browse files
[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 commitc8c162e)
1 parent15f4bba commit26d87fd

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

‎Python/suggestions.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -147,14 +147,14 @@ calculate_suggestions(PyObject *dir,
147147

148148
for (inti=0;i<dir_size;++i) {
149149
PyObject*item=PyList_GET_ITEM(dir,i);
150+
if (_PyUnicode_Equal(name,item)) {
151+
continue;
152+
}
150153
Py_ssize_titem_size;
151154
constchar*item_str=PyUnicode_AsUTF8AndSize(item,&item_size);
152155
if (item_str==NULL) {
153156
returnNULL;
154157
}
155-
if (PyUnicode_CompareWithASCIIString(name,item_str)==0) {
156-
continue;
157-
}
158158
// No more than 1/3 of the involved characters should need changed.
159159
Py_ssize_tmax_distance= (name_size+item_size+3)*MOVE_COST /6;
160160
// Don't take matches we've already beaten.
@@ -225,19 +225,19 @@ offer_suggestions_for_name_error(PyNameErrorObject *exc)
225225
PyCodeObject*code=PyFrame_GetCode(frame);
226226
assert(code!=NULL&&code->co_localsplusnames!=NULL);
227227
PyObject*varnames=_PyCode_GetVarnames(code);
228+
Py_DECREF(code);
228229
if (varnames==NULL) {
229230
returnNULL;
230231
}
231232
PyObject*dir=PySequence_List(varnames);
232233
Py_DECREF(varnames);
233-
Py_DECREF(code);
234234
if (dir==NULL) {
235235
returnNULL;
236236
}
237237

238238
PyObject*suggestions=calculate_suggestions(dir,name);
239239
Py_DECREF(dir);
240-
if (suggestions!=NULL) {
240+
if (suggestions!=NULL||PyErr_Occurred()) {
241241
returnsuggestions;
242242
}
243243

@@ -247,7 +247,7 @@ offer_suggestions_for_name_error(PyNameErrorObject *exc)
247247
}
248248
suggestions=calculate_suggestions(dir,name);
249249
Py_DECREF(dir);
250-
if (suggestions!=NULL) {
250+
if (suggestions!=NULL||PyErr_Occurred()) {
251251
returnsuggestions;
252252
}
253253

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp