Skip to content

Commit b60b67c

Browse files
Perform suggested changes
1 parent 4e715b0 commit b60b67c

File tree

1 file changed

+11
-13
lines changed

1 file changed

+11
-13
lines changed

Objects/unicodeobject.c

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -13090,8 +13090,6 @@ unicode_maketrans_from_dict(PyObject *x, PyObject *newdict)
1309013090
PyObject *key, *value;
1309113091
Py_ssize_t i = 0;
1309213092
int res;
13093-
int ret = -1;
13094-
Py_BEGIN_CRITICAL_SECTION(x);
1309513093
while (PyDict_Next(x, &i, &key, &value)) {
1309613094
if (PyUnicode_Check(key)) {
1309713095
PyObject *newkey;
@@ -13100,33 +13098,29 @@ unicode_maketrans_from_dict(PyObject *x, PyObject *newdict)
1310013098
if (PyUnicode_GET_LENGTH(key) != 1) {
1310113099
PyErr_SetString(PyExc_ValueError, "string keys in translate"
1310213100
"table must be of length 1");
13103-
break;
13101+
return -1;
1310413102
}
1310513103
kind = PyUnicode_KIND(key);
1310613104
data = PyUnicode_DATA(key);
1310713105
newkey = PyLong_FromLong(PyUnicode_READ(kind, data, 0));
1310813106
if (!newkey)
13109-
break;
13107+
return -1;
1311013108
res = PyDict_SetItem(newdict, newkey, value);
1311113109
Py_DECREF(newkey);
1311213110
if (res < 0)
13113-
break;
13111+
return -1;
1311413112
}
1311513113
else if (PyLong_Check(key)) {
1311613114
if (PyDict_SetItem(newdict, key, value) < 0)
13117-
break;
13115+
return -1;
1311813116
}
1311913117
else {
1312013118
PyErr_SetString(PyExc_TypeError, "keys in translate table must"
1312113119
"be strings or integers");
13122-
break;
13120+
return -1;
1312313121
}
1312413122
}
13125-
if (!PyErr_Occurred()) {
13126-
ret = 0;
13127-
}
13128-
Py_END_CRITICAL_SECTION();
13129-
return ret;
13123+
return 0;
1313013124
}
1313113125

1313213126
static PyObject *
@@ -13197,7 +13191,11 @@ unicode_maketrans_impl(PyObject *x, PyObject *y, PyObject *z)
1319713191
goto err;
1319813192
}
1319913193
/* copy entries into the new dict, converting string keys to int keys */
13200-
if(unicode_maketrans_from_dict(x, new) < 0)
13194+
int errcode;
13195+
Py_BEGIN_CRITICAL_SECTION(x);
13196+
errcode = unicode_maketrans_from_dict(x, new);
13197+
Py_END_CRITICAL_SECTION();
13198+
if (errcode < 0)
1320113199
goto err;
1320213200
}
1320313201
return new;

0 commit comments

Comments
 (0)