Skip to content
Merged
Prev Previous commit
Next Next commit
Update function
  • Loading branch information
VanshAgarwal24036 committed Feb 24, 2026
commit 4e715b009b73f76063db88741b415a0a355d7a37
18 changes: 9 additions & 9 deletions Objects/unicodeobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -13090,8 +13090,7 @@ unicode_maketrans_from_dict(PyObject *x, PyObject *newdict)
PyObject *key, *value;
Py_ssize_t i = 0;
int res;
int ret = -1; /* assume failure */

int ret = -1;
Py_BEGIN_CRITICAL_SECTION(x);
while (PyDict_Next(x, &i, &key, &value)) {
if (PyUnicode_Check(key)) {
Expand All @@ -13101,30 +13100,31 @@ unicode_maketrans_from_dict(PyObject *x, PyObject *newdict)
if (PyUnicode_GET_LENGTH(key) != 1) {
PyErr_SetString(PyExc_ValueError, "string keys in translate"
"table must be of length 1");
goto done;
break;
}
kind = PyUnicode_KIND(key);
data = PyUnicode_DATA(key);
newkey = PyLong_FromLong(PyUnicode_READ(kind, data, 0));
if (!newkey)
goto done;
break;
res = PyDict_SetItem(newdict, newkey, value);
Py_DECREF(newkey);
if (res < 0)
goto done;
break;
}
else if (PyLong_Check(key)) {
if (PyDict_SetItem(newdict, key, value) < 0)
goto done;
break;
}
else {
PyErr_SetString(PyExc_TypeError, "keys in translate table must"
"be strings or integers");
goto done;
break;
}
}
ret = 0;
done:
if (!PyErr_Occurred()) {
ret = 0;
}
Py_END_CRITICAL_SECTION();
return ret;
}
Expand Down
Loading