goto err;
}
/* create entries for translating chars in x to those in y */
- for (i = 0; i < PyUnicode_GET_SIZE(x); i++) {
- key = PyLong_FromLong(PyUnicode_AS_UNICODE(x)[i]);
+ x_kind = PyUnicode_KIND(x);
+ y_kind = PyUnicode_KIND(y);
+ x_data = PyUnicode_DATA(x);
+ y_data = PyUnicode_DATA(y);
+ for (i = 0; i < PyUnicode_GET_LENGTH(x); i++) {
+ key = PyLong_FromLong(PyUnicode_READ(x_kind, x_data, i));
+ if (!key)
+ goto err;
- value = PyLong_FromLong(PyUnicode_AS_UNICODE(y)[i]);
+ value = PyLong_FromLong(PyUnicode_READ(y_kind, y_data, i));
- if (!key || !value)
+ if (!value) {
+ Py_DECREF(key);
goto err;
+ }
res = PyDict_SetItem(new, key, value);
Py_DECREF(key);
Py_DECREF(value);